From: Daniel Sanders Date: Tue, 6 Aug 2019 00:53:47 +0000 (+0000) Subject: Re-commit Register/MCRegister: Add conversion operators to avoid use of implicit... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=141c03a94114331a4000d95f2136cd46375c5d95;p=llvm Re-commit Register/MCRegister: Add conversion operators to avoid use of implicit convert to unsigned. NFC Added two more conversions to satisfy MSVC and moved the declaration of MCPhysReg to MCRegister.h to enable that This reverts r367932 (git commit eac86ec25f5cd5d7a973c913d3c2ca8c90b24115) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@367965 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/CodeGen/Register.h b/include/llvm/CodeGen/Register.h index 640bd82bde2..73bca60ffcb 100644 --- a/include/llvm/CodeGen/Register.h +++ b/include/llvm/CodeGen/Register.h @@ -113,6 +113,19 @@ public: bool isValid() const { return Reg != 0; } + + /// Comparisons between register objects + bool operator==(const Register &Other) const { return Reg == Other.Reg; } + bool operator!=(const Register &Other) const { return Reg != Other.Reg; } + + /// Comparisons against register constants. E.g. + /// * R == AArch64::WZR + /// * R == 0 + /// * R == VirtRegMap::NO_PHYS_REG + bool operator==(unsigned Other) const { return Reg == Other; } + bool operator!=(unsigned Other) const { return Reg != Other; } + bool operator==(int Other) const { return Reg == unsigned(Other); } + bool operator!=(int Other) const { return Reg != unsigned(Other); } }; // Provide DenseMapInfo for Register diff --git a/include/llvm/MC/MCRegister.h b/include/llvm/MC/MCRegister.h index 0e889c7adf7..5ac7cc356b6 100644 --- a/include/llvm/MC/MCRegister.h +++ b/include/llvm/MC/MCRegister.h @@ -14,6 +14,10 @@ namespace llvm { +/// An unsigned integer type large enough to represent all physical registers, +/// but not necessarily virtual registers. +using MCPhysReg = uint16_t; + /// Wrapper class representing physical registers. Should be passed by value. class MCRegister { unsigned Reg; @@ -63,6 +67,22 @@ public: bool isValid() const { return Reg != 0; } + + /// Comparisons between register objects + bool operator==(const MCRegister &Other) const { return Reg == Other.Reg; } + bool operator!=(const MCRegister &Other) const { return Reg != Other.Reg; } + + /// Comparisons against register constants. E.g. + /// * R == AArch64::WZR + /// * R == 0 + /// * R == VirtRegMap::NO_PHYS_REG + bool operator==(unsigned Other) const { return Reg == Other; } + bool operator!=(unsigned Other) const { return Reg != Other; } + bool operator==(int Other) const { return Reg == unsigned(Other); } + bool operator!=(int Other) const { return Reg != unsigned(Other); } + // MSVC requires that we explicitly declare these two as well. + bool operator==(MCPhysReg Other) const { return Reg == unsigned(Other); } + bool operator!=(MCPhysReg Other) const { return Reg != unsigned(Other); } }; // Provide DenseMapInfo for MCRegister diff --git a/include/llvm/MC/MCRegisterInfo.h b/include/llvm/MC/MCRegisterInfo.h index 8671a861d2a..33ce3bd6aaf 100644 --- a/include/llvm/MC/MCRegisterInfo.h +++ b/include/llvm/MC/MCRegisterInfo.h @@ -25,10 +25,6 @@ namespace llvm { -/// An unsigned integer type large enough to represent all physical registers, -/// but not necessarily virtual registers. -using MCPhysReg = uint16_t; - /// MCRegisterClass - Base class of TargetRegisterClass. class MCRegisterClass { public: