summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Sanders <daniel_l_sanders@apple.com>2019-08-05 19:50:25 +0000
committerDaniel Sanders <daniel_l_sanders@apple.com>2019-08-05 19:50:25 +0000
commitaa15ec3c231717826e3c262b5ef9813d2fb5cadb (patch)
tree7568deb0949012db2212e64fe18cef829e6780b1
parent36eab654c5c3e60329e731ed21d17f31ec70df3e (diff)
downloadbcm5719-llvm-aa15ec3c231717826e3c262b5ef9813d2fb5cadb.tar.gz
bcm5719-llvm-aa15ec3c231717826e3c262b5ef9813d2fb5cadb.zip
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 llvm-svn: 367916
-rw-r--r--llvm/include/llvm/CodeGen/Register.h13
-rw-r--r--llvm/include/llvm/MC/MCRegister.h13
2 files changed, 26 insertions, 0 deletions
diff --git a/llvm/include/llvm/CodeGen/Register.h b/llvm/include/llvm/CodeGen/Register.h
index 640bd82bde2..73bca60ffcb 100644
--- a/llvm/include/llvm/CodeGen/Register.h
+++ b/llvm/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/llvm/include/llvm/MC/MCRegister.h b/llvm/include/llvm/MC/MCRegister.h
index 0e889c7adf7..2d4ac211f09 100644
--- a/llvm/include/llvm/MC/MCRegister.h
+++ b/llvm/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
OpenPOWER on IntegriCloud