| 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 18 matching lines...) Expand all Loading... |
| 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 12 matching lines...) Expand all Loading... |
| 62 return loc; | 64 return loc; |
| 63 } | 65 } |
| 64 | 66 |
| 65 const Object& constant() { | 67 const Object& constant() { |
| 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. |
| 71 enum Policy { | 73 enum Policy { |
| 74 kAny, |
| 75 kPrefersRegister, |
| 72 kRequiresRegister, | 76 kRequiresRegister, |
| 73 kSameAsFirstInput, | 77 kSameAsFirstInput, |
| 74 }; | 78 }; |
| 75 | 79 |
| 76 bool IsUnallocated() const { | 80 bool IsUnallocated() const { |
| 77 return kind() == kUnallocated; | 81 return kind() == kUnallocated; |
| 78 } | 82 } |
| 79 | 83 |
| 84 bool IsRegisterBeneficial() { |
| 85 return !Equals(Any()); |
| 86 } |
| 87 |
| 80 static Location UnallocatedLocation(Policy policy) { | 88 static Location UnallocatedLocation(Policy policy) { |
| 81 return Location(kUnallocated, PolicyField::encode(policy)); | 89 return Location(kUnallocated, PolicyField::encode(policy)); |
| 82 } | 90 } |
| 83 | 91 |
| 84 // Any free register is suitable to replace this unallocated location. | 92 // Any free register is suitable to replace this unallocated location. |
| 93 static Location Any() { |
| 94 return UnallocatedLocation(kAny); |
| 95 } |
| 96 |
| 97 static Location PrefersRegister() { |
| 98 return UnallocatedLocation(kPrefersRegister); |
| 99 } |
| 100 |
| 85 static Location RequiresRegister() { | 101 static Location RequiresRegister() { |
| 86 return UnallocatedLocation(kRequiresRegister); | 102 return UnallocatedLocation(kRequiresRegister); |
| 87 } | 103 } |
| 88 | 104 |
| 89 // The location of the first input to the instruction will be | 105 // The location of the first input to the instruction will be |
| 90 // used to replace this unallocated location. | 106 // used to replace this unallocated location. |
| 91 static Location SameAsFirstInput() { | 107 static Location SameAsFirstInput() { |
| 92 return UnallocatedLocation(kSameAsFirstInput); | 108 return UnallocatedLocation(kSameAsFirstInput); |
| 93 } | 109 } |
| 94 | 110 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 109 | 125 |
| 110 bool IsRegister() const { | 126 bool IsRegister() const { |
| 111 return kind() == kRegister; | 127 return kind() == kRegister; |
| 112 } | 128 } |
| 113 | 129 |
| 114 Register reg() const { | 130 Register reg() const { |
| 115 ASSERT(IsRegister()); | 131 ASSERT(IsRegister()); |
| 116 return static_cast<Register>(payload()); | 132 return static_cast<Register>(payload()); |
| 117 } | 133 } |
| 118 | 134 |
| 135 // Spill slots. |
| 136 static Location SpillSlot(intptr_t spill_index) { |
| 137 return Location(kSpillSlot, static_cast<uword>(spill_index)); |
| 138 } |
| 139 |
| 140 bool IsSpillSlot() const { |
| 141 return kind() == kSpillSlot; |
| 142 } |
| 143 |
| 144 intptr_t spill_index() const { |
| 145 ASSERT(IsSpillSlot()); |
| 146 return static_cast<uword>(payload()); |
| 147 } |
| 148 |
| 119 const char* Name() const; | 149 const char* Name() const; |
| 150 void PrintTo(BufferFormatter* f) const; |
| 120 | 151 |
| 121 // Compare two non-constant locations. | 152 // Compare two non-constant locations. |
| 122 bool Equals(Location other) const { | 153 bool Equals(Location other) const { |
| 123 ASSERT(!IsConstant() && !other.IsConstant()); | 154 ASSERT(!IsConstant() && !other.IsConstant()); |
| 124 return value_ == other.value_; | 155 return value_ == other.value_; |
| 125 } | 156 } |
| 126 | 157 |
| 127 private: | 158 private: |
| 128 explicit Location(uword value) : value_(value) { } | 159 explicit Location(uword value) : value_(value) { } |
| 129 | 160 |
| 130 Location(Kind kind, uword payload) | 161 Location(Kind kind, uword payload) |
| 131 : value_(KindField::encode(kind) | PayloadField::encode(payload)) { } | 162 : value_(KindField::encode(kind) | PayloadField::encode(payload)) { } |
| 132 | 163 |
| 133 uword payload() const { | 164 uword payload() const { |
| 134 return PayloadField::decode(value_); | 165 return PayloadField::decode(value_); |
| 135 } | 166 } |
| 136 | 167 |
| 137 // If current location is constant might return something that | 168 // If current location is constant might return something that |
| 138 // is not equal to any Kind. | 169 // is not equal to any Kind. |
| 139 Kind kind() const { | 170 Kind kind() const { |
| 140 return KindField::decode(value_); | 171 return KindField::decode(value_); |
| 141 } | 172 } |
| 142 | 173 |
| 143 typedef BitField<Kind, 0, 2> KindField; | 174 typedef BitField<Kind, 0, 3> KindField; |
| 144 typedef BitField<uword, 2, kWordSize * kBitsPerByte - 2> PayloadField; | 175 typedef BitField<uword, 3, kWordSize * kBitsPerByte - 2> PayloadField; |
| 145 | 176 |
| 146 // Layout for kUnallocated locations payload. | 177 // Layout for kUnallocated locations payload. |
| 147 typedef BitField<Policy, 0, 1> PolicyField; | 178 typedef BitField<Policy, 0, 2> PolicyField; |
| 148 | 179 |
| 149 // Location either contains kind and payload fields or a tagged handle for | 180 // 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 | 181 // 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. | 182 // way that none of them can be interpreted as a kConstant tag. |
| 152 uword value_; | 183 uword value_; |
| 153 }; | 184 }; |
| 154 | 185 |
| 155 | 186 |
| 156 // Specification of locations for inputs and output. | 187 // Specification of locations for inputs and output. |
| 157 class LocationSummary : public ZoneAllocated { | 188 class LocationSummary : public ZoneAllocated { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 GrowableArray<Location> temp_locations_; | 269 GrowableArray<Location> temp_locations_; |
| 239 Location output_location_; | 270 Location output_location_; |
| 240 | 271 |
| 241 const bool is_call_; | 272 const bool is_call_; |
| 242 }; | 273 }; |
| 243 | 274 |
| 244 | 275 |
| 245 } // namespace dart | 276 } // namespace dart |
| 246 | 277 |
| 247 #endif // VM_LOCATIONS_H_ | 278 #endif // VM_LOCATIONS_H_ |
| OLD | NEW |