llvm.org GIT mirror llvm / c910922
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 Chandler Carruth 4 years ago
2 changed file(s) with 36 addition(s) and 44 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
470464 private:
471465 /// \brief Allocator that holds all the call graph nodes.
472466 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
581544 LazyCallGraph::Node &LazyCallGraph::insertInto(Function &F, Node *&MappedN) {
582545 return *new (MappedN = BPA.Allocate()) Node(*this, F);
583546 }
720683
721684 LazyCallGraphPrinterPass::LazyCallGraphPrinterPass(raw_ostream &OS) : OS(OS) {}
722685
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
723710 PreservedAnalyses LazyCallGraphPrinterPass::run(Module &M,
724711 ModuleAnalysisManager *AM) {
725 AM->getResult(M).print(OS, M);
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);
726724
727725 return PreservedAnalyses::all();
728726 }