[llvm] r225854 - [PM] Move the LazyCallGraph printing functionality to a print method.

Chandler Carruth chandlerc at gmail.com
Tue Jan 13 15:53:51 PST 2015


Author: chandlerc
Date: Tue Jan 13 17:53:50 2015
New Revision: 225854

URL: http://llvm.org/viewvc/llvm-project?rev=225854&view=rev
Log:
[PM] Move the LazyCallGraph printing functionality to a print method.

I'm adding generic analysis printing utility pass support which will
require such a method (or a specialization) so this will let the
existing printing logic satisfy that.

Modified:
    llvm/trunk/include/llvm/Analysis/LazyCallGraph.h
    llvm/trunk/lib/Analysis/LazyCallGraph.cpp

Modified: llvm/trunk/include/llvm/Analysis/LazyCallGraph.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/LazyCallGraph.h?rev=225854&r1=225853&r2=225854&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/LazyCallGraph.h (original)
+++ llvm/trunk/include/llvm/Analysis/LazyCallGraph.h Tue Jan 13 17:53:50 2015
@@ -462,6 +462,12 @@ 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<Node> BPA;

Modified: llvm/trunk/lib/Analysis/LazyCallGraph.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/LazyCallGraph.cpp?rev=225854&r1=225853&r2=225854&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/LazyCallGraph.cpp (original)
+++ llvm/trunk/lib/Analysis/LazyCallGraph.cpp Tue Jan 13 17:53:50 2015
@@ -542,6 +542,43 @@ void LazyCallGraph::removeEdge(Node &Cal
   return CallerN.removeEdgeInternal(Callee);
 }
 
+static void printNodes(raw_ostream &OS, LazyCallGraph::Node &N,
+                       SmallPtrSetImpl<LazyCallGraph::Node *> &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<LazyCallGraph::Node *, 16> 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);
 }
@@ -684,44 +721,9 @@ char LazyCallGraphAnalysis::PassID;
 
 LazyCallGraphPrinterPass::LazyCallGraphPrinterPass(raw_ostream &OS) : OS(OS) {}
 
-static void printNodes(raw_ostream &OS, LazyCallGraph::Node &N,
-                       SmallPtrSetImpl<LazyCallGraph::Node *> &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) {
-  LazyCallGraph &G = AM->getResult<LazyCallGraphAnalysis>(M);
-
-  OS << "Printing the call graph for module: " << M.getModuleIdentifier()
-     << "\n\n";
-
-  SmallPtrSet<LazyCallGraph::Node *, 16> 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);
+  AM->getResult<LazyCallGraphAnalysis>(M).print(OS, M);
 
   return PreservedAnalyses::all();
 }





More information about the llvm-commits mailing list