[llvm] r367916 - 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 12:50:25 PDT 2019
Author: dsanders
Date: Mon Aug 5 12:50:25 2019
New Revision: 367916
URL: http://llvm.org/viewvc/llvm-project?rev=367916&view=rev
Log:
Register/MCRegister: Add conversion operators to avoid use of implicit convert to unsigned. NFC
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
Modified:
llvm/trunk/include/llvm/CodeGen/Register.h
llvm/trunk/include/llvm/MC/MCRegister.h
Modified: llvm/trunk/include/llvm/CodeGen/Register.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/Register.h?rev=367916&r1=367915&r2=367916&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/Register.h (original)
+++ llvm/trunk/include/llvm/CodeGen/Register.h Mon Aug 5 12:50:25 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=367916&r1=367915&r2=367916&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCRegister.h (original)
+++ llvm/trunk/include/llvm/MC/MCRegister.h Mon Aug 5 12:50:25 2019
@@ -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
More information about the llvm-commits
mailing list