llvm.org GIT mirror llvm / 2a463a1
[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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225854 91177308-0d34-0410-b5e6-96231b3b80d8 Chandler Carruth 5 years ago
2 changed file(s) with 44 addition(s) and 36 deletion(s). Raw diff Collapse all Expand all
461461
462462 ///@}
463463
464 /// \brief Print out the CFG to the provided stream.
465 ///
466 /// This will fully traverse the call graph (and so is non-const) and print
467 /// it out to the provided stream.
468 void print(raw_ostream &OS, Module &M);
469
464470 private:
465471 /// \brief Allocator that holds all the call graph nodes.
466472 SpecificBumpPtrAllocator BPA;
541541 return CallerN.removeEdgeInternal(Callee);
542542 }
543543
544 static void printNodes(raw_ostream &OS, LazyCallGraph::Node &N,
545 SmallPtrSetImpl &Printed) {
546 // Recurse depth first through the nodes.
547 for (LazyCallGraph::Node &ChildN : N)
548 if (Printed.insert(&ChildN).second)
549 printNodes(OS, ChildN, Printed);
550
551 OS << " Call edges in function: " << N.getFunction().getName() << "\n";
552 for (LazyCallGraph::iterator I = N.begin(), E = N.end(); I != E; ++I)
553 OS << " -> " << I->getFunction().getName() << "\n";
554
555 OS << "\n";
556 }
557
558 static void printSCC(raw_ostream &OS, LazyCallGraph::SCC &SCC) {
559 ptrdiff_t SCCSize = std::distance(SCC.begin(), SCC.end());
560 OS << " SCC with " << SCCSize << " functions:\n";
561
562 for (LazyCallGraph::Node *N : SCC)
563 OS << " " << N->getFunction().getName() << "\n";
564
565 OS << "\n";
566 }
567
568 void LazyCallGraph::print(raw_ostream &OS, Module &M) {
569 OS << "Printing the call graph for module: " << M.getModuleIdentifier()
570 << "\n\n";
571
572 SmallPtrSet Printed;
573 for (LazyCallGraph::Node &N : *this)
574 if (Printed.insert(&N).second)
575 printNodes(OS, N, Printed);
576
577 for (LazyCallGraph::SCC &SCC : this->postorder_sccs())
578 printSCC(OS, SCC);
579 }
580
544581 LazyCallGraph::Node &LazyCallGraph::insertInto(Function &F, Node *&MappedN) {
545582 return *new (MappedN = BPA.Allocate()) Node(*this, F);
546583 }
683720
684721 LazyCallGraphPrinterPass::LazyCallGraphPrinterPass(raw_ostream &OS) : OS(OS) {}
685722
686 static void printNodes(raw_ostream &OS, LazyCallGraph::Node &N,
687 SmallPtrSetImpl &Printed) {
688 // Recurse depth first through the nodes.
689 for (LazyCallGraph::Node &ChildN : N)
690 if (Printed.insert(&ChildN).second)
691 printNodes(OS, ChildN, Printed);
692
693 OS << " Call edges in function: " << N.getFunction().getName() << "\n";
694 for (LazyCallGraph::iterator I = N.begin(), E = N.end(); I != E; ++I)
695 OS << " -> " << I->getFunction().getName() << "\n";
696
697 OS << "\n";
698 }
699
700 static void printSCC(raw_ostream &OS, LazyCallGraph::SCC &SCC) {
701 ptrdiff_t SCCSize = std::distance(SCC.begin(), SCC.end());
702 OS << " SCC with " << SCCSize << " functions:\n";
703
704 for (LazyCallGraph::Node *N : SCC)
705 OS << " " << N->getFunction().getName() << "\n";
706
707 OS << "\n";
708 }
709
710723 PreservedAnalyses LazyCallGraphPrinterPass::run(Module &M,
711724 ModuleAnalysisManager *AM) {
712 LazyCallGraph &G = AM->getResult(M);
713
714 OS << "Printing the call graph for module: " << M.getModuleIdentifier()
715 << "\n\n";
716
717 SmallPtrSet Printed;
718 for (LazyCallGraph::Node &N : G)
719 if (Printed.insert(&N).second)
720 printNodes(OS, N, Printed);
721
722 for (LazyCallGraph::SCC &SCC : G.postorder_sccs())
723 printSCC(OS, SCC);
725 AM->getResult(M).print(OS, M);
724726
725727 return PreservedAnalyses::all();
726728 }