]> granicus.if.org Git - llvm/commitdiff
Register/MCRegister: Add conversion operators to avoid use of implicit convert to...
authorDaniel Sanders <daniel_l_sanders@apple.com>
Mon, 5 Aug 2019 19:50:25 +0000 (19:50 +0000)
committerDaniel Sanders <daniel_l_sanders@apple.com>
Mon, 5 Aug 2019 19:50:25 +0000 (19:50 +0000)
Summary:
This has no functional effect but makes it more obvious which parts of the
compiler do not use Register/MCRegister when you mark the implicit conversion
deprecated.

Implicit conversions for comparisons accounted for ~20% (~3k of ~13k) of
the implicit conversions when I first measured it. I haven't maintained
those numbers as other patches have landed though so it may be out of date.

Reviewers: arsenm

Reviewed By: arsenm

Subscribers: wdng, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D65678

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@367916 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/Register.h
include/llvm/MC/MCRegister.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..2d4ac211f093f0c7533d67a44877a09d4d43238b 100644 (file)
@@ -63,6 +63,19 @@ 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); }
 };
 
 // Provide DenseMapInfo for MCRegister