From 532de3dc6ea98387368954c0ac0e07b0adca8b62 Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Fri, 22 Oct 2010 20:28:21 +0000 Subject: [PATCH] Add print methods git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@117143 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/SplitKit.cpp | 43 +++++++++++++++++++++++++------------------ lib/CodeGen/SplitKit.h | 7 +++++++ 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/lib/CodeGen/SplitKit.cpp b/lib/CodeGen/SplitKit.cpp index 88bf01800cf..81a58674bb3 100644 --- a/lib/CodeGen/SplitKit.cpp +++ b/lib/CodeGen/SplitKit.cpp @@ -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. diff --git a/lib/CodeGen/SplitKit.h b/lib/CodeGen/SplitKit.h index 8d794e5f4d8..80fc23642a8 100644 --- a/lib/CodeGen/SplitKit.h +++ b/lib/CodeGen/SplitKit.h @@ -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 BlockPtrSet; typedef SmallPtrSet 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); -- 2.11.0