OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 11 matching lines...) Expand all Loading... |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 #include "v8.h" | 28 #include "v8.h" |
29 | 29 |
30 #if defined(V8_TARGET_ARCH_X64) | 30 #if defined(V8_TARGET_ARCH_X64) |
31 | 31 |
| 32 #include "lithium-allocator-inl.h" |
32 #include "x64/lithium-x64.h" | 33 #include "x64/lithium-x64.h" |
33 #include "x64/lithium-codegen-x64.h" | 34 #include "x64/lithium-codegen-x64.h" |
34 | 35 |
35 namespace v8 { | 36 namespace v8 { |
36 namespace internal { | 37 namespace internal { |
37 | 38 |
38 #define DEFINE_COMPILE(type) \ | 39 #define DEFINE_COMPILE(type) \ |
39 void L##type::CompileToNative(LCodeGen* generator) { \ | 40 void L##type::CompileToNative(LCodeGen* generator) { \ |
40 generator->Do##type(this); \ | 41 generator->Do##type(this); \ |
41 } | 42 } |
(...skipping 19 matching lines...) Expand all Loading... |
61 | 62 |
62 | 63 |
63 void LOsrEntry::MarkSpilledDoubleRegister(int allocation_index, | 64 void LOsrEntry::MarkSpilledDoubleRegister(int allocation_index, |
64 LOperand* spill_operand) { | 65 LOperand* spill_operand) { |
65 ASSERT(spill_operand->IsDoubleStackSlot()); | 66 ASSERT(spill_operand->IsDoubleStackSlot()); |
66 ASSERT(double_register_spills_[allocation_index] == NULL); | 67 ASSERT(double_register_spills_[allocation_index] == NULL); |
67 double_register_spills_[allocation_index] = spill_operand; | 68 double_register_spills_[allocation_index] = spill_operand; |
68 } | 69 } |
69 | 70 |
70 | 71 |
| 72 #ifdef DEBUG |
| 73 void LInstruction::VerifyCall() { |
| 74 // Call instructions can use only fixed registers as |
| 75 // temporaries and outputs because all registers |
| 76 // are blocked by the calling convention. |
| 77 // Inputs can use either fixed register or have a short lifetime (be |
| 78 // used at start of the instruction). |
| 79 ASSERT(Output() == NULL || |
| 80 LUnallocated::cast(Output())->HasFixedPolicy() || |
| 81 !LUnallocated::cast(Output())->HasRegisterPolicy()); |
| 82 for (UseIterator it(this); it.HasNext(); it.Advance()) { |
| 83 LOperand* operand = it.Next(); |
| 84 ASSERT(LUnallocated::cast(operand)->HasFixedPolicy() || |
| 85 LUnallocated::cast(operand)->IsUsedAtStart() || |
| 86 !LUnallocated::cast(operand)->HasRegisterPolicy()); |
| 87 } |
| 88 for (TempIterator it(this); it.HasNext(); it.Advance()) { |
| 89 LOperand* operand = it.Next(); |
| 90 ASSERT(LUnallocated::cast(operand)->HasFixedPolicy() || |
| 91 !LUnallocated::cast(operand)->HasRegisterPolicy()); |
| 92 } |
| 93 } |
| 94 #endif |
| 95 |
| 96 |
71 void LInstruction::PrintTo(StringStream* stream) { | 97 void LInstruction::PrintTo(StringStream* stream) { |
72 stream->Add("%s ", this->Mnemonic()); | 98 stream->Add("%s ", this->Mnemonic()); |
73 if (HasResult()) { | 99 |
74 PrintOutputOperandTo(stream); | 100 PrintOutputOperandTo(stream); |
75 } | |
76 | 101 |
77 PrintDataTo(stream); | 102 PrintDataTo(stream); |
78 | 103 |
79 if (HasEnvironment()) { | 104 if (HasEnvironment()) { |
80 stream->Add(" "); | 105 stream->Add(" "); |
81 environment()->PrintTo(stream); | 106 environment()->PrintTo(stream); |
82 } | 107 } |
83 | 108 |
84 if (HasPointerMap()) { | 109 if (HasPointerMap()) { |
85 stream->Add(" "); | 110 stream->Add(" "); |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 | 404 |
380 void LStoreKeyed::PrintDataTo(StringStream* stream) { | 405 void LStoreKeyed::PrintDataTo(StringStream* stream) { |
381 object()->PrintTo(stream); | 406 object()->PrintTo(stream); |
382 stream->Add("["); | 407 stream->Add("["); |
383 key()->PrintTo(stream); | 408 key()->PrintTo(stream); |
384 stream->Add("] <- "); | 409 stream->Add("] <- "); |
385 value()->PrintTo(stream); | 410 value()->PrintTo(stream); |
386 } | 411 } |
387 | 412 |
388 | 413 |
389 int LChunk::AddInstruction(LInstruction* instr, HBasicBlock* block) { | 414 void LChunk::AddInstruction(LInstruction* instr, HBasicBlock* block) { |
390 LGap* gap = new LGap(block); | 415 LGap* gap = new LGap(block); |
391 int index = -1; | 416 int index = -1; |
392 if (instr->IsControl()) { | 417 if (instr->IsControl()) { |
393 instructions_.Add(gap); | 418 instructions_.Add(gap); |
394 index = instructions_.length(); | 419 index = instructions_.length(); |
395 instructions_.Add(instr); | 420 instructions_.Add(instr); |
396 } else { | 421 } else { |
397 index = instructions_.length(); | 422 index = instructions_.length(); |
398 instructions_.Add(instr); | 423 instructions_.Add(instr); |
399 instructions_.Add(gap); | 424 instructions_.Add(gap); |
400 } | 425 } |
401 if (instr->HasPointerMap()) { | 426 if (instr->HasPointerMap()) { |
402 pointer_maps_.Add(instr->pointer_map()); | 427 pointer_maps_.Add(instr->pointer_map()); |
403 instr->pointer_map()->set_lithium_position(index); | 428 instr->pointer_map()->set_lithium_position(index); |
404 } | 429 } |
405 return index; | |
406 } | 430 } |
407 | 431 |
408 | 432 |
409 LConstantOperand* LChunk::DefineConstantOperand(HConstant* constant) { | 433 LConstantOperand* LChunk::DefineConstantOperand(HConstant* constant) { |
410 return LConstantOperand::Create(constant->id()); | 434 return LConstantOperand::Create(constant->id()); |
411 } | 435 } |
412 | 436 |
413 | 437 |
414 int LChunk::GetParameterStackSlot(int index) const { | 438 int LChunk::GetParameterStackSlot(int index) const { |
415 // The receiver is at index 0, the first parameter at index 1, so we | 439 // The receiver is at index 0, the first parameter at index 1, so we |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 LInstruction* LChunkBuilder::AssignEnvironment(LInstruction* instr) { | 671 LInstruction* LChunkBuilder::AssignEnvironment(LInstruction* instr) { |
648 HEnvironment* hydrogen_env = current_block_->last_environment(); | 672 HEnvironment* hydrogen_env = current_block_->last_environment(); |
649 instr->set_environment(CreateEnvironment(hydrogen_env)); | 673 instr->set_environment(CreateEnvironment(hydrogen_env)); |
650 return instr; | 674 return instr; |
651 } | 675 } |
652 | 676 |
653 | 677 |
654 LInstruction* LChunkBuilder::MarkAsCall(LInstruction* instr, | 678 LInstruction* LChunkBuilder::MarkAsCall(LInstruction* instr, |
655 HInstruction* hinstr, | 679 HInstruction* hinstr, |
656 CanDeoptimize can_deoptimize) { | 680 CanDeoptimize can_deoptimize) { |
657 allocator_->MarkAsCall(); | 681 #ifdef DEBUG |
| 682 instr->VerifyCall(); |
| 683 #endif |
| 684 instr->MarkAsCall(); |
658 instr = AssignPointerMap(instr); | 685 instr = AssignPointerMap(instr); |
659 | 686 |
660 if (hinstr->HasSideEffects()) { | 687 if (hinstr->HasSideEffects()) { |
661 ASSERT(hinstr->next()->IsSimulate()); | 688 ASSERT(hinstr->next()->IsSimulate()); |
662 HSimulate* sim = HSimulate::cast(hinstr->next()); | 689 HSimulate* sim = HSimulate::cast(hinstr->next()); |
663 ASSERT(pending_deoptimization_ast_id_ == AstNode::kNoNumber); | 690 ASSERT(pending_deoptimization_ast_id_ == AstNode::kNoNumber); |
664 pending_deoptimization_ast_id_ = sim->ast_id(); | 691 pending_deoptimization_ast_id_ = sim->ast_id(); |
665 } | 692 } |
666 | 693 |
667 // If instruction does not have side-effects lazy deoptimization | 694 // If instruction does not have side-effects lazy deoptimization |
668 // after the call will try to deoptimize to the point before the call. | 695 // after the call will try to deoptimize to the point before the call. |
669 // Thus we still need to attach environment to this call even if | 696 // Thus we still need to attach environment to this call even if |
670 // call sequence can not deoptimize eagerly. | 697 // call sequence can not deoptimize eagerly. |
671 bool needs_environment = | 698 bool needs_environment = |
672 (can_deoptimize == CAN_DEOPTIMIZE_EAGERLY) || !hinstr->HasSideEffects(); | 699 (can_deoptimize == CAN_DEOPTIMIZE_EAGERLY) || !hinstr->HasSideEffects(); |
673 if (needs_environment && !instr->HasEnvironment()) { | 700 if (needs_environment && !instr->HasEnvironment()) { |
674 instr = AssignEnvironment(instr); | 701 instr = AssignEnvironment(instr); |
675 } | 702 } |
676 | 703 |
677 return instr; | 704 return instr; |
678 } | 705 } |
679 | 706 |
680 | 707 |
681 LInstruction* LChunkBuilder::MarkAsSaveDoubles(LInstruction* instr) { | 708 LInstruction* LChunkBuilder::MarkAsSaveDoubles(LInstruction* instr) { |
682 allocator_->MarkAsSaveDoubles(); | 709 instr->MarkAsSaveDoubles(); |
683 return instr; | 710 return instr; |
684 } | 711 } |
685 | 712 |
686 | 713 |
687 LInstruction* LChunkBuilder::AssignPointerMap(LInstruction* instr) { | 714 LInstruction* LChunkBuilder::AssignPointerMap(LInstruction* instr) { |
688 ASSERT(!instr->HasPointerMap()); | 715 ASSERT(!instr->HasPointerMap()); |
689 instr->set_pointer_map(new LPointerMap(position_)); | 716 instr->set_pointer_map(new LPointerMap(position_)); |
690 return instr; | 717 return instr; |
691 } | 718 } |
692 | 719 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
813 } | 840 } |
814 block->set_argument_count(argument_count_); | 841 block->set_argument_count(argument_count_); |
815 next_block_ = NULL; | 842 next_block_ = NULL; |
816 current_block_ = NULL; | 843 current_block_ = NULL; |
817 } | 844 } |
818 | 845 |
819 | 846 |
820 void LChunkBuilder::VisitInstruction(HInstruction* current) { | 847 void LChunkBuilder::VisitInstruction(HInstruction* current) { |
821 HInstruction* old_current = current_instruction_; | 848 HInstruction* old_current = current_instruction_; |
822 current_instruction_ = current; | 849 current_instruction_ = current; |
823 allocator_->BeginInstruction(); | |
824 if (current->has_position()) position_ = current->position(); | 850 if (current->has_position()) position_ = current->position(); |
825 LInstruction* instr = current->CompileToLithium(this); | 851 LInstruction* instr = current->CompileToLithium(this); |
826 | 852 |
827 if (instr != NULL) { | 853 if (instr != NULL) { |
828 if (FLAG_stress_pointer_maps && !instr->HasPointerMap()) { | 854 if (FLAG_stress_pointer_maps && !instr->HasPointerMap()) { |
829 instr = AssignPointerMap(instr); | 855 instr = AssignPointerMap(instr); |
830 } | 856 } |
831 if (FLAG_stress_environments && !instr->HasEnvironment()) { | 857 if (FLAG_stress_environments && !instr->HasEnvironment()) { |
832 instr = AssignEnvironment(instr); | 858 instr = AssignEnvironment(instr); |
833 } | 859 } |
834 if (current->IsTest() && !instr->IsGoto()) { | 860 if (current->IsTest() && !instr->IsGoto()) { |
835 ASSERT(instr->IsControl()); | 861 ASSERT(instr->IsControl()); |
836 HTest* test = HTest::cast(current); | 862 HTest* test = HTest::cast(current); |
837 instr->set_hydrogen_value(test->value()); | 863 instr->set_hydrogen_value(test->value()); |
838 HBasicBlock* first = test->FirstSuccessor(); | 864 HBasicBlock* first = test->FirstSuccessor(); |
839 HBasicBlock* second = test->SecondSuccessor(); | 865 HBasicBlock* second = test->SecondSuccessor(); |
840 ASSERT(first != NULL && second != NULL); | 866 ASSERT(first != NULL && second != NULL); |
841 instr->SetBranchTargets(first->block_id(), second->block_id()); | 867 instr->SetBranchTargets(first->block_id(), second->block_id()); |
842 } else { | 868 } else { |
843 instr->set_hydrogen_value(current); | 869 instr->set_hydrogen_value(current); |
844 } | 870 } |
845 | 871 |
846 int index = chunk_->AddInstruction(instr, current_block_); | 872 chunk_->AddInstruction(instr, current_block_); |
847 allocator_->SummarizeInstruction(index); | |
848 } else { | |
849 // This instruction should be omitted. | |
850 allocator_->OmitInstruction(); | |
851 } | 873 } |
852 current_instruction_ = old_current; | 874 current_instruction_ = old_current; |
853 } | 875 } |
854 | 876 |
855 | 877 |
856 LEnvironment* LChunkBuilder::CreateEnvironment(HEnvironment* hydrogen_env) { | 878 LEnvironment* LChunkBuilder::CreateEnvironment(HEnvironment* hydrogen_env) { |
857 if (hydrogen_env == NULL) return NULL; | 879 if (hydrogen_env == NULL) return NULL; |
858 | 880 |
859 LEnvironment* outer = CreateEnvironment(hydrogen_env->outer()); | 881 LEnvironment* outer = CreateEnvironment(hydrogen_env->outer()); |
860 int ast_id = hydrogen_env->ast_id(); | 882 int ast_id = hydrogen_env->ast_id(); |
(...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1655 | 1677 |
1656 | 1678 |
1657 LInstruction* LChunkBuilder::DoLeaveInlined(HLeaveInlined* instr) { | 1679 LInstruction* LChunkBuilder::DoLeaveInlined(HLeaveInlined* instr) { |
1658 Abort("Unimplemented: %s", "DoLeaveInlined"); | 1680 Abort("Unimplemented: %s", "DoLeaveInlined"); |
1659 return NULL; | 1681 return NULL; |
1660 } | 1682 } |
1661 | 1683 |
1662 } } // namespace v8::internal | 1684 } } // namespace v8::internal |
1663 | 1685 |
1664 #endif // V8_TARGET_ARCH_X64 | 1686 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |