Add MachineBasicBlock::getName, and use it in place of getBasicBlock()->getName.
authorJakob Stoklund Olesen <stoklund@2pi.dk>
Fri, 20 Nov 2009 01:17:03 +0000 (01:17 +0000)
committerJakob Stoklund Olesen <stoklund@2pi.dk>
Fri, 20 Nov 2009 01:17:03 +0000 (01:17 +0000)
Fix debug code that assumes getBasicBlock never returns NULL.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@89428 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/MachineBasicBlock.h
lib/CodeGen/LiveIntervalAnalysis.cpp
lib/CodeGen/MachineBasicBlock.cpp
lib/CodeGen/MachineLICM.cpp
lib/CodeGen/MachineVerifier.cpp
lib/CodeGen/SimpleRegisterCoalescing.cpp
lib/CodeGen/VirtRegRewriter.cpp

index bb50b5df4ca81ac5b9883908c7592d74402e3cae..78662784eb517c3a9019de9a72a9183d939874ee 100644 (file)
@@ -92,10 +92,15 @@ class MachineBasicBlock : public ilist_node<MachineBasicBlock> {
 
 public:
   /// getBasicBlock - Return the LLVM basic block that this instance
-  /// corresponded to originally.
+  /// corresponded to originally. Note that this may be NULL if this instance
+  /// does not correspond directly to an LLVM basic block.
   ///
   const BasicBlock *getBasicBlock() const { return BB; }
 
+  /// getName - Return the name of the corresponding LLVM basic block, or
+  /// "(null)".
+  StringRef getName() const;
+
   /// hasAddressTaken - Test whether this block is potentially the target
   /// of an indirect branch.
   bool hasAddressTaken() const { return AddressTaken; }
index bbfc82b5d96d259deb66b2f09932768f57d29d44..56a9c561244dd1895205452384d4bd9b686bbbb7 100644 (file)
@@ -136,7 +136,7 @@ void LiveIntervals::printInstrs(raw_ostream &OS) const {
 
   for (MachineFunction::iterator mbbi = mf_->begin(), mbbe = mf_->end();
        mbbi != mbbe; ++mbbi) {
-    OS << ((Value*)mbbi->getBasicBlock())->getName() << ":\n";
+    OS << mbbi->getName() << ":\n";
     for (MachineBasicBlock::iterator mii = mbbi->begin(),
            mie = mbbi->end(); mii != mie; ++mii) {
       OS << getInstructionIndex(mii) << '\t' << *mii;
@@ -658,7 +658,7 @@ void LiveIntervals::computeIntervals() {
     MachineBasicBlock *MBB = MBBI;
     // Track the index of the current machine instr.
     SlotIndex MIIndex = getMBBStartIdx(MBB);
-    DEBUG(errs() << ((Value*)MBB->getBasicBlock())->getName() << ":\n");
+    DEBUG(errs() << MBB->getName() << ":\n");
 
     MachineBasicBlock::iterator MI = MBB->begin(), miEnd = MBB->end();
 
index cd52825d21f12cf5449df5a2f6543d59a76ba773..2e6bd8a94b7b9d10a149853fb37a5ee33265dcc5 100644 (file)
@@ -172,6 +172,13 @@ static inline void OutputReg(raw_ostream &os, unsigned RegNo,
     os << " %reg" << RegNo;
 }
 
+StringRef MachineBasicBlock::getName() const {
+  if (const BasicBlock *LBB = getBasicBlock())
+    return LBB->getName();
+  else
+    return "(null)";
+}
+
 void MachineBasicBlock::print(raw_ostream &OS) const {
   const MachineFunction *MF = getParent();
   if (!MF) {
index 33b6b823446e620b473da3e3f1faf00e5d175baa..694282b2260aabd7cb4b1a1939e6834b655690f0 100644 (file)
@@ -487,10 +487,10 @@ void MachineLICM::Hoist(MachineInstr *MI) {
       errs() << "Hoisting " << *MI;
       if (CurPreheader->getBasicBlock())
         errs() << " to MachineBasicBlock "
-               << CurPreheader->getBasicBlock()->getName();
+               << CurPreheader->getName();
       if (MI->getParent()->getBasicBlock())
         errs() << " from MachineBasicBlock "
-               << MI->getParent()->getBasicBlock()->getName();
+               << MI->getParent()->getName();
       errs() << "\n";
     });
 
index a1c74c0c48a4c478401781eb043607d9de0b0429..d9f4c997b905d27eba2182b7c3cb8a487a6ef0eb 100644 (file)
@@ -305,7 +305,7 @@ void MachineVerifier::report(const char *msg, const MachineFunction *MF) {
 void MachineVerifier::report(const char *msg, const MachineBasicBlock *MBB) {
   assert(MBB);
   report(msg, MBB->getParent());
-  *OS << "- basic block: " << MBB->getBasicBlock()->getNameStr()
+  *OS << "- basic block: " << MBB->getName()
       << " " << (void*)MBB
       << " (BB#" << MBB->getNumber() << ")\n";
 }
index 3909c56bdbb22fa55004a6821e1a614a3b48ffbf..7847f8ec20e5de5d3279b0af3f822d3aff454329 100644 (file)
@@ -2380,7 +2380,7 @@ namespace {
 
 void SimpleRegisterCoalescing::CopyCoalesceInMBB(MachineBasicBlock *MBB,
                                                std::vector<CopyRec> &TryAgain) {
-  DEBUG(errs() << ((Value*)MBB->getBasicBlock())->getName() << ":\n");
+  DEBUG(errs() << MBB->getName() << ":\n");
 
   std::vector<CopyRec> VirtCopies;
   std::vector<CopyRec> PhysCopies;
index c836286f60ff6c4ff1af750769fda036f381ecef..10c806677c932c0b7025a9f2bbdaed31ca977f12 100644 (file)
@@ -1600,7 +1600,7 @@ private:
                   std::vector<MachineOperand*> &KillOps) {
 
     DEBUG(errs() << "\n**** Local spiller rewriting MBB '"
-          << MBB.getBasicBlock()->getName() << "':\n");
+          << MBB.getName() << "':\n");
 
     MachineFunction &MF = *MBB.getParent();