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