blob: bc2065ef653196074833f9f839f366f3542a11f2 [file] [log] [blame]
Chris Lattnerfccd06f2002-10-01 22:33:50 +00001//===- Local.cpp - Compute a local data structure graph for a function ----===//
Chris Lattnerc68c31b2002-07-10 22:38:08 +00002//
3// Compute the local version of the data structure graph for a function. The
4// external interface to this file is the DSGraph constructor.
5//
6//===----------------------------------------------------------------------===//
7
Chris Lattnerc5f21de2002-10-02 22:14:38 +00008#include "llvm/Analysis/DSGraph.h"
Chris Lattner055dc2c2002-07-18 15:54:42 +00009#include "llvm/Analysis/DataStructure.h"
Chris Lattnerc68c31b2002-07-10 22:38:08 +000010#include "llvm/iMemory.h"
11#include "llvm/iTerminators.h"
12#include "llvm/iPHINode.h"
13#include "llvm/iOther.h"
14#include "llvm/Constants.h"
15#include "llvm/DerivedTypes.h"
Chris Lattnerfccd06f2002-10-01 22:33:50 +000016#include "llvm/Function.h"
17#include "llvm/GlobalVariable.h"
Chris Lattnerc68c31b2002-07-10 22:38:08 +000018#include "llvm/Support/InstVisitor.h"
Chris Lattnerfccd06f2002-10-01 22:33:50 +000019#include "llvm/Target/TargetData.h"
20#include "Support/Statistic.h"
21
22// FIXME: This should eventually be a FunctionPass that is automatically
23// aggregated into a Pass.
24//
25#include "llvm/Module.h"
26
Chris Lattnerc68c31b2002-07-10 22:38:08 +000027using std::map;
28using std::vector;
29
Chris Lattner97f51a32002-07-27 01:12:15 +000030static RegisterAnalysis<LocalDataStructures>
31X("datastructure", "Local Data Structure Analysis");
Chris Lattner97f51a32002-07-27 01:12:15 +000032
Chris Lattnerfccd06f2002-10-01 22:33:50 +000033using namespace DataStructureAnalysis;
34
35namespace DataStructureAnalysis {
36 // FIXME: Do something smarter with target data!
37 TargetData TD("temp-td");
38 unsigned PointerSize(TD.getPointerSize());
39
40 // isPointerType - Return true if this type is big enough to hold a pointer.
41 bool isPointerType(const Type *Ty) {
42 if (isa<PointerType>(Ty))
43 return true;
44 else if (Ty->isPrimitiveType() && Ty->isInteger())
45 return Ty->getPrimitiveSize() >= PointerSize;
46 return false;
47 }
48}
49
Chris Lattnerc68c31b2002-07-10 22:38:08 +000050
51namespace {
Chris Lattnerfccd06f2002-10-01 22:33:50 +000052 //===--------------------------------------------------------------------===//
53 // GraphBuilder Class
54 //===--------------------------------------------------------------------===//
55 //
56 /// This class is the builder class that constructs the local data structure
57 /// graph by performing a single pass over the function in question.
58 ///
Chris Lattnerc68c31b2002-07-10 22:38:08 +000059 class GraphBuilder : InstVisitor<GraphBuilder> {
60 DSGraph &G;
61 vector<DSNode*> &Nodes;
62 DSNodeHandle &RetNode; // Node that gets returned...
Chris Lattnerc875f022002-11-03 21:27:48 +000063 map<Value*, DSNodeHandle> &ScalarMap;
Vikram S. Adve42fd1692002-10-20 18:07:37 +000064 vector<DSCallSite> &FunctionCalls;
Chris Lattnerc68c31b2002-07-10 22:38:08 +000065
66 public:
67 GraphBuilder(DSGraph &g, vector<DSNode*> &nodes, DSNodeHandle &retNode,
Chris Lattnerc875f022002-11-03 21:27:48 +000068 map<Value*, DSNodeHandle> &SM,
Vikram S. Adve42fd1692002-10-20 18:07:37 +000069 vector<DSCallSite> &fc)
Chris Lattnerc875f022002-11-03 21:27:48 +000070 : G(g), Nodes(nodes), RetNode(retNode), ScalarMap(SM), FunctionCalls(fc) {
Chris Lattner0d9bab82002-07-18 00:12:30 +000071
72 // Create scalar nodes for all pointer arguments...
73 for (Function::aiterator I = G.getFunction().abegin(),
74 E = G.getFunction().aend(); I != E; ++I)
Chris Lattnerfccd06f2002-10-01 22:33:50 +000075 if (isPointerType(I->getType()))
76 getValueDest(*I);
Chris Lattner0d9bab82002-07-18 00:12:30 +000077
Chris Lattnerc68c31b2002-07-10 22:38:08 +000078 visit(G.getFunction()); // Single pass over the function
Chris Lattner2a2c4902002-07-18 18:19:09 +000079
80 // Not inlining, only eliminate trivially dead nodes.
81 G.removeTriviallyDeadNodes();
Chris Lattnerc68c31b2002-07-10 22:38:08 +000082 }
83
84 private:
85 // Visitor functions, used to handle each instruction type we encounter...
86 friend class InstVisitor<GraphBuilder>;
Chris Lattnerd18f3422002-11-03 21:24:04 +000087 void visitMallocInst(MallocInst &MI) { handleAlloc(MI, DSNode::HeapNode); }
Chris Lattnerc68c31b2002-07-10 22:38:08 +000088 void visitAllocaInst(AllocaInst &AI) { handleAlloc(AI, DSNode::AllocaNode);}
89 void handleAlloc(AllocationInst &AI, DSNode::NodeTy NT);
90
91 void visitPHINode(PHINode &PN);
92
93 void visitGetElementPtrInst(GetElementPtrInst &GEP);
94 void visitReturnInst(ReturnInst &RI);
95 void visitLoadInst(LoadInst &LI);
96 void visitStoreInst(StoreInst &SI);
97 void visitCallInst(CallInst &CI);
98 void visitSetCondInst(SetCondInst &SCI) {} // SetEQ & friends are ignored
99 void visitFreeInst(FreeInst &FI) {} // Ignore free instructions
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000100 void visitCastInst(CastInst &CI);
101 void visitInstruction(Instruction &I) {}
Chris Lattnerc68c31b2002-07-10 22:38:08 +0000102
103 private:
104 // Helper functions used to implement the visitation functions...
105
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000106 /// createNode - Create a new DSNode, ensuring that it is properly added to
107 /// the graph.
108 ///
Chris Lattner92673292002-11-02 00:13:20 +0000109 DSNode *createNode(DSNode::NodeTy NodeType, const Type *Ty = 0) {
110 DSNode *N = new DSNode(NodeType, Ty); // Create the node
111 Nodes.push_back(N); // Add node to nodes list
112 return N;
113 }
Chris Lattnerc68c31b2002-07-10 22:38:08 +0000114
Chris Lattnerc875f022002-11-03 21:27:48 +0000115 /// setDestTo - Set the ScalarMap entry for the specified value to point to
Chris Lattner92673292002-11-02 00:13:20 +0000116 /// the specified destination. If the Value already points to a node, make
117 /// sure to merge the two destinations together.
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000118 ///
Chris Lattner92673292002-11-02 00:13:20 +0000119 void setDestTo(Value &V, const DSNodeHandle &NH);
Chris Lattnerc68c31b2002-07-10 22:38:08 +0000120
Chris Lattner92673292002-11-02 00:13:20 +0000121 /// getValueDest - Return the DSNode that the actual value points to.
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000122 ///
Chris Lattner92673292002-11-02 00:13:20 +0000123 DSNodeHandle getValueDest(Value &V);
Chris Lattnerc68c31b2002-07-10 22:38:08 +0000124
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000125 /// getLink - This method is used to return the specified link in the
126 /// specified node if one exists. If a link does not already exist (it's
Chris Lattner7e51c872002-10-31 06:52:26 +0000127 /// null), then we create a new node, link it, then return it.
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000128 ///
Chris Lattner7e51c872002-10-31 06:52:26 +0000129 DSNodeHandle &getLink(const DSNodeHandle &Node, unsigned Link = 0);
Chris Lattnerc68c31b2002-07-10 22:38:08 +0000130 };
131}
132
133//===----------------------------------------------------------------------===//
134// DSGraph constructor - Simply use the GraphBuilder to construct the local
135// graph.
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000136DSGraph::DSGraph(Function &F) : Func(&F) {
137 // Use the graph builder to construct the local version of the graph
Chris Lattnerc875f022002-11-03 21:27:48 +0000138 GraphBuilder B(*this, Nodes, RetNode, ScalarMap, FunctionCalls);
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000139 markIncompleteNodes();
Chris Lattnerc68c31b2002-07-10 22:38:08 +0000140}
141
142
143//===----------------------------------------------------------------------===//
144// Helper method implementations...
145//
146
147
Chris Lattner92673292002-11-02 00:13:20 +0000148/// getValueDest - Return the DSNode that the actual value points to.
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000149///
Chris Lattner92673292002-11-02 00:13:20 +0000150DSNodeHandle GraphBuilder::getValueDest(Value &V) {
151 if (Constant *C = dyn_cast<Constant>(&V)) {
152 // FIXME: Return null NH for constants like 10 or null
153 // FIXME: Handle constant exprs here.
154
155 return 0; // Constant doesn't point to anything.
156 }
157
Chris Lattnerc875f022002-11-03 21:27:48 +0000158 DSNodeHandle &NH = ScalarMap[&V];
Chris Lattner92673292002-11-02 00:13:20 +0000159 if (NH.getNode())
160 return NH; // Already have a node? Just return it...
161
162 // Otherwise we need to create a new node to point to...
163 DSNode *N;
164 if (GlobalValue *GV = dyn_cast<GlobalValue>(&V)) {
165 // Create a new global node for this global variable...
166 N = createNode(DSNode::GlobalNode, GV->getType()->getElementType());
167 N->addGlobal(GV);
168 } else {
169 // Otherwise just create a shadow node
170 N = createNode(DSNode::ShadowNode);
171 }
172
173 NH.setNode(N); // Remember that we are pointing to it...
174 NH.setOffset(0);
175 return NH;
Chris Lattnerc68c31b2002-07-10 22:38:08 +0000176}
177
Chris Lattner0d9bab82002-07-18 00:12:30 +0000178
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000179/// getLink - This method is used to return the specified link in the
180/// specified node if one exists. If a link does not already exist (it's
181/// null), then we create a new node, link it, then return it. We must
182/// specify the type of the Node field we are accessing so that we know what
183/// type should be linked to if we need to create a new node.
184///
Chris Lattner7e51c872002-10-31 06:52:26 +0000185DSNodeHandle &GraphBuilder::getLink(const DSNodeHandle &node, unsigned LinkNo) {
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000186 DSNodeHandle &Node = const_cast<DSNodeHandle&>(node);
Chris Lattner08db7192002-11-06 06:20:27 +0000187 DSNodeHandle &Link = Node.getLink(LinkNo);
188 if (!Link.getNode()) {
189 // If the link hasn't been created yet, make and return a new shadow node
190 Link = createNode(DSNode::ShadowNode);
191 }
192 return Link;
Chris Lattnerc68c31b2002-07-10 22:38:08 +0000193}
194
Chris Lattnerc68c31b2002-07-10 22:38:08 +0000195
Chris Lattnerc875f022002-11-03 21:27:48 +0000196/// setDestTo - Set the ScalarMap entry for the specified value to point to the
Chris Lattner92673292002-11-02 00:13:20 +0000197/// specified destination. If the Value already points to a node, make sure to
198/// merge the two destinations together.
199///
200void GraphBuilder::setDestTo(Value &V, const DSNodeHandle &NH) {
Chris Lattnerc875f022002-11-03 21:27:48 +0000201 DSNodeHandle &AINH = ScalarMap[&V];
Chris Lattner92673292002-11-02 00:13:20 +0000202 if (AINH.getNode() == 0) // Not pointing to anything yet?
203 AINH = NH; // Just point directly to NH
204 else
205 AINH.mergeWith(NH);
206}
207
208
Chris Lattnerc68c31b2002-07-10 22:38:08 +0000209//===----------------------------------------------------------------------===//
210// Specific instruction type handler implementations...
211//
212
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000213/// Alloca & Malloc instruction implementation - Simply create a new memory
214/// object, pointing the scalar to it.
215///
Chris Lattnerc68c31b2002-07-10 22:38:08 +0000216void GraphBuilder::handleAlloc(AllocationInst &AI, DSNode::NodeTy NodeType) {
Chris Lattner92673292002-11-02 00:13:20 +0000217 setDestTo(AI, createNode(NodeType));
Chris Lattnerc68c31b2002-07-10 22:38:08 +0000218}
219
220// PHINode - Make the scalar for the PHI node point to all of the things the
221// incoming values point to... which effectively causes them to be merged.
222//
223void GraphBuilder::visitPHINode(PHINode &PN) {
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000224 if (!isPointerType(PN.getType())) return; // Only pointer PHIs
Chris Lattnerc68c31b2002-07-10 22:38:08 +0000225
Chris Lattnerc875f022002-11-03 21:27:48 +0000226 DSNodeHandle &PNDest = ScalarMap[&PN];
Chris Lattnerc68c31b2002-07-10 22:38:08 +0000227 for (unsigned i = 0, e = PN.getNumIncomingValues(); i != e; ++i)
Chris Lattner92673292002-11-02 00:13:20 +0000228 PNDest.mergeWith(getValueDest(*PN.getIncomingValue(i)));
Chris Lattnerc68c31b2002-07-10 22:38:08 +0000229}
230
231void GraphBuilder::visitGetElementPtrInst(GetElementPtrInst &GEP) {
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000232 DSNodeHandle Value = getValueDest(*GEP.getOperand(0));
Chris Lattner92673292002-11-02 00:13:20 +0000233 if (Value.getNode() == 0) return;
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000234
235 unsigned Offset = 0;
Chris Lattner8f0a16e2002-10-31 05:45:02 +0000236 const PointerType *PTy = cast<PointerType>(GEP.getOperand(0)->getType());
237 const Type *CurTy = PTy->getElementType();
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000238
Chris Lattner08db7192002-11-06 06:20:27 +0000239 if (Value.getNode()->mergeTypeInfo(CurTy, Value.getOffset())) {
240 // If the node had to be folded... exit quickly
Chris Lattner92673292002-11-02 00:13:20 +0000241 setDestTo(GEP, Value); // GEP result points to folded node
Chris Lattner8f0a16e2002-10-31 05:45:02 +0000242 return;
243 }
244
Chris Lattner08db7192002-11-06 06:20:27 +0000245#if 0
Chris Lattner8f0a16e2002-10-31 05:45:02 +0000246 // Handle the pointer index specially...
247 if (GEP.getNumOperands() > 1 &&
248 GEP.getOperand(1) != ConstantSInt::getNullValue(Type::LongTy)) {
249
250 // If we already know this is an array being accessed, don't do anything...
251 if (!TopTypeRec.isArray) {
252 TopTypeRec.isArray = true;
253
254 // If we are treating some inner field pointer as an array, fold the node
255 // up because we cannot handle it right. This can come because of
256 // something like this: &((&Pt->X)[1]) == &Pt->Y
257 //
258 if (Value.getOffset()) {
259 // Value is now the pointer we want to GEP to be...
260 Value.getNode()->foldNodeCompletely();
Chris Lattner92673292002-11-02 00:13:20 +0000261 setDestTo(GEP, Value); // GEP result points to folded node
Chris Lattner8f0a16e2002-10-31 05:45:02 +0000262 return;
263 } else {
264 // This is a pointer to the first byte of the node. Make sure that we
265 // are pointing to the outter most type in the node.
266 // FIXME: We need to check one more case here...
267 }
268 }
269 }
Chris Lattner08db7192002-11-06 06:20:27 +0000270#endif
Chris Lattner8f0a16e2002-10-31 05:45:02 +0000271
272 // All of these subscripts are indexing INTO the elements we have...
273 for (unsigned i = 2, e = GEP.getNumOperands(); i < e; ++i)
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000274 if (GEP.getOperand(i)->getType() == Type::LongTy) {
Chris Lattnere03f32b2002-10-02 06:24:36 +0000275 // Get the type indexing into...
276 const SequentialType *STy = cast<SequentialType>(CurTy);
277 CurTy = STy->getElementType();
Chris Lattner08db7192002-11-06 06:20:27 +0000278#if 0
Chris Lattnere03f32b2002-10-02 06:24:36 +0000279 if (ConstantSInt *CS = dyn_cast<ConstantSInt>(GEP.getOperand(i))) {
Chris Lattner8f0a16e2002-10-31 05:45:02 +0000280 Offset += CS->getValue()*TD.getTypeSize(CurTy);
Chris Lattnere03f32b2002-10-02 06:24:36 +0000281 } else {
282 // Variable index into a node. We must merge all of the elements of the
283 // sequential type here.
284 if (isa<PointerType>(STy))
285 std::cerr << "Pointer indexing not handled yet!\n";
286 else {
287 const ArrayType *ATy = cast<ArrayType>(STy);
288 unsigned ElSize = TD.getTypeSize(CurTy);
289 DSNode *N = Value.getNode();
290 assert(N && "Value must have a node!");
291 unsigned RawOffset = Offset+Value.getOffset();
292
293 // Loop over all of the elements of the array, merging them into the
294 // zero'th element.
295 for (unsigned i = 1, e = ATy->getNumElements(); i != e; ++i)
296 // Merge all of the byte components of this array element
297 for (unsigned j = 0; j != ElSize; ++j)
298 N->mergeIndexes(RawOffset+j, RawOffset+i*ElSize+j);
299 }
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000300 }
Chris Lattner08db7192002-11-06 06:20:27 +0000301#endif
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000302 } else if (GEP.getOperand(i)->getType() == Type::UByteTy) {
303 unsigned FieldNo = cast<ConstantUInt>(GEP.getOperand(i))->getValue();
304 const StructType *STy = cast<StructType>(CurTy);
305 Offset += TD.getStructLayout(STy)->MemberOffsets[FieldNo];
306 CurTy = STy->getContainedType(FieldNo);
307 }
308
309 // Add in the offset calculated...
310 Value.setOffset(Value.getOffset()+Offset);
311
312 // Value is now the pointer we want to GEP to be...
Chris Lattner92673292002-11-02 00:13:20 +0000313 setDestTo(GEP, Value);
Chris Lattnerc68c31b2002-07-10 22:38:08 +0000314}
315
316void GraphBuilder::visitLoadInst(LoadInst &LI) {
Chris Lattner92673292002-11-02 00:13:20 +0000317 DSNodeHandle Ptr = getValueDest(*LI.getOperand(0));
318 if (Ptr.getNode() == 0) return;
319
320 // Make that the node is read from...
Chris Lattner06285232002-10-17 22:13:19 +0000321 Ptr.getNode()->NodeType |= DSNode::Read;
Chris Lattner8f0a16e2002-10-31 05:45:02 +0000322
323 // Ensure a typerecord exists...
Chris Lattner08db7192002-11-06 06:20:27 +0000324 Ptr.getNode()->mergeTypeInfo(LI.getType(), Ptr.getOffset());
Chris Lattner92673292002-11-02 00:13:20 +0000325
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000326 if (isPointerType(LI.getType()))
Chris Lattner92673292002-11-02 00:13:20 +0000327 setDestTo(LI, getLink(Ptr));
Chris Lattnerc68c31b2002-07-10 22:38:08 +0000328}
329
330void GraphBuilder::visitStoreInst(StoreInst &SI) {
Chris Lattner8f0a16e2002-10-31 05:45:02 +0000331 const Type *StoredTy = SI.getOperand(0)->getType();
Chris Lattner92673292002-11-02 00:13:20 +0000332 DSNodeHandle Dest = getValueDest(*SI.getOperand(1));
333 if (Dest.getNode() == 0) return;
334
335 // Make that the node is written to...
336 Dest.getNode()->NodeType |= DSNode::Modified;
Chris Lattner8f0a16e2002-10-31 05:45:02 +0000337
338 // Ensure a typerecord exists...
Chris Lattner08db7192002-11-06 06:20:27 +0000339 Dest.getNode()->mergeTypeInfo(StoredTy, Dest.getOffset());
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000340
341 // Avoid adding edges from null, or processing non-"pointer" stores
Chris Lattner92673292002-11-02 00:13:20 +0000342 if (isPointerType(StoredTy))
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000343 Dest.addEdgeTo(getValueDest(*SI.getOperand(0)));
Chris Lattnerc68c31b2002-07-10 22:38:08 +0000344}
345
346void GraphBuilder::visitReturnInst(ReturnInst &RI) {
Chris Lattner92673292002-11-02 00:13:20 +0000347 if (RI.getNumOperands() && isPointerType(RI.getOperand(0)->getType()))
348 RetNode.mergeWith(getValueDest(*RI.getOperand(0)));
Chris Lattnerc68c31b2002-07-10 22:38:08 +0000349}
350
351void GraphBuilder::visitCallInst(CallInst &CI) {
Chris Lattnerc314ac42002-07-11 20:32:02 +0000352 // Set up the return value...
Chris Lattner0969c502002-10-21 02:08:03 +0000353 DSNodeHandle RetVal;
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000354 if (isPointerType(CI.getType()))
Chris Lattner92673292002-11-02 00:13:20 +0000355 RetVal = getValueDest(CI);
Chris Lattnerc314ac42002-07-11 20:32:02 +0000356
Chris Lattner92673292002-11-02 00:13:20 +0000357 DSNodeHandle Callee = getValueDest(*CI.getOperand(0));
Chris Lattner0d9bab82002-07-18 00:12:30 +0000358
Chris Lattner0969c502002-10-21 02:08:03 +0000359 std::vector<DSNodeHandle> Args;
360 Args.reserve(CI.getNumOperands()-1);
361
362 // Calculate the arguments vector...
363 for (unsigned i = 1, e = CI.getNumOperands(); i != e; ++i)
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000364 if (isPointerType(CI.getOperand(i)->getType()))
Chris Lattner92673292002-11-02 00:13:20 +0000365 Args.push_back(getValueDest(*CI.getOperand(i)));
Chris Lattner0969c502002-10-21 02:08:03 +0000366
367 // Add a new function call entry...
368 FunctionCalls.push_back(DSCallSite(CI, RetVal, Callee, Args));
Chris Lattnerc68c31b2002-07-10 22:38:08 +0000369}
Chris Lattner055dc2c2002-07-18 15:54:42 +0000370
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000371/// Handle casts...
372void GraphBuilder::visitCastInst(CastInst &CI) {
Chris Lattner5af344d2002-11-02 00:36:03 +0000373 if (isPointerType(CI.getType()))
374 if (isPointerType(CI.getOperand(0)->getType())) {
375 // Cast one pointer to the other, just act like a copy instruction
Chris Lattner92673292002-11-02 00:13:20 +0000376 setDestTo(CI, getValueDest(*CI.getOperand(0)));
Chris Lattner5af344d2002-11-02 00:36:03 +0000377 } else {
378 // Cast something (floating point, small integer) to a pointer. We need
379 // to track the fact that the node points to SOMETHING, just something we
380 // don't know about. Make an "Unknown" node.
381 //
382 setDestTo(CI, createNode(DSNode::UnknownNode));
383 }
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000384}
Chris Lattner055dc2c2002-07-18 15:54:42 +0000385
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000386
387
388
389//===----------------------------------------------------------------------===//
390// LocalDataStructures Implementation
391//===----------------------------------------------------------------------===//
392
393// releaseMemory - If the pass pipeline is done with this pass, we can release
394// our memory... here...
395//
396void LocalDataStructures::releaseMemory() {
397 for (std::map<const Function*, DSGraph*>::iterator I = DSInfo.begin(),
398 E = DSInfo.end(); I != E; ++I)
399 delete I->second;
400
401 // Empty map so next time memory is released, data structures are not
402 // re-deleted.
403 DSInfo.clear();
404}
405
406bool LocalDataStructures::run(Module &M) {
407 // Calculate all of the graphs...
408 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
409 if (!I->isExternal())
410 DSInfo.insert(std::make_pair(I, new DSGraph(*I)));
411 return false;
Chris Lattner055dc2c2002-07-18 15:54:42 +0000412}