blob: bd279b6082213e04ce183732e6e6159e186dc7f4 [file] [log] [blame]
Chris Lattnerbb2a28f2002-03-26 22:39:06 +00001//===- NodeImpl.cpp - Implement the data structure analysis nodes ---------===//
2//
3// Implement the LLVM data structure analysis library.
4//
5//===----------------------------------------------------------------------===//
6
Chris Lattnerb28bf052002-03-31 07:16:08 +00007#include "llvm/Analysis/DataStructureGraph.h"
Chris Lattnere6d4ec32002-04-08 21:58:53 +00008#include "llvm/Assembly/Writer.h"
Chris Lattnerbb2a28f2002-03-26 22:39:06 +00009#include "llvm/DerivedTypes.h"
10#include "llvm/Function.h"
Chris Lattnerbb2a28f2002-03-26 22:39:06 +000011#include "llvm/iMemory.h"
12#include "llvm/iOther.h"
Chris Lattnerbb2a28f2002-03-26 22:39:06 +000013#include "Support/STLExtras.h"
14#include <algorithm>
15#include <sstream>
16
Chris Lattnerb28bf052002-03-31 07:16:08 +000017bool AllocDSNode::isEquivalentTo(DSNode *Node) const {
18 if (AllocDSNode *N = dyn_cast<AllocDSNode>(Node))
19 return getType() == Node->getType();
Chris Lattner18961502002-06-25 16:12:52 +000020 //&& isAllocaNode() == N->isAllocaNode();
Chris Lattnerb28bf052002-03-31 07:16:08 +000021 return false;
22}
23
Chris Lattneree7eafa2002-04-27 02:28:41 +000024void AllocDSNode::mergeInto(DSNode *Node) const {
25 // Make sure the merged node is variable size if this node is var size
26 AllocDSNode *N = cast<AllocDSNode>(Node);
27 N->isVarSize |= isVarSize;
28}
29
Chris Lattnerb28bf052002-03-31 07:16:08 +000030bool GlobalDSNode::isEquivalentTo(DSNode *Node) const {
Chris Lattner212be2e2002-04-16 03:44:03 +000031 if (GlobalDSNode *G = dyn_cast<GlobalDSNode>(Node)) {
32 if (G->Val != Val) return false;
33
34 // Check that the outgoing links are identical...
35 assert(getNumLinks() == G->getNumLinks() && "Not identical shape?");
36 for (unsigned i = 0, e = getNumLinks(); i != e; ++i)
37 if (getLink(i) != G->getLink(i)) // Check links
38 return false;
39 return true;
40 }
Chris Lattnerb28bf052002-03-31 07:16:08 +000041 return false;
42}
43
Chris Lattner212be2e2002-04-16 03:44:03 +000044// Call node equivalency - Two call nodes are identical if all of the outgoing
45// links are the same, AND if all of the incoming links are identical.
46//
Chris Lattnerb28bf052002-03-31 07:16:08 +000047bool CallDSNode::isEquivalentTo(DSNode *Node) const {
Chris Lattner212be2e2002-04-16 03:44:03 +000048 if (CallDSNode *C = dyn_cast<CallDSNode>(Node)) {
Chris Lattner7650b942002-04-16 20:39:59 +000049 if (getReferrers().size() != C->getReferrers().size() ||
50 C->getType() != getType())
Chris Lattner212be2e2002-04-16 03:44:03 +000051 return false; // Quick check...
Chris Lattnerb28bf052002-03-31 07:16:08 +000052
Chris Lattner212be2e2002-04-16 03:44:03 +000053 // Check that the outgoing links are identical...
54 assert(getNumLinks() == C->getNumLinks() && "Not identical shape?");
55 for (unsigned i = 0, e = getNumLinks(); i != e; ++i)
56 if (getLink(i) != C->getLink(i)) // Check links
57 return false;
58
59
60 std::vector<PointerValSet*> Refs1 = C->getReferrers();
61 std::vector<PointerValSet*> Refs2 = getReferrers();
62
63 sort(Refs1.begin(), Refs1.end());
64 sort(Refs2.begin(), Refs2.end());
65 if (Refs1 != Refs2) return false; // Incoming edges different?
66
67 // Check that all outgoing links are the same...
68 return C->ArgLinks == ArgLinks; // Check that the arguments are identical
69 }
Chris Lattnerb28bf052002-03-31 07:16:08 +000070 return false;
71}
72
73// NodesAreEquivalent - Check to see if the nodes are equivalent in all ways
74// except node type. Since we know N1 is a shadow node, N2 is allowed to be
75// any type.
76//
77bool ShadowDSNode::isEquivalentTo(DSNode *Node) const {
Chris Lattner0009dac2002-04-04 19:21:51 +000078 return getType() == Node->getType();
Chris Lattnerb28bf052002-03-31 07:16:08 +000079}
80
81
82
83
Chris Lattnerbb2a28f2002-03-26 22:39:06 +000084//===----------------------------------------------------------------------===//
85// DSNode Class Implementation
86//
87
88static void MapPVS(PointerValSet &PVSOut, const PointerValSet &PVSIn,
Chris Lattner1120c8b2002-03-28 17:56:03 +000089 map<const DSNode*, DSNode*> &NodeMap, bool ReinitOk = false){
90 assert((ReinitOk || PVSOut.empty()) && "Value set already initialized!");
Chris Lattnerbb2a28f2002-03-26 22:39:06 +000091
92 for (unsigned i = 0, e = PVSIn.size(); i != e; ++i)
93 PVSOut.add(PointerVal(NodeMap[PVSIn[i].Node], PVSIn[i].Index));
94}
95
96
97
98unsigned countPointerFields(const Type *Ty) {
99 switch (Ty->getPrimitiveID()) {
100 case Type::StructTyID: {
101 const StructType *ST = cast<StructType>(Ty);
102 unsigned Sum = 0;
103 for (unsigned i = 0, e = ST->getNumContainedTypes(); i != e; ++i)
104 Sum += countPointerFields(ST->getContainedType(i));
105
106 return Sum;
107 }
108
109 case Type::ArrayTyID:
110 // All array elements are folded together...
111 return countPointerFields(cast<ArrayType>(Ty)->getElementType());
112
113 case Type::PointerTyID:
114 return 1;
115
116 default: // Some other type, just treat it like a scalar
117 return 0;
118 }
119}
120
121DSNode::DSNode(enum NodeTy NT, const Type *T) : Ty(T), NodeType(NT) {
122 // Create field entries for all of the values in this type...
123 FieldLinks.resize(countPointerFields(getType()));
124}
125
126void DSNode::removeReferrer(PointerValSet *PVS) {
127 vector<PointerValSet*>::iterator I = std::find(Referrers.begin(),
128 Referrers.end(), PVS);
129 assert(I != Referrers.end() && "PVS not pointing to node!");
130 Referrers.erase(I);
131}
132
133
Chris Lattner6088c4f2002-03-27 19:46:05 +0000134// removeAllIncomingEdges - Erase all edges in the graph that point to this node
135void DSNode::removeAllIncomingEdges() {
136 while (!Referrers.empty())
137 Referrers.back()->removePointerTo(this);
138}
139
140
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000141static void replaceIn(std::string &S, char From, const std::string &To) {
142 for (unsigned i = 0; i < S.size(); )
143 if (S[i] == From) {
144 S.replace(S.begin()+i, S.begin()+i+1,
145 To.begin(), To.end());
146 i += To.size();
147 } else {
148 ++i;
149 }
150}
151
152static void writeEdges(std::ostream &O, const void *SrcNode,
153 const char *SrcNodePortName, int SrcNodeIdx,
154 const PointerValSet &VS, const string &EdgeAttr = "") {
155 for (unsigned j = 0, je = VS.size(); j != je; ++j) {
156 O << "\t\tNode" << SrcNode << SrcNodePortName;
157 if (SrcNodeIdx != -1) O << SrcNodeIdx;
158
159 O << " -> Node" << VS[j].Node;
160 if (VS[j].Index)
161 O << ":g" << VS[j].Index;
162
163 if (!EdgeAttr.empty())
164 O << "[" << EdgeAttr << "]";
165 O << ";\n";
166 }
167}
168
169static string escapeLabel(const string &In) {
170 string Label(In);
171 replaceIn(Label, '\\', "\\\\\\\\"); // Escape caption...
172 replaceIn(Label, ' ', "\\ ");
173 replaceIn(Label, '{', "\\{");
174 replaceIn(Label, '}', "\\}");
175 return Label;
176}
177
Chris Lattnerb28bf052002-03-31 07:16:08 +0000178void DSNode::dump() const { print(cerr); }
179
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000180void DSNode::print(std::ostream &O) const {
181 string Caption = escapeLabel(getCaption());
182
183 O << "\t\tNode" << (void*)this << " [ label =\"{" << Caption;
184
185 const vector<PointerValSet> *Links = getAuxLinks();
186 if (Links && !Links->empty()) {
187 O << "|{";
188 for (unsigned i = 0; i < Links->size(); ++i) {
189 if (i) O << "|";
190 O << "<f" << i << ">";
191 }
192 O << "}";
193 }
194
195 if (!FieldLinks.empty()) {
196 O << "|{";
197 for (unsigned i = 0; i < FieldLinks.size(); ++i) {
198 if (i) O << "|";
199 O << "<g" << i << ">";
200 }
201 O << "}";
202 }
203 O << "}\"];\n";
204
205 if (Links)
206 for (unsigned i = 0; i < Links->size(); ++i)
207 writeEdges(O, this, ":f", i, (*Links)[i]);
208 for (unsigned i = 0; i < FieldLinks.size(); ++i)
209 writeEdges(O, this, ":g", i, FieldLinks[i]);
210}
211
212void DSNode::mapNode(map<const DSNode*, DSNode*> &NodeMap, const DSNode *Old) {
213 assert(FieldLinks.size() == Old->FieldLinks.size() &&
214 "Cloned nodes do not have the same number of links!");
215 for (unsigned j = 0, je = FieldLinks.size(); j != je; ++j)
216 MapPVS(FieldLinks[j], Old->FieldLinks[j], NodeMap);
Chris Lattnerfe145682002-04-17 03:24:59 +0000217
218 // Map our SynthNodes...
219 assert(SynthNodes.empty() && "Synthnodes already mapped?");
220 SynthNodes.reserve(Old->SynthNodes.size());
221 for (unsigned i = 0, e = Old->SynthNodes.size(); i != e; ++i)
222 SynthNodes.push_back(std::make_pair(Old->SynthNodes[i].first,
223 (ShadowDSNode*)NodeMap[Old->SynthNodes[i].second]));
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000224}
225
Chris Lattneree7eafa2002-04-27 02:28:41 +0000226AllocDSNode::AllocDSNode(AllocationInst *V, bool isvarsize)
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000227 : DSNode(NewNode, V->getType()->getElementType()), Allocation(V) {
Chris Lattneree7eafa2002-04-27 02:28:41 +0000228
229 // Is variable size if incoming flag says so, or if allocation is var size
230 // already.
231 isVarSize = isvarsize || !isa<Constant>(V->getArraySize());
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000232}
233
Chris Lattner1120c8b2002-03-28 17:56:03 +0000234bool AllocDSNode::isAllocaNode() const {
Chris Lattner6088c4f2002-03-27 19:46:05 +0000235 return isa<AllocaInst>(Allocation);
236}
237
238
Chris Lattner1120c8b2002-03-28 17:56:03 +0000239string AllocDSNode::getCaption() const {
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000240 stringstream OS;
Chris Lattner6088c4f2002-03-27 19:46:05 +0000241 OS << (isMallocNode() ? "new " : "alloca ");
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000242
243 WriteTypeSymbolic(OS, getType(),
244 Allocation->getParent()->getParent()->getParent());
Chris Lattneree7eafa2002-04-27 02:28:41 +0000245 if (isVarSize)
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000246 OS << "[ ]";
247 return OS.str();
248}
249
250GlobalDSNode::GlobalDSNode(GlobalValue *V)
251 : DSNode(GlobalNode, V->getType()->getElementType()), Val(V) {
252}
253
254string GlobalDSNode::getCaption() const {
255 stringstream OS;
Chris Lattner7650b942002-04-16 20:39:59 +0000256 if (isa<Function>(Val))
257 OS << "fn ";
258 else
259 OS << "global ";
260
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000261 WriteTypeSymbolic(OS, getType(), Val->getParent());
Chris Lattner7650b942002-04-16 20:39:59 +0000262 return OS.str() + " %" + Val->getName();
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000263}
264
265
Chris Lattner7650b942002-04-16 20:39:59 +0000266ShadowDSNode::ShadowDSNode(const Type *Ty, Module *M) : DSNode(ShadowNode, Ty) {
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000267 Mod = M;
268 ShadowParent = 0;
269}
270
Chris Lattnerfe145682002-04-17 03:24:59 +0000271ShadowDSNode::ShadowDSNode(const Type *Ty, Module *M, DSNode *ShadParent)
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000272 : DSNode(ShadowNode, Ty) {
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000273 Mod = M;
274 ShadowParent = ShadParent;
275}
276
277std::string ShadowDSNode::getCaption() const {
278 stringstream OS;
Chris Lattner6088c4f2002-03-27 19:46:05 +0000279 OS << "shadow ";
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000280 WriteTypeSymbolic(OS, getType(), Mod);
Chris Lattner6088c4f2002-03-27 19:46:05 +0000281 return OS.str();
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000282}
283
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000284CallDSNode::CallDSNode(CallInst *ci) : DSNode(CallNode, ci->getType()), CI(ci) {
285 unsigned NumPtrs = 0;
Chris Lattner7650b942002-04-16 20:39:59 +0000286 for (unsigned i = 0, e = ci->getNumOperands(); i != e; ++i)
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000287 if (isa<PointerType>(ci->getOperand(i)->getType()))
288 NumPtrs++;
289 ArgLinks.resize(NumPtrs);
290}
291
292string CallDSNode::getCaption() const {
293 stringstream OS;
294 if (const Function *CM = CI->getCalledFunction())
295 OS << "call " << CM->getName();
296 else
297 OS << "call <indirect>";
Chris Lattneref35ff02002-04-17 03:42:51 +0000298 OS << ": ";
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000299 WriteTypeSymbolic(OS, getType(),
300 CI->getParent()->getParent()->getParent());
301 return OS.str();
302}
303
304void CallDSNode::mapNode(map<const DSNode*, DSNode*> &NodeMap,
305 const DSNode *O) {
Chris Lattner1120c8b2002-03-28 17:56:03 +0000306 const CallDSNode *Old = cast<CallDSNode>(O);
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000307 DSNode::mapNode(NodeMap, Old); // Map base portions first...
308
309 assert(ArgLinks.size() == Old->ArgLinks.size() && "# Arguments changed!?");
310 for (unsigned i = 0, e = Old->ArgLinks.size(); i != e; ++i)
311 MapPVS(ArgLinks[i], Old->ArgLinks[i], NodeMap);
312}
313
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000314void FunctionDSGraph::printFunction(std::ostream &O,
315 const char *Label) const {
316 O << "\tsubgraph cluster_" << Label << "_Function" << (void*)this << " {\n";
317 O << "\t\tlabel=\"" << Label << " Function\\ " << Func->getName() << "\";\n";
Chris Lattner1120c8b2002-03-28 17:56:03 +0000318 for (unsigned i = 0, e = AllocNodes.size(); i != e; ++i)
319 AllocNodes[i]->print(O);
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000320 for (unsigned i = 0, e = ShadowNodes.size(); i != e; ++i)
321 ShadowNodes[i]->print(O);
Chris Lattner1120c8b2002-03-28 17:56:03 +0000322 for (unsigned i = 0, e = GlobalNodes.size(); i != e; ++i)
323 GlobalNodes[i]->print(O);
324 for (unsigned i = 0, e = CallNodes.size(); i != e; ++i)
325 CallNodes[i]->print(O);
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000326
327 if (RetNode.size()) {
328 O << "\t\tNode" << (void*)this << Label
329 << " [shape=\"ellipse\", label=\"Returns\"];\n";
330 writeEdges(O, this, Label, -1, RetNode);
331 }
332
333 O << "\n";
334 for (std::map<Value*, PointerValSet>::const_iterator I = ValueMap.begin(),
335 E = ValueMap.end(); I != E; ++I) {
Chris Lattner7650b942002-04-16 20:39:59 +0000336 if (I->second.size()) { // Only output nodes with edges...
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000337 stringstream OS;
338 WriteTypeSymbolic(OS, I->first->getType(), Func->getParent());
339
340 // Create node for I->first
Chris Lattner595d2f62002-04-18 18:14:19 +0000341 O << "\t\tNode" << (void*)I->first << Label << " [shape=\""
342 << (isa<Argument>(I->first) ? "ellipse" : "box") << "\", label=\""
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000343 << escapeLabel(OS.str()) << "\\n%" << escapeLabel(I->first->getName())
344 << "\",fontsize=\"12.0\",color=\"gray70\"];\n";
345
346 // add edges from I->first to all pointers in I->second
347 writeEdges(O, I->first, Label, -1, I->second,
348 "weight=\"0.9\",color=\"gray70\"");
349 }
350 }
351
352 O << "\t}\n";
353}
354
355// Copy constructor - Since we copy the nodes over, we have to be sure to go
356// through and fix pointers to point into the new graph instead of into the old
357// graph...
358//
359FunctionDSGraph::FunctionDSGraph(const FunctionDSGraph &DSG) : Func(DSG.Func) {
Chris Lattner212be2e2002-04-16 03:44:03 +0000360 vector<PointerValSet> Args;
361 RetNode = cloneFunctionIntoSelf(DSG, true, Args);
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000362}
363
364
365// cloneFunctionIntoSelf - Clone the specified method graph into the current
366// method graph, returning the Return's set of the graph. If ValueMap is set
367// to true, the ValueMap of the function is cloned into this function as well
Chris Lattner212be2e2002-04-16 03:44:03 +0000368// as the data structure graph itself. Regardless, the arguments value sets
369// of DSG are copied into Args.
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000370//
371PointerValSet FunctionDSGraph::cloneFunctionIntoSelf(const FunctionDSGraph &DSG,
Chris Lattner212be2e2002-04-16 03:44:03 +0000372 bool CloneValueMap,
373 vector<PointerValSet> &Args) {
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000374 map<const DSNode*, DSNode*> NodeMap; // Map from old graph to new graph...
Chris Lattner1120c8b2002-03-28 17:56:03 +0000375 unsigned StartAllocSize = AllocNodes.size();
376 AllocNodes.reserve(StartAllocSize+DSG.AllocNodes.size());
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000377 unsigned StartShadowSize = ShadowNodes.size();
378 ShadowNodes.reserve(StartShadowSize+DSG.ShadowNodes.size());
Chris Lattner1120c8b2002-03-28 17:56:03 +0000379 unsigned StartGlobalSize = GlobalNodes.size();
380 GlobalNodes.reserve(StartGlobalSize+DSG.GlobalNodes.size());
381 unsigned StartCallSize = CallNodes.size();
382 CallNodes.reserve(StartCallSize+DSG.CallNodes.size());
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000383
Chris Lattner1120c8b2002-03-28 17:56:03 +0000384 // Clone all of the alloc nodes similarly...
385 for (unsigned i = 0, e = DSG.AllocNodes.size(); i != e; ++i) {
386 AllocDSNode *New = cast<AllocDSNode>(DSG.AllocNodes[i]->clone());
387 NodeMap[DSG.AllocNodes[i]] = New;
388 AllocNodes.push_back(New);
389 }
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000390
391 // Clone all of the shadow nodes similarly...
Chris Lattnerdd3fc182002-03-27 00:54:31 +0000392 for (unsigned i = 0, e = DSG.ShadowNodes.size(); i != e; ++i) {
393 ShadowDSNode *New = cast<ShadowDSNode>(DSG.ShadowNodes[i]->clone());
394 NodeMap[DSG.ShadowNodes[i]] = New;
395 ShadowNodes.push_back(New);
396 }
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000397
Chris Lattner1120c8b2002-03-28 17:56:03 +0000398 // Clone all of the global nodes...
399 for (unsigned i = 0, e = DSG.GlobalNodes.size(); i != e; ++i) {
400 GlobalDSNode *New = cast<GlobalDSNode>(DSG.GlobalNodes[i]->clone());
401 NodeMap[DSG.GlobalNodes[i]] = New;
402 GlobalNodes.push_back(New);
403 }
404
405 // Clone all of the call nodes...
406 for (unsigned i = 0, e = DSG.CallNodes.size(); i != e; ++i) {
407 CallDSNode *New = cast<CallDSNode>(DSG.CallNodes[i]->clone());
408 NodeMap[DSG.CallNodes[i]] = New;
409 CallNodes.push_back(New);
410 }
411
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000412 // Convert all of the links over in the nodes now that the map has been filled
413 // in all the way...
414 //
Chris Lattner1120c8b2002-03-28 17:56:03 +0000415 for (unsigned i = 0, e = DSG.AllocNodes.size(); i != e; ++i)
416 AllocNodes[i+StartAllocSize]->mapNode(NodeMap, DSG.AllocNodes[i]);
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000417 for (unsigned i = 0, e = DSG.ShadowNodes.size(); i != e; ++i)
418 ShadowNodes[i+StartShadowSize]->mapNode(NodeMap, DSG.ShadowNodes[i]);
Chris Lattner1120c8b2002-03-28 17:56:03 +0000419 for (unsigned i = 0, e = DSG.GlobalNodes.size(); i != e; ++i)
420 GlobalNodes[i+StartGlobalSize]->mapNode(NodeMap, DSG.GlobalNodes[i]);
421 for (unsigned i = 0, e = DSG.CallNodes.size(); i != e; ++i)
422 CallNodes[i+StartCallSize]->mapNode(NodeMap, DSG.CallNodes[i]);
423
Chris Lattner212be2e2002-04-16 03:44:03 +0000424 // Convert over the arguments...
425 Function *OF = DSG.getFunction();
Chris Lattner18961502002-06-25 16:12:52 +0000426 for (Function::aiterator I = OF->abegin(), E = OF->aend(); I != E; ++I)
427 if (isa<PointerType>(I->getType())) {
Chris Lattner212be2e2002-04-16 03:44:03 +0000428 PointerValSet ArgPVS;
Chris Lattner18961502002-06-25 16:12:52 +0000429 assert(DSG.getValueMap().find(I) != DSG.getValueMap().end());
430 MapPVS(ArgPVS, DSG.getValueMap().find(I)->second, NodeMap);
Chris Lattner212be2e2002-04-16 03:44:03 +0000431 assert(!ArgPVS.empty() && "Argument has no links!");
432 Args.push_back(ArgPVS);
433 }
434
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000435
436 if (CloneValueMap) {
437 // Convert value map... the values themselves stay the same, just the nodes
438 // have to change...
439 //
440 for (std::map<Value*,PointerValSet>::const_iterator I =DSG.ValueMap.begin(),
441 E = DSG.ValueMap.end(); I != E; ++I)
Chris Lattner1120c8b2002-03-28 17:56:03 +0000442 MapPVS(ValueMap[I->first], I->second, NodeMap, true);
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000443 }
444
445 // Convert over return node...
446 PointerValSet RetVals;
447 MapPVS(RetVals, DSG.RetNode, NodeMap);
448 return RetVals;
449}
450
451
452FunctionDSGraph::~FunctionDSGraph() {
453 RetNode.clear();
454 ValueMap.clear();
Chris Lattner1120c8b2002-03-28 17:56:03 +0000455 for_each(AllocNodes.begin(), AllocNodes.end(),
456 mem_fun(&DSNode::dropAllReferences));
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000457 for_each(ShadowNodes.begin(), ShadowNodes.end(),
458 mem_fun(&DSNode::dropAllReferences));
Chris Lattner1120c8b2002-03-28 17:56:03 +0000459 for_each(GlobalNodes.begin(), GlobalNodes.end(),
460 mem_fun(&DSNode::dropAllReferences));
461 for_each(CallNodes.begin(), CallNodes.end(),
462 mem_fun(&DSNode::dropAllReferences));
Chris Lattner1120c8b2002-03-28 17:56:03 +0000463 for_each(AllocNodes.begin(), AllocNodes.end(), deleter<DSNode>);
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000464 for_each(ShadowNodes.begin(), ShadowNodes.end(), deleter<DSNode>);
Chris Lattner1120c8b2002-03-28 17:56:03 +0000465 for_each(GlobalNodes.begin(), GlobalNodes.end(), deleter<DSNode>);
466 for_each(CallNodes.begin(), CallNodes.end(), deleter<DSNode>);
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000467}
468