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