From 5b65c475ad6fc14aa6260b26948d598554c00547 Mon Sep 17 00:00:00 2001 From: Daniel Sanders Date: Mon, 5 Aug 2019 19:50:25 +0000 Subject: [PATCH] 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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@367916 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/Register.h | 13 +++++++++++++ include/llvm/MC/MCRegister.h | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/include/llvm/CodeGen/Register.h b/include/llvm/CodeGen/Register.h index 640bd82bde2..73bca60ffcb 100644 --- a/include/llvm/CodeGen/Register.h +++ b/include/llvm/CodeGen/Register.h @@ -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 diff --git a/include/llvm/MC/MCRegister.h b/include/llvm/MC/MCRegister.h index 0e889c7adf7..2d4ac211f09 100644 --- a/include/llvm/MC/MCRegister.h +++ b/include/llvm/MC/MCRegister.h @@ -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 -- 2.40.0