[PATCH] D65678: Register/MCRegister: Add conversion operators to avoid use of implicit convert to unsigned. NFC
Daniel Sanders via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 2 15:02:06 PDT 2019
dsanders created this revision.
dsanders added a reviewer: arsenm.
Herald added a subscriber: wdng.
Herald added a project: LLVM.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D65678
Files:
llvm/include/llvm/CodeGen/Register.h
llvm/include/llvm/MC/MCRegister.h
Index: llvm/include/llvm/MC/MCRegister.h
===================================================================
--- llvm/include/llvm/MC/MCRegister.h
+++ llvm/include/llvm/MC/MCRegister.h
@@ -63,6 +63,19 @@
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
Index: llvm/include/llvm/CodeGen/Register.h
===================================================================
--- llvm/include/llvm/CodeGen/Register.h
+++ llvm/include/llvm/CodeGen/Register.h
@@ -113,6 +113,19 @@
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65678.213134.patch
Type: text/x-patch
Size: 1837 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190802/c715826f/attachment.bin>
More information about the llvm-commits
mailing list