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: low 2 bits denote location kind, | 20 // Each location is encoded as a single word: low 2 bits denote location kind, |
|
srdjan
2012/07/22 23:27:33
It seems that you are now using 3 bits with SpillS
Vyacheslav Egorov (Google)
2012/07/23 11:48:39
It works because no location kind has the same low
srdjan
2012/07/23 17:02:50
I think the improved documentation in the other sp
| |
| 21 // rest is kind specific location payload e.g. for REGISTER kind payload is | 21 // rest is kind specific location payload e.g. for REGISTER kind payload is |
| 22 // register code (value of the Register enumeration). | 22 // register code (value of the Register enumeration). |
| 23 class Location : public ValueObject { | 23 class Location : public ValueObject { |
| 24 public: | 24 public: |
| 25 // Constant payload can overlap with kind field so Kind values | 25 // Constant payload can overlap with kind field so Kind values |
| 26 // have to be chosen in a way that their last 2 bits are never | 26 // have to be chosen in a way that their last 2 bits are never |
| 27 // the same as kConstant. | 27 // the same as kConstant. |
|
srdjan
2012/07/22 23:27:33
Describe also what is the payload of each kind, an
Vyacheslav Egorov (Google)
2012/07/23 11:48:39
Done.
| |
| 28 enum Kind { | 28 enum Kind { |
| 29 kInvalid = 0, | 29 kInvalid = 0, |
| 30 | 30 |
| 31 kConstant = 1, | 31 kConstant = 1, |
| 32 | 32 |
| 33 // Unallocated location represents a location that is not fixed and can be | 33 // Unallocated location represents a location that is not fixed and can be |
| 34 // allocated by a register allocator. Each unallocated location has | 34 // allocated by a register allocator. Each unallocated location has |
| 35 // a policy that specifies what kind of location is suitable. | 35 // a policy that specifies what kind of location is suitable. |
| 36 kUnallocated = 2, | 36 kUnallocated = 2, |
| 37 | 37 |
| 38 // Register location represents a fixed register. | 38 // Register location represents a fixed register. |
| 39 kRegister = 3 | 39 kRegister = 3, |
| 40 | |
| 41 kSpillSlot = 4 | |
| 40 }; | 42 }; |
| 41 | 43 |
| 42 static const uword kInvalidLocation = 0; | 44 static const uword kInvalidLocation = 0; |
| 43 static const uword kConstantMask = 0x3; | 45 static const uword kConstantMask = 0x3; |
| 44 | 46 |
| 45 Location() : value_(kInvalidLocation) { | 47 Location() : value_(kInvalidLocation) { |
| 46 ASSERT(IsInvalid()); | 48 ASSERT(IsInvalid()); |
| 47 } | 49 } |
| 48 | 50 |
| 49 bool IsInvalid() const { | 51 bool IsInvalid() const { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 61 ASSERT(&obj == &loc.constant()); | 63 ASSERT(&obj == &loc.constant()); |
| 62 return loc; | 64 return loc; |
| 63 } | 65 } |
| 64 | 66 |
| 65 const Object& constant() const { | 67 const Object& constant() const { |
| 66 ASSERT(IsConstant()); | 68 ASSERT(IsConstant()); |
| 67 return *reinterpret_cast<const Object*>(value_ & ~kConstantMask); | 69 return *reinterpret_cast<const Object*>(value_ & ~kConstantMask); |
| 68 } | 70 } |
| 69 | 71 |
| 70 // Unallocated locations. | 72 // Unallocated locations. |
| 73 // TODO(vegorov): writable register policy? | |
| 71 enum Policy { | 74 enum Policy { |
| 75 kAny, | |
| 76 kPrefersRegister, | |
| 72 kRequiresRegister, | 77 kRequiresRegister, |
| 73 kSameAsFirstInput, | 78 kSameAsFirstInput, |
| 74 }; | 79 }; |
| 75 | 80 |
| 76 bool IsUnallocated() const { | 81 bool IsUnallocated() const { |
| 77 return kind() == kUnallocated; | 82 return kind() == kUnallocated; |
| 78 } | 83 } |
| 79 | 84 |
| 85 bool IsRegisterBeneficial() { | |
| 86 return !Equals(Any()); | |
| 87 } | |
| 88 | |
| 80 static Location UnallocatedLocation(Policy policy) { | 89 static Location UnallocatedLocation(Policy policy) { |
| 81 return Location(kUnallocated, PolicyField::encode(policy)); | 90 return Location(kUnallocated, PolicyField::encode(policy)); |
| 82 } | 91 } |
| 83 | 92 |
| 84 // Any free register is suitable to replace this unallocated location. | 93 // Any free register is suitable to replace this unallocated location. |
| 94 static Location Any() { | |
| 95 return UnallocatedLocation(kAny); | |
| 96 } | |
| 97 | |
| 98 static Location PrefersRegister() { | |
| 99 return UnallocatedLocation(kPrefersRegister); | |
| 100 } | |
| 101 | |
| 85 static Location RequiresRegister() { | 102 static Location RequiresRegister() { |
| 86 return UnallocatedLocation(kRequiresRegister); | 103 return UnallocatedLocation(kRequiresRegister); |
| 87 } | 104 } |
| 88 | 105 |
| 89 // The location of the first input to the instruction will be | 106 // The location of the first input to the instruction will be |
| 90 // used to replace this unallocated location. | 107 // used to replace this unallocated location. |
| 91 static Location SameAsFirstInput() { | 108 static Location SameAsFirstInput() { |
| 92 return UnallocatedLocation(kSameAsFirstInput); | 109 return UnallocatedLocation(kSameAsFirstInput); |
| 93 } | 110 } |
| 94 | 111 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 109 | 126 |
| 110 bool IsRegister() const { | 127 bool IsRegister() const { |
| 111 return kind() == kRegister; | 128 return kind() == kRegister; |
| 112 } | 129 } |
| 113 | 130 |
| 114 Register reg() const { | 131 Register reg() const { |
| 115 ASSERT(IsRegister()); | 132 ASSERT(IsRegister()); |
| 116 return static_cast<Register>(payload()); | 133 return static_cast<Register>(payload()); |
| 117 } | 134 } |
| 118 | 135 |
| 136 // Spill slots. | |
| 137 static Location SpillSlot(intptr_t spill_index) { | |
| 138 return Location(kSpillSlot, static_cast<uword>(spill_index)); | |
| 139 } | |
| 140 | |
| 141 bool IsSpillSlot() const { | |
| 142 return kind() == kSpillSlot; | |
| 143 } | |
| 144 | |
| 145 intptr_t spill_index() const { | |
| 146 ASSERT(IsSpillSlot()); | |
| 147 return static_cast<uword>(payload()); | |
| 148 } | |
| 149 | |
| 119 const char* Name() const; | 150 const char* Name() const; |
| 151 void PrintTo(BufferFormatter* f) const; | |
| 120 | 152 |
| 121 // Compare two non-constant locations. | 153 // Compare two non-constant locations. |
| 122 bool Equals(Location other) const { | 154 bool Equals(Location other) const { |
| 123 ASSERT(!IsConstant() && !other.IsConstant()); | 155 ASSERT(!IsConstant() && !other.IsConstant()); |
| 124 return value_ == other.value_; | 156 return value_ == other.value_; |
| 125 } | 157 } |
| 126 | 158 |
| 127 private: | 159 private: |
| 128 explicit Location(uword value) : value_(value) { } | 160 explicit Location(uword value) : value_(value) { } |
| 129 | 161 |
| 130 Location(Kind kind, uword payload) | 162 Location(Kind kind, uword payload) |
| 131 : value_(KindField::encode(kind) | PayloadField::encode(payload)) { } | 163 : value_(KindField::encode(kind) | PayloadField::encode(payload)) { } |
| 132 | 164 |
| 133 uword payload() const { | 165 uword payload() const { |
| 134 return PayloadField::decode(value_); | 166 return PayloadField::decode(value_); |
| 135 } | 167 } |
| 136 | 168 |
| 137 // If current location is constant might return something that | 169 // If current location is constant might return something that |
| 138 // is not equal to any Kind. | 170 // is not equal to any Kind. |
| 139 Kind kind() const { | 171 Kind kind() const { |
| 140 return KindField::decode(value_); | 172 return KindField::decode(value_); |
| 141 } | 173 } |
| 142 | 174 |
| 143 typedef BitField<Kind, 0, 2> KindField; | 175 typedef BitField<Kind, 0, 3> KindField; |
| 144 typedef BitField<uword, 2, kWordSize * kBitsPerByte - 2> PayloadField; | 176 typedef BitField<uword, 3, kWordSize * kBitsPerByte - 2> PayloadField; |
| 145 | 177 |
| 146 // Layout for kUnallocated locations payload. | 178 // Layout for kUnallocated locations payload. |
| 147 typedef BitField<Policy, 0, 1> PolicyField; | 179 typedef BitField<Policy, 0, 2> PolicyField; |
| 148 | 180 |
| 149 // Location either contains kind and payload fields or a tagged handle for | 181 // Location either contains kind and payload fields or a tagged handle for |
| 150 // a constant locations. Values of enumeration Kind are selected in such a | 182 // a constant locations. Values of enumeration Kind are selected in such a |
| 151 // way that none of them can be interpreted as a kConstant tag. | 183 // way that none of them can be interpreted as a kConstant tag. |
| 152 uword value_; | 184 uword value_; |
| 153 }; | 185 }; |
| 154 | 186 |
| 155 | 187 |
| 156 // Specification of locations for inputs and output. | 188 // Specification of locations for inputs and output. |
| 157 class LocationSummary : public ZoneAllocated { | 189 class LocationSummary : public ZoneAllocated { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 227 GrowableArray<Location> temp_locations_; | 259 GrowableArray<Location> temp_locations_; |
| 228 Location output_location_; | 260 Location output_location_; |
| 229 | 261 |
| 230 const bool is_call_; | 262 const bool is_call_; |
| 231 }; | 263 }; |
| 232 | 264 |
| 233 | 265 |
| 234 } // namespace dart | 266 } // namespace dart |
| 235 | 267 |
| 236 #endif // VM_LOCATIONS_H_ | 268 #endif // VM_LOCATIONS_H_ |
| OLD | NEW |