Skip to content

[GISel] Remove remainder of the concept of an invalid RegisterBank. #71118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 2, 2023

Conversation

topperc
Copy link
Collaborator

@topperc topperc commented Nov 2, 2023

RegisterBank no longer has a default constructor so there's no way to create an invalid register bank.

Remove InvalidID and the isValid method.

Replace the one use of isValid outside of RegBank with a check that the ID matches so there's still some check of sanity.

RegisterBank no longer has a default constructor so there's no
way to create an invalid register bank.

Remove InvalidID and the isValid method.

Replace the one use of isValid outside of RegBank with a check
that the ID matches so there's still some check of sanity.
@llvmbot
Copy link
Member

llvmbot commented Nov 2, 2023

@llvm/pr-subscribers-llvm-regalloc

Author: Craig Topper (topperc)

Changes

RegisterBank no longer has a default constructor so there's no way to create an invalid register bank.

Remove InvalidID and the isValid method.

Replace the one use of isValid outside of RegBank with a check that the ID matches so there's still some check of sanity.


Full diff: https://github.com/llvm/llvm-project/pull/71118.diff

3 Files Affected:

  • (modified) llvm/include/llvm/CodeGen/RegisterBank.h (-8)
  • (modified) llvm/lib/CodeGen/RegisterBank.cpp (-11)
  • (modified) llvm/lib/CodeGen/RegisterBankInfo.cpp (+2-1)
diff --git a/llvm/include/llvm/CodeGen/RegisterBank.h b/llvm/include/llvm/CodeGen/RegisterBank.h
index ee295c7cdde0048..30e7aaf53f7839d 100644
--- a/llvm/include/llvm/CodeGen/RegisterBank.h
+++ b/llvm/include/llvm/CodeGen/RegisterBank.h
@@ -31,10 +31,6 @@ class RegisterBank {
   const char *Name;
   BitVector ContainedRegClasses;
 
-  /// Sentinel value used to recognize register bank not properly
-  /// initialized yet.
-  static const unsigned InvalidID;
-
   /// Only the RegisterBankInfo can initialize RegisterBank properly.
   friend RegisterBankInfo;
 
@@ -49,9 +45,6 @@ class RegisterBank {
   /// Should be used only for debugging purposes.
   const char *getName() const { return Name; }
 
-  /// 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.
   ///
@@ -63,7 +56,6 @@ class RegisterBank {
   /// Check whether this register bank covers \p RC.
   /// In other words, check if this register bank fully covers
   /// the registers that \p RC contains.
-  /// \pre isValid()
   bool covers(const TargetRegisterClass &RC) const;
 
   /// Check whether \p OtherRB is the same as this.
diff --git a/llvm/lib/CodeGen/RegisterBank.cpp b/llvm/lib/CodeGen/RegisterBank.cpp
index 8e0a0b0dc2824a0..b17ba261a17b95d 100644
--- a/llvm/lib/CodeGen/RegisterBank.cpp
+++ b/llvm/lib/CodeGen/RegisterBank.cpp
@@ -20,8 +20,6 @@
 
 using namespace llvm;
 
-const unsigned RegisterBank::InvalidID = UINT_MAX;
-
 RegisterBank::RegisterBank(unsigned ID, const char *Name,
                            const uint32_t *CoveredClasses,
                            unsigned NumRegClasses)
@@ -32,7 +30,6 @@ RegisterBank::RegisterBank(unsigned ID, const char *Name,
 
 bool RegisterBank::verify(const RegisterBankInfo &RBI,
                           const TargetRegisterInfo &TRI) const {
-  assert(isValid() && "Invalid register bank");
   for (unsigned RCId = 0, End = TRI.getNumRegClasses(); RCId != End; ++RCId) {
     const TargetRegisterClass &RC = *TRI.getRegClass(RCId);
 
@@ -61,16 +58,9 @@ bool RegisterBank::verify(const RegisterBankInfo &RBI,
 }
 
 bool RegisterBank::covers(const TargetRegisterClass &RC) const {
-  assert(isValid() && "RB hasn't been initialized yet");
   return ContainedRegClasses.test(RC.getID());
 }
 
-bool RegisterBank::isValid() const {
-  return ID != InvalidID && Name != nullptr &&
-         // A register bank that does not cover anything is useless.
-         !ContainedRegClasses.empty();
-}
-
 bool RegisterBank::operator==(const RegisterBank &OtherRB) const {
   // There must be only one instance of a given register bank alive
   // for the whole compilation.
@@ -92,7 +82,6 @@ void RegisterBank::print(raw_ostream &OS, bool IsForDebug,
   if (!IsForDebug)
     return;
   OS << "(ID:" << getID() << ")\n"
-     << "isValid:" << isValid() << '\n'
      << "Number of Covered register classes: " << ContainedRegClasses.count()
      << '\n';
   // Print all the subclasses if we can.
diff --git a/llvm/lib/CodeGen/RegisterBankInfo.cpp b/llvm/lib/CodeGen/RegisterBankInfo.cpp
index 658a09fd870094e..f9721d7d9386958 100644
--- a/llvm/lib/CodeGen/RegisterBankInfo.cpp
+++ b/llvm/lib/CodeGen/RegisterBankInfo.cpp
@@ -61,7 +61,8 @@ RegisterBankInfo::RegisterBankInfo(const RegisterBank **RegBanks,
 #ifndef NDEBUG
   for (unsigned Idx = 0, End = getNumRegBanks(); Idx != End; ++Idx) {
     assert(RegBanks[Idx] != nullptr && "Invalid RegisterBank");
-    assert(RegBanks[Idx]->isValid() && "RegisterBank should be valid");
+    assert(RegBanks[Idx]->getID() == Idx &&
+           "RegisterBank ID should match index");
   }
 #endif // NDEBUG
 }

@topperc topperc merged commit d22d42c into llvm:main Nov 2, 2023
@topperc topperc deleted the pr/invalid-regbank branch November 2, 2023 23:58
@qcolombet
Copy link
Collaborator

Awesome! Thanks @topperc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants