Vikram S. Adve | aaeee75 | 2002-07-30 22:06:40 +0000 | [diff] [blame] | 1 | //===- TopDownClosure.cpp - Compute the top-down interprocedure closure ---===// |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame^] | 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 | //===----------------------------------------------------------------------===// |
Vikram S. Adve | aaeee75 | 2002-07-30 22:06:40 +0000 | [diff] [blame] | 9 | // |
| 10 | // This file implements the TDDataStructures class, which represents the |
| 11 | // Top-down Interprocedural closure of the data structure graph over the |
| 12 | // program. This is useful (but not strictly necessary?) for applications |
| 13 | // like pointer analysis. |
| 14 | // |
| 15 | //===----------------------------------------------------------------------===// |
| 16 | |
| 17 | #include "llvm/Analysis/DataStructure.h" |
| 18 | #include "llvm/Module.h" |
| 19 | #include "llvm/DerivedTypes.h" |
Chris Lattner | 6806f56 | 2003-08-01 22:15:03 +0000 | [diff] [blame] | 20 | #include "Support/Debug.h" |
Chris Lattner | fccd06f | 2002-10-01 22:33:50 +0000 | [diff] [blame] | 21 | #include "Support/Statistic.h" |
Chris Lattner | 18f07a1 | 2003-07-01 16:28:11 +0000 | [diff] [blame] | 22 | #include "DSCallSiteIterator.h" |
Vikram S. Adve | aaeee75 | 2002-07-30 22:06:40 +0000 | [diff] [blame] | 23 | |
Chris Lattner | 4923d1b | 2003-02-03 22:51:28 +0000 | [diff] [blame] | 24 | namespace { |
| 25 | RegisterAnalysis<TDDataStructures> // Register the pass |
Chris Lattner | 312edd3 | 2003-06-28 22:14:55 +0000 | [diff] [blame] | 26 | Y("tddatastructure", "Top-down Data Structure Analysis"); |
Chris Lattner | a8da51b | 2003-07-02 04:39:44 +0000 | [diff] [blame] | 27 | |
| 28 | Statistic<> NumTDInlines("tddatastructures", "Number of graphs inlined"); |
| 29 | } |
| 30 | |
Chris Lattner | 3b0a9be | 2003-09-20 22:24:04 +0000 | [diff] [blame] | 31 | void TDDataStructures::markReachableFunctionsExternallyAccessible(DSNode *N, |
| 32 | hash_set<DSNode*> &Visited) { |
Chris Lattner | 11fc930 | 2003-09-20 23:58:33 +0000 | [diff] [blame] | 33 | if (!N || Visited.count(N)) return; |
Chris Lattner | 3b0a9be | 2003-09-20 22:24:04 +0000 | [diff] [blame] | 34 | Visited.insert(N); |
| 35 | |
| 36 | for (unsigned i = 0, e = N->getNumLinks(); i != e; ++i) { |
| 37 | DSNodeHandle &NH = N->getLink(i*N->getPointerSize()); |
| 38 | if (DSNode *NN = NH.getNode()) { |
| 39 | const std::vector<GlobalValue*> &Globals = NN->getGlobals(); |
| 40 | for (unsigned G = 0, e = Globals.size(); G != e; ++G) |
| 41 | if (Function *F = dyn_cast<Function>(Globals[G])) |
| 42 | ArgsRemainIncomplete.insert(F); |
| 43 | |
| 44 | markReachableFunctionsExternallyAccessible(NN, Visited); |
| 45 | } |
| 46 | } |
Chris Lattner | 4923d1b | 2003-02-03 22:51:28 +0000 | [diff] [blame] | 47 | } |
Vikram S. Adve | aaeee75 | 2002-07-30 22:06:40 +0000 | [diff] [blame] | 48 | |
Chris Lattner | 3b0a9be | 2003-09-20 22:24:04 +0000 | [diff] [blame] | 49 | |
Chris Lattner | aa0b468 | 2002-11-09 21:12:07 +0000 | [diff] [blame] | 50 | // run - Calculate the top down data structure graphs for each function in the |
| 51 | // program. |
| 52 | // |
| 53 | bool TDDataStructures::run(Module &M) { |
| 54 | BUDataStructures &BU = getAnalysis<BUDataStructures>(); |
Chris Lattner | 312edd3 | 2003-06-28 22:14:55 +0000 | [diff] [blame] | 55 | GlobalsGraph = new DSGraph(BU.getGlobalsGraph()); |
Chris Lattner | 11fc930 | 2003-09-20 23:58:33 +0000 | [diff] [blame] | 56 | GlobalsGraph->setPrintAuxCalls(); |
Chris Lattner | aa0b468 | 2002-11-09 21:12:07 +0000 | [diff] [blame] | 57 | |
Chris Lattner | a8da51b | 2003-07-02 04:39:44 +0000 | [diff] [blame] | 58 | // Figure out which functions must not mark their arguments complete because |
Chris Lattner | 3b0a9be | 2003-09-20 22:24:04 +0000 | [diff] [blame] | 59 | // they are accessible outside this compilation unit. Currently, these |
| 60 | // arguments are functions which are reachable by global variables in the |
| 61 | // globals graph. |
| 62 | const DSGraph::ScalarMapTy &GGSM = GlobalsGraph->getScalarMap(); |
| 63 | hash_set<DSNode*> Visited; |
| 64 | for (DSGraph::ScalarMapTy::const_iterator I = GGSM.begin(), E = GGSM.end(); |
| 65 | I != E; ++I) |
| 66 | if (isa<GlobalValue>(I->first)) |
| 67 | markReachableFunctionsExternallyAccessible(I->second.getNode(), Visited); |
Chris Lattner | 11fc930 | 2003-09-20 23:58:33 +0000 | [diff] [blame] | 68 | |
| 69 | // Loop over unresolved call nodes. Any functions passed into (but not |
| 70 | // returned!?) from unresolvable call nodes may be invoked outside of the |
| 71 | // current module. |
| 72 | const std::vector<DSCallSite> &Calls = GlobalsGraph->getAuxFunctionCalls(); |
| 73 | for (unsigned i = 0, e = Calls.size(); i != e; ++i) { |
| 74 | const DSCallSite &CS = Calls[i]; |
| 75 | for (unsigned arg = 0, e = CS.getNumPtrArgs(); arg != e; ++arg) |
| 76 | markReachableFunctionsExternallyAccessible(CS.getPtrArg(arg).getNode(), |
| 77 | Visited); |
| 78 | } |
Chris Lattner | 3b0a9be | 2003-09-20 22:24:04 +0000 | [diff] [blame] | 79 | Visited.clear(); |
| 80 | |
| 81 | // Functions without internal linkage also have unknown incoming arguments! |
Chris Lattner | a8da51b | 2003-07-02 04:39:44 +0000 | [diff] [blame] | 82 | for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) |
Chris Lattner | 3b0a9be | 2003-09-20 22:24:04 +0000 | [diff] [blame] | 83 | if (!I->isExternal() && !I->hasInternalLinkage()) |
Chris Lattner | a8da51b | 2003-07-02 04:39:44 +0000 | [diff] [blame] | 84 | ArgsRemainIncomplete.insert(I); |
| 85 | |
Chris Lattner | 6c87461 | 2003-07-02 23:42:48 +0000 | [diff] [blame] | 86 | // We want to traverse the call graph in reverse post-order. To do this, we |
| 87 | // calculate a post-order traversal, then reverse it. |
| 88 | hash_set<DSGraph*> VisitedGraph; |
| 89 | std::vector<DSGraph*> PostOrder; |
| 90 | const BUDataStructures::ActualCalleesTy &ActualCallees = |
| 91 | getAnalysis<BUDataStructures>().getActualCallees(); |
| 92 | |
Chris Lattner | aa0b468 | 2002-11-09 21:12:07 +0000 | [diff] [blame] | 93 | // Calculate top-down from main... |
| 94 | if (Function *F = M.getMainFunction()) |
Chris Lattner | 61691c5 | 2003-07-02 23:44:15 +0000 | [diff] [blame] | 95 | ComputePostOrder(*F, VisitedGraph, PostOrder, ActualCallees); |
Chris Lattner | aa0b468 | 2002-11-09 21:12:07 +0000 | [diff] [blame] | 96 | |
Vikram S. Adve | 03e19dd | 2003-07-16 21:40:28 +0000 | [diff] [blame] | 97 | // Next calculate the graphs for each unreachable function... |
Chris Lattner | a8da51b | 2003-07-02 04:39:44 +0000 | [diff] [blame] | 98 | for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) |
Chris Lattner | 6c87461 | 2003-07-02 23:42:48 +0000 | [diff] [blame] | 99 | ComputePostOrder(*I, VisitedGraph, PostOrder, ActualCallees); |
| 100 | |
| 101 | VisitedGraph.clear(); // Release memory! |
| 102 | |
| 103 | // Visit each of the graphs in reverse post-order now! |
| 104 | while (!PostOrder.empty()) { |
| 105 | inlineGraphIntoCallees(*PostOrder.back()); |
| 106 | PostOrder.pop_back(); |
| 107 | } |
Chris Lattner | aa0b468 | 2002-11-09 21:12:07 +0000 | [diff] [blame] | 108 | |
Chris Lattner | a8da51b | 2003-07-02 04:39:44 +0000 | [diff] [blame] | 109 | ArgsRemainIncomplete.clear(); |
Chris Lattner | aa0b468 | 2002-11-09 21:12:07 +0000 | [diff] [blame] | 110 | return false; |
| 111 | } |
| 112 | |
Vikram S. Adve | aaeee75 | 2002-07-30 22:06:40 +0000 | [diff] [blame] | 113 | |
Chris Lattner | 7a21163 | 2002-11-08 21:28:37 +0000 | [diff] [blame] | 114 | DSGraph &TDDataStructures::getOrCreateDSGraph(Function &F) { |
| 115 | DSGraph *&G = DSInfo[&F]; |
| 116 | if (G == 0) { // Not created yet? Clone BU graph... |
| 117 | G = new DSGraph(getAnalysis<BUDataStructures>().getDSGraph(F)); |
| 118 | G->getAuxFunctionCalls().clear(); |
Chris Lattner | 24d8007 | 2003-02-04 00:59:32 +0000 | [diff] [blame] | 119 | G->setPrintAuxCalls(); |
Chris Lattner | aa0b468 | 2002-11-09 21:12:07 +0000 | [diff] [blame] | 120 | G->setGlobalsGraph(GlobalsGraph); |
Chris Lattner | 7a21163 | 2002-11-08 21:28:37 +0000 | [diff] [blame] | 121 | } |
| 122 | return *G; |
| 123 | } |
Vikram S. Adve | 26b9826 | 2002-10-20 21:41:02 +0000 | [diff] [blame] | 124 | |
Chris Lattner | dea8146 | 2003-06-29 22:37:07 +0000 | [diff] [blame] | 125 | |
Chris Lattner | 18f07a1 | 2003-07-01 16:28:11 +0000 | [diff] [blame] | 126 | void TDDataStructures::ComputePostOrder(Function &F,hash_set<DSGraph*> &Visited, |
| 127 | std::vector<DSGraph*> &PostOrder, |
| 128 | const BUDataStructures::ActualCalleesTy &ActualCallees) { |
| 129 | if (F.isExternal()) return; |
| 130 | DSGraph &G = getOrCreateDSGraph(F); |
| 131 | if (Visited.count(&G)) return; |
| 132 | Visited.insert(&G); |
| 133 | |
| 134 | // Recursively traverse all of the callee graphs. |
| 135 | const std::vector<DSCallSite> &FunctionCalls = G.getFunctionCalls(); |
Chris Lattner | dea8146 | 2003-06-29 22:37:07 +0000 | [diff] [blame] | 136 | |
Chris Lattner | 18f07a1 | 2003-07-01 16:28:11 +0000 | [diff] [blame] | 137 | for (unsigned i = 0, e = FunctionCalls.size(); i != e; ++i) { |
Chris Lattner | 808a7ae | 2003-09-20 16:34:13 +0000 | [diff] [blame] | 138 | Instruction *CallI = FunctionCalls[i].getCallSite().getInstruction(); |
Chris Lattner | 18f07a1 | 2003-07-01 16:28:11 +0000 | [diff] [blame] | 139 | std::pair<BUDataStructures::ActualCalleesTy::const_iterator, |
| 140 | BUDataStructures::ActualCalleesTy::const_iterator> |
Chris Lattner | 808a7ae | 2003-09-20 16:34:13 +0000 | [diff] [blame] | 141 | IP = ActualCallees.equal_range(CallI); |
Vikram S. Adve | aaeee75 | 2002-07-30 22:06:40 +0000 | [diff] [blame] | 142 | |
Chris Lattner | 18f07a1 | 2003-07-01 16:28:11 +0000 | [diff] [blame] | 143 | for (BUDataStructures::ActualCalleesTy::const_iterator I = IP.first; |
| 144 | I != IP.second; ++I) |
| 145 | ComputePostOrder(*I->second, Visited, PostOrder, ActualCallees); |
| 146 | } |
Chris Lattner | 198be22 | 2002-10-21 19:47:18 +0000 | [diff] [blame] | 147 | |
Chris Lattner | 18f07a1 | 2003-07-01 16:28:11 +0000 | [diff] [blame] | 148 | PostOrder.push_back(&G); |
| 149 | } |
| 150 | |
| 151 | |
| 152 | |
Chris Lattner | 18f07a1 | 2003-07-01 16:28:11 +0000 | [diff] [blame] | 153 | |
Chris Lattner | 6c87461 | 2003-07-02 23:42:48 +0000 | [diff] [blame] | 154 | |
| 155 | // releaseMemory - If the pass pipeline is done with this pass, we can release |
| 156 | // our memory... here... |
| 157 | // |
| 158 | // FIXME: This should be releaseMemory and will work fine, except that LoadVN |
| 159 | // has no way to extend the lifetime of the pass, which screws up ds-aa. |
| 160 | // |
| 161 | void TDDataStructures::releaseMyMemory() { |
| 162 | for (hash_map<Function*, DSGraph*>::iterator I = DSInfo.begin(), |
| 163 | E = DSInfo.end(); I != E; ++I) { |
| 164 | I->second->getReturnNodes().erase(I->first); |
| 165 | if (I->second->getReturnNodes().empty()) |
| 166 | delete I->second; |
Chris Lattner | 18f07a1 | 2003-07-01 16:28:11 +0000 | [diff] [blame] | 167 | } |
Chris Lattner | 18f07a1 | 2003-07-01 16:28:11 +0000 | [diff] [blame] | 168 | |
Chris Lattner | 6c87461 | 2003-07-02 23:42:48 +0000 | [diff] [blame] | 169 | // Empty map so next time memory is released, data structures are not |
| 170 | // re-deleted. |
| 171 | DSInfo.clear(); |
| 172 | delete GlobalsGraph; |
| 173 | GlobalsGraph = 0; |
| 174 | } |
Chris Lattner | 18f07a1 | 2003-07-01 16:28:11 +0000 | [diff] [blame] | 175 | |
| 176 | void TDDataStructures::inlineGraphIntoCallees(DSGraph &Graph) { |
Chris Lattner | 4f2cfc0 | 2003-02-10 18:16:36 +0000 | [diff] [blame] | 177 | // Recompute the Incomplete markers and eliminate unreachable nodes. |
Chris Lattner | 47030f8 | 2003-07-02 19:49:11 +0000 | [diff] [blame] | 178 | Graph.removeTriviallyDeadNodes(); |
Chris Lattner | 4f2cfc0 | 2003-02-10 18:16:36 +0000 | [diff] [blame] | 179 | Graph.maskIncompleteMarkers(); |
Chris Lattner | a8da51b | 2003-07-02 04:39:44 +0000 | [diff] [blame] | 180 | |
| 181 | // If any of the functions has incomplete incoming arguments, don't mark any |
| 182 | // of them as complete. |
| 183 | bool HasIncompleteArgs = false; |
| 184 | const DSGraph::ReturnNodesTy &GraphReturnNodes = Graph.getReturnNodes(); |
| 185 | for (DSGraph::ReturnNodesTy::const_iterator I = GraphReturnNodes.begin(), |
| 186 | E = GraphReturnNodes.end(); I != E; ++I) |
| 187 | if (ArgsRemainIncomplete.count(I->first)) { |
| 188 | HasIncompleteArgs = true; |
| 189 | break; |
| 190 | } |
Vikram S. Adve | 03e19dd | 2003-07-16 21:40:28 +0000 | [diff] [blame] | 191 | |
| 192 | // Now fold in the necessary globals from the GlobalsGraph. A global G |
| 193 | // must be folded in if it exists in the current graph (i.e., is not dead) |
| 194 | // and it was not inlined from any of my callers. If it was inlined from |
| 195 | // a caller, it would have been fully consistent with the GlobalsGraph |
| 196 | // in the caller so folding in is not necessary. Otherwise, this node came |
| 197 | // solely from this function's BU graph and so has to be made consistent. |
| 198 | // |
| 199 | Graph.updateFromGlobalGraph(); |
| 200 | |
| 201 | // Recompute the Incomplete markers. Depends on whether args are complete |
Chris Lattner | a8da51b | 2003-07-02 04:39:44 +0000 | [diff] [blame] | 202 | unsigned Flags |
| 203 | = HasIncompleteArgs ? DSGraph::MarkFormalArgs : DSGraph::IgnoreFormalArgs; |
Chris Lattner | 4f2cfc0 | 2003-02-10 18:16:36 +0000 | [diff] [blame] | 204 | Graph.markIncompleteNodes(Flags | DSGraph::IgnoreGlobals); |
Vikram S. Adve | 03e19dd | 2003-07-16 21:40:28 +0000 | [diff] [blame] | 205 | |
| 206 | // Delete dead nodes. Treat globals that are unreachable as dead also. |
Chris Lattner | 4f2cfc0 | 2003-02-10 18:16:36 +0000 | [diff] [blame] | 207 | Graph.removeDeadNodes(DSGraph::RemoveUnreachableGlobals); |
| 208 | |
Vikram S. Adve | 03e19dd | 2003-07-16 21:40:28 +0000 | [diff] [blame] | 209 | // We are done with computing the current TD Graph! Now move on to |
| 210 | // inlining the current graph into the graphs for its callees, if any. |
| 211 | // |
Chris Lattner | a8da51b | 2003-07-02 04:39:44 +0000 | [diff] [blame] | 212 | const std::vector<DSCallSite> &FunctionCalls = Graph.getFunctionCalls(); |
| 213 | if (FunctionCalls.empty()) { |
Chris Lattner | 18f07a1 | 2003-07-01 16:28:11 +0000 | [diff] [blame] | 214 | DEBUG(std::cerr << " [TD] No callees for: " << Graph.getFunctionNames() |
| 215 | << "\n"); |
| 216 | return; |
| 217 | } |
| 218 | |
Chris Lattner | 18f07a1 | 2003-07-01 16:28:11 +0000 | [diff] [blame] | 219 | // Now that we have information about all of the callees, propagate the |
Vikram S. Adve | 03e19dd | 2003-07-16 21:40:28 +0000 | [diff] [blame] | 220 | // current graph into the callees. Clone only the reachable subgraph at |
| 221 | // each call-site, not the entire graph (even though the entire graph |
| 222 | // would be cloned only once, this should still be better on average). |
Chris Lattner | 18f07a1 | 2003-07-01 16:28:11 +0000 | [diff] [blame] | 223 | // |
| 224 | DEBUG(std::cerr << " [TD] Inlining '" << Graph.getFunctionNames() <<"' into " |
Chris Lattner | a8da51b | 2003-07-02 04:39:44 +0000 | [diff] [blame] | 225 | << FunctionCalls.size() << " call nodes.\n"); |
Chris Lattner | 18f07a1 | 2003-07-01 16:28:11 +0000 | [diff] [blame] | 226 | |
Chris Lattner | a8da51b | 2003-07-02 04:39:44 +0000 | [diff] [blame] | 227 | const BUDataStructures::ActualCalleesTy &ActualCallees = |
| 228 | getAnalysis<BUDataStructures>().getActualCallees(); |
Chris Lattner | 18f07a1 | 2003-07-01 16:28:11 +0000 | [diff] [blame] | 229 | |
Vikram S. Adve | 03e19dd | 2003-07-16 21:40:28 +0000 | [diff] [blame] | 230 | // Loop over all the call sites and all the callees at each call site. |
| 231 | // Clone and merge the reachable subgraph from the call into callee's graph. |
| 232 | // |
Chris Lattner | a8da51b | 2003-07-02 04:39:44 +0000 | [diff] [blame] | 233 | for (unsigned i = 0, e = FunctionCalls.size(); i != e; ++i) { |
Chris Lattner | 808a7ae | 2003-09-20 16:34:13 +0000 | [diff] [blame] | 234 | Instruction *CallI = FunctionCalls[i].getCallSite().getInstruction(); |
Vikram S. Adve | 03e19dd | 2003-07-16 21:40:28 +0000 | [diff] [blame] | 235 | // For each function in the invoked function list at this call site... |
Chris Lattner | a8da51b | 2003-07-02 04:39:44 +0000 | [diff] [blame] | 236 | std::pair<BUDataStructures::ActualCalleesTy::const_iterator, |
| 237 | BUDataStructures::ActualCalleesTy::const_iterator> |
Chris Lattner | 808a7ae | 2003-09-20 16:34:13 +0000 | [diff] [blame] | 238 | IP = ActualCallees.equal_range(CallI); |
Chris Lattner | a8da51b | 2003-07-02 04:39:44 +0000 | [diff] [blame] | 239 | |
Vikram S. Adve | 03e19dd | 2003-07-16 21:40:28 +0000 | [diff] [blame] | 240 | // Multiple callees may have the same graph, so try to inline and merge |
| 241 | // only once for each <callSite,calleeGraph> pair, not once for each |
| 242 | // <callSite,calleeFunction> pair; the latter will be correct but slower. |
| 243 | hash_set<DSGraph*> GraphsSeen; |
| 244 | |
| 245 | // Loop over each actual callee at this call site |
| 246 | for (BUDataStructures::ActualCalleesTy::const_iterator I = IP.first; |
| 247 | I != IP.second; ++I) { |
| 248 | DSGraph& CalleeGraph = getDSGraph(*I->second); |
| 249 | assert(&CalleeGraph != &Graph && "TD need not inline graph into self!"); |
| 250 | |
| 251 | // if this callee graph is already done at this site, skip this callee |
| 252 | if (GraphsSeen.find(&CalleeGraph) != GraphsSeen.end()) |
| 253 | continue; |
| 254 | GraphsSeen.insert(&CalleeGraph); |
| 255 | |
| 256 | // Get the root nodes for cloning the reachable subgraph into each callee: |
| 257 | // -- all global nodes that appear in both the caller and the callee |
| 258 | // -- return value at this call site, if any |
| 259 | // -- actual arguments passed at this call site |
| 260 | // -- callee node at this call site, if this is an indirect call (this may |
| 261 | // not be needed for merging, but allows us to create CS and therefore |
| 262 | // simplify the merging below). |
| 263 | hash_set<const DSNode*> RootNodeSet; |
| 264 | for (DSGraph::ScalarMapTy::const_iterator |
| 265 | SI = CalleeGraph.getScalarMap().begin(), |
| 266 | SE = CalleeGraph.getScalarMap().end(); SI != SE; ++SI) |
| 267 | if (GlobalValue* GV = dyn_cast<GlobalValue>(SI->first)) { |
| 268 | DSGraph::ScalarMapTy::const_iterator GI=Graph.getScalarMap().find(GV); |
| 269 | if (GI != Graph.getScalarMap().end()) |
| 270 | RootNodeSet.insert(GI->second.getNode()); |
Chris Lattner | a8da51b | 2003-07-02 04:39:44 +0000 | [diff] [blame] | 271 | } |
Chris Lattner | 18f07a1 | 2003-07-01 16:28:11 +0000 | [diff] [blame] | 272 | |
Vikram S. Adve | 03e19dd | 2003-07-16 21:40:28 +0000 | [diff] [blame] | 273 | if (const DSNode* RetNode = FunctionCalls[i].getRetVal().getNode()) |
| 274 | RootNodeSet.insert(RetNode); |
Chris Lattner | 0e74412 | 2002-10-17 04:26:54 +0000 | [diff] [blame] | 275 | |
Vikram S. Adve | 03e19dd | 2003-07-16 21:40:28 +0000 | [diff] [blame] | 276 | for (unsigned j=0, N=FunctionCalls[i].getNumPtrArgs(); j < N; ++j) |
| 277 | if (const DSNode* ArgTarget = FunctionCalls[i].getPtrArg(j).getNode()) |
| 278 | RootNodeSet.insert(ArgTarget); |
| 279 | |
| 280 | if (FunctionCalls[i].isIndirectCall()) |
| 281 | RootNodeSet.insert(FunctionCalls[i].getCalleeNode()); |
| 282 | |
Chris Lattner | a8da51b | 2003-07-02 04:39:44 +0000 | [diff] [blame] | 283 | DEBUG(std::cerr << " [TD] Resolving arguments for callee graph '" |
Vikram S. Adve | 03e19dd | 2003-07-16 21:40:28 +0000 | [diff] [blame] | 284 | << CalleeGraph.getFunctionNames() |
| 285 | << "': " << I->second->getFunctionType()->getNumParams() |
| 286 | << " args\n at call site (DSCallSite*) 0x" |
| 287 | << &FunctionCalls[i] << "\n"); |
| 288 | |
| 289 | DSGraph::NodeMapTy NodeMapInCallee; // map from nodes to clones in callee |
| 290 | DSGraph::NodeMapTy CompletedMap; // unused map for nodes not to do |
| 291 | CalleeGraph.cloneReachableSubgraph(Graph, RootNodeSet, |
| 292 | NodeMapInCallee, CompletedMap, |
| 293 | DSGraph::StripModRefBits | |
| 294 | DSGraph::KeepAllocaBit); |
Chris Lattner | 7a21163 | 2002-11-08 21:28:37 +0000 | [diff] [blame] | 295 | |
Vikram S. Adve | 03e19dd | 2003-07-16 21:40:28 +0000 | [diff] [blame] | 296 | // Transform our call site info into the cloned version for CalleeGraph |
| 297 | DSCallSite CS(FunctionCalls[i], NodeMapInCallee); |
Chris Lattner | a8da51b | 2003-07-02 04:39:44 +0000 | [diff] [blame] | 298 | |
Vikram S. Adve | 03e19dd | 2003-07-16 21:40:28 +0000 | [diff] [blame] | 299 | // Get the formal argument and return nodes for the called function |
| 300 | // and merge them with the cloned subgraph. Global nodes were merged |
| 301 | // already by cloneReachableSubgraph() above. |
| 302 | CalleeGraph.getCallSiteForArguments(*I->second).mergeWith(CS); |
| 303 | |
| 304 | ++NumTDInlines; |
Chris Lattner | a8da51b | 2003-07-02 04:39:44 +0000 | [diff] [blame] | 305 | } |
Chris Lattner | e0fbd48 | 2003-02-09 18:42:43 +0000 | [diff] [blame] | 306 | } |
Chris Lattner | 18f07a1 | 2003-07-01 16:28:11 +0000 | [diff] [blame] | 307 | |
| 308 | DEBUG(std::cerr << " [TD] Done inlining into callees for: " |
| 309 | << Graph.getFunctionNames() << " [" << Graph.getGraphSize() << "+" |
| 310 | << Graph.getFunctionCalls().size() << "]\n"); |
Vikram S. Adve | aaeee75 | 2002-07-30 22:06:40 +0000 | [diff] [blame] | 311 | } |
Chris Lattner | 4923d1b | 2003-02-03 22:51:28 +0000 | [diff] [blame] | 312 | |