| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 |
| 11 // with the distribution. | 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
| 15 // | 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 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 "lithium-allocator.h" | 28 #include "lithium-allocator.h" |
| 29 | 29 |
| 30 #include "data-flow.h" | |
| 31 #include "hydrogen.h" | 30 #include "hydrogen.h" |
| 32 #include "string-stream.h" | 31 #include "string-stream.h" |
| 33 | 32 |
| 34 #if V8_TARGET_ARCH_IA32 | 33 #if V8_TARGET_ARCH_IA32 |
| 35 #include "ia32/lithium-ia32.h" | 34 #include "ia32/lithium-ia32.h" |
| 36 #elif V8_TARGET_ARCH_X64 | 35 #elif V8_TARGET_ARCH_X64 |
| 37 #include "x64/lithium-x64.h" | 36 #include "x64/lithium-x64.h" |
| 38 #elif V8_TARGET_ARCH_ARM | 37 #elif V8_TARGET_ARCH_ARM |
| 39 #include "arm/lithium-arm.h" | 38 #include "arm/lithium-arm.h" |
| 40 #else | 39 #else |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 break; | 99 break; |
| 101 case LUnallocated::MUST_HAVE_REGISTER: | 100 case LUnallocated::MUST_HAVE_REGISTER: |
| 102 stream->Add("(R)"); | 101 stream->Add("(R)"); |
| 103 break; | 102 break; |
| 104 case LUnallocated::WRITABLE_REGISTER: | 103 case LUnallocated::WRITABLE_REGISTER: |
| 105 stream->Add("(WR)"); | 104 stream->Add("(WR)"); |
| 106 break; | 105 break; |
| 107 case LUnallocated::SAME_AS_FIRST_INPUT: | 106 case LUnallocated::SAME_AS_FIRST_INPUT: |
| 108 stream->Add("(1)"); | 107 stream->Add("(1)"); |
| 109 break; | 108 break; |
| 110 case LUnallocated::SAME_AS_ANY_INPUT: | |
| 111 stream->Add("(A)"); | |
| 112 break; | |
| 113 case LUnallocated::ANY: | 109 case LUnallocated::ANY: |
| 114 stream->Add("(-)"); | 110 stream->Add("(-)"); |
| 115 break; | 111 break; |
| 116 case LUnallocated::IGNORE: | 112 case LUnallocated::IGNORE: |
| 117 stream->Add("(0)"); | 113 stream->Add("(0)"); |
| 118 break; | 114 break; |
| 119 } | 115 } |
| 120 break; | 116 break; |
| 121 case CONSTANT_OPERAND: | 117 case CONSTANT_OPERAND: |
| 122 stream->Add("[constant:%d]", index()); | 118 stream->Add("[constant:%d]", index()); |
| (...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 827 for (int i = 0; i < second->InputCount(); ++i) { | 823 for (int i = 0; i < second->InputCount(); ++i) { |
| 828 LUnallocated* cur_input = LUnallocated::cast(second->InputAt(i)); | 824 LUnallocated* cur_input = LUnallocated::cast(second->InputAt(i)); |
| 829 if (cur_input->HasFixedPolicy()) { | 825 if (cur_input->HasFixedPolicy()) { |
| 830 LUnallocated* input_copy = cur_input->CopyUnconstrained(); | 826 LUnallocated* input_copy = cur_input->CopyUnconstrained(); |
| 831 bool is_tagged = HasTaggedValue(cur_input->VirtualRegister()); | 827 bool is_tagged = HasTaggedValue(cur_input->VirtualRegister()); |
| 832 AllocateFixed(cur_input, gap_index + 1, is_tagged); | 828 AllocateFixed(cur_input, gap_index + 1, is_tagged); |
| 833 AddConstraintsGapMove(gap_index, input_copy, cur_input); | 829 AddConstraintsGapMove(gap_index, input_copy, cur_input); |
| 834 } else if (cur_input->policy() == LUnallocated::WRITABLE_REGISTER) { | 830 } else if (cur_input->policy() == LUnallocated::WRITABLE_REGISTER) { |
| 835 LUnallocated* input_copy = cur_input->CopyUnconstrained(); | 831 LUnallocated* input_copy = cur_input->CopyUnconstrained(); |
| 836 cur_input->set_virtual_register(next_virtual_register_++); | 832 cur_input->set_virtual_register(next_virtual_register_++); |
| 833 |
| 834 if (RequiredRegisterKind(input_copy->virtual_register()) == |
| 835 DOUBLE_REGISTERS) { |
| 836 double_artificial_registers_.Add( |
| 837 cur_input->virtual_register() - first_artificial_register_); |
| 838 } |
| 839 |
| 837 second->AddTemp(cur_input); | 840 second->AddTemp(cur_input); |
| 838 AddConstraintsGapMove(gap_index, input_copy, cur_input); | 841 AddConstraintsGapMove(gap_index, input_copy, cur_input); |
| 839 } | 842 } |
| 840 } | 843 } |
| 841 } | 844 } |
| 842 | 845 |
| 843 // Handle "output same as input" for second instruction. | 846 // Handle "output same as input" for second instruction. |
| 844 if (second != NULL && second->Output() != NULL) { | 847 if (second != NULL && second->Output() != NULL) { |
| 845 LUnallocated* second_output = LUnallocated::cast(second->Output()); | 848 LUnallocated* second_output = LUnallocated::cast(second->Output()); |
| 846 if (second_output->HasSameAsInputPolicy()) { | 849 if (second_output->HasSameAsInputPolicy()) { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 930 | 933 |
| 931 if (summary->IsCall()) { | 934 if (summary->IsCall()) { |
| 932 for (int i = 0; i < Register::kNumAllocatableRegisters; ++i) { | 935 for (int i = 0; i < Register::kNumAllocatableRegisters; ++i) { |
| 933 if (output == NULL || !output->IsRegister() || | 936 if (output == NULL || !output->IsRegister() || |
| 934 output->index() != i) { | 937 output->index() != i) { |
| 935 LiveRange* range = FixedLiveRangeFor(i); | 938 LiveRange* range = FixedLiveRangeFor(i); |
| 936 range->AddUseInterval(curr_position, | 939 range->AddUseInterval(curr_position, |
| 937 curr_position.InstructionEnd()); | 940 curr_position.InstructionEnd()); |
| 938 } | 941 } |
| 939 } | 942 } |
| 943 } |
| 944 |
| 945 if (summary->IsCall() || summary->IsSaveDoubles()) { |
| 940 for (int i = 0; i < DoubleRegister::kNumAllocatableRegisters; ++i) { | 946 for (int i = 0; i < DoubleRegister::kNumAllocatableRegisters; ++i) { |
| 941 if (output == NULL || !output->IsDoubleRegister() || | 947 if (output == NULL || !output->IsDoubleRegister() || |
| 942 output->index() != i) { | 948 output->index() != i) { |
| 943 LiveRange* range = FixedDoubleLiveRangeFor(i); | 949 LiveRange* range = FixedDoubleLiveRangeFor(i); |
| 944 range->AddUseInterval(curr_position, | 950 range->AddUseInterval(curr_position, |
| 945 curr_position.InstructionEnd()); | 951 curr_position.InstructionEnd()); |
| 946 } | 952 } |
| 947 } | 953 } |
| 948 } | 954 } |
| 949 | 955 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1029 AllocateDoubleRegisters(); | 1035 AllocateDoubleRegisters(); |
| 1030 PopulatePointerMaps(); | 1036 PopulatePointerMaps(); |
| 1031 if (has_osr_entry_) ProcessOsrEntry(); | 1037 if (has_osr_entry_) ProcessOsrEntry(); |
| 1032 ConnectRanges(); | 1038 ConnectRanges(); |
| 1033 ResolveControlFlow(); | 1039 ResolveControlFlow(); |
| 1034 } | 1040 } |
| 1035 | 1041 |
| 1036 | 1042 |
| 1037 void LAllocator::MeetRegisterConstraints() { | 1043 void LAllocator::MeetRegisterConstraints() { |
| 1038 HPhase phase("Register constraints", chunk()); | 1044 HPhase phase("Register constraints", chunk()); |
| 1045 first_artificial_register_ = next_virtual_register_; |
| 1039 const ZoneList<HBasicBlock*>* blocks = graph()->blocks(); | 1046 const ZoneList<HBasicBlock*>* blocks = graph()->blocks(); |
| 1040 for (int i = 0; i < blocks->length(); ++i) { | 1047 for (int i = 0; i < blocks->length(); ++i) { |
| 1041 HBasicBlock* block = blocks->at(i); | 1048 HBasicBlock* block = blocks->at(i); |
| 1042 MeetRegisterConstraints(block); | 1049 MeetRegisterConstraints(block); |
| 1043 } | 1050 } |
| 1044 } | 1051 } |
| 1045 | 1052 |
| 1046 | 1053 |
| 1047 void LAllocator::ResolvePhis() { | 1054 void LAllocator::ResolvePhis() { |
| 1048 HPhase phase("Resolve phis", chunk()); | 1055 HPhase phase("Resolve phis", chunk()); |
| (...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1557 | 1564 |
| 1558 | 1565 |
| 1559 bool LAllocator::HasTaggedValue(int virtual_register) const { | 1566 bool LAllocator::HasTaggedValue(int virtual_register) const { |
| 1560 HValue* value = graph()->LookupValue(virtual_register); | 1567 HValue* value = graph()->LookupValue(virtual_register); |
| 1561 if (value == NULL) return false; | 1568 if (value == NULL) return false; |
| 1562 return value->representation().IsTagged(); | 1569 return value->representation().IsTagged(); |
| 1563 } | 1570 } |
| 1564 | 1571 |
| 1565 | 1572 |
| 1566 RegisterKind LAllocator::RequiredRegisterKind(int virtual_register) const { | 1573 RegisterKind LAllocator::RequiredRegisterKind(int virtual_register) const { |
| 1567 HValue* value = graph()->LookupValue(virtual_register); | 1574 if (virtual_register < first_artificial_register_) { |
| 1568 if (value != NULL && value->representation().IsDouble()) { | 1575 HValue* value = graph()->LookupValue(virtual_register); |
| 1576 if (value != NULL && value->representation().IsDouble()) { |
| 1577 return DOUBLE_REGISTERS; |
| 1578 } |
| 1579 } else if (double_artificial_registers_.Contains( |
| 1580 virtual_register - first_artificial_register_)) { |
| 1569 return DOUBLE_REGISTERS; | 1581 return DOUBLE_REGISTERS; |
| 1570 } | 1582 } |
| 1583 |
| 1571 return GENERAL_REGISTERS; | 1584 return GENERAL_REGISTERS; |
| 1572 } | 1585 } |
| 1573 | 1586 |
| 1574 | 1587 |
| 1575 void LAllocator::MarkAsCall() { | 1588 void LAllocator::MarkAsCall() { |
| 1576 current_summary()->MarkAsCall(); | 1589 // Call instructions can use only fixed registers as |
| 1590 // temporaries and outputs because all registers |
| 1591 // are blocked by the calling convention. |
| 1592 // Inputs can use either fixed register or have a short lifetime (be |
| 1593 // used at start of the instruction). |
| 1594 InstructionSummary* summary = current_summary(); |
| 1595 #ifdef DEBUG |
| 1596 ASSERT(summary->Output() == NULL || |
| 1597 LUnallocated::cast(summary->Output())->HasFixedPolicy() || |
| 1598 !LUnallocated::cast(summary->Output())->HasRegisterPolicy()); |
| 1599 for (int i = 0; i < summary->InputCount(); i++) { |
| 1600 ASSERT(LUnallocated::cast(summary->InputAt(i))->HasFixedPolicy() || |
| 1601 LUnallocated::cast(summary->InputAt(i))->IsUsedAtStart() || |
| 1602 !LUnallocated::cast(summary->InputAt(i))->HasRegisterPolicy()); |
| 1603 } |
| 1604 for (int i = 0; i < summary->TempCount(); i++) { |
| 1605 ASSERT(LUnallocated::cast(summary->TempAt(i))->HasFixedPolicy() || |
| 1606 !LUnallocated::cast(summary->TempAt(i))->HasRegisterPolicy()); |
| 1607 } |
| 1608 #endif |
| 1609 summary->MarkAsCall(); |
| 1610 } |
| 1611 |
| 1612 |
| 1613 void LAllocator::MarkAsSaveDoubles() { |
| 1614 current_summary()->MarkAsSaveDoubles(); |
| 1577 } | 1615 } |
| 1578 | 1616 |
| 1579 | 1617 |
| 1580 void LAllocator::RecordDefinition(HInstruction* instr, LUnallocated* operand) { | 1618 void LAllocator::RecordDefinition(HInstruction* instr, LUnallocated* operand) { |
| 1581 operand->set_virtual_register(instr->id()); | 1619 operand->set_virtual_register(instr->id()); |
| 1582 current_summary()->SetOutput(operand); | 1620 current_summary()->SetOutput(operand); |
| 1583 } | 1621 } |
| 1584 | 1622 |
| 1585 | 1623 |
| 1586 void LAllocator::RecordTemporary(LUnallocated* operand) { | 1624 void LAllocator::RecordTemporary(LUnallocated* operand) { |
| (...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2107 LiveRange* current = live_ranges()->at(i); | 2145 LiveRange* current = live_ranges()->at(i); |
| 2108 if (current != NULL) current->Verify(); | 2146 if (current != NULL) current->Verify(); |
| 2109 } | 2147 } |
| 2110 } | 2148 } |
| 2111 | 2149 |
| 2112 | 2150 |
| 2113 #endif | 2151 #endif |
| 2114 | 2152 |
| 2115 | 2153 |
| 2116 } } // namespace v8::internal | 2154 } } // namespace v8::internal |
| OLD | NEW |