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: