OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/base/adapters.h" | 5 #include "src/base/adapters.h" |
6 #include "src/compiler/linkage.h" | 6 #include "src/compiler/linkage.h" |
7 #include "src/compiler/register-allocator.h" | 7 #include "src/compiler/register-allocator.h" |
8 #include "src/string-stream.h" | 8 #include "src/string-stream.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 LifetimePosition pos) { | 57 LifetimePosition pos) { |
58 return code->GetInstructionBlock(pos.ToInstructionIndex()); | 58 return code->GetInstructionBlock(pos.ToInstructionIndex()); |
59 } | 59 } |
60 | 60 |
61 | 61 |
62 Instruction* GetLastInstruction(InstructionSequence* code, | 62 Instruction* GetLastInstruction(InstructionSequence* code, |
63 const InstructionBlock* block) { | 63 const InstructionBlock* block) { |
64 return code->InstructionAt(block->last_instruction_index()); | 64 return code->InstructionAt(block->last_instruction_index()); |
65 } | 65 } |
66 | 66 |
67 bool IsOutputRegisterOf(Instruction* instr, int code) { | |
68 for (size_t i = 0; i < instr->OutputCount(); i++) { | |
69 InstructionOperand* output = instr->OutputAt(i); | |
70 if (output->IsRegister() && | |
71 LocationOperand::cast(output)->register_code() == code) { | |
72 return true; | |
73 } | |
74 } | |
75 return false; | |
76 } | |
77 | |
78 bool IsOutputFPRegisterOf(Instruction* instr, MachineRepresentation rep, | |
79 int code) { | |
80 for (size_t i = 0; i < instr->OutputCount(); i++) { | |
81 InstructionOperand* output = instr->OutputAt(i); | |
82 if (output->IsFPRegister()) { | |
83 const LocationOperand* op = LocationOperand::cast(output); | |
84 if (kSimpleFPAliasing) { | |
85 if (op->register_code() == code) return true; | |
86 } else { | |
87 if (RegisterConfiguration::Turbofan()->AreAliases( | |
88 op->representation(), op->register_code(), rep, code)) { | |
89 return true; | |
90 } | |
91 } | |
92 } | |
93 } | |
94 return false; | |
95 } | |
96 | |
97 | |
98 // TODO(dcarney): fix frame to allow frame accesses to half size location. | 67 // TODO(dcarney): fix frame to allow frame accesses to half size location. |
99 int GetByteWidth(MachineRepresentation rep) { | 68 int GetByteWidth(MachineRepresentation rep) { |
100 switch (rep) { | 69 switch (rep) { |
101 case MachineRepresentation::kBit: | 70 case MachineRepresentation::kBit: |
102 case MachineRepresentation::kWord8: | 71 case MachineRepresentation::kWord8: |
103 case MachineRepresentation::kWord16: | 72 case MachineRepresentation::kWord16: |
104 case MachineRepresentation::kWord32: | 73 case MachineRepresentation::kWord32: |
105 case MachineRepresentation::kTagged: | 74 case MachineRepresentation::kTagged: |
106 return kPointerSize; | 75 return kPointerSize; |
107 case MachineRepresentation::kFloat32: | 76 case MachineRepresentation::kFloat32: |
(...skipping 1935 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2043 // TODO(mtrofin): should we explore an explicit opcode for | 2012 // TODO(mtrofin): should we explore an explicit opcode for |
2044 // the first instruction in the handler? | 2013 // the first instruction in the handler? |
2045 Define(LifetimePosition::GapFromInstructionIndex(index), output); | 2014 Define(LifetimePosition::GapFromInstructionIndex(index), output); |
2046 } else { | 2015 } else { |
2047 Define(curr_position, output); | 2016 Define(curr_position, output); |
2048 } | 2017 } |
2049 } | 2018 } |
2050 | 2019 |
2051 if (instr->ClobbersRegisters()) { | 2020 if (instr->ClobbersRegisters()) { |
2052 for (int i = 0; i < config()->num_allocatable_general_registers(); ++i) { | 2021 for (int i = 0; i < config()->num_allocatable_general_registers(); ++i) { |
| 2022 // Create a UseInterval at this instruction for all fixed registers, |
| 2023 // (including the instruction outputs). Adding another UseInterval here |
| 2024 // is OK because AddUseInterval will just merge it with the existing |
| 2025 // one at the end of the range. |
2053 int code = config()->GetAllocatableGeneralCode(i); | 2026 int code = config()->GetAllocatableGeneralCode(i); |
2054 if (!IsOutputRegisterOf(instr, code)) { | 2027 TopLevelLiveRange* range = FixedLiveRangeFor(code); |
2055 TopLevelLiveRange* range = FixedLiveRangeFor(code); | 2028 range->AddUseInterval(curr_position, curr_position.End(), |
| 2029 allocation_zone()); |
| 2030 } |
| 2031 } |
| 2032 |
| 2033 if (instr->ClobbersDoubleRegisters()) { |
| 2034 for (int i = 0; i < config()->num_allocatable_double_registers(); ++i) { |
| 2035 // Add a UseInterval for all DoubleRegisters. See comment above for |
| 2036 // general registers. |
| 2037 int code = config()->GetAllocatableDoubleCode(i); |
| 2038 TopLevelLiveRange* range = |
| 2039 FixedFPLiveRangeFor(code, MachineRepresentation::kFloat64); |
| 2040 range->AddUseInterval(curr_position, curr_position.End(), |
| 2041 allocation_zone()); |
| 2042 } |
| 2043 // Preserve fixed float registers on archs with non-simple aliasing. |
| 2044 if (!kSimpleFPAliasing) { |
| 2045 for (int i = 0; i < config()->num_allocatable_float_registers(); ++i) { |
| 2046 // Add a UseInterval for all FloatRegisters. See comment above for |
| 2047 // general registers. |
| 2048 int code = config()->GetAllocatableFloatCode(i); |
| 2049 TopLevelLiveRange* range = |
| 2050 FixedFPLiveRangeFor(code, MachineRepresentation::kFloat32); |
2056 range->AddUseInterval(curr_position, curr_position.End(), | 2051 range->AddUseInterval(curr_position, curr_position.End(), |
2057 allocation_zone()); | 2052 allocation_zone()); |
2058 } | 2053 } |
2059 } | 2054 } |
2060 } | 2055 } |
2061 | |
2062 if (instr->ClobbersDoubleRegisters()) { | |
2063 for (int i = 0; i < config()->num_allocatable_double_registers(); ++i) { | |
2064 int code = config()->GetAllocatableDoubleCode(i); | |
2065 if (!IsOutputFPRegisterOf(instr, MachineRepresentation::kFloat64, | |
2066 code)) { | |
2067 TopLevelLiveRange* range = | |
2068 FixedFPLiveRangeFor(code, MachineRepresentation::kFloat64); | |
2069 range->AddUseInterval(curr_position, curr_position.End(), | |
2070 allocation_zone()); | |
2071 } | |
2072 } | |
2073 // Preserve fixed float registers on archs with non-simple aliasing. | |
2074 if (!kSimpleFPAliasing) { | |
2075 for (int i = 0; i < config()->num_allocatable_float_registers(); ++i) { | |
2076 int code = config()->GetAllocatableFloatCode(i); | |
2077 if (!IsOutputFPRegisterOf(instr, MachineRepresentation::kFloat32, | |
2078 code)) { | |
2079 TopLevelLiveRange* range = | |
2080 FixedFPLiveRangeFor(code, MachineRepresentation::kFloat32); | |
2081 range->AddUseInterval(curr_position, curr_position.End(), | |
2082 allocation_zone()); | |
2083 } | |
2084 } | |
2085 } | |
2086 } | |
2087 | 2056 |
2088 for (size_t i = 0; i < instr->InputCount(); i++) { | 2057 for (size_t i = 0; i < instr->InputCount(); i++) { |
2089 InstructionOperand* input = instr->InputAt(i); | 2058 InstructionOperand* input = instr->InputAt(i); |
2090 if (input->IsImmediate() || input->IsExplicit()) { | 2059 if (input->IsImmediate() || input->IsExplicit()) { |
2091 continue; // Ignore immediates and explicitly reserved registers. | 2060 continue; // Ignore immediates and explicitly reserved registers. |
2092 } | 2061 } |
2093 LifetimePosition use_pos; | 2062 LifetimePosition use_pos; |
2094 if (input->IsUnallocated() && | 2063 if (input->IsUnallocated() && |
2095 UnallocatedOperand::cast(input)->IsUsedAtStart()) { | 2064 UnallocatedOperand::cast(input)->IsUsedAtStart()) { |
2096 use_pos = curr_position; | 2065 use_pos = curr_position; |
(...skipping 1672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3769 } | 3738 } |
3770 } | 3739 } |
3771 } | 3740 } |
3772 } | 3741 } |
3773 } | 3742 } |
3774 | 3743 |
3775 | 3744 |
3776 } // namespace compiler | 3745 } // namespace compiler |
3777 } // namespace internal | 3746 } // namespace internal |
3778 } // namespace v8 | 3747 } // namespace v8 |
OLD | NEW |