From 2b9926fc8eceb304bafe0e77a8876579d392f7bb Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 2 Nov 2003 22:27:28 +0000 Subject: All DSGraphs keep a reference to the targetdata they are created with. This is used to eliminate the hard coded, hacked in, sparc specific, global TargetData. Changing the TargetData used to actually match the code fixes problems, and eliminates a crash. llvm-svn: 9659 --- llvm/lib/Analysis/DataStructure/Local.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'llvm/lib/Analysis/DataStructure/Local.cpp') diff --git a/llvm/lib/Analysis/DataStructure/Local.cpp b/llvm/lib/Analysis/DataStructure/Local.cpp index fcaadf3755f..689373ee7d2 100644 --- a/llvm/lib/Analysis/DataStructure/Local.cpp +++ b/llvm/lib/Analysis/DataStructure/Local.cpp @@ -16,8 +16,6 @@ #include "llvm/Analysis/DSGraph.h" #include "llvm/Constants.h" #include "llvm/DerivedTypes.h" -#include "llvm/Function.h" -#include "llvm/GlobalVariable.h" #include "llvm/Instructions.h" #include "llvm/Support/InstVisitor.h" #include "llvm/Target/TargetData.h" @@ -34,9 +32,6 @@ static RegisterAnalysis X("datastructure", "Local Data Structure Analysis"); namespace DS { - // FIXME: Do something smarter with target data! - TargetData TD("temp-td"); - // isPointerType - Return true if this type is big enough to hold a pointer. bool isPointerType(const Type *Ty) { if (isa(Ty)) @@ -152,7 +147,8 @@ namespace { //===----------------------------------------------------------------------===// // DSGraph constructor - Simply use the GraphBuilder to construct the local // graph. -DSGraph::DSGraph(Function &F, DSGraph *GG) : GlobalsGraph(GG) { +DSGraph::DSGraph(const TargetData &td, Function &F, DSGraph *GG) + : GlobalsGraph(GG), TD(td) { PrintAuxCalls = false; DEBUG(std::cerr << " [Loc] Calculating graph for: " << F.getName() << "\n"); @@ -311,6 +307,8 @@ void GraphBuilder::visitGetElementPtrInst(User &GEP) { return; } + const TargetData &TD = Value.getNode()->getTargetData(); + #if 0 // Handle the pointer index specially... if (GEP.getNumOperands() > 1 && @@ -531,7 +529,9 @@ void GraphBuilder::MergeConstantInitIntoNode(DSNodeHandle &NH, Constant *C) { NH.addEdgeTo(getValueDest(*C)); return; } - + + const TargetData &TD = NH.getNode()->getTargetData(); + if (ConstantArray *CA = dyn_cast(C)) { for (unsigned i = 0, e = CA->getNumOperands(); i != e; ++i) // We don't currently do any indexing for arrays... @@ -556,12 +556,14 @@ void GraphBuilder::mergeInGlobalInitializer(GlobalVariable *GV) { bool LocalDataStructures::run(Module &M) { - GlobalsGraph = new DSGraph(); + GlobalsGraph = new DSGraph(getAnalysis()); + + const TargetData &TD = getAnalysis(); // Calculate all of the graphs... for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) if (!I->isExternal()) - DSInfo.insert(std::make_pair(I, new DSGraph(*I, GlobalsGraph))); + DSInfo.insert(std::make_pair(I, new DSGraph(TD, *I, GlobalsGraph))); GraphBuilder GGB(*GlobalsGraph); -- cgit v1.2.3