blob: 12c1c7d4af90fb4d97a9fb8ecfead3a046c9022d [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
David Majnemer35639382014-11-19 19:36:18 +000058 bool ASHadUnknownInsts = !AS.UnknownInsts.empty();
Eli Friedmanae8161e2011-07-27 00:46:46 +000059 if (UnknownInsts.empty()) { // Merge call sites...
David Majnemer35639382014-11-19 19:36:18 +000060 if (ASHadUnknownInsts) {
Eli Friedmanae8161e2011-07-27 00:46:46 +000061 std::swap(UnknownInsts, AS.UnknownInsts);
David Majnemerb7adf342014-11-19 09:41:05 +000062 addRef();
63 }
David Majnemer35639382014-11-19 19:36:18 +000064 } else if (ASHadUnknownInsts) {
Eli Friedmanae8161e2011-07-27 00:46:46 +000065 UnknownInsts.insert(UnknownInsts.end(), AS.UnknownInsts.begin(), AS.UnknownInsts.end());
66 AS.UnknownInsts.clear();
Chris Lattner7606fb62003-02-24 20:37:56 +000067 }
Misha Brukman01808ca2005-04-21 21:13:18 +000068
Chris Lattner7606fb62003-02-24 20:37:56 +000069 AS.Forward = this; // Forward across AS now...
Chris Lattner053427f2004-07-22 07:58:18 +000070 addRef(); // AS is now pointing to us...
Chris Lattner7606fb62003-02-24 20:37:56 +000071
72 // Merge the list of constituent pointers...
Chris Lattner44fea542003-12-18 08:11:56 +000073 if (AS.PtrList) {
74 *PtrListEnd = AS.PtrList;
Chris Lattner0eab5ec2009-03-09 05:11:09 +000075 AS.PtrList->setPrevInList(PtrListEnd);
Chris Lattner44fea542003-12-18 08:11:56 +000076 PtrListEnd = AS.PtrListEnd;
77
Craig Topper9f008862014-04-15 04:59:12 +000078 AS.PtrList = nullptr;
Chris Lattner44fea542003-12-18 08:11:56 +000079 AS.PtrListEnd = &AS.PtrList;
Craig Topper9f008862014-04-15 04:59:12 +000080 assert(*AS.PtrListEnd == nullptr && "End of list is not null?");
Chris Lattner44fea542003-12-18 08:11:56 +000081 }
David Majnemerb7adf342014-11-19 09:41:05 +000082 if (ASHadUnknownInsts)
83 AS.dropRef(AST);
Chris Lattner647df642002-09-26 21:49:07 +000084}
85
Chris Lattner7606fb62003-02-24 20:37:56 +000086void AliasSetTracker::removeAliasSet(AliasSet *AS) {
Chris Lattner053427f2004-07-22 07:58:18 +000087 if (AliasSet *Fwd = AS->Forward) {
88 Fwd->dropRef(*this);
Craig Topper9f008862014-04-15 04:59:12 +000089 AS->Forward = nullptr;
Chris Lattner053427f2004-07-22 07:58:18 +000090 }
Chris Lattner7606fb62003-02-24 20:37:56 +000091 AliasSets.erase(AS);
92}
93
94void AliasSet::removeFromTracker(AliasSetTracker &AST) {
95 assert(RefCount == 0 && "Cannot remove non-dead alias set from tracker!");
96 AST.removeAliasSet(this);
97}
98
Chris Lattner0eab5ec2009-03-09 05:11:09 +000099void AliasSet::addPointer(AliasSetTracker &AST, PointerRec &Entry,
Hal Finkelcc39b672014-07-24 12:16:19 +0000100 uint64_t Size, const AAMDNodes &AAInfo,
Dan Gohman71af9db2010-10-18 20:44:50 +0000101 bool KnownMustAlias) {
Chris Lattner0eab5ec2009-03-09 05:11:09 +0000102 assert(!Entry.hasAliasSet() && "Entry already in set!");
Chris Lattner7606fb62003-02-24 20:37:56 +0000103
Chris Lattnerab644812004-09-14 19:15:32 +0000104 // Check to see if we have to downgrade to _may_ alias.
105 if (isMustAlias() && !KnownMustAlias)
Chris Lattner0eab5ec2009-03-09 05:11:09 +0000106 if (PointerRec *P = getSomePointer()) {
Chris Lattner6fa96652004-09-15 16:59:47 +0000107 AliasAnalysis &AA = AST.getAliasAnalysis();
Chris Lattnerb5b0b7a2003-02-26 22:11:00 +0000108 AliasAnalysis::AliasResult Result =
Dan Gohman71af9db2010-10-18 20:44:50 +0000109 AA.alias(AliasAnalysis::Location(P->getValue(), P->getSize(),
Hal Finkelcc39b672014-07-24 12:16:19 +0000110 P->getAAInfo()),
111 AliasAnalysis::Location(Entry.getValue(), Size, AAInfo));
Dan Gohmanfb0a3752010-12-10 19:40:47 +0000112 if (Result != AliasAnalysis::MustAlias)
Chris Lattner7606fb62003-02-24 20:37:56 +0000113 AliasTy = MayAlias;
Chris Lattnerb5b0b7a2003-02-26 22:11:00 +0000114 else // First entry of must alias must have maximum size!
Hal Finkelcc39b672014-07-24 12:16:19 +0000115 P->updateSizeAndAAInfo(Size, AAInfo);
Chris Lattnerb5b0b7a2003-02-26 22:11:00 +0000116 assert(Result != AliasAnalysis::NoAlias && "Cannot be part of must set!");
117 }
Chris Lattner7606fb62003-02-24 20:37:56 +0000118
Chris Lattner0eab5ec2009-03-09 05:11:09 +0000119 Entry.setAliasSet(this);
Hal Finkelcc39b672014-07-24 12:16:19 +0000120 Entry.updateSizeAndAAInfo(Size, AAInfo);
Chris Lattner7606fb62003-02-24 20:37:56 +0000121
122 // Add it to the end of the list...
Craig Topper9f008862014-04-15 04:59:12 +0000123 assert(*PtrListEnd == nullptr && "End of list is not null?");
Chris Lattner44fea542003-12-18 08:11:56 +0000124 *PtrListEnd = &Entry;
Chris Lattner0eab5ec2009-03-09 05:11:09 +0000125 PtrListEnd = Entry.setPrevInList(PtrListEnd);
Craig Topper9f008862014-04-15 04:59:12 +0000126 assert(*PtrListEnd == nullptr && "End of list is not null?");
Chris Lattnereef6b192010-08-29 04:13:43 +0000127 addRef(); // Entry points to alias set.
Chris Lattner7606fb62003-02-24 20:37:56 +0000128}
129
Eli Friedmanae8161e2011-07-27 00:46:46 +0000130void AliasSet::addUnknownInst(Instruction *I, AliasAnalysis &AA) {
David Majnemerb7adf342014-11-19 09:41:05 +0000131 if (UnknownInsts.empty())
132 addRef();
Benjamin Kramerf5e2fc42015-05-29 19:43:39 +0000133 UnknownInsts.emplace_back(I);
Chris Lattner21c60f12004-03-15 04:08:36 +0000134
Eli Friedmanae8161e2011-07-27 00:46:46 +0000135 if (!I->mayWriteToMemory()) {
Duncan Sands68b6f502007-12-01 07:51:45 +0000136 AliasTy = MayAlias;
137 AccessTy |= Refs;
138 return;
Chris Lattner21c60f12004-03-15 04:08:36 +0000139 }
140
141 // FIXME: This should use mod/ref information to make this not suck so bad
142 AliasTy = MayAlias;
Chris Lattnerd14c2002003-05-03 03:42:08 +0000143 AccessTy = ModRef;
Chris Lattner7606fb62003-02-24 20:37:56 +0000144}
145
146/// aliasesPointer - Return true if the specified pointer "may" (or must)
Chris Lattner647df642002-09-26 21:49:07 +0000147/// alias one of the members in the set.
148///
Dan Gohmanf372cf82010-10-19 22:54:46 +0000149bool AliasSet::aliasesPointer(const Value *Ptr, uint64_t Size,
Hal Finkelcc39b672014-07-24 12:16:19 +0000150 const AAMDNodes &AAInfo,
Chris Lattnerb5b0b7a2003-02-26 22:11:00 +0000151 AliasAnalysis &AA) const {
Chris Lattner7606fb62003-02-24 20:37:56 +0000152 if (AliasTy == MustAlias) {
Eli Friedmanae8161e2011-07-27 00:46:46 +0000153 assert(UnknownInsts.empty() && "Illegal must alias set!");
Chris Lattner7f04ebc2004-03-15 06:28:07 +0000154
Chris Lattner7606fb62003-02-24 20:37:56 +0000155 // If this is a set of MustAliases, only check to see if the pointer aliases
Chris Lattnereef6b192010-08-29 04:13:43 +0000156 // SOME value in the set.
Chris Lattner0eab5ec2009-03-09 05:11:09 +0000157 PointerRec *SomePtr = getSomePointer();
Chris Lattner7606fb62003-02-24 20:37:56 +0000158 assert(SomePtr && "Empty must-alias set??");
Dan Gohman71af9db2010-10-18 20:44:50 +0000159 return AA.alias(AliasAnalysis::Location(SomePtr->getValue(),
160 SomePtr->getSize(),
Hal Finkelcc39b672014-07-24 12:16:19 +0000161 SomePtr->getAAInfo()),
162 AliasAnalysis::Location(Ptr, Size, AAInfo));
Chris Lattner7606fb62003-02-24 20:37:56 +0000163 }
164
165 // If this is a may-alias set, we have to check all of the pointers in the set
166 // to be sure it doesn't alias the set...
167 for (iterator I = begin(), E = end(); I != E; ++I)
Hal Finkelcc39b672014-07-24 12:16:19 +0000168 if (AA.alias(AliasAnalysis::Location(Ptr, Size, AAInfo),
Dan Gohman408beac2010-10-18 21:28:00 +0000169 AliasAnalysis::Location(I.getPointer(), I.getSize(),
Hal Finkelcc39b672014-07-24 12:16:19 +0000170 I.getAAInfo())))
Chris Lattner7606fb62003-02-24 20:37:56 +0000171 return true;
172
Eli Friedmanae8161e2011-07-27 00:46:46 +0000173 // Check the unknown instructions...
174 if (!UnknownInsts.empty()) {
175 for (unsigned i = 0, e = UnknownInsts.size(); i != e; ++i)
176 if (AA.getModRefInfo(UnknownInsts[i],
Hal Finkelcc39b672014-07-24 12:16:19 +0000177 AliasAnalysis::Location(Ptr, Size, AAInfo)) !=
Dan Gohman71af9db2010-10-18 20:44:50 +0000178 AliasAnalysis::NoModRef)
Chris Lattner9b323c32004-07-27 02:20:26 +0000179 return true;
180 }
Chris Lattner7606fb62003-02-24 20:37:56 +0000181
Chris Lattner647df642002-09-26 21:49:07 +0000182 return false;
183}
184
Pete Cooper4bf388d2015-05-13 01:12:12 +0000185bool AliasSet::aliasesUnknownInst(const Instruction *Inst,
186 AliasAnalysis &AA) const {
Eli Friedmanae8161e2011-07-27 00:46:46 +0000187 if (!Inst->mayReadOrWriteMemory())
Duncan Sands68b6f502007-12-01 07:51:45 +0000188 return false;
Chris Lattner21c60f12004-03-15 04:08:36 +0000189
Eli Friedmanae8161e2011-07-27 00:46:46 +0000190 for (unsigned i = 0, e = UnknownInsts.size(); i != e; ++i) {
Pete Cooper4bf388d2015-05-13 01:12:12 +0000191 ImmutableCallSite C1(getUnknownInst(i)), C2(Inst);
Eli Friedmanae8161e2011-07-27 00:46:46 +0000192 if (!C1 || !C2 ||
Eli Friedman8b5277c2011-07-27 01:02:25 +0000193 AA.getModRefInfo(C1, C2) != AliasAnalysis::NoModRef ||
194 AA.getModRefInfo(C2, C1) != AliasAnalysis::NoModRef)
Chris Lattner9b323c32004-07-27 02:20:26 +0000195 return true;
Chris Lattnerf58382e2010-08-29 18:42:23 +0000196 }
Chris Lattner9b323c32004-07-27 02:20:26 +0000197
198 for (iterator I = begin(), E = end(); I != E; ++I)
Hal Finkel56f6b0f2012-02-10 15:52:39 +0000199 if (AA.getModRefInfo(Inst, AliasAnalysis::Location(I.getPointer(),
200 I.getSize(),
Hal Finkelcc39b672014-07-24 12:16:19 +0000201 I.getAAInfo())) !=
Chris Lattner9b323c32004-07-27 02:20:26 +0000202 AliasAnalysis::NoModRef)
203 return true;
204
205 return false;
Chris Lattner647df642002-09-26 21:49:07 +0000206}
207
Chris Lattner0eab5ec2009-03-09 05:11:09 +0000208void AliasSetTracker::clear() {
209 // Delete all the PointerRec entries.
Dan Gohmanf4362da2009-07-30 20:21:41 +0000210 for (PointerMapType::iterator I = PointerMap.begin(), E = PointerMap.end();
211 I != E; ++I)
Chris Lattner0eab5ec2009-03-09 05:11:09 +0000212 I->second->eraseFromList();
213
214 PointerMap.clear();
215
216 // The alias sets should all be clear now.
217 AliasSets.clear();
218}
219
Chris Lattner647df642002-09-26 21:49:07 +0000220
Chris Lattner647df642002-09-26 21:49:07 +0000221/// findAliasSetForPointer - Given a pointer, find the one alias set to put the
222/// instruction referring to the pointer into. If there are multiple alias sets
223/// that may alias the pointer, merge them together and return the unified set.
224///
Chris Lattnerb5b0b7a2003-02-26 22:11:00 +0000225AliasSet *AliasSetTracker::findAliasSetForPointer(const Value *Ptr,
Dan Gohmanf372cf82010-10-19 22:54:46 +0000226 uint64_t Size,
Hal Finkelcc39b672014-07-24 12:16:19 +0000227 const AAMDNodes &AAInfo) {
Craig Topper9f008862014-04-15 04:59:12 +0000228 AliasSet *FoundSet = nullptr;
David Majnemerb7adf342014-11-19 09:41:05 +0000229 for (iterator I = begin(), E = end(); I != E;) {
230 iterator Cur = I++;
231 if (Cur->Forward || !Cur->aliasesPointer(Ptr, Size, AAInfo, AA)) continue;
Chris Lattnerafb70742010-08-29 04:06:55 +0000232
Craig Topper9f008862014-04-15 04:59:12 +0000233 if (!FoundSet) { // If this is the first alias set ptr can go into.
David Majnemerb7adf342014-11-19 09:41:05 +0000234 FoundSet = Cur; // Remember it.
Chris Lattnerafb70742010-08-29 04:06:55 +0000235 } else { // Otherwise, we must merge the sets.
David Majnemerb7adf342014-11-19 09:41:05 +0000236 FoundSet->mergeSetIn(*Cur, *this); // Merge in contents.
Chris Lattner647df642002-09-26 21:49:07 +0000237 }
Chris Lattnerafb70742010-08-29 04:06:55 +0000238 }
Chris Lattner7606fb62003-02-24 20:37:56 +0000239
240 return FoundSet;
241}
242
Chris Lattnereeaa29c2004-11-26 21:36:25 +0000243/// containsPointer - Return true if the specified location is represented by
244/// this alias set, false otherwise. This does not modify the AST object or
245/// alias sets.
Pete Cooper4bf388d2015-05-13 01:12:12 +0000246bool AliasSetTracker::containsPointer(const Value *Ptr, uint64_t Size,
Hal Finkelcc39b672014-07-24 12:16:19 +0000247 const AAMDNodes &AAInfo) const {
Chris Lattnereeaa29c2004-11-26 21:36:25 +0000248 for (const_iterator I = begin(), E = end(); I != E; ++I)
Hal Finkelcc39b672014-07-24 12:16:19 +0000249 if (!I->Forward && I->aliasesPointer(Ptr, Size, AAInfo, AA))
Chris Lattnereeaa29c2004-11-26 21:36:25 +0000250 return true;
251 return false;
252}
253
Pete Cooper4bf388d2015-05-13 01:12:12 +0000254bool AliasSetTracker::containsUnknown(const Instruction *Inst) const {
Hal Finkel840257a2014-11-03 23:19:16 +0000255 for (const_iterator I = begin(), E = end(); I != E; ++I)
256 if (!I->Forward && I->aliasesUnknownInst(Inst, AA))
257 return true;
258 return false;
259}
Chris Lattnereeaa29c2004-11-26 21:36:25 +0000260
Eli Friedmanae8161e2011-07-27 00:46:46 +0000261AliasSet *AliasSetTracker::findAliasSetForUnknownInst(Instruction *Inst) {
Craig Topper9f008862014-04-15 04:59:12 +0000262 AliasSet *FoundSet = nullptr;
David Majnemerb7adf342014-11-19 09:41:05 +0000263 for (iterator I = begin(), E = end(); I != E;) {
264 iterator Cur = I++;
265 if (Cur->Forward || !Cur->aliasesUnknownInst(Inst, AA))
Chris Lattnerafb70742010-08-29 04:06:55 +0000266 continue;
Craig Topper9f008862014-04-15 04:59:12 +0000267 if (!FoundSet) // If this is the first alias set ptr can go into.
David Majnemerb7adf342014-11-19 09:41:05 +0000268 FoundSet = Cur; // Remember it.
269 else if (!Cur->Forward) // Otherwise, we must merge the sets.
270 FoundSet->mergeSetIn(*Cur, *this); // Merge in contents.
Chris Lattnerafb70742010-08-29 04:06:55 +0000271 }
Chris Lattner647df642002-09-26 21:49:07 +0000272 return FoundSet;
273}
274
275
Chris Lattner647df642002-09-26 21:49:07 +0000276
Chris Lattner7606fb62003-02-24 20:37:56 +0000277
278/// getAliasSetForPointer - Return the alias set that the specified pointer
Chris Lattner0eab5ec2009-03-09 05:11:09 +0000279/// lives in.
Dan Gohmanf372cf82010-10-19 22:54:46 +0000280AliasSet &AliasSetTracker::getAliasSetForPointer(Value *Pointer, uint64_t Size,
Hal Finkelcc39b672014-07-24 12:16:19 +0000281 const AAMDNodes &AAInfo,
Chris Lattner2cfaef22004-07-21 05:18:04 +0000282 bool *New) {
Chris Lattner0eab5ec2009-03-09 05:11:09 +0000283 AliasSet::PointerRec &Entry = getEntryFor(Pointer);
Chris Lattner7606fb62003-02-24 20:37:56 +0000284
Chris Lattnereef6b192010-08-29 04:13:43 +0000285 // Check to see if the pointer is already known.
Chris Lattner0eab5ec2009-03-09 05:11:09 +0000286 if (Entry.hasAliasSet()) {
Hal Finkelcc39b672014-07-24 12:16:19 +0000287 Entry.updateSizeAndAAInfo(Size, AAInfo);
Chris Lattner7606fb62003-02-24 20:37:56 +0000288 // Return the set!
Chris Lattner0eab5ec2009-03-09 05:11:09 +0000289 return *Entry.getAliasSet(*this)->getForwardedTarget(*this);
Chris Lattnerafb70742010-08-29 04:06:55 +0000290 }
291
Hal Finkelcc39b672014-07-24 12:16:19 +0000292 if (AliasSet *AS = findAliasSetForPointer(Pointer, Size, AAInfo)) {
Chris Lattnereef6b192010-08-29 04:13:43 +0000293 // Add it to the alias set it aliases.
Hal Finkelcc39b672014-07-24 12:16:19 +0000294 AS->addPointer(*this, Entry, Size, AAInfo);
Chris Lattner7606fb62003-02-24 20:37:56 +0000295 return *AS;
Chris Lattner647df642002-09-26 21:49:07 +0000296 }
Chris Lattnerafb70742010-08-29 04:06:55 +0000297
298 if (New) *New = true;
Chris Lattnereef6b192010-08-29 04:13:43 +0000299 // Otherwise create a new alias set to hold the loaded pointer.
Chris Lattnerafb70742010-08-29 04:06:55 +0000300 AliasSets.push_back(new AliasSet());
Hal Finkelcc39b672014-07-24 12:16:19 +0000301 AliasSets.back().addPointer(*this, Entry, Size, AAInfo);
Chris Lattnerafb70742010-08-29 04:06:55 +0000302 return AliasSets.back();
Chris Lattner647df642002-09-26 21:49:07 +0000303}
304
Hal Finkelcc39b672014-07-24 12:16:19 +0000305bool AliasSetTracker::add(Value *Ptr, uint64_t Size, const AAMDNodes &AAInfo) {
Chris Lattnerbf8c3c42004-07-26 05:50:23 +0000306 bool NewPtr;
Hal Finkelcc39b672014-07-24 12:16:19 +0000307 addPointer(Ptr, Size, AAInfo, AliasSet::NoModRef, NewPtr);
Chris Lattnerbf8c3c42004-07-26 05:50:23 +0000308 return NewPtr;
309}
310
311
Chris Lattner2cfaef22004-07-21 05:18:04 +0000312bool AliasSetTracker::add(LoadInst *LI) {
Eli Friedman91386c72011-08-15 20:52:09 +0000313 if (LI->getOrdering() > Monotonic) return addUnknown(LI);
Hal Finkelcc39b672014-07-24 12:16:19 +0000314
315 AAMDNodes AAInfo;
316 LI->getAAMetadata(AAInfo);
317
Eli Friedman91386c72011-08-15 20:52:09 +0000318 AliasSet::AccessType ATy = AliasSet::Refs;
Chris Lattner2cfaef22004-07-21 05:18:04 +0000319 bool NewPtr;
320 AliasSet &AS = addPointer(LI->getOperand(0),
Dan Gohman43d19d62009-07-25 00:48:42 +0000321 AA.getTypeStoreSize(LI->getType()),
Hal Finkelcc39b672014-07-24 12:16:19 +0000322 AAInfo, ATy, NewPtr);
Chris Lattner0a140602003-12-14 04:52:11 +0000323 if (LI->isVolatile()) AS.setVolatile();
Chris Lattner2cfaef22004-07-21 05:18:04 +0000324 return NewPtr;
Chris Lattner7606fb62003-02-24 20:37:56 +0000325}
326
Chris Lattner2cfaef22004-07-21 05:18:04 +0000327bool AliasSetTracker::add(StoreInst *SI) {
Eli Friedman91386c72011-08-15 20:52:09 +0000328 if (SI->getOrdering() > Monotonic) return addUnknown(SI);
Hal Finkelcc39b672014-07-24 12:16:19 +0000329
330 AAMDNodes AAInfo;
331 SI->getAAMetadata(AAInfo);
332
Eli Friedman91386c72011-08-15 20:52:09 +0000333 AliasSet::AccessType ATy = AliasSet::Mods;
Chris Lattner2cfaef22004-07-21 05:18:04 +0000334 bool NewPtr;
335 Value *Val = SI->getOperand(0);
336 AliasSet &AS = addPointer(SI->getOperand(1),
Dan Gohman43d19d62009-07-25 00:48:42 +0000337 AA.getTypeStoreSize(Val->getType()),
Hal Finkelcc39b672014-07-24 12:16:19 +0000338 AAInfo, ATy, NewPtr);
Chris Lattner0a140602003-12-14 04:52:11 +0000339 if (SI->isVolatile()) AS.setVolatile();
Chris Lattner2cfaef22004-07-21 05:18:04 +0000340 return NewPtr;
Chris Lattner647df642002-09-26 21:49:07 +0000341}
342
Dan Gohman2cd8e382008-04-14 18:34:50 +0000343bool AliasSetTracker::add(VAArgInst *VAAI) {
Hal Finkelcc39b672014-07-24 12:16:19 +0000344 AAMDNodes AAInfo;
345 VAAI->getAAMetadata(AAInfo);
346
Dan Gohman2cd8e382008-04-14 18:34:50 +0000347 bool NewPtr;
Dan Gohman71af9db2010-10-18 20:44:50 +0000348 addPointer(VAAI->getOperand(0), AliasAnalysis::UnknownSize,
Hal Finkelcc39b672014-07-24 12:16:19 +0000349 AAInfo, AliasSet::ModRef, NewPtr);
Dan Gohman2cd8e382008-04-14 18:34:50 +0000350 return NewPtr;
351}
352
Chris Lattner0a140602003-12-14 04:52:11 +0000353
Eli Friedmanae8161e2011-07-27 00:46:46 +0000354bool AliasSetTracker::addUnknown(Instruction *Inst) {
355 if (isa<DbgInfoIntrinsic>(Inst))
Zhou Sheng506035102009-03-03 06:02:04 +0000356 return true; // Ignore DbgInfo Intrinsics.
Eli Friedmanae8161e2011-07-27 00:46:46 +0000357 if (!Inst->mayReadOrWriteMemory())
Duncan Sands68b6f502007-12-01 07:51:45 +0000358 return true; // doesn't alias anything
Chris Lattner7f04ebc2004-03-15 06:28:07 +0000359
Eli Friedmanae8161e2011-07-27 00:46:46 +0000360 AliasSet *AS = findAliasSetForUnknownInst(Inst);
Chris Lattnerafb70742010-08-29 04:06:55 +0000361 if (AS) {
Eli Friedmanae8161e2011-07-27 00:46:46 +0000362 AS->addUnknownInst(Inst, AA);
Chris Lattner2cfaef22004-07-21 05:18:04 +0000363 return false;
Chris Lattner7606fb62003-02-24 20:37:56 +0000364 }
Chris Lattnerafb70742010-08-29 04:06:55 +0000365 AliasSets.push_back(new AliasSet());
366 AS = &AliasSets.back();
Eli Friedmanae8161e2011-07-27 00:46:46 +0000367 AS->addUnknownInst(Inst, AA);
Chris Lattnerafb70742010-08-29 04:06:55 +0000368 return true;
Chris Lattner647df642002-09-26 21:49:07 +0000369}
370
Chris Lattner2cfaef22004-07-21 05:18:04 +0000371bool AliasSetTracker::add(Instruction *I) {
Chris Lattnerafb70742010-08-29 04:06:55 +0000372 // Dispatch to one of the other add methods.
Chris Lattner7606fb62003-02-24 20:37:56 +0000373 if (LoadInst *LI = dyn_cast<LoadInst>(I))
Chris Lattner2cfaef22004-07-21 05:18:04 +0000374 return add(LI);
Chris Lattnerafb70742010-08-29 04:06:55 +0000375 if (StoreInst *SI = dyn_cast<StoreInst>(I))
Chris Lattner2cfaef22004-07-21 05:18:04 +0000376 return add(SI);
Chris Lattnerafb70742010-08-29 04:06:55 +0000377 if (VAArgInst *VAAI = dyn_cast<VAArgInst>(I))
Dan Gohman2cd8e382008-04-14 18:34:50 +0000378 return add(VAAI);
Eli Friedmanae8161e2011-07-27 00:46:46 +0000379 return addUnknown(I);
Chris Lattner647df642002-09-26 21:49:07 +0000380}
381
Chris Lattnerc048bb32003-03-03 23:28:05 +0000382void AliasSetTracker::add(BasicBlock &BB) {
383 for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E; ++I)
384 add(I);
385}
386
387void AliasSetTracker::add(const AliasSetTracker &AST) {
388 assert(&AA == &AST.AA &&
389 "Merging AliasSetTracker objects with different Alias Analyses!");
390
391 // Loop over all of the alias sets in AST, adding the pointers contained
392 // therein into the current alias sets. This can cause alias sets to be
393 // merged together in the current AST.
Chris Lattnerafb70742010-08-29 04:06:55 +0000394 for (const_iterator I = AST.begin(), E = AST.end(); I != E; ++I) {
395 if (I->Forward) continue; // Ignore forwarding alias sets
396
397 AliasSet &AS = const_cast<AliasSet&>(*I);
Chris Lattnerc048bb32003-03-03 23:28:05 +0000398
Chris Lattnerafb70742010-08-29 04:06:55 +0000399 // If there are any call sites in the alias set, add them to this AST.
Eli Friedmanae8161e2011-07-27 00:46:46 +0000400 for (unsigned i = 0, e = AS.UnknownInsts.size(); i != e; ++i)
401 add(AS.UnknownInsts[i]);
Chris Lattnerc048bb32003-03-03 23:28:05 +0000402
Chris Lattnerafb70742010-08-29 04:06:55 +0000403 // Loop over all of the pointers in this alias set.
404 bool X;
405 for (AliasSet::iterator ASI = AS.begin(), E = AS.end(); ASI != E; ++ASI) {
406 AliasSet &NewAS = addPointer(ASI.getPointer(), ASI.getSize(),
Hal Finkelcc39b672014-07-24 12:16:19 +0000407 ASI.getAAInfo(),
Chris Lattnerafb70742010-08-29 04:06:55 +0000408 (AliasSet::AccessType)AS.AccessTy, X);
409 if (AS.isVolatile()) NewAS.setVolatile();
Chris Lattnerc048bb32003-03-03 23:28:05 +0000410 }
Chris Lattnerafb70742010-08-29 04:06:55 +0000411 }
Chris Lattnerc048bb32003-03-03 23:28:05 +0000412}
413
Chris Lattnerabc4f452004-07-21 07:04:26 +0000414/// remove - Remove the specified (potentially non-empty) alias set from the
415/// tracker.
416void AliasSetTracker::remove(AliasSet &AS) {
Chris Lattnerf4e06532006-06-27 23:48:59 +0000417 // Drop all call sites.
David Majnemerb7adf342014-11-19 09:41:05 +0000418 if (!AS.UnknownInsts.empty())
419 AS.dropRef(*this);
Eli Friedmanae8161e2011-07-27 00:46:46 +0000420 AS.UnknownInsts.clear();
Chris Lattnerf4e06532006-06-27 23:48:59 +0000421
422 // Clear the alias set.
423 unsigned NumRefs = 0;
424 while (!AS.empty()) {
Chris Lattner0eab5ec2009-03-09 05:11:09 +0000425 AliasSet::PointerRec *P = AS.PtrList;
426
427 Value *ValToRemove = P->getValue();
Chris Lattnerf4e06532006-06-27 23:48:59 +0000428
Chris Lattner0eab5ec2009-03-09 05:11:09 +0000429 // Unlink and delete entry from the list of values.
430 P->eraseFromList();
Chris Lattnerf4e06532006-06-27 23:48:59 +0000431
432 // Remember how many references need to be dropped.
433 ++NumRefs;
Chris Lattnerabc4f452004-07-21 07:04:26 +0000434
Chris Lattnerf4e06532006-06-27 23:48:59 +0000435 // Finally, remove the entry.
Chris Lattner0eab5ec2009-03-09 05:11:09 +0000436 PointerMap.erase(ValToRemove);
Chris Lattnerf4e06532006-06-27 23:48:59 +0000437 }
438
439 // Stop using the alias set, removing it.
Chris Lattner90213c62006-06-27 23:56:13 +0000440 AS.RefCount -= NumRefs;
441 if (AS.RefCount == 0)
442 AS.removeFromTracker(*this);
Chris Lattnerabc4f452004-07-21 07:04:26 +0000443}
444
Dan Gohman71af9db2010-10-18 20:44:50 +0000445bool
Hal Finkelcc39b672014-07-24 12:16:19 +0000446AliasSetTracker::remove(Value *Ptr, uint64_t Size, const AAMDNodes &AAInfo) {
447 AliasSet *AS = findAliasSetForPointer(Ptr, Size, AAInfo);
Chris Lattnerbf8c3c42004-07-26 05:50:23 +0000448 if (!AS) return false;
449 remove(*AS);
450 return true;
451}
Chris Lattnerabc4f452004-07-21 07:04:26 +0000452
453bool AliasSetTracker::remove(LoadInst *LI) {
Dan Gohmanf372cf82010-10-19 22:54:46 +0000454 uint64_t Size = AA.getTypeStoreSize(LI->getType());
Hal Finkelcc39b672014-07-24 12:16:19 +0000455
456 AAMDNodes AAInfo;
457 LI->getAAMetadata(AAInfo);
458
459 AliasSet *AS = findAliasSetForPointer(LI->getOperand(0), Size, AAInfo);
Chris Lattnerabc4f452004-07-21 07:04:26 +0000460 if (!AS) return false;
461 remove(*AS);
462 return true;
463}
464
465bool AliasSetTracker::remove(StoreInst *SI) {
Dan Gohmanf372cf82010-10-19 22:54:46 +0000466 uint64_t Size = AA.getTypeStoreSize(SI->getOperand(0)->getType());
Hal Finkelcc39b672014-07-24 12:16:19 +0000467
468 AAMDNodes AAInfo;
469 SI->getAAMetadata(AAInfo);
470
471 AliasSet *AS = findAliasSetForPointer(SI->getOperand(1), Size, AAInfo);
Chris Lattnerabc4f452004-07-21 07:04:26 +0000472 if (!AS) return false;
473 remove(*AS);
474 return true;
475}
476
Dan Gohman2cd8e382008-04-14 18:34:50 +0000477bool AliasSetTracker::remove(VAArgInst *VAAI) {
Hal Finkelcc39b672014-07-24 12:16:19 +0000478 AAMDNodes AAInfo;
479 VAAI->getAAMetadata(AAInfo);
480
Dan Gohman71af9db2010-10-18 20:44:50 +0000481 AliasSet *AS = findAliasSetForPointer(VAAI->getOperand(0),
Hal Finkelcc39b672014-07-24 12:16:19 +0000482 AliasAnalysis::UnknownSize, AAInfo);
Dan Gohman2cd8e382008-04-14 18:34:50 +0000483 if (!AS) return false;
484 remove(*AS);
485 return true;
486}
487
Eli Friedmanae8161e2011-07-27 00:46:46 +0000488bool AliasSetTracker::removeUnknown(Instruction *I) {
489 if (!I->mayReadOrWriteMemory())
Duncan Sands68b6f502007-12-01 07:51:45 +0000490 return false; // doesn't alias anything
Chris Lattnerabc4f452004-07-21 07:04:26 +0000491
Eli Friedmanae8161e2011-07-27 00:46:46 +0000492 AliasSet *AS = findAliasSetForUnknownInst(I);
Chris Lattnerabc4f452004-07-21 07:04:26 +0000493 if (!AS) return false;
494 remove(*AS);
495 return true;
496}
497
498bool AliasSetTracker::remove(Instruction *I) {
499 // Dispatch to one of the other remove methods...
500 if (LoadInst *LI = dyn_cast<LoadInst>(I))
501 return remove(LI);
Chris Lattnereef6b192010-08-29 04:13:43 +0000502 if (StoreInst *SI = dyn_cast<StoreInst>(I))
Chris Lattnerabc4f452004-07-21 07:04:26 +0000503 return remove(SI);
Chris Lattnereef6b192010-08-29 04:13:43 +0000504 if (VAArgInst *VAAI = dyn_cast<VAArgInst>(I))
Dan Gohman2cd8e382008-04-14 18:34:50 +0000505 return remove(VAAI);
Eli Friedmanae8161e2011-07-27 00:46:46 +0000506 return removeUnknown(I);
Chris Lattnerabc4f452004-07-21 07:04:26 +0000507}
508
Chris Lattner44fea542003-12-18 08:11:56 +0000509
Chris Lattner746e1e12004-05-23 21:10:58 +0000510// deleteValue method - This method is used to remove a pointer value from the
Chris Lattner44fea542003-12-18 08:11:56 +0000511// AliasSetTracker entirely. It should be used when an instruction is deleted
512// from the program to update the AST. If you don't use this, you would have
513// dangling pointers to deleted instructions.
514//
Chris Lattner746e1e12004-05-23 21:10:58 +0000515void AliasSetTracker::deleteValue(Value *PtrVal) {
Chris Lattnerab644812004-09-14 19:15:32 +0000516 // Notify the alias analysis implementation that this value is gone.
517 AA.deleteValue(PtrVal);
518
Chris Lattnere7d4e562006-06-26 19:20:48 +0000519 // If this is a call instruction, remove the callsite from the appropriate
Chris Lattnerf58382e2010-08-29 18:42:23 +0000520 // AliasSet (if present).
Eli Friedmanae8161e2011-07-27 00:46:46 +0000521 if (Instruction *Inst = dyn_cast<Instruction>(PtrVal)) {
522 if (Inst->mayReadOrWriteMemory()) {
Chris Lattnerf58382e2010-08-29 18:42:23 +0000523 // Scan all the alias sets to see if this call site is contained.
David Majnemerb7adf342014-11-19 09:41:05 +0000524 for (iterator I = begin(), E = end(); I != E;) {
525 iterator Cur = I++;
526 if (!Cur->Forward)
527 Cur->removeUnknownInst(*this, Inst);
Chris Lattnerf58382e2010-08-29 18:42:23 +0000528 }
529 }
530 }
Chris Lattnere7d4e562006-06-26 19:20:48 +0000531
Chris Lattnerab644812004-09-14 19:15:32 +0000532 // First, look up the PointerRec for this pointer.
Benjamin Kramere2ef47c2012-06-30 22:37:15 +0000533 PointerMapType::iterator I = PointerMap.find_as(PtrVal);
Chris Lattner44fea542003-12-18 08:11:56 +0000534 if (I == PointerMap.end()) return; // Noop
535
536 // If we found one, remove the pointer from the alias set it is in.
Chris Lattner0eab5ec2009-03-09 05:11:09 +0000537 AliasSet::PointerRec *PtrValEnt = I->second;
538 AliasSet *AS = PtrValEnt->getAliasSet(*this);
Chris Lattner44fea542003-12-18 08:11:56 +0000539
Chris Lattner0eab5ec2009-03-09 05:11:09 +0000540 // Unlink and delete from the list of values.
541 PtrValEnt->eraseFromList();
542
543 // Stop using the alias set.
Chris Lattner053427f2004-07-22 07:58:18 +0000544 AS->dropRef(*this);
Chris Lattner0eab5ec2009-03-09 05:11:09 +0000545
Chris Lattner44fea542003-12-18 08:11:56 +0000546 PointerMap.erase(I);
547}
548
Chris Lattnerab644812004-09-14 19:15:32 +0000549// copyValue - This method should be used whenever a preexisting value in the
550// program is copied or cloned, introducing a new value. Note that it is ok for
551// clients that use this method to introduce the same value multiple times: if
552// the tracker already knows about a value, it will ignore the request.
553//
554void AliasSetTracker::copyValue(Value *From, Value *To) {
555 // Notify the alias analysis implementation that this value is copied.
556 AA.copyValue(From, To);
557
558 // First, look up the PointerRec for this pointer.
Benjamin Kramere2ef47c2012-06-30 22:37:15 +0000559 PointerMapType::iterator I = PointerMap.find_as(From);
Chris Lattner0eab5ec2009-03-09 05:11:09 +0000560 if (I == PointerMap.end())
Chris Lattnerab644812004-09-14 19:15:32 +0000561 return; // Noop
Chris Lattner0eab5ec2009-03-09 05:11:09 +0000562 assert(I->second->hasAliasSet() && "Dead entry?");
Chris Lattnerab644812004-09-14 19:15:32 +0000563
Chris Lattner0eab5ec2009-03-09 05:11:09 +0000564 AliasSet::PointerRec &Entry = getEntryFor(To);
565 if (Entry.hasAliasSet()) return; // Already in the tracker!
Chris Lattnerab644812004-09-14 19:15:32 +0000566
567 // Add it to the alias set it aliases...
Benjamin Kramere2ef47c2012-06-30 22:37:15 +0000568 I = PointerMap.find_as(From);
Chris Lattner0eab5ec2009-03-09 05:11:09 +0000569 AliasSet *AS = I->second->getAliasSet(*this);
Dan Gohman408beac2010-10-18 21:28:00 +0000570 AS->addPointer(*this, Entry, I->second->getSize(),
Hal Finkelcc39b672014-07-24 12:16:19 +0000571 I->second->getAAInfo(),
Dan Gohman71af9db2010-10-18 20:44:50 +0000572 true);
Chris Lattnerab644812004-09-14 19:15:32 +0000573}
574
575
Chris Lattner44fea542003-12-18 08:11:56 +0000576
Chris Lattner7606fb62003-02-24 20:37:56 +0000577//===----------------------------------------------------------------------===//
578// AliasSet/AliasSetTracker Printing Support
579//===----------------------------------------------------------------------===//
580
Chris Lattnerb1d782b2009-08-23 05:17:37 +0000581void AliasSet::print(raw_ostream &OS) const {
Roman Divackyad06cee2012-09-05 22:26:57 +0000582 OS << " AliasSet[" << (const void*)this << ", " << RefCount << "] ";
Dan Gohman79fff7c2008-04-21 19:48:48 +0000583 OS << (AliasTy == MustAlias ? "must" : "may") << " alias, ";
Chris Lattner7606fb62003-02-24 20:37:56 +0000584 switch (AccessTy) {
585 case NoModRef: OS << "No access "; break;
586 case Refs : OS << "Ref "; break;
587 case Mods : OS << "Mod "; break;
588 case ModRef : OS << "Mod/Ref "; break;
Torok Edwinfbcc6632009-07-14 16:55:14 +0000589 default: llvm_unreachable("Bad value for AccessTy!");
Chris Lattner647df642002-09-26 21:49:07 +0000590 }
Chris Lattner0a140602003-12-14 04:52:11 +0000591 if (isVolatile()) OS << "[volatile] ";
Chris Lattner7606fb62003-02-24 20:37:56 +0000592 if (Forward)
593 OS << " forwarding to " << (void*)Forward;
594
595
Dan Gohmanc731c972007-10-03 19:26:29 +0000596 if (!empty()) {
Chris Lattner7606fb62003-02-24 20:37:56 +0000597 OS << "Pointers: ";
598 for (iterator I = begin(), E = end(); I != E; ++I) {
599 if (I != begin()) OS << ", ";
Chandler Carruthd48cdbf2014-01-09 02:29:41 +0000600 I.getPointer()->printAsOperand(OS << "(");
Chris Lattner053427f2004-07-22 07:58:18 +0000601 OS << ", " << I.getSize() << ")";
Chris Lattner7606fb62003-02-24 20:37:56 +0000602 }
603 }
Eli Friedmanae8161e2011-07-27 00:46:46 +0000604 if (!UnknownInsts.empty()) {
605 OS << "\n " << UnknownInsts.size() << " Unknown instructions: ";
606 for (unsigned i = 0, e = UnknownInsts.size(); i != e; ++i) {
Chris Lattner7606fb62003-02-24 20:37:56 +0000607 if (i) OS << ", ";
Chandler Carruthd48cdbf2014-01-09 02:29:41 +0000608 UnknownInsts[i]->printAsOperand(OS);
Misha Brukman01808ca2005-04-21 21:13:18 +0000609 }
Chris Lattner7606fb62003-02-24 20:37:56 +0000610 }
611 OS << "\n";
612}
613
Chris Lattnerb1d782b2009-08-23 05:17:37 +0000614void AliasSetTracker::print(raw_ostream &OS) const {
Chris Lattner7606fb62003-02-24 20:37:56 +0000615 OS << "Alias Set Tracker: " << AliasSets.size() << " alias sets for "
616 << PointerMap.size() << " pointer values.\n";
617 for (const_iterator I = begin(), E = end(); I != E; ++I)
618 I->print(OS);
619 OS << "\n";
620}
621
Manman Ren49d684e2012-09-12 05:06:18 +0000622#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
David Greene2ec90032009-12-23 19:27:59 +0000623void AliasSet::dump() const { print(dbgs()); }
624void AliasSetTracker::dump() const { print(dbgs()); }
Manman Renc3366cc2012-09-06 19:55:56 +0000625#endif
Chris Lattner7606fb62003-02-24 20:37:56 +0000626
Chris Lattner7606fb62003-02-24 20:37:56 +0000627//===----------------------------------------------------------------------===//
Dan Gohmanf4362da2009-07-30 20:21:41 +0000628// ASTCallbackVH Class Implementation
629//===----------------------------------------------------------------------===//
630
631void AliasSetTracker::ASTCallbackVH::deleted() {
632 assert(AST && "ASTCallbackVH called with a null AliasSetTracker!");
633 AST->deleteValue(getValPtr());
634 // this now dangles!
635}
636
Eli Friedman17822fc2011-04-09 06:55:46 +0000637void AliasSetTracker::ASTCallbackVH::allUsesReplacedWith(Value *V) {
638 AST->copyValue(getValPtr(), V);
639}
640
Dan Gohmanf4362da2009-07-30 20:21:41 +0000641AliasSetTracker::ASTCallbackVH::ASTCallbackVH(Value *V, AliasSetTracker *ast)
Dan Gohmandc2b1b02009-07-31 18:21:48 +0000642 : CallbackVH(V), AST(ast) {}
643
644AliasSetTracker::ASTCallbackVH &
645AliasSetTracker::ASTCallbackVH::operator=(Value *V) {
646 return *this = ASTCallbackVH(V, AST);
647}
Dan Gohmanf4362da2009-07-30 20:21:41 +0000648
649//===----------------------------------------------------------------------===//
Chris Lattner7606fb62003-02-24 20:37:56 +0000650// AliasSetPrinter Pass
651//===----------------------------------------------------------------------===//
652
653namespace {
Nick Lewycky02d5f772009-10-25 06:33:48 +0000654 class AliasSetPrinter : public FunctionPass {
Chris Lattner7606fb62003-02-24 20:37:56 +0000655 AliasSetTracker *Tracker;
656 public:
Nick Lewyckye7da2d62007-05-06 13:37:16 +0000657 static char ID; // Pass identification, replacement for typeid
Owen Anderson6c18d1a2010-10-19 17:21:58 +0000658 AliasSetPrinter() : FunctionPass(ID) {
659 initializeAliasSetPrinterPass(*PassRegistry::getPassRegistry());
660 }
Devang Patel09f162c2007-05-01 21:15:47 +0000661
Craig Toppere9ba7592014-03-05 07:30:04 +0000662 void getAnalysisUsage(AnalysisUsage &AU) const override {
Chris Lattner7606fb62003-02-24 20:37:56 +0000663 AU.setPreservesAll();
664 AU.addRequired<AliasAnalysis>();
665 }
666
Craig Toppere9ba7592014-03-05 07:30:04 +0000667 bool runOnFunction(Function &F) override {
Chris Lattner7606fb62003-02-24 20:37:56 +0000668 Tracker = new AliasSetTracker(getAnalysis<AliasAnalysis>());
669
670 for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I)
Chris Lattner2d3a7a62004-04-27 15:13:33 +0000671 Tracker->add(&*I);
David Greene0295ecf2009-12-23 22:49:57 +0000672 Tracker->print(errs());
Chris Lattner44497852006-01-03 06:05:22 +0000673 delete Tracker;
Chris Lattner7606fb62003-02-24 20:37:56 +0000674 return false;
675 }
Chris Lattner7606fb62003-02-24 20:37:56 +0000676 };
Chris Lattner647df642002-09-26 21:49:07 +0000677}
Dan Gohmand78c4002008-05-13 00:00:25 +0000678
679char AliasSetPrinter::ID = 0;
Owen Anderson8ac477f2010-10-12 19:48:12 +0000680INITIALIZE_PASS_BEGIN(AliasSetPrinter, "print-alias-sets",
681 "Alias Set Printer", false, true)
682INITIALIZE_AG_DEPENDENCY(AliasAnalysis)
683INITIALIZE_PASS_END(AliasSetPrinter, "print-alias-sets",
Owen Andersondf7a4f22010-10-07 22:25:06 +0000684 "Alias Set Printer", false, true)