diff options
author | Quentin Colombet <qcolombet@apple.com> | 2016-04-05 20:48:32 +0000 |
---|---|---|
committer | Quentin Colombet <qcolombet@apple.com> | 2016-04-05 20:48:32 +0000 |
commit | c4db2ad5b87de895e74c86536ddd6b754ad48afe (patch) | |
tree | ebe13f37c5e34dd3c7d494bacc41f1dacee4a3a4 | |
parent | 91d3cfed785b46723ebbf8197f70aa0f854c05d7 (diff) | |
download | bcm5719-llvm-c4db2ad5b87de895e74c86536ddd6b754ad48afe.tar.gz bcm5719-llvm-c4db2ad5b87de895e74c86536ddd6b754ad48afe.zip |
[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.
llvm-svn: 265460
-rw-r--r-- | llvm/include/llvm/CodeGen/GlobalISel/RegisterBank.h | 15 | ||||
-rw-r--r-- | llvm/lib/CodeGen/GlobalISel/RegisterBank.cpp | 13 |
2 files changed, 25 insertions, 3 deletions
diff --git a/llvm/include/llvm/CodeGen/GlobalISel/RegisterBank.h b/llvm/include/llvm/CodeGen/GlobalISel/RegisterBank.h index 9c1d25d5e0e..57a37025583 100644 --- a/llvm/include/llvm/CodeGen/GlobalISel/RegisterBank.h +++ b/llvm/include/llvm/CodeGen/GlobalISel/RegisterBank.h @@ -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. diff --git a/llvm/lib/CodeGen/GlobalISel/RegisterBank.cpp b/llvm/lib/CodeGen/GlobalISel/RegisterBank.cpp index 5c86e426e1b..4e0aa080039 100644 --- a/llvm/lib/CodeGen/GlobalISel/RegisterBank.cpp +++ b/llvm/lib/CodeGen/GlobalISel/RegisterBank.cpp @@ -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 TargetRegisterInfo &TRI) const { } 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 { |