From c9109225e27d5f9ef455d3008ec6e52ea0de61f3 Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Wed, 14 Jan 2015 00:27:45 +0000 Subject: [PATCH] Revert r225854: [PM] Move the LazyCallGraph printing functionality to a print method. This was formulated on a bad idea, but sadly I didn't uncover how bad this was until I got further down the path. I had hoped that we could provide a low boilerplate way of printing analyses, but it just doesn't seem like this really fits the needs of the analyses. Not all analyses really want to do printing, and those that do don't all use the same interface. Instead, with the new pass manager let's just take advantage of the fact that creating an explicit printer pass like the LCG has is pretty low boilerplate already and rely on that for testing. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225861 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Analysis/LazyCallGraph.h | 6 --- lib/Analysis/LazyCallGraph.cpp | 74 +++++++++++++-------------- 2 files changed, 36 insertions(+), 44 deletions(-) diff --git a/include/llvm/Analysis/LazyCallGraph.h b/include/llvm/Analysis/LazyCallGraph.h index a7960e18614..b0b9068de34 100644 --- a/include/llvm/Analysis/LazyCallGraph.h +++ b/include/llvm/Analysis/LazyCallGraph.h @@ -462,12 +462,6 @@ public: ///@} - /// \brief Print out the CFG to the provided stream. - /// - /// This will fully traverse the call graph (and so is non-const) and print - /// it out to the provided stream. - void print(raw_ostream &OS, Module &M); - private: /// \brief Allocator that holds all the call graph nodes. SpecificBumpPtrAllocator BPA; diff --git a/lib/Analysis/LazyCallGraph.cpp b/lib/Analysis/LazyCallGraph.cpp index edb8531f924..c8d0410c1e0 100644 --- a/lib/Analysis/LazyCallGraph.cpp +++ b/lib/Analysis/LazyCallGraph.cpp @@ -542,43 +542,6 @@ void LazyCallGraph::removeEdge(Node &CallerN, Function &Callee) { return CallerN.removeEdgeInternal(Callee); } -static void printNodes(raw_ostream &OS, LazyCallGraph::Node &N, - SmallPtrSetImpl &Printed) { - // Recurse depth first through the nodes. - for (LazyCallGraph::Node &ChildN : N) - if (Printed.insert(&ChildN).second) - printNodes(OS, ChildN, Printed); - - OS << " Call edges in function: " << N.getFunction().getName() << "\n"; - for (LazyCallGraph::iterator I = N.begin(), E = N.end(); I != E; ++I) - OS << " -> " << I->getFunction().getName() << "\n"; - - OS << "\n"; -} - -static void printSCC(raw_ostream &OS, LazyCallGraph::SCC &SCC) { - ptrdiff_t SCCSize = std::distance(SCC.begin(), SCC.end()); - OS << " SCC with " << SCCSize << " functions:\n"; - - for (LazyCallGraph::Node *N : SCC) - OS << " " << N->getFunction().getName() << "\n"; - - OS << "\n"; -} - -void LazyCallGraph::print(raw_ostream &OS, Module &M) { - OS << "Printing the call graph for module: " << M.getModuleIdentifier() - << "\n\n"; - - SmallPtrSet Printed; - for (LazyCallGraph::Node &N : *this) - if (Printed.insert(&N).second) - printNodes(OS, N, Printed); - - for (LazyCallGraph::SCC &SCC : this->postorder_sccs()) - printSCC(OS, SCC); -} - LazyCallGraph::Node &LazyCallGraph::insertInto(Function &F, Node *&MappedN) { return *new (MappedN = BPA.Allocate()) Node(*this, F); } @@ -721,9 +684,44 @@ char LazyCallGraphAnalysis::PassID; LazyCallGraphPrinterPass::LazyCallGraphPrinterPass(raw_ostream &OS) : OS(OS) {} +static void printNodes(raw_ostream &OS, LazyCallGraph::Node &N, + SmallPtrSetImpl &Printed) { + // Recurse depth first through the nodes. + for (LazyCallGraph::Node &ChildN : N) + if (Printed.insert(&ChildN).second) + printNodes(OS, ChildN, Printed); + + OS << " Call edges in function: " << N.getFunction().getName() << "\n"; + for (LazyCallGraph::iterator I = N.begin(), E = N.end(); I != E; ++I) + OS << " -> " << I->getFunction().getName() << "\n"; + + OS << "\n"; +} + +static void printSCC(raw_ostream &OS, LazyCallGraph::SCC &SCC) { + ptrdiff_t SCCSize = std::distance(SCC.begin(), SCC.end()); + OS << " SCC with " << SCCSize << " functions:\n"; + + for (LazyCallGraph::Node *N : SCC) + OS << " " << N->getFunction().getName() << "\n"; + + OS << "\n"; +} + PreservedAnalyses LazyCallGraphPrinterPass::run(Module &M, ModuleAnalysisManager *AM) { - AM->getResult(M).print(OS, M); + LazyCallGraph &G = AM->getResult(M); + + OS << "Printing the call graph for module: " << M.getModuleIdentifier() + << "\n\n"; + + SmallPtrSet Printed; + for (LazyCallGraph::Node &N : G) + if (Printed.insert(&N).second) + printNodes(OS, N, Printed); + + for (LazyCallGraph::SCC &SCC : G.postorder_sccs()) + printSCC(OS, SCC); return PreservedAnalyses::all(); }