diff options
author | Chris Lattner <sabre@nondot.org> | 2003-09-20 22:24:04 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2003-09-20 22:24:04 +0000 |
commit | 3b0a9be238e95fc125bec302272157f63e1110f3 (patch) | |
tree | 66c72a2b4bcdeebb1d2cf80f498c9104d497d6f7 /lib/Analysis/DataStructure/TopDownClosure.cpp | |
parent | 26c4fc3b69b01b4c8c5954d1ecd85a556422cd80 (diff) |
Do not mark incoming arguments to functions complete if the function is pointed to by a global in the globals graph
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8637 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/DataStructure/TopDownClosure.cpp')
-rw-r--r-- | lib/Analysis/DataStructure/TopDownClosure.cpp | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/lib/Analysis/DataStructure/TopDownClosure.cpp b/lib/Analysis/DataStructure/TopDownClosure.cpp index 13535e3f80..1266e5ee09 100644 --- a/lib/Analysis/DataStructure/TopDownClosure.cpp +++ b/lib/Analysis/DataStructure/TopDownClosure.cpp @@ -21,16 +21,25 @@ namespace { Statistic<> NumTDInlines("tddatastructures", "Number of graphs inlined"); } -/// FunctionHasCompleteArguments - This function returns true if it is safe not -/// to mark arguments to the function complete. -/// -/// FIXME: Need to check if all callers have been found, or rather if a -/// funcpointer escapes! -/// -static bool FunctionHasCompleteArguments(Function &F) { - return F.hasInternalLinkage(); +void TDDataStructures::markReachableFunctionsExternallyAccessible(DSNode *N, + hash_set<DSNode*> &Visited) { + if (Visited.count(N)) return; + Visited.insert(N); + + for (unsigned i = 0, e = N->getNumLinks(); i != e; ++i) { + DSNodeHandle &NH = N->getLink(i*N->getPointerSize()); + if (DSNode *NN = NH.getNode()) { + const std::vector<GlobalValue*> &Globals = NN->getGlobals(); + for (unsigned G = 0, e = Globals.size(); G != e; ++G) + if (Function *F = dyn_cast<Function>(Globals[G])) + ArgsRemainIncomplete.insert(F); + + markReachableFunctionsExternallyAccessible(NN, Visited); + } + } } + // run - Calculate the top down data structure graphs for each function in the // program. // @@ -39,9 +48,20 @@ bool TDDataStructures::run(Module &M) { GlobalsGraph = new DSGraph(BU.getGlobalsGraph()); // Figure out which functions must not mark their arguments complete because - // they are accessible outside this compilation unit. + // they are accessible outside this compilation unit. Currently, these + // arguments are functions which are reachable by global variables in the + // globals graph. + const DSGraph::ScalarMapTy &GGSM = GlobalsGraph->getScalarMap(); + hash_set<DSNode*> Visited; + for (DSGraph::ScalarMapTy::const_iterator I = GGSM.begin(), E = GGSM.end(); + I != E; ++I) + if (isa<GlobalValue>(I->first)) + markReachableFunctionsExternallyAccessible(I->second.getNode(), Visited); + Visited.clear(); + + // Functions without internal linkage also have unknown incoming arguments! for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) - if (!FunctionHasCompleteArguments(*I)) + if (!I->isExternal() && !I->hasInternalLinkage()) ArgsRemainIncomplete.insert(I); // We want to traverse the call graph in reverse post-order. To do this, we |