blob: f555bb66851b969953dc97d2ca580d975ba5dca9 [file] [log] [blame]
Vikram S. Advec5204fb2004-05-23 07:54:02 +00001//===- EquivClassGraphs.cpp - Merge equiv-class graphs & inline bottom-up -===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This pass is the same as the complete bottom-up graphs, but
11// with functions partitioned into equivalence classes and a single merged
12// DS graph for all functions in an equivalence class. After this merging,
13// graphs are inlined bottom-up on the SCCs of the final (CBU) call graph.
14//
15//===----------------------------------------------------------------------===//
16
17#define DEBUG_TYPE "ECGraphs"
18#include "EquivClassGraphs.h"
Vikram S. Advec5204fb2004-05-23 07:54:02 +000019#include "llvm/Module.h"
20#include "llvm/Pass.h"
Chris Lattnereaef5682004-07-07 06:22:54 +000021#include "llvm/Analysis/DataStructure/DSGraph.h"
22#include "llvm/Analysis/DataStructure/DataStructure.h"
Vikram S. Advec5204fb2004-05-23 07:54:02 +000023#include "llvm/Support/CallSite.h"
Chris Lattnerc9b93802004-10-11 20:53:28 +000024#include "llvm/Support/Debug.h"
25#include "llvm/ADT/SCCIterator.h"
26#include "llvm/ADT/Statistic.h"
27#include "llvm/ADT/EquivalenceClasses.h"
28#include "llvm/ADT/STLExtras.h"
Vikram S. Advec5204fb2004-05-23 07:54:02 +000029using namespace llvm;
30
Vikram S. Advec5204fb2004-05-23 07:54:02 +000031namespace {
Chris Lattner15d879e2004-10-12 16:52:09 +000032 RegisterAnalysis<PA::EquivClassGraphs> X("equivdatastructure",
Vikram S. Advec5204fb2004-05-23 07:54:02 +000033 "Equivalence-class Bottom-up Data Structure Analysis");
Chris Lattnerab8544a2004-10-31 21:56:11 +000034 Statistic<> NumEquivBUInlines("equivdatastructures",
35 "Number of graphs inlined");
Chris Lattner15d879e2004-10-12 16:52:09 +000036 Statistic<> NumFoldGraphInlines("Inline equiv-class graphs bottom up",
37 "Number of graphs inlined");
Vikram S. Advec5204fb2004-05-23 07:54:02 +000038}
39
Chris Lattner31d3f672004-10-31 23:41:26 +000040#ifndef NDEBUG
41template<typename GT>
42static void CheckAllGraphs(Module *M, GT &ECGraphs) {
43 DSGraph &GG = ECGraphs.getGlobalsGraph();
44
45 for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
46 if (!I->isExternal()) {
47 DSGraph &G = ECGraphs.getDSGraph(*I);
48
49 DSGraph::NodeMapTy GlobalsGraphNodeMapping;
50 for (DSScalarMap::global_iterator I = G.getScalarMap().global_begin(),
51 E = G.getScalarMap().global_end(); I != E; ++I)
52 DSGraph::computeNodeMapping(G.getNodeForValue(*I),
53 GG.getNodeForValue(*I),
54 GlobalsGraphNodeMapping);
55 }
56}
57#endif
58
Chris Lattner4457f7e2004-11-01 21:07:05 +000059// getSomeCalleeForCallSite - Return any one callee function at a call site.
Vikram S. Advec5204fb2004-05-23 07:54:02 +000060//
Chris Lattner15d879e2004-10-12 16:52:09 +000061Function *PA::EquivClassGraphs::
62getSomeCalleeForCallSite(const CallSite &CS) const {
Vikram S. Advec5204fb2004-05-23 07:54:02 +000063 Function *thisFunc = CS.getCaller();
Chris Lattner4457f7e2004-11-01 21:07:05 +000064 assert(thisFunc && "getSomeCalleeForCallSite(): Not a valid call site?");
Chris Lattnerab8544a2004-10-31 21:56:11 +000065 DSGraph &DSG = getDSGraph(*thisFunc);
66 DSNode *calleeNode = DSG.getNodeForValue(CS.getCalledValue()).getNode();
Vikram S. Advec5204fb2004-05-23 07:54:02 +000067 std::map<DSNode*, Function *>::const_iterator I =
68 OneCalledFunction.find(calleeNode);
69 return (I == OneCalledFunction.end())? NULL : I->second;
70}
71
Chris Lattnerab8544a2004-10-31 21:56:11 +000072// runOnModule - Calculate the bottom up data structure graphs for each function
73// in the program.
Vikram S. Advec5204fb2004-05-23 07:54:02 +000074//
Chris Lattnerab8544a2004-10-31 21:56:11 +000075bool PA::EquivClassGraphs::runOnModule(Module &M) {
Vikram S. Advec5204fb2004-05-23 07:54:02 +000076 CBU = &getAnalysis<CompleteBUDataStructures>();
Chris Lattner31d3f672004-10-31 23:41:26 +000077 CheckAllGraphs(&M, *CBU);
Vikram S. Advec5204fb2004-05-23 07:54:02 +000078
Chris Lattnerab8544a2004-10-31 21:56:11 +000079 GlobalsGraph = new DSGraph(CBU->getGlobalsGraph());
80 GlobalsGraph->setPrintAuxCalls();
81
Chris Lattner31d3f672004-10-31 23:41:26 +000082 ActualCallees = CBU->getActualCallees();
83
Vikram S. Advec5204fb2004-05-23 07:54:02 +000084 // Find equivalence classes of functions called from common call sites.
85 // Fold the CBU graphs for all functions in an equivalence class.
86 buildIndirectFunctionSets(M);
87
88 // Stack of functions used for Tarjan's SCC-finding algorithm.
89 std::vector<Function*> Stack;
Chris Lattner4bbf3df2004-10-31 23:01:34 +000090 std::map<Function*, unsigned> ValMap;
Vikram S. Advec5204fb2004-05-23 07:54:02 +000091 unsigned NextID = 1;
92
93 if (Function *Main = M.getMainFunction()) {
94 if (!Main->isExternal())
95 processSCC(getOrCreateGraph(*Main), *Main, Stack, NextID, ValMap);
96 } else {
97 std::cerr << "Fold Graphs: No 'main' function found!\n";
98 }
99
100 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
Chris Lattner31d3f672004-10-31 23:41:26 +0000101 if (!I->isExternal() && !ValMap.count(I))
Vikram S. Advec5204fb2004-05-23 07:54:02 +0000102 processSCC(getOrCreateGraph(*I), *I, Stack, NextID, ValMap);
103
Chris Lattner31d3f672004-10-31 23:41:26 +0000104 DEBUG(CheckAllGraphs(&M, *this));
105
Vikram S. Advec5204fb2004-05-23 07:54:02 +0000106 getGlobalsGraph().removeTriviallyDeadNodes();
Chris Lattnerab8544a2004-10-31 21:56:11 +0000107 return false;
Vikram S. Advec5204fb2004-05-23 07:54:02 +0000108}
109
110
111// buildIndirectFunctionSets - Iterate over the module looking for indirect
112// calls to functions. If a call site can invoke any functions [F1, F2... FN],
113// unify the N functions together in the FuncECs set.
114//
Chris Lattner15d879e2004-10-12 16:52:09 +0000115void PA::EquivClassGraphs::buildIndirectFunctionSets(Module &M) {
Vikram S. Advec5204fb2004-05-23 07:54:02 +0000116 const ActualCalleesTy& AC = CBU->getActualCallees();
Chris Lattner77408b82004-11-01 20:37:00 +0000117
Vikram S. Advec5204fb2004-05-23 07:54:02 +0000118 // Loop over all of the indirect calls in the program. If a call site can
119 // call multiple different functions, we need to unify all of the callees into
120 // the same equivalence class.
121 Instruction *LastInst = 0;
122 Function *FirstFunc = 0;
123 for (ActualCalleesTy::const_iterator I=AC.begin(), E=AC.end(); I != E; ++I) {
124 if (I->second->isExternal())
125 continue; // Ignore functions we cannot modify
126
127 CallSite CS = CallSite::get(I->first);
128
129 if (CS.getCalledFunction()) { // Direct call:
130 FuncECs.addElement(I->second); // -- Make sure function has equiv class
131 FirstFunc = I->second; // -- First callee at this site
132 } else { // Else indirect call
133 // DEBUG(std::cerr << "CALLEE: " << I->second->getName()
134 // << " from : " << I->first);
135 if (I->first != LastInst) {
136 // This is the first callee from this call site.
137 LastInst = I->first;
138 FirstFunc = I->second;
139 // Instead of storing the lastInst For Indirection call Sites we store
140 // the DSNode for the function ptr arguemnt
141 Function *thisFunc = LastInst->getParent()->getParent();
Chris Lattner15d879e2004-10-12 16:52:09 +0000142 DSGraph &TFG = CBU->getDSGraph(*thisFunc);
143 DSNode *calleeNode = TFG.getNodeForValue(CS.getCalledValue()).getNode();
Vikram S. Advec5204fb2004-05-23 07:54:02 +0000144 OneCalledFunction[calleeNode] = FirstFunc;
145 FuncECs.addElement(I->second);
146 } else {
147 // This is not the first possible callee from a particular call site.
148 // Union the callee in with the other functions.
149 FuncECs.unionSetsWith(FirstFunc, I->second);
150#ifndef NDEBUG
151 Function *thisFunc = LastInst->getParent()->getParent();
Chris Lattner15d879e2004-10-12 16:52:09 +0000152 DSGraph &TFG = CBU->getDSGraph(*thisFunc);
153 DSNode *calleeNode = TFG.getNodeForValue(CS.getCalledValue()).getNode();
Vikram S. Advec5204fb2004-05-23 07:54:02 +0000154 assert(OneCalledFunction.count(calleeNode) > 0 && "Missed a call?");
155#endif
156 }
157 }
158
159 // Now include all functions that share a graph with any function in the
160 // equivalence class. More precisely, if F is in the class, and G(F) is
161 // its graph, then we include all other functions that are also in G(F).
162 // Currently, that is just the functions in the same call-graph-SCC as F.
163 //
164 DSGraph& funcDSGraph = CBU->getDSGraph(*I->second);
165 const DSGraph::ReturnNodesTy &RetNodes = funcDSGraph.getReturnNodes();
166 for (DSGraph::ReturnNodesTy::const_iterator RI=RetNodes.begin(),
167 RE=RetNodes.end(); RI != RE; ++RI)
168 FuncECs.unionSetsWith(FirstFunc, RI->first);
169 }
170
171 // Now that all of the equivalences have been built, merge the graphs for
172 // each equivalence class.
173 //
174 std::set<Function*> &leaderSet = FuncECs.getLeaderSet();
175 DEBUG(std::cerr << "\nIndirect Function Equivalence Sets:\n");
176 for (std::set<Function*>::iterator LI = leaderSet.begin(),
177 LE = leaderSet.end(); LI != LE; ++LI) {
178
179 Function* LF = *LI;
180 const std::set<Function*>& EqClass = FuncECs.getEqClass(LF);
181
Vikram S. Advec5204fb2004-05-23 07:54:02 +0000182 if (EqClass.size() > 1) {
Chris Lattner983baf42004-11-02 06:38:58 +0000183#ifndef NDEBUG
Vikram S. Advec5204fb2004-05-23 07:54:02 +0000184 DEBUG(std::cerr <<" Equivalence set for leader " <<LF->getName()<<" = ");
185 for (std::set<Function*>::const_iterator EqI = EqClass.begin(),
186 EqEnd = EqClass.end(); EqI != EqEnd; ++EqI)
187 DEBUG(std::cerr << " " << (*EqI)->getName() << ",");
188 DEBUG(std::cerr << "\n");
Vikram S. Advec5204fb2004-05-23 07:54:02 +0000189#endif
190
Chris Lattnerab8544a2004-10-31 21:56:11 +0000191 // This equiv class has multiple functions: merge their graphs. First,
192 // clone the CBU graph for the leader and make it the common graph for the
193 // equivalence graph.
Chris Lattner983baf42004-11-02 06:38:58 +0000194 DSGraph &MergedG = getOrCreateGraph(*LF);
Vikram S. Advec5204fb2004-05-23 07:54:02 +0000195
Chris Lattner77408b82004-11-01 20:37:00 +0000196 // Record the argument nodes for use in merging later below.
197 std::vector<DSNodeHandle> ArgNodes;
198
Vikram S. Advec5204fb2004-05-23 07:54:02 +0000199 for (Function::aiterator AI1 = LF->abegin(); AI1 != LF->aend(); ++AI1)
Chris Lattnerf4985682004-10-31 18:13:19 +0000200 if (DS::isPointerType(AI1->getType()))
Chris Lattner983baf42004-11-02 06:38:58 +0000201 ArgNodes.push_back(MergedG.getNodeForValue(AI1));
Vikram S. Advec5204fb2004-05-23 07:54:02 +0000202
Chris Lattnerab8544a2004-10-31 21:56:11 +0000203 // Merge in the graphs of all other functions in this equiv. class. Note
204 // that two or more functions may have the same graph, and it only needs
Chris Lattner983baf42004-11-02 06:38:58 +0000205 // to be merged in once.
Vikram S. Advec5204fb2004-05-23 07:54:02 +0000206 std::set<DSGraph*> GraphsMerged;
Chris Lattner983baf42004-11-02 06:38:58 +0000207 GraphsMerged.insert(&CBU->getDSGraph(*LF));
Chris Lattner113cde82004-10-31 17:47:48 +0000208
Chris Lattner983baf42004-11-02 06:38:58 +0000209 for (std::set<Function*>::const_iterator EqI = EqClass.begin(),
210 E = EqClass.end(); EqI != E; ++EqI) {
211 Function *F = *EqI;
212 DSGraph *&FG = DSInfo[F];
213
214 DSGraph &CBUGraph = CBU->getDSGraph(*F);
215 if (!GraphsMerged.insert(&CBUGraph).second)
Vikram S. Advec5204fb2004-05-23 07:54:02 +0000216 continue;
Chris Lattner983baf42004-11-02 06:38:58 +0000217 assert(FG == 0 && "Remerged a graph?");
Vikram S. Advec5204fb2004-05-23 07:54:02 +0000218
219 // Record the "folded" graph for the function.
Chris Lattner983baf42004-11-02 06:38:58 +0000220 FG = &MergedG;
Vikram S. Advec5204fb2004-05-23 07:54:02 +0000221
Chris Lattner983baf42004-11-02 06:38:58 +0000222 // Clone this member of the equivalence class into MergedG.
Vikram S. Advec5204fb2004-05-23 07:54:02 +0000223 DSGraph::NodeMapTy NodeMap;
Chris Lattner113cde82004-10-31 17:47:48 +0000224
Chris Lattner983baf42004-11-02 06:38:58 +0000225 MergedG.cloneInto(CBUGraph, MergedG.getScalarMap(),
226 MergedG.getReturnNodes(), NodeMap, 0);
Vikram S. Advec5204fb2004-05-23 07:54:02 +0000227
228 // Merge the return nodes of all functions together.
Chris Lattner983baf42004-11-02 06:38:58 +0000229 MergedG.getReturnNodes()[LF].mergeWith(MergedG.getReturnNodes()[F]);
Vikram S. Advec5204fb2004-05-23 07:54:02 +0000230
231 // Merge the function arguments with all argument nodes found so far.
232 // If there are extra function args, add them to the vector of argNodes
233 Function::aiterator AI2 = F->abegin(), AI2end = F->aend();
Chris Lattner77408b82004-11-01 20:37:00 +0000234 for (unsigned arg=0, numArgs = ArgNodes.size();
Chris Lattner113cde82004-10-31 17:47:48 +0000235 arg != numArgs && AI2 != AI2end; ++AI2, ++arg)
236 if (DS::isPointerType(AI2->getType()))
Chris Lattner983baf42004-11-02 06:38:58 +0000237 ArgNodes[arg].mergeWith(MergedG.getNodeForValue(AI2));
Chris Lattner113cde82004-10-31 17:47:48 +0000238
Vikram S. Advec5204fb2004-05-23 07:54:02 +0000239 for ( ; AI2 != AI2end; ++AI2)
Chris Lattner113cde82004-10-31 17:47:48 +0000240 if (DS::isPointerType(AI2->getType()))
Chris Lattner983baf42004-11-02 06:38:58 +0000241 ArgNodes.push_back(MergedG.getNodeForValue(AI2));
242 DEBUG(MergedG.AssertGraphOK());
Vikram S. Advec5204fb2004-05-23 07:54:02 +0000243 }
244 }
245 }
246 DEBUG(std::cerr << "\n");
247}
248
249
Chris Lattner15d879e2004-10-12 16:52:09 +0000250DSGraph &PA::EquivClassGraphs::getOrCreateGraph(Function &F) {
Vikram S. Advec5204fb2004-05-23 07:54:02 +0000251 // Has the graph already been created?
Chris Lattnerfcb7d952004-11-01 21:02:23 +0000252 DSGraph *&Graph = DSInfo[&F];
Vikram S. Advec5204fb2004-05-23 07:54:02 +0000253 if (Graph) return *Graph;
254
Vikram S. Advec5204fb2004-05-23 07:54:02 +0000255 DSGraph &CBUGraph = CBU->getDSGraph(F);
Vikram S. Advec5204fb2004-05-23 07:54:02 +0000256
257 // Copy the CBU graph...
258 Graph = new DSGraph(CBUGraph); // updates the map via reference
259 Graph->setGlobalsGraph(&getGlobalsGraph());
260 Graph->setPrintAuxCalls();
261
Chris Lattnerfcb7d952004-11-01 21:02:23 +0000262 // Make sure to update the DSInfo map for all functions in the graph!
Vikram S. Advec5204fb2004-05-23 07:54:02 +0000263 for (DSGraph::ReturnNodesTy::iterator I = Graph->getReturnNodes().begin();
264 I != Graph->getReturnNodes().end(); ++I)
265 if (I->first != &F) {
Chris Lattnerfcb7d952004-11-01 21:02:23 +0000266 DSGraph *&FG = DSInfo[I->first];
Chris Lattner983baf42004-11-02 06:38:58 +0000267 assert(FG == 0 && "Merging function in SCC twice?");
Vikram S. Advec5204fb2004-05-23 07:54:02 +0000268 FG = Graph;
269 }
270
Chris Lattner68f96582004-11-01 19:54:06 +0000271 return *Graph;
Vikram S. Advec5204fb2004-05-23 07:54:02 +0000272}
273
274
Chris Lattner4bbf3df2004-10-31 23:01:34 +0000275unsigned PA::EquivClassGraphs::processSCC(DSGraph &FG, Function &F,
Chris Lattner15d879e2004-10-12 16:52:09 +0000276 std::vector<Function*> &Stack,
277 unsigned &NextID,
Chris Lattner4bbf3df2004-10-31 23:01:34 +0000278 std::map<Function*,unsigned> &ValMap){
Vikram S. Advec5204fb2004-05-23 07:54:02 +0000279 DEBUG(std::cerr << " ProcessSCC for function " << F.getName() << "\n");
280
Chris Lattner4bbf3df2004-10-31 23:01:34 +0000281 std::map<Function*, unsigned>::iterator It = ValMap.lower_bound(&F);
282 if (It != ValMap.end() && It->first == &F)
283 return It->second;
284
Vikram S. Advec5204fb2004-05-23 07:54:02 +0000285 unsigned Min = NextID++, MyID = Min;
286 ValMap[&F] = Min;
287 Stack.push_back(&F);
288
289 // The edges out of the current node are the call site targets...
290 for (unsigned i = 0, e = FG.getFunctionCalls().size(); i != e; ++i) {
291 Instruction *Call = FG.getFunctionCalls()[i].getCallSite().getInstruction();
292
293 // Loop over all of the actually called functions...
294 ActualCalleesTy::const_iterator I, E;
295 for (tie(I, E) = getActualCallees().equal_range(Call); I != E; ++I)
296 if (!I->second->isExternal()) {
Chris Lattner31d3f672004-10-31 23:41:26 +0000297 // Process the callee as necessary.
298 unsigned M = processSCC(getOrCreateGraph(*I->second), *I->second,
299 Stack, NextID, ValMap);
Vikram S. Advec5204fb2004-05-23 07:54:02 +0000300 if (M < Min) Min = M;
301 }
302 }
303
304 assert(ValMap[&F] == MyID && "SCC construction assumption wrong!");
305 if (Min != MyID)
306 return Min; // This is part of a larger SCC!
307
308 // If this is a new SCC, process it now.
309 bool IsMultiNodeSCC = false;
310 while (Stack.back() != &F) {
Chris Lattner31d3f672004-10-31 23:41:26 +0000311 DSGraph *NG = &getOrCreateGraph(*Stack.back());
Vikram S. Advec5204fb2004-05-23 07:54:02 +0000312 ValMap[Stack.back()] = ~0U;
313
314 // Since all SCCs must be the same as those found in CBU, we do not need to
315 // do any merging. Make sure all functions in the SCC share the same graph.
Chris Lattner31d3f672004-10-31 23:41:26 +0000316 assert(NG == &FG && "ECG discovered different SCC's than the CBU pass?");
Vikram S. Advec5204fb2004-05-23 07:54:02 +0000317
318 Stack.pop_back();
319 IsMultiNodeSCC = true;
320 }
321
Vikram S. Advec5204fb2004-05-23 07:54:02 +0000322 Stack.pop_back();
Chris Lattner113cde82004-10-31 17:47:48 +0000323
Vikram S. Advec5204fb2004-05-23 07:54:02 +0000324 processGraph(FG, F);
325 ValMap[&F] = ~0U;
326 return MyID;
327}
328
329
330/// processGraph - Process the CBU graphs for the program in bottom-up order on
331/// the SCC of the __ACTUAL__ call graph. This builds final folded CBU graphs.
Chris Lattner15d879e2004-10-12 16:52:09 +0000332void PA::EquivClassGraphs::processGraph(DSGraph &G, Function &F) {
Vikram S. Advec5204fb2004-05-23 07:54:02 +0000333 DEBUG(std::cerr << " ProcessGraph for function " << F.getName() << "\n");
334
335 hash_set<Instruction*> calls;
336
Chris Lattnerab8544a2004-10-31 21:56:11 +0000337 DSGraph* CallerGraph = &getOrCreateGraph(F);
Vikram S. Advec5204fb2004-05-23 07:54:02 +0000338
339 // Else we need to inline some callee graph. Visit all call sites.
340 // The edges out of the current node are the call site targets...
341 for (unsigned i=0, e = CallerGraph->getFunctionCalls().size(); i != e; ++i) {
342 const DSCallSite &CS = CallerGraph->getFunctionCalls()[i];
343 Instruction *TheCall = CS.getCallSite().getInstruction();
344
345 assert(calls.insert(TheCall).second &&
346 "Call instruction occurs multiple times in graph??");
347
348 // Inline the common callee graph into the current graph, if the callee
349 // graph has not changed. Note that all callees should have the same
350 // graph so we only need to do this once.
351 //
352 DSGraph* CalleeGraph = NULL;
353 ActualCalleesTy::const_iterator I, E;
354 tie(I, E) = getActualCallees().equal_range(TheCall);
355 unsigned TNum, Num;
356
357 // Loop over all potential callees to find the first non-external callee.
358 for (TNum = 0, Num = std::distance(I, E); I != E; ++I, ++TNum)
359 if (!I->second->isExternal())
360 break;
361
362 // Now check if the graph has changed and if so, clone and inline it.
Chris Lattnerab8544a2004-10-31 21:56:11 +0000363 if (I != E) {
Vikram S. Advec5204fb2004-05-23 07:54:02 +0000364 Function *CalleeFunc = I->second;
365
366 // Merge the callee's graph into this graph, if not already the same.
367 // Callees in the same equivalence class (which subsumes those
368 // in the same SCCs) have the same graph. Note that all recursion
369 // including self-recursion have been folded in the equiv classes.
370 //
371 CalleeGraph = &getOrCreateGraph(*CalleeFunc);
372 if (CalleeGraph != CallerGraph) {
373 ++NumFoldGraphInlines;
374 CallerGraph->mergeInGraph(CS, *CalleeFunc, *CalleeGraph,
375 DSGraph::KeepModRefBits |
376 DSGraph::StripAllocaBit |
377 DSGraph::DontCloneCallNodes |
378 DSGraph::DontCloneAuxCallNodes);
379 DEBUG(std::cerr << " Inlining graph [" << i << "/" << e-1
380 << ":" << TNum << "/" << Num-1 << "] for "
381 << CalleeFunc->getName() << "["
382 << CalleeGraph->getGraphSize() << "+"
383 << CalleeGraph->getAuxFunctionCalls().size()
384 << "] into '" /*<< CallerGraph->getFunctionNames()*/ << "' ["
385 << CallerGraph->getGraphSize() << "+"
386 << CallerGraph->getAuxFunctionCalls().size()
387 << "]\n");
388 }
389 }
390
391#ifndef NDEBUG
392 // Now loop over the rest of the callees and make sure they have the
393 // same graph as the one inlined above.
394 if (CalleeGraph)
395 for (++I, ++TNum; I != E; ++I, ++TNum)
396 if (!I->second->isExternal())
397 assert(CalleeGraph == &getOrCreateGraph(*I->second) &&
398 "Callees at a call site have different graphs?");
399#endif
400 }
401
Chris Lattner31d3f672004-10-31 23:41:26 +0000402 // Recompute the Incomplete markers.
403 assert(CallerGraph->getInlinedGlobals().empty());
404 CallerGraph->maskIncompleteMarkers();
405 CallerGraph->markIncompleteNodes(DSGraph::MarkFormalArgs);
406
407 // Delete dead nodes. Treat globals that are unreachable but that can
408 // reach live nodes as live.
409 CallerGraph->removeDeadNodes(DSGraph::KeepUnreachableGlobals);
Chris Lattnerab8544a2004-10-31 21:56:11 +0000410
411 // When this graph is finalized, clone the globals in the graph into the
412 // globals graph to make sure it has everything, from all graphs.
413 DSScalarMap &MainSM = CallerGraph->getScalarMap();
414 ReachabilityCloner RC(*CallerGraph->getGlobalsGraph(), *CallerGraph,
415 DSGraph::StripAllocaBit);
416
417 // Clone everything reachable from globals in the function graph into the
418 // globals graph.
419 for (DSScalarMap::global_iterator I = MainSM.global_begin(),
420 E = MainSM.global_end(); I != E; ++I)
421 RC.getClonedNH(MainSM[*I]);
422
Chris Lattner31d3f672004-10-31 23:41:26 +0000423 DEBUG(std::cerr << " -- DONE ProcessGraph for function "
Chris Lattner15d879e2004-10-12 16:52:09 +0000424 << F.getName() << "\n");
Vikram S. Advec5204fb2004-05-23 07:54:02 +0000425}