blob: 228bb80ae3b8a1866d50048116031d057be4072d [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===- AliasSetTracker.cpp - Alias Sets Tracker implementation-------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the AliasSetTracker and AliasSet classes.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/Analysis/AliasSetTracker.h"
15#include "llvm/Analysis/AliasAnalysis.h"
16#include "llvm/Instructions.h"
17#include "llvm/Pass.h"
18#include "llvm/Type.h"
19#include "llvm/Target/TargetData.h"
20#include "llvm/Assembly/Writer.h"
21#include "llvm/Support/Compiler.h"
22#include "llvm/Support/InstIterator.h"
23#include "llvm/Support/Streams.h"
24using namespace llvm;
25
26/// mergeSetIn - Merge the specified alias set into this alias set.
27///
28void AliasSet::mergeSetIn(AliasSet &AS, AliasSetTracker &AST) {
29 assert(!AS.Forward && "Alias set is already forwarding!");
30 assert(!Forward && "This set is a forwarding set!!");
31
32 // Update the alias and access types of this set...
33 AccessTy |= AS.AccessTy;
34 AliasTy |= AS.AliasTy;
35
36 if (AliasTy == MustAlias) {
37 // Check that these two merged sets really are must aliases. Since both
38 // used to be must-alias sets, we can just check any pointer from each set
39 // for aliasing.
40 AliasAnalysis &AA = AST.getAliasAnalysis();
41 HashNodePair *L = getSomePointer();
42 HashNodePair *R = AS.getSomePointer();
43
44 // If the pointers are not a must-alias pair, this set becomes a may alias.
45 if (AA.alias(L->first, L->second.getSize(), R->first, R->second.getSize())
46 != AliasAnalysis::MustAlias)
47 AliasTy = MayAlias;
48 }
49
50 if (CallSites.empty()) { // Merge call sites...
51 if (!AS.CallSites.empty())
52 std::swap(CallSites, AS.CallSites);
53 } else if (!AS.CallSites.empty()) {
54 CallSites.insert(CallSites.end(), AS.CallSites.begin(), AS.CallSites.end());
55 AS.CallSites.clear();
56 }
57
58 AS.Forward = this; // Forward across AS now...
59 addRef(); // AS is now pointing to us...
60
61 // Merge the list of constituent pointers...
62 if (AS.PtrList) {
63 *PtrListEnd = AS.PtrList;
64 AS.PtrList->second.setPrevInList(PtrListEnd);
65 PtrListEnd = AS.PtrListEnd;
66
67 AS.PtrList = 0;
68 AS.PtrListEnd = &AS.PtrList;
69 assert(*AS.PtrListEnd == 0 && "End of list is not null?");
70 }
71}
72
73void AliasSetTracker::removeAliasSet(AliasSet *AS) {
74 if (AliasSet *Fwd = AS->Forward) {
75 Fwd->dropRef(*this);
76 AS->Forward = 0;
77 }
78 AliasSets.erase(AS);
79}
80
81void AliasSet::removeFromTracker(AliasSetTracker &AST) {
82 assert(RefCount == 0 && "Cannot remove non-dead alias set from tracker!");
83 AST.removeAliasSet(this);
84}
85
86void AliasSet::addPointer(AliasSetTracker &AST, HashNodePair &Entry,
87 unsigned Size, bool KnownMustAlias) {
88 assert(!Entry.second.hasAliasSet() && "Entry already in set!");
89
90 // Check to see if we have to downgrade to _may_ alias.
91 if (isMustAlias() && !KnownMustAlias)
92 if (HashNodePair *P = getSomePointer()) {
93 AliasAnalysis &AA = AST.getAliasAnalysis();
94 AliasAnalysis::AliasResult Result =
95 AA.alias(P->first, P->second.getSize(), Entry.first, Size);
96 if (Result == AliasAnalysis::MayAlias)
97 AliasTy = MayAlias;
98 else // First entry of must alias must have maximum size!
99 P->second.updateSize(Size);
100 assert(Result != AliasAnalysis::NoAlias && "Cannot be part of must set!");
101 }
102
103 Entry.second.setAliasSet(this);
104 Entry.second.updateSize(Size);
105
106 // Add it to the end of the list...
107 assert(*PtrListEnd == 0 && "End of list is not null?");
108 *PtrListEnd = &Entry;
109 PtrListEnd = Entry.second.setPrevInList(PtrListEnd);
110 assert(*PtrListEnd == 0 && "End of list is not null?");
111 addRef(); // Entry points to alias set...
112}
113
114void AliasSet::addCallSite(CallSite CS, AliasAnalysis &AA) {
115 CallSites.push_back(CS);
116
Duncan Sands00b24b52007-12-01 07:51:45 +0000117 AliasAnalysis::ModRefBehavior Behavior = AA.getModRefBehavior(CS);
118 if (Behavior == AliasAnalysis::DoesNotAccessMemory)
119 return;
120 else if (Behavior == AliasAnalysis::OnlyReadsMemory) {
121 AliasTy = MayAlias;
122 AccessTy |= Refs;
123 return;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000124 }
125
126 // FIXME: This should use mod/ref information to make this not suck so bad
127 AliasTy = MayAlias;
128 AccessTy = ModRef;
129}
130
131/// aliasesPointer - Return true if the specified pointer "may" (or must)
132/// alias one of the members in the set.
133///
134bool AliasSet::aliasesPointer(const Value *Ptr, unsigned Size,
135 AliasAnalysis &AA) const {
136 if (AliasTy == MustAlias) {
137 assert(CallSites.empty() && "Illegal must alias set!");
138
139 // If this is a set of MustAliases, only check to see if the pointer aliases
140 // SOME value in the set...
141 HashNodePair *SomePtr = getSomePointer();
142 assert(SomePtr && "Empty must-alias set??");
143 return AA.alias(SomePtr->first, SomePtr->second.getSize(), Ptr, Size);
144 }
145
146 // If this is a may-alias set, we have to check all of the pointers in the set
147 // to be sure it doesn't alias the set...
148 for (iterator I = begin(), E = end(); I != E; ++I)
149 if (AA.alias(Ptr, Size, I.getPointer(), I.getSize()))
150 return true;
151
152 // Check the call sites list and invoke list...
153 if (!CallSites.empty()) {
154 if (AA.hasNoModRefInfoForCalls())
155 return true;
156
157 for (unsigned i = 0, e = CallSites.size(); i != e; ++i)
158 if (AA.getModRefInfo(CallSites[i], const_cast<Value*>(Ptr), Size)
159 != AliasAnalysis::NoModRef)
160 return true;
161 }
162
163 return false;
164}
165
166bool AliasSet::aliasesCallSite(CallSite CS, AliasAnalysis &AA) const {
Duncan Sands00b24b52007-12-01 07:51:45 +0000167 if (AA.doesNotAccessMemory(CS))
168 return false;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000169
170 if (AA.hasNoModRefInfoForCalls())
171 return true;
172
173 for (unsigned i = 0, e = CallSites.size(); i != e; ++i)
174 if (AA.getModRefInfo(CallSites[i], CS) != AliasAnalysis::NoModRef ||
175 AA.getModRefInfo(CS, CallSites[i]) != AliasAnalysis::NoModRef)
176 return true;
177
178 for (iterator I = begin(), E = end(); I != E; ++I)
179 if (AA.getModRefInfo(CS, I.getPointer(), I.getSize()) !=
180 AliasAnalysis::NoModRef)
181 return true;
182
183 return false;
184}
185
186
187/// findAliasSetForPointer - Given a pointer, find the one alias set to put the
188/// instruction referring to the pointer into. If there are multiple alias sets
189/// that may alias the pointer, merge them together and return the unified set.
190///
191AliasSet *AliasSetTracker::findAliasSetForPointer(const Value *Ptr,
192 unsigned Size) {
193 AliasSet *FoundSet = 0;
194 for (iterator I = begin(), E = end(); I != E; ++I)
195 if (!I->Forward && I->aliasesPointer(Ptr, Size, AA)) {
196 if (FoundSet == 0) { // If this is the first alias set ptr can go into.
197 FoundSet = I; // Remember it.
198 } else { // Otherwise, we must merge the sets.
199 FoundSet->mergeSetIn(*I, *this); // Merge in contents.
200 }
201 }
202
203 return FoundSet;
204}
205
206/// containsPointer - Return true if the specified location is represented by
207/// this alias set, false otherwise. This does not modify the AST object or
208/// alias sets.
209bool AliasSetTracker::containsPointer(Value *Ptr, unsigned Size) const {
210 for (const_iterator I = begin(), E = end(); I != E; ++I)
211 if (!I->Forward && I->aliasesPointer(Ptr, Size, AA))
212 return true;
213 return false;
214}
215
216
217
218AliasSet *AliasSetTracker::findAliasSetForCallSite(CallSite CS) {
219 AliasSet *FoundSet = 0;
220 for (iterator I = begin(), E = end(); I != E; ++I)
221 if (!I->Forward && I->aliasesCallSite(CS, AA)) {
222 if (FoundSet == 0) { // If this is the first alias set ptr can go into.
223 FoundSet = I; // Remember it.
224 } else if (!I->Forward) { // Otherwise, we must merge the sets.
225 FoundSet->mergeSetIn(*I, *this); // Merge in contents.
226 }
227 }
228
229 return FoundSet;
230}
231
232
233
234
235/// getAliasSetForPointer - Return the alias set that the specified pointer
236/// lives in...
237AliasSet &AliasSetTracker::getAliasSetForPointer(Value *Pointer, unsigned Size,
238 bool *New) {
239 AliasSet::HashNodePair &Entry = getEntryFor(Pointer);
240
241 // Check to see if the pointer is already known...
242 if (Entry.second.hasAliasSet()) {
243 Entry.second.updateSize(Size);
244 // Return the set!
245 return *Entry.second.getAliasSet(*this)->getForwardedTarget(*this);
246 } else if (AliasSet *AS = findAliasSetForPointer(Pointer, Size)) {
247 // Add it to the alias set it aliases...
248 AS->addPointer(*this, Entry, Size);
249 return *AS;
250 } else {
251 if (New) *New = true;
252 // Otherwise create a new alias set to hold the loaded pointer...
253 AliasSets.push_back(new AliasSet());
254 AliasSets.back().addPointer(*this, Entry, Size);
255 return AliasSets.back();
256 }
257}
258
259bool AliasSetTracker::add(Value *Ptr, unsigned Size) {
260 bool NewPtr;
261 addPointer(Ptr, Size, AliasSet::NoModRef, NewPtr);
262 return NewPtr;
263}
264
265
266bool AliasSetTracker::add(LoadInst *LI) {
267 bool NewPtr;
268 AliasSet &AS = addPointer(LI->getOperand(0),
Duncan Sandsf99fdc62007-11-01 20:53:16 +0000269 AA.getTargetData().getTypeStoreSize(LI->getType()),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000270 AliasSet::Refs, NewPtr);
271 if (LI->isVolatile()) AS.setVolatile();
272 return NewPtr;
273}
274
275bool AliasSetTracker::add(StoreInst *SI) {
276 bool NewPtr;
277 Value *Val = SI->getOperand(0);
278 AliasSet &AS = addPointer(SI->getOperand(1),
Duncan Sandsf99fdc62007-11-01 20:53:16 +0000279 AA.getTargetData().getTypeStoreSize(Val->getType()),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000280 AliasSet::Mods, NewPtr);
281 if (SI->isVolatile()) AS.setVolatile();
282 return NewPtr;
283}
284
285bool AliasSetTracker::add(FreeInst *FI) {
286 bool NewPtr;
287 AliasSet &AS = addPointer(FI->getOperand(0), ~0,
288 AliasSet::Mods, NewPtr);
289
290 // Free operations are volatile ops (cannot be moved).
291 AS.setVolatile();
292 return NewPtr;
293}
294
Dan Gohmanddcc8562008-04-14 18:34:50 +0000295bool AliasSetTracker::add(VAArgInst *VAAI) {
296 bool NewPtr;
Chris Lattner337c1ca2008-05-20 22:05:28 +0000297 AliasSet &AS = addPointer(VAAI->getOperand(0), ~0, AliasSet::ModRef, NewPtr);
298
299 // Treat vaarg instructions as volatile (not to be moved).
300 AS.setVolatile();
Dan Gohmanddcc8562008-04-14 18:34:50 +0000301 return NewPtr;
302}
303
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000304
305bool AliasSetTracker::add(CallSite CS) {
Duncan Sands00b24b52007-12-01 07:51:45 +0000306 if (AA.doesNotAccessMemory(CS))
307 return true; // doesn't alias anything
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000308
309 AliasSet *AS = findAliasSetForCallSite(CS);
310 if (!AS) {
311 AliasSets.push_back(new AliasSet());
312 AS = &AliasSets.back();
313 AS->addCallSite(CS, AA);
314 return true;
315 } else {
316 AS->addCallSite(CS, AA);
317 return false;
318 }
319}
320
321bool AliasSetTracker::add(Instruction *I) {
322 // Dispatch to one of the other add methods...
323 if (LoadInst *LI = dyn_cast<LoadInst>(I))
324 return add(LI);
325 else if (StoreInst *SI = dyn_cast<StoreInst>(I))
326 return add(SI);
327 else if (CallInst *CI = dyn_cast<CallInst>(I))
328 return add(CI);
329 else if (InvokeInst *II = dyn_cast<InvokeInst>(I))
330 return add(II);
331 else if (FreeInst *FI = dyn_cast<FreeInst>(I))
332 return add(FI);
Dan Gohmanddcc8562008-04-14 18:34:50 +0000333 else if (VAArgInst *VAAI = dyn_cast<VAArgInst>(I))
334 return add(VAAI);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000335 return true;
336}
337
338void AliasSetTracker::add(BasicBlock &BB) {
339 for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E; ++I)
340 add(I);
341}
342
343void AliasSetTracker::add(const AliasSetTracker &AST) {
344 assert(&AA == &AST.AA &&
345 "Merging AliasSetTracker objects with different Alias Analyses!");
346
347 // Loop over all of the alias sets in AST, adding the pointers contained
348 // therein into the current alias sets. This can cause alias sets to be
349 // merged together in the current AST.
350 for (const_iterator I = AST.begin(), E = AST.end(); I != E; ++I)
351 if (!I->Forward) { // Ignore forwarding alias sets
352 AliasSet &AS = const_cast<AliasSet&>(*I);
353
354 // If there are any call sites in the alias set, add them to this AST.
355 for (unsigned i = 0, e = AS.CallSites.size(); i != e; ++i)
356 add(AS.CallSites[i]);
357
358 // Loop over all of the pointers in this alias set...
359 AliasSet::iterator I = AS.begin(), E = AS.end();
360 bool X;
361 for (; I != E; ++I) {
362 AliasSet &NewAS = addPointer(I.getPointer(), I.getSize(),
363 (AliasSet::AccessType)AS.AccessTy, X);
364 if (AS.isVolatile()) NewAS.setVolatile();
365 }
366 }
367}
368
369/// remove - Remove the specified (potentially non-empty) alias set from the
370/// tracker.
371void AliasSetTracker::remove(AliasSet &AS) {
372 // Drop all call sites.
373 AS.CallSites.clear();
374
375 // Clear the alias set.
376 unsigned NumRefs = 0;
377 while (!AS.empty()) {
378 AliasSet::HashNodePair *P = AS.PtrList;
379
380 // Unlink from the list of values.
381 P->second.removeFromList();
382
383 // Remember how many references need to be dropped.
384 ++NumRefs;
385
386 // Finally, remove the entry.
387 Value *Remove = P->first; // Take a copy because it is invalid to pass
388 PointerMap.erase(Remove); // a reference to the data being erased.
389 }
390
391 // Stop using the alias set, removing it.
392 AS.RefCount -= NumRefs;
393 if (AS.RefCount == 0)
394 AS.removeFromTracker(*this);
395}
396
397bool AliasSetTracker::remove(Value *Ptr, unsigned Size) {
398 AliasSet *AS = findAliasSetForPointer(Ptr, Size);
399 if (!AS) return false;
400 remove(*AS);
401 return true;
402}
403
404bool AliasSetTracker::remove(LoadInst *LI) {
Duncan Sandsf99fdc62007-11-01 20:53:16 +0000405 unsigned Size = AA.getTargetData().getTypeStoreSize(LI->getType());
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000406 AliasSet *AS = findAliasSetForPointer(LI->getOperand(0), Size);
407 if (!AS) return false;
408 remove(*AS);
409 return true;
410}
411
412bool AliasSetTracker::remove(StoreInst *SI) {
Duncan Sandsf99fdc62007-11-01 20:53:16 +0000413 unsigned Size =
414 AA.getTargetData().getTypeStoreSize(SI->getOperand(0)->getType());
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000415 AliasSet *AS = findAliasSetForPointer(SI->getOperand(1), Size);
416 if (!AS) return false;
417 remove(*AS);
418 return true;
419}
420
421bool AliasSetTracker::remove(FreeInst *FI) {
422 AliasSet *AS = findAliasSetForPointer(FI->getOperand(0), ~0);
423 if (!AS) return false;
424 remove(*AS);
425 return true;
426}
427
Dan Gohmanddcc8562008-04-14 18:34:50 +0000428bool AliasSetTracker::remove(VAArgInst *VAAI) {
429 AliasSet *AS = findAliasSetForPointer(VAAI->getOperand(0), ~0);
430 if (!AS) return false;
431 remove(*AS);
432 return true;
433}
434
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000435bool AliasSetTracker::remove(CallSite CS) {
Duncan Sands00b24b52007-12-01 07:51:45 +0000436 if (AA.doesNotAccessMemory(CS))
437 return false; // doesn't alias anything
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000438
439 AliasSet *AS = findAliasSetForCallSite(CS);
440 if (!AS) return false;
441 remove(*AS);
442 return true;
443}
444
445bool AliasSetTracker::remove(Instruction *I) {
446 // Dispatch to one of the other remove methods...
447 if (LoadInst *LI = dyn_cast<LoadInst>(I))
448 return remove(LI);
449 else if (StoreInst *SI = dyn_cast<StoreInst>(I))
450 return remove(SI);
451 else if (CallInst *CI = dyn_cast<CallInst>(I))
452 return remove(CI);
453 else if (FreeInst *FI = dyn_cast<FreeInst>(I))
454 return remove(FI);
Dan Gohmanddcc8562008-04-14 18:34:50 +0000455 else if (VAArgInst *VAAI = dyn_cast<VAArgInst>(I))
456 return remove(VAAI);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000457 return true;
458}
459
460
461// deleteValue method - This method is used to remove a pointer value from the
462// AliasSetTracker entirely. It should be used when an instruction is deleted
463// from the program to update the AST. If you don't use this, you would have
464// dangling pointers to deleted instructions.
465//
466void AliasSetTracker::deleteValue(Value *PtrVal) {
467 // Notify the alias analysis implementation that this value is gone.
468 AA.deleteValue(PtrVal);
469
470 // If this is a call instruction, remove the callsite from the appropriate
471 // AliasSet.
472 CallSite CS = CallSite::get(PtrVal);
Duncan Sands00b24b52007-12-01 07:51:45 +0000473 if (CS.getInstruction())
474 if (!AA.doesNotAccessMemory(CS))
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000475 if (AliasSet *AS = findAliasSetForCallSite(CS))
476 AS->removeCallSite(CS);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000477
478 // First, look up the PointerRec for this pointer.
479 hash_map<Value*, AliasSet::PointerRec>::iterator I = PointerMap.find(PtrVal);
480 if (I == PointerMap.end()) return; // Noop
481
482 // If we found one, remove the pointer from the alias set it is in.
483 AliasSet::HashNodePair &PtrValEnt = *I;
484 AliasSet *AS = PtrValEnt.second.getAliasSet(*this);
485
486 // Unlink from the list of values...
487 PtrValEnt.second.removeFromList();
488 // Stop using the alias set
489 AS->dropRef(*this);
490 PointerMap.erase(I);
491}
492
493// copyValue - This method should be used whenever a preexisting value in the
494// program is copied or cloned, introducing a new value. Note that it is ok for
495// clients that use this method to introduce the same value multiple times: if
496// the tracker already knows about a value, it will ignore the request.
497//
498void AliasSetTracker::copyValue(Value *From, Value *To) {
499 // Notify the alias analysis implementation that this value is copied.
500 AA.copyValue(From, To);
501
502 // First, look up the PointerRec for this pointer.
503 hash_map<Value*, AliasSet::PointerRec>::iterator I = PointerMap.find(From);
504 if (I == PointerMap.end() || !I->second.hasAliasSet())
505 return; // Noop
506
507 AliasSet::HashNodePair &Entry = getEntryFor(To);
508 if (Entry.second.hasAliasSet()) return; // Already in the tracker!
509
510 // Add it to the alias set it aliases...
511 AliasSet *AS = I->second.getAliasSet(*this);
512 AS->addPointer(*this, Entry, I->second.getSize(), true);
513}
514
515
516
517//===----------------------------------------------------------------------===//
518// AliasSet/AliasSetTracker Printing Support
519//===----------------------------------------------------------------------===//
520
521void AliasSet::print(std::ostream &OS) const {
522 OS << " AliasSet[" << (void*)this << "," << RefCount << "] ";
Dan Gohmancbec0762008-04-21 19:48:48 +0000523 OS << (AliasTy == MustAlias ? "must" : "may") << " alias, ";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000524 switch (AccessTy) {
525 case NoModRef: OS << "No access "; break;
526 case Refs : OS << "Ref "; break;
527 case Mods : OS << "Mod "; break;
528 case ModRef : OS << "Mod/Ref "; break;
529 default: assert(0 && "Bad value for AccessTy!");
530 }
531 if (isVolatile()) OS << "[volatile] ";
532 if (Forward)
533 OS << " forwarding to " << (void*)Forward;
534
535
Dan Gohman3f7d94b2007-10-03 19:26:29 +0000536 if (!empty()) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000537 OS << "Pointers: ";
538 for (iterator I = begin(), E = end(); I != E; ++I) {
539 if (I != begin()) OS << ", ";
540 WriteAsOperand(OS << "(", I.getPointer());
541 OS << ", " << I.getSize() << ")";
542 }
543 }
544 if (!CallSites.empty()) {
545 OS << "\n " << CallSites.size() << " Call Sites: ";
546 for (unsigned i = 0, e = CallSites.size(); i != e; ++i) {
547 if (i) OS << ", ";
548 WriteAsOperand(OS, CallSites[i].getCalledValue());
549 }
550 }
551 OS << "\n";
552}
553
554void AliasSetTracker::print(std::ostream &OS) const {
555 OS << "Alias Set Tracker: " << AliasSets.size() << " alias sets for "
556 << PointerMap.size() << " pointer values.\n";
557 for (const_iterator I = begin(), E = end(); I != E; ++I)
558 I->print(OS);
559 OS << "\n";
560}
561
562void AliasSet::dump() const { print (cerr); }
563void AliasSetTracker::dump() const { print(cerr); }
564
565//===----------------------------------------------------------------------===//
566// AliasSetPrinter Pass
567//===----------------------------------------------------------------------===//
568
569namespace {
570 class VISIBILITY_HIDDEN AliasSetPrinter : public FunctionPass {
571 AliasSetTracker *Tracker;
572 public:
573 static char ID; // Pass identification, replacement for typeid
Devang Patel3aab76e2008-03-19 21:56:59 +0000574 AliasSetPrinter() : FunctionPass((intptr_t)&ID) {}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000575
576 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
577 AU.setPreservesAll();
578 AU.addRequired<AliasAnalysis>();
579 }
580
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000581 virtual bool runOnFunction(Function &F) {
582 Tracker = new AliasSetTracker(getAnalysis<AliasAnalysis>());
583
584 for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I)
585 Tracker->add(&*I);
586 Tracker->print(cerr);
587 delete Tracker;
588 return false;
589 }
590 };
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000591}
Dan Gohman089efff2008-05-13 00:00:25 +0000592
593char AliasSetPrinter::ID = 0;
594static RegisterPass<AliasSetPrinter>
595X("print-alias-sets", "Alias Set Printer", false, true);