| OLD | NEW |
| 1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 cgen_->allocator()->Use(reg); | 132 cgen_->allocator()->Use(reg); |
| 133 } | 133 } |
| 134 | 134 |
| 135 | 135 |
| 136 void VirtualFrame::Unuse(Register reg) { | 136 void VirtualFrame::Unuse(Register reg) { |
| 137 frame_registers_.Unuse(reg); | 137 frame_registers_.Unuse(reg); |
| 138 cgen_->allocator()->Unuse(reg); | 138 cgen_->allocator()->Unuse(reg); |
| 139 } | 139 } |
| 140 | 140 |
| 141 | 141 |
| 142 // Clear the dirty bit for the element at a given index. We can only | 142 // Clear the dirty bit for the element at a given index. This requires |
| 143 // allocate space in the actual frame for the virtual element immediately | 143 // writing dirty elements to the actual frame. We can only allocate space |
| 144 // above the stack pointer. | 144 // in the actual frame for the virtual element immediately above the stack |
| 145 // pointer. |
| 145 void VirtualFrame::SyncElementAt(int index) { | 146 void VirtualFrame::SyncElementAt(int index) { |
| 146 FrameElement element = elements_[index]; | 147 FrameElement element = elements_[index]; |
| 147 | 148 |
| 148 if (!element.is_synced()) { | 149 if (!element.is_synced()) { |
| 149 if (index <= stack_pointer_) { | 150 if (index <= stack_pointer_) { |
| 150 // Write elements below the stack pointer to their (already allocated) | 151 // Write elements below the stack pointer to their (already allocated) |
| 151 // actual frame location. | 152 // actual frame location. |
| 152 if (element.is_constant()) { | 153 if (element.is_constant()) { |
| 153 __ Set(Operand(ebp, fp_relative(index)), Immediate(element.handle())); | 154 __ Set(Operand(ebp, fp_relative(index)), Immediate(element.handle())); |
| 154 } else { | 155 } else { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 i++; | 209 i++; |
| 209 } | 210 } |
| 210 } | 211 } |
| 211 | 212 |
| 212 ASSERT(cgen_->allocator()->count(best_register_code) == 0); | 213 ASSERT(cgen_->allocator()->count(best_register_code) == 0); |
| 213 Register result = { best_register_code }; | 214 Register result = { best_register_code }; |
| 214 return result; | 215 return result; |
| 215 } | 216 } |
| 216 | 217 |
| 217 | 218 |
| 219 // Spill an element, making its type be MEMORY. If it is a register the |
| 220 // reference count is not decremented, so it must be done externally. |
| 221 void VirtualFrame::RawSpillElementAt(int index) { |
| 222 if (index > stack_pointer_ + 1) { |
| 223 SyncRange(stack_pointer_ + 1, index); |
| 224 } |
| 225 SyncElementAt(index); |
| 226 // The element is now in memory. |
| 227 FrameElement memory_element; |
| 228 elements_[index] = memory_element; |
| 229 } |
| 230 |
| 231 |
| 218 // Make the type of the element at a given index be MEMORY. We can only | 232 // Make the type of the element at a given index be MEMORY. We can only |
| 219 // allocate space in the actual frame for the virtual element immediately | 233 // allocate space in the actual frame for the virtual element immediately |
| 220 // above the stack pointer. | 234 // above the stack pointer. |
| 221 void VirtualFrame::SpillElementAt(int index) { | 235 void VirtualFrame::SpillElementAt(int index) { |
| 222 if (index > stack_pointer_ + 1) { | |
| 223 SyncRange(stack_pointer_ + 1, index); | |
| 224 } | |
| 225 SyncElementAt(index); | |
| 226 // The element is now in memory. | |
| 227 if (elements_[index].is_register()) { | 236 if (elements_[index].is_register()) { |
| 228 Unuse(elements_[index].reg()); | 237 Unuse(elements_[index].reg()); |
| 229 } | 238 } |
| 230 elements_[index] = FrameElement(); | 239 RawSpillElementAt(index); |
| 231 } | 240 } |
| 232 | 241 |
| 233 | 242 |
| 234 // Clear the dirty bits for the range of elements in [begin, end). | 243 // Clear the dirty bits for the range of elements in [begin, end). |
| 235 void VirtualFrame::SyncRange(int begin, int end) { | 244 void VirtualFrame::SyncRange(int begin, int end) { |
| 236 ASSERT(begin >= 0); | 245 ASSERT(begin >= 0); |
| 237 ASSERT(end <= elements_.length()); | 246 ASSERT(end <= elements_.length()); |
| 238 for (int i = begin; i < end; i++) { | 247 for (int i = begin; i < end; i++) { |
| 239 SyncElementAt(i); | 248 SyncElementAt(i); |
| 240 } | 249 } |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 frame_registers_.Use(target.reg()); | 391 frame_registers_.Use(target.reg()); |
| 383 __ Set(target.reg(), Immediate(source.handle())); | 392 __ Set(target.reg(), Immediate(source.handle())); |
| 384 } else if (source.is_register() && !source.reg().is(target.reg())) { | 393 } else if (source.is_register() && !source.reg().is(target.reg())) { |
| 385 // The frame now owns the reference. | 394 // The frame now owns the reference. |
| 386 frame_registers_.Use(target.reg()); | 395 frame_registers_.Use(target.reg()); |
| 387 __ mov(target.reg(), source.reg()); | 396 __ mov(target.reg(), source.reg()); |
| 388 } | 397 } |
| 389 elements_[i] = target; | 398 elements_[i] = target; |
| 390 } else { | 399 } else { |
| 391 // The target is memory. | 400 // The target is memory. |
| 392 SpillElementAt(i); | 401 if (!source.is_memory()) { |
| 402 // Spilling a source register would decrement its reference count, |
| 403 // but we have already done that when computing new target elements, |
| 404 // so we use a raw spill. |
| 405 RawSpillElementAt(i); |
| 406 } |
| 393 } | 407 } |
| 394 } | 408 } |
| 395 | 409 |
| 396 delete[] new_elements; | 410 delete[] new_elements; |
| 397 } | 411 } |
| 398 | 412 |
| 399 | 413 |
| 400 void VirtualFrame::MergeTo(VirtualFrame* expected) { | 414 void VirtualFrame::MergeTo(VirtualFrame* expected) { |
| 401 Comment cmnt(masm_, "[ Merge frame"); | 415 Comment cmnt(masm_, "[ Merge frame"); |
| 402 ASSERT(cgen_ == expected->cgen_); | 416 ASSERT(cgen_ == expected->cgen_); |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 | 580 |
| 567 if (count > 0) { | 581 if (count > 0) { |
| 568 Comment cmnt(masm_, "[ Allocate space for locals"); | 582 Comment cmnt(masm_, "[ Allocate space for locals"); |
| 569 // The locals are initialized to a constant (the undefined value), but | 583 // The locals are initialized to a constant (the undefined value), but |
| 570 // we sync them with the actual frame to allocate space for spilling | 584 // we sync them with the actual frame to allocate space for spilling |
| 571 // them later. First sync everything above the stack pointer so we can | 585 // them later. First sync everything above the stack pointer so we can |
| 572 // use pushes to allocate and initialize the locals. | 586 // use pushes to allocate and initialize the locals. |
| 573 SyncRange(stack_pointer_ + 1, elements_.length()); | 587 SyncRange(stack_pointer_ + 1, elements_.length()); |
| 574 Handle<Object> undefined = Factory::undefined_value(); | 588 Handle<Object> undefined = Factory::undefined_value(); |
| 575 FrameElement initial_value(undefined, FrameElement::SYNCED); | 589 FrameElement initial_value(undefined, FrameElement::SYNCED); |
| 576 Register tmp = cgen_->allocator()->Allocate(); | 590 Register temp = cgen_->allocator()->Allocate(); |
| 577 __ Set(tmp, Immediate(undefined)); | 591 __ Set(temp, Immediate(undefined)); |
| 578 for (int i = 0; i < count; i++) { | 592 for (int i = 0; i < count; i++) { |
| 579 elements_.Add(initial_value); | 593 elements_.Add(initial_value); |
| 580 stack_pointer_++; | 594 stack_pointer_++; |
| 581 __ push(tmp); | 595 __ push(temp); |
| 582 } | 596 } |
| 583 cgen_->allocator()->Unuse(tmp); | 597 cgen_->allocator()->Unuse(temp); |
| 598 } |
| 599 } |
| 600 |
| 601 |
| 602 void VirtualFrame::LoadFrameSlotAt(int index) { |
| 603 ASSERT(index >= 0); |
| 604 ASSERT(index < elements_.length()); |
| 605 |
| 606 FrameElement element = elements_[index]; |
| 607 |
| 608 if (element.is_memory()) { |
| 609 ASSERT(index <= stack_pointer_); |
| 610 // Eagerly load memory elements into a register. The element at |
| 611 // the index and the new top of the frame are backed by the same |
| 612 // register location. |
| 613 Register temp = cgen_->allocator()->Allocate(); |
| 614 ASSERT(!temp.is(no_reg)); |
| 615 FrameElement new_element(temp, FrameElement::NOT_SYNCED); |
| 616 Use(temp); |
| 617 elements_[index] = new_element; |
| 618 Use(temp); |
| 619 elements_.Add(new_element); |
| 620 |
| 621 // Finally, move the element at the index into its new location. |
| 622 elements_[index].set_sync(); |
| 623 __ mov(temp, Operand(ebp, fp_relative(index))); |
| 624 |
| 625 cgen_->allocator()->Unuse(temp); |
| 626 } else { |
| 627 // For constants and registers, add a copy of the element to the |
| 628 // top of the frame. |
| 629 ASSERT(element.is_register() || element.is_constant()); |
| 630 if (element.is_register()) { |
| 631 Use(element.reg()); |
| 632 } |
| 633 elements_.Add(element); |
| 584 } | 634 } |
| 585 } | 635 } |
| 586 | 636 |
| 587 | 637 |
| 588 void VirtualFrame::StoreToFrameSlotAt(int index) { | 638 void VirtualFrame::StoreToFrameSlotAt(int index) { |
| 589 // Store the value on top of the frame to the virtual frame slot at a | 639 // Store the value on top of the frame to the virtual frame slot at a |
| 590 // given index. The value on top of the frame is left in place. | 640 // given index. The value on top of the frame is left in place. |
| 641 ASSERT(index >= 0); |
| 591 ASSERT(index < elements_.length()); | 642 ASSERT(index < elements_.length()); |
| 592 FrameElement top = elements_[elements_.length() - 1]; | 643 FrameElement top = elements_[elements_.length() - 1]; |
| 593 | 644 |
| 594 // The virtual frame slot is now of the same type and has the same value | |
| 595 // as the frame top. | |
| 596 if (elements_[index].is_register()) { | 645 if (elements_[index].is_register()) { |
| 597 Unuse(elements_[index].reg()); | 646 Unuse(elements_[index].reg()); |
| 598 } | 647 } |
| 648 // The virtual frame slot will be of the same type and have the same value |
| 649 // as the frame top. |
| 599 elements_[index] = top; | 650 elements_[index] = top; |
| 600 | 651 |
| 601 if (top.is_memory()) { | 652 if (top.is_memory()) { |
| 602 // Emit code to store memory values into the required frame slot. | 653 // Emit code to store memory values into the required frame slot. |
| 603 Register temp = cgen_->allocator()->Allocate(); | 654 Register temp = cgen_->allocator()->Allocate(); |
| 604 ASSERT(!temp.is(no_reg)); | 655 ASSERT(!temp.is(no_reg)); |
| 605 __ mov(temp, Top()); | 656 __ mov(temp, Top()); |
| 606 __ mov(Operand(ebp, fp_relative(index)), temp); | 657 __ mov(Operand(ebp, fp_relative(index)), temp); |
| 607 cgen_->allocator()->Unuse(temp); | 658 cgen_->allocator()->Unuse(temp); |
| 608 } else { | 659 } else { |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 789 return false; | 840 return false; |
| 790 } | 841 } |
| 791 } | 842 } |
| 792 return true; | 843 return true; |
| 793 } | 844 } |
| 794 #endif | 845 #endif |
| 795 | 846 |
| 796 #undef __ | 847 #undef __ |
| 797 | 848 |
| 798 } } // namespace v8::internal | 849 } } // namespace v8::internal |
| OLD | NEW |