1 /* 2 * Copyright (C) 2011 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_MANAGED_REGISTER_H_ 18 #define ART_COMPILER_UTILS_MANAGED_REGISTER_H_ 19 20 #include <type_traits> 21 #include <vector> 22 23 #include "base/macros.h" 24 #include "base/value_object.h" 25 26 namespace art HIDDEN { 27 28 namespace arm { 29 class ArmManagedRegister; 30 } // namespace arm 31 namespace arm64 { 32 class Arm64ManagedRegister; 33 } // namespace arm64 34 35 namespace riscv64 { 36 class Riscv64ManagedRegister; 37 } // namespace riscv64 38 39 namespace x86 { 40 class X86ManagedRegister; 41 } // namespace x86 42 43 namespace x86_64 { 44 class X86_64ManagedRegister; 45 } // namespace x86_64 46 47 class ManagedRegister : public ValueObject { 48 public: 49 // ManagedRegister is a value class. There exists no method to change the 50 // internal state. We therefore allow a copy constructor and an 51 // assignment-operator. 52 constexpr ManagedRegister(const ManagedRegister& other) = default; 53 54 ManagedRegister& operator=(const ManagedRegister& other) = default; 55 56 constexpr arm::ArmManagedRegister AsArm() const; 57 constexpr arm64::Arm64ManagedRegister AsArm64() const; 58 constexpr riscv64::Riscv64ManagedRegister AsRiscv64() const; 59 constexpr x86::X86ManagedRegister AsX86() const; 60 constexpr x86_64::X86_64ManagedRegister AsX86_64() const; 61 62 // It is valid to invoke Equals on and with a NoRegister. Equals(const ManagedRegister & other)63 constexpr bool Equals(const ManagedRegister& other) const { 64 return id_ == other.id_; 65 } 66 IsRegister()67 constexpr bool IsRegister() const { 68 return id_ != kNoRegister; 69 } 70 IsNoRegister()71 constexpr bool IsNoRegister() const { 72 return id_ == kNoRegister; 73 } 74 NoRegister()75 static constexpr ManagedRegister NoRegister() { 76 return ManagedRegister(); 77 } 78 RegId()79 constexpr int RegId() const { return id_; } ManagedRegister(int reg_id)80 explicit constexpr ManagedRegister(int reg_id) : id_(reg_id) { } 81 82 protected: 83 static constexpr int kNoRegister = -1; 84 ManagedRegister()85 constexpr ManagedRegister() : id_(kNoRegister) { } 86 87 int id_; 88 }; 89 90 static_assert(std::is_trivially_copyable<ManagedRegister>::value, 91 "ManagedRegister should be trivially copyable"); 92 93 } // namespace art 94 95 #endif // ART_COMPILER_UTILS_MANAGED_REGISTER_H_ 96