Chromium Code Reviews| 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" |
| 11 | 11 |
| 12 namespace dart { | 12 namespace dart { |
| 13 | 13 |
| 14 class BufferFormatter; | 14 class BufferFormatter; |
| 15 | 15 |
| 16 // Location objects are used to connect register allocator and code generator. | 16 // Location objects are used to connect register allocator and code generator. |
| 17 // Instruction templates used by code generator have a corresponding | 17 // Instruction templates used by code generator have a corresponding |
| 18 // LocationSummary object which specifies expected location for every input | 18 // LocationSummary object which specifies expected location for every input |
| 19 // and output. | 19 // and output. |
| 20 // Each location is encoded as a single word: for non-constant locations | 20 // Each location is encoded as a single word: for non-constant locations |
| 21 // low 3 bits denote location kind, rest is kind specific location payload | 21 // low 3 bits denote location kind, rest is kind specific location payload |
| 22 // e.g. for REGISTER kind payload is register code (value of the Register | 22 // e.g. for REGISTER kind payload is register code (value of the Register |
| 23 // enumeration), constant locations contain a tagged (low 2 bits are set to 01) | 23 // enumeration), constant locations contain a tagged (low 2 bits are set to 01) |
| 24 // Object handle | 24 // Object handle |
| 25 class Location : public ValueObject { | 25 class Location : public ValueObject { |
| 26 private: | |
| 27 enum { | |
| 28 // Number of bits required to encode Kind value. | |
| 29 kBitsForKind = 3, | |
| 30 kBitsForPayload = kWordSize * kBitsPerByte - kBitsForKind, | |
| 31 }; | |
| 32 | |
| 33 static const uword kInvalidLocation = 0; | |
| 34 static const uword kConstantMask = 0x3; | |
| 35 static const intptr_t kStackIndexBias = | |
| 36 static_cast<intptr_t>(1) << (kBitsForPayload - 1); | |
| 37 | |
|
siva
2012/08/04 01:21:50
Similar comment about private: coming before publi
| |
| 26 public: | 38 public: |
| 27 // Constant payload can overlap with kind field so Kind values | 39 // Constant payload can overlap with kind field so Kind values |
| 28 // have to be chosen in a way that their last 2 bits are never | 40 // have to be chosen in a way that their last 2 bits are never |
| 29 // the same as kConstant. | 41 // the same as kConstant. |
| 30 enum Kind { | 42 enum Kind { |
| 31 // This location is invalid. Payload must be zero. | 43 // This location is invalid. Payload must be zero. |
| 32 kInvalid = 0, | 44 kInvalid = 0, |
| 33 | 45 |
| 34 // Constant value. This location contains a tagged Object handle. | 46 // Constant value. This location contains a tagged Object handle. |
| 35 kConstant = 1, | 47 kConstant = 1, |
| 36 | 48 |
| 37 // Unallocated location represents a location that is not fixed and can be | 49 // Unallocated location represents a location that is not fixed and can be |
| 38 // allocated by a register allocator. Each unallocated location has | 50 // allocated by a register allocator. Each unallocated location has |
| 39 // a policy that specifies what kind of location is suitable. Payload | 51 // a policy that specifies what kind of location is suitable. Payload |
| 40 // contains register allocation policy. | 52 // contains register allocation policy. |
| 41 kUnallocated = 2, | 53 kUnallocated = 2, |
| 42 | 54 |
| 43 // Register location represents a fixed register. Payload contains | 55 // Register location represents a fixed register. Payload contains |
| 44 // register code. | 56 // register code. |
| 45 kRegister = 3, | 57 kRegister = 3, |
| 46 | 58 |
| 47 // Spill slot allocated by the register allocator. Payload contains | 59 // Spill slot allocated by the register allocator. Payload contains |
| 48 // a spill index. | 60 // a spill index. |
| 49 kStackSlot = 4, | 61 kStackSlot = 4, |
| 50 }; | 62 }; |
| 51 | 63 |
| 52 enum { | |
| 53 // Number of bits required to encode Kind value. | |
| 54 kBitsForKind = 3, | |
| 55 kBitsForPayload = kWordSize * kBitsPerByte - kBitsForKind, | |
| 56 }; | |
| 57 | |
| 58 static const uword kInvalidLocation = 0; | |
| 59 static const uword kConstantMask = 0x3; | |
| 60 | |
| 61 Location() : value_(kInvalidLocation) { | 64 Location() : value_(kInvalidLocation) { |
| 62 ASSERT(IsInvalid()); | 65 ASSERT(IsInvalid()); |
| 63 } | 66 } |
| 64 | 67 |
| 65 bool IsInvalid() const { | 68 bool IsInvalid() const { |
| 66 return value_ == kInvalidLocation; | 69 return value_ == kInvalidLocation; |
| 67 } | 70 } |
| 68 | 71 |
| 69 // Constants. | 72 // Constants. |
| 70 bool IsConstant() const { | 73 bool IsConstant() const { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 bool IsRegister() const { | 144 bool IsRegister() const { |
| 142 return kind() == kRegister; | 145 return kind() == kRegister; |
| 143 } | 146 } |
| 144 | 147 |
| 145 Register reg() const { | 148 Register reg() const { |
| 146 ASSERT(IsRegister()); | 149 ASSERT(IsRegister()); |
| 147 return static_cast<Register>(payload()); | 150 return static_cast<Register>(payload()); |
| 148 } | 151 } |
| 149 | 152 |
| 150 // Spill slots. | 153 // Spill slots. |
| 151 static const intptr_t kStackIndexBias = | |
| 152 static_cast<intptr_t>(1) << (kBitsForPayload - 1); | |
| 153 static Location StackSlot(intptr_t stack_index) { | 154 static Location StackSlot(intptr_t stack_index) { |
| 154 ASSERT((-kStackIndexBias <= stack_index) && | 155 ASSERT((-kStackIndexBias <= stack_index) && |
| 155 (stack_index < kStackIndexBias)); | 156 (stack_index < kStackIndexBias)); |
| 156 Location loc(kStackSlot, static_cast<uword>(kStackIndexBias + stack_index)); | 157 Location loc(kStackSlot, static_cast<uword>(kStackIndexBias + stack_index)); |
| 157 // Ensure that sign is preserved. | 158 // Ensure that sign is preserved. |
| 158 ASSERT(loc.stack_index() == stack_index); | 159 ASSERT(loc.stack_index() == stack_index); |
| 159 return loc; | 160 return loc; |
| 160 } | 161 } |
| 161 | 162 |
| 162 bool IsStackSlot() const { | 163 bool IsStackSlot() const { |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 283 GrowableArray<Location> temp_locations_; | 284 GrowableArray<Location> temp_locations_; |
| 284 Location output_location_; | 285 Location output_location_; |
| 285 | 286 |
| 286 const bool is_call_; | 287 const bool is_call_; |
| 287 }; | 288 }; |
| 288 | 289 |
| 289 | 290 |
| 290 } // namespace dart | 291 } // namespace dart |
| 291 | 292 |
| 292 #endif // VM_LOCATIONS_H_ | 293 #endif // VM_LOCATIONS_H_ |
| OLD | NEW |