]> granicus.if.org Git - llvm/commitdiff
Re-commit Register/MCRegister: Add conversion operators to avoid use of implicit...
authorDaniel Sanders <daniel_l_sanders@apple.com>
Tue, 6 Aug 2019 00:53:47 +0000 (00:53 +0000)
committerDaniel Sanders <daniel_l_sanders@apple.com>
Tue, 6 Aug 2019 00:53:47 +0000 (00:53 +0000)
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

include/llvm/CodeGen/Register.h
include/llvm/MC/MCRegister.h
include/llvm/MC/MCRegisterInfo.h

index 640bd82bde2c9c51c49db5e3b59ab4e286567e18..73bca60ffcb4fb955a54c30fbc54a2052f3bbd73 100644 (file)
@@ -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
index 0e889c7adf7a8081304d2e2b1ab0237409c16fcc..5ac7cc356b66a61cda392a817a2ff14afffb03b6 100644 (file)
 
 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
index 8671a861d2ac101ebf0fdb6c891c7e083de54964..33ce3bd6aaf07db7a552a8b4059f8f5285b0ef03 100644 (file)
 
 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: