Add print methods
authorJakob Stoklund Olesen <stoklund@2pi.dk>
Fri, 22 Oct 2010 20:28:21 +0000 (20:28 +0000)
committerJakob Stoklund Olesen <stoklund@2pi.dk>
Fri, 22 Oct 2010 20:28:21 +0000 (20:28 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@117143 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/SplitKit.cpp
lib/CodeGen/SplitKit.h

index 88bf01800cf1942abd9241d43cd54cdb3dc5084f..81a58674bb3815331519f0393f4cd54dba7b17d9 100644 (file)
@@ -79,6 +79,15 @@ void SplitAnalysis::analyzeUses() {
                << usingLoops_.size()  << " loops.\n");
 }
 
+void SplitAnalysis::print(const BlockPtrSet &B, raw_ostream &OS) const {
+  for (BlockPtrSet::const_iterator I = B.begin(), E = B.end(); I != E; ++I) {
+    unsigned count = usingBlocks_.lookup(*I);
+    OS << " BB#" << (*I)->getNumber();
+    if (count)
+      OS << '(' << count << ')';
+  }
+}
+
 // Get three sets of basic blocks surrounding a loop: Blocks inside the loop,
 // predecessor blocks, and exit blocks.
 void SplitAnalysis::getLoopBlocks(const MachineLoop *Loop, LoopBlocks &Blocks) {
@@ -105,6 +114,15 @@ void SplitAnalysis::getLoopBlocks(const MachineLoop *Loop, LoopBlocks &Blocks) {
   }
 }
 
+void SplitAnalysis::print(const LoopBlocks &B, raw_ostream &OS) const {
+  OS << "Loop:";
+  print(B.Loop, OS);
+  OS << ", preds:";
+  print(B.Preds, OS);
+  OS << ", exits:";
+  print(B.Exits, OS);
+}
+
 /// analyzeLoopPeripheralUse - Return an enum describing how curli_ is used in
 /// and around the Loop.
 SplitAnalysis::LoopPeripheralUse SplitAnalysis::
@@ -124,6 +142,7 @@ analyzeLoopPeripheralUse(const SplitAnalysis::LoopBlocks &Blocks) {
     if (Blocks.Loop.count(MBB))
       continue;
     // It must be an unrelated block.
+    DEBUG(dbgs() << ", outside: BB#" << MBB->getNumber());
     return OutsideLoop;
   }
   return use;
@@ -223,6 +242,7 @@ const MachineLoop *SplitAnalysis::getBestSplitLoop() {
        E = usingLoops_.end(); I != E; ++I) {
     const MachineLoop *Loop = I->first;
     getLoopBlocks(Loop, Blocks);
+    DEBUG({ dbgs() << "  "; print(Blocks, dbgs()); });
 
     switch(analyzeLoopPeripheralUse(Blocks)) {
     case OutsideLoop:
@@ -235,19 +255,18 @@ const MachineLoop *SplitAnalysis::getBestSplitLoop() {
       // forever.
       // For safety, stick to splitting live ranges with uses outside the
       // periphery.
-      DEBUG(dbgs() << "  multiple peripheral uses in " << *Loop);
+      DEBUG(dbgs() << ": multiple peripheral uses\n");
       break;
     case ContainedInLoop:
-      DEBUG(dbgs() << "  contained in " << *Loop);
+      DEBUG(dbgs() << ": fully contained\n");
       continue;
     case SinglePeripheral:
-      DEBUG(dbgs() << "  single peripheral use in " << *Loop);
+      DEBUG(dbgs() << ": single peripheral use\n");
       continue;
     }
     // Will it be possible to split around this loop?
     getCriticalExits(Blocks, CriticalExits);
-    DEBUG(dbgs() << "  " << CriticalExits.size() << " critical exits from "
-                 << *Loop);
+    DEBUG(dbgs() << ": " << CriticalExits.size() << " critical exits\n");
     if (!canSplitCriticalExits(Blocks, CriticalExits))
       continue;
     // This is a possible split.
@@ -891,19 +910,7 @@ void SplitEditor::splitAroundLoop(const MachineLoop *Loop) {
   sa_.getLoopBlocks(Loop, Blocks);
 
   DEBUG({
-    dbgs() << "  splitAroundLoop";
-    for (SplitAnalysis::BlockPtrSet::iterator I = Blocks.Loop.begin(),
-         E = Blocks.Loop.end(); I != E; ++I)
-      dbgs() << " BB#" << (*I)->getNumber();
-    dbgs() << ", preds:";
-    for (SplitAnalysis::BlockPtrSet::iterator I = Blocks.Preds.begin(),
-         E = Blocks.Preds.end(); I != E; ++I)
-      dbgs() << " BB#" << (*I)->getNumber();
-    dbgs() << ", exits:";
-    for (SplitAnalysis::BlockPtrSet::iterator I = Blocks.Exits.begin(),
-         E = Blocks.Exits.end(); I != E; ++I)
-      dbgs() << " BB#" << (*I)->getNumber();
-    dbgs() << '\n';
+    dbgs() << "  splitAround"; sa_.print(Blocks, dbgs()); dbgs() << '\n';
   });
 
   // Break critical edges as needed.
index 8d794e5f4d8e52daadffe93f1b2b16f2d1790ad5..80fc23642a8b4c1ae08999a15aecda47599c1d98 100644 (file)
@@ -28,6 +28,7 @@ class MachineRegisterInfo;
 class TargetInstrInfo;
 class VirtRegMap;
 class VNInfo;
+class raw_ostream;
 
 /// SplitAnalysis - Analyze a LiveInterval, looking for live range splitting
 /// opportunities.
@@ -76,6 +77,9 @@ public:
   typedef SmallPtrSet<const MachineBasicBlock*, 16> BlockPtrSet;
   typedef SmallPtrSet<const MachineLoop*, 16> LoopPtrSet;
 
+  // Print a set of blocks with use counts.
+  void print(const BlockPtrSet&, raw_ostream&) const;
+
   // Sets of basic blocks surrounding a machine loop.
   struct LoopBlocks {
     BlockPtrSet Loop;  // Blocks in the loop.
@@ -89,6 +93,9 @@ public:
     }
   };
 
+  // Print loop blocks with use counts.
+  void print(const LoopBlocks&, raw_ostream&) const;
+
   // Calculate the block sets surrounding the loop.
   void getLoopBlocks(const MachineLoop *Loop, LoopBlocks &Blocks);