diff options
| author | Quentin Colombet <qcolombet@apple.com> | 2016-04-05 21:40:43 +0000 |
|---|---|---|
| committer | Quentin Colombet <qcolombet@apple.com> | 2016-04-05 21:40:43 +0000 |
| commit | c94fbee9f66ea7f5777accf421096808bbb083b1 (patch) | |
| tree | a674fd273062f188f133abc37aca46c60d738e78 | |
| parent | 2d390b6c8b1bdffbe5db91fa8372768415880cb4 (diff) | |
| download | bcm5719-llvm-c94fbee9f66ea7f5777accf421096808bbb083b1.tar.gz bcm5719-llvm-c94fbee9f66ea7f5777accf421096808bbb083b1.zip | |
[RegisterBank] Add printable capabilities for future debugging.
llvm-svn: 265473
| -rw-r--r-- | llvm/include/llvm/CodeGen/GlobalISel/RegisterBank.h | 18 | ||||
| -rw-r--r-- | llvm/lib/CodeGen/GlobalISel/RegisterBank.cpp | 34 |
2 files changed, 52 insertions, 0 deletions
diff --git a/llvm/include/llvm/CodeGen/GlobalISel/RegisterBank.h b/llvm/include/llvm/CodeGen/GlobalISel/RegisterBank.h index 57a37025583..087affc25e4 100644 --- a/llvm/include/llvm/CodeGen/GlobalISel/RegisterBank.h +++ b/llvm/include/llvm/CodeGen/GlobalISel/RegisterBank.h @@ -19,6 +19,7 @@ namespace llvm { // Forward declarations. class RegisterBankInfo; +class raw_ostream; class TargetRegisterClass; class TargetRegisterInfo; @@ -73,7 +74,24 @@ public: bool operator!=(const RegisterBank &OtherRB) const { return !this->operator==(OtherRB); } + + /// Dump the register mask on dbgs() stream. + /// The dump is verbose. + void dump(const TargetRegisterInfo *TRI = nullptr) const; + + /// Print the register mask on OS. + /// If IsForDebug is false, then only the name of the register bank + /// is printed. Otherwise, all the fields are printing. + /// TRI is then used to print the name of the register classes that + /// this register bank covers. + void print(raw_ostream &OS, bool IsForDebug = false, + const TargetRegisterInfo *TRI = nullptr) const; }; + +inline raw_ostream &operator<<(raw_ostream &OS, const RegisterBank &RegBank) { + RegBank.print(OS); + return OS; +} } // End namespace llvm. #endif diff --git a/llvm/lib/CodeGen/GlobalISel/RegisterBank.cpp b/llvm/lib/CodeGen/GlobalISel/RegisterBank.cpp index 4e0aa080039..9557bd0df78 100644 --- a/llvm/lib/CodeGen/GlobalISel/RegisterBank.cpp +++ b/llvm/lib/CodeGen/GlobalISel/RegisterBank.cpp @@ -48,3 +48,37 @@ bool RegisterBank::operator==(const RegisterBank &OtherRB) const { "ID does not uniquely identify a RegisterBank"); return &OtherRB == this; } + +void RegisterBank::dump(const TargetRegisterInfo *TRI) const { + print(dbgs(), /* IsForDebug */ true, TRI); +} + +void RegisterBank::print(raw_ostream &OS, bool IsForDebug, + const TargetRegisterInfo *TRI) const { + OS << getName(); + if (!IsForDebug) + return; + OS << "(ID:" << getID() << ", Size:" << getSize() << ")\n" + << "isValid:" << isValid() << '\n' + << "Number of Covered register classes: " << ContainedRegClasses.count() + << '\n'; + // Print all the subclasses if we can. + // This register classes may not be properly initialized yet. + if (!TRI || ContainedRegClasses.empty()) + return; + assert(ContainedRegClasses.size() == TRI->getNumRegClasses() && + "TRI does not match the initialization process?"); + bool IsFirst = true; + OS << "Covered register classes:\n"; + for (unsigned RCId = 0, End = TRI->getNumRegClasses(); RCId != End; ++RCId) { + const TargetRegisterClass &RC = *TRI->getRegClass(RCId); + + if (!contains(RC)) + continue; + + if (!IsFirst) + OS << ", "; + OS << TRI->getRegClassName(&RC); + IsFirst = false; + } +} |

