[PATCH] D22817: Utility to print all the basic blocks of a loop.

Aditya Kumar via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 26 09:14:49 PDT 2016


hiraditya created this revision.
hiraditya added reviewers: hfinkel, sanjoy.
hiraditya added subscribers: eli.friedman, sebpop, llvm-commits.
Herald added a subscriber: mzolotukhin.

Useful in debugging.

https://reviews.llvm.org/D22817

Files:
  llvm/include/llvm/Analysis/LoopInfo.h
  llvm/include/llvm/Analysis/LoopInfoImpl.h
  llvm/lib/Analysis/LoopInfo.cpp

Index: llvm/lib/Analysis/LoopInfo.cpp
===================================================================
--- llvm/lib/Analysis/LoopInfo.cpp
+++ llvm/lib/Analysis/LoopInfo.cpp
@@ -387,6 +387,10 @@
 LLVM_DUMP_METHOD void Loop::dump() const {
   print(dbgs());
 }
+
+LLVM_DUMP_METHOD void Loop::dumpVerbose() const {
+  printVerbose(dbgs());
+}
 #endif
 
 //===----------------------------------------------------------------------===//
Index: llvm/include/llvm/Analysis/LoopInfoImpl.h
===================================================================
--- llvm/include/llvm/Analysis/LoopInfoImpl.h
+++ llvm/include/llvm/Analysis/LoopInfoImpl.h
@@ -335,6 +335,27 @@
     (*I)->print(OS, Depth+2);
 }
 
+template<class BlockT, class LoopT>
+void LoopBase<BlockT, LoopT>::printVerbose(raw_ostream &OS,
+                                           unsigned Depth) const {
+  OS.indent(Depth*2) << "Loop at depth " << getLoopDepth()
+       << " containing: ";
+
+  BlockT *H = getHeader();
+  BlockT *L = getLoopLatch();
+  for (unsigned i = 0; i < getBlocks().size(); ++i) {
+    BlockT *BB = getBlocks()[i];
+    if (BB == H) OS << "<header>\n";
+    if (BB == L) OS << "<latch>\n";
+    if (isLoopExiting(BB)) OS << "<exiting>\n";
+    BB->print(OS);
+  }
+  OS << "\n";
+
+  for (iterator I = begin(), E = end(); I != E; ++I)
+    (*I)->print(OS, Depth+2);
+}
+
 //===----------------------------------------------------------------------===//
 /// Stable LoopInfo Analysis - Build a loop tree using stable iterators so the
 /// result does / not depend on use list (block predecessor) order.
Index: llvm/include/llvm/Analysis/LoopInfo.h
===================================================================
--- llvm/include/llvm/Analysis/LoopInfo.h
+++ llvm/include/llvm/Analysis/LoopInfo.h
@@ -331,6 +331,9 @@
 
   void print(raw_ostream &OS, unsigned Depth = 0) const;
 
+  /// Print loop with all the BBs inside it.
+  void printVerbose(raw_ostream &OS, unsigned Depth = 0) const;
+
 protected:
   friend class LoopInfoBase<BlockT, LoopT>;
   explicit LoopBase(BlockT *BB) : ParentLoop(nullptr) {
@@ -451,6 +454,7 @@
   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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22817.65541.patch
Type: text/x-patch
Size: 2346 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160726/2fb8bb53/attachment.bin>


More information about the llvm-commits mailing list