Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [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_UTILS_ARM64_MANAGED_REGISTER_ARM64_H_ |
| 18 | #define ART_COMPILER_UTILS_ARM64_MANAGED_REGISTER_ARM64_H_ |
| 19 | |
Alexandre Rames | 087930f | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 20 | #include "arch/arm64/registers_arm64.h" |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 21 | #include "base/logging.h" |
David Srbecky | 4fda4eb | 2016-02-05 13:34:46 +0000 | [diff] [blame] | 22 | #include "debug/dwarf/register.h" |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 23 | #include "utils/managed_register.h" |
| 24 | |
| 25 | namespace art { |
| 26 | namespace arm64 { |
| 27 | |
Alexandre Rames | 37c92df | 2014-10-17 14:35:27 +0100 | [diff] [blame] | 28 | const int kNumberOfXRegIds = kNumberOfXRegisters; |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 29 | const int kNumberOfWRegIds = kNumberOfWRegisters; |
| 30 | const int kNumberOfDRegIds = kNumberOfDRegisters; |
| 31 | const int kNumberOfSRegIds = kNumberOfSRegisters; |
| 32 | |
Alexandre Rames | 37c92df | 2014-10-17 14:35:27 +0100 | [diff] [blame] | 33 | const int kNumberOfRegIds = kNumberOfXRegIds + kNumberOfWRegIds + |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 34 | kNumberOfDRegIds + kNumberOfSRegIds; |
| 35 | |
| 36 | // Register ids map: |
Alexandre Rames | 37c92df | 2014-10-17 14:35:27 +0100 | [diff] [blame] | 37 | // [0..X[ core registers 64bit (enum XRegister) |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 38 | // [X..W[ core registers 32bit (enum WRegister) |
| 39 | // [W..D[ double precision VFP registers (enum DRegister) |
| 40 | // [D..S[ single precision VFP registers (enum SRegister) |
| 41 | // |
| 42 | // where: |
Alexandre Rames | 37c92df | 2014-10-17 14:35:27 +0100 | [diff] [blame] | 43 | // X = kNumberOfXRegIds |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 44 | // W = X + kNumberOfWRegIds |
| 45 | // D = W + kNumberOfDRegIds |
| 46 | // S = D + kNumberOfSRegIds |
| 47 | // |
| 48 | // An instance of class 'ManagedRegister' represents a single Arm64 |
| 49 | // register. A register can be one of the following: |
Alexandre Rames | 37c92df | 2014-10-17 14:35:27 +0100 | [diff] [blame] | 50 | // * core register 64bit context (enum XRegister) |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 51 | // * core register 32bit context (enum WRegister) |
| 52 | // * VFP double precision register (enum DRegister) |
| 53 | // * VFP single precision register (enum SRegister) |
| 54 | // |
| 55 | // There is a one to one mapping between ManagedRegister and register id. |
| 56 | |
| 57 | class Arm64ManagedRegister : public ManagedRegister { |
| 58 | public: |
Vladimir Marko | 3224838 | 2016-05-19 10:37:24 +0100 | [diff] [blame] | 59 | constexpr XRegister AsXRegister() const { |
Alexandre Rames | 37c92df | 2014-10-17 14:35:27 +0100 | [diff] [blame] | 60 | CHECK(IsXRegister()); |
| 61 | return static_cast<XRegister>(id_); |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 62 | } |
| 63 | |
Vladimir Marko | 3224838 | 2016-05-19 10:37:24 +0100 | [diff] [blame] | 64 | constexpr WRegister AsWRegister() const { |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 65 | CHECK(IsWRegister()); |
Alexandre Rames | 37c92df | 2014-10-17 14:35:27 +0100 | [diff] [blame] | 66 | return static_cast<WRegister>(id_ - kNumberOfXRegIds); |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 67 | } |
| 68 | |
Vladimir Marko | 3224838 | 2016-05-19 10:37:24 +0100 | [diff] [blame] | 69 | constexpr DRegister AsDRegister() const { |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 70 | CHECK(IsDRegister()); |
Alexandre Rames | 37c92df | 2014-10-17 14:35:27 +0100 | [diff] [blame] | 71 | return static_cast<DRegister>(id_ - kNumberOfXRegIds - kNumberOfWRegIds); |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 72 | } |
| 73 | |
Vladimir Marko | 3224838 | 2016-05-19 10:37:24 +0100 | [diff] [blame] | 74 | constexpr SRegister AsSRegister() const { |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 75 | CHECK(IsSRegister()); |
Alexandre Rames | 37c92df | 2014-10-17 14:35:27 +0100 | [diff] [blame] | 76 | return static_cast<SRegister>(id_ - kNumberOfXRegIds - kNumberOfWRegIds - |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 77 | kNumberOfDRegIds); |
| 78 | } |
| 79 | |
Vladimir Marko | 3224838 | 2016-05-19 10:37:24 +0100 | [diff] [blame] | 80 | constexpr WRegister AsOverlappingWRegister() const { |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 81 | CHECK(IsValidManagedRegister()); |
Alexandre Rames | a304f97 | 2014-10-17 14:35:27 +0100 | [diff] [blame] | 82 | if (IsZeroRegister()) return WZR; |
Alexandre Rames | 37c92df | 2014-10-17 14:35:27 +0100 | [diff] [blame] | 83 | return static_cast<WRegister>(AsXRegister()); |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 84 | } |
| 85 | |
Vladimir Marko | 3224838 | 2016-05-19 10:37:24 +0100 | [diff] [blame] | 86 | constexpr XRegister AsOverlappingXRegister() const { |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 87 | CHECK(IsValidManagedRegister()); |
Alexandre Rames | 37c92df | 2014-10-17 14:35:27 +0100 | [diff] [blame] | 88 | return static_cast<XRegister>(AsWRegister()); |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 89 | } |
| 90 | |
Vladimir Marko | 3224838 | 2016-05-19 10:37:24 +0100 | [diff] [blame] | 91 | constexpr SRegister AsOverlappingSRegister() const { |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 92 | CHECK(IsValidManagedRegister()); |
| 93 | return static_cast<SRegister>(AsDRegister()); |
| 94 | } |
| 95 | |
Vladimir Marko | 3224838 | 2016-05-19 10:37:24 +0100 | [diff] [blame] | 96 | constexpr DRegister AsOverlappingDRegister() const { |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 97 | CHECK(IsValidManagedRegister()); |
| 98 | return static_cast<DRegister>(AsSRegister()); |
| 99 | } |
| 100 | |
Vladimir Marko | 3224838 | 2016-05-19 10:37:24 +0100 | [diff] [blame] | 101 | constexpr bool IsXRegister() const { |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 102 | CHECK(IsValidManagedRegister()); |
Alexandre Rames | 37c92df | 2014-10-17 14:35:27 +0100 | [diff] [blame] | 103 | return (0 <= id_) && (id_ < kNumberOfXRegIds); |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 104 | } |
| 105 | |
Vladimir Marko | 3224838 | 2016-05-19 10:37:24 +0100 | [diff] [blame] | 106 | constexpr bool IsWRegister() const { |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 107 | CHECK(IsValidManagedRegister()); |
Alexandre Rames | 37c92df | 2014-10-17 14:35:27 +0100 | [diff] [blame] | 108 | const int test = id_ - kNumberOfXRegIds; |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 109 | return (0 <= test) && (test < kNumberOfWRegIds); |
| 110 | } |
| 111 | |
Vladimir Marko | 3224838 | 2016-05-19 10:37:24 +0100 | [diff] [blame] | 112 | constexpr bool IsDRegister() const { |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 113 | CHECK(IsValidManagedRegister()); |
Alexandre Rames | 37c92df | 2014-10-17 14:35:27 +0100 | [diff] [blame] | 114 | const int test = id_ - (kNumberOfXRegIds + kNumberOfWRegIds); |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 115 | return (0 <= test) && (test < kNumberOfDRegIds); |
| 116 | } |
| 117 | |
Vladimir Marko | 3224838 | 2016-05-19 10:37:24 +0100 | [diff] [blame] | 118 | constexpr bool IsSRegister() const { |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 119 | CHECK(IsValidManagedRegister()); |
Vladimir Marko | 80afd02 | 2015-05-19 18:08:00 +0100 | [diff] [blame] | 120 | const int test = id_ - (kNumberOfXRegIds + kNumberOfWRegIds + kNumberOfDRegIds); |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 121 | return (0 <= test) && (test < kNumberOfSRegIds); |
| 122 | } |
| 123 | |
Vladimir Marko | 3224838 | 2016-05-19 10:37:24 +0100 | [diff] [blame] | 124 | constexpr bool IsGPRegister() const { |
Alexandre Rames | 37c92df | 2014-10-17 14:35:27 +0100 | [diff] [blame] | 125 | return IsXRegister() || IsWRegister(); |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 126 | } |
| 127 | |
Vladimir Marko | 3224838 | 2016-05-19 10:37:24 +0100 | [diff] [blame] | 128 | constexpr bool IsFPRegister() const { |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 129 | return IsDRegister() || IsSRegister(); |
| 130 | } |
| 131 | |
Vladimir Marko | 3224838 | 2016-05-19 10:37:24 +0100 | [diff] [blame] | 132 | constexpr bool IsSameType(Arm64ManagedRegister test) const { |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 133 | CHECK(IsValidManagedRegister() && test.IsValidManagedRegister()); |
| 134 | return |
Alexandre Rames | 37c92df | 2014-10-17 14:35:27 +0100 | [diff] [blame] | 135 | (IsXRegister() && test.IsXRegister()) || |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 136 | (IsWRegister() && test.IsWRegister()) || |
| 137 | (IsDRegister() && test.IsDRegister()) || |
| 138 | (IsSRegister() && test.IsSRegister()); |
| 139 | } |
| 140 | |
| 141 | // Returns true if the two managed-registers ('this' and 'other') overlap. |
| 142 | // Either managed-register may be the NoRegister. If both are the NoRegister |
| 143 | // then false is returned. |
| 144 | bool Overlaps(const Arm64ManagedRegister& other) const; |
| 145 | |
| 146 | void Print(std::ostream& os) const; |
| 147 | |
Vladimir Marko | 3224838 | 2016-05-19 10:37:24 +0100 | [diff] [blame] | 148 | static constexpr Arm64ManagedRegister FromXRegister(XRegister r) { |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 149 | CHECK_NE(r, kNoRegister); |
| 150 | return FromRegId(r); |
| 151 | } |
| 152 | |
Vladimir Marko | 3224838 | 2016-05-19 10:37:24 +0100 | [diff] [blame] | 153 | static constexpr Arm64ManagedRegister FromWRegister(WRegister r) { |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 154 | CHECK_NE(r, kNoWRegister); |
Alexandre Rames | 37c92df | 2014-10-17 14:35:27 +0100 | [diff] [blame] | 155 | return FromRegId(r + kNumberOfXRegIds); |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 156 | } |
| 157 | |
Vladimir Marko | 3224838 | 2016-05-19 10:37:24 +0100 | [diff] [blame] | 158 | static constexpr Arm64ManagedRegister FromDRegister(DRegister r) { |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 159 | CHECK_NE(r, kNoDRegister); |
Alexandre Rames | 37c92df | 2014-10-17 14:35:27 +0100 | [diff] [blame] | 160 | return FromRegId(r + (kNumberOfXRegIds + kNumberOfWRegIds)); |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 161 | } |
| 162 | |
Vladimir Marko | 3224838 | 2016-05-19 10:37:24 +0100 | [diff] [blame] | 163 | static constexpr Arm64ManagedRegister FromSRegister(SRegister r) { |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 164 | CHECK_NE(r, kNoSRegister); |
Alexandre Rames | 37c92df | 2014-10-17 14:35:27 +0100 | [diff] [blame] | 165 | return FromRegId(r + (kNumberOfXRegIds + kNumberOfWRegIds + |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 166 | kNumberOfDRegIds)); |
| 167 | } |
| 168 | |
| 169 | // Returns the X register overlapping W register r. |
Vladimir Marko | 3224838 | 2016-05-19 10:37:24 +0100 | [diff] [blame] | 170 | static constexpr Arm64ManagedRegister FromWRegisterX(WRegister r) { |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 171 | CHECK_NE(r, kNoWRegister); |
| 172 | return FromRegId(r); |
| 173 | } |
| 174 | |
| 175 | // Return the D register overlapping S register r. |
Vladimir Marko | 3224838 | 2016-05-19 10:37:24 +0100 | [diff] [blame] | 176 | static constexpr Arm64ManagedRegister FromSRegisterD(SRegister r) { |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 177 | CHECK_NE(r, kNoSRegister); |
Alexandre Rames | 37c92df | 2014-10-17 14:35:27 +0100 | [diff] [blame] | 178 | return FromRegId(r + (kNumberOfXRegIds + kNumberOfWRegIds)); |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | private: |
Vladimir Marko | 3224838 | 2016-05-19 10:37:24 +0100 | [diff] [blame] | 182 | constexpr bool IsValidManagedRegister() const { |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 183 | return (0 <= id_) && (id_ < kNumberOfRegIds); |
| 184 | } |
| 185 | |
Vladimir Marko | 3224838 | 2016-05-19 10:37:24 +0100 | [diff] [blame] | 186 | constexpr bool IsStackPointer() const { |
Alexandre Rames | 37c92df | 2014-10-17 14:35:27 +0100 | [diff] [blame] | 187 | return IsXRegister() && (id_ == SP); |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 188 | } |
| 189 | |
Vladimir Marko | 3224838 | 2016-05-19 10:37:24 +0100 | [diff] [blame] | 190 | constexpr bool IsZeroRegister() const { |
Alexandre Rames | 37c92df | 2014-10-17 14:35:27 +0100 | [diff] [blame] | 191 | return IsXRegister() && (id_ == XZR); |
Serban Constantinescu | 1552373 | 2014-04-02 13:18:05 +0100 | [diff] [blame] | 192 | } |
| 193 | |
Vladimir Marko | 3224838 | 2016-05-19 10:37:24 +0100 | [diff] [blame] | 194 | constexpr int RegId() const { |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 195 | CHECK(!IsNoRegister()); |
| 196 | return id_; |
| 197 | } |
| 198 | |
| 199 | int RegNo() const; |
| 200 | int RegIdLow() const; |
| 201 | int RegIdHigh() const; |
| 202 | |
| 203 | friend class ManagedRegister; |
| 204 | |
Vladimir Marko | 3224838 | 2016-05-19 10:37:24 +0100 | [diff] [blame] | 205 | explicit constexpr Arm64ManagedRegister(int reg_id) : ManagedRegister(reg_id) {} |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 206 | |
Vladimir Marko | 3224838 | 2016-05-19 10:37:24 +0100 | [diff] [blame] | 207 | static constexpr Arm64ManagedRegister FromRegId(int reg_id) { |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 208 | Arm64ManagedRegister reg(reg_id); |
| 209 | CHECK(reg.IsValidManagedRegister()); |
| 210 | return reg; |
| 211 | } |
| 212 | }; |
| 213 | |
| 214 | std::ostream& operator<<(std::ostream& os, const Arm64ManagedRegister& reg); |
| 215 | |
| 216 | } // namespace arm64 |
| 217 | |
Vladimir Marko | 3224838 | 2016-05-19 10:37:24 +0100 | [diff] [blame] | 218 | constexpr inline arm64::Arm64ManagedRegister ManagedRegister::AsArm64() const { |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 219 | arm64::Arm64ManagedRegister reg(id_); |
| 220 | CHECK(reg.IsNoRegister() || reg.IsValidManagedRegister()); |
| 221 | return reg; |
| 222 | } |
| 223 | |
| 224 | } // namespace art |
| 225 | |
| 226 | #endif // ART_COMPILER_UTILS_ARM64_MANAGED_REGISTER_ARM64_H_ |