OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 | 43 |
44 class VirtualFrame : public ZoneObject { | 44 class VirtualFrame : public ZoneObject { |
45 public: | 45 public: |
46 // A utility class to introduce a scope where the virtual frame is | 46 // A utility class to introduce a scope where the virtual frame is |
47 // expected to remain spilled. The constructor spills the code | 47 // expected to remain spilled. The constructor spills the code |
48 // generator's current frame, but no attempt is made to require it | 48 // generator's current frame, but no attempt is made to require it |
49 // to stay spilled. It is intended as documentation while the code | 49 // to stay spilled. It is intended as documentation while the code |
50 // generator is being transformed. | 50 // generator is being transformed. |
51 class SpilledScope BASE_EMBEDDED { | 51 class SpilledScope BASE_EMBEDDED { |
52 public: | 52 public: |
53 explicit SpilledScope(CodeGenerator* cgen); | 53 explicit SpilledScope(CodeGenerator* cgen) |
| 54 : cgen_(cgen), |
| 55 previous_state_(cgen->in_spilled_code()) { |
| 56 ASSERT(cgen->has_valid_frame()); |
| 57 cgen->frame()->SpillAll(); |
| 58 cgen->set_in_spilled_code(true); |
| 59 } |
54 | 60 |
55 ~SpilledScope(); | 61 ~SpilledScope() { |
| 62 cgen_->set_in_spilled_code(previous_state_); |
| 63 } |
56 | 64 |
57 private: | 65 private: |
58 CodeGenerator* cgen_; | 66 CodeGenerator* cgen_; |
59 bool previous_state_; | 67 bool previous_state_; |
60 }; | 68 }; |
61 | 69 |
62 // An illegal index into the virtual frame. | 70 // An illegal index into the virtual frame. |
63 static const int kIllegalIndex = -1; | 71 static const int kIllegalIndex = -1; |
64 | 72 |
65 // Construct an initial virtual frame on entry to a JS function. | 73 // Construct an initial virtual frame on entry to a JS function. |
(...skipping 25 matching lines...) Expand all Loading... |
91 // Add extra in-memory elements to the top of the frame to match an actual | 99 // Add extra in-memory elements to the top of the frame to match an actual |
92 // frame (eg, the frame after an exception handler is pushed). No code is | 100 // frame (eg, the frame after an exception handler is pushed). No code is |
93 // emitted. | 101 // emitted. |
94 void Adjust(int count); | 102 void Adjust(int count); |
95 | 103 |
96 // Forget count elements from the top of the frame all in-memory | 104 // Forget count elements from the top of the frame all in-memory |
97 // (including synced) and adjust the stack pointer downward, to | 105 // (including synced) and adjust the stack pointer downward, to |
98 // match an external frame effect (examples include a call removing | 106 // match an external frame effect (examples include a call removing |
99 // its arguments, and exiting a try/catch removing an exception | 107 // its arguments, and exiting a try/catch removing an exception |
100 // handler). No code will be emitted. | 108 // handler). No code will be emitted. |
101 void Forget(int count); | 109 void Forget(int count) { |
| 110 ASSERT(count >= 0); |
| 111 ASSERT(stack_pointer_ == elements_.length() - 1); |
| 112 stack_pointer_ -= count; |
| 113 ForgetElements(count); |
| 114 } |
102 | 115 |
103 // Forget count elements from the top of the frame without adjusting | 116 // Forget count elements from the top of the frame without adjusting |
104 // the stack pointer downward. This is used, for example, before | 117 // the stack pointer downward. This is used, for example, before |
105 // merging frames at break, continue, and return targets. | 118 // merging frames at break, continue, and return targets. |
106 void ForgetElements(int count); | 119 void ForgetElements(int count); |
107 | 120 |
108 // Spill all values from the frame to memory. | 121 // Spill all values from the frame to memory. |
109 void SpillAll(); | 122 void SpillAll(); |
110 | 123 |
111 // Spill all occurrences of a specific register from the frame. | 124 // Spill all occurrences of a specific register from the frame. |
112 void Spill(Register reg); | 125 void Spill(Register reg) { |
| 126 if (is_used(reg)) SpillElementAt(register_index(reg)); |
| 127 } |
113 | 128 |
114 // Spill all occurrences of an arbitrary register if possible. Return the | 129 // Spill all occurrences of an arbitrary register if possible. Return the |
115 // register spilled or no_reg if it was not possible to free any register | 130 // register spilled or no_reg if it was not possible to free any register |
116 // (ie, they all have frame-external references). | 131 // (ie, they all have frame-external references). |
117 Register SpillAnyRegister(); | 132 Register SpillAnyRegister(); |
118 | 133 |
119 // Make this frame so that an arbitrary frame of the same height can | 134 // Make this frame so that an arbitrary frame of the same height can |
120 // be merged to it. Copies and constants are removed from the | 135 // be merged to it. Copies and constants are removed from the |
121 // topmost mergable_elements elements of the frame. A | 136 // topmost mergable_elements elements of the frame. A |
122 // mergable_elements of JumpTarget::kAllElements indicates constants | 137 // mergable_elements of JumpTarget::kAllElements indicates constants |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 } | 278 } |
264 | 279 |
265 // The receiver frame slot. | 280 // The receiver frame slot. |
266 Operand Receiver() const { return ParameterAt(-1); } | 281 Operand Receiver() const { return ParameterAt(-1); } |
267 | 282 |
268 // Push a try-catch or try-finally handler on top of the virtual frame. | 283 // Push a try-catch or try-finally handler on top of the virtual frame. |
269 void PushTryHandler(HandlerType type); | 284 void PushTryHandler(HandlerType type); |
270 | 285 |
271 // Call stub given the number of arguments it expects on (and | 286 // Call stub given the number of arguments it expects on (and |
272 // removes from) the stack. | 287 // removes from) the stack. |
273 Result CallStub(CodeStub* stub, int arg_count); | 288 Result CallStub(CodeStub* stub, int arg_count) { |
| 289 PrepareForCall(arg_count, arg_count); |
| 290 return RawCallStub(stub); |
| 291 } |
274 | 292 |
275 // Call stub that takes a single argument passed in eax. The | 293 // Call stub that takes a single argument passed in eax. The |
276 // argument is given as a result which does not have to be eax or | 294 // argument is given as a result which does not have to be eax or |
277 // even a register. The argument is consumed by the call. | 295 // even a register. The argument is consumed by the call. |
278 Result CallStub(CodeStub* stub, Result* arg); | 296 Result CallStub(CodeStub* stub, Result* arg); |
279 | 297 |
280 // Call stub that takes a pair of arguments passed in edx (arg0) and | 298 // Call stub that takes a pair of arguments passed in edx (arg0) and |
281 // eax (arg1). The arguments are given as results which do not have | 299 // eax (arg1). The arguments are given as results which do not have |
282 // to be in the proper registers or even in registers. The | 300 // to be in the proper registers or even in registers. The |
283 // arguments are consumed by the call. | 301 // arguments are consumed by the call. |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 void EmitPush(Operand operand); | 365 void EmitPush(Operand operand); |
348 void EmitPush(Immediate immediate); | 366 void EmitPush(Immediate immediate); |
349 | 367 |
350 // Push an element on the virtual frame. | 368 // Push an element on the virtual frame. |
351 void Push(Register reg, StaticType static_type = StaticType()); | 369 void Push(Register reg, StaticType static_type = StaticType()); |
352 void Push(Handle<Object> value); | 370 void Push(Handle<Object> value); |
353 void Push(Smi* value) { Push(Handle<Object>(value)); } | 371 void Push(Smi* value) { Push(Handle<Object>(value)); } |
354 | 372 |
355 // Pushing a result invalidates it (its contents become owned by the | 373 // Pushing a result invalidates it (its contents become owned by the |
356 // frame). | 374 // frame). |
357 void Push(Result* result); | 375 void Push(Result* result) { |
| 376 if (result->is_register()) { |
| 377 Push(result->reg(), result->static_type()); |
| 378 } else { |
| 379 ASSERT(result->is_constant()); |
| 380 Push(result->handle()); |
| 381 } |
| 382 result->Unuse(); |
| 383 } |
358 | 384 |
359 // Nip removes zero or more elements from immediately below the top | 385 // Nip removes zero or more elements from immediately below the top |
360 // of the frame, leaving the previous top-of-frame value on top of | 386 // of the frame, leaving the previous top-of-frame value on top of |
361 // the frame. Nip(k) is equivalent to x = Pop(), Drop(k), Push(x). | 387 // the frame. Nip(k) is equivalent to x = Pop(), Drop(k), Push(x). |
362 void Nip(int num_dropped); | 388 void Nip(int num_dropped); |
363 | 389 |
364 private: | 390 private: |
365 static const int kLocal0Offset = JavaScriptFrameConstants::kLocal0Offset; | 391 static const int kLocal0Offset = JavaScriptFrameConstants::kLocal0Offset; |
366 static const int kFunctionOffset = JavaScriptFrameConstants::kFunctionOffset; | 392 static const int kFunctionOffset = JavaScriptFrameConstants::kFunctionOffset; |
367 static const int kContextOffset = StandardFrameConstants::kContextOffset; | 393 static const int kContextOffset = StandardFrameConstants::kContextOffset; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 | 446 |
421 // Convert a frame index into a frame pointer relative offset into the | 447 // Convert a frame index into a frame pointer relative offset into the |
422 // actual stack. | 448 // actual stack. |
423 int fp_relative(int index) const { | 449 int fp_relative(int index) const { |
424 return (frame_pointer_ - index) * kPointerSize; | 450 return (frame_pointer_ - index) * kPointerSize; |
425 } | 451 } |
426 | 452 |
427 // Record an occurrence of a register in the virtual frame. This has the | 453 // Record an occurrence of a register in the virtual frame. This has the |
428 // effect of incrementing the register's external reference count and | 454 // effect of incrementing the register's external reference count and |
429 // of updating the index of the register's location in the frame. | 455 // of updating the index of the register's location in the frame. |
430 void Use(Register reg, int index); | 456 void Use(Register reg, int index) { |
| 457 ASSERT(!is_used(reg)); |
| 458 register_locations_[reg.code()] = index; |
| 459 cgen_->allocator()->Use(reg); |
| 460 } |
431 | 461 |
432 // Record that a register reference has been dropped from the frame. This | 462 // Record that a register reference has been dropped from the frame. This |
433 // decrements the register's external reference count and invalidates the | 463 // decrements the register's external reference count and invalidates the |
434 // index of the register's location in the frame. | 464 // index of the register's location in the frame. |
435 void Unuse(Register reg); | 465 void Unuse(Register reg) { |
| 466 ASSERT(register_locations_[reg.code()] != kIllegalIndex); |
| 467 register_locations_[reg.code()] = kIllegalIndex; |
| 468 cgen_->allocator()->Unuse(reg); |
| 469 } |
436 | 470 |
437 // Spill the element at a particular index---write it to memory if | 471 // Spill the element at a particular index---write it to memory if |
438 // necessary, free any associated register, and forget its value if | 472 // necessary, free any associated register, and forget its value if |
439 // constant. | 473 // constant. |
440 void SpillElementAt(int index); | 474 void SpillElementAt(int index); |
441 | 475 |
442 // Sync the element at a particular index. If it is a register or | 476 // Sync the element at a particular index. If it is a register or |
443 // constant that disagrees with the value on the stack, write it to memory. | 477 // constant that disagrees with the value on the stack, write it to memory. |
444 // Keep the element type as register or constant, and clear the dirty bit. | 478 // Keep the element type as register or constant, and clear the dirty bit. |
445 void SyncElementAt(int index); | 479 void SyncElementAt(int index); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 Result RawCallCodeObject(Handle<Code> code, RelocInfo::Mode rmode); | 541 Result RawCallCodeObject(Handle<Code> code, RelocInfo::Mode rmode); |
508 | 542 |
509 bool Equals(VirtualFrame* other); | 543 bool Equals(VirtualFrame* other); |
510 | 544 |
511 friend class JumpTarget; | 545 friend class JumpTarget; |
512 }; | 546 }; |
513 | 547 |
514 } } // namespace v8::internal | 548 } } // namespace v8::internal |
515 | 549 |
516 #endif // V8_IA32_VIRTUAL_FRAME_IA32_H_ | 550 #endif // V8_IA32_VIRTUAL_FRAME_IA32_H_ |
OLD | NEW |