From 18c964d7a43a9c3c8fbecb5d4646d5ba3a871ca7 Mon Sep 17 00:00:00 2001 From: Sebastian Pop Date: Wed, 27 Jul 2016 05:02:17 +0000 Subject: [PATCH] add a verbose mode to Loop->print() to print all the basic blocks of a loop Differential Revision: https://reviews.llvm.org/D22817 llvm-svn: 276838 --- llvm/include/llvm/Analysis/LoopInfo.h | 6 +++++- llvm/include/llvm/Analysis/LoopInfoImpl.h | 19 +++++++++++++------ llvm/lib/Analysis/LoopInfo.cpp | 4 ++++ 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/llvm/include/llvm/Analysis/LoopInfo.h b/llvm/include/llvm/Analysis/LoopInfo.h index 0888530..88f7685 100644 --- a/llvm/include/llvm/Analysis/LoopInfo.h +++ b/llvm/include/llvm/Analysis/LoopInfo.h @@ -342,7 +342,10 @@ public: /// Verify loop structure of this loop and all nested loops. void verifyLoopNest(DenseSet *Loops) const; - void print(raw_ostream &OS, unsigned Depth = 0) const; + void print(raw_ostream &OS, unsigned Depth = 0, bool Verbose = false) const; + + /// Print loop with all the BBs inside it. + void printVerbose(raw_ostream &OS, unsigned Depth = 0) const; protected: friend class LoopInfoBase; @@ -464,6 +467,7 @@ public: BasicBlock *getUniqueExitBlock() const; void dump() const; + void dumpVerbose() const; /// Return the debug location of the start of this loop. /// This looks for a BB terminating instruction with a known debug diff --git a/llvm/include/llvm/Analysis/LoopInfoImpl.h b/llvm/include/llvm/Analysis/LoopInfoImpl.h index 79593f4..dbe2ca5 100644 --- a/llvm/include/llvm/Analysis/LoopInfoImpl.h +++ b/llvm/include/llvm/Analysis/LoopInfoImpl.h @@ -309,17 +309,24 @@ void LoopBase::verifyLoopNest( } template -void LoopBase::print(raw_ostream &OS, unsigned Depth) const { +void LoopBase::print(raw_ostream &OS, unsigned Depth, + bool Verbose) const { OS.indent(Depth*2) << "Loop at depth " << getLoopDepth() << " containing: "; + BlockT *H = getHeader(); for (unsigned i = 0; i < getBlocks().size(); ++i) { - if (i) OS << ","; BlockT *BB = getBlocks()[i]; - BB->printAsOperand(OS, false); - if (BB == getHeader()) OS << "
"; - if (BB == getLoopLatch()) OS << ""; - if (isLoopExiting(BB)) OS << ""; + if (!Verbose) { + if (i) OS << ","; + BB->printAsOperand(OS, false); + } else OS << "\n"; + + if (BB == H) OS << "
"; + if (isLoopLatch(BB)) OS << ""; + if (isLoopExiting(BB)) OS << ""; + if (Verbose) + BB->print(OS); } OS << "\n"; diff --git a/llvm/lib/Analysis/LoopInfo.cpp b/llvm/lib/Analysis/LoopInfo.cpp index 16325f6..cbd5ede 100644 --- a/llvm/lib/Analysis/LoopInfo.cpp +++ b/llvm/lib/Analysis/LoopInfo.cpp @@ -387,6 +387,10 @@ BasicBlock *Loop::getUniqueExitBlock() const { LLVM_DUMP_METHOD void Loop::dump() const { print(dbgs()); } + +LLVM_DUMP_METHOD void Loop::dumpVerbose() const { + print(dbgs(), /*Depth=*/ 0, /*Verbose=*/ true); +} #endif //===----------------------------------------------------------------------===// -- 2.7.4