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