blob: b47b265814e0b59598bcd185dda4535e5ac302ab [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>
Anand Shuklaa9284032002-06-25 20:35:19 +000016#include <iostream>
17using std::map;
18using std::string;
Chris Lattnerbb2a28f2002-03-26 22:39:06 +000019
Chris Lattnerb28bf052002-03-31 07:16:08 +000020bool AllocDSNode::isEquivalentTo(DSNode *Node) const {
21 if (AllocDSNode *N = dyn_cast<AllocDSNode>(Node))
22 return getType() == Node->getType();
Chris Lattner18961502002-06-25 16:12:52 +000023 //&& isAllocaNode() == N->isAllocaNode();
Chris Lattnerb28bf052002-03-31 07:16:08 +000024 return false;
25}
26
Chris Lattneree7eafa2002-04-27 02:28:41 +000027void AllocDSNode::mergeInto(DSNode *Node) const {
28 // Make sure the merged node is variable size if this node is var size
29 AllocDSNode *N = cast<AllocDSNode>(Node);
30 N->isVarSize |= isVarSize;
31}
32
Chris Lattnerb28bf052002-03-31 07:16:08 +000033bool GlobalDSNode::isEquivalentTo(DSNode *Node) const {
Anand Shuklaa9284032002-06-25 20:35:19 +000034 if (const GlobalDSNode *G = dyn_cast<GlobalDSNode>(Node)) {
Chris Lattner212be2e2002-04-16 03:44:03 +000035 if (G->Val != Val) return false;
36
37 // Check that the outgoing links are identical...
38 assert(getNumLinks() == G->getNumLinks() && "Not identical shape?");
39 for (unsigned i = 0, e = getNumLinks(); i != e; ++i)
40 if (getLink(i) != G->getLink(i)) // Check links
41 return false;
42 return true;
43 }
Chris Lattnerb28bf052002-03-31 07:16:08 +000044 return false;
45}
46
Chris Lattner212be2e2002-04-16 03:44:03 +000047// Call node equivalency - Two call nodes are identical if all of the outgoing
48// links are the same, AND if all of the incoming links are identical.
49//
Chris Lattnerb28bf052002-03-31 07:16:08 +000050bool CallDSNode::isEquivalentTo(DSNode *Node) const {
Chris Lattner212be2e2002-04-16 03:44:03 +000051 if (CallDSNode *C = dyn_cast<CallDSNode>(Node)) {
Chris Lattner7650b942002-04-16 20:39:59 +000052 if (getReferrers().size() != C->getReferrers().size() ||
53 C->getType() != getType())
Chris Lattner212be2e2002-04-16 03:44:03 +000054 return false; // Quick check...
Chris Lattnerb28bf052002-03-31 07:16:08 +000055
Chris Lattner212be2e2002-04-16 03:44:03 +000056 // Check that the outgoing links are identical...
57 assert(getNumLinks() == C->getNumLinks() && "Not identical shape?");
58 for (unsigned i = 0, e = getNumLinks(); i != e; ++i)
59 if (getLink(i) != C->getLink(i)) // Check links
60 return false;
61
62
63 std::vector<PointerValSet*> Refs1 = C->getReferrers();
64 std::vector<PointerValSet*> Refs2 = getReferrers();
65
66 sort(Refs1.begin(), Refs1.end());
67 sort(Refs2.begin(), Refs2.end());
68 if (Refs1 != Refs2) return false; // Incoming edges different?
69
70 // Check that all outgoing links are the same...
71 return C->ArgLinks == ArgLinks; // Check that the arguments are identical
72 }
Chris Lattnerb28bf052002-03-31 07:16:08 +000073 return false;
74}
75
76// NodesAreEquivalent - Check to see if the nodes are equivalent in all ways
77// except node type. Since we know N1 is a shadow node, N2 is allowed to be
78// any type.
79//
80bool ShadowDSNode::isEquivalentTo(DSNode *Node) const {
Chris Lattner0009dac2002-04-04 19:21:51 +000081 return getType() == Node->getType();
Chris Lattnerb28bf052002-03-31 07:16:08 +000082}
83
84
85
86
Chris Lattnerbb2a28f2002-03-26 22:39:06 +000087//===----------------------------------------------------------------------===//
88// DSNode Class Implementation
89//
90
91static void MapPVS(PointerValSet &PVSOut, const PointerValSet &PVSIn,
Chris Lattner1120c8b2002-03-28 17:56:03 +000092 map<const DSNode*, DSNode*> &NodeMap, bool ReinitOk = false){
93 assert((ReinitOk || PVSOut.empty()) && "Value set already initialized!");
Chris Lattnerbb2a28f2002-03-26 22:39:06 +000094
95 for (unsigned i = 0, e = PVSIn.size(); i != e; ++i)
96 PVSOut.add(PointerVal(NodeMap[PVSIn[i].Node], PVSIn[i].Index));
97}
98
99
100
101unsigned countPointerFields(const Type *Ty) {
102 switch (Ty->getPrimitiveID()) {
103 case Type::StructTyID: {
104 const StructType *ST = cast<StructType>(Ty);
105 unsigned Sum = 0;
106 for (unsigned i = 0, e = ST->getNumContainedTypes(); i != e; ++i)
107 Sum += countPointerFields(ST->getContainedType(i));
108
109 return Sum;
110 }
111
112 case Type::ArrayTyID:
113 // All array elements are folded together...
114 return countPointerFields(cast<ArrayType>(Ty)->getElementType());
115
116 case Type::PointerTyID:
117 return 1;
118
119 default: // Some other type, just treat it like a scalar
120 return 0;
121 }
122}
123
124DSNode::DSNode(enum NodeTy NT, const Type *T) : Ty(T), NodeType(NT) {
125 // Create field entries for all of the values in this type...
126 FieldLinks.resize(countPointerFields(getType()));
127}
128
129void DSNode::removeReferrer(PointerValSet *PVS) {
Anand Shuklaa9284032002-06-25 20:35:19 +0000130 std::vector<PointerValSet*>::iterator I = std::find(Referrers.begin(),
131 Referrers.end(), PVS);
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000132 assert(I != Referrers.end() && "PVS not pointing to node!");
133 Referrers.erase(I);
134}
135
136
Chris Lattner6088c4f2002-03-27 19:46:05 +0000137// removeAllIncomingEdges - Erase all edges in the graph that point to this node
138void DSNode::removeAllIncomingEdges() {
139 while (!Referrers.empty())
140 Referrers.back()->removePointerTo(this);
141}
142
143
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000144static void replaceIn(std::string &S, char From, const std::string &To) {
145 for (unsigned i = 0; i < S.size(); )
146 if (S[i] == From) {
147 S.replace(S.begin()+i, S.begin()+i+1,
148 To.begin(), To.end());
149 i += To.size();
150 } else {
151 ++i;
152 }
153}
154
155static void writeEdges(std::ostream &O, const void *SrcNode,
156 const char *SrcNodePortName, int SrcNodeIdx,
157 const PointerValSet &VS, const string &EdgeAttr = "") {
158 for (unsigned j = 0, je = VS.size(); j != je; ++j) {
159 O << "\t\tNode" << SrcNode << SrcNodePortName;
160 if (SrcNodeIdx != -1) O << SrcNodeIdx;
161
162 O << " -> Node" << VS[j].Node;
163 if (VS[j].Index)
164 O << ":g" << VS[j].Index;
165
166 if (!EdgeAttr.empty())
167 O << "[" << EdgeAttr << "]";
168 O << ";\n";
169 }
170}
171
172static string escapeLabel(const string &In) {
173 string Label(In);
174 replaceIn(Label, '\\', "\\\\\\\\"); // Escape caption...
175 replaceIn(Label, ' ', "\\ ");
176 replaceIn(Label, '{', "\\{");
177 replaceIn(Label, '}', "\\}");
178 return Label;
179}
180
Anand Shuklaa9284032002-06-25 20:35:19 +0000181void DSNode::dump() const { print(std::cerr); }
Chris Lattnerb28bf052002-03-31 07:16:08 +0000182
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000183void DSNode::print(std::ostream &O) const {
184 string Caption = escapeLabel(getCaption());
185
186 O << "\t\tNode" << (void*)this << " [ label =\"{" << Caption;
187
Anand Shuklaa9284032002-06-25 20:35:19 +0000188 const std::vector<PointerValSet> *Links = getAuxLinks();
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000189 if (Links && !Links->empty()) {
190 O << "|{";
191 for (unsigned i = 0; i < Links->size(); ++i) {
192 if (i) O << "|";
193 O << "<f" << i << ">";
194 }
195 O << "}";
196 }
197
198 if (!FieldLinks.empty()) {
199 O << "|{";
200 for (unsigned i = 0; i < FieldLinks.size(); ++i) {
201 if (i) O << "|";
202 O << "<g" << i << ">";
203 }
204 O << "}";
205 }
206 O << "}\"];\n";
207
208 if (Links)
209 for (unsigned i = 0; i < Links->size(); ++i)
210 writeEdges(O, this, ":f", i, (*Links)[i]);
211 for (unsigned i = 0; i < FieldLinks.size(); ++i)
212 writeEdges(O, this, ":g", i, FieldLinks[i]);
213}
214
215void DSNode::mapNode(map<const DSNode*, DSNode*> &NodeMap, const DSNode *Old) {
216 assert(FieldLinks.size() == Old->FieldLinks.size() &&
217 "Cloned nodes do not have the same number of links!");
218 for (unsigned j = 0, je = FieldLinks.size(); j != je; ++j)
219 MapPVS(FieldLinks[j], Old->FieldLinks[j], NodeMap);
Chris Lattnerfe145682002-04-17 03:24:59 +0000220
221 // Map our SynthNodes...
222 assert(SynthNodes.empty() && "Synthnodes already mapped?");
223 SynthNodes.reserve(Old->SynthNodes.size());
224 for (unsigned i = 0, e = Old->SynthNodes.size(); i != e; ++i)
225 SynthNodes.push_back(std::make_pair(Old->SynthNodes[i].first,
226 (ShadowDSNode*)NodeMap[Old->SynthNodes[i].second]));
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000227}
228
Chris Lattneree7eafa2002-04-27 02:28:41 +0000229AllocDSNode::AllocDSNode(AllocationInst *V, bool isvarsize)
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000230 : DSNode(NewNode, V->getType()->getElementType()), Allocation(V) {
Chris Lattneree7eafa2002-04-27 02:28:41 +0000231
232 // Is variable size if incoming flag says so, or if allocation is var size
233 // already.
234 isVarSize = isvarsize || !isa<Constant>(V->getArraySize());
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000235}
236
Chris Lattner1120c8b2002-03-28 17:56:03 +0000237bool AllocDSNode::isAllocaNode() const {
Chris Lattner6088c4f2002-03-27 19:46:05 +0000238 return isa<AllocaInst>(Allocation);
239}
240
241
Chris Lattner1120c8b2002-03-28 17:56:03 +0000242string AllocDSNode::getCaption() const {
Anand Shuklaa9284032002-06-25 20:35:19 +0000243 std::stringstream OS;
Chris Lattner6088c4f2002-03-27 19:46:05 +0000244 OS << (isMallocNode() ? "new " : "alloca ");
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000245
246 WriteTypeSymbolic(OS, getType(),
247 Allocation->getParent()->getParent()->getParent());
Chris Lattneree7eafa2002-04-27 02:28:41 +0000248 if (isVarSize)
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000249 OS << "[ ]";
250 return OS.str();
251}
252
253GlobalDSNode::GlobalDSNode(GlobalValue *V)
254 : DSNode(GlobalNode, V->getType()->getElementType()), Val(V) {
255}
256
257string GlobalDSNode::getCaption() const {
Anand Shuklaa9284032002-06-25 20:35:19 +0000258 std::stringstream OS;
Chris Lattner7650b942002-04-16 20:39:59 +0000259 if (isa<Function>(Val))
260 OS << "fn ";
261 else
262 OS << "global ";
263
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000264 WriteTypeSymbolic(OS, getType(), Val->getParent());
Chris Lattner7650b942002-04-16 20:39:59 +0000265 return OS.str() + " %" + Val->getName();
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000266}
267
268
Chris Lattner7650b942002-04-16 20:39:59 +0000269ShadowDSNode::ShadowDSNode(const Type *Ty, Module *M) : DSNode(ShadowNode, Ty) {
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000270 Mod = M;
271 ShadowParent = 0;
272}
273
Chris Lattnerfe145682002-04-17 03:24:59 +0000274ShadowDSNode::ShadowDSNode(const Type *Ty, Module *M, DSNode *ShadParent)
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000275 : DSNode(ShadowNode, Ty) {
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000276 Mod = M;
277 ShadowParent = ShadParent;
278}
279
280std::string ShadowDSNode::getCaption() const {
Anand Shuklaa9284032002-06-25 20:35:19 +0000281 std::stringstream OS;
Chris Lattner6088c4f2002-03-27 19:46:05 +0000282 OS << "shadow ";
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000283 WriteTypeSymbolic(OS, getType(), Mod);
Chris Lattner6088c4f2002-03-27 19:46:05 +0000284 return OS.str();
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000285}
286
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000287CallDSNode::CallDSNode(CallInst *ci) : DSNode(CallNode, ci->getType()), CI(ci) {
288 unsigned NumPtrs = 0;
Chris Lattner7650b942002-04-16 20:39:59 +0000289 for (unsigned i = 0, e = ci->getNumOperands(); i != e; ++i)
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000290 if (isa<PointerType>(ci->getOperand(i)->getType()))
291 NumPtrs++;
292 ArgLinks.resize(NumPtrs);
293}
294
295string CallDSNode::getCaption() const {
Anand Shuklaa9284032002-06-25 20:35:19 +0000296 std::stringstream OS;
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000297 if (const Function *CM = CI->getCalledFunction())
298 OS << "call " << CM->getName();
299 else
300 OS << "call <indirect>";
Chris Lattneref35ff02002-04-17 03:42:51 +0000301 OS << ": ";
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000302 WriteTypeSymbolic(OS, getType(),
303 CI->getParent()->getParent()->getParent());
304 return OS.str();
305}
306
307void CallDSNode::mapNode(map<const DSNode*, DSNode*> &NodeMap,
308 const DSNode *O) {
Chris Lattner1120c8b2002-03-28 17:56:03 +0000309 const CallDSNode *Old = cast<CallDSNode>(O);
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000310 DSNode::mapNode(NodeMap, Old); // Map base portions first...
311
312 assert(ArgLinks.size() == Old->ArgLinks.size() && "# Arguments changed!?");
313 for (unsigned i = 0, e = Old->ArgLinks.size(); i != e; ++i)
314 MapPVS(ArgLinks[i], Old->ArgLinks[i], NodeMap);
315}
316
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000317void FunctionDSGraph::printFunction(std::ostream &O,
318 const char *Label) const {
319 O << "\tsubgraph cluster_" << Label << "_Function" << (void*)this << " {\n";
320 O << "\t\tlabel=\"" << Label << " Function\\ " << Func->getName() << "\";\n";
Chris Lattner1120c8b2002-03-28 17:56:03 +0000321 for (unsigned i = 0, e = AllocNodes.size(); i != e; ++i)
322 AllocNodes[i]->print(O);
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000323 for (unsigned i = 0, e = ShadowNodes.size(); i != e; ++i)
324 ShadowNodes[i]->print(O);
Chris Lattner1120c8b2002-03-28 17:56:03 +0000325 for (unsigned i = 0, e = GlobalNodes.size(); i != e; ++i)
326 GlobalNodes[i]->print(O);
327 for (unsigned i = 0, e = CallNodes.size(); i != e; ++i)
328 CallNodes[i]->print(O);
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000329
330 if (RetNode.size()) {
331 O << "\t\tNode" << (void*)this << Label
332 << " [shape=\"ellipse\", label=\"Returns\"];\n";
333 writeEdges(O, this, Label, -1, RetNode);
334 }
335
336 O << "\n";
337 for (std::map<Value*, PointerValSet>::const_iterator I = ValueMap.begin(),
338 E = ValueMap.end(); I != E; ++I) {
Chris Lattner7650b942002-04-16 20:39:59 +0000339 if (I->second.size()) { // Only output nodes with edges...
Anand Shuklaa9284032002-06-25 20:35:19 +0000340 std::stringstream OS;
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000341 WriteTypeSymbolic(OS, I->first->getType(), Func->getParent());
342
343 // Create node for I->first
Chris Lattner595d2f62002-04-18 18:14:19 +0000344 O << "\t\tNode" << (void*)I->first << Label << " [shape=\""
345 << (isa<Argument>(I->first) ? "ellipse" : "box") << "\", label=\""
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000346 << escapeLabel(OS.str()) << "\\n%" << escapeLabel(I->first->getName())
347 << "\",fontsize=\"12.0\",color=\"gray70\"];\n";
348
349 // add edges from I->first to all pointers in I->second
350 writeEdges(O, I->first, Label, -1, I->second,
351 "weight=\"0.9\",color=\"gray70\"");
352 }
353 }
354
355 O << "\t}\n";
356}
357
358// Copy constructor - Since we copy the nodes over, we have to be sure to go
359// through and fix pointers to point into the new graph instead of into the old
360// graph...
361//
362FunctionDSGraph::FunctionDSGraph(const FunctionDSGraph &DSG) : Func(DSG.Func) {
Anand Shuklaa9284032002-06-25 20:35:19 +0000363 std::vector<PointerValSet> Args;
Chris Lattner212be2e2002-04-16 03:44:03 +0000364 RetNode = cloneFunctionIntoSelf(DSG, true, Args);
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000365}
366
367
368// cloneFunctionIntoSelf - Clone the specified method graph into the current
369// method graph, returning the Return's set of the graph. If ValueMap is set
370// to true, the ValueMap of the function is cloned into this function as well
Chris Lattner212be2e2002-04-16 03:44:03 +0000371// as the data structure graph itself. Regardless, the arguments value sets
372// of DSG are copied into Args.
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000373//
374PointerValSet FunctionDSGraph::cloneFunctionIntoSelf(const FunctionDSGraph &DSG,
Chris Lattner212be2e2002-04-16 03:44:03 +0000375 bool CloneValueMap,
Anand Shuklaa9284032002-06-25 20:35:19 +0000376 std::vector<PointerValSet> &Args) {
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000377 map<const DSNode*, DSNode*> NodeMap; // Map from old graph to new graph...
Chris Lattner1120c8b2002-03-28 17:56:03 +0000378 unsigned StartAllocSize = AllocNodes.size();
379 AllocNodes.reserve(StartAllocSize+DSG.AllocNodes.size());
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000380 unsigned StartShadowSize = ShadowNodes.size();
381 ShadowNodes.reserve(StartShadowSize+DSG.ShadowNodes.size());
Chris Lattner1120c8b2002-03-28 17:56:03 +0000382 unsigned StartGlobalSize = GlobalNodes.size();
383 GlobalNodes.reserve(StartGlobalSize+DSG.GlobalNodes.size());
384 unsigned StartCallSize = CallNodes.size();
385 CallNodes.reserve(StartCallSize+DSG.CallNodes.size());
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000386
Chris Lattner1120c8b2002-03-28 17:56:03 +0000387 // Clone all of the alloc nodes similarly...
388 for (unsigned i = 0, e = DSG.AllocNodes.size(); i != e; ++i) {
389 AllocDSNode *New = cast<AllocDSNode>(DSG.AllocNodes[i]->clone());
390 NodeMap[DSG.AllocNodes[i]] = New;
391 AllocNodes.push_back(New);
392 }
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000393
394 // Clone all of the shadow nodes similarly...
Chris Lattnerdd3fc182002-03-27 00:54:31 +0000395 for (unsigned i = 0, e = DSG.ShadowNodes.size(); i != e; ++i) {
396 ShadowDSNode *New = cast<ShadowDSNode>(DSG.ShadowNodes[i]->clone());
397 NodeMap[DSG.ShadowNodes[i]] = New;
398 ShadowNodes.push_back(New);
399 }
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000400
Chris Lattner1120c8b2002-03-28 17:56:03 +0000401 // Clone all of the global nodes...
402 for (unsigned i = 0, e = DSG.GlobalNodes.size(); i != e; ++i) {
403 GlobalDSNode *New = cast<GlobalDSNode>(DSG.GlobalNodes[i]->clone());
404 NodeMap[DSG.GlobalNodes[i]] = New;
405 GlobalNodes.push_back(New);
406 }
407
408 // Clone all of the call nodes...
409 for (unsigned i = 0, e = DSG.CallNodes.size(); i != e; ++i) {
410 CallDSNode *New = cast<CallDSNode>(DSG.CallNodes[i]->clone());
411 NodeMap[DSG.CallNodes[i]] = New;
412 CallNodes.push_back(New);
413 }
414
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000415 // Convert all of the links over in the nodes now that the map has been filled
416 // in all the way...
417 //
Chris Lattner1120c8b2002-03-28 17:56:03 +0000418 for (unsigned i = 0, e = DSG.AllocNodes.size(); i != e; ++i)
419 AllocNodes[i+StartAllocSize]->mapNode(NodeMap, DSG.AllocNodes[i]);
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000420 for (unsigned i = 0, e = DSG.ShadowNodes.size(); i != e; ++i)
421 ShadowNodes[i+StartShadowSize]->mapNode(NodeMap, DSG.ShadowNodes[i]);
Chris Lattner1120c8b2002-03-28 17:56:03 +0000422 for (unsigned i = 0, e = DSG.GlobalNodes.size(); i != e; ++i)
423 GlobalNodes[i+StartGlobalSize]->mapNode(NodeMap, DSG.GlobalNodes[i]);
424 for (unsigned i = 0, e = DSG.CallNodes.size(); i != e; ++i)
425 CallNodes[i+StartCallSize]->mapNode(NodeMap, DSG.CallNodes[i]);
426
Chris Lattner212be2e2002-04-16 03:44:03 +0000427 // Convert over the arguments...
428 Function *OF = DSG.getFunction();
Chris Lattner18961502002-06-25 16:12:52 +0000429 for (Function::aiterator I = OF->abegin(), E = OF->aend(); I != E; ++I)
430 if (isa<PointerType>(I->getType())) {
Chris Lattner212be2e2002-04-16 03:44:03 +0000431 PointerValSet ArgPVS;
Chris Lattner18961502002-06-25 16:12:52 +0000432 assert(DSG.getValueMap().find(I) != DSG.getValueMap().end());
433 MapPVS(ArgPVS, DSG.getValueMap().find(I)->second, NodeMap);
Chris Lattner212be2e2002-04-16 03:44:03 +0000434 assert(!ArgPVS.empty() && "Argument has no links!");
435 Args.push_back(ArgPVS);
436 }
437
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000438
439 if (CloneValueMap) {
440 // Convert value map... the values themselves stay the same, just the nodes
441 // have to change...
442 //
443 for (std::map<Value*,PointerValSet>::const_iterator I =DSG.ValueMap.begin(),
444 E = DSG.ValueMap.end(); I != E; ++I)
Chris Lattner1120c8b2002-03-28 17:56:03 +0000445 MapPVS(ValueMap[I->first], I->second, NodeMap, true);
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000446 }
447
448 // Convert over return node...
449 PointerValSet RetVals;
450 MapPVS(RetVals, DSG.RetNode, NodeMap);
451 return RetVals;
452}
453
454
455FunctionDSGraph::~FunctionDSGraph() {
456 RetNode.clear();
457 ValueMap.clear();
Chris Lattner1120c8b2002-03-28 17:56:03 +0000458 for_each(AllocNodes.begin(), AllocNodes.end(),
Anand Shuklaa9284032002-06-25 20:35:19 +0000459 std::mem_fun(&DSNode::dropAllReferences));
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000460 for_each(ShadowNodes.begin(), ShadowNodes.end(),
Anand Shuklaa9284032002-06-25 20:35:19 +0000461 std::mem_fun(&DSNode::dropAllReferences));
Chris Lattner1120c8b2002-03-28 17:56:03 +0000462 for_each(GlobalNodes.begin(), GlobalNodes.end(),
Anand Shuklaa9284032002-06-25 20:35:19 +0000463 std::mem_fun(&DSNode::dropAllReferences));
Chris Lattner1120c8b2002-03-28 17:56:03 +0000464 for_each(CallNodes.begin(), CallNodes.end(),
Anand Shuklaa9284032002-06-25 20:35:19 +0000465 std::mem_fun(&DSNode::dropAllReferences));
Chris Lattner1120c8b2002-03-28 17:56:03 +0000466 for_each(AllocNodes.begin(), AllocNodes.end(), deleter<DSNode>);
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000467 for_each(ShadowNodes.begin(), ShadowNodes.end(), deleter<DSNode>);
Chris Lattner1120c8b2002-03-28 17:56:03 +0000468 for_each(GlobalNodes.begin(), GlobalNodes.end(), deleter<DSNode>);
469 for_each(CallNodes.begin(), CallNodes.end(), deleter<DSNode>);
Chris Lattnerbb2a28f2002-03-26 22:39:06 +0000470}
471