Chandler Carruth | bf71a34 | 2014-02-06 04:37:03 +0000 | [diff] [blame] | 1 | //===- LazyCallGraph.cpp - Analysis of a Module's call graph --------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "llvm/Analysis/LazyCallGraph.h" |
Chandler Carruth | 18eadd92 | 2014-04-18 10:50:32 +0000 | [diff] [blame] | 11 | #include "llvm/ADT/STLExtras.h" |
Chandler Carruth | 219b89b | 2014-03-04 11:01:28 +0000 | [diff] [blame] | 12 | #include "llvm/IR/CallSite.h" |
Chandler Carruth | 7da14f1 | 2014-03-06 03:23:41 +0000 | [diff] [blame] | 13 | #include "llvm/IR/InstVisitor.h" |
Chandler Carruth | bf71a34 | 2014-02-06 04:37:03 +0000 | [diff] [blame] | 14 | #include "llvm/IR/Instructions.h" |
| 15 | #include "llvm/IR/PassManager.h" |
Chandler Carruth | 99b756d | 2014-04-21 05:04:24 +0000 | [diff] [blame] | 16 | #include "llvm/Support/Debug.h" |
Chandler Carruth | bf71a34 | 2014-02-06 04:37:03 +0000 | [diff] [blame] | 17 | #include "llvm/Support/raw_ostream.h" |
Chandler Carruth | bf71a34 | 2014-02-06 04:37:03 +0000 | [diff] [blame] | 18 | |
| 19 | using namespace llvm; |
| 20 | |
Chandler Carruth | f1221bd | 2014-04-22 02:48:03 +0000 | [diff] [blame] | 21 | #define DEBUG_TYPE "lcg" |
| 22 | |
Chandler Carruth | bf71a34 | 2014-02-06 04:37:03 +0000 | [diff] [blame] | 23 | static void findCallees( |
| 24 | SmallVectorImpl<Constant *> &Worklist, SmallPtrSetImpl<Constant *> &Visited, |
Chandler Carruth | e9b5061 | 2014-03-10 02:14:14 +0000 | [diff] [blame] | 25 | SmallVectorImpl<PointerUnion<Function *, LazyCallGraph::Node *>> &Callees, |
Chandler Carruth | 0b623ba | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 26 | DenseMap<Function *, size_t> &CalleeIndexMap) { |
Chandler Carruth | bf71a34 | 2014-02-06 04:37:03 +0000 | [diff] [blame] | 27 | while (!Worklist.empty()) { |
| 28 | Constant *C = Worklist.pop_back_val(); |
| 29 | |
| 30 | if (Function *F = dyn_cast<Function>(C)) { |
| 31 | // Note that we consider *any* function with a definition to be a viable |
| 32 | // edge. Even if the function's definition is subject to replacement by |
| 33 | // some other module (say, a weak definition) there may still be |
| 34 | // optimizations which essentially speculate based on the definition and |
| 35 | // a way to check that the specific definition is in fact the one being |
| 36 | // used. For example, this could be done by moving the weak definition to |
| 37 | // a strong (internal) definition and making the weak definition be an |
| 38 | // alias. Then a test of the address of the weak function against the new |
| 39 | // strong definition's address would be an effective way to determine the |
| 40 | // safety of optimizing a direct call edge. |
Chandler Carruth | 0b623ba | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 41 | if (!F->isDeclaration() && |
| 42 | CalleeIndexMap.insert(std::make_pair(F, Callees.size())).second) { |
Chandler Carruth | 99b756d | 2014-04-21 05:04:24 +0000 | [diff] [blame] | 43 | DEBUG(dbgs() << " Added callable function: " << F->getName() |
| 44 | << "\n"); |
Chandler Carruth | e9b5061 | 2014-03-10 02:14:14 +0000 | [diff] [blame] | 45 | Callees.push_back(F); |
Chandler Carruth | 99b756d | 2014-04-21 05:04:24 +0000 | [diff] [blame] | 46 | } |
Chandler Carruth | bf71a34 | 2014-02-06 04:37:03 +0000 | [diff] [blame] | 47 | continue; |
| 48 | } |
| 49 | |
Chandler Carruth | 1583e99 | 2014-03-03 10:42:58 +0000 | [diff] [blame] | 50 | for (Value *Op : C->operand_values()) |
| 51 | if (Visited.insert(cast<Constant>(Op))) |
| 52 | Worklist.push_back(cast<Constant>(Op)); |
Chandler Carruth | bf71a34 | 2014-02-06 04:37:03 +0000 | [diff] [blame] | 53 | } |
| 54 | } |
| 55 | |
Chandler Carruth | 18eadd92 | 2014-04-18 10:50:32 +0000 | [diff] [blame] | 56 | LazyCallGraph::Node::Node(LazyCallGraph &G, Function &F) |
| 57 | : G(&G), F(F), DFSNumber(0), LowLink(0) { |
Chandler Carruth | 99b756d | 2014-04-21 05:04:24 +0000 | [diff] [blame] | 58 | DEBUG(dbgs() << " Adding functions called by '" << F.getName() |
| 59 | << "' to the graph.\n"); |
| 60 | |
Chandler Carruth | bf71a34 | 2014-02-06 04:37:03 +0000 | [diff] [blame] | 61 | SmallVector<Constant *, 16> Worklist; |
| 62 | SmallPtrSet<Constant *, 16> Visited; |
| 63 | // Find all the potential callees in this function. First walk the |
| 64 | // instructions and add every operand which is a constant to the worklist. |
Chandler Carruth | b9e2f8c | 2014-03-09 12:20:34 +0000 | [diff] [blame] | 65 | for (BasicBlock &BB : F) |
| 66 | for (Instruction &I : BB) |
| 67 | for (Value *Op : I.operand_values()) |
Chandler Carruth | 1583e99 | 2014-03-03 10:42:58 +0000 | [diff] [blame] | 68 | if (Constant *C = dyn_cast<Constant>(Op)) |
Chandler Carruth | bf71a34 | 2014-02-06 04:37:03 +0000 | [diff] [blame] | 69 | if (Visited.insert(C)) |
| 70 | Worklist.push_back(C); |
| 71 | |
| 72 | // We've collected all the constant (and thus potentially function or |
| 73 | // function containing) operands to all of the instructions in the function. |
| 74 | // Process them (recursively) collecting every function found. |
Chandler Carruth | 0b623ba | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 75 | findCallees(Worklist, Visited, Callees, CalleeIndexMap); |
Chandler Carruth | bf71a34 | 2014-02-06 04:37:03 +0000 | [diff] [blame] | 76 | } |
| 77 | |
Chandler Carruth | 2174f44 | 2014-04-18 20:44:16 +0000 | [diff] [blame] | 78 | LazyCallGraph::LazyCallGraph(Module &M) : NextDFSNumber(0) { |
Chandler Carruth | 99b756d | 2014-04-21 05:04:24 +0000 | [diff] [blame] | 79 | DEBUG(dbgs() << "Building CG for module: " << M.getModuleIdentifier() |
| 80 | << "\n"); |
Chandler Carruth | b9e2f8c | 2014-03-09 12:20:34 +0000 | [diff] [blame] | 81 | for (Function &F : M) |
| 82 | if (!F.isDeclaration() && !F.hasLocalLinkage()) |
Chandler Carruth | 0b623ba | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 83 | if (EntryIndexMap.insert(std::make_pair(&F, EntryNodes.size())).second) { |
Chandler Carruth | 99b756d | 2014-04-21 05:04:24 +0000 | [diff] [blame] | 84 | DEBUG(dbgs() << " Adding '" << F.getName() |
| 85 | << "' to entry set of the graph.\n"); |
Chandler Carruth | b9e2f8c | 2014-03-09 12:20:34 +0000 | [diff] [blame] | 86 | EntryNodes.push_back(&F); |
Chandler Carruth | 99b756d | 2014-04-21 05:04:24 +0000 | [diff] [blame] | 87 | } |
Chandler Carruth | bf71a34 | 2014-02-06 04:37:03 +0000 | [diff] [blame] | 88 | |
| 89 | // Now add entry nodes for functions reachable via initializers to globals. |
| 90 | SmallVector<Constant *, 16> Worklist; |
| 91 | SmallPtrSet<Constant *, 16> Visited; |
Chandler Carruth | b9e2f8c | 2014-03-09 12:20:34 +0000 | [diff] [blame] | 92 | for (GlobalVariable &GV : M.globals()) |
| 93 | if (GV.hasInitializer()) |
| 94 | if (Visited.insert(GV.getInitializer())) |
| 95 | Worklist.push_back(GV.getInitializer()); |
Chandler Carruth | bf71a34 | 2014-02-06 04:37:03 +0000 | [diff] [blame] | 96 | |
Chandler Carruth | 99b756d | 2014-04-21 05:04:24 +0000 | [diff] [blame] | 97 | DEBUG(dbgs() << " Adding functions referenced by global initializers to the " |
| 98 | "entry set.\n"); |
Chandler Carruth | 0b623ba | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 99 | findCallees(Worklist, Visited, EntryNodes, EntryIndexMap); |
Chandler Carruth | 18eadd92 | 2014-04-18 10:50:32 +0000 | [diff] [blame] | 100 | |
| 101 | for (auto &Entry : EntryNodes) |
| 102 | if (Function *F = Entry.dyn_cast<Function *>()) |
| 103 | SCCEntryNodes.insert(F); |
| 104 | else |
| 105 | SCCEntryNodes.insert(&Entry.get<Node *>()->getFunction()); |
Chandler Carruth | bf71a34 | 2014-02-06 04:37:03 +0000 | [diff] [blame] | 106 | } |
| 107 | |
Chandler Carruth | bf71a34 | 2014-02-06 04:37:03 +0000 | [diff] [blame] | 108 | LazyCallGraph::LazyCallGraph(LazyCallGraph &&G) |
Chandler Carruth | 2174f44 | 2014-04-18 20:44:16 +0000 | [diff] [blame] | 109 | : BPA(std::move(G.BPA)), NodeMap(std::move(G.NodeMap)), |
| 110 | EntryNodes(std::move(G.EntryNodes)), |
Chandler Carruth | 0b623ba | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 111 | EntryIndexMap(std::move(G.EntryIndexMap)), SCCBPA(std::move(G.SCCBPA)), |
Chandler Carruth | 18eadd92 | 2014-04-18 10:50:32 +0000 | [diff] [blame] | 112 | SCCMap(std::move(G.SCCMap)), LeafSCCs(std::move(G.LeafSCCs)), |
| 113 | DFSStack(std::move(G.DFSStack)), |
Chandler Carruth | 2174f44 | 2014-04-18 20:44:16 +0000 | [diff] [blame] | 114 | SCCEntryNodes(std::move(G.SCCEntryNodes)), |
| 115 | NextDFSNumber(G.NextDFSNumber) { |
Chandler Carruth | d8d865e | 2014-04-18 11:02:33 +0000 | [diff] [blame] | 116 | updateGraphPtrs(); |
| 117 | } |
| 118 | |
| 119 | LazyCallGraph &LazyCallGraph::operator=(LazyCallGraph &&G) { |
| 120 | BPA = std::move(G.BPA); |
Chandler Carruth | 2174f44 | 2014-04-18 20:44:16 +0000 | [diff] [blame] | 121 | NodeMap = std::move(G.NodeMap); |
Chandler Carruth | d8d865e | 2014-04-18 11:02:33 +0000 | [diff] [blame] | 122 | EntryNodes = std::move(G.EntryNodes); |
Chandler Carruth | 0b623ba | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 123 | EntryIndexMap = std::move(G.EntryIndexMap); |
Chandler Carruth | d8d865e | 2014-04-18 11:02:33 +0000 | [diff] [blame] | 124 | SCCBPA = std::move(G.SCCBPA); |
| 125 | SCCMap = std::move(G.SCCMap); |
| 126 | LeafSCCs = std::move(G.LeafSCCs); |
| 127 | DFSStack = std::move(G.DFSStack); |
| 128 | SCCEntryNodes = std::move(G.SCCEntryNodes); |
Chandler Carruth | 2174f44 | 2014-04-18 20:44:16 +0000 | [diff] [blame] | 129 | NextDFSNumber = G.NextDFSNumber; |
Chandler Carruth | d8d865e | 2014-04-18 11:02:33 +0000 | [diff] [blame] | 130 | updateGraphPtrs(); |
| 131 | return *this; |
| 132 | } |
| 133 | |
| 134 | LazyCallGraph::Node *LazyCallGraph::insertInto(Function &F, Node *&MappedN) { |
| 135 | return new (MappedN = BPA.Allocate()) Node(*this, F); |
| 136 | } |
| 137 | |
| 138 | void LazyCallGraph::updateGraphPtrs() { |
Chandler Carruth | b60cb31 | 2014-04-17 07:25:59 +0000 | [diff] [blame] | 139 | // Process all nodes updating the graph pointers. |
| 140 | SmallVector<Node *, 16> Worklist; |
Chandler Carruth | b9e2f8c | 2014-03-09 12:20:34 +0000 | [diff] [blame] | 141 | for (auto &Entry : EntryNodes) |
| 142 | if (Node *EntryN = Entry.dyn_cast<Node *>()) |
Chandler Carruth | b60cb31 | 2014-04-17 07:25:59 +0000 | [diff] [blame] | 143 | Worklist.push_back(EntryN); |
| 144 | |
| 145 | while (!Worklist.empty()) { |
| 146 | Node *N = Worklist.pop_back_val(); |
| 147 | N->G = this; |
| 148 | for (auto &Callee : N->Callees) |
| 149 | if (Node *CalleeN = Callee.dyn_cast<Node *>()) |
| 150 | Worklist.push_back(CalleeN); |
| 151 | } |
Chandler Carruth | bf71a34 | 2014-02-06 04:37:03 +0000 | [diff] [blame] | 152 | } |
Chandler Carruth | bf71a34 | 2014-02-06 04:37:03 +0000 | [diff] [blame] | 153 | |
Chandler Carruth | 3f9869a | 2014-04-23 06:09:03 +0000 | [diff] [blame] | 154 | LazyCallGraph::SCC *LazyCallGraph::formSCCFromDFSStack( |
Chandler Carruth | cace662 | 2014-04-23 10:31:17 +0000 | [diff] [blame] | 155 | SmallVectorImpl<std::pair<Node *, Node::iterator>> &DFSStack, |
| 156 | SmallVectorImpl<std::pair<Node *, Node::iterator>>::iterator SCCBegin) { |
Chandler Carruth | 3f9869a | 2014-04-23 06:09:03 +0000 | [diff] [blame] | 157 | // The tail of the stack is the new SCC. Allocate the SCC and pop the stack |
| 158 | // into it. |
| 159 | SCC *NewSCC = new (SCCBPA.Allocate()) SCC(); |
| 160 | |
Chandler Carruth | cace662 | 2014-04-23 10:31:17 +0000 | [diff] [blame] | 161 | for (auto I = SCCBegin, E = DFSStack.end(); I != E; ++I) { |
| 162 | Node *SCCN = I->first; |
| 163 | assert(SCCN->LowLink >= SCCBegin->first->LowLink && |
| 164 | "We cannot have a low link in an SCC lower than its root on the " |
| 165 | "stack!"); |
| 166 | |
Chandler Carruth | 3f9869a | 2014-04-23 06:09:03 +0000 | [diff] [blame] | 167 | SCCMap[&SCCN->getFunction()] = NewSCC; |
| 168 | NewSCC->Nodes.push_back(SCCN); |
Chandler Carruth | 3f9869a | 2014-04-23 06:09:03 +0000 | [diff] [blame] | 169 | bool Inserted = |
| 170 | NewSCC->NodeSet.insert(&SCCN->getFunction()); |
| 171 | (void)Inserted; |
| 172 | assert(Inserted && "Cannot have duplicates in the DFSStack!"); |
Chandler Carruth | cace662 | 2014-04-23 10:31:17 +0000 | [diff] [blame] | 173 | } |
| 174 | DFSStack.erase(SCCBegin, DFSStack.end()); |
Chandler Carruth | 3f9869a | 2014-04-23 06:09:03 +0000 | [diff] [blame] | 175 | |
| 176 | // A final pass over all edges in the SCC (this remains linear as we only |
| 177 | // do this once when we build the SCC) to connect it to the parent sets of |
| 178 | // its children. |
| 179 | bool IsLeafSCC = true; |
| 180 | for (Node *SCCN : NewSCC->Nodes) |
| 181 | for (Node *SCCChildN : *SCCN) { |
| 182 | if (NewSCC->NodeSet.count(&SCCChildN->getFunction())) |
| 183 | continue; |
| 184 | SCC *ChildSCC = SCCMap.lookup(&SCCChildN->getFunction()); |
| 185 | assert(ChildSCC && |
| 186 | "Must have all child SCCs processed when building a new SCC!"); |
| 187 | ChildSCC->ParentSCCs.insert(NewSCC); |
| 188 | IsLeafSCC = false; |
| 189 | } |
| 190 | |
| 191 | // For the SCCs where we fine no child SCCs, add them to the leaf list. |
| 192 | if (IsLeafSCC) |
| 193 | LeafSCCs.push_back(NewSCC); |
| 194 | |
| 195 | return NewSCC; |
| 196 | } |
| 197 | |
Chandler Carruth | 18eadd92 | 2014-04-18 10:50:32 +0000 | [diff] [blame] | 198 | LazyCallGraph::SCC *LazyCallGraph::getNextSCCInPostOrder() { |
| 199 | // When the stack is empty, there are no more SCCs to walk in this graph. |
| 200 | if (DFSStack.empty()) { |
| 201 | // If we've handled all candidate entry nodes to the SCC forest, we're done. |
| 202 | if (SCCEntryNodes.empty()) |
| 203 | return nullptr; |
| 204 | |
Chandler Carruth | c7bad9a | 2014-04-23 08:08:49 +0000 | [diff] [blame] | 205 | // Reset the DFS numbering. |
| 206 | NextDFSNumber = 1; |
Chandler Carruth | 18eadd92 | 2014-04-18 10:50:32 +0000 | [diff] [blame] | 207 | Node *N = get(*SCCEntryNodes.pop_back_val()); |
| 208 | DFSStack.push_back(std::make_pair(N, N->begin())); |
| 209 | } |
| 210 | |
Chandler Carruth | cace662 | 2014-04-23 10:31:17 +0000 | [diff] [blame] | 211 | auto SI = DFSStack.rbegin(); |
| 212 | if (SI->first->DFSNumber == 0) { |
Chandler Carruth | 18eadd92 | 2014-04-18 10:50:32 +0000 | [diff] [blame] | 213 | // This node hasn't been visited before, assign it a DFS number and remove |
| 214 | // it from the entry set. |
Chandler Carruth | cace662 | 2014-04-23 10:31:17 +0000 | [diff] [blame] | 215 | SI->first->LowLink = SI->first->DFSNumber = NextDFSNumber++; |
| 216 | SCCEntryNodes.remove(&SI->first->getFunction()); |
Chandler Carruth | 18eadd92 | 2014-04-18 10:50:32 +0000 | [diff] [blame] | 217 | } |
| 218 | |
Chandler Carruth | cace662 | 2014-04-23 10:31:17 +0000 | [diff] [blame] | 219 | do { |
| 220 | Node *N = SI->first; |
| 221 | for (auto I = SI->second, E = N->end(); I != E; ++I) { |
| 222 | Node *ChildN = *I; |
| 223 | if (ChildN->DFSNumber == 0) { |
| 224 | // Mark that we should start at this child when next this node is the |
| 225 | // top of the stack. We don't start at the next child to ensure this |
| 226 | // child's lowlink is reflected. |
| 227 | SI->second = I; |
Chandler Carruth | 18eadd92 | 2014-04-18 10:50:32 +0000 | [diff] [blame] | 228 | |
Chandler Carruth | cace662 | 2014-04-23 10:31:17 +0000 | [diff] [blame] | 229 | // Recurse onto this node via a tail call. |
| 230 | DFSStack.push_back(std::make_pair(ChildN, ChildN->begin())); |
| 231 | return LazyCallGraph::getNextSCCInPostOrder(); |
| 232 | } |
| 233 | |
| 234 | // Track the lowest link of the childen, if any are still in the stack. |
| 235 | if (ChildN->LowLink < N->LowLink && !SCCMap.count(&ChildN->getFunction())) |
| 236 | N->LowLink = ChildN->LowLink; |
Chandler Carruth | 18eadd92 | 2014-04-18 10:50:32 +0000 | [diff] [blame] | 237 | } |
Chandler Carruth | cace662 | 2014-04-23 10:31:17 +0000 | [diff] [blame] | 238 | // No more children to process for this stack entry. |
| 239 | SI->second = N->end(); |
Chandler Carruth | 18eadd92 | 2014-04-18 10:50:32 +0000 | [diff] [blame] | 240 | |
Chandler Carruth | cace662 | 2014-04-23 10:31:17 +0000 | [diff] [blame] | 241 | if (N->LowLink == N->DFSNumber) |
| 242 | // Form the new SCC out of the top of the DFS stack. |
| 243 | return formSCCFromDFSStack(DFSStack, std::prev(SI.base())); |
Chandler Carruth | 18eadd92 | 2014-04-18 10:50:32 +0000 | [diff] [blame] | 244 | |
Chandler Carruth | cace662 | 2014-04-23 10:31:17 +0000 | [diff] [blame] | 245 | ++SI; |
| 246 | } while (SI != DFSStack.rend()); |
| 247 | |
| 248 | llvm_unreachable( |
| 249 | "We cannot reach the bottom of the stack without popping an SCC."); |
Chandler Carruth | 18eadd92 | 2014-04-18 10:50:32 +0000 | [diff] [blame] | 250 | } |
| 251 | |
Chandler Carruth | bf71a34 | 2014-02-06 04:37:03 +0000 | [diff] [blame] | 252 | char LazyCallGraphAnalysis::PassID; |
| 253 | |
| 254 | LazyCallGraphPrinterPass::LazyCallGraphPrinterPass(raw_ostream &OS) : OS(OS) {} |
| 255 | |
| 256 | static void printNodes(raw_ostream &OS, LazyCallGraph::Node &N, |
| 257 | SmallPtrSetImpl<LazyCallGraph::Node *> &Printed) { |
| 258 | // Recurse depth first through the nodes. |
Chandler Carruth | b9e2f8c | 2014-03-09 12:20:34 +0000 | [diff] [blame] | 259 | for (LazyCallGraph::Node *ChildN : N) |
| 260 | if (Printed.insert(ChildN)) |
| 261 | printNodes(OS, *ChildN, Printed); |
Chandler Carruth | bf71a34 | 2014-02-06 04:37:03 +0000 | [diff] [blame] | 262 | |
| 263 | OS << " Call edges in function: " << N.getFunction().getName() << "\n"; |
| 264 | for (LazyCallGraph::iterator I = N.begin(), E = N.end(); I != E; ++I) |
| 265 | OS << " -> " << I->getFunction().getName() << "\n"; |
| 266 | |
| 267 | OS << "\n"; |
| 268 | } |
| 269 | |
Chandler Carruth | 18eadd92 | 2014-04-18 10:50:32 +0000 | [diff] [blame] | 270 | static void printSCC(raw_ostream &OS, LazyCallGraph::SCC &SCC) { |
| 271 | ptrdiff_t SCCSize = std::distance(SCC.begin(), SCC.end()); |
| 272 | OS << " SCC with " << SCCSize << " functions:\n"; |
| 273 | |
| 274 | for (LazyCallGraph::Node *N : SCC) |
| 275 | OS << " " << N->getFunction().getName() << "\n"; |
| 276 | |
| 277 | OS << "\n"; |
| 278 | } |
| 279 | |
Chandler Carruth | e9b5061 | 2014-03-10 02:14:14 +0000 | [diff] [blame] | 280 | PreservedAnalyses LazyCallGraphPrinterPass::run(Module *M, |
| 281 | ModuleAnalysisManager *AM) { |
Chandler Carruth | bf71a34 | 2014-02-06 04:37:03 +0000 | [diff] [blame] | 282 | LazyCallGraph &G = AM->getResult<LazyCallGraphAnalysis>(M); |
| 283 | |
Chandler Carruth | e9b5061 | 2014-03-10 02:14:14 +0000 | [diff] [blame] | 284 | OS << "Printing the call graph for module: " << M->getModuleIdentifier() |
| 285 | << "\n\n"; |
Chandler Carruth | bf71a34 | 2014-02-06 04:37:03 +0000 | [diff] [blame] | 286 | |
| 287 | SmallPtrSet<LazyCallGraph::Node *, 16> Printed; |
Chandler Carruth | b9e2f8c | 2014-03-09 12:20:34 +0000 | [diff] [blame] | 288 | for (LazyCallGraph::Node *N : G) |
| 289 | if (Printed.insert(N)) |
| 290 | printNodes(OS, *N, Printed); |
Chandler Carruth | bf71a34 | 2014-02-06 04:37:03 +0000 | [diff] [blame] | 291 | |
Chandler Carruth | 18eadd92 | 2014-04-18 10:50:32 +0000 | [diff] [blame] | 292 | for (LazyCallGraph::SCC *SCC : G.postorder_sccs()) |
| 293 | printSCC(OS, *SCC); |
| 294 | |
Chandler Carruth | bf71a34 | 2014-02-06 04:37:03 +0000 | [diff] [blame] | 295 | return PreservedAnalyses::all(); |
Chandler Carruth | 18eadd92 | 2014-04-18 10:50:32 +0000 | [diff] [blame] | 296 | |
Chandler Carruth | bf71a34 | 2014-02-06 04:37:03 +0000 | [diff] [blame] | 297 | } |