| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ART_COMPILER_OPTIMIZING_LOCATIONS_H_ |
| 18 | #define ART_COMPILER_OPTIMIZING_LOCATIONS_H_ |
| 19 | |
| Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 20 | #include "base/arena_containers.h" |
| Mathieu Chartier | b666f48 | 2015-02-18 14:33:14 -0800 | [diff] [blame] | 21 | #include "base/arena_object.h" |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 22 | #include "base/bit_field.h" |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 23 | #include "base/bit_utils.h" |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 24 | #include "base/bit_vector.h" |
| Vladimir Marko | e272715 | 2019-10-10 10:46:42 +0100 | [diff] [blame^] | 25 | #include "base/macros.h" |
| Ian Rogers | 0279ebb | 2014-10-08 17:27:48 -0700 | [diff] [blame] | 26 | #include "base/value_object.h" |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 27 | |
| Vladimir Marko | e272715 | 2019-10-10 10:46:42 +0100 | [diff] [blame^] | 28 | namespace art HIDDEN { |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 29 | |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 30 | class HConstant; |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 31 | class HInstruction; |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 32 | class Location; |
| 33 | |
| 34 | std::ostream& operator<<(std::ostream& os, const Location& location); |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 35 | |
| 36 | /** |
| 37 | * A Location is an abstraction over the potential location |
| 38 | * of an instruction. It could be in register or stack. |
| 39 | */ |
| Vladimir Marko | 76c92ac | 2015-09-17 15:39:16 +0100 | [diff] [blame] | 40 | class Location : public ValueObject { |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 41 | public: |
| Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 42 | enum OutputOverlap { |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 43 | // The liveness of the output overlaps the liveness of one or |
| 44 | // several input(s); the register allocator cannot reuse an |
| 45 | // input's location for the output's location. |
| Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 46 | kOutputOverlap, |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 47 | // The liveness of the output does not overlap the liveness of any |
| 48 | // input; the register allocator is allowed to reuse an input's |
| 49 | // location for the output's location. |
| Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 50 | kNoOutputOverlap |
| 51 | }; |
| Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 52 | |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 53 | enum Kind { |
| 54 | kInvalid = 0, |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 55 | kConstant = 1, |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 56 | kStackSlot = 2, // 32bit stack slot. |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 57 | kDoubleStackSlot = 3, // 64bit stack slot. |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 58 | |
| 59 | kRegister = 4, // Core register. |
| 60 | |
| 61 | // We do not use the value 5 because it conflicts with kLocationConstantMask. |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 62 | kDoNotUse5 = 5, |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 63 | |
| Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 64 | kFpuRegister = 6, // Float register. |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 65 | |
| Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 66 | kRegisterPair = 7, // Long register. |
| 67 | |
| 68 | kFpuRegisterPair = 8, // Double register. |
| 69 | |
| 70 | // We do not use the value 9 because it conflicts with kLocationConstantMask. |
| 71 | kDoNotUse9 = 9, |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 72 | |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 73 | kSIMDStackSlot = 10, // 128bit stack slot. TODO: generalize with encoded #bytes? |
| 74 | |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 75 | // Unallocated location represents a location that is not fixed and can be |
| 76 | // allocated by a register allocator. Each unallocated location has |
| 77 | // a policy that specifies what kind of location is suitable. Payload |
| 78 | // contains register allocation policy. |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 79 | kUnallocated = 11, |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 80 | }; |
| 81 | |
| Vladimir Marko | 76c92ac | 2015-09-17 15:39:16 +0100 | [diff] [blame] | 82 | Location() : ValueObject(), value_(kInvalid) { |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 83 | // Verify that non-constant location kinds do not interfere with kConstant. |
| Andreas Gampe | 785d2f2 | 2014-11-03 22:57:30 -0800 | [diff] [blame] | 84 | static_assert((kInvalid & kLocationConstantMask) != kConstant, "TagError"); |
| 85 | static_assert((kUnallocated & kLocationConstantMask) != kConstant, "TagError"); |
| 86 | static_assert((kStackSlot & kLocationConstantMask) != kConstant, "TagError"); |
| 87 | static_assert((kDoubleStackSlot & kLocationConstantMask) != kConstant, "TagError"); |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 88 | static_assert((kSIMDStackSlot & kLocationConstantMask) != kConstant, "TagError"); |
| Andreas Gampe | 785d2f2 | 2014-11-03 22:57:30 -0800 | [diff] [blame] | 89 | static_assert((kRegister & kLocationConstantMask) != kConstant, "TagError"); |
| Andreas Gampe | 785d2f2 | 2014-11-03 22:57:30 -0800 | [diff] [blame] | 90 | static_assert((kFpuRegister & kLocationConstantMask) != kConstant, "TagError"); |
| 91 | static_assert((kRegisterPair & kLocationConstantMask) != kConstant, "TagError"); |
| 92 | static_assert((kFpuRegisterPair & kLocationConstantMask) != kConstant, "TagError"); |
| 93 | static_assert((kConstant & kLocationConstantMask) == kConstant, "TagError"); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 94 | |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 95 | DCHECK(!IsValid()); |
| 96 | } |
| 97 | |
| Andreas Gampe | 2e6f38a | 2016-11-03 14:06:20 -0700 | [diff] [blame] | 98 | Location(const Location& other) = default; |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 99 | |
| Andreas Gampe | 2e6f38a | 2016-11-03 14:06:20 -0700 | [diff] [blame] | 100 | Location& operator=(const Location& other) = default; |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 101 | |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 102 | bool IsConstant() const { |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 103 | return (value_ & kLocationConstantMask) == kConstant; |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | static Location ConstantLocation(HConstant* constant) { |
| 107 | DCHECK(constant != nullptr); |
| Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 108 | return Location(kConstant | reinterpret_cast<uintptr_t>(constant)); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | HConstant* GetConstant() const { |
| 112 | DCHECK(IsConstant()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 113 | return reinterpret_cast<HConstant*>(value_ & ~kLocationConstantMask); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 114 | } |
| 115 | |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 116 | bool IsValid() const { |
| 117 | return value_ != kInvalid; |
| 118 | } |
| 119 | |
| 120 | bool IsInvalid() const { |
| 121 | return !IsValid(); |
| 122 | } |
| 123 | |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 124 | // Empty location. Used if there the location should be ignored. |
| 125 | static Location NoLocation() { |
| 126 | return Location(); |
| 127 | } |
| 128 | |
| 129 | // Register locations. |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 130 | static Location RegisterLocation(int reg) { |
| 131 | return Location(kRegister, reg); |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 132 | } |
| 133 | |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 134 | static Location FpuRegisterLocation(int reg) { |
| 135 | return Location(kFpuRegister, reg); |
| 136 | } |
| 137 | |
| 138 | static Location RegisterPairLocation(int low, int high) { |
| 139 | return Location(kRegisterPair, low << 16 | high); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 140 | } |
| 141 | |
| Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 142 | static Location FpuRegisterPairLocation(int low, int high) { |
| 143 | return Location(kFpuRegisterPair, low << 16 | high); |
| 144 | } |
| 145 | |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 146 | bool IsRegister() const { |
| 147 | return GetKind() == kRegister; |
| 148 | } |
| 149 | |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 150 | bool IsFpuRegister() const { |
| 151 | return GetKind() == kFpuRegister; |
| 152 | } |
| 153 | |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 154 | bool IsRegisterPair() const { |
| 155 | return GetKind() == kRegisterPair; |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 156 | } |
| 157 | |
| Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 158 | bool IsFpuRegisterPair() const { |
| 159 | return GetKind() == kFpuRegisterPair; |
| 160 | } |
| 161 | |
| Nicolas Geoffray | da02afe | 2015-02-11 02:29:42 +0000 | [diff] [blame] | 162 | bool IsRegisterKind() const { |
| 163 | return IsRegister() || IsFpuRegister() || IsRegisterPair() || IsFpuRegisterPair(); |
| 164 | } |
| 165 | |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 166 | int reg() const { |
| 167 | DCHECK(IsRegister() || IsFpuRegister()); |
| 168 | return GetPayload(); |
| 169 | } |
| 170 | |
| Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 171 | int low() const { |
| 172 | DCHECK(IsPair()); |
| 173 | return GetPayload() >> 16; |
| 174 | } |
| 175 | |
| 176 | int high() const { |
| 177 | DCHECK(IsPair()); |
| 178 | return GetPayload() & 0xFFFF; |
| 179 | } |
| 180 | |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 181 | template <typename T> |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 182 | T AsRegister() const { |
| 183 | DCHECK(IsRegister()); |
| 184 | return static_cast<T>(reg()); |
| 185 | } |
| 186 | |
| 187 | template <typename T> |
| 188 | T AsFpuRegister() const { |
| 189 | DCHECK(IsFpuRegister()); |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 190 | return static_cast<T>(reg()); |
| 191 | } |
| 192 | |
| 193 | template <typename T> |
| 194 | T AsRegisterPairLow() const { |
| 195 | DCHECK(IsRegisterPair()); |
| Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 196 | return static_cast<T>(low()); |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | template <typename T> |
| 200 | T AsRegisterPairHigh() const { |
| 201 | DCHECK(IsRegisterPair()); |
| Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 202 | return static_cast<T>(high()); |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 203 | } |
| 204 | |
| Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 205 | template <typename T> |
| 206 | T AsFpuRegisterPairLow() const { |
| 207 | DCHECK(IsFpuRegisterPair()); |
| Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 208 | return static_cast<T>(low()); |
| Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | template <typename T> |
| 212 | T AsFpuRegisterPairHigh() const { |
| 213 | DCHECK(IsFpuRegisterPair()); |
| Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 214 | return static_cast<T>(high()); |
| 215 | } |
| 216 | |
| 217 | bool IsPair() const { |
| 218 | return IsRegisterPair() || IsFpuRegisterPair(); |
| 219 | } |
| 220 | |
| 221 | Location ToLow() const { |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 222 | if (IsRegisterPair()) { |
| 223 | return Location::RegisterLocation(low()); |
| 224 | } else if (IsFpuRegisterPair()) { |
| 225 | return Location::FpuRegisterLocation(low()); |
| 226 | } else { |
| 227 | DCHECK(IsDoubleStackSlot()); |
| 228 | return Location::StackSlot(GetStackIndex()); |
| 229 | } |
| Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | Location ToHigh() const { |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 233 | if (IsRegisterPair()) { |
| 234 | return Location::RegisterLocation(high()); |
| 235 | } else if (IsFpuRegisterPair()) { |
| 236 | return Location::FpuRegisterLocation(high()); |
| 237 | } else { |
| 238 | DCHECK(IsDoubleStackSlot()); |
| 239 | return Location::StackSlot(GetHighStackIndex(4)); |
| 240 | } |
| Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 241 | } |
| 242 | |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 243 | static uintptr_t EncodeStackIndex(intptr_t stack_index) { |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 244 | DCHECK(-kStackIndexBias <= stack_index); |
| 245 | DCHECK(stack_index < kStackIndexBias); |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 246 | return static_cast<uintptr_t>(kStackIndexBias + stack_index); |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | static Location StackSlot(intptr_t stack_index) { |
| Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 250 | uintptr_t payload = EncodeStackIndex(stack_index); |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 251 | Location loc(kStackSlot, payload); |
| 252 | // Ensure that sign is preserved. |
| 253 | DCHECK_EQ(loc.GetStackIndex(), stack_index); |
| 254 | return loc; |
| 255 | } |
| 256 | |
| 257 | bool IsStackSlot() const { |
| 258 | return GetKind() == kStackSlot; |
| 259 | } |
| 260 | |
| 261 | static Location DoubleStackSlot(intptr_t stack_index) { |
| Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 262 | uintptr_t payload = EncodeStackIndex(stack_index); |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 263 | Location loc(kDoubleStackSlot, payload); |
| 264 | // Ensure that sign is preserved. |
| 265 | DCHECK_EQ(loc.GetStackIndex(), stack_index); |
| 266 | return loc; |
| 267 | } |
| 268 | |
| 269 | bool IsDoubleStackSlot() const { |
| 270 | return GetKind() == kDoubleStackSlot; |
| 271 | } |
| 272 | |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 273 | static Location SIMDStackSlot(intptr_t stack_index) { |
| 274 | uintptr_t payload = EncodeStackIndex(stack_index); |
| 275 | Location loc(kSIMDStackSlot, payload); |
| 276 | // Ensure that sign is preserved. |
| 277 | DCHECK_EQ(loc.GetStackIndex(), stack_index); |
| 278 | return loc; |
| 279 | } |
| 280 | |
| 281 | bool IsSIMDStackSlot() const { |
| 282 | return GetKind() == kSIMDStackSlot; |
| 283 | } |
| 284 | |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 285 | intptr_t GetStackIndex() const { |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 286 | DCHECK(IsStackSlot() || IsDoubleStackSlot() || IsSIMDStackSlot()); |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 287 | // Decode stack index manually to preserve sign. |
| 288 | return GetPayload() - kStackIndexBias; |
| 289 | } |
| 290 | |
| 291 | intptr_t GetHighStackIndex(uintptr_t word_size) const { |
| 292 | DCHECK(IsDoubleStackSlot()); |
| 293 | // Decode stack index manually to preserve sign. |
| 294 | return GetPayload() - kStackIndexBias + word_size; |
| 295 | } |
| 296 | |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 297 | Kind GetKind() const { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 298 | return IsConstant() ? kConstant : KindField::Decode(value_); |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | bool Equals(Location other) const { |
| 302 | return value_ == other.value_; |
| 303 | } |
| 304 | |
| Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 305 | bool Contains(Location other) const { |
| 306 | if (Equals(other)) { |
| 307 | return true; |
| Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 308 | } else if (IsPair() || IsDoubleStackSlot()) { |
| 309 | return ToLow().Equals(other) || ToHigh().Equals(other); |
| Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 310 | } |
| 311 | return false; |
| 312 | } |
| 313 | |
| Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 314 | bool OverlapsWith(Location other) const { |
| 315 | // Only check the overlapping case that can happen with our register allocation algorithm. |
| 316 | bool overlap = Contains(other) || other.Contains(*this); |
| 317 | if (kIsDebugBuild && !overlap) { |
| 318 | // Note: These are also overlapping cases. But we are not able to handle them in |
| 319 | // ParallelMoveResolverWithSwap. Make sure that we do not meet such case with our compiler. |
| 320 | if ((IsPair() && other.IsPair()) || (IsDoubleStackSlot() && other.IsDoubleStackSlot())) { |
| 321 | DCHECK(!Contains(other.ToLow())); |
| 322 | DCHECK(!Contains(other.ToHigh())); |
| 323 | } |
| 324 | } |
| 325 | return overlap; |
| 326 | } |
| 327 | |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 328 | const char* DebugString() const { |
| 329 | switch (GetKind()) { |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 330 | case kInvalid: return "I"; |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 331 | case kRegister: return "R"; |
| 332 | case kStackSlot: return "S"; |
| 333 | case kDoubleStackSlot: return "DS"; |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 334 | case kSIMDStackSlot: return "SIMD"; |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 335 | case kUnallocated: return "U"; |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 336 | case kConstant: return "C"; |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 337 | case kFpuRegister: return "F"; |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 338 | case kRegisterPair: return "RP"; |
| Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 339 | case kFpuRegisterPair: return "FP"; |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 340 | case kDoNotUse5: // fall-through |
| 341 | case kDoNotUse9: |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 342 | LOG(FATAL) << "Should not use this location kind"; |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 343 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 344 | UNREACHABLE(); |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | // Unallocated locations. |
| 348 | enum Policy { |
| 349 | kAny, |
| 350 | kRequiresRegister, |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 351 | kRequiresFpuRegister, |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 352 | kSameAsFirstInput, |
| 353 | }; |
| 354 | |
| 355 | bool IsUnallocated() const { |
| 356 | return GetKind() == kUnallocated; |
| 357 | } |
| 358 | |
| 359 | static Location UnallocatedLocation(Policy policy) { |
| 360 | return Location(kUnallocated, PolicyField::Encode(policy)); |
| 361 | } |
| 362 | |
| 363 | // Any free register is suitable to replace this unallocated location. |
| 364 | static Location Any() { |
| 365 | return UnallocatedLocation(kAny); |
| 366 | } |
| 367 | |
| 368 | static Location RequiresRegister() { |
| 369 | return UnallocatedLocation(kRequiresRegister); |
| 370 | } |
| 371 | |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 372 | static Location RequiresFpuRegister() { |
| 373 | return UnallocatedLocation(kRequiresFpuRegister); |
| 374 | } |
| 375 | |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 376 | static Location RegisterOrConstant(HInstruction* instruction); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 377 | static Location RegisterOrInt32Constant(HInstruction* instruction); |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 378 | static Location ByteRegisterOrConstant(int reg, HInstruction* instruction); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 379 | static Location FpuRegisterOrConstant(HInstruction* instruction); |
| 380 | static Location FpuRegisterOrInt32Constant(HInstruction* instruction); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 381 | |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 382 | // The location of the first input to the instruction will be |
| 383 | // used to replace this unallocated location. |
| 384 | static Location SameAsFirstInput() { |
| 385 | return UnallocatedLocation(kSameAsFirstInput); |
| 386 | } |
| 387 | |
| 388 | Policy GetPolicy() const { |
| 389 | DCHECK(IsUnallocated()); |
| 390 | return PolicyField::Decode(GetPayload()); |
| 391 | } |
| 392 | |
| Matthew Gharrity | d9ffd0d | 2016-06-22 10:27:55 -0700 | [diff] [blame] | 393 | bool RequiresRegisterKind() const { |
| 394 | return GetPolicy() == kRequiresRegister || GetPolicy() == kRequiresFpuRegister; |
| 395 | } |
| 396 | |
| Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 397 | uintptr_t GetEncoding() const { |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 398 | return GetPayload(); |
| 399 | } |
| 400 | |
| 401 | private: |
| 402 | // Number of bits required to encode Kind value. |
| 403 | static constexpr uint32_t kBitsForKind = 4; |
| Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 404 | static constexpr uint32_t kBitsForPayload = kBitsPerIntPtrT - kBitsForKind; |
| 405 | static constexpr uintptr_t kLocationConstantMask = 0x3; |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 406 | |
| Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 407 | explicit Location(uintptr_t value) : value_(value) {} |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 408 | |
| Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 409 | Location(Kind kind, uintptr_t payload) |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 410 | : value_(KindField::Encode(kind) | PayloadField::Encode(payload)) {} |
| 411 | |
| Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 412 | uintptr_t GetPayload() const { |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 413 | return PayloadField::Decode(value_); |
| 414 | } |
| 415 | |
| 416 | typedef BitField<Kind, 0, kBitsForKind> KindField; |
| Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 417 | typedef BitField<uintptr_t, kBitsForKind, kBitsForPayload> PayloadField; |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 418 | |
| 419 | // Layout for kUnallocated locations payload. |
| 420 | typedef BitField<Policy, 0, 3> PolicyField; |
| 421 | |
| 422 | // Layout for stack slots. |
| 423 | static const intptr_t kStackIndexBias = |
| 424 | static_cast<intptr_t>(1) << (kBitsForPayload - 1); |
| 425 | |
| 426 | // Location either contains kind and payload fields or a tagged handle for |
| 427 | // a constant locations. Values of enumeration Kind are selected in such a |
| 428 | // way that none of them can be interpreted as a kConstant tag. |
| Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 429 | uintptr_t value_; |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 430 | }; |
| Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 431 | std::ostream& operator<<(std::ostream& os, const Location::Kind& rhs); |
| 432 | std::ostream& operator<<(std::ostream& os, const Location::Policy& rhs); |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 433 | |
| Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 434 | class RegisterSet : public ValueObject { |
| 435 | public: |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 436 | static RegisterSet Empty() { return RegisterSet(); } |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 437 | static RegisterSet AllFpu() { return RegisterSet(0, -1); } |
| Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 438 | |
| 439 | void Add(Location loc) { |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 440 | if (loc.IsRegister()) { |
| 441 | core_registers_ |= (1 << loc.reg()); |
| 442 | } else { |
| 443 | DCHECK(loc.IsFpuRegister()); |
| 444 | floating_point_registers_ |= (1 << loc.reg()); |
| 445 | } |
| Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 446 | } |
| 447 | |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 448 | void Remove(Location loc) { |
| 449 | if (loc.IsRegister()) { |
| 450 | core_registers_ &= ~(1 << loc.reg()); |
| 451 | } else { |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 452 | DCHECK(loc.IsFpuRegister()) << loc; |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 453 | floating_point_registers_ &= ~(1 << loc.reg()); |
| 454 | } |
| 455 | } |
| 456 | |
| Nicolas Geoffray | 45b83af | 2015-07-06 15:12:53 +0000 | [diff] [blame] | 457 | bool ContainsCoreRegister(uint32_t id) const { |
| Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 458 | return Contains(core_registers_, id); |
| 459 | } |
| 460 | |
| Nicolas Geoffray | 45b83af | 2015-07-06 15:12:53 +0000 | [diff] [blame] | 461 | bool ContainsFloatingPointRegister(uint32_t id) const { |
| Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 462 | return Contains(floating_point_registers_, id); |
| 463 | } |
| 464 | |
| 465 | static bool Contains(uint32_t register_set, uint32_t reg) { |
| 466 | return (register_set & (1 << reg)) != 0; |
| 467 | } |
| 468 | |
| Nicolas Geoffray | 87d0376 | 2014-11-19 15:17:56 +0000 | [diff] [blame] | 469 | size_t GetNumberOfRegisters() const { |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 470 | return POPCOUNT(core_registers_) + POPCOUNT(floating_point_registers_); |
| Nicolas Geoffray | 87d0376 | 2014-11-19 15:17:56 +0000 | [diff] [blame] | 471 | } |
| 472 | |
| Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 473 | uint32_t GetCoreRegisters() const { |
| 474 | return core_registers_; |
| 475 | } |
| 476 | |
| 477 | uint32_t GetFloatingPointRegisters() const { |
| 478 | return floating_point_registers_; |
| 479 | } |
| 480 | |
| Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 481 | private: |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 482 | RegisterSet() : core_registers_(0), floating_point_registers_(0) {} |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 483 | RegisterSet(uint32_t core, uint32_t fp) : core_registers_(core), floating_point_registers_(fp) {} |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 484 | |
| Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 485 | uint32_t core_registers_; |
| 486 | uint32_t floating_point_registers_; |
| Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 487 | }; |
| 488 | |
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 489 | static constexpr bool kIntrinsified = true; |
| 490 | |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 491 | /** |
| 492 | * The code generator computes LocationSummary for each instruction so that |
| 493 | * the instruction itself knows what code to generate: where to find the inputs |
| 494 | * and where to place the result. |
| 495 | * |
| 496 | * The intent is to have the code for generating the instruction independent of |
| 497 | * register allocation. A register allocator just has to provide a LocationSummary. |
| 498 | */ |
| Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 499 | class LocationSummary : public ArenaObject<kArenaAllocLocationSummary> { |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 500 | public: |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 501 | enum CallKind { |
| 502 | kNoCall, |
| Serban Constantinescu | 806f012 | 2016-03-09 11:10:16 +0000 | [diff] [blame] | 503 | kCallOnMainAndSlowPath, |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 504 | kCallOnSlowPath, |
| Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 505 | kCallOnMainOnly |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 506 | }; |
| 507 | |
| Chih-Hung Hsieh | a593118 | 2016-09-01 15:08:13 -0700 | [diff] [blame] | 508 | explicit LocationSummary(HInstruction* instruction, |
| 509 | CallKind call_kind = kNoCall, |
| 510 | bool intrinsified = false); |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 511 | |
| Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 512 | void SetInAt(uint32_t at, Location location) { |
| Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 513 | inputs_[at] = location; |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | Location InAt(uint32_t at) const { |
| Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 517 | return inputs_[at]; |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | size_t GetInputCount() const { |
| Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 521 | return inputs_.size(); |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 522 | } |
| 523 | |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 524 | // Set the output location. Argument `overlaps` tells whether the |
| 525 | // output overlaps any of the inputs (if so, it cannot share the |
| 526 | // same register as one of the inputs); it is set to |
| 527 | // `Location::kOutputOverlap` by default for safety. |
| Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 528 | void SetOut(Location location, Location::OutputOverlap overlaps = Location::kOutputOverlap) { |
| Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 529 | DCHECK(output_.IsInvalid()); |
| Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 530 | output_overlaps_ = overlaps; |
| Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 531 | output_ = location; |
| 532 | } |
| 533 | |
| 534 | void UpdateOut(Location location) { |
| Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 535 | // There are two reasons for updating an output: |
| 536 | // 1) Parameters, where we only know the exact stack slot after |
| 537 | // doing full register allocation. |
| 538 | // 2) Unallocated location. |
| 539 | DCHECK(output_.IsStackSlot() || output_.IsDoubleStackSlot() || output_.IsUnallocated()); |
| Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 540 | output_ = location; |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | void AddTemp(Location location) { |
| Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 544 | temps_.push_back(location); |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 545 | } |
| 546 | |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 547 | void AddRegisterTemps(size_t count) { |
| 548 | for (size_t i = 0; i < count; ++i) { |
| 549 | AddTemp(Location::RequiresRegister()); |
| 550 | } |
| 551 | } |
| 552 | |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 553 | Location GetTemp(uint32_t at) const { |
| Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 554 | return temps_[at]; |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | void SetTempAt(uint32_t at, Location location) { |
| Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 558 | DCHECK(temps_[at].IsUnallocated() || temps_[at].IsInvalid()); |
| 559 | temps_[at] = location; |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | size_t GetTempCount() const { |
| Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 563 | return temps_.size(); |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 564 | } |
| 565 | |
| Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 566 | bool HasTemps() const { return !temps_.empty(); } |
| Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 567 | |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 568 | Location Out() const { return output_; } |
| 569 | |
| Serban Constantinescu | 806f012 | 2016-03-09 11:10:16 +0000 | [diff] [blame] | 570 | bool CanCall() const { |
| 571 | return call_kind_ != kNoCall; |
| 572 | } |
| 573 | |
| 574 | bool WillCall() const { |
| 575 | return call_kind_ == kCallOnMainOnly || call_kind_ == kCallOnMainAndSlowPath; |
| 576 | } |
| 577 | |
| 578 | bool CallsOnSlowPath() const { |
| 579 | return call_kind_ == kCallOnSlowPath || call_kind_ == kCallOnMainAndSlowPath; |
| 580 | } |
| 581 | |
| 582 | bool OnlyCallsOnSlowPath() const { |
| 583 | return call_kind_ == kCallOnSlowPath; |
| 584 | } |
| 585 | |
| 586 | bool CallsOnMainAndSlowPath() const { |
| 587 | return call_kind_ == kCallOnMainAndSlowPath; |
| 588 | } |
| 589 | |
| 590 | bool NeedsSafepoint() const { |
| 591 | return CanCall(); |
| 592 | } |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 593 | |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 594 | void SetCustomSlowPathCallerSaves(const RegisterSet& caller_saves) { |
| 595 | DCHECK(OnlyCallsOnSlowPath()); |
| 596 | has_custom_slow_path_calling_convention_ = true; |
| 597 | custom_slow_path_caller_saves_ = caller_saves; |
| 598 | } |
| 599 | |
| 600 | bool HasCustomSlowPathCallingConvention() const { |
| 601 | return has_custom_slow_path_calling_convention_; |
| 602 | } |
| 603 | |
| 604 | const RegisterSet& GetCustomSlowPathCallerSaves() const { |
| 605 | DCHECK(HasCustomSlowPathCallingConvention()); |
| 606 | return custom_slow_path_caller_saves_; |
| 607 | } |
| 608 | |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 609 | void SetStackBit(uint32_t index) { |
| 610 | stack_mask_->SetBit(index); |
| 611 | } |
| 612 | |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 613 | void ClearStackBit(uint32_t index) { |
| 614 | stack_mask_->ClearBit(index); |
| 615 | } |
| 616 | |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 617 | void SetRegisterBit(uint32_t reg_id) { |
| 618 | register_mask_ |= (1 << reg_id); |
| 619 | } |
| 620 | |
| Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 621 | uint32_t GetRegisterMask() const { |
| 622 | return register_mask_; |
| 623 | } |
| 624 | |
| Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 625 | bool RegisterContainsObject(uint32_t reg_id) { |
| 626 | return RegisterSet::Contains(register_mask_, reg_id); |
| 627 | } |
| 628 | |
| 629 | void AddLiveRegister(Location location) { |
| 630 | live_registers_.Add(location); |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | BitVector* GetStackMask() const { |
| 634 | return stack_mask_; |
| 635 | } |
| 636 | |
| Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 637 | RegisterSet* GetLiveRegisters() { |
| 638 | return &live_registers_; |
| 639 | } |
| 640 | |
| Nicolas Geoffray | 87d0376 | 2014-11-19 15:17:56 +0000 | [diff] [blame] | 641 | size_t GetNumberOfLiveRegisters() const { |
| 642 | return live_registers_.GetNumberOfRegisters(); |
| 643 | } |
| 644 | |
| Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 645 | bool OutputUsesSameAs(uint32_t input_index) const { |
| 646 | return (input_index == 0) |
| Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 647 | && output_.IsUnallocated() |
| Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 648 | && (output_.GetPolicy() == Location::kSameAsFirstInput); |
| 649 | } |
| 650 | |
| 651 | bool IsFixedInput(uint32_t input_index) const { |
| Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 652 | Location input = inputs_[input_index]; |
| Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 653 | return input.IsRegister() |
| Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 654 | || input.IsFpuRegister() |
| 655 | || input.IsPair() |
| 656 | || input.IsStackSlot() |
| Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 657 | || input.IsDoubleStackSlot(); |
| Nicolas Geoffray | 7690562 | 2014-09-25 14:39:26 +0100 | [diff] [blame] | 658 | } |
| 659 | |
| Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 660 | bool OutputCanOverlapWithInputs() const { |
| Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 661 | return output_overlaps_ == Location::kOutputOverlap; |
| Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 662 | } |
| 663 | |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 664 | bool Intrinsified() const { |
| 665 | return intrinsified_; |
| 666 | } |
| 667 | |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 668 | private: |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 669 | LocationSummary(HInstruction* instruction, |
| 670 | CallKind call_kind, |
| 671 | bool intrinsified, |
| 672 | ArenaAllocator* allocator); |
| 673 | |
| Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 674 | ArenaVector<Location> inputs_; |
| 675 | ArenaVector<Location> temps_; |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 676 | const CallKind call_kind_; |
| 677 | // Whether these are locations for an intrinsified call. |
| 678 | const bool intrinsified_; |
| 679 | // Whether the slow path has default or custom calling convention. |
| 680 | bool has_custom_slow_path_calling_convention_; |
| Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 681 | // Whether the output overlaps with any of the inputs. If it overlaps, then it cannot |
| 682 | // share the same register as the inputs. |
| Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 683 | Location::OutputOverlap output_overlaps_; |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 684 | Location output_; |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 685 | |
| 686 | // Mask of objects that live in the stack. |
| 687 | BitVector* stack_mask_; |
| 688 | |
| 689 | // Mask of objects that live in register. |
| 690 | uint32_t register_mask_; |
| 691 | |
| 692 | // Registers that are in use at this position. |
| Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 693 | RegisterSet live_registers_; |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 694 | |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 695 | // Custom slow path caller saves. Valid only if indicated by slow_path_calling_convention_. |
| 696 | RegisterSet custom_slow_path_caller_saves_; |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 697 | |
| Matthew Gharrity | 2ac06bc | 2016-08-05 09:34:52 -0700 | [diff] [blame] | 698 | friend class RegisterAllocatorTest; |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 699 | DISALLOW_COPY_AND_ASSIGN(LocationSummary); |
| 700 | }; |
| 701 | |
| Nicolas Geoffray | 76716a6 | 2014-05-23 10:14:19 +0100 | [diff] [blame] | 702 | } // namespace art |
| 703 | |
| 704 | #endif // ART_COMPILER_OPTIMIZING_LOCATIONS_H_ |