index e0736162a77aab6ceaffa9ce886b09bc331b75c2..edb8531f924dc11c02793726130b8de699319fe9 100644 (file)
}
for (Value *Op : C->operand_values())
- if (Visited.insert(cast<Constant>(Op)))
+ if (Visited.insert(cast<Constant>(Op)).second)
Worklist.push_back(cast<Constant>(Op));
}
}
for (Instruction &I : BB)
for (Value *Op : I.operand_values())
if (Constant *C = dyn_cast<Constant>(Op))
- if (Visited.insert(C))
+ if (Visited.insert(C).second)
Worklist.push_back(C);
// We've collected all the constant (and thus potentially function or
SmallPtrSet<Constant *, 16> Visited;
for (GlobalVariable &GV : M.globals())
if (GV.hasInitializer())
- if (Visited.insert(GV.getInitializer()))
+ if (Visited.insert(GV.getInitializer()).second)
Worklist.push_back(GV.getInitializer());
DEBUG(dbgs() << " Adding functions referenced by global initializers to the "
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);
}
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))
- 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,
+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))
- printNodes(OS, N, Printed);
-
- for (LazyCallGraph::SCC &SCC : G.postorder_sccs())
- printSCC(OS, SCC);
+ AM->getResult<LazyCallGraphAnalysis>(M).print(OS, M);
return PreservedAnalyses::all();
-
}