[llvm] r367965 - Re-commit Register/MCRegister: Add conversion operators to avoid use of implicit convert to unsigned. NFC

Daniel Sanders via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 5 17:53:47 PDT 2019


Author: dsanders
Date: Mon Aug  5 17:53:47 2019
New Revision: 367965

URL: http://llvm.org/viewvc/llvm-project?rev=367965&view=rev
Log:
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)

Modified:
    llvm/trunk/include/llvm/CodeGen/Register.h
    llvm/trunk/include/llvm/MC/MCRegister.h
    llvm/trunk/include/llvm/MC/MCRegisterInfo.h

Modified: llvm/trunk/include/llvm/CodeGen/Register.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/Register.h?rev=367965&r1=367964&r2=367965&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/Register.h (original)
+++ llvm/trunk/include/llvm/CodeGen/Register.h Mon Aug  5 17:53:47 2019
@@ -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

Modified: llvm/trunk/include/llvm/MC/MCRegister.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCRegister.h?rev=367965&r1=367964&r2=367965&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCRegister.h (original)
+++ llvm/trunk/include/llvm/MC/MCRegister.h Mon Aug  5 17:53:47 2019
@@ -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

Modified: llvm/trunk/include/llvm/MC/MCRegisterInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCRegisterInfo.h?rev=367965&r1=367964&r2=367965&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCRegisterInfo.h (original)
+++ llvm/trunk/include/llvm/MC/MCRegisterInfo.h Mon Aug  5 17:53:47 2019
@@ -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:




More information about the llvm-commits mailing list