| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/locations.h" | 5 #include "vm/locations.h" |
| 6 | 6 |
| 7 #include "vm/assembler.h" | 7 #include "vm/assembler.h" |
| 8 #include "vm/il_printer.h" | 8 #include "vm/il_printer.h" |
| 9 #include "vm/log.h" | 9 #include "vm/log.h" |
| 10 #include "vm/stack_frame.h" | 10 #include "vm/stack_frame.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 input_locations_ = zone->Alloc<Location>(num_inputs_); | 37 input_locations_ = zone->Alloc<Location>(num_inputs_); |
| 38 temp_locations_ = zone->Alloc<Location>(num_temps_); | 38 temp_locations_ = zone->Alloc<Location>(num_temps_); |
| 39 } | 39 } |
| 40 | 40 |
| 41 | 41 |
| 42 LocationSummary* LocationSummary::Make( | 42 LocationSummary* LocationSummary::Make( |
| 43 Zone* zone, | 43 Zone* zone, |
| 44 intptr_t input_count, | 44 intptr_t input_count, |
| 45 Location out, | 45 Location out, |
| 46 LocationSummary::ContainsCall contains_call) { | 46 LocationSummary::ContainsCall contains_call) { |
| 47 LocationSummary* summary = new(zone) LocationSummary( | 47 LocationSummary* summary = |
| 48 zone, input_count, 0, contains_call); | 48 new (zone) LocationSummary(zone, input_count, 0, contains_call); |
| 49 for (intptr_t i = 0; i < input_count; i++) { | 49 for (intptr_t i = 0; i < input_count; i++) { |
| 50 summary->set_in(i, Location::RequiresRegister()); | 50 summary->set_in(i, Location::RequiresRegister()); |
| 51 } | 51 } |
| 52 summary->set_out(0, out); | 52 summary->set_out(0, out); |
| 53 return summary; | 53 return summary; |
| 54 } | 54 } |
| 55 | 55 |
| 56 | 56 |
| 57 Location Location::Pair(Location first, Location second) { | 57 Location Location::Pair(Location first, Location second) { |
| 58 PairLocation* pair_location = new PairLocation(); | 58 PairLocation* pair_location = new PairLocation(); |
| 59 ASSERT((reinterpret_cast<intptr_t>(pair_location) & kLocationTagMask) == 0); | 59 ASSERT((reinterpret_cast<intptr_t>(pair_location) & kLocationTagMask) == 0); |
| 60 pair_location->SetAt(0, first); | 60 pair_location->SetAt(0, first); |
| 61 pair_location->SetAt(1, second); | 61 pair_location->SetAt(1, second); |
| 62 Location loc(reinterpret_cast<uword>(pair_location) | kPairLocationTag); | 62 Location loc(reinterpret_cast<uword>(pair_location) | kPairLocationTag); |
| 63 return loc; | 63 return loc; |
| 64 } | 64 } |
| 65 | 65 |
| 66 | 66 |
| 67 PairLocation* Location::AsPairLocation() const { | 67 PairLocation* Location::AsPairLocation() const { |
| 68 ASSERT(IsPairLocation()); | 68 ASSERT(IsPairLocation()); |
| 69 return reinterpret_cast<PairLocation*>(value_ & ~kLocationTagMask); | 69 return reinterpret_cast<PairLocation*>(value_ & ~kLocationTagMask); |
| 70 } | 70 } |
| 71 | 71 |
| 72 | 72 |
| 73 Location Location::RegisterOrConstant(Value* value) { | 73 Location Location::RegisterOrConstant(Value* value) { |
| 74 ConstantInstr* constant = value->definition()->AsConstant(); | 74 ConstantInstr* constant = value->definition()->AsConstant(); |
| 75 return ((constant != NULL) && Assembler::IsSafe(constant->value())) | 75 return ((constant != NULL) && Assembler::IsSafe(constant->value())) |
| 76 ? Location::Constant(constant) | 76 ? Location::Constant(constant) |
| 77 : Location::RequiresRegister(); | 77 : Location::RequiresRegister(); |
| 78 } | 78 } |
| 79 | 79 |
| 80 | 80 |
| 81 Location Location::RegisterOrSmiConstant(Value* value) { | 81 Location Location::RegisterOrSmiConstant(Value* value) { |
| 82 ConstantInstr* constant = value->definition()->AsConstant(); | 82 ConstantInstr* constant = value->definition()->AsConstant(); |
| 83 return ((constant != NULL) && Assembler::IsSafeSmi(constant->value())) | 83 return ((constant != NULL) && Assembler::IsSafeSmi(constant->value())) |
| 84 ? Location::Constant(constant) | 84 ? Location::Constant(constant) |
| 85 : Location::RequiresRegister(); | 85 : Location::RequiresRegister(); |
| 86 } | 86 } |
| 87 | 87 |
| 88 | 88 |
| 89 Location Location::WritableRegisterOrSmiConstant(Value* value) { | 89 Location Location::WritableRegisterOrSmiConstant(Value* value) { |
| 90 ConstantInstr* constant = value->definition()->AsConstant(); | 90 ConstantInstr* constant = value->definition()->AsConstant(); |
| 91 return ((constant != NULL) && Assembler::IsSafeSmi(constant->value())) | 91 return ((constant != NULL) && Assembler::IsSafeSmi(constant->value())) |
| 92 ? Location::Constant(constant) | 92 ? Location::Constant(constant) |
| 93 : Location::WritableRegister(); | 93 : Location::WritableRegister(); |
| 94 } | 94 } |
| 95 | 95 |
| 96 | 96 |
| 97 Location Location::FixedRegisterOrConstant(Value* value, Register reg) { | 97 Location Location::FixedRegisterOrConstant(Value* value, Register reg) { |
| 98 ConstantInstr* constant = value->definition()->AsConstant(); | 98 ConstantInstr* constant = value->definition()->AsConstant(); |
| 99 return ((constant != NULL) && Assembler::IsSafe(constant->value())) | 99 return ((constant != NULL) && Assembler::IsSafe(constant->value())) |
| 100 ? Location::Constant(constant) | 100 ? Location::Constant(constant) |
| 101 : Location::RegisterLocation(reg); | 101 : Location::RegisterLocation(reg); |
| 102 } | 102 } |
| 103 | 103 |
| 104 | 104 |
| 105 Location Location::FixedRegisterOrSmiConstant(Value* value, Register reg) { | 105 Location Location::FixedRegisterOrSmiConstant(Value* value, Register reg) { |
| 106 ConstantInstr* constant = value->definition()->AsConstant(); | 106 ConstantInstr* constant = value->definition()->AsConstant(); |
| 107 return ((constant != NULL) && Assembler::IsSafeSmi(constant->value())) | 107 return ((constant != NULL) && Assembler::IsSafeSmi(constant->value())) |
| 108 ? Location::Constant(constant) | 108 ? Location::Constant(constant) |
| 109 : Location::RegisterLocation(reg); | 109 : Location::RegisterLocation(reg); |
| 110 } | 110 } |
| 111 | 111 |
| 112 | 112 |
| 113 Location Location::AnyOrConstant(Value* value) { | 113 Location Location::AnyOrConstant(Value* value) { |
| 114 ConstantInstr* constant = value->definition()->AsConstant(); | 114 ConstantInstr* constant = value->definition()->AsConstant(); |
| 115 return ((constant != NULL) && Assembler::IsSafe(constant->value())) | 115 return ((constant != NULL) && Assembler::IsSafe(constant->value())) |
| 116 ? Location::Constant(constant) | 116 ? Location::Constant(constant) |
| 117 : Location::Any(); | 117 : Location::Any(); |
| 118 } | 118 } |
| 119 | 119 |
| 120 | 120 |
| 121 // DBC does not have an notion of 'address' in its instruction set. | 121 // DBC does not have an notion of 'address' in its instruction set. |
| 122 #if !defined(TARGET_ARCH_DBC) | 122 #if !defined(TARGET_ARCH_DBC) |
| 123 Address Location::ToStackSlotAddress() const { | 123 Address Location::ToStackSlotAddress() const { |
| 124 const intptr_t index = stack_index(); | 124 const intptr_t index = stack_index(); |
| 125 const Register base = base_reg(); | 125 const Register base = base_reg(); |
| 126 if (base == FPREG) { | 126 if (base == FPREG) { |
| 127 if (index < 0) { | 127 if (index < 0) { |
| 128 const intptr_t offset = (kParamEndSlotFromFp - index) * kWordSize; | 128 const intptr_t offset = (kParamEndSlotFromFp - index) * kWordSize; |
| 129 return Address(base, offset); | 129 return Address(base, offset); |
| 130 } else { | 130 } else { |
| 131 const intptr_t offset = (kFirstLocalSlotFromFp - index) * kWordSize; | 131 const intptr_t offset = (kFirstLocalSlotFromFp - index) * kWordSize; |
| 132 return Address(base, offset); | 132 return Address(base, offset); |
| 133 } | 133 } |
| 134 } else { | 134 } else { |
| 135 ASSERT(base == SPREG); | 135 ASSERT(base == SPREG); |
| 136 return Address(base, index * kWordSize); | 136 return Address(base, index * kWordSize); |
| 137 } | 137 } |
| 138 } | 138 } |
| 139 #endif | 139 #endif |
| 140 | 140 |
| 141 intptr_t Location::ToStackSlotOffset() const { | 141 intptr_t Location::ToStackSlotOffset() const { |
| 142 const intptr_t index = stack_index(); | 142 const intptr_t index = stack_index(); |
| 143 if (base_reg() == FPREG) { | 143 if (base_reg() == FPREG) { |
| 144 if (index < 0) { | 144 if (index < 0) { |
| 145 const intptr_t offset = (kParamEndSlotFromFp - index) * kWordSize; | 145 const intptr_t offset = (kParamEndSlotFromFp - index) * kWordSize; |
| 146 return offset; | 146 return offset; |
| 147 } else { | 147 } else { |
| 148 const intptr_t offset = (kFirstLocalSlotFromFp - index) * kWordSize; | 148 const intptr_t offset = (kFirstLocalSlotFromFp - index) * kWordSize; |
| 149 return offset; | 149 return offset; |
| 150 } | 150 } |
| 151 } else { | 151 } else { |
| 152 ASSERT(base_reg() == SPREG); | 152 ASSERT(base_reg() == SPREG); |
| 153 return index * kWordSize; | 153 return index * kWordSize; |
| 154 } | 154 } |
| 155 } | 155 } |
| 156 | 156 |
| 157 | 157 |
| 158 const Object& Location::constant() const { | 158 const Object& Location::constant() const { |
| 159 return constant_instruction()->value(); | 159 return constant_instruction()->value(); |
| 160 } | 160 } |
| 161 | 161 |
| 162 | 162 |
| 163 const char* Location::Name() const { | 163 const char* Location::Name() const { |
| 164 switch (kind()) { | 164 switch (kind()) { |
| 165 case kInvalid: return "?"; | 165 case kInvalid: |
| 166 case kRegister: return Assembler::RegisterName(reg()); | 166 return "?"; |
| 167 case kFpuRegister: return Assembler::FpuRegisterName(fpu_reg()); | 167 case kRegister: |
| 168 case kStackSlot: return "S"; | 168 return Assembler::RegisterName(reg()); |
| 169 case kDoubleStackSlot: return "DS"; | 169 case kFpuRegister: |
| 170 case kQuadStackSlot: return "QS"; | 170 return Assembler::FpuRegisterName(fpu_reg()); |
| 171 case kStackSlot: |
| 172 return "S"; |
| 173 case kDoubleStackSlot: |
| 174 return "DS"; |
| 175 case kQuadStackSlot: |
| 176 return "QS"; |
| 171 case kUnallocated: | 177 case kUnallocated: |
| 172 switch (policy()) { | 178 switch (policy()) { |
| 173 case kAny: | 179 case kAny: |
| 174 return "A"; | 180 return "A"; |
| 175 case kPrefersRegister: | 181 case kPrefersRegister: |
| 176 return "P"; | 182 return "P"; |
| 177 case kRequiresRegister: | 183 case kRequiresRegister: |
| 178 return "R"; | 184 return "R"; |
| 179 case kRequiresFpuRegister: | 185 case kRequiresFpuRegister: |
| 180 return "DR"; | 186 return "DR"; |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 // with the right representation because register allocator does not know | 361 // with the right representation because register allocator does not know |
| 356 // how they are used within the instruction template. | 362 // how they are used within the instruction template. |
| 357 ASSERT(in(i).IsMachineRegister()); | 363 ASSERT(in(i).IsMachineRegister()); |
| 358 ASSERT(live_registers()->Contains(in(i))); | 364 ASSERT(live_registers()->Contains(in(i))); |
| 359 } | 365 } |
| 360 } | 366 } |
| 361 } | 367 } |
| 362 #endif | 368 #endif |
| 363 | 369 |
| 364 } // namespace dart | 370 } // namespace dart |
| OLD | NEW |