diff options
author | Chris Lattner <sabre@nondot.org> | 2005-03-15 17:14:09 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2005-03-15 17:14:09 +0000 |
commit | 2af8c5185a18f96429432f2c15b2425ac429f0fd (patch) | |
tree | fabfcc5864fb789e67ba23180633560f40e2ba7e /lib/Analysis/DataStructure/EquivClassGraphs.cpp | |
parent | a5f47ea23d274527bdbe461d69bc63c82416d685 (diff) |
Finally fix (the right way) the problem where functions like this:
void foo() {
G = 1;
}
would have an empty DSGraph even though G (a global) is directly used
in the function.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20619 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/DataStructure/EquivClassGraphs.cpp')
-rw-r--r-- | lib/Analysis/DataStructure/EquivClassGraphs.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/Analysis/DataStructure/EquivClassGraphs.cpp b/lib/Analysis/DataStructure/EquivClassGraphs.cpp index daefb673cb..2ddc684e01 100644 --- a/lib/Analysis/DataStructure/EquivClassGraphs.cpp +++ b/lib/Analysis/DataStructure/EquivClassGraphs.cpp @@ -16,6 +16,7 @@ #define DEBUG_TYPE "ECGraphs" #include "llvm/Analysis/DataStructure/EquivClassGraphs.h" +#include "llvm/DerivedTypes.h" #include "llvm/Module.h" #include "llvm/Pass.h" #include "llvm/Analysis/DataStructure/DSGraph.h" @@ -123,6 +124,29 @@ bool EquivClassGraphs::runOnModule(Module &M) { DSGraph::IgnoreGlobals); } + // Final processing. Note that dead node elimination may actually remove + // globals from a function graph that are immediately used. If there are no + // scalars pointing to the node (e.g. because the only use is a direct store + // to a scalar global) we have to make sure to rematerialize the globals back + // into the graphs here, or clients will break! + for (Module::global_iterator GI = M.global_begin(), E = M.global_end(); + GI != E; ++GI) + // This only happens to first class typed globals. + if (GI->getType()->getElementType()->isFirstClassType()) + for (Value::use_iterator UI = GI->use_begin(), E = GI->use_end(); + UI != E; ++UI) + // This only happens to direct uses by instructions. + if (Instruction *User = dyn_cast<Instruction>(*UI)) { + DSGraph &DSG = getOrCreateGraph(*User->getParent()->getParent()); + if (!DSG.getScalarMap().count(GI)) { + // If this global does not exist in the graph, but it is immediately + // used by an instruction in the graph, clone it over from the + // globals graph. + ReachabilityCloner RC(DSG, *GlobalsGraph, 0); + RC.getClonedNH(GlobalsGraph->getNodeForValue(GI)); + } + } + return false; } |