[llvm] r265460 - [RegisterBank] Provide a way to check if a register bank is valid.
Quentin Colombet via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 5 13:48:34 PDT 2016
Author: qcolombet
Date: Tue Apr 5 15:48:32 2016
New Revision: 265460
URL: http://llvm.org/viewvc/llvm-project?rev=265460&view=rev
Log:
[RegisterBank] Provide a way to check if a register bank is valid.
Change the default constructor to create invalid object.
The target will have to properly initialize the register banks before
using them.
Modified:
llvm/trunk/include/llvm/CodeGen/GlobalISel/RegisterBank.h
llvm/trunk/lib/CodeGen/GlobalISel/RegisterBank.cpp
Modified: llvm/trunk/include/llvm/CodeGen/GlobalISel/RegisterBank.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/GlobalISel/RegisterBank.h?rev=265460&r1=265459&r2=265460&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/GlobalISel/RegisterBank.h (original)
+++ llvm/trunk/include/llvm/CodeGen/GlobalISel/RegisterBank.h Tue Apr 5 15:48:32 2016
@@ -30,10 +30,17 @@ private:
unsigned ID;
const char *Name;
unsigned Size;
- BitVector ContainedRegClass;
+ BitVector ContainedRegClasses;
+
+ /// Sentinel value used to recognize register bank not properly
+ /// initialized yet.
+ static const unsigned InvalidID;
/// Only the RegisterBankInfo can create RegisterBank.
- RegisterBank() = default;
+ /// The default constructor will leave the object in
+ /// an invalid state. I.e. isValid() == false.
+ /// The field must be updated to fix that.
+ RegisterBank();
friend RegisterBankInfo;
@@ -48,6 +55,9 @@ public:
/// Get the maximal size in bits that fits in this register bank.
unsigned getSize() const { return Size; }
+ /// Check whether this instance is ready to be used.
+ bool isValid() const;
+
/// Check if this register bank is valid. In other words,
/// if it has been properly constructed.
void verify(const TargetRegisterInfo &TRI) const;
@@ -55,6 +65,7 @@ public:
/// Check whether this register bank contains \p RC.
/// In other words, check if this register bank fully covers
/// the registers that \p RC contains.
+ /// \pre isValid()
bool contains(const TargetRegisterClass &RC) const;
/// Check whether \p OtherRB is the same as this.
Modified: llvm/trunk/lib/CodeGen/GlobalISel/RegisterBank.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/RegisterBank.cpp?rev=265460&r1=265459&r2=265460&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/RegisterBank.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/RegisterBank.cpp Tue Apr 5 15:48:32 2016
@@ -18,6 +18,10 @@
using namespace llvm;
+const unsigned RegisterBank::InvalidID = UINT_MAX;
+
+RegisterBank::RegisterBank() : ID(InvalidID), Name(nullptr), Size(0) {}
+
void RegisterBank::verify(const TargetRegisterInfo &TRI) const {
// Verify that the Size of the register bank is big enough to cover all the
// register classes it covers.
@@ -26,7 +30,14 @@ void RegisterBank::verify(const TargetRe
}
bool RegisterBank::contains(const TargetRegisterClass &RC) const {
- return ContainedRegClass.test(RC.getID());
+ assert(isValid() && "RB hasn't been initialized yet");
+ return ContainedRegClasses.test(RC.getID());
+}
+
+bool RegisterBank::isValid() const {
+ return ID != InvalidID && Name != nullptr && Size != 0 &&
+ // A register bank that does not cover anything is useless.
+ !ContainedRegClasses.empty();
}
bool RegisterBank::operator==(const RegisterBank &OtherRB) const {
More information about the llvm-commits
mailing list