blob: 60a89ffae1805ff7332ca89364019720b7e106e5 [file] [log] [blame]
Chris Lattnerc68c31b2002-07-10 22:38:08 +00001//===- DataStructure.cpp - Implement the core data structure analysis -----===//
Chris Lattnerbb2a28f2002-03-26 22:39:06 +00002//
Chris Lattnerc68c31b2002-07-10 22:38:08 +00003// This file implements the core data structure functionality.
Chris Lattnerbb2a28f2002-03-26 22:39:06 +00004//
5//===----------------------------------------------------------------------===//
6
Chris Lattnerfccd06f2002-10-01 22:33:50 +00007#include "llvm/Analysis/DSGraph.h"
8#include "llvm/Function.h"
Vikram S. Adve26b98262002-10-20 21:41:02 +00009#include "llvm/iOther.h"
Chris Lattnerc68c31b2002-07-10 22:38:08 +000010#include "llvm/DerivedTypes.h"
Chris Lattner7b7200c2002-10-02 04:57:39 +000011#include "llvm/Target/TargetData.h"
Chris Lattnerc68c31b2002-07-10 22:38:08 +000012#include "Support/STLExtras.h"
Chris Lattnerfccd06f2002-10-01 22:33:50 +000013#include "Support/Statistic.h"
Chris Lattner0d9bab82002-07-18 00:12:30 +000014#include <algorithm>
Chris Lattnerfccd06f2002-10-01 22:33:50 +000015#include <set>
Chris Lattnerc68c31b2002-07-10 22:38:08 +000016
Chris Lattnere2219762002-07-18 18:22:40 +000017using std::vector;
18
Chris Lattner08db7192002-11-06 06:20:27 +000019namespace {
Chris Lattner33312f72002-11-08 01:21:07 +000020 Statistic<> NumFolds ("dsnode", "Number of nodes completely folded");
21 Statistic<> NumCallNodesMerged("dsnode", "Number of call nodes merged");
Chris Lattner08db7192002-11-06 06:20:27 +000022};
23
Chris Lattnerb1060432002-11-07 05:20:53 +000024namespace DS { // TODO: FIXME
Chris Lattnerfccd06f2002-10-01 22:33:50 +000025 extern TargetData TD;
26}
Chris Lattnerb1060432002-11-07 05:20:53 +000027using namespace DS;
Chris Lattnerfccd06f2002-10-01 22:33:50 +000028
Chris Lattnerbb2a28f2002-03-26 22:39:06 +000029//===----------------------------------------------------------------------===//
Chris Lattnerc68c31b2002-07-10 22:38:08 +000030// DSNode Implementation
31//===----------------------------------------------------------------------===//
Chris Lattnerbb2a28f2002-03-26 22:39:06 +000032
Chris Lattner08db7192002-11-06 06:20:27 +000033DSNode::DSNode(enum NodeTy NT, const Type *T)
34 : Ty(Type::VoidTy), Size(0), NodeType(NT) {
Chris Lattner8f0a16e2002-10-31 05:45:02 +000035 // Add the type entry if it is specified...
Chris Lattner08db7192002-11-06 06:20:27 +000036 if (T) mergeTypeInfo(T, 0);
Chris Lattnerc68c31b2002-07-10 22:38:08 +000037}
38
Chris Lattner0d9bab82002-07-18 00:12:30 +000039// DSNode copy constructor... do not copy over the referrers list!
40DSNode::DSNode(const DSNode &N)
Chris Lattner08db7192002-11-06 06:20:27 +000041 : Links(N.Links), Globals(N.Globals), Ty(N.Ty), Size(N.Size),
42 NodeType(N.NodeType) {
Chris Lattner0d9bab82002-07-18 00:12:30 +000043}
44
Chris Lattnerc68c31b2002-07-10 22:38:08 +000045void DSNode::removeReferrer(DSNodeHandle *H) {
46 // Search backwards, because we depopulate the list from the back for
47 // efficiency (because it's a vector).
Chris Lattnere2219762002-07-18 18:22:40 +000048 vector<DSNodeHandle*>::reverse_iterator I =
Chris Lattnerc68c31b2002-07-10 22:38:08 +000049 std::find(Referrers.rbegin(), Referrers.rend(), H);
50 assert(I != Referrers.rend() && "Referrer not pointing to node!");
51 Referrers.erase(I.base()-1);
52}
53
Chris Lattnerf9ae4c52002-07-11 20:32:22 +000054// addGlobal - Add an entry for a global value to the Globals list. This also
55// marks the node with the 'G' flag if it does not already have it.
56//
57void DSNode::addGlobal(GlobalValue *GV) {
Chris Lattner0d9bab82002-07-18 00:12:30 +000058 // Keep the list sorted.
Chris Lattnere2219762002-07-18 18:22:40 +000059 vector<GlobalValue*>::iterator I =
Chris Lattner0d9bab82002-07-18 00:12:30 +000060 std::lower_bound(Globals.begin(), Globals.end(), GV);
61
62 if (I == Globals.end() || *I != GV) {
Chris Lattnerfccd06f2002-10-01 22:33:50 +000063 //assert(GV->getType()->getElementType() == Ty);
Chris Lattner0d9bab82002-07-18 00:12:30 +000064 Globals.insert(I, GV);
65 NodeType |= GlobalNode;
66 }
Chris Lattnerf9ae4c52002-07-11 20:32:22 +000067}
68
Chris Lattner8f0a16e2002-10-31 05:45:02 +000069/// foldNodeCompletely - If we determine that this node has some funny
70/// behavior happening to it that we cannot represent, we fold it down to a
71/// single, completely pessimistic, node. This node is represented as a
72/// single byte with a single TypeEntry of "void".
73///
74void DSNode::foldNodeCompletely() {
Chris Lattner08db7192002-11-06 06:20:27 +000075 if (isNodeCompletelyFolded()) return;
Chris Lattner8f0a16e2002-10-31 05:45:02 +000076
Chris Lattner08db7192002-11-06 06:20:27 +000077 ++NumFolds;
78
79 // We are no longer typed at all...
80 Ty = DSTypeRec(Type::VoidTy, true);
81 Size = 1;
82
83 // Loop over all of our referrers, making them point to our zero bytes of
84 // space.
Chris Lattner8f0a16e2002-10-31 05:45:02 +000085 for (vector<DSNodeHandle*>::iterator I = Referrers.begin(), E=Referrers.end();
86 I != E; ++I)
87 (*I)->setOffset(0);
88
Chris Lattner8f0a16e2002-10-31 05:45:02 +000089 // If we have links, merge all of our outgoing links together...
Chris Lattner08db7192002-11-06 06:20:27 +000090 for (unsigned i = 1, e = Links.size(); i < e; ++i)
91 Links[0].mergeWith(Links[i]);
92 Links.resize(1);
Chris Lattner8f0a16e2002-10-31 05:45:02 +000093}
Chris Lattner076c1f92002-11-07 06:31:54 +000094
Chris Lattner8f0a16e2002-10-31 05:45:02 +000095/// isNodeCompletelyFolded - Return true if this node has been completely
96/// folded down to something that can never be expanded, effectively losing
97/// all of the field sensitivity that may be present in the node.
98///
99bool DSNode::isNodeCompletelyFolded() const {
Chris Lattner08db7192002-11-06 06:20:27 +0000100 return getSize() == 1 && Ty.Ty == Type::VoidTy && Ty.isArray;
Chris Lattner8f0a16e2002-10-31 05:45:02 +0000101}
102
103
Chris Lattner08db7192002-11-06 06:20:27 +0000104/// mergeTypeInfo - This method merges the specified type into the current node
105/// at the specified offset. This may update the current node's type record if
106/// this gives more information to the node, it may do nothing to the node if
107/// this information is already known, or it may merge the node completely (and
108/// return true) if the information is incompatible with what is already known.
Chris Lattner7b7200c2002-10-02 04:57:39 +0000109///
Chris Lattner08db7192002-11-06 06:20:27 +0000110/// This method returns true if the node is completely folded, otherwise false.
111///
112bool DSNode::mergeTypeInfo(const Type *NewTy, unsigned Offset) {
113 // Check to make sure the Size member is up-to-date. Size can be one of the
114 // following:
115 // Size = 0, Ty = Void: Nothing is known about this node.
116 // Size = 0, Ty = FnTy: FunctionPtr doesn't have a size, so we use zero
117 // Size = 1, Ty = Void, Array = 1: The node is collapsed
118 // Otherwise, sizeof(Ty) = Size
119 //
120 assert(((Size == 0 && Ty.Ty == Type::VoidTy && !Ty.isArray) ||
121 (Size == 0 && !Ty.Ty->isSized() && !Ty.isArray) ||
122 (Size == 1 && Ty.Ty == Type::VoidTy && Ty.isArray) ||
123 (Size == 0 && !Ty.Ty->isSized() && !Ty.isArray) ||
124 (TD.getTypeSize(Ty.Ty) == Size)) &&
125 "Size member of DSNode doesn't match the type structure!");
126 assert(NewTy != Type::VoidTy && "Cannot merge void type into DSNode!");
Chris Lattner7b7200c2002-10-02 04:57:39 +0000127
Chris Lattner08db7192002-11-06 06:20:27 +0000128 if (Offset == 0 && NewTy == Ty.Ty)
129 return false; // This should be a common case, handle it efficiently
Chris Lattner7b7200c2002-10-02 04:57:39 +0000130
Chris Lattner08db7192002-11-06 06:20:27 +0000131 // Return true immediately if the node is completely folded.
132 if (isNodeCompletelyFolded()) return true;
133
134 // Figure out how big the new type we're merging in is...
135 unsigned NewTySize = NewTy->isSized() ? TD.getTypeSize(NewTy) : 0;
136
137 // Otherwise check to see if we can fold this type into the current node. If
138 // we can't, we fold the node completely, if we can, we potentially update our
139 // internal state.
140 //
141 if (Ty.Ty == Type::VoidTy) {
142 // If this is the first type that this node has seen, just accept it without
143 // question....
144 assert(Offset == 0 && "Cannot have an offset into a void node!");
145 assert(Ty.isArray == false && "This shouldn't happen!");
146 Ty.Ty = NewTy;
147 Size = NewTySize;
148
149 // Calculate the number of outgoing links from this node.
150 Links.resize((Size+DS::PointerSize-1) >> DS::PointerShift);
151 return false;
Chris Lattner7b7200c2002-10-02 04:57:39 +0000152 }
Chris Lattner08db7192002-11-06 06:20:27 +0000153
154 // Handle node expansion case here...
155 if (Offset+NewTySize > Size) {
156 // It is illegal to grow this node if we have treated it as an array of
157 // objects...
158 if (Ty.isArray) {
159 foldNodeCompletely();
160 return true;
161 }
162
163 if (Offset) { // We could handle this case, but we don't for now...
Chris Lattner3c87b292002-11-07 01:54:56 +0000164 DEBUG(std::cerr << "UNIMP: Trying to merge a growth type into "
165 << "offset != 0: Collapsing!\n");
Chris Lattner08db7192002-11-06 06:20:27 +0000166 foldNodeCompletely();
167 return true;
168 }
169
170 // Okay, the situation is nice and simple, we are trying to merge a type in
171 // at offset 0 that is bigger than our current type. Implement this by
172 // switching to the new type and then merge in the smaller one, which should
173 // hit the other code path here. If the other code path decides it's not
174 // ok, it will collapse the node as appropriate.
175 //
176 const Type *OldTy = Ty.Ty;
177 Ty.Ty = NewTy;
178 Size = NewTySize;
179
180 // Must grow links to be the appropriate size...
181 Links.resize((Size+DS::PointerSize-1) >> DS::PointerShift);
182
183 // Merge in the old type now... which is guaranteed to be smaller than the
184 // "current" type.
185 return mergeTypeInfo(OldTy, 0);
186 }
187
Chris Lattnerf17b39a2002-11-07 04:59:28 +0000188 assert(Offset <= Size &&
Chris Lattner08db7192002-11-06 06:20:27 +0000189 "Cannot merge something into a part of our type that doesn't exist!");
190
191 // Find the section of Ty.Ty that NewTy overlaps with... first we find the
192 // type that starts at offset Offset.
193 //
194 unsigned O = 0;
195 const Type *SubType = Ty.Ty;
196 while (O < Offset) {
197 assert(Offset-O < TD.getTypeSize(SubType) && "Offset out of range!");
198
199 switch (SubType->getPrimitiveID()) {
200 case Type::StructTyID: {
201 const StructType *STy = cast<StructType>(SubType);
202 const StructLayout &SL = *TD.getStructLayout(STy);
203
204 unsigned i = 0, e = SL.MemberOffsets.size();
205 for (; i+1 < e && SL.MemberOffsets[i+1] <= Offset-O; ++i)
206 /* empty */;
207
208 // The offset we are looking for must be in the i'th element...
209 SubType = STy->getElementTypes()[i];
210 O += SL.MemberOffsets[i];
211 break;
212 }
213 case Type::ArrayTyID: {
214 SubType = cast<ArrayType>(SubType)->getElementType();
215 unsigned ElSize = TD.getTypeSize(SubType);
216 unsigned Remainder = (Offset-O) % ElSize;
217 O = Offset-Remainder;
218 break;
219 }
220 default:
221 assert(0 && "Unknown type!");
222 }
223 }
224
225 assert(O == Offset && "Could not achieve the correct offset!");
226
227 // If we found our type exactly, early exit
228 if (SubType == NewTy) return false;
229
230 // Okay, so we found the leader type at the offset requested. Search the list
231 // of types that starts at this offset. If SubType is currently an array or
232 // structure, the type desired may actually be the first element of the
233 // composite type...
234 //
Chris Lattnerf17b39a2002-11-07 04:59:28 +0000235 unsigned SubTypeSize = SubType->isSized() ? TD.getTypeSize(SubType) : 0;
Chris Lattner08db7192002-11-06 06:20:27 +0000236 while (SubType != NewTy) {
237 const Type *NextSubType = 0;
238 unsigned NextSubTypeSize;
239 switch (SubType->getPrimitiveID()) {
240 case Type::StructTyID:
241 NextSubType = cast<StructType>(SubType)->getElementTypes()[0];
242 NextSubTypeSize = TD.getTypeSize(SubType);
243 break;
244 case Type::ArrayTyID:
245 NextSubType = cast<ArrayType>(SubType)->getElementType();
246 NextSubTypeSize = TD.getTypeSize(SubType);
247 break;
248 default: ;
249 // fall out
250 }
251
252 if (NextSubType == 0)
253 break; // In the default case, break out of the loop
254
255 if (NextSubTypeSize < NewTySize)
256 break; // Don't allow shrinking to a smaller type than NewTySize
257 SubType = NextSubType;
258 SubTypeSize = NextSubTypeSize;
259 }
260
261 // If we found the type exactly, return it...
262 if (SubType == NewTy)
263 return false;
264
265 // Check to see if we have a compatible, but different type...
266 if (NewTySize == SubTypeSize) {
267 // Check to see if this type is obviously convertable... int -> uint f.e.
268 if (NewTy->isLosslesslyConvertableTo(SubType))
269 return false;
270
271 // Check to see if we have a pointer & integer mismatch going on here,
272 // loading a pointer as a long, for example.
273 //
274 if (SubType->isInteger() && isa<PointerType>(NewTy) ||
275 NewTy->isInteger() && isa<PointerType>(SubType))
276 return false;
277
278 }
279
280
Chris Lattner3c87b292002-11-07 01:54:56 +0000281 DEBUG(std::cerr << "MergeTypeInfo Folding OrigTy: " << Ty.Ty
282 << "\n due to:" << NewTy << " @ " << Offset << "!\n"
283 << "SubType: " << SubType << "\n\n");
Chris Lattner08db7192002-11-06 06:20:27 +0000284
285 foldNodeCompletely();
286 return true;
Chris Lattner7b7200c2002-10-02 04:57:39 +0000287}
288
Chris Lattner08db7192002-11-06 06:20:27 +0000289
290
Chris Lattnerc68c31b2002-07-10 22:38:08 +0000291// addEdgeTo - Add an edge from the current node to the specified node. This
292// can cause merging of nodes in the graph.
293//
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000294void DSNode::addEdgeTo(unsigned Offset, const DSNodeHandle &NH) {
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000295 if (NH.getNode() == 0) return; // Nothing to do
296
Chris Lattner08db7192002-11-06 06:20:27 +0000297 DSNodeHandle &ExistingEdge = getLink(Offset);
298 if (ExistingEdge.getNode()) {
Chris Lattner7b7200c2002-10-02 04:57:39 +0000299 // Merge the two nodes...
Chris Lattner08db7192002-11-06 06:20:27 +0000300 ExistingEdge.mergeWith(NH);
Chris Lattner7b7200c2002-10-02 04:57:39 +0000301 } else { // No merging to perform...
302 setLink(Offset, NH); // Just force a link in there...
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000303 }
Chris Lattner7b7200c2002-10-02 04:57:39 +0000304}
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000305
Chris Lattnerc68c31b2002-07-10 22:38:08 +0000306
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000307// MergeSortedVectors - Efficiently merge a vector into another vector where
308// duplicates are not allowed and both are sorted. This assumes that 'T's are
309// efficiently copyable and have sane comparison semantics.
Chris Lattnerc68c31b2002-07-10 22:38:08 +0000310//
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000311template<typename T>
312void MergeSortedVectors(vector<T> &Dest, const vector<T> &Src) {
313 // By far, the most common cases will be the simple ones. In these cases,
314 // avoid having to allocate a temporary vector...
315 //
316 if (Src.empty()) { // Nothing to merge in...
317 return;
318 } else if (Dest.empty()) { // Just copy the result in...
319 Dest = Src;
320 } else if (Src.size() == 1) { // Insert a single element...
321 const T &V = Src[0];
322 typename vector<T>::iterator I =
323 std::lower_bound(Dest.begin(), Dest.end(), V);
324 if (I == Dest.end() || *I != Src[0]) // If not already contained...
325 Dest.insert(I, Src[0]);
326 } else if (Dest.size() == 1) {
327 T Tmp = Dest[0]; // Save value in temporary...
328 Dest = Src; // Copy over list...
329 typename vector<T>::iterator I =
330 std::lower_bound(Dest.begin(), Dest.end(),Tmp);
331 if (I == Dest.end() || *I != Src[0]) // If not already contained...
332 Dest.insert(I, Src[0]);
333
334 } else {
335 // Make a copy to the side of Dest...
336 vector<T> Old(Dest);
337
338 // Make space for all of the type entries now...
339 Dest.resize(Dest.size()+Src.size());
340
341 // Merge the two sorted ranges together... into Dest.
342 std::merge(Old.begin(), Old.end(), Src.begin(), Src.end(), Dest.begin());
343
344 // Now erase any duplicate entries that may have accumulated into the
345 // vectors (because they were in both of the input sets)
346 Dest.erase(std::unique(Dest.begin(), Dest.end()), Dest.end());
347 }
348}
349
350
351// mergeWith - Merge this node and the specified node, moving all links to and
352// from the argument node into the current node, deleting the node argument.
353// Offset indicates what offset the specified node is to be merged into the
354// current node.
355//
356// The specified node may be a null pointer (in which case, nothing happens).
357//
358void DSNode::mergeWith(const DSNodeHandle &NH, unsigned Offset) {
359 DSNode *N = NH.getNode();
360 if (N == 0 || (N == this && NH.getOffset() == Offset))
Chris Lattner8f0a16e2002-10-31 05:45:02 +0000361 return; // Noop
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000362
Chris Lattner679e8e12002-11-08 21:27:12 +0000363 assert((N->NodeType & DSNode::DEAD) == 0);
364 assert((NodeType & DSNode::DEAD) == 0);
365 assert(!hasNoReferrers() && "Should not try to fold a useless node!");
366
Chris Lattner02606632002-11-04 06:48:26 +0000367 if (N == this) {
Chris Lattner08db7192002-11-06 06:20:27 +0000368 // We cannot merge two pieces of the same node together, collapse the node
369 // completely.
Chris Lattner3c87b292002-11-07 01:54:56 +0000370 DEBUG(std::cerr << "Attempting to merge two chunks of"
371 << " the same node together!\n");
Chris Lattner08db7192002-11-06 06:20:27 +0000372 foldNodeCompletely();
Chris Lattner02606632002-11-04 06:48:26 +0000373 return;
374 }
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000375
Chris Lattner08db7192002-11-06 06:20:27 +0000376 // Merge the type entries of the two nodes together...
Chris Lattner679e8e12002-11-08 21:27:12 +0000377 if (N->Ty.Ty != Type::VoidTy) {
Chris Lattner08db7192002-11-06 06:20:27 +0000378 mergeTypeInfo(N->Ty.Ty, Offset);
379
Chris Lattner679e8e12002-11-08 21:27:12 +0000380 // mergeTypeInfo can cause collapsing, which can cause this node to become
381 // dead.
382 if (hasNoReferrers()) return;
383 }
384 assert((NodeType & DSNode::DEAD) == 0);
385
Chris Lattner8f0a16e2002-10-31 05:45:02 +0000386 // If we are merging a node with a completely folded node, then both nodes are
387 // now completely folded.
388 //
389 if (isNodeCompletelyFolded()) {
Chris Lattner679e8e12002-11-08 21:27:12 +0000390 if (!N->isNodeCompletelyFolded()) {
Chris Lattner02606632002-11-04 06:48:26 +0000391 N->foldNodeCompletely();
Chris Lattner679e8e12002-11-08 21:27:12 +0000392 if (hasNoReferrers()) return;
393 }
Chris Lattner02606632002-11-04 06:48:26 +0000394 } else if (N->isNodeCompletelyFolded()) {
Chris Lattner8f0a16e2002-10-31 05:45:02 +0000395 foldNodeCompletely();
396 Offset = 0;
Chris Lattner679e8e12002-11-08 21:27:12 +0000397 if (hasNoReferrers()) return;
Chris Lattner8f0a16e2002-10-31 05:45:02 +0000398 }
Chris Lattner02606632002-11-04 06:48:26 +0000399 N = NH.getNode();
Chris Lattner679e8e12002-11-08 21:27:12 +0000400 assert((NodeType & DSNode::DEAD) == 0);
Chris Lattner02606632002-11-04 06:48:26 +0000401
Chris Lattner2c0bd012002-11-06 18:01:39 +0000402 if (this == N || N == 0) return;
Chris Lattner679e8e12002-11-08 21:27:12 +0000403 assert((NodeType & DSNode::DEAD) == 0);
Chris Lattner8f0a16e2002-10-31 05:45:02 +0000404
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000405 // If both nodes are not at offset 0, make sure that we are merging the node
406 // at an later offset into the node with the zero offset.
407 //
408 if (Offset > NH.getOffset()) {
409 N->mergeWith(DSNodeHandle(this, Offset), NH.getOffset());
410 return;
Chris Lattner9b87c5c2002-10-31 22:41:15 +0000411 } else if (Offset == NH.getOffset() && getSize() < N->getSize()) {
412 // If the offsets are the same, merge the smaller node into the bigger node
413 N->mergeWith(DSNodeHandle(this, Offset), NH.getOffset());
414 return;
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000415 }
416
417#if 0
418 std::cerr << "\n\nMerging:\n";
419 N->print(std::cerr, 0);
420 std::cerr << " and:\n";
421 print(std::cerr, 0);
422#endif
423
424 // Now we know that Offset <= NH.Offset, so convert it so our "Offset" (with
425 // respect to NH.Offset) is now zero.
426 //
427 unsigned NOffset = NH.getOffset()-Offset;
Chris Lattner7b7200c2002-10-02 04:57:39 +0000428 unsigned NSize = N->getSize();
Chris Lattner7b7200c2002-10-02 04:57:39 +0000429
Chris Lattner679e8e12002-11-08 21:27:12 +0000430 assert((NodeType & DSNode::DEAD) == 0);
431
Chris Lattnerc68c31b2002-07-10 22:38:08 +0000432 // Remove all edges pointing at N, causing them to point to 'this' instead.
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000433 // Make sure to adjust their offset, not just the node pointer.
434 //
435 while (!N->Referrers.empty()) {
436 DSNodeHandle &Ref = *N->Referrers.back();
437 Ref = DSNodeHandle(this, NOffset+Ref.getOffset());
438 }
Chris Lattner679e8e12002-11-08 21:27:12 +0000439 assert((NodeType & DSNode::DEAD) == 0);
Chris Lattner59535132002-11-05 00:01:58 +0000440
441 // Make all of the outgoing links of N now be outgoing links of this. This
442 // can cause recursive merging!
443 //
Chris Lattner08db7192002-11-06 06:20:27 +0000444 for (unsigned i = 0; i < NSize; i += DS::PointerSize) {
445 DSNodeHandle &Link = N->getLink(i);
446 if (Link.getNode()) {
447 addEdgeTo((i+NOffset) % getSize(), Link);
Chris Lattner59535132002-11-05 00:01:58 +0000448
Chris Lattner08db7192002-11-06 06:20:27 +0000449 // It's possible that after adding the new edge that some recursive
450 // merging just occured, causing THIS node to get merged into oblivion.
451 // If that happens, we must not try to merge any more edges into it!
Chris Lattner7b7200c2002-10-02 04:57:39 +0000452 //
Chris Lattner08db7192002-11-06 06:20:27 +0000453 if (Size == 0) return;
Chris Lattner7b7200c2002-10-02 04:57:39 +0000454 }
455 }
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000456
457 // Now that there are no outgoing edges, all of the Links are dead.
458 N->Links.clear();
Chris Lattner08db7192002-11-06 06:20:27 +0000459 N->Size = 0;
460 N->Ty.Ty = Type::VoidTy;
461 N->Ty.isArray = false;
Chris Lattnerc68c31b2002-07-10 22:38:08 +0000462
Chris Lattnerf9ae4c52002-07-11 20:32:22 +0000463 // Merge the node types
Chris Lattnerc68c31b2002-07-10 22:38:08 +0000464 NodeType |= N->NodeType;
Chris Lattner33312f72002-11-08 01:21:07 +0000465 N->NodeType = DEAD; // N is now a dead node.
Chris Lattnerf9ae4c52002-07-11 20:32:22 +0000466
467 // Merge the globals list...
Chris Lattner0d9bab82002-07-18 00:12:30 +0000468 if (!N->Globals.empty()) {
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000469 MergeSortedVectors(Globals, N->Globals);
Chris Lattner0d9bab82002-07-18 00:12:30 +0000470
471 // Delete the globals from the old node...
472 N->Globals.clear();
473 }
Chris Lattnerc68c31b2002-07-10 22:38:08 +0000474}
475
Chris Lattner9de906c2002-10-20 22:11:44 +0000476//===----------------------------------------------------------------------===//
477// DSCallSite Implementation
478//===----------------------------------------------------------------------===//
479
Vikram S. Adve26b98262002-10-20 21:41:02 +0000480// Define here to avoid including iOther.h and BasicBlock.h in DSGraph.h
Chris Lattner9de906c2002-10-20 22:11:44 +0000481Function &DSCallSite::getCaller() const {
Chris Lattner0969c502002-10-21 02:08:03 +0000482 return *Inst->getParent()->getParent();
Vikram S. Adve26b98262002-10-20 21:41:02 +0000483}
Vikram S. Adve42fd1692002-10-20 18:07:37 +0000484
Vikram S. Adve42fd1692002-10-20 18:07:37 +0000485
Chris Lattnerc68c31b2002-07-10 22:38:08 +0000486//===----------------------------------------------------------------------===//
487// DSGraph Implementation
488//===----------------------------------------------------------------------===//
489
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000490DSGraph::DSGraph(const DSGraph &G) : Func(G.Func) {
Chris Lattnerf8c6aab2002-11-08 05:01:14 +0000491 std::map<const DSNode*, DSNodeHandle> NodeMap;
Chris Lattnerc875f022002-11-03 21:27:48 +0000492 RetNode = cloneInto(G, ScalarMap, NodeMap);
Chris Lattner0d9bab82002-07-18 00:12:30 +0000493}
494
Chris Lattnerf8c6aab2002-11-08 05:01:14 +0000495DSGraph::DSGraph(const DSGraph &G,
496 std::map<const DSNode*, DSNodeHandle> &NodeMap)
Chris Lattnereff0da92002-10-21 15:32:34 +0000497 : Func(G.Func) {
Chris Lattnerc875f022002-11-03 21:27:48 +0000498 RetNode = cloneInto(G, ScalarMap, NodeMap);
Chris Lattnereff0da92002-10-21 15:32:34 +0000499}
500
Chris Lattnerc68c31b2002-07-10 22:38:08 +0000501DSGraph::~DSGraph() {
502 FunctionCalls.clear();
Chris Lattner679e8e12002-11-08 21:27:12 +0000503 AuxFunctionCalls.clear();
Chris Lattnerc875f022002-11-03 21:27:48 +0000504 ScalarMap.clear();
Chris Lattner13ec72a2002-10-21 13:31:48 +0000505 RetNode.setNode(0);
Chris Lattnerc68c31b2002-07-10 22:38:08 +0000506
507#ifndef NDEBUG
508 // Drop all intra-node references, so that assertions don't fail...
509 std::for_each(Nodes.begin(), Nodes.end(),
510 std::mem_fun(&DSNode::dropAllReferences));
511#endif
512
513 // Delete all of the nodes themselves...
514 std::for_each(Nodes.begin(), Nodes.end(), deleter<DSNode>);
515}
516
Chris Lattner0d9bab82002-07-18 00:12:30 +0000517// dump - Allow inspection of graph in a debugger.
518void DSGraph::dump() const { print(std::cerr); }
519
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000520
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000521/// remapLinks - Change all of the Links in the current node according to the
522/// specified mapping.
Chris Lattner8f0a16e2002-10-31 05:45:02 +0000523///
Chris Lattnerf8c6aab2002-11-08 05:01:14 +0000524void DSNode::remapLinks(std::map<const DSNode*, DSNodeHandle> &OldNodeMap) {
525 for (unsigned i = 0, e = Links.size(); i != e; ++i) {
526 DSNodeHandle &H = OldNodeMap[Links[i].getNode()];
527 Links[i].setNode(H.getNode());
528 Links[i].setOffset(Links[i].getOffset()+H.getOffset());
529 }
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000530}
Vikram S. Adve355e2ca2002-07-30 22:05:22 +0000531
Vikram S. Adve42fd1692002-10-20 18:07:37 +0000532
Chris Lattner0d9bab82002-07-18 00:12:30 +0000533// cloneInto - Clone the specified DSGraph into the current graph, returning the
Chris Lattnerc875f022002-11-03 21:27:48 +0000534// Return node of the graph. The translated ScalarMap for the old function is
Chris Lattner92673292002-11-02 00:13:20 +0000535// filled into the OldValMap member. If StripAllocas is set to true, Alloca
536// markers are removed from the graph, as the graph is being cloned into a
537// calling function's graph.
Chris Lattner0d9bab82002-07-18 00:12:30 +0000538//
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000539DSNodeHandle DSGraph::cloneInto(const DSGraph &G,
540 std::map<Value*, DSNodeHandle> &OldValMap,
Chris Lattnerf8c6aab2002-11-08 05:01:14 +0000541 std::map<const DSNode*, DSNodeHandle> &OldNodeMap,
Chris Lattner679e8e12002-11-08 21:27:12 +0000542 unsigned CloneFlags) {
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000543 assert(OldNodeMap.empty() && "Returned OldNodeMap should be empty!");
Chris Lattner33312f72002-11-08 01:21:07 +0000544 assert(&G != this && "Cannot clone graph into itself!");
Chris Lattner0d9bab82002-07-18 00:12:30 +0000545
Vikram S. Adve355e2ca2002-07-30 22:05:22 +0000546 unsigned FN = Nodes.size(); // First new node...
Chris Lattner0d9bab82002-07-18 00:12:30 +0000547
548 // Duplicate all of the nodes, populating the node map...
549 Nodes.reserve(FN+G.Nodes.size());
550 for (unsigned i = 0, e = G.Nodes.size(); i != e; ++i) {
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000551 DSNode *Old = G.Nodes[i];
552 DSNode *New = new DSNode(*Old);
Chris Lattner679e8e12002-11-08 21:27:12 +0000553 New->NodeType &= ~DSNode::DEAD; // Clear dead flag...
Chris Lattner0d9bab82002-07-18 00:12:30 +0000554 Nodes.push_back(New);
Vikram S. Adve6aa0d622002-07-18 16:12:08 +0000555 OldNodeMap[Old] = New;
Chris Lattner0d9bab82002-07-18 00:12:30 +0000556 }
557
Vikram S. Adve355e2ca2002-07-30 22:05:22 +0000558 // Rewrite the links in the new nodes to point into the current graph now.
Chris Lattner0d9bab82002-07-18 00:12:30 +0000559 for (unsigned i = FN, e = Nodes.size(); i != e; ++i)
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000560 Nodes[i]->remapLinks(OldNodeMap);
Chris Lattner0d9bab82002-07-18 00:12:30 +0000561
Chris Lattner460ea292002-11-07 07:06:20 +0000562 // Remove alloca markers as specified
Chris Lattner679e8e12002-11-08 21:27:12 +0000563 if (CloneFlags & StripAllocaBit)
Chris Lattner0d9bab82002-07-18 00:12:30 +0000564 for (unsigned i = FN, e = Nodes.size(); i != e; ++i)
Chris Lattner460ea292002-11-07 07:06:20 +0000565 Nodes[i]->NodeType &= ~DSNode::AllocaNode;
Chris Lattner0d9bab82002-07-18 00:12:30 +0000566
Chris Lattnercf15db32002-10-17 20:09:52 +0000567 // Copy the value map... and merge all of the global nodes...
Chris Lattnerc875f022002-11-03 21:27:48 +0000568 for (std::map<Value*, DSNodeHandle>::const_iterator I = G.ScalarMap.begin(),
569 E = G.ScalarMap.end(); I != E; ++I) {
Chris Lattnercf15db32002-10-17 20:09:52 +0000570 DSNodeHandle &H = OldValMap[I->first];
Chris Lattnerf8c6aab2002-11-08 05:01:14 +0000571 DSNodeHandle &MappedNode = OldNodeMap[I->second.getNode()];
572 H.setNode(MappedNode.getNode());
573 H.setOffset(I->second.getOffset()+MappedNode.getOffset());
Chris Lattnercf15db32002-10-17 20:09:52 +0000574
575 if (isa<GlobalValue>(I->first)) { // Is this a global?
Chris Lattnerc875f022002-11-03 21:27:48 +0000576 std::map<Value*, DSNodeHandle>::iterator GVI = ScalarMap.find(I->first);
577 if (GVI != ScalarMap.end()) { // Is the global value in this fn already?
Chris Lattnercf15db32002-10-17 20:09:52 +0000578 GVI->second.mergeWith(H);
579 } else {
Chris Lattnerc875f022002-11-03 21:27:48 +0000580 ScalarMap[I->first] = H; // Add global pointer to this graph
Chris Lattnercf15db32002-10-17 20:09:52 +0000581 }
582 }
583 }
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000584
Chris Lattner679e8e12002-11-08 21:27:12 +0000585 if (!(CloneFlags & DontCloneCallNodes)) {
586 // Copy the function calls list...
587 unsigned FC = FunctionCalls.size(); // FirstCall
588 FunctionCalls.reserve(FC+G.FunctionCalls.size());
589 for (unsigned i = 0, ei = G.FunctionCalls.size(); i != ei; ++i)
590 FunctionCalls.push_back(DSCallSite(G.FunctionCalls[i], OldNodeMap));
591
592 // Copy the auxillary function calls list...
593 FC = AuxFunctionCalls.size(); // FirstCall
594 AuxFunctionCalls.reserve(FC+G.AuxFunctionCalls.size());
595 for (unsigned i = 0, ei = G.AuxFunctionCalls.size(); i != ei; ++i)
596 AuxFunctionCalls.push_back(DSCallSite(G.AuxFunctionCalls[i], OldNodeMap));
597 }
Chris Lattnercf15db32002-10-17 20:09:52 +0000598
Chris Lattner0d9bab82002-07-18 00:12:30 +0000599 // Return the returned node pointer...
Chris Lattnerf8c6aab2002-11-08 05:01:14 +0000600 DSNodeHandle &MappedRet = OldNodeMap[G.RetNode.getNode()];
601 return DSNodeHandle(MappedRet.getNode(),
602 MappedRet.getOffset()+G.RetNode.getOffset());
Chris Lattner0d9bab82002-07-18 00:12:30 +0000603}
604
Chris Lattner076c1f92002-11-07 06:31:54 +0000605/// mergeInGraph - The method is used for merging graphs together. If the
606/// argument graph is not *this, it makes a clone of the specified graph, then
607/// merges the nodes specified in the call site with the formal arguments in the
608/// graph.
609///
610void DSGraph::mergeInGraph(DSCallSite &CS, const DSGraph &Graph,
Chris Lattner679e8e12002-11-08 21:27:12 +0000611 unsigned CloneFlags) {
Chris Lattner076c1f92002-11-07 06:31:54 +0000612 std::map<Value*, DSNodeHandle> OldValMap;
613 DSNodeHandle RetVal;
614 std::map<Value*, DSNodeHandle> *ScalarMap = &OldValMap;
615
616 // If this is not a recursive call, clone the graph into this graph...
617 if (&Graph != this) {
618 // Clone the callee's graph into the current graph, keeping
619 // track of where scalars in the old graph _used_ to point,
620 // and of the new nodes matching nodes of the old graph.
Chris Lattnerf8c6aab2002-11-08 05:01:14 +0000621 std::map<const DSNode*, DSNodeHandle> OldNodeMap;
Chris Lattner076c1f92002-11-07 06:31:54 +0000622
623 // The clone call may invalidate any of the vectors in the data
624 // structure graph. Strip locals and don't copy the list of callers
Chris Lattner679e8e12002-11-08 21:27:12 +0000625 RetVal = cloneInto(Graph, OldValMap, OldNodeMap, CloneFlags);
Chris Lattner076c1f92002-11-07 06:31:54 +0000626 ScalarMap = &OldValMap;
627 } else {
628 RetVal = getRetNode();
629 ScalarMap = &getScalarMap();
630 }
631
632 // Merge the return value with the return value of the context...
633 RetVal.mergeWith(CS.getRetVal());
634
635 // Resolve all of the function arguments...
636 Function &F = Graph.getFunction();
637 Function::aiterator AI = F.abegin();
638 for (unsigned i = 0, e = CS.getNumPtrArgs(); i != e; ++i, ++AI) {
639 // Advance the argument iterator to the first pointer argument...
640 while (!isPointerType(AI->getType())) {
641 ++AI;
642#ifndef NDEBUG
643 if (AI == F.aend())
644 std::cerr << "Bad call to Function: " << F.getName() << "\n";
645#endif
646 assert(AI != F.aend() && "# Args provided is not # Args required!");
647 }
648
649 // Add the link from the argument scalar to the provided value
650 DSNodeHandle &NH = (*ScalarMap)[AI];
651 assert(NH.getNode() && "Pointer argument without scalarmap entry?");
652 NH.mergeWith(CS.getPtrArg(i));
653 }
654}
655
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000656#if 0
Vikram S. Adve355e2ca2002-07-30 22:05:22 +0000657// cloneGlobalInto - Clone the given global node and all its target links
658// (and all their llinks, recursively).
659//
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000660DSNode *DSGraph::cloneGlobalInto(const DSNode *GNode) {
Vikram S. Adve355e2ca2002-07-30 22:05:22 +0000661 if (GNode == 0 || GNode->getGlobals().size() == 0) return 0;
662
663 // If a clone has already been created for GNode, return it.
Chris Lattnerc875f022002-11-03 21:27:48 +0000664 DSNodeHandle& ValMapEntry = ScalarMap[GNode->getGlobals()[0]];
Vikram S. Adve355e2ca2002-07-30 22:05:22 +0000665 if (ValMapEntry != 0)
666 return ValMapEntry;
667
668 // Clone the node and update the ValMap.
669 DSNode* NewNode = new DSNode(*GNode);
670 ValMapEntry = NewNode; // j=0 case of loop below!
671 Nodes.push_back(NewNode);
672 for (unsigned j = 1, N = NewNode->getGlobals().size(); j < N; ++j)
Chris Lattnerc875f022002-11-03 21:27:48 +0000673 ScalarMap[NewNode->getGlobals()[j]] = NewNode;
Vikram S. Adve355e2ca2002-07-30 22:05:22 +0000674
675 // Rewrite the links in the new node to point into the current graph.
676 for (unsigned j = 0, e = GNode->getNumLinks(); j != e; ++j)
677 NewNode->setLink(j, cloneGlobalInto(GNode->getLink(j)));
678
679 return NewNode;
680}
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000681#endif
Vikram S. Adve355e2ca2002-07-30 22:05:22 +0000682
683
Chris Lattner0d9bab82002-07-18 00:12:30 +0000684// markIncompleteNodes - Mark the specified node as having contents that are not
685// known with the current analysis we have performed. Because a node makes all
686// of the nodes it can reach imcomplete if the node itself is incomplete, we
687// must recursively traverse the data structure graph, marking all reachable
688// nodes as incomplete.
689//
690static void markIncompleteNode(DSNode *N) {
691 // Stop recursion if no node, or if node already marked...
692 if (N == 0 || (N->NodeType & DSNode::Incomplete)) return;
693
694 // Actually mark the node
695 N->NodeType |= DSNode::Incomplete;
696
697 // Recusively process children...
Chris Lattner08db7192002-11-06 06:20:27 +0000698 for (unsigned i = 0, e = N->getSize(); i < e; i += DS::PointerSize)
699 if (DSNode *DSN = N->getLink(i).getNode())
700 markIncompleteNode(DSN);
Chris Lattner0d9bab82002-07-18 00:12:30 +0000701}
702
703
704// markIncompleteNodes - Traverse the graph, identifying nodes that may be
705// modified by other functions that have not been resolved yet. This marks
706// nodes that are reachable through three sources of "unknownness":
707//
708// Global Variables, Function Calls, and Incoming Arguments
709//
710// For any node that may have unknown components (because something outside the
711// scope of current analysis may have modified it), the 'Incomplete' flag is
712// added to the NodeType.
713//
Vikram S. Adve355e2ca2002-07-30 22:05:22 +0000714void DSGraph::markIncompleteNodes(bool markFormalArgs) {
Chris Lattner0d9bab82002-07-18 00:12:30 +0000715 // Mark any incoming arguments as incomplete...
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000716 if (markFormalArgs && Func)
717 for (Function::aiterator I = Func->abegin(), E = Func->aend(); I != E; ++I)
Chris Lattnerc875f022002-11-03 21:27:48 +0000718 if (isPointerType(I->getType()) && ScalarMap.find(I) != ScalarMap.end())
719 markIncompleteNode(ScalarMap[I].getNode());
Chris Lattner0d9bab82002-07-18 00:12:30 +0000720
721 // Mark stuff passed into functions calls as being incomplete...
722 for (unsigned i = 0, e = FunctionCalls.size(); i != e; ++i) {
Vikram S. Adve26b98262002-10-20 21:41:02 +0000723 DSCallSite &Call = FunctionCalls[i];
Chris Lattnere2219762002-07-18 18:22:40 +0000724 // Then the return value is certainly incomplete!
Chris Lattner0969c502002-10-21 02:08:03 +0000725 markIncompleteNode(Call.getRetVal().getNode());
Chris Lattner0d9bab82002-07-18 00:12:30 +0000726
Chris Lattner92673292002-11-02 00:13:20 +0000727 // All objects pointed to by function arguments are incomplete though!
Vikram S. Adve26b98262002-10-20 21:41:02 +0000728 for (unsigned i = 0, e = Call.getNumPtrArgs(); i != e; ++i)
Chris Lattner0969c502002-10-21 02:08:03 +0000729 markIncompleteNode(Call.getPtrArg(i).getNode());
Chris Lattner0d9bab82002-07-18 00:12:30 +0000730 }
731
Chris Lattner92673292002-11-02 00:13:20 +0000732 // Mark all of the nodes pointed to by global nodes as incomplete...
Chris Lattner0d9bab82002-07-18 00:12:30 +0000733 for (unsigned i = 0, e = Nodes.size(); i != e; ++i)
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000734 if (Nodes[i]->NodeType & DSNode::GlobalNode) {
Chris Lattner0d9bab82002-07-18 00:12:30 +0000735 DSNode *N = Nodes[i];
Chris Lattner92673292002-11-02 00:13:20 +0000736 // FIXME: Make more efficient by looking over Links directly
Chris Lattner08db7192002-11-06 06:20:27 +0000737 for (unsigned i = 0, e = N->getSize(); i < e; i += DS::PointerSize)
738 if (DSNode *DSN = N->getLink(i).getNode())
739 markIncompleteNode(DSN);
Chris Lattner0d9bab82002-07-18 00:12:30 +0000740 }
741}
742
Vikram S. Adve355e2ca2002-07-30 22:05:22 +0000743// removeRefsToGlobal - Helper function that removes globals from the
Chris Lattnerc875f022002-11-03 21:27:48 +0000744// ScalarMap so that the referrer count will go down to zero.
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000745static void removeRefsToGlobal(DSNode* N,
Chris Lattnerc875f022002-11-03 21:27:48 +0000746 std::map<Value*, DSNodeHandle> &ScalarMap) {
Vikram S. Adve355e2ca2002-07-30 22:05:22 +0000747 while (!N->getGlobals().empty()) {
748 GlobalValue *GV = N->getGlobals().back();
749 N->getGlobals().pop_back();
Chris Lattnerc875f022002-11-03 21:27:48 +0000750 ScalarMap.erase(GV);
Vikram S. Adve355e2ca2002-07-30 22:05:22 +0000751 }
752}
753
754
Chris Lattner0d9bab82002-07-18 00:12:30 +0000755// isNodeDead - This method checks to see if a node is dead, and if it isn't, it
756// checks to see if there are simple transformations that it can do to make it
757// dead.
758//
759bool DSGraph::isNodeDead(DSNode *N) {
760 // Is it a trivially dead shadow node...
Chris Lattner33312f72002-11-08 01:21:07 +0000761 if (N->getReferrers().empty() &&
762 (N->NodeType == 0 || N->NodeType == DSNode::DEAD))
Chris Lattner0d9bab82002-07-18 00:12:30 +0000763 return true;
764
765 // Is it a function node or some other trivially unused global?
Chris Lattner92673292002-11-02 00:13:20 +0000766 if ((N->NodeType & ~DSNode::GlobalNode) == 0 && N->getSize() == 0 &&
Chris Lattner0d9bab82002-07-18 00:12:30 +0000767 N->getReferrers().size() == N->getGlobals().size()) {
768
Chris Lattnerc875f022002-11-03 21:27:48 +0000769 // Remove the globals from the ScalarMap, so that the referrer count will go
Chris Lattner0d9bab82002-07-18 00:12:30 +0000770 // down to zero.
Chris Lattnerc875f022002-11-03 21:27:48 +0000771 removeRefsToGlobal(N, ScalarMap);
Chris Lattner0d9bab82002-07-18 00:12:30 +0000772 assert(N->getReferrers().empty() && "Referrers should all be gone now!");
773 return true;
774 }
775
776 return false;
777}
778
Vikram S. Adve42fd1692002-10-20 18:07:37 +0000779static void removeIdenticalCalls(vector<DSCallSite> &Calls,
Chris Lattner7541b892002-07-31 19:32:12 +0000780 const std::string &where) {
Vikram S. Adve355e2ca2002-07-30 22:05:22 +0000781 // Remove trivially identical function calls
782 unsigned NumFns = Calls.size();
783 std::sort(Calls.begin(), Calls.end());
784 Calls.erase(std::unique(Calls.begin(), Calls.end()),
785 Calls.end());
786
Chris Lattner33312f72002-11-08 01:21:07 +0000787 // Track the number of call nodes merged away...
788 NumCallNodesMerged += NumFns-Calls.size();
789
Vikram S. Adve355e2ca2002-07-30 22:05:22 +0000790 DEBUG(if (NumFns != Calls.size())
Chris Lattner7541b892002-07-31 19:32:12 +0000791 std::cerr << "Merged " << (NumFns-Calls.size())
792 << " call nodes in " << where << "\n";);
Vikram S. Adve355e2ca2002-07-30 22:05:22 +0000793}
Chris Lattner0d9bab82002-07-18 00:12:30 +0000794
Chris Lattnere2219762002-07-18 18:22:40 +0000795// removeTriviallyDeadNodes - After the graph has been constructed, this method
796// removes all unreachable nodes that are created because they got merged with
797// other nodes in the graph. These nodes will all be trivially unreachable, so
798// we don't have to perform any non-trivial analysis here.
Chris Lattner0d9bab82002-07-18 00:12:30 +0000799//
Vikram S. Adve355e2ca2002-07-30 22:05:22 +0000800void DSGraph::removeTriviallyDeadNodes(bool KeepAllGlobals) {
Chris Lattner0d9bab82002-07-18 00:12:30 +0000801 for (unsigned i = 0; i != Nodes.size(); ++i)
Chris Lattnera00397e2002-10-03 21:55:28 +0000802 if (!KeepAllGlobals || !(Nodes[i]->NodeType & DSNode::GlobalNode))
Vikram S. Adve355e2ca2002-07-30 22:05:22 +0000803 if (isNodeDead(Nodes[i])) { // This node is dead!
804 delete Nodes[i]; // Free memory...
805 Nodes.erase(Nodes.begin()+i--); // Remove from node list...
806 }
Chris Lattner0d9bab82002-07-18 00:12:30 +0000807
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000808 removeIdenticalCalls(FunctionCalls, Func ? Func->getName() : "");
Chris Lattner0d9bab82002-07-18 00:12:30 +0000809}
810
811
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000812// markAlive - Simple graph walker that recursively traverses the graph, marking
Chris Lattnere2219762002-07-18 18:22:40 +0000813// stuff to be alive.
814//
815static void markAlive(DSNode *N, std::set<DSNode*> &Alive) {
Vikram S. Adve355e2ca2002-07-30 22:05:22 +0000816 if (N == 0) return;
Chris Lattnere2219762002-07-18 18:22:40 +0000817
818 Alive.insert(N);
Chris Lattner08db7192002-11-06 06:20:27 +0000819 for (unsigned i = 0, e = N->getSize(); i < e; i += DS::PointerSize)
820 if (DSNode *DSN = N->getLink(i).getNode())
821 if (!Alive.count(DSN))
822 markAlive(DSN, Alive);
Chris Lattnere2219762002-07-18 18:22:40 +0000823}
824
Vikram S. Adve355e2ca2002-07-30 22:05:22 +0000825static bool checkGlobalAlive(DSNode *N, std::set<DSNode*> &Alive,
826 std::set<DSNode*> &Visiting) {
827 if (N == 0) return false;
828
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000829 if (Visiting.count(N)) return false; // terminate recursion on a cycle
Vikram S. Adve355e2ca2002-07-30 22:05:22 +0000830 Visiting.insert(N);
831
832 // If any immediate successor is alive, N is alive
Chris Lattner08db7192002-11-06 06:20:27 +0000833 for (unsigned i = 0, e = N->getSize(); i < e; i += DS::PointerSize)
834 if (DSNode *DSN = N->getLink(i).getNode())
835 if (Alive.count(DSN)) {
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000836 Visiting.erase(N);
837 return true;
838 }
Vikram S. Adve355e2ca2002-07-30 22:05:22 +0000839
840 // Else if any successor reaches a live node, N is alive
Chris Lattner08db7192002-11-06 06:20:27 +0000841 for (unsigned i = 0, e = N->getSize(); i < e; i += DS::PointerSize)
842 if (DSNode *DSN = N->getLink(i).getNode())
843 if (checkGlobalAlive(DSN, Alive, Visiting)) {
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000844 Visiting.erase(N); return true;
845 }
Vikram S. Adve355e2ca2002-07-30 22:05:22 +0000846
847 Visiting.erase(N);
848 return false;
849}
850
851
852// markGlobalsIteration - Recursive helper function for markGlobalsAlive().
853// This would be unnecessary if function calls were real nodes! In that case,
854// the simple iterative loop in the first few lines below suffice.
855//
856static void markGlobalsIteration(std::set<DSNode*>& GlobalNodes,
Vikram S. Adve42fd1692002-10-20 18:07:37 +0000857 vector<DSCallSite> &Calls,
Vikram S. Adve355e2ca2002-07-30 22:05:22 +0000858 std::set<DSNode*> &Alive,
859 bool FilterCalls) {
860
861 // Iterate, marking globals or cast nodes alive until no new live nodes
862 // are added to Alive
863 std::set<DSNode*> Visiting; // Used to identify cycles
Chris Lattner0969c502002-10-21 02:08:03 +0000864 std::set<DSNode*>::iterator I = GlobalNodes.begin(), E = GlobalNodes.end();
Vikram S. Adve355e2ca2002-07-30 22:05:22 +0000865 for (size_t liveCount = 0; liveCount < Alive.size(); ) {
866 liveCount = Alive.size();
867 for ( ; I != E; ++I)
868 if (Alive.count(*I) == 0) {
869 Visiting.clear();
870 if (checkGlobalAlive(*I, Alive, Visiting))
871 markAlive(*I, Alive);
872 }
873 }
874
875 // Find function calls with some dead and some live nodes.
876 // Since all call nodes must be live if any one is live, we have to mark
877 // all nodes of the call as live and continue the iteration (via recursion).
878 if (FilterCalls) {
Chris Lattner0969c502002-10-21 02:08:03 +0000879 bool Recurse = false;
880 for (unsigned i = 0, ei = Calls.size(); i < ei; ++i) {
Vikram S. Adve355e2ca2002-07-30 22:05:22 +0000881 bool CallIsDead = true, CallHasDeadArg = false;
Chris Lattner0969c502002-10-21 02:08:03 +0000882 DSCallSite &CS = Calls[i];
883 for (unsigned j = 0, ej = CS.getNumPtrArgs(); j != ej; ++j)
884 if (DSNode *N = CS.getPtrArg(j).getNode()) {
885 bool ArgIsDead = !Alive.count(N);
886 CallHasDeadArg |= ArgIsDead;
887 CallIsDead &= ArgIsDead;
888 }
889
890 if (DSNode *N = CS.getRetVal().getNode()) {
891 bool RetIsDead = !Alive.count(N);
892 CallHasDeadArg |= RetIsDead;
893 CallIsDead &= RetIsDead;
Vikram S. Adve355e2ca2002-07-30 22:05:22 +0000894 }
Chris Lattner0969c502002-10-21 02:08:03 +0000895
896 DSNode *N = CS.getCallee().getNode();
897 bool FnIsDead = !Alive.count(N);
898 CallHasDeadArg |= FnIsDead;
899 CallIsDead &= FnIsDead;
900
Vikram S. Adve355e2ca2002-07-30 22:05:22 +0000901 if (!CallIsDead && CallHasDeadArg) {
902 // Some node in this call is live and another is dead.
903 // Mark all nodes of call as live and iterate once more.
Chris Lattner0969c502002-10-21 02:08:03 +0000904 Recurse = true;
905 for (unsigned j = 0, ej = CS.getNumPtrArgs(); j != ej; ++j)
906 markAlive(CS.getPtrArg(j).getNode(), Alive);
907 markAlive(CS.getRetVal().getNode(), Alive);
908 markAlive(CS.getCallee().getNode(), Alive);
Vikram S. Adve355e2ca2002-07-30 22:05:22 +0000909 }
910 }
Chris Lattner0969c502002-10-21 02:08:03 +0000911 if (Recurse)
Vikram S. Adve355e2ca2002-07-30 22:05:22 +0000912 markGlobalsIteration(GlobalNodes, Calls, Alive, FilterCalls);
913 }
914}
915
916
917// markGlobalsAlive - Mark global nodes and cast nodes alive if they
918// can reach any other live node. Since this can produce new live nodes,
919// we use a simple iterative algorithm.
920//
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000921static void markGlobalsAlive(DSGraph &G, std::set<DSNode*> &Alive,
Vikram S. Adve355e2ca2002-07-30 22:05:22 +0000922 bool FilterCalls) {
923 // Add global and cast nodes to a set so we don't walk all nodes every time
924 std::set<DSNode*> GlobalNodes;
925 for (unsigned i = 0, e = G.getNodes().size(); i != e; ++i)
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000926 if (G.getNodes()[i]->NodeType & DSNode::GlobalNode)
Vikram S. Adve355e2ca2002-07-30 22:05:22 +0000927 GlobalNodes.insert(G.getNodes()[i]);
928
929 // Add all call nodes to the same set
Chris Lattner679e8e12002-11-08 21:27:12 +0000930 vector<DSCallSite> &Calls = G.getAuxFunctionCalls();
Vikram S. Adve355e2ca2002-07-30 22:05:22 +0000931 if (FilterCalls) {
Chris Lattner0969c502002-10-21 02:08:03 +0000932 for (unsigned i = 0, e = Calls.size(); i != e; ++i) {
933 for (unsigned j = 0, e = Calls[i].getNumPtrArgs(); j != e; ++j)
934 if (DSNode *N = Calls[i].getPtrArg(j).getNode())
935 GlobalNodes.insert(N);
936 if (DSNode *N = Calls[i].getRetVal().getNode())
937 GlobalNodes.insert(N);
938 if (DSNode *N = Calls[i].getCallee().getNode())
939 GlobalNodes.insert(N);
940 }
Vikram S. Adve355e2ca2002-07-30 22:05:22 +0000941 }
942
943 // Iterate and recurse until no new live node are discovered.
944 // This would be a simple iterative loop if function calls were real nodes!
945 markGlobalsIteration(GlobalNodes, Calls, Alive, FilterCalls);
946
Chris Lattnerc875f022002-11-03 21:27:48 +0000947 // Free up references to dead globals from the ScalarMap
Chris Lattner92673292002-11-02 00:13:20 +0000948 std::set<DSNode*>::iterator I = GlobalNodes.begin(), E = GlobalNodes.end();
Vikram S. Adve355e2ca2002-07-30 22:05:22 +0000949 for( ; I != E; ++I)
950 if (Alive.count(*I) == 0)
Chris Lattnerc875f022002-11-03 21:27:48 +0000951 removeRefsToGlobal(*I, G.getScalarMap());
Vikram S. Adve355e2ca2002-07-30 22:05:22 +0000952
953 // Delete dead function calls
954 if (FilterCalls)
955 for (int ei = Calls.size(), i = ei-1; i >= 0; --i) {
956 bool CallIsDead = true;
Chris Lattner0969c502002-10-21 02:08:03 +0000957 for (unsigned j = 0, ej = Calls[i].getNumPtrArgs();
958 CallIsDead && j != ej; ++j)
959 CallIsDead = Alive.count(Calls[i].getPtrArg(j).getNode()) == 0;
Vikram S. Adve355e2ca2002-07-30 22:05:22 +0000960 if (CallIsDead)
961 Calls.erase(Calls.begin() + i); // remove the call entirely
962 }
963}
Chris Lattnere2219762002-07-18 18:22:40 +0000964
965// removeDeadNodes - Use a more powerful reachability analysis to eliminate
966// subgraphs that are unreachable. This often occurs because the data
967// structure doesn't "escape" into it's caller, and thus should be eliminated
968// from the caller's graph entirely. This is only appropriate to use when
969// inlining graphs.
970//
Vikram S. Adve355e2ca2002-07-30 22:05:22 +0000971void DSGraph::removeDeadNodes(bool KeepAllGlobals, bool KeepCalls) {
Chris Lattner33312f72002-11-08 01:21:07 +0000972 assert((!KeepAllGlobals || KeepCalls) && // FIXME: This should be an enum!
Vikram S. Adve355e2ca2002-07-30 22:05:22 +0000973 "KeepAllGlobals without KeepCalls is meaningless");
974
Chris Lattnere2219762002-07-18 18:22:40 +0000975 // Reduce the amount of work we have to do...
Vikram S. Adve355e2ca2002-07-30 22:05:22 +0000976 removeTriviallyDeadNodes(KeepAllGlobals);
977
Chris Lattnere2219762002-07-18 18:22:40 +0000978 // FIXME: Merge nontrivially identical call nodes...
979
980 // Alive - a set that holds all nodes found to be reachable/alive.
981 std::set<DSNode*> Alive;
982
Vikram S. Adve355e2ca2002-07-30 22:05:22 +0000983 // If KeepCalls, mark all nodes reachable by call nodes as alive...
984 if (KeepCalls)
Chris Lattner0969c502002-10-21 02:08:03 +0000985 for (unsigned i = 0, e = FunctionCalls.size(); i != e; ++i) {
986 for (unsigned j = 0, e = FunctionCalls[i].getNumPtrArgs(); j != e; ++j)
987 markAlive(FunctionCalls[i].getPtrArg(j).getNode(), Alive);
988 markAlive(FunctionCalls[i].getRetVal().getNode(), Alive);
989 markAlive(FunctionCalls[i].getCallee().getNode(), Alive);
990 }
Chris Lattnere2219762002-07-18 18:22:40 +0000991
Chris Lattner92673292002-11-02 00:13:20 +0000992 // Mark all nodes reachable by scalar nodes as alive...
Chris Lattnerc875f022002-11-03 21:27:48 +0000993 for (std::map<Value*, DSNodeHandle>::iterator I = ScalarMap.begin(),
994 E = ScalarMap.end(); I != E; ++I)
Chris Lattner92673292002-11-02 00:13:20 +0000995 markAlive(I->second.getNode(), Alive);
Chris Lattnere2219762002-07-18 18:22:40 +0000996
Vikram S. Adve355e2ca2002-07-30 22:05:22 +0000997 // The return value is alive as well...
Chris Lattnerfccd06f2002-10-01 22:33:50 +0000998 markAlive(RetNode.getNode(), Alive);
Vikram S. Adve355e2ca2002-07-30 22:05:22 +0000999
1000 // Mark all globals or cast nodes that can reach a live node as alive.
1001 // This also marks all nodes reachable from such nodes as alive.
1002 // Of course, if KeepAllGlobals is specified, they would be live already.
Chris Lattner33312f72002-11-08 01:21:07 +00001003
Chris Lattner0969c502002-10-21 02:08:03 +00001004 if (!KeepAllGlobals)
Chris Lattner92673292002-11-02 00:13:20 +00001005 markGlobalsAlive(*this, Alive, !KeepCalls);
Vikram S. Adve355e2ca2002-07-30 22:05:22 +00001006
Chris Lattnere2219762002-07-18 18:22:40 +00001007 // Loop over all unreachable nodes, dropping their references...
Chris Lattnerfccd06f2002-10-01 22:33:50 +00001008 vector<DSNode*> DeadNodes;
Chris Lattnere2219762002-07-18 18:22:40 +00001009 DeadNodes.reserve(Nodes.size()); // Only one allocation is allowed.
1010 for (unsigned i = 0; i != Nodes.size(); ++i)
1011 if (!Alive.count(Nodes[i])) {
1012 DSNode *N = Nodes[i];
1013 Nodes.erase(Nodes.begin()+i--); // Erase node from alive list.
1014 DeadNodes.push_back(N); // Add node to our list of dead nodes
1015 N->dropAllReferences(); // Drop all outgoing edges
1016 }
1017
Chris Lattnere2219762002-07-18 18:22:40 +00001018 // Delete all dead nodes...
1019 std::for_each(DeadNodes.begin(), DeadNodes.end(), deleter<DSNode>);
1020}
1021
1022
1023
Chris Lattner0d9bab82002-07-18 00:12:30 +00001024// maskNodeTypes - Apply a mask to all of the node types in the graph. This
1025// is useful for clearing out markers like Scalar or Incomplete.
1026//
1027void DSGraph::maskNodeTypes(unsigned char Mask) {
1028 for (unsigned i = 0, e = Nodes.size(); i != e; ++i)
1029 Nodes[i]->NodeType &= Mask;
1030}
1031
1032
Chris Lattnerfccd06f2002-10-01 22:33:50 +00001033#if 0
Chris Lattnerc68c31b2002-07-10 22:38:08 +00001034//===----------------------------------------------------------------------===//
Vikram S. Adve355e2ca2002-07-30 22:05:22 +00001035// GlobalDSGraph Implementation
1036//===----------------------------------------------------------------------===//
1037
1038GlobalDSGraph::GlobalDSGraph() : DSGraph(*(Function*)0, this) {
1039}
1040
1041GlobalDSGraph::~GlobalDSGraph() {
1042 assert(Referrers.size() == 0 &&
1043 "Deleting global graph while references from other graphs exist");
1044}
1045
1046void GlobalDSGraph::addReference(const DSGraph* referrer) {
1047 if (referrer != this)
1048 Referrers.insert(referrer);
1049}
1050
1051void GlobalDSGraph::removeReference(const DSGraph* referrer) {
1052 if (referrer != this) {
1053 assert(Referrers.find(referrer) != Referrers.end() && "This is very bad!");
1054 Referrers.erase(referrer);
1055 if (Referrers.size() == 0)
1056 delete this;
1057 }
1058}
1059
Chris Lattnerfccd06f2002-10-01 22:33:50 +00001060#if 0
Chris Lattnerd18f3422002-11-03 21:24:04 +00001061// Bits used in the next function
1062static const char ExternalTypeBits = DSNode::GlobalNode | DSNode::HeapNode;
1063
1064
Vikram S. Adve355e2ca2002-07-30 22:05:22 +00001065// GlobalDSGraph::cloneNodeInto - Clone a global node and all its externally
1066// visible target links (and recursively their such links) into this graph.
1067// NodeCache maps the node being cloned to its clone in the Globals graph,
1068// in order to track cycles.
1069// GlobalsAreFinal is a flag that says whether it is safe to assume that
1070// an existing global node is complete. This is important to avoid
1071// reinserting all globals when inserting Calls to functions.
1072// This is a helper function for cloneGlobals and cloneCalls.
1073//
1074DSNode* GlobalDSGraph::cloneNodeInto(DSNode *OldNode,
1075 std::map<const DSNode*, DSNode*> &NodeCache,
1076 bool GlobalsAreFinal) {
1077 if (OldNode == 0) return 0;
1078
1079 // The caller should check this is an external node. Just more efficient...
1080 assert((OldNode->NodeType & ExternalTypeBits) && "Non-external node");
1081
1082 // If a clone has already been created for OldNode, return it.
1083 DSNode*& CacheEntry = NodeCache[OldNode];
1084 if (CacheEntry != 0)
1085 return CacheEntry;
1086
1087 // The result value...
1088 DSNode* NewNode = 0;
1089
1090 // If nodes already exist for any of the globals of OldNode,
1091 // merge all such nodes together since they are merged in OldNode.
1092 // If ValueCacheIsFinal==true, look for an existing node that has
1093 // an identical list of globals and return it if it exists.
1094 //
Chris Lattnerfccd06f2002-10-01 22:33:50 +00001095 for (unsigned j = 0, N = OldNode->getGlobals().size(); j != N; ++j)
Chris Lattnerc875f022002-11-03 21:27:48 +00001096 if (DSNode *PrevNode = ScalarMap[OldNode->getGlobals()[j]].getNode()) {
Vikram S. Adve355e2ca2002-07-30 22:05:22 +00001097 if (NewNode == 0) {
1098 NewNode = PrevNode; // first existing node found
1099 if (GlobalsAreFinal && j == 0)
1100 if (OldNode->getGlobals() == PrevNode->getGlobals()) {
1101 CacheEntry = NewNode;
1102 return NewNode;
1103 }
1104 }
1105 else if (NewNode != PrevNode) { // found another, different from prev
1106 // update ValMap *before* merging PrevNode into NewNode
1107 for (unsigned k = 0, NK = PrevNode->getGlobals().size(); k < NK; ++k)
Chris Lattnerc875f022002-11-03 21:27:48 +00001108 ScalarMap[PrevNode->getGlobals()[k]] = NewNode;
Vikram S. Adve355e2ca2002-07-30 22:05:22 +00001109 NewNode->mergeWith(PrevNode);
1110 }
1111 } else if (NewNode != 0) {
Chris Lattnerc875f022002-11-03 21:27:48 +00001112 ScalarMap[OldNode->getGlobals()[j]] = NewNode; // add the merged node
Vikram S. Adve355e2ca2002-07-30 22:05:22 +00001113 }
1114
1115 // If no existing node was found, clone the node and update the ValMap.
1116 if (NewNode == 0) {
1117 NewNode = new DSNode(*OldNode);
1118 Nodes.push_back(NewNode);
1119 for (unsigned j = 0, e = NewNode->getNumLinks(); j != e; ++j)
1120 NewNode->setLink(j, 0);
1121 for (unsigned j = 0, N = NewNode->getGlobals().size(); j < N; ++j)
Chris Lattnerc875f022002-11-03 21:27:48 +00001122 ScalarMap[NewNode->getGlobals()[j]] = NewNode;
Vikram S. Adve355e2ca2002-07-30 22:05:22 +00001123 }
1124 else
1125 NewNode->NodeType |= OldNode->NodeType; // Markers may be different!
1126
1127 // Add the entry to NodeCache
1128 CacheEntry = NewNode;
1129
1130 // Rewrite the links in the new node to point into the current graph,
1131 // but only for links to external nodes. Set other links to NULL.
1132 for (unsigned j = 0, e = OldNode->getNumLinks(); j != e; ++j) {
1133 DSNode* OldTarget = OldNode->getLink(j);
1134 if (OldTarget && (OldTarget->NodeType & ExternalTypeBits)) {
1135 DSNode* NewLink = this->cloneNodeInto(OldTarget, NodeCache);
1136 if (NewNode->getLink(j))
1137 NewNode->getLink(j)->mergeWith(NewLink);
1138 else
1139 NewNode->setLink(j, NewLink);
1140 }
1141 }
1142
1143 // Remove all local markers
1144 NewNode->NodeType &= ~(DSNode::AllocaNode | DSNode::ScalarNode);
1145
1146 return NewNode;
1147}
1148
1149
1150// GlobalDSGraph::cloneGlobals - Clone global nodes and all their externally
1151// visible target links (and recursively their such links) into this graph.
1152//
1153void GlobalDSGraph::cloneGlobals(DSGraph& Graph, bool CloneCalls) {
1154 std::map<const DSNode*, DSNode*> NodeCache;
Chris Lattnerfccd06f2002-10-01 22:33:50 +00001155#if 0
Vikram S. Adve355e2ca2002-07-30 22:05:22 +00001156 for (unsigned i = 0, N = Graph.Nodes.size(); i < N; ++i)
1157 if (Graph.Nodes[i]->NodeType & DSNode::GlobalNode)
1158 GlobalsGraph->cloneNodeInto(Graph.Nodes[i], NodeCache, false);
Vikram S. Adve355e2ca2002-07-30 22:05:22 +00001159 if (CloneCalls)
1160 GlobalsGraph->cloneCalls(Graph);
1161
1162 GlobalsGraph->removeDeadNodes(/*KeepAllGlobals*/ true, /*KeepCalls*/ true);
Chris Lattnerfccd06f2002-10-01 22:33:50 +00001163#endif
Vikram S. Adve355e2ca2002-07-30 22:05:22 +00001164}
1165
1166
1167// GlobalDSGraph::cloneCalls - Clone function calls and their visible target
1168// links (and recursively their such links) into this graph.
1169//
1170void GlobalDSGraph::cloneCalls(DSGraph& Graph) {
1171 std::map<const DSNode*, DSNode*> NodeCache;
Vikram S. Adve42fd1692002-10-20 18:07:37 +00001172 vector<DSCallSite >& FromCalls =Graph.FunctionCalls;
Vikram S. Adve355e2ca2002-07-30 22:05:22 +00001173
1174 FunctionCalls.reserve(FunctionCalls.size() + FromCalls.size());
1175
1176 for (int i = 0, ei = FromCalls.size(); i < ei; ++i) {
Vikram S. Adve42fd1692002-10-20 18:07:37 +00001177 DSCallSite& callCopy = FunctionCalls.back();
1178 callCopy.reserve(FromCalls[i].size());
Vikram S. Adve355e2ca2002-07-30 22:05:22 +00001179 for (unsigned j = 0, ej = FromCalls[i].size(); j != ej; ++j)
Vikram S. Adve42fd1692002-10-20 18:07:37 +00001180 callCopy.push_back
Vikram S. Adve355e2ca2002-07-30 22:05:22 +00001181 ((FromCalls[i][j] && (FromCalls[i][j]->NodeType & ExternalTypeBits))
1182 ? cloneNodeInto(FromCalls[i][j], NodeCache, true)
1183 : 0);
1184 }
1185
1186 // remove trivially identical function calls
Chris Lattner7541b892002-07-31 19:32:12 +00001187 removeIdenticalCalls(FunctionCalls, "Globals Graph");
Vikram S. Adve355e2ca2002-07-30 22:05:22 +00001188}
Chris Lattnerfccd06f2002-10-01 22:33:50 +00001189#endif
Vikram S. Adve355e2ca2002-07-30 22:05:22 +00001190
Chris Lattnerfccd06f2002-10-01 22:33:50 +00001191#endif