| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 #ifndef VM_LOCATIONS_H_ | 5 #ifndef VM_LOCATIONS_H_ |
| 6 #define VM_LOCATIONS_H_ | 6 #define VM_LOCATIONS_H_ |
| 7 | 7 |
| 8 #include "vm/allocation.h" | 8 #include "vm/allocation.h" |
| 9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
| 10 #include "vm/bitfield.h" | 10 #include "vm/bitfield.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 // a policy that specifies what kind of location is suitable. Payload | 39 // a policy that specifies what kind of location is suitable. Payload |
| 40 // contains register allocation policy. | 40 // contains register allocation policy. |
| 41 kUnallocated = 2, | 41 kUnallocated = 2, |
| 42 | 42 |
| 43 // Register location represents a fixed register. Payload contains | 43 // Register location represents a fixed register. Payload contains |
| 44 // register code. | 44 // register code. |
| 45 kRegister = 3, | 45 kRegister = 3, |
| 46 | 46 |
| 47 // Spill slot allocated by the register allocator. Payload contains | 47 // Spill slot allocated by the register allocator. Payload contains |
| 48 // a spill index. | 48 // a spill index. |
| 49 kSpillSlot = 4 | 49 kStackSlot = 4, |
| 50 }; |
| 51 |
| 52 enum { |
| 53 // Number of bits required to encode Kind value. |
| 54 kBitsForKind = 3, |
| 55 kBitsForPayload = kWordSize * kBitsPerByte - kBitsForKind |
| 50 }; | 56 }; |
| 51 | 57 |
| 52 static const uword kInvalidLocation = 0; | 58 static const uword kInvalidLocation = 0; |
| 53 static const uword kConstantMask = 0x3; | 59 static const uword kConstantMask = 0x3; |
| 54 | 60 |
| 55 Location() : value_(kInvalidLocation) { | 61 Location() : value_(kInvalidLocation) { |
| 56 ASSERT(IsInvalid()); | 62 ASSERT(IsInvalid()); |
| 57 } | 63 } |
| 58 | 64 |
| 59 bool IsInvalid() const { | 65 bool IsInvalid() const { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 bool IsRegister() const { | 141 bool IsRegister() const { |
| 136 return kind() == kRegister; | 142 return kind() == kRegister; |
| 137 } | 143 } |
| 138 | 144 |
| 139 Register reg() const { | 145 Register reg() const { |
| 140 ASSERT(IsRegister()); | 146 ASSERT(IsRegister()); |
| 141 return static_cast<Register>(payload()); | 147 return static_cast<Register>(payload()); |
| 142 } | 148 } |
| 143 | 149 |
| 144 // Spill slots. | 150 // Spill slots. |
| 145 static Location SpillSlot(intptr_t spill_index) { | 151 static const intptr_t kStackIndexBias = |
| 146 return Location(kSpillSlot, static_cast<uword>(spill_index)); | 152 static_cast<intptr_t>(1) << (kBitsForPayload - 1); |
| 153 static Location StackSlot(intptr_t stack_index) { |
| 154 ASSERT((-kStackIndexBias <= stack_index) && |
| 155 (stack_index < kStackIndexBias)); |
| 156 Location loc(kStackSlot, static_cast<uword>(kStackIndexBias + stack_index)); |
| 157 // Ensure that sign is preserved. |
| 158 ASSERT(loc.stack_index() == stack_index); |
| 159 return loc; |
| 147 } | 160 } |
| 148 | 161 |
| 149 bool IsSpillSlot() const { | 162 bool IsStackSlot() const { |
| 150 return kind() == kSpillSlot; | 163 return kind() == kStackSlot; |
| 151 } | 164 } |
| 152 | 165 |
| 153 intptr_t spill_index() const { | 166 intptr_t stack_index() const { |
| 154 ASSERT(IsSpillSlot()); | 167 ASSERT(IsStackSlot()); |
| 155 return static_cast<intptr_t>(payload()); | 168 // Decode stack index manually to preserve sign. |
| 169 return payload() - kStackIndexBias; |
| 156 } | 170 } |
| 157 | 171 |
| 158 const char* Name() const; | 172 const char* Name() const; |
| 159 void PrintTo(BufferFormatter* f) const; | 173 void PrintTo(BufferFormatter* f) const; |
| 160 | 174 |
| 161 // Compare two locations. | 175 // Compare two locations. |
| 162 bool Equals(Location other) const { | 176 bool Equals(Location other) const { |
| 163 return value_ == other.value_; | 177 return value_ == other.value_; |
| 164 } | 178 } |
| 165 | 179 |
| 166 private: | 180 private: |
| 167 explicit Location(uword value) : value_(value) { } | 181 explicit Location(uword value) : value_(value) { } |
| 168 | 182 |
| 169 Location(Kind kind, uword payload) | 183 Location(Kind kind, uword payload) |
| 170 : value_(KindField::encode(kind) | PayloadField::encode(payload)) { } | 184 : value_(KindField::encode(kind) | PayloadField::encode(payload)) { } |
| 171 | 185 |
| 172 uword payload() const { | 186 uword payload() const { |
| 173 return PayloadField::decode(value_); | 187 return PayloadField::decode(value_); |
| 174 } | 188 } |
| 175 | 189 |
| 176 // If current location is constant might return something that | 190 // If current location is constant might return something that |
| 177 // is not equal to any Kind. | 191 // is not equal to any Kind. |
| 178 Kind kind() const { | 192 Kind kind() const { |
| 179 return KindField::decode(value_); | 193 return KindField::decode(value_); |
| 180 } | 194 } |
| 181 | 195 |
| 182 typedef BitField<Kind, 0, 3> KindField; | 196 typedef BitField<Kind, 0, kBitsForKind> KindField; |
| 183 typedef BitField<uword, 3, kWordSize * kBitsPerByte - 2> PayloadField; | 197 typedef BitField<uword, kBitsForKind, kBitsForPayload> PayloadField; |
| 184 | 198 |
| 185 // Layout for kUnallocated locations payload. | 199 // Layout for kUnallocated locations payload. |
| 186 typedef BitField<Policy, 0, 2> PolicyField; | 200 typedef BitField<Policy, 0, 2> PolicyField; |
| 187 | 201 |
| 188 // Location either contains kind and payload fields or a tagged handle for | 202 // Location either contains kind and payload fields or a tagged handle for |
| 189 // a constant locations. Values of enumeration Kind are selected in such a | 203 // a constant locations. Values of enumeration Kind are selected in such a |
| 190 // way that none of them can be interpreted as a kConstant tag. | 204 // way that none of them can be interpreted as a kConstant tag. |
| 191 uword value_; | 205 uword value_; |
| 192 }; | 206 }; |
| 193 | 207 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 GrowableArray<Location> temp_locations_; | 283 GrowableArray<Location> temp_locations_; |
| 270 Location output_location_; | 284 Location output_location_; |
| 271 | 285 |
| 272 const bool is_call_; | 286 const bool is_call_; |
| 273 }; | 287 }; |
| 274 | 288 |
| 275 | 289 |
| 276 } // namespace dart | 290 } // namespace dart |
| 277 | 291 |
| 278 #endif // VM_LOCATIONS_H_ | 292 #endif // VM_LOCATIONS_H_ |
| OLD | NEW |