Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/x64/virtual-frame-x64.h

Issue 6811012: Remove some dead code. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/x64/stub-cache-x64.cc ('k') | src/x64/virtual-frame-x64.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 #ifndef V8_X64_VIRTUAL_FRAME_X64_H_
29 #define V8_X64_VIRTUAL_FRAME_X64_H_
30
31 #include "type-info.h"
32 #include "register-allocator.h"
33 #include "scopes.h"
34 #include "codegen.h"
35
36 namespace v8 {
37 namespace internal {
38
39 // -------------------------------------------------------------------------
40 // Virtual frames
41 //
42 // The virtual frame is an abstraction of the physical stack frame. It
43 // encapsulates the parameters, frame-allocated locals, and the expression
44 // stack. It supports push/pop operations on the expression stack, as well
45 // as random access to the expression stack elements, locals, and
46 // parameters.
47
48 class VirtualFrame : public ZoneObject {
49 public:
50 // A utility class to introduce a scope where the virtual frame is
51 // expected to remain spilled. The constructor spills the code
52 // generator's current frame, but no attempt is made to require it
53 // to stay spilled. It is intended as documentation while the code
54 // generator is being transformed.
55 class SpilledScope BASE_EMBEDDED {
56 public:
57 SpilledScope() : previous_state_(cgen()->in_spilled_code()) {
58 ASSERT(cgen()->has_valid_frame());
59 cgen()->frame()->SpillAll();
60 cgen()->set_in_spilled_code(true);
61 }
62
63 ~SpilledScope() {
64 cgen()->set_in_spilled_code(previous_state_);
65 }
66
67 private:
68 bool previous_state_;
69
70 CodeGenerator* cgen() {
71 return CodeGeneratorScope::Current(Isolate::Current());
72 }
73 };
74
75 // An illegal index into the virtual frame.
76 static const int kIllegalIndex = -1;
77
78 // Construct an initial virtual frame on entry to a JS function.
79 inline VirtualFrame();
80
81 // Construct a virtual frame as a clone of an existing one.
82 explicit inline VirtualFrame(VirtualFrame* original);
83
84 CodeGenerator* cgen() {
85 return CodeGeneratorScope::Current(Isolate::Current());
86 }
87
88 MacroAssembler* masm() { return cgen()->masm(); }
89
90 // Create a duplicate of an existing valid frame element.
91 FrameElement CopyElementAt(int index,
92 TypeInfo info = TypeInfo::Uninitialized());
93
94 // The number of elements on the virtual frame.
95 int element_count() { return elements_.length(); }
96
97 // The height of the virtual expression stack.
98 int height() {
99 return element_count() - expression_base_index();
100 }
101
102 int register_location(int num) {
103 ASSERT(num >= 0 && num < RegisterAllocator::kNumRegisters);
104 return register_locations_[num];
105 }
106
107 inline int register_location(Register reg);
108
109 inline void set_register_location(Register reg, int index);
110
111 bool is_used(int num) {
112 ASSERT(num >= 0 && num < RegisterAllocator::kNumRegisters);
113 return register_locations_[num] != kIllegalIndex;
114 }
115
116 inline bool is_used(Register reg);
117
118 // Add extra in-memory elements to the top of the frame to match an actual
119 // frame (eg, the frame after an exception handler is pushed). No code is
120 // emitted.
121 void Adjust(int count);
122
123 // Forget count elements from the top of the frame all in-memory
124 // (including synced) and adjust the stack pointer downward, to
125 // match an external frame effect (examples include a call removing
126 // its arguments, and exiting a try/catch removing an exception
127 // handler). No code will be emitted.
128 void Forget(int count) {
129 ASSERT(count >= 0);
130 ASSERT(stack_pointer_ == element_count() - 1);
131 stack_pointer_ -= count;
132 ForgetElements(count);
133 }
134
135 // Forget count elements from the top of the frame without adjusting
136 // the stack pointer downward. This is used, for example, before
137 // merging frames at break, continue, and return targets.
138 void ForgetElements(int count);
139
140 // Spill all values from the frame to memory.
141 inline void SpillAll();
142
143 // Spill all occurrences of a specific register from the frame.
144 void Spill(Register reg) {
145 if (is_used(reg)) SpillElementAt(register_location(reg));
146 }
147
148 // Spill all occurrences of an arbitrary register if possible. Return the
149 // register spilled or no_reg if it was not possible to free any register
150 // (ie, they all have frame-external references).
151 Register SpillAnyRegister();
152
153 // Spill the top element of the frame to memory.
154 void SpillTop() { SpillElementAt(element_count() - 1); }
155
156 // Sync the range of elements in [begin, end] with memory.
157 void SyncRange(int begin, int end);
158
159 // Make this frame so that an arbitrary frame of the same height can
160 // be merged to it. Copies and constants are removed from the frame.
161 void MakeMergable();
162
163 // Prepare this virtual frame for merging to an expected frame by
164 // performing some state changes that do not require generating
165 // code. It is guaranteed that no code will be generated.
166 void PrepareMergeTo(VirtualFrame* expected);
167
168 // Make this virtual frame have a state identical to an expected virtual
169 // frame. As a side effect, code may be emitted to make this frame match
170 // the expected one.
171 void MergeTo(VirtualFrame* expected);
172
173 // Detach a frame from its code generator, perhaps temporarily. This
174 // tells the register allocator that it is free to use frame-internal
175 // registers. Used when the code generator's frame is switched from this
176 // one to NULL by an unconditional jump.
177 void DetachFromCodeGenerator() {
178 RegisterAllocator* cgen_allocator = cgen()->allocator();
179 for (int i = 0; i < RegisterAllocator::kNumRegisters; i++) {
180 if (is_used(i)) cgen_allocator->Unuse(i);
181 }
182 }
183
184 // (Re)attach a frame to its code generator. This informs the register
185 // allocator that the frame-internal register references are active again.
186 // Used when a code generator's frame is switched from NULL to this one by
187 // binding a label.
188 void AttachToCodeGenerator() {
189 RegisterAllocator* cgen_allocator = cgen()->allocator();
190 for (int i = 0; i < RegisterAllocator::kNumRegisters; i++) {
191 if (is_used(i)) cgen_allocator->Use(i);
192 }
193 }
194
195 // Emit code for the physical JS entry and exit frame sequences. After
196 // calling Enter, the virtual frame is ready for use; and after calling
197 // Exit it should not be used. Note that Enter does not allocate space in
198 // the physical frame for storing frame-allocated locals.
199 void Enter();
200 void Exit();
201
202 // Prepare for returning from the frame by spilling locals. This
203 // avoids generating unnecessary merge code when jumping to the
204 // shared return site. Emits code for spills.
205 inline void PrepareForReturn();
206
207 // Number of local variables after when we use a loop for allocating.
208 static const int kLocalVarBound = 14;
209
210 // Allocate and initialize the frame-allocated locals.
211 void AllocateStackSlots();
212
213 // An element of the expression stack as an assembly operand.
214 Operand ElementAt(int index) const {
215 return Operand(rsp, index * kPointerSize);
216 }
217
218 // Random-access store to a frame-top relative frame element. The result
219 // becomes owned by the frame and is invalidated.
220 void SetElementAt(int index, Result* value);
221
222 // Set a frame element to a constant. The index is frame-top relative.
223 inline void SetElementAt(int index, Handle<Object> value);
224
225 void PushElementAt(int index) {
226 PushFrameSlotAt(element_count() - index - 1);
227 }
228
229 void StoreToElementAt(int index) {
230 StoreToFrameSlotAt(element_count() - index - 1);
231 }
232
233 // A frame-allocated local as an assembly operand.
234 Operand LocalAt(int index) {
235 ASSERT(0 <= index);
236 ASSERT(index < local_count());
237 return Operand(rbp, kLocal0Offset - index * kPointerSize);
238 }
239
240 // Push a copy of the value of a local frame slot on top of the frame.
241 void PushLocalAt(int index) {
242 PushFrameSlotAt(local0_index() + index);
243 }
244
245 // Push the value of a local frame slot on top of the frame and invalidate
246 // the local slot. The slot should be written to before trying to read
247 // from it again.
248 void TakeLocalAt(int index) {
249 TakeFrameSlotAt(local0_index() + index);
250 }
251
252 // Store the top value on the virtual frame into a local frame slot. The
253 // value is left in place on top of the frame.
254 void StoreToLocalAt(int index) {
255 StoreToFrameSlotAt(local0_index() + index);
256 }
257
258 // Push the address of the receiver slot on the frame.
259 void PushReceiverSlotAddress();
260
261 // Push the function on top of the frame.
262 void PushFunction() { PushFrameSlotAt(function_index()); }
263
264 // Save the value of the esi register to the context frame slot.
265 void SaveContextRegister();
266
267 // Restore the esi register from the value of the context frame
268 // slot.
269 void RestoreContextRegister();
270
271 // A parameter as an assembly operand.
272 Operand ParameterAt(int index) {
273 ASSERT(-1 <= index); // -1 is the receiver.
274 ASSERT(index < parameter_count());
275 return Operand(rbp, (1 + parameter_count() - index) * kPointerSize);
276 }
277
278 // Push a copy of the value of a parameter frame slot on top of the frame.
279 void PushParameterAt(int index) {
280 PushFrameSlotAt(param0_index() + index);
281 }
282
283 // Push the value of a paramter frame slot on top of the frame and
284 // invalidate the parameter slot. The slot should be written to before
285 // trying to read from it again.
286 void TakeParameterAt(int index) {
287 TakeFrameSlotAt(param0_index() + index);
288 }
289
290 // Store the top value on the virtual frame into a parameter frame slot.
291 // The value is left in place on top of the frame.
292 void StoreToParameterAt(int index) {
293 StoreToFrameSlotAt(param0_index() + index);
294 }
295
296 // The receiver frame slot.
297 Operand Receiver() { return ParameterAt(-1); }
298
299 // Push a try-catch or try-finally handler on top of the virtual frame.
300 void PushTryHandler(HandlerType type);
301
302 // Call stub given the number of arguments it expects on (and
303 // removes from) the stack.
304 inline Result CallStub(CodeStub* stub, int arg_count);
305
306 // Call stub that takes a single argument passed in eax. The
307 // argument is given as a result which does not have to be eax or
308 // even a register. The argument is consumed by the call.
309 Result CallStub(CodeStub* stub, Result* arg);
310
311 // Call stub that takes a pair of arguments passed in edx (arg0, rdx) and
312 // eax (arg1, rax). The arguments are given as results which do not have
313 // to be in the proper registers or even in registers. The
314 // arguments are consumed by the call.
315 Result CallStub(CodeStub* stub, Result* arg0, Result* arg1);
316
317 // Call JS function from top of the stack with arguments
318 // taken from the stack.
319 Result CallJSFunction(int arg_count);
320
321 // Call runtime given the number of arguments expected on (and
322 // removed from) the stack.
323 Result CallRuntime(const Runtime::Function* f, int arg_count);
324 Result CallRuntime(Runtime::FunctionId id, int arg_count);
325
326 #ifdef ENABLE_DEBUGGER_SUPPORT
327 void DebugBreak();
328 #endif
329
330 // Invoke builtin given the number of arguments it expects on (and
331 // removes from) the stack.
332 Result InvokeBuiltin(Builtins::JavaScript id,
333 InvokeFlag flag,
334 int arg_count);
335
336 // Call load IC. Name and receiver are found on top of the frame.
337 // Both are dropped.
338 Result CallLoadIC(RelocInfo::Mode mode);
339
340 // Call keyed load IC. Key and receiver are found on top of the
341 // frame. Both are dropped.
342 Result CallKeyedLoadIC(RelocInfo::Mode mode);
343
344 // Call store IC. If the load is contextual, value is found on top of the
345 // frame. If not, value and receiver are on the frame. Both are dropped.
346 Result CallStoreIC(Handle<String> name, bool is_contextual,
347 StrictModeFlag strict_mode);
348
349 // Call keyed store IC. Value, key, and receiver are found on top
350 Result CallKeyedStoreIC(StrictModeFlag strict_mode);
351
352 // Call call IC. Function name, arguments, and receiver are found on top
353 // of the frame and dropped by the call.
354 // The argument count does not include the receiver.
355 Result CallCallIC(RelocInfo::Mode mode, int arg_count, int loop_nesting);
356
357 // Call keyed call IC. Same calling convention as CallCallIC.
358 Result CallKeyedCallIC(RelocInfo::Mode mode, int arg_count, int loop_nesting);
359
360 // Allocate and call JS function as constructor. Arguments,
361 // receiver (global object), and function are found on top of the
362 // frame. Function is not dropped. The argument count does not
363 // include the receiver.
364 Result CallConstructor(int arg_count);
365
366 // Drop a number of elements from the top of the expression stack. May
367 // emit code to affect the physical frame. Does not clobber any registers
368 // excepting possibly the stack pointer.
369 void Drop(int count);
370
371 // Drop one element.
372 void Drop() { Drop(1); }
373
374 // Duplicate the top element of the frame.
375 void Dup() { PushFrameSlotAt(element_count() - 1); }
376
377 // Duplicate the n'th element from the top of the frame.
378 // Dup(1) is equivalent to Dup().
379 void Dup(int n) {
380 ASSERT(n > 0);
381 PushFrameSlotAt(element_count() - n);
382 }
383
384 // Pop an element from the top of the expression stack. Returns a
385 // Result, which may be a constant or a register.
386 Result Pop();
387
388 // Pop and save an element from the top of the expression stack and
389 // emit a corresponding pop instruction.
390 void EmitPop(Register reg);
391 void EmitPop(const Operand& operand);
392
393 // Push an element on top of the expression stack and emit a
394 // corresponding push instruction.
395 void EmitPush(Register reg,
396 TypeInfo info = TypeInfo::Unknown());
397 void EmitPush(const Operand& operand,
398 TypeInfo info = TypeInfo::Unknown());
399 void EmitPush(Heap::RootListIndex index,
400 TypeInfo info = TypeInfo::Unknown());
401 void EmitPush(Immediate immediate,
402 TypeInfo info = TypeInfo::Unknown());
403 void EmitPush(Smi* value);
404 // Uses kScratchRegister, emits appropriate relocation info.
405 void EmitPush(Handle<Object> value);
406
407 inline bool ConstantPoolOverflowed();
408
409 // Push an element on the virtual frame.
410 void Push(Handle<Object> value);
411 inline void Push(Register reg, TypeInfo info = TypeInfo::Unknown());
412 inline void Push(Smi* value);
413
414 // Pushing a result invalidates it (its contents become owned by the
415 // frame).
416 void Push(Result* result) {
417 if (result->is_register()) {
418 Push(result->reg(), result->type_info());
419 } else {
420 ASSERT(result->is_constant());
421 Push(result->handle());
422 }
423 result->Unuse();
424 }
425
426 // Pushing an expression expects that the expression is trivial (according
427 // to Expression::IsTrivial).
428 void Push(Expression* expr);
429
430 // Nip removes zero or more elements from immediately below the top
431 // of the frame, leaving the previous top-of-frame value on top of
432 // the frame. Nip(k) is equivalent to x = Pop(), Drop(k), Push(x).
433 inline void Nip(int num_dropped);
434
435 inline void SetTypeForLocalAt(int index, TypeInfo info);
436 inline void SetTypeForParamAt(int index, TypeInfo info);
437
438 private:
439 static const int kLocal0Offset = JavaScriptFrameConstants::kLocal0Offset;
440 static const int kFunctionOffset = JavaScriptFrameConstants::kFunctionOffset;
441 static const int kContextOffset = StandardFrameConstants::kContextOffset;
442
443 static const int kHandlerSize = StackHandlerConstants::kSize / kPointerSize;
444 static const int kPreallocatedElements = 5 + 8; // 8 expression stack slots.
445
446 ZoneList<FrameElement> elements_;
447
448 // The index of the element that is at the processor's stack pointer
449 // (the esp register).
450 int stack_pointer_;
451
452 // The index of the register frame element using each register, or
453 // kIllegalIndex if a register is not on the frame.
454 int register_locations_[RegisterAllocator::kNumRegisters];
455
456 // The number of frame-allocated locals and parameters respectively.
457 inline int parameter_count();
458 inline int local_count();
459
460 // The index of the element that is at the processor's frame pointer
461 // (the ebp register). The parameters, receiver, and return address
462 // are below the frame pointer.
463 int frame_pointer() { return parameter_count() + 2; }
464
465 // The index of the first parameter. The receiver lies below the first
466 // parameter.
467 int param0_index() { return 1; }
468
469 // The index of the context slot in the frame. It is immediately
470 // above the frame pointer.
471 int context_index() { return frame_pointer() + 1; }
472
473 // The index of the function slot in the frame. It is above the frame
474 // pointer and the context slot.
475 int function_index() { return frame_pointer() + 2; }
476
477 // The index of the first local. Between the frame pointer and the
478 // locals lie the context and the function.
479 int local0_index() { return frame_pointer() + 3; }
480
481 // The index of the base of the expression stack.
482 int expression_base_index() { return local0_index() + local_count(); }
483
484 // Convert a frame index into a frame pointer relative offset into the
485 // actual stack.
486 int fp_relative(int index) {
487 ASSERT(index < element_count());
488 ASSERT(frame_pointer() < element_count()); // FP is on the frame.
489 return (frame_pointer() - index) * kPointerSize;
490 }
491
492 // Record an occurrence of a register in the virtual frame. This has the
493 // effect of incrementing the register's external reference count and
494 // of updating the index of the register's location in the frame.
495 void Use(Register reg, int index) {
496 ASSERT(!is_used(reg));
497 set_register_location(reg, index);
498 cgen()->allocator()->Use(reg);
499 }
500
501 // Record that a register reference has been dropped from the frame. This
502 // decrements the register's external reference count and invalidates the
503 // index of the register's location in the frame.
504 void Unuse(Register reg) {
505 ASSERT(is_used(reg));
506 set_register_location(reg, kIllegalIndex);
507 cgen()->allocator()->Unuse(reg);
508 }
509
510 // Spill the element at a particular index---write it to memory if
511 // necessary, free any associated register, and forget its value if
512 // constant.
513 void SpillElementAt(int index);
514
515 // Sync the element at a particular index. If it is a register or
516 // constant that disagrees with the value on the stack, write it to memory.
517 // Keep the element type as register or constant, and clear the dirty bit.
518 void SyncElementAt(int index);
519
520 // Sync a single unsynced element that lies beneath or at the stack pointer.
521 void SyncElementBelowStackPointer(int index);
522
523 // Sync a single unsynced element that lies just above the stack pointer.
524 void SyncElementByPushing(int index);
525
526 // Push a copy of a frame slot (typically a local or parameter) on top of
527 // the frame.
528 inline void PushFrameSlotAt(int index);
529
530 // Push a the value of a frame slot (typically a local or parameter) on
531 // top of the frame and invalidate the slot.
532 void TakeFrameSlotAt(int index);
533
534 // Store the value on top of the frame to a frame slot (typically a local
535 // or parameter).
536 void StoreToFrameSlotAt(int index);
537
538 // Spill all elements in registers. Spill the top spilled_args elements
539 // on the frame. Sync all other frame elements.
540 // Then drop dropped_args elements from the virtual frame, to match
541 // the effect of an upcoming call that will drop them from the stack.
542 void PrepareForCall(int spilled_args, int dropped_args);
543
544 // Move frame elements currently in registers or constants, that
545 // should be in memory in the expected frame, to memory.
546 void MergeMoveRegistersToMemory(VirtualFrame* expected);
547
548 // Make the register-to-register moves necessary to
549 // merge this frame with the expected frame.
550 // Register to memory moves must already have been made,
551 // and memory to register moves must follow this call.
552 // This is because some new memory-to-register moves are
553 // created in order to break cycles of register moves.
554 // Used in the implementation of MergeTo().
555 void MergeMoveRegistersToRegisters(VirtualFrame* expected);
556
557 // Make the memory-to-register and constant-to-register moves
558 // needed to make this frame equal the expected frame.
559 // Called after all register-to-memory and register-to-register
560 // moves have been made. After this function returns, the frames
561 // should be equal.
562 void MergeMoveMemoryToRegisters(VirtualFrame* expected);
563
564 // Invalidates a frame slot (puts an invalid frame element in it).
565 // Copies on the frame are correctly handled, and if this slot was
566 // the backing store of copies, the index of the new backing store
567 // is returned. Otherwise, returns kIllegalIndex.
568 // Register counts are correctly updated.
569 int InvalidateFrameSlotAt(int index);
570
571 // This function assumes that a and b are the only results that could be in
572 // the registers a_reg or b_reg. Other results can be live, but must not
573 // be in the registers a_reg or b_reg. The results a and b are invalidated.
574 void MoveResultsToRegisters(Result* a,
575 Result* b,
576 Register a_reg,
577 Register b_reg);
578
579 // Call a code stub that has already been prepared for calling (via
580 // PrepareForCall).
581 Result RawCallStub(CodeStub* stub);
582
583 // Calls a code object which has already been prepared for calling
584 // (via PrepareForCall).
585 Result RawCallCodeObject(Handle<Code> code, RelocInfo::Mode rmode);
586
587 inline bool Equals(VirtualFrame* other);
588
589 // Classes that need raw access to the elements_ array.
590 friend class FrameRegisterState;
591 friend class JumpTarget;
592 };
593
594
595 } } // namespace v8::internal
596
597 #endif // V8_X64_VIRTUAL_FRAME_X64_H_
OLDNEW
« no previous file with comments | « src/x64/stub-cache-x64.cc ('k') | src/x64/virtual-frame-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698