Minor simplification.
[oota-llvm.git] / lib / Analysis / AliasSetTracker.cpp
1 //===- AliasSetTracker.cpp - Alias Sets Tracker implementation-------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
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/IntrinsicInst.h"
18 #include "llvm/LLVMContext.h"
19 #include "llvm/Pass.h"
20 #include "llvm/Type.h"
21 #include "llvm/Target/TargetData.h"
22 #include "llvm/Assembly/Writer.h"
23 #include "llvm/Support/Debug.h"
24 #include "llvm/Support/ErrorHandling.h"
25 #include "llvm/Support/InstIterator.h"
26 #include "llvm/Support/raw_ostream.h"
27 using namespace llvm;
28
29 /// mergeSetIn - Merge the specified alias set into this alias set.
30 ///
31 void AliasSet::mergeSetIn(AliasSet &AS, AliasSetTracker &AST) {
32   assert(!AS.Forward && "Alias set is already forwarding!");
33   assert(!Forward && "This set is a forwarding set!!");
34
35   // Update the alias and access types of this set...
36   AccessTy |= AS.AccessTy;
37   AliasTy  |= AS.AliasTy;
38   Volatile |= AS.Volatile;
39
40   if (AliasTy == MustAlias) {
41     // Check that these two merged sets really are must aliases.  Since both
42     // used to be must-alias sets, we can just check any pointer from each set
43     // for aliasing.
44     AliasAnalysis &AA = AST.getAliasAnalysis();
45     PointerRec *L = getSomePointer();
46     PointerRec *R = AS.getSomePointer();
47
48     // If the pointers are not a must-alias pair, this set becomes a may alias.
49     if (AA.alias(AliasAnalysis::Location(L->getValue(),
50                                          L->getSize(),
51                                          L->getTBAAInfo()),
52                  AliasAnalysis::Location(R->getValue(),
53                                          R->getSize(),
54                                          R->getTBAAInfo()))
55         != AliasAnalysis::MustAlias)
56       AliasTy = MayAlias;
57   }
58
59   if (UnknownInsts.empty()) {            // Merge call sites...
60     if (!AS.UnknownInsts.empty())
61       std::swap(UnknownInsts, AS.UnknownInsts);
62   } else if (!AS.UnknownInsts.empty()) {
63     UnknownInsts.insert(UnknownInsts.end(), AS.UnknownInsts.begin(), AS.UnknownInsts.end());
64     AS.UnknownInsts.clear();
65   }
66
67   AS.Forward = this;  // Forward across AS now...
68   addRef();           // AS is now pointing to us...
69
70   // Merge the list of constituent pointers...
71   if (AS.PtrList) {
72     *PtrListEnd = AS.PtrList;
73     AS.PtrList->setPrevInList(PtrListEnd);
74     PtrListEnd = AS.PtrListEnd;
75
76     AS.PtrList = 0;
77     AS.PtrListEnd = &AS.PtrList;
78     assert(*AS.PtrListEnd == 0 && "End of list is not null?");
79   }
80 }
81
82 void AliasSetTracker::removeAliasSet(AliasSet *AS) {
83   if (AliasSet *Fwd = AS->Forward) {
84     Fwd->dropRef(*this);
85     AS->Forward = 0;
86   }
87   AliasSets.erase(AS);
88 }
89
90 void AliasSet::removeFromTracker(AliasSetTracker &AST) {
91   assert(RefCount == 0 && "Cannot remove non-dead alias set from tracker!");
92   AST.removeAliasSet(this);
93 }
94
95 void AliasSet::addPointer(AliasSetTracker &AST, PointerRec &Entry,
96                           uint64_t Size, const MDNode *TBAAInfo,
97                           bool KnownMustAlias) {
98   assert(!Entry.hasAliasSet() && "Entry already in set!");
99
100   // Check to see if we have to downgrade to _may_ alias.
101   if (isMustAlias() && !KnownMustAlias)
102     if (PointerRec *P = getSomePointer()) {
103       AliasAnalysis &AA = AST.getAliasAnalysis();
104       AliasAnalysis::AliasResult Result =
105         AA.alias(AliasAnalysis::Location(P->getValue(), P->getSize(),
106                                          P->getTBAAInfo()),
107                  AliasAnalysis::Location(Entry.getValue(), Size, TBAAInfo));
108       if (Result != AliasAnalysis::MustAlias)
109         AliasTy = MayAlias;
110       else                  // First entry of must alias must have maximum size!
111         P->updateSizeAndTBAAInfo(Size, TBAAInfo);
112       assert(Result != AliasAnalysis::NoAlias && "Cannot be part of must set!");
113     }
114
115   Entry.setAliasSet(this);
116   Entry.updateSizeAndTBAAInfo(Size, TBAAInfo);
117
118   // Add it to the end of the list...
119   assert(*PtrListEnd == 0 && "End of list is not null?");
120   *PtrListEnd = &Entry;
121   PtrListEnd = Entry.setPrevInList(PtrListEnd);
122   assert(*PtrListEnd == 0 && "End of list is not null?");
123   addRef();               // Entry points to alias set.
124 }
125
126 void AliasSet::addUnknownInst(Instruction *I, AliasAnalysis &AA) {
127   UnknownInsts.push_back(I);
128
129   if (!I->mayReadOrWriteMemory())
130     return;
131   if (!I->mayWriteToMemory()) {
132     AliasTy = MayAlias;
133     AccessTy |= Refs;
134     return;
135   }
136
137   // FIXME: This should use mod/ref information to make this not suck so bad
138   AliasTy = MayAlias;
139   AccessTy = ModRef;
140 }
141
142 /// aliasesPointer - Return true if the specified pointer "may" (or must)
143 /// alias one of the members in the set.
144 ///
145 bool AliasSet::aliasesPointer(const Value *Ptr, uint64_t Size,
146                               const MDNode *TBAAInfo,
147                               AliasAnalysis &AA) const {
148   if (AliasTy == MustAlias) {
149     assert(UnknownInsts.empty() && "Illegal must alias set!");
150
151     // If this is a set of MustAliases, only check to see if the pointer aliases
152     // SOME value in the set.
153     PointerRec *SomePtr = getSomePointer();
154     assert(SomePtr && "Empty must-alias set??");
155     return AA.alias(AliasAnalysis::Location(SomePtr->getValue(),
156                                             SomePtr->getSize(),
157                                             SomePtr->getTBAAInfo()),
158                     AliasAnalysis::Location(Ptr, Size, TBAAInfo));
159   }
160
161   // If this is a may-alias set, we have to check all of the pointers in the set
162   // to be sure it doesn't alias the set...
163   for (iterator I = begin(), E = end(); I != E; ++I)
164     if (AA.alias(AliasAnalysis::Location(Ptr, Size, TBAAInfo),
165                  AliasAnalysis::Location(I.getPointer(), I.getSize(),
166                                          I.getTBAAInfo())))
167       return true;
168
169   // Check the unknown instructions...
170   if (!UnknownInsts.empty()) {
171     for (unsigned i = 0, e = UnknownInsts.size(); i != e; ++i)
172       if (AA.getModRefInfo(UnknownInsts[i],
173                            AliasAnalysis::Location(Ptr, Size, TBAAInfo)) !=
174             AliasAnalysis::NoModRef)
175         return true;
176   }
177
178   return false;
179 }
180
181 bool AliasSet::aliasesUnknownInst(Instruction *Inst, AliasAnalysis &AA) const {
182   if (!Inst->mayReadOrWriteMemory())
183     return false;
184
185   for (unsigned i = 0, e = UnknownInsts.size(); i != e; ++i) {
186     CallSite C1 = getUnknownInst(i), C2 = Inst;
187     if (!C1 || !C2 ||
188         AA.getModRefInfo(C1, C2) != AliasAnalysis::NoModRef ||
189         AA.getModRefInfo(C2, C1) != AliasAnalysis::NoModRef)
190       return true;
191   }
192
193   for (iterator I = begin(), E = end(); I != E; ++I)
194     if (AA.getModRefInfo(Inst, I.getPointer(), I.getSize()) !=
195            AliasAnalysis::NoModRef)
196       return true;
197
198   return false;
199 }
200
201 void AliasSetTracker::clear() {
202   // Delete all the PointerRec entries.
203   for (PointerMapType::iterator I = PointerMap.begin(), E = PointerMap.end();
204        I != E; ++I)
205     I->second->eraseFromList();
206   
207   PointerMap.clear();
208   
209   // The alias sets should all be clear now.
210   AliasSets.clear();
211 }
212
213
214 /// findAliasSetForPointer - Given a pointer, find the one alias set to put the
215 /// instruction referring to the pointer into.  If there are multiple alias sets
216 /// that may alias the pointer, merge them together and return the unified set.
217 ///
218 AliasSet *AliasSetTracker::findAliasSetForPointer(const Value *Ptr,
219                                                   uint64_t Size,
220                                                   const MDNode *TBAAInfo) {
221   AliasSet *FoundSet = 0;
222   for (iterator I = begin(), E = end(); I != E; ++I) {
223     if (I->Forward || !I->aliasesPointer(Ptr, Size, TBAAInfo, AA)) continue;
224     
225     if (FoundSet == 0) {  // If this is the first alias set ptr can go into.
226       FoundSet = I;       // Remember it.
227     } else {              // Otherwise, we must merge the sets.
228       FoundSet->mergeSetIn(*I, *this);     // Merge in contents.
229     }
230   }
231
232   return FoundSet;
233 }
234
235 /// containsPointer - Return true if the specified location is represented by
236 /// this alias set, false otherwise.  This does not modify the AST object or
237 /// alias sets.
238 bool AliasSetTracker::containsPointer(Value *Ptr, uint64_t Size,
239                                       const MDNode *TBAAInfo) const {
240   for (const_iterator I = begin(), E = end(); I != E; ++I)
241     if (!I->Forward && I->aliasesPointer(Ptr, Size, TBAAInfo, AA))
242       return true;
243   return false;
244 }
245
246
247
248 AliasSet *AliasSetTracker::findAliasSetForUnknownInst(Instruction *Inst) {
249   AliasSet *FoundSet = 0;
250   for (iterator I = begin(), E = end(); I != E; ++I) {
251     if (I->Forward || !I->aliasesUnknownInst(Inst, AA))
252       continue;
253     
254     if (FoundSet == 0)        // If this is the first alias set ptr can go into.
255       FoundSet = I;           // Remember it.
256     else if (!I->Forward)     // Otherwise, we must merge the sets.
257       FoundSet->mergeSetIn(*I, *this);     // Merge in contents.
258   }
259   return FoundSet;
260 }
261
262
263
264
265 /// getAliasSetForPointer - Return the alias set that the specified pointer
266 /// lives in.
267 AliasSet &AliasSetTracker::getAliasSetForPointer(Value *Pointer, uint64_t Size,
268                                                  const MDNode *TBAAInfo,
269                                                  bool *New) {
270   AliasSet::PointerRec &Entry = getEntryFor(Pointer);
271
272   // Check to see if the pointer is already known.
273   if (Entry.hasAliasSet()) {
274     Entry.updateSizeAndTBAAInfo(Size, TBAAInfo);
275     // Return the set!
276     return *Entry.getAliasSet(*this)->getForwardedTarget(*this);
277   }
278   
279   if (AliasSet *AS = findAliasSetForPointer(Pointer, Size, TBAAInfo)) {
280     // Add it to the alias set it aliases.
281     AS->addPointer(*this, Entry, Size, TBAAInfo);
282     return *AS;
283   }
284   
285   if (New) *New = true;
286   // Otherwise create a new alias set to hold the loaded pointer.
287   AliasSets.push_back(new AliasSet());
288   AliasSets.back().addPointer(*this, Entry, Size, TBAAInfo);
289   return AliasSets.back();
290 }
291
292 bool AliasSetTracker::add(Value *Ptr, uint64_t Size, const MDNode *TBAAInfo) {
293   bool NewPtr;
294   addPointer(Ptr, Size, TBAAInfo, AliasSet::NoModRef, NewPtr);
295   return NewPtr;
296 }
297
298
299 bool AliasSetTracker::add(LoadInst *LI) {
300   bool NewPtr;
301   AliasSet &AS = addPointer(LI->getOperand(0),
302                             AA.getTypeStoreSize(LI->getType()),
303                             LI->getMetadata(LLVMContext::MD_tbaa),
304                             AliasSet::Refs, NewPtr);
305   if (LI->isVolatile()) AS.setVolatile();
306   return NewPtr;
307 }
308
309 bool AliasSetTracker::add(StoreInst *SI) {
310   bool NewPtr;
311   Value *Val = SI->getOperand(0);
312   AliasSet &AS = addPointer(SI->getOperand(1),
313                             AA.getTypeStoreSize(Val->getType()),
314                             SI->getMetadata(LLVMContext::MD_tbaa),
315                             AliasSet::Mods, NewPtr);
316   if (SI->isVolatile()) AS.setVolatile();
317   return NewPtr;
318 }
319
320 bool AliasSetTracker::add(VAArgInst *VAAI) {
321   bool NewPtr;
322   addPointer(VAAI->getOperand(0), AliasAnalysis::UnknownSize, 
323              VAAI->getMetadata(LLVMContext::MD_tbaa),
324              AliasSet::ModRef, NewPtr);
325   return NewPtr;
326 }
327
328
329 bool AliasSetTracker::addUnknown(Instruction *Inst) {
330   if (isa<DbgInfoIntrinsic>(Inst)) 
331     return true; // Ignore DbgInfo Intrinsics.
332   if (!Inst->mayReadOrWriteMemory())
333     return true; // doesn't alias anything
334
335   AliasSet *AS = findAliasSetForUnknownInst(Inst);
336   if (AS) {
337     AS->addUnknownInst(Inst, AA);
338     return false;
339   }
340   AliasSets.push_back(new AliasSet());
341   AS = &AliasSets.back();
342   AS->addUnknownInst(Inst, AA);
343   return true;
344 }
345
346 bool AliasSetTracker::add(Instruction *I) {
347   // Dispatch to one of the other add methods.
348   if (LoadInst *LI = dyn_cast<LoadInst>(I))
349     return add(LI);
350   if (StoreInst *SI = dyn_cast<StoreInst>(I))
351     return add(SI);
352   if (VAArgInst *VAAI = dyn_cast<VAArgInst>(I))
353     return add(VAAI);
354   return addUnknown(I);
355 }
356
357 void AliasSetTracker::add(BasicBlock &BB) {
358   for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E; ++I)
359     add(I);
360 }
361
362 void AliasSetTracker::add(const AliasSetTracker &AST) {
363   assert(&AA == &AST.AA &&
364          "Merging AliasSetTracker objects with different Alias Analyses!");
365
366   // Loop over all of the alias sets in AST, adding the pointers contained
367   // therein into the current alias sets.  This can cause alias sets to be
368   // merged together in the current AST.
369   for (const_iterator I = AST.begin(), E = AST.end(); I != E; ++I) {
370     if (I->Forward) continue;   // Ignore forwarding alias sets
371     
372     AliasSet &AS = const_cast<AliasSet&>(*I);
373
374     // If there are any call sites in the alias set, add them to this AST.
375     for (unsigned i = 0, e = AS.UnknownInsts.size(); i != e; ++i)
376       add(AS.UnknownInsts[i]);
377
378     // Loop over all of the pointers in this alias set.
379     bool X;
380     for (AliasSet::iterator ASI = AS.begin(), E = AS.end(); ASI != E; ++ASI) {
381       AliasSet &NewAS = addPointer(ASI.getPointer(), ASI.getSize(),
382                                    ASI.getTBAAInfo(),
383                                    (AliasSet::AccessType)AS.AccessTy, X);
384       if (AS.isVolatile()) NewAS.setVolatile();
385     }
386   }
387 }
388
389 /// remove - Remove the specified (potentially non-empty) alias set from the
390 /// tracker.
391 void AliasSetTracker::remove(AliasSet &AS) {
392   // Drop all call sites.
393   AS.UnknownInsts.clear();
394   
395   // Clear the alias set.
396   unsigned NumRefs = 0;
397   while (!AS.empty()) {
398     AliasSet::PointerRec *P = AS.PtrList;
399
400     Value *ValToRemove = P->getValue();
401     
402     // Unlink and delete entry from the list of values.
403     P->eraseFromList();
404     
405     // Remember how many references need to be dropped.
406     ++NumRefs;
407
408     // Finally, remove the entry.
409     PointerMap.erase(ValToRemove);
410   }
411   
412   // Stop using the alias set, removing it.
413   AS.RefCount -= NumRefs;
414   if (AS.RefCount == 0)
415     AS.removeFromTracker(*this);
416 }
417
418 bool
419 AliasSetTracker::remove(Value *Ptr, uint64_t Size, const MDNode *TBAAInfo) {
420   AliasSet *AS = findAliasSetForPointer(Ptr, Size, TBAAInfo);
421   if (!AS) return false;
422   remove(*AS);
423   return true;
424 }
425
426 bool AliasSetTracker::remove(LoadInst *LI) {
427   uint64_t Size = AA.getTypeStoreSize(LI->getType());
428   const MDNode *TBAAInfo = LI->getMetadata(LLVMContext::MD_tbaa);
429   AliasSet *AS = findAliasSetForPointer(LI->getOperand(0), Size, TBAAInfo);
430   if (!AS) return false;
431   remove(*AS);
432   return true;
433 }
434
435 bool AliasSetTracker::remove(StoreInst *SI) {
436   uint64_t Size = AA.getTypeStoreSize(SI->getOperand(0)->getType());
437   const MDNode *TBAAInfo = SI->getMetadata(LLVMContext::MD_tbaa);
438   AliasSet *AS = findAliasSetForPointer(SI->getOperand(1), Size, TBAAInfo);
439   if (!AS) return false;
440   remove(*AS);
441   return true;
442 }
443
444 bool AliasSetTracker::remove(VAArgInst *VAAI) {
445   AliasSet *AS = findAliasSetForPointer(VAAI->getOperand(0),
446                                         AliasAnalysis::UnknownSize,
447                                         VAAI->getMetadata(LLVMContext::MD_tbaa));
448   if (!AS) return false;
449   remove(*AS);
450   return true;
451 }
452
453 bool AliasSetTracker::removeUnknown(Instruction *I) {
454   if (!I->mayReadOrWriteMemory())
455     return false; // doesn't alias anything
456
457   AliasSet *AS = findAliasSetForUnknownInst(I);
458   if (!AS) return false;
459   remove(*AS);
460   return true;
461 }
462
463 bool AliasSetTracker::remove(Instruction *I) {
464   // Dispatch to one of the other remove methods...
465   if (LoadInst *LI = dyn_cast<LoadInst>(I))
466     return remove(LI);
467   if (StoreInst *SI = dyn_cast<StoreInst>(I))
468     return remove(SI);
469   if (VAArgInst *VAAI = dyn_cast<VAArgInst>(I))
470     return remove(VAAI);
471   return removeUnknown(I);
472 }
473
474
475 // deleteValue method - This method is used to remove a pointer value from the
476 // AliasSetTracker entirely.  It should be used when an instruction is deleted
477 // from the program to update the AST.  If you don't use this, you would have
478 // dangling pointers to deleted instructions.
479 //
480 void AliasSetTracker::deleteValue(Value *PtrVal) {
481   // Notify the alias analysis implementation that this value is gone.
482   AA.deleteValue(PtrVal);
483
484   // If this is a call instruction, remove the callsite from the appropriate
485   // AliasSet (if present).
486   if (Instruction *Inst = dyn_cast<Instruction>(PtrVal)) {
487     if (Inst->mayReadOrWriteMemory()) {
488       // Scan all the alias sets to see if this call site is contained.
489       for (iterator I = begin(), E = end(); I != E; ++I) {
490         if (I->Forward) continue;
491         
492         I->removeUnknownInst(Inst);
493       }
494     }
495   }
496
497   // First, look up the PointerRec for this pointer.
498   PointerMapType::iterator I = PointerMap.find(PtrVal);
499   if (I == PointerMap.end()) return;  // Noop
500
501   // If we found one, remove the pointer from the alias set it is in.
502   AliasSet::PointerRec *PtrValEnt = I->second;
503   AliasSet *AS = PtrValEnt->getAliasSet(*this);
504
505   // Unlink and delete from the list of values.
506   PtrValEnt->eraseFromList();
507   
508   // Stop using the alias set.
509   AS->dropRef(*this);
510   
511   PointerMap.erase(I);
512 }
513
514 // copyValue - This method should be used whenever a preexisting value in the
515 // program is copied or cloned, introducing a new value.  Note that it is ok for
516 // clients that use this method to introduce the same value multiple times: if
517 // the tracker already knows about a value, it will ignore the request.
518 //
519 void AliasSetTracker::copyValue(Value *From, Value *To) {
520   // Notify the alias analysis implementation that this value is copied.
521   AA.copyValue(From, To);
522
523   // First, look up the PointerRec for this pointer.
524   PointerMapType::iterator I = PointerMap.find(From);
525   if (I == PointerMap.end())
526     return;  // Noop
527   assert(I->second->hasAliasSet() && "Dead entry?");
528
529   AliasSet::PointerRec &Entry = getEntryFor(To);
530   if (Entry.hasAliasSet()) return;    // Already in the tracker!
531
532   // Add it to the alias set it aliases...
533   I = PointerMap.find(From);
534   AliasSet *AS = I->second->getAliasSet(*this);
535   AS->addPointer(*this, Entry, I->second->getSize(),
536                  I->second->getTBAAInfo(),
537                  true);
538 }
539
540
541
542 //===----------------------------------------------------------------------===//
543 //               AliasSet/AliasSetTracker Printing Support
544 //===----------------------------------------------------------------------===//
545
546 void AliasSet::print(raw_ostream &OS) const {
547   OS << "  AliasSet[" << (void*)this << ", " << RefCount << "] ";
548   OS << (AliasTy == MustAlias ? "must" : "may") << " alias, ";
549   switch (AccessTy) {
550   case NoModRef: OS << "No access "; break;
551   case Refs    : OS << "Ref       "; break;
552   case Mods    : OS << "Mod       "; break;
553   case ModRef  : OS << "Mod/Ref   "; break;
554   default: llvm_unreachable("Bad value for AccessTy!");
555   }
556   if (isVolatile()) OS << "[volatile] ";
557   if (Forward)
558     OS << " forwarding to " << (void*)Forward;
559
560
561   if (!empty()) {
562     OS << "Pointers: ";
563     for (iterator I = begin(), E = end(); I != E; ++I) {
564       if (I != begin()) OS << ", ";
565       WriteAsOperand(OS << "(", I.getPointer());
566       OS << ", " << I.getSize() << ")";
567     }
568   }
569   if (!UnknownInsts.empty()) {
570     OS << "\n    " << UnknownInsts.size() << " Unknown instructions: ";
571     for (unsigned i = 0, e = UnknownInsts.size(); i != e; ++i) {
572       if (i) OS << ", ";
573       WriteAsOperand(OS, UnknownInsts[i]);
574     }
575   }
576   OS << "\n";
577 }
578
579 void AliasSetTracker::print(raw_ostream &OS) const {
580   OS << "Alias Set Tracker: " << AliasSets.size() << " alias sets for "
581      << PointerMap.size() << " pointer values.\n";
582   for (const_iterator I = begin(), E = end(); I != E; ++I)
583     I->print(OS);
584   OS << "\n";
585 }
586
587 void AliasSet::dump() const { print(dbgs()); }
588 void AliasSetTracker::dump() const { print(dbgs()); }
589
590 //===----------------------------------------------------------------------===//
591 //                     ASTCallbackVH Class Implementation
592 //===----------------------------------------------------------------------===//
593
594 void AliasSetTracker::ASTCallbackVH::deleted() {
595   assert(AST && "ASTCallbackVH called with a null AliasSetTracker!");
596   AST->deleteValue(getValPtr());
597   // this now dangles!
598 }
599
600 void AliasSetTracker::ASTCallbackVH::allUsesReplacedWith(Value *V) {
601   AST->copyValue(getValPtr(), V);
602 }
603
604 AliasSetTracker::ASTCallbackVH::ASTCallbackVH(Value *V, AliasSetTracker *ast)
605   : CallbackVH(V), AST(ast) {}
606
607 AliasSetTracker::ASTCallbackVH &
608 AliasSetTracker::ASTCallbackVH::operator=(Value *V) {
609   return *this = ASTCallbackVH(V, AST);
610 }
611
612 //===----------------------------------------------------------------------===//
613 //                            AliasSetPrinter Pass
614 //===----------------------------------------------------------------------===//
615
616 namespace {
617   class AliasSetPrinter : public FunctionPass {
618     AliasSetTracker *Tracker;
619   public:
620     static char ID; // Pass identification, replacement for typeid
621     AliasSetPrinter() : FunctionPass(ID) {
622       initializeAliasSetPrinterPass(*PassRegistry::getPassRegistry());
623     }
624
625     virtual void getAnalysisUsage(AnalysisUsage &AU) const {
626       AU.setPreservesAll();
627       AU.addRequired<AliasAnalysis>();
628     }
629
630     virtual bool runOnFunction(Function &F) {
631       Tracker = new AliasSetTracker(getAnalysis<AliasAnalysis>());
632
633       for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I)
634         Tracker->add(&*I);
635       Tracker->print(errs());
636       delete Tracker;
637       return false;
638     }
639   };
640 }
641
642 char AliasSetPrinter::ID = 0;
643 INITIALIZE_PASS_BEGIN(AliasSetPrinter, "print-alias-sets",
644                 "Alias Set Printer", false, true)
645 INITIALIZE_AG_DEPENDENCY(AliasAnalysis)
646 INITIALIZE_PASS_END(AliasSetPrinter, "print-alias-sets",
647                 "Alias Set Printer", false, true)