blob: 9d941e557978c6183e4b7f5e14496c102ad99976 [file] [log] [blame]
Chris Lattner647df642002-09-26 21:49:07 +00001//===- AliasSetTracker.cpp - Alias Sets Tracker implementation-------------===//
Misha Brukman01808ca2005-04-21 21:13:18 +00002//
John Criswell482202a2003-10-20 19:43:21 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukman01808ca2005-04-21 21:13:18 +00007//
John Criswell482202a2003-10-20 19:43:21 +00008//===----------------------------------------------------------------------===//
Chris Lattner647df642002-09-26 21:49:07 +00009//
10// This file implements the AliasSetTracker and AliasSet classes.
Misha Brukman01808ca2005-04-21 21:13:18 +000011//
Chris Lattner647df642002-09-26 21:49:07 +000012//===----------------------------------------------------------------------===//
13
14#include "llvm/Analysis/AliasSetTracker.h"
15#include "llvm/Analysis/AliasAnalysis.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000016#include "llvm/IR/DataLayout.h"
Chandler Carruth83948572014-03-04 10:30:26 +000017#include "llvm/IR/InstIterator.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000018#include "llvm/IR/Instructions.h"
19#include "llvm/IR/IntrinsicInst.h"
20#include "llvm/IR/LLVMContext.h"
21#include "llvm/IR/Type.h"
Chris Lattner7606fb62003-02-24 20:37:56 +000022#include "llvm/Pass.h"
David Greene2ec90032009-12-23 19:27:59 +000023#include "llvm/Support/Debug.h"
Torok Edwin56d06592009-07-11 20:10:48 +000024#include "llvm/Support/ErrorHandling.h"
Chris Lattnerb1d782b2009-08-23 05:17:37 +000025#include "llvm/Support/raw_ostream.h"
Chris Lattner0a140602003-12-14 04:52:11 +000026using namespace llvm;
Brian Gaeke960707c2003-11-11 22:41:34 +000027
Chris Lattner24bba4d2004-11-27 18:37:42 +000028/// mergeSetIn - Merge the specified alias set into this alias set.
Chris Lattner647df642002-09-26 21:49:07 +000029///
Chris Lattner24bba4d2004-11-27 18:37:42 +000030void AliasSet::mergeSetIn(AliasSet &AS, AliasSetTracker &AST) {
Chris Lattner7606fb62003-02-24 20:37:56 +000031 assert(!AS.Forward && "Alias set is already forwarding!");
32 assert(!Forward && "This set is a forwarding set!!");
Chris Lattner647df642002-09-26 21:49:07 +000033
34 // Update the alias and access types of this set...
Chris Lattner7606fb62003-02-24 20:37:56 +000035 AccessTy |= AS.AccessTy;
36 AliasTy |= AS.AliasTy;
Chris Lattnerdc8070e2010-08-29 04:14:47 +000037 Volatile |= AS.Volatile;
Chris Lattner7606fb62003-02-24 20:37:56 +000038
Chris Lattner24bba4d2004-11-27 18:37:42 +000039 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();
Chris Lattner0eab5ec2009-03-09 05:11:09 +000044 PointerRec *L = getSomePointer();
45 PointerRec *R = AS.getSomePointer();
Chris Lattner24bba4d2004-11-27 18:37:42 +000046
47 // If the pointers are not a must-alias pair, this set becomes a may alias.
Dan Gohman46863882010-11-11 21:27:26 +000048 if (AA.alias(AliasAnalysis::Location(L->getValue(),
49 L->getSize(),
Hal Finkelcc39b672014-07-24 12:16:19 +000050 L->getAAInfo()),
Dan Gohman46863882010-11-11 21:27:26 +000051 AliasAnalysis::Location(R->getValue(),
52 R->getSize(),
Hal Finkelcc39b672014-07-24 12:16:19 +000053 R->getAAInfo()))
Chris Lattner24bba4d2004-11-27 18:37:42 +000054 != AliasAnalysis::MustAlias)
55 AliasTy = MayAlias;
56 }
57
Eli Friedmanae8161e2011-07-27 00:46:46 +000058 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();
Chris Lattner7606fb62003-02-24 20:37:56 +000064 }
Misha Brukman01808ca2005-04-21 21:13:18 +000065
Chris Lattner7606fb62003-02-24 20:37:56 +000066 AS.Forward = this; // Forward across AS now...
Chris Lattner053427f2004-07-22 07:58:18 +000067 addRef(); // AS is now pointing to us...
Chris Lattner7606fb62003-02-24 20:37:56 +000068
69 // Merge the list of constituent pointers...
Chris Lattner44fea542003-12-18 08:11:56 +000070 if (AS.PtrList) {
71 *PtrListEnd = AS.PtrList;
Chris Lattner0eab5ec2009-03-09 05:11:09 +000072 AS.PtrList->setPrevInList(PtrListEnd);
Chris Lattner44fea542003-12-18 08:11:56 +000073 PtrListEnd = AS.PtrListEnd;
74
Craig Topper9f008862014-04-15 04:59:12 +000075 AS.PtrList = nullptr;
Chris Lattner44fea542003-12-18 08:11:56 +000076 AS.PtrListEnd = &AS.PtrList;
Craig Topper9f008862014-04-15 04:59:12 +000077 assert(*AS.PtrListEnd == nullptr && "End of list is not null?");
Chris Lattner44fea542003-12-18 08:11:56 +000078 }
Chris Lattner647df642002-09-26 21:49:07 +000079}
80
Chris Lattner7606fb62003-02-24 20:37:56 +000081void AliasSetTracker::removeAliasSet(AliasSet *AS) {
Chris Lattner053427f2004-07-22 07:58:18 +000082 if (AliasSet *Fwd = AS->Forward) {
83 Fwd->dropRef(*this);
Craig Topper9f008862014-04-15 04:59:12 +000084 AS->Forward = nullptr;
Chris Lattner053427f2004-07-22 07:58:18 +000085 }
Chris Lattner7606fb62003-02-24 20:37:56 +000086 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
Chris Lattner0eab5ec2009-03-09 05:11:09 +000094void AliasSet::addPointer(AliasSetTracker &AST, PointerRec &Entry,
Hal Finkelcc39b672014-07-24 12:16:19 +000095 uint64_t Size, const AAMDNodes &AAInfo,
Dan Gohman71af9db2010-10-18 20:44:50 +000096 bool KnownMustAlias) {
Chris Lattner0eab5ec2009-03-09 05:11:09 +000097 assert(!Entry.hasAliasSet() && "Entry already in set!");
Chris Lattner7606fb62003-02-24 20:37:56 +000098
Chris Lattnerab644812004-09-14 19:15:32 +000099 // Check to see if we have to downgrade to _may_ alias.
100 if (isMustAlias() && !KnownMustAlias)
Chris Lattner0eab5ec2009-03-09 05:11:09 +0000101 if (PointerRec *P = getSomePointer()) {
Chris Lattner6fa96652004-09-15 16:59:47 +0000102 AliasAnalysis &AA = AST.getAliasAnalysis();
Chris Lattnerb5b0b7a2003-02-26 22:11:00 +0000103 AliasAnalysis::AliasResult Result =
Dan Gohman71af9db2010-10-18 20:44:50 +0000104 AA.alias(AliasAnalysis::Location(P->getValue(), P->getSize(),
Hal Finkelcc39b672014-07-24 12:16:19 +0000105 P->getAAInfo()),
106 AliasAnalysis::Location(Entry.getValue(), Size, AAInfo));
Dan Gohmanfb0a3752010-12-10 19:40:47 +0000107 if (Result != AliasAnalysis::MustAlias)
Chris Lattner7606fb62003-02-24 20:37:56 +0000108 AliasTy = MayAlias;
Chris Lattnerb5b0b7a2003-02-26 22:11:00 +0000109 else // First entry of must alias must have maximum size!
Hal Finkelcc39b672014-07-24 12:16:19 +0000110 P->updateSizeAndAAInfo(Size, AAInfo);
Chris Lattnerb5b0b7a2003-02-26 22:11:00 +0000111 assert(Result != AliasAnalysis::NoAlias && "Cannot be part of must set!");
112 }
Chris Lattner7606fb62003-02-24 20:37:56 +0000113
Chris Lattner0eab5ec2009-03-09 05:11:09 +0000114 Entry.setAliasSet(this);
Hal Finkelcc39b672014-07-24 12:16:19 +0000115 Entry.updateSizeAndAAInfo(Size, AAInfo);
Chris Lattner7606fb62003-02-24 20:37:56 +0000116
117 // Add it to the end of the list...
Craig Topper9f008862014-04-15 04:59:12 +0000118 assert(*PtrListEnd == nullptr && "End of list is not null?");
Chris Lattner44fea542003-12-18 08:11:56 +0000119 *PtrListEnd = &Entry;
Chris Lattner0eab5ec2009-03-09 05:11:09 +0000120 PtrListEnd = Entry.setPrevInList(PtrListEnd);
Craig Topper9f008862014-04-15 04:59:12 +0000121 assert(*PtrListEnd == nullptr && "End of list is not null?");
Chris Lattnereef6b192010-08-29 04:13:43 +0000122 addRef(); // Entry points to alias set.
Chris Lattner7606fb62003-02-24 20:37:56 +0000123}
124
Eli Friedmanae8161e2011-07-27 00:46:46 +0000125void AliasSet::addUnknownInst(Instruction *I, AliasAnalysis &AA) {
126 UnknownInsts.push_back(I);
Chris Lattner21c60f12004-03-15 04:08:36 +0000127
Eli Friedmanae8161e2011-07-27 00:46:46 +0000128 if (!I->mayWriteToMemory()) {
Duncan Sands68b6f502007-12-01 07:51:45 +0000129 AliasTy = MayAlias;
130 AccessTy |= Refs;
131 return;
Chris Lattner21c60f12004-03-15 04:08:36 +0000132 }
133
134 // FIXME: This should use mod/ref information to make this not suck so bad
135 AliasTy = MayAlias;
Chris Lattnerd14c2002003-05-03 03:42:08 +0000136 AccessTy = ModRef;
Chris Lattner7606fb62003-02-24 20:37:56 +0000137}
138
139/// aliasesPointer - Return true if the specified pointer "may" (or must)
Chris Lattner647df642002-09-26 21:49:07 +0000140/// alias one of the members in the set.
141///
Dan Gohmanf372cf82010-10-19 22:54:46 +0000142bool AliasSet::aliasesPointer(const Value *Ptr, uint64_t Size,
Hal Finkelcc39b672014-07-24 12:16:19 +0000143 const AAMDNodes &AAInfo,
Chris Lattnerb5b0b7a2003-02-26 22:11:00 +0000144 AliasAnalysis &AA) const {
Chris Lattner7606fb62003-02-24 20:37:56 +0000145 if (AliasTy == MustAlias) {
Eli Friedmanae8161e2011-07-27 00:46:46 +0000146 assert(UnknownInsts.empty() && "Illegal must alias set!");
Chris Lattner7f04ebc2004-03-15 06:28:07 +0000147
Chris Lattner7606fb62003-02-24 20:37:56 +0000148 // If this is a set of MustAliases, only check to see if the pointer aliases
Chris Lattnereef6b192010-08-29 04:13:43 +0000149 // SOME value in the set.
Chris Lattner0eab5ec2009-03-09 05:11:09 +0000150 PointerRec *SomePtr = getSomePointer();
Chris Lattner7606fb62003-02-24 20:37:56 +0000151 assert(SomePtr && "Empty must-alias set??");
Dan Gohman71af9db2010-10-18 20:44:50 +0000152 return AA.alias(AliasAnalysis::Location(SomePtr->getValue(),
153 SomePtr->getSize(),
Hal Finkelcc39b672014-07-24 12:16:19 +0000154 SomePtr->getAAInfo()),
155 AliasAnalysis::Location(Ptr, Size, AAInfo));
Chris Lattner7606fb62003-02-24 20:37:56 +0000156 }
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)
Hal Finkelcc39b672014-07-24 12:16:19 +0000161 if (AA.alias(AliasAnalysis::Location(Ptr, Size, AAInfo),
Dan Gohman408beac2010-10-18 21:28:00 +0000162 AliasAnalysis::Location(I.getPointer(), I.getSize(),
Hal Finkelcc39b672014-07-24 12:16:19 +0000163 I.getAAInfo())))
Chris Lattner7606fb62003-02-24 20:37:56 +0000164 return true;
165
Eli Friedmanae8161e2011-07-27 00:46:46 +0000166 // 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],
Hal Finkelcc39b672014-07-24 12:16:19 +0000170 AliasAnalysis::Location(Ptr, Size, AAInfo)) !=
Dan Gohman71af9db2010-10-18 20:44:50 +0000171 AliasAnalysis::NoModRef)
Chris Lattner9b323c32004-07-27 02:20:26 +0000172 return true;
173 }
Chris Lattner7606fb62003-02-24 20:37:56 +0000174
Chris Lattner647df642002-09-26 21:49:07 +0000175 return false;
176}
177
Eli Friedmanae8161e2011-07-27 00:46:46 +0000178bool AliasSet::aliasesUnknownInst(Instruction *Inst, AliasAnalysis &AA) const {
179 if (!Inst->mayReadOrWriteMemory())
Duncan Sands68b6f502007-12-01 07:51:45 +0000180 return false;
Chris Lattner21c60f12004-03-15 04:08:36 +0000181
Eli Friedmanae8161e2011-07-27 00:46:46 +0000182 for (unsigned i = 0, e = UnknownInsts.size(); i != e; ++i) {
183 CallSite C1 = getUnknownInst(i), C2 = Inst;
184 if (!C1 || !C2 ||
Eli Friedman8b5277c2011-07-27 01:02:25 +0000185 AA.getModRefInfo(C1, C2) != AliasAnalysis::NoModRef ||
186 AA.getModRefInfo(C2, C1) != AliasAnalysis::NoModRef)
Chris Lattner9b323c32004-07-27 02:20:26 +0000187 return true;
Chris Lattnerf58382e2010-08-29 18:42:23 +0000188 }
Chris Lattner9b323c32004-07-27 02:20:26 +0000189
190 for (iterator I = begin(), E = end(); I != E; ++I)
Hal Finkel56f6b0f2012-02-10 15:52:39 +0000191 if (AA.getModRefInfo(Inst, AliasAnalysis::Location(I.getPointer(),
192 I.getSize(),
Hal Finkelcc39b672014-07-24 12:16:19 +0000193 I.getAAInfo())) !=
Chris Lattner9b323c32004-07-27 02:20:26 +0000194 AliasAnalysis::NoModRef)
195 return true;
196
197 return false;
Chris Lattner647df642002-09-26 21:49:07 +0000198}
199
Chris Lattner0eab5ec2009-03-09 05:11:09 +0000200void AliasSetTracker::clear() {
201 // Delete all the PointerRec entries.
Dan Gohmanf4362da2009-07-30 20:21:41 +0000202 for (PointerMapType::iterator I = PointerMap.begin(), E = PointerMap.end();
203 I != E; ++I)
Chris Lattner0eab5ec2009-03-09 05:11:09 +0000204 I->second->eraseFromList();
205
206 PointerMap.clear();
207
208 // The alias sets should all be clear now.
209 AliasSets.clear();
210}
211
Chris Lattner647df642002-09-26 21:49:07 +0000212
Chris Lattner647df642002-09-26 21:49:07 +0000213/// 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///
Chris Lattnerb5b0b7a2003-02-26 22:11:00 +0000217AliasSet *AliasSetTracker::findAliasSetForPointer(const Value *Ptr,
Dan Gohmanf372cf82010-10-19 22:54:46 +0000218 uint64_t Size,
Hal Finkelcc39b672014-07-24 12:16:19 +0000219 const AAMDNodes &AAInfo) {
Craig Topper9f008862014-04-15 04:59:12 +0000220 AliasSet *FoundSet = nullptr;
Chris Lattnerafb70742010-08-29 04:06:55 +0000221 for (iterator I = begin(), E = end(); I != E; ++I) {
Hal Finkelcc39b672014-07-24 12:16:19 +0000222 if (I->Forward || !I->aliasesPointer(Ptr, Size, AAInfo, AA)) continue;
Chris Lattnerafb70742010-08-29 04:06:55 +0000223
Craig Topper9f008862014-04-15 04:59:12 +0000224 if (!FoundSet) { // If this is the first alias set ptr can go into.
Chris Lattnerafb70742010-08-29 04:06:55 +0000225 FoundSet = I; // Remember it.
226 } else { // Otherwise, we must merge the sets.
227 FoundSet->mergeSetIn(*I, *this); // Merge in contents.
Chris Lattner647df642002-09-26 21:49:07 +0000228 }
Chris Lattnerafb70742010-08-29 04:06:55 +0000229 }
Chris Lattner7606fb62003-02-24 20:37:56 +0000230
231 return FoundSet;
232}
233
Chris Lattnereeaa29c2004-11-26 21:36:25 +0000234/// 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.
Dan Gohmanf372cf82010-10-19 22:54:46 +0000237bool AliasSetTracker::containsPointer(Value *Ptr, uint64_t Size,
Hal Finkelcc39b672014-07-24 12:16:19 +0000238 const AAMDNodes &AAInfo) const {
Chris Lattnereeaa29c2004-11-26 21:36:25 +0000239 for (const_iterator I = begin(), E = end(); I != E; ++I)
Hal Finkelcc39b672014-07-24 12:16:19 +0000240 if (!I->Forward && I->aliasesPointer(Ptr, Size, AAInfo, AA))
Chris Lattnereeaa29c2004-11-26 21:36:25 +0000241 return true;
242 return false;
243}
244
Hal Finkel840257a2014-11-03 23:19:16 +0000245bool AliasSetTracker::containsUnknown(Instruction *Inst) const {
246 for (const_iterator I = begin(), E = end(); I != E; ++I)
247 if (!I->Forward && I->aliasesUnknownInst(Inst, AA))
248 return true;
249 return false;
250}
Chris Lattnereeaa29c2004-11-26 21:36:25 +0000251
Eli Friedmanae8161e2011-07-27 00:46:46 +0000252AliasSet *AliasSetTracker::findAliasSetForUnknownInst(Instruction *Inst) {
Craig Topper9f008862014-04-15 04:59:12 +0000253 AliasSet *FoundSet = nullptr;
Chris Lattnerafb70742010-08-29 04:06:55 +0000254 for (iterator I = begin(), E = end(); I != E; ++I) {
Eli Friedmanae8161e2011-07-27 00:46:46 +0000255 if (I->Forward || !I->aliasesUnknownInst(Inst, AA))
Chris Lattnerafb70742010-08-29 04:06:55 +0000256 continue;
257
Craig Topper9f008862014-04-15 04:59:12 +0000258 if (!FoundSet) // If this is the first alias set ptr can go into.
Chris Lattnerf58382e2010-08-29 18:42:23 +0000259 FoundSet = I; // Remember it.
260 else if (!I->Forward) // Otherwise, we must merge the sets.
Chris Lattnerafb70742010-08-29 04:06:55 +0000261 FoundSet->mergeSetIn(*I, *this); // Merge in contents.
Chris Lattnerafb70742010-08-29 04:06:55 +0000262 }
Chris Lattner647df642002-09-26 21:49:07 +0000263 return FoundSet;
264}
265
266
Chris Lattner647df642002-09-26 21:49:07 +0000267
Chris Lattner7606fb62003-02-24 20:37:56 +0000268
269/// getAliasSetForPointer - Return the alias set that the specified pointer
Chris Lattner0eab5ec2009-03-09 05:11:09 +0000270/// lives in.
Dan Gohmanf372cf82010-10-19 22:54:46 +0000271AliasSet &AliasSetTracker::getAliasSetForPointer(Value *Pointer, uint64_t Size,
Hal Finkelcc39b672014-07-24 12:16:19 +0000272 const AAMDNodes &AAInfo,
Chris Lattner2cfaef22004-07-21 05:18:04 +0000273 bool *New) {
Chris Lattner0eab5ec2009-03-09 05:11:09 +0000274 AliasSet::PointerRec &Entry = getEntryFor(Pointer);
Chris Lattner7606fb62003-02-24 20:37:56 +0000275
Chris Lattnereef6b192010-08-29 04:13:43 +0000276 // Check to see if the pointer is already known.
Chris Lattner0eab5ec2009-03-09 05:11:09 +0000277 if (Entry.hasAliasSet()) {
Hal Finkelcc39b672014-07-24 12:16:19 +0000278 Entry.updateSizeAndAAInfo(Size, AAInfo);
Chris Lattner7606fb62003-02-24 20:37:56 +0000279 // Return the set!
Chris Lattner0eab5ec2009-03-09 05:11:09 +0000280 return *Entry.getAliasSet(*this)->getForwardedTarget(*this);
Chris Lattnerafb70742010-08-29 04:06:55 +0000281 }
282
Hal Finkelcc39b672014-07-24 12:16:19 +0000283 if (AliasSet *AS = findAliasSetForPointer(Pointer, Size, AAInfo)) {
Chris Lattnereef6b192010-08-29 04:13:43 +0000284 // Add it to the alias set it aliases.
Hal Finkelcc39b672014-07-24 12:16:19 +0000285 AS->addPointer(*this, Entry, Size, AAInfo);
Chris Lattner7606fb62003-02-24 20:37:56 +0000286 return *AS;
Chris Lattner647df642002-09-26 21:49:07 +0000287 }
Chris Lattnerafb70742010-08-29 04:06:55 +0000288
289 if (New) *New = true;
Chris Lattnereef6b192010-08-29 04:13:43 +0000290 // Otherwise create a new alias set to hold the loaded pointer.
Chris Lattnerafb70742010-08-29 04:06:55 +0000291 AliasSets.push_back(new AliasSet());
Hal Finkelcc39b672014-07-24 12:16:19 +0000292 AliasSets.back().addPointer(*this, Entry, Size, AAInfo);
Chris Lattnerafb70742010-08-29 04:06:55 +0000293 return AliasSets.back();
Chris Lattner647df642002-09-26 21:49:07 +0000294}
295
Hal Finkelcc39b672014-07-24 12:16:19 +0000296bool AliasSetTracker::add(Value *Ptr, uint64_t Size, const AAMDNodes &AAInfo) {
Chris Lattnerbf8c3c42004-07-26 05:50:23 +0000297 bool NewPtr;
Hal Finkelcc39b672014-07-24 12:16:19 +0000298 addPointer(Ptr, Size, AAInfo, AliasSet::NoModRef, NewPtr);
Chris Lattnerbf8c3c42004-07-26 05:50:23 +0000299 return NewPtr;
300}
301
302
Chris Lattner2cfaef22004-07-21 05:18:04 +0000303bool AliasSetTracker::add(LoadInst *LI) {
Eli Friedman91386c72011-08-15 20:52:09 +0000304 if (LI->getOrdering() > Monotonic) return addUnknown(LI);
Hal Finkelcc39b672014-07-24 12:16:19 +0000305
306 AAMDNodes AAInfo;
307 LI->getAAMetadata(AAInfo);
308
Eli Friedman91386c72011-08-15 20:52:09 +0000309 AliasSet::AccessType ATy = AliasSet::Refs;
Chris Lattner2cfaef22004-07-21 05:18:04 +0000310 bool NewPtr;
311 AliasSet &AS = addPointer(LI->getOperand(0),
Dan Gohman43d19d62009-07-25 00:48:42 +0000312 AA.getTypeStoreSize(LI->getType()),
Hal Finkelcc39b672014-07-24 12:16:19 +0000313 AAInfo, ATy, NewPtr);
Chris Lattner0a140602003-12-14 04:52:11 +0000314 if (LI->isVolatile()) AS.setVolatile();
Chris Lattner2cfaef22004-07-21 05:18:04 +0000315 return NewPtr;
Chris Lattner7606fb62003-02-24 20:37:56 +0000316}
317
Chris Lattner2cfaef22004-07-21 05:18:04 +0000318bool AliasSetTracker::add(StoreInst *SI) {
Eli Friedman91386c72011-08-15 20:52:09 +0000319 if (SI->getOrdering() > Monotonic) return addUnknown(SI);
Hal Finkelcc39b672014-07-24 12:16:19 +0000320
321 AAMDNodes AAInfo;
322 SI->getAAMetadata(AAInfo);
323
Eli Friedman91386c72011-08-15 20:52:09 +0000324 AliasSet::AccessType ATy = AliasSet::Mods;
Chris Lattner2cfaef22004-07-21 05:18:04 +0000325 bool NewPtr;
326 Value *Val = SI->getOperand(0);
327 AliasSet &AS = addPointer(SI->getOperand(1),
Dan Gohman43d19d62009-07-25 00:48:42 +0000328 AA.getTypeStoreSize(Val->getType()),
Hal Finkelcc39b672014-07-24 12:16:19 +0000329 AAInfo, ATy, NewPtr);
Chris Lattner0a140602003-12-14 04:52:11 +0000330 if (SI->isVolatile()) AS.setVolatile();
Chris Lattner2cfaef22004-07-21 05:18:04 +0000331 return NewPtr;
Chris Lattner647df642002-09-26 21:49:07 +0000332}
333
Dan Gohman2cd8e382008-04-14 18:34:50 +0000334bool AliasSetTracker::add(VAArgInst *VAAI) {
Hal Finkelcc39b672014-07-24 12:16:19 +0000335 AAMDNodes AAInfo;
336 VAAI->getAAMetadata(AAInfo);
337
Dan Gohman2cd8e382008-04-14 18:34:50 +0000338 bool NewPtr;
Dan Gohman71af9db2010-10-18 20:44:50 +0000339 addPointer(VAAI->getOperand(0), AliasAnalysis::UnknownSize,
Hal Finkelcc39b672014-07-24 12:16:19 +0000340 AAInfo, AliasSet::ModRef, NewPtr);
Dan Gohman2cd8e382008-04-14 18:34:50 +0000341 return NewPtr;
342}
343
Chris Lattner0a140602003-12-14 04:52:11 +0000344
Eli Friedmanae8161e2011-07-27 00:46:46 +0000345bool AliasSetTracker::addUnknown(Instruction *Inst) {
346 if (isa<DbgInfoIntrinsic>(Inst))
Zhou Sheng506035102009-03-03 06:02:04 +0000347 return true; // Ignore DbgInfo Intrinsics.
Eli Friedmanae8161e2011-07-27 00:46:46 +0000348 if (!Inst->mayReadOrWriteMemory())
Duncan Sands68b6f502007-12-01 07:51:45 +0000349 return true; // doesn't alias anything
Chris Lattner7f04ebc2004-03-15 06:28:07 +0000350
Eli Friedmanae8161e2011-07-27 00:46:46 +0000351 AliasSet *AS = findAliasSetForUnknownInst(Inst);
Chris Lattnerafb70742010-08-29 04:06:55 +0000352 if (AS) {
Eli Friedmanae8161e2011-07-27 00:46:46 +0000353 AS->addUnknownInst(Inst, AA);
Chris Lattner2cfaef22004-07-21 05:18:04 +0000354 return false;
Chris Lattner7606fb62003-02-24 20:37:56 +0000355 }
Chris Lattnerafb70742010-08-29 04:06:55 +0000356 AliasSets.push_back(new AliasSet());
357 AS = &AliasSets.back();
Eli Friedmanae8161e2011-07-27 00:46:46 +0000358 AS->addUnknownInst(Inst, AA);
Chris Lattnerafb70742010-08-29 04:06:55 +0000359 return true;
Chris Lattner647df642002-09-26 21:49:07 +0000360}
361
Chris Lattner2cfaef22004-07-21 05:18:04 +0000362bool AliasSetTracker::add(Instruction *I) {
Chris Lattnerafb70742010-08-29 04:06:55 +0000363 // Dispatch to one of the other add methods.
Chris Lattner7606fb62003-02-24 20:37:56 +0000364 if (LoadInst *LI = dyn_cast<LoadInst>(I))
Chris Lattner2cfaef22004-07-21 05:18:04 +0000365 return add(LI);
Chris Lattnerafb70742010-08-29 04:06:55 +0000366 if (StoreInst *SI = dyn_cast<StoreInst>(I))
Chris Lattner2cfaef22004-07-21 05:18:04 +0000367 return add(SI);
Chris Lattnerafb70742010-08-29 04:06:55 +0000368 if (VAArgInst *VAAI = dyn_cast<VAArgInst>(I))
Dan Gohman2cd8e382008-04-14 18:34:50 +0000369 return add(VAAI);
Eli Friedmanae8161e2011-07-27 00:46:46 +0000370 return addUnknown(I);
Chris Lattner647df642002-09-26 21:49:07 +0000371}
372
Chris Lattnerc048bb32003-03-03 23:28:05 +0000373void AliasSetTracker::add(BasicBlock &BB) {
374 for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E; ++I)
375 add(I);
376}
377
378void AliasSetTracker::add(const AliasSetTracker &AST) {
379 assert(&AA == &AST.AA &&
380 "Merging AliasSetTracker objects with different Alias Analyses!");
381
382 // Loop over all of the alias sets in AST, adding the pointers contained
383 // therein into the current alias sets. This can cause alias sets to be
384 // merged together in the current AST.
Chris Lattnerafb70742010-08-29 04:06:55 +0000385 for (const_iterator I = AST.begin(), E = AST.end(); I != E; ++I) {
386 if (I->Forward) continue; // Ignore forwarding alias sets
387
388 AliasSet &AS = const_cast<AliasSet&>(*I);
Chris Lattnerc048bb32003-03-03 23:28:05 +0000389
Chris Lattnerafb70742010-08-29 04:06:55 +0000390 // If there are any call sites in the alias set, add them to this AST.
Eli Friedmanae8161e2011-07-27 00:46:46 +0000391 for (unsigned i = 0, e = AS.UnknownInsts.size(); i != e; ++i)
392 add(AS.UnknownInsts[i]);
Chris Lattnerc048bb32003-03-03 23:28:05 +0000393
Chris Lattnerafb70742010-08-29 04:06:55 +0000394 // Loop over all of the pointers in this alias set.
395 bool X;
396 for (AliasSet::iterator ASI = AS.begin(), E = AS.end(); ASI != E; ++ASI) {
397 AliasSet &NewAS = addPointer(ASI.getPointer(), ASI.getSize(),
Hal Finkelcc39b672014-07-24 12:16:19 +0000398 ASI.getAAInfo(),
Chris Lattnerafb70742010-08-29 04:06:55 +0000399 (AliasSet::AccessType)AS.AccessTy, X);
400 if (AS.isVolatile()) NewAS.setVolatile();
Chris Lattnerc048bb32003-03-03 23:28:05 +0000401 }
Chris Lattnerafb70742010-08-29 04:06:55 +0000402 }
Chris Lattnerc048bb32003-03-03 23:28:05 +0000403}
404
Chris Lattnerabc4f452004-07-21 07:04:26 +0000405/// remove - Remove the specified (potentially non-empty) alias set from the
406/// tracker.
407void AliasSetTracker::remove(AliasSet &AS) {
Chris Lattnerf4e06532006-06-27 23:48:59 +0000408 // Drop all call sites.
Eli Friedmanae8161e2011-07-27 00:46:46 +0000409 AS.UnknownInsts.clear();
Chris Lattnerf4e06532006-06-27 23:48:59 +0000410
411 // Clear the alias set.
412 unsigned NumRefs = 0;
413 while (!AS.empty()) {
Chris Lattner0eab5ec2009-03-09 05:11:09 +0000414 AliasSet::PointerRec *P = AS.PtrList;
415
416 Value *ValToRemove = P->getValue();
Chris Lattnerf4e06532006-06-27 23:48:59 +0000417
Chris Lattner0eab5ec2009-03-09 05:11:09 +0000418 // Unlink and delete entry from the list of values.
419 P->eraseFromList();
Chris Lattnerf4e06532006-06-27 23:48:59 +0000420
421 // Remember how many references need to be dropped.
422 ++NumRefs;
Chris Lattnerabc4f452004-07-21 07:04:26 +0000423
Chris Lattnerf4e06532006-06-27 23:48:59 +0000424 // Finally, remove the entry.
Chris Lattner0eab5ec2009-03-09 05:11:09 +0000425 PointerMap.erase(ValToRemove);
Chris Lattnerf4e06532006-06-27 23:48:59 +0000426 }
427
428 // Stop using the alias set, removing it.
Chris Lattner90213c62006-06-27 23:56:13 +0000429 AS.RefCount -= NumRefs;
430 if (AS.RefCount == 0)
431 AS.removeFromTracker(*this);
Chris Lattnerabc4f452004-07-21 07:04:26 +0000432}
433
Dan Gohman71af9db2010-10-18 20:44:50 +0000434bool
Hal Finkelcc39b672014-07-24 12:16:19 +0000435AliasSetTracker::remove(Value *Ptr, uint64_t Size, const AAMDNodes &AAInfo) {
436 AliasSet *AS = findAliasSetForPointer(Ptr, Size, AAInfo);
Chris Lattnerbf8c3c42004-07-26 05:50:23 +0000437 if (!AS) return false;
438 remove(*AS);
439 return true;
440}
Chris Lattnerabc4f452004-07-21 07:04:26 +0000441
442bool AliasSetTracker::remove(LoadInst *LI) {
Dan Gohmanf372cf82010-10-19 22:54:46 +0000443 uint64_t Size = AA.getTypeStoreSize(LI->getType());
Hal Finkelcc39b672014-07-24 12:16:19 +0000444
445 AAMDNodes AAInfo;
446 LI->getAAMetadata(AAInfo);
447
448 AliasSet *AS = findAliasSetForPointer(LI->getOperand(0), Size, AAInfo);
Chris Lattnerabc4f452004-07-21 07:04:26 +0000449 if (!AS) return false;
450 remove(*AS);
451 return true;
452}
453
454bool AliasSetTracker::remove(StoreInst *SI) {
Dan Gohmanf372cf82010-10-19 22:54:46 +0000455 uint64_t Size = AA.getTypeStoreSize(SI->getOperand(0)->getType());
Hal Finkelcc39b672014-07-24 12:16:19 +0000456
457 AAMDNodes AAInfo;
458 SI->getAAMetadata(AAInfo);
459
460 AliasSet *AS = findAliasSetForPointer(SI->getOperand(1), Size, AAInfo);
Chris Lattnerabc4f452004-07-21 07:04:26 +0000461 if (!AS) return false;
462 remove(*AS);
463 return true;
464}
465
Dan Gohman2cd8e382008-04-14 18:34:50 +0000466bool AliasSetTracker::remove(VAArgInst *VAAI) {
Hal Finkelcc39b672014-07-24 12:16:19 +0000467 AAMDNodes AAInfo;
468 VAAI->getAAMetadata(AAInfo);
469
Dan Gohman71af9db2010-10-18 20:44:50 +0000470 AliasSet *AS = findAliasSetForPointer(VAAI->getOperand(0),
Hal Finkelcc39b672014-07-24 12:16:19 +0000471 AliasAnalysis::UnknownSize, AAInfo);
Dan Gohman2cd8e382008-04-14 18:34:50 +0000472 if (!AS) return false;
473 remove(*AS);
474 return true;
475}
476
Eli Friedmanae8161e2011-07-27 00:46:46 +0000477bool AliasSetTracker::removeUnknown(Instruction *I) {
478 if (!I->mayReadOrWriteMemory())
Duncan Sands68b6f502007-12-01 07:51:45 +0000479 return false; // doesn't alias anything
Chris Lattnerabc4f452004-07-21 07:04:26 +0000480
Eli Friedmanae8161e2011-07-27 00:46:46 +0000481 AliasSet *AS = findAliasSetForUnknownInst(I);
Chris Lattnerabc4f452004-07-21 07:04:26 +0000482 if (!AS) return false;
483 remove(*AS);
484 return true;
485}
486
487bool AliasSetTracker::remove(Instruction *I) {
488 // Dispatch to one of the other remove methods...
489 if (LoadInst *LI = dyn_cast<LoadInst>(I))
490 return remove(LI);
Chris Lattnereef6b192010-08-29 04:13:43 +0000491 if (StoreInst *SI = dyn_cast<StoreInst>(I))
Chris Lattnerabc4f452004-07-21 07:04:26 +0000492 return remove(SI);
Chris Lattnereef6b192010-08-29 04:13:43 +0000493 if (VAArgInst *VAAI = dyn_cast<VAArgInst>(I))
Dan Gohman2cd8e382008-04-14 18:34:50 +0000494 return remove(VAAI);
Eli Friedmanae8161e2011-07-27 00:46:46 +0000495 return removeUnknown(I);
Chris Lattnerabc4f452004-07-21 07:04:26 +0000496}
497
Chris Lattner44fea542003-12-18 08:11:56 +0000498
Chris Lattner746e1e12004-05-23 21:10:58 +0000499// deleteValue method - This method is used to remove a pointer value from the
Chris Lattner44fea542003-12-18 08:11:56 +0000500// AliasSetTracker entirely. It should be used when an instruction is deleted
501// from the program to update the AST. If you don't use this, you would have
502// dangling pointers to deleted instructions.
503//
Chris Lattner746e1e12004-05-23 21:10:58 +0000504void AliasSetTracker::deleteValue(Value *PtrVal) {
Chris Lattnerab644812004-09-14 19:15:32 +0000505 // Notify the alias analysis implementation that this value is gone.
506 AA.deleteValue(PtrVal);
507
Chris Lattnere7d4e562006-06-26 19:20:48 +0000508 // If this is a call instruction, remove the callsite from the appropriate
Chris Lattnerf58382e2010-08-29 18:42:23 +0000509 // AliasSet (if present).
Eli Friedmanae8161e2011-07-27 00:46:46 +0000510 if (Instruction *Inst = dyn_cast<Instruction>(PtrVal)) {
511 if (Inst->mayReadOrWriteMemory()) {
Chris Lattnerf58382e2010-08-29 18:42:23 +0000512 // Scan all the alias sets to see if this call site is contained.
513 for (iterator I = begin(), E = end(); I != E; ++I) {
514 if (I->Forward) continue;
515
Eli Friedmanae8161e2011-07-27 00:46:46 +0000516 I->removeUnknownInst(Inst);
Chris Lattnerf58382e2010-08-29 18:42:23 +0000517 }
518 }
519 }
Chris Lattnere7d4e562006-06-26 19:20:48 +0000520
Chris Lattnerab644812004-09-14 19:15:32 +0000521 // First, look up the PointerRec for this pointer.
Benjamin Kramere2ef47c2012-06-30 22:37:15 +0000522 PointerMapType::iterator I = PointerMap.find_as(PtrVal);
Chris Lattner44fea542003-12-18 08:11:56 +0000523 if (I == PointerMap.end()) return; // Noop
524
525 // If we found one, remove the pointer from the alias set it is in.
Chris Lattner0eab5ec2009-03-09 05:11:09 +0000526 AliasSet::PointerRec *PtrValEnt = I->second;
527 AliasSet *AS = PtrValEnt->getAliasSet(*this);
Chris Lattner44fea542003-12-18 08:11:56 +0000528
Chris Lattner0eab5ec2009-03-09 05:11:09 +0000529 // Unlink and delete from the list of values.
530 PtrValEnt->eraseFromList();
531
532 // Stop using the alias set.
Chris Lattner053427f2004-07-22 07:58:18 +0000533 AS->dropRef(*this);
Chris Lattner0eab5ec2009-03-09 05:11:09 +0000534
Chris Lattner44fea542003-12-18 08:11:56 +0000535 PointerMap.erase(I);
536}
537
Chris Lattnerab644812004-09-14 19:15:32 +0000538// copyValue - This method should be used whenever a preexisting value in the
539// program is copied or cloned, introducing a new value. Note that it is ok for
540// clients that use this method to introduce the same value multiple times: if
541// the tracker already knows about a value, it will ignore the request.
542//
543void AliasSetTracker::copyValue(Value *From, Value *To) {
544 // Notify the alias analysis implementation that this value is copied.
545 AA.copyValue(From, To);
546
547 // First, look up the PointerRec for this pointer.
Benjamin Kramere2ef47c2012-06-30 22:37:15 +0000548 PointerMapType::iterator I = PointerMap.find_as(From);
Chris Lattner0eab5ec2009-03-09 05:11:09 +0000549 if (I == PointerMap.end())
Chris Lattnerab644812004-09-14 19:15:32 +0000550 return; // Noop
Chris Lattner0eab5ec2009-03-09 05:11:09 +0000551 assert(I->second->hasAliasSet() && "Dead entry?");
Chris Lattnerab644812004-09-14 19:15:32 +0000552
Chris Lattner0eab5ec2009-03-09 05:11:09 +0000553 AliasSet::PointerRec &Entry = getEntryFor(To);
554 if (Entry.hasAliasSet()) return; // Already in the tracker!
Chris Lattnerab644812004-09-14 19:15:32 +0000555
556 // Add it to the alias set it aliases...
Benjamin Kramere2ef47c2012-06-30 22:37:15 +0000557 I = PointerMap.find_as(From);
Chris Lattner0eab5ec2009-03-09 05:11:09 +0000558 AliasSet *AS = I->second->getAliasSet(*this);
Dan Gohman408beac2010-10-18 21:28:00 +0000559 AS->addPointer(*this, Entry, I->second->getSize(),
Hal Finkelcc39b672014-07-24 12:16:19 +0000560 I->second->getAAInfo(),
Dan Gohman71af9db2010-10-18 20:44:50 +0000561 true);
Chris Lattnerab644812004-09-14 19:15:32 +0000562}
563
564
Chris Lattner44fea542003-12-18 08:11:56 +0000565
Chris Lattner7606fb62003-02-24 20:37:56 +0000566//===----------------------------------------------------------------------===//
567// AliasSet/AliasSetTracker Printing Support
568//===----------------------------------------------------------------------===//
569
Chris Lattnerb1d782b2009-08-23 05:17:37 +0000570void AliasSet::print(raw_ostream &OS) const {
Roman Divackyad06cee2012-09-05 22:26:57 +0000571 OS << " AliasSet[" << (const void*)this << ", " << RefCount << "] ";
Dan Gohman79fff7c2008-04-21 19:48:48 +0000572 OS << (AliasTy == MustAlias ? "must" : "may") << " alias, ";
Chris Lattner7606fb62003-02-24 20:37:56 +0000573 switch (AccessTy) {
574 case NoModRef: OS << "No access "; break;
575 case Refs : OS << "Ref "; break;
576 case Mods : OS << "Mod "; break;
577 case ModRef : OS << "Mod/Ref "; break;
Torok Edwinfbcc6632009-07-14 16:55:14 +0000578 default: llvm_unreachable("Bad value for AccessTy!");
Chris Lattner647df642002-09-26 21:49:07 +0000579 }
Chris Lattner0a140602003-12-14 04:52:11 +0000580 if (isVolatile()) OS << "[volatile] ";
Chris Lattner7606fb62003-02-24 20:37:56 +0000581 if (Forward)
582 OS << " forwarding to " << (void*)Forward;
583
584
Dan Gohmanc731c972007-10-03 19:26:29 +0000585 if (!empty()) {
Chris Lattner7606fb62003-02-24 20:37:56 +0000586 OS << "Pointers: ";
587 for (iterator I = begin(), E = end(); I != E; ++I) {
588 if (I != begin()) OS << ", ";
Chandler Carruthd48cdbf2014-01-09 02:29:41 +0000589 I.getPointer()->printAsOperand(OS << "(");
Chris Lattner053427f2004-07-22 07:58:18 +0000590 OS << ", " << I.getSize() << ")";
Chris Lattner7606fb62003-02-24 20:37:56 +0000591 }
592 }
Eli Friedmanae8161e2011-07-27 00:46:46 +0000593 if (!UnknownInsts.empty()) {
594 OS << "\n " << UnknownInsts.size() << " Unknown instructions: ";
595 for (unsigned i = 0, e = UnknownInsts.size(); i != e; ++i) {
Chris Lattner7606fb62003-02-24 20:37:56 +0000596 if (i) OS << ", ";
Chandler Carruthd48cdbf2014-01-09 02:29:41 +0000597 UnknownInsts[i]->printAsOperand(OS);
Misha Brukman01808ca2005-04-21 21:13:18 +0000598 }
Chris Lattner7606fb62003-02-24 20:37:56 +0000599 }
600 OS << "\n";
601}
602
Chris Lattnerb1d782b2009-08-23 05:17:37 +0000603void AliasSetTracker::print(raw_ostream &OS) const {
Chris Lattner7606fb62003-02-24 20:37:56 +0000604 OS << "Alias Set Tracker: " << AliasSets.size() << " alias sets for "
605 << PointerMap.size() << " pointer values.\n";
606 for (const_iterator I = begin(), E = end(); I != E; ++I)
607 I->print(OS);
608 OS << "\n";
609}
610
Manman Ren49d684e2012-09-12 05:06:18 +0000611#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
David Greene2ec90032009-12-23 19:27:59 +0000612void AliasSet::dump() const { print(dbgs()); }
613void AliasSetTracker::dump() const { print(dbgs()); }
Manman Renc3366cc2012-09-06 19:55:56 +0000614#endif
Chris Lattner7606fb62003-02-24 20:37:56 +0000615
Chris Lattner7606fb62003-02-24 20:37:56 +0000616//===----------------------------------------------------------------------===//
Dan Gohmanf4362da2009-07-30 20:21:41 +0000617// ASTCallbackVH Class Implementation
618//===----------------------------------------------------------------------===//
619
620void AliasSetTracker::ASTCallbackVH::deleted() {
621 assert(AST && "ASTCallbackVH called with a null AliasSetTracker!");
622 AST->deleteValue(getValPtr());
623 // this now dangles!
624}
625
Eli Friedman17822fc2011-04-09 06:55:46 +0000626void AliasSetTracker::ASTCallbackVH::allUsesReplacedWith(Value *V) {
627 AST->copyValue(getValPtr(), V);
628}
629
Dan Gohmanf4362da2009-07-30 20:21:41 +0000630AliasSetTracker::ASTCallbackVH::ASTCallbackVH(Value *V, AliasSetTracker *ast)
Dan Gohmandc2b1b02009-07-31 18:21:48 +0000631 : CallbackVH(V), AST(ast) {}
632
633AliasSetTracker::ASTCallbackVH &
634AliasSetTracker::ASTCallbackVH::operator=(Value *V) {
635 return *this = ASTCallbackVH(V, AST);
636}
Dan Gohmanf4362da2009-07-30 20:21:41 +0000637
638//===----------------------------------------------------------------------===//
Chris Lattner7606fb62003-02-24 20:37:56 +0000639// AliasSetPrinter Pass
640//===----------------------------------------------------------------------===//
641
642namespace {
Nick Lewycky02d5f772009-10-25 06:33:48 +0000643 class AliasSetPrinter : public FunctionPass {
Chris Lattner7606fb62003-02-24 20:37:56 +0000644 AliasSetTracker *Tracker;
645 public:
Nick Lewyckye7da2d62007-05-06 13:37:16 +0000646 static char ID; // Pass identification, replacement for typeid
Owen Anderson6c18d1a2010-10-19 17:21:58 +0000647 AliasSetPrinter() : FunctionPass(ID) {
648 initializeAliasSetPrinterPass(*PassRegistry::getPassRegistry());
649 }
Devang Patel09f162c2007-05-01 21:15:47 +0000650
Craig Toppere9ba7592014-03-05 07:30:04 +0000651 void getAnalysisUsage(AnalysisUsage &AU) const override {
Chris Lattner7606fb62003-02-24 20:37:56 +0000652 AU.setPreservesAll();
653 AU.addRequired<AliasAnalysis>();
654 }
655
Craig Toppere9ba7592014-03-05 07:30:04 +0000656 bool runOnFunction(Function &F) override {
Chris Lattner7606fb62003-02-24 20:37:56 +0000657 Tracker = new AliasSetTracker(getAnalysis<AliasAnalysis>());
658
659 for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I)
Chris Lattner2d3a7a62004-04-27 15:13:33 +0000660 Tracker->add(&*I);
David Greene0295ecf2009-12-23 22:49:57 +0000661 Tracker->print(errs());
Chris Lattner44497852006-01-03 06:05:22 +0000662 delete Tracker;
Chris Lattner7606fb62003-02-24 20:37:56 +0000663 return false;
664 }
Chris Lattner7606fb62003-02-24 20:37:56 +0000665 };
Chris Lattner647df642002-09-26 21:49:07 +0000666}
Dan Gohmand78c4002008-05-13 00:00:25 +0000667
668char AliasSetPrinter::ID = 0;
Owen Anderson8ac477f2010-10-12 19:48:12 +0000669INITIALIZE_PASS_BEGIN(AliasSetPrinter, "print-alias-sets",
670 "Alias Set Printer", false, true)
671INITIALIZE_AG_DEPENDENCY(AliasAnalysis)
672INITIALIZE_PASS_END(AliasSetPrinter, "print-alias-sets",
Owen Andersondf7a4f22010-10-07 22:25:06 +0000673 "Alias Set Printer", false, true)