Chris Lattner | 009cc3d | 2002-09-26 21:49:07 +0000 | [diff] [blame] | 1 | //===- AliasSetTracker.cpp - Alias Sets Tracker implementation-------------===// |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by the LLVM research group and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | 009cc3d | 2002-09-26 21:49:07 +0000 | [diff] [blame] | 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/iMemory.h" |
| 17 | #include "llvm/iOther.h" |
| 18 | #include "llvm/iTerminators.h" |
Chris Lattner | 9971ac4 | 2003-02-24 20:37:56 +0000 | [diff] [blame] | 19 | #include "llvm/Pass.h" |
Chris Lattner | 31a9d18 | 2003-02-26 22:11:00 +0000 | [diff] [blame] | 20 | #include "llvm/Target/TargetData.h" |
Chris Lattner | 9971ac4 | 2003-02-24 20:37:56 +0000 | [diff] [blame] | 21 | #include "llvm/Assembly/Writer.h" |
| 22 | #include "llvm/Support/InstIterator.h" |
Chris Lattner | e260924 | 2003-12-14 04:52:11 +0000 | [diff] [blame] | 23 | using namespace llvm; |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 24 | |
Chris Lattner | 009cc3d | 2002-09-26 21:49:07 +0000 | [diff] [blame] | 25 | /// mergeSetIn - Merge the specified alias set into this alias set... |
| 26 | /// |
Chris Lattner | 9971ac4 | 2003-02-24 20:37:56 +0000 | [diff] [blame] | 27 | void AliasSet::mergeSetIn(AliasSet &AS) { |
| 28 | assert(!AS.Forward && "Alias set is already forwarding!"); |
| 29 | assert(!Forward && "This set is a forwarding set!!"); |
Chris Lattner | 009cc3d | 2002-09-26 21:49:07 +0000 | [diff] [blame] | 30 | |
| 31 | // Update the alias and access types of this set... |
Chris Lattner | 9971ac4 | 2003-02-24 20:37:56 +0000 | [diff] [blame] | 32 | AccessTy |= AS.AccessTy; |
| 33 | AliasTy |= AS.AliasTy; |
| 34 | |
| 35 | if (CallSites.empty()) { // Merge call sites... |
| 36 | if (!AS.CallSites.empty()) |
| 37 | std::swap(CallSites, AS.CallSites); |
| 38 | } else if (!AS.CallSites.empty()) { |
| 39 | CallSites.insert(CallSites.end(), AS.CallSites.begin(), AS.CallSites.end()); |
| 40 | AS.CallSites.clear(); |
| 41 | } |
| 42 | |
| 43 | // FIXME: If AS's refcount is zero, nuke it now... |
| 44 | assert(RefCount != 0); |
| 45 | |
| 46 | AS.Forward = this; // Forward across AS now... |
| 47 | RefCount++; // AS is now pointing to us... |
| 48 | |
| 49 | // Merge the list of constituent pointers... |
Chris Lattner | 2cffeec | 2003-12-18 08:11:56 +0000 | [diff] [blame] | 50 | if (AS.PtrList) { |
| 51 | *PtrListEnd = AS.PtrList; |
| 52 | AS.PtrList->second.setPrevInList(PtrListEnd); |
| 53 | PtrListEnd = AS.PtrListEnd; |
| 54 | |
| 55 | AS.PtrList = 0; |
| 56 | AS.PtrListEnd = &AS.PtrList; |
| 57 | } |
Chris Lattner | 009cc3d | 2002-09-26 21:49:07 +0000 | [diff] [blame] | 58 | } |
| 59 | |
Chris Lattner | 9971ac4 | 2003-02-24 20:37:56 +0000 | [diff] [blame] | 60 | void AliasSetTracker::removeAliasSet(AliasSet *AS) { |
| 61 | AliasSets.erase(AS); |
| 62 | } |
| 63 | |
| 64 | void AliasSet::removeFromTracker(AliasSetTracker &AST) { |
| 65 | assert(RefCount == 0 && "Cannot remove non-dead alias set from tracker!"); |
| 66 | AST.removeAliasSet(this); |
| 67 | } |
| 68 | |
Chris Lattner | 31a9d18 | 2003-02-26 22:11:00 +0000 | [diff] [blame] | 69 | void AliasSet::addPointer(AliasSetTracker &AST, HashNodePair &Entry, |
| 70 | unsigned Size) { |
Chris Lattner | 9971ac4 | 2003-02-24 20:37:56 +0000 | [diff] [blame] | 71 | assert(!Entry.second.hasAliasSet() && "Entry already in set!"); |
| 72 | |
| 73 | AliasAnalysis &AA = AST.getAliasAnalysis(); |
| 74 | |
| 75 | if (isMustAlias()) // Check to see if we have to downgrade to _may_ alias |
Chris Lattner | 31a9d18 | 2003-02-26 22:11:00 +0000 | [diff] [blame] | 76 | if (HashNodePair *P = getSomePointer()) { |
| 77 | AliasAnalysis::AliasResult Result = |
| 78 | AA.alias(P->first, P->second.getSize(), Entry.first, Size); |
| 79 | if (Result == AliasAnalysis::MayAlias) |
Chris Lattner | 9971ac4 | 2003-02-24 20:37:56 +0000 | [diff] [blame] | 80 | AliasTy = MayAlias; |
Chris Lattner | 31a9d18 | 2003-02-26 22:11:00 +0000 | [diff] [blame] | 81 | else // First entry of must alias must have maximum size! |
| 82 | P->second.updateSize(Size); |
| 83 | assert(Result != AliasAnalysis::NoAlias && "Cannot be part of must set!"); |
| 84 | } |
Chris Lattner | 9971ac4 | 2003-02-24 20:37:56 +0000 | [diff] [blame] | 85 | |
| 86 | Entry.second.setAliasSet(this); |
Chris Lattner | 31a9d18 | 2003-02-26 22:11:00 +0000 | [diff] [blame] | 87 | Entry.second.updateSize(Size); |
Chris Lattner | 9971ac4 | 2003-02-24 20:37:56 +0000 | [diff] [blame] | 88 | |
| 89 | // Add it to the end of the list... |
Chris Lattner | 2cffeec | 2003-12-18 08:11:56 +0000 | [diff] [blame] | 90 | assert(*PtrListEnd == 0 && "End of list is not null?"); |
| 91 | *PtrListEnd = &Entry; |
| 92 | PtrListEnd = Entry.second.setPrevInList(PtrListEnd); |
Chris Lattner | 9971ac4 | 2003-02-24 20:37:56 +0000 | [diff] [blame] | 93 | RefCount++; // Entry points to alias set... |
| 94 | } |
| 95 | |
Chris Lattner | 5b5f7c1 | 2004-03-15 04:08:36 +0000 | [diff] [blame] | 96 | void AliasSet::addCallSite(CallSite CS, AliasAnalysis &AA) { |
Chris Lattner | 9971ac4 | 2003-02-24 20:37:56 +0000 | [diff] [blame] | 97 | CallSites.push_back(CS); |
Chris Lattner | 5b5f7c1 | 2004-03-15 04:08:36 +0000 | [diff] [blame] | 98 | |
| 99 | if (Function *F = CS.getCalledFunction()) { |
| 100 | if (AA.doesNotAccessMemory(F)) |
| 101 | return; |
| 102 | else if (AA.onlyReadsMemory(F)) { |
| 103 | AliasTy = MayAlias; |
| 104 | AccessTy = Refs; |
| 105 | return; |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | // FIXME: This should use mod/ref information to make this not suck so bad |
| 110 | AliasTy = MayAlias; |
Chris Lattner | 577385e | 2003-05-03 03:42:08 +0000 | [diff] [blame] | 111 | AccessTy = ModRef; |
Chris Lattner | 9971ac4 | 2003-02-24 20:37:56 +0000 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | /// aliasesPointer - Return true if the specified pointer "may" (or must) |
Chris Lattner | 009cc3d | 2002-09-26 21:49:07 +0000 | [diff] [blame] | 115 | /// alias one of the members in the set. |
| 116 | /// |
Chris Lattner | 31a9d18 | 2003-02-26 22:11:00 +0000 | [diff] [blame] | 117 | bool AliasSet::aliasesPointer(const Value *Ptr, unsigned Size, |
| 118 | AliasAnalysis &AA) const { |
Chris Lattner | 9971ac4 | 2003-02-24 20:37:56 +0000 | [diff] [blame] | 119 | if (AliasTy == MustAlias) { |
Chris Lattner | 9971ac4 | 2003-02-24 20:37:56 +0000 | [diff] [blame] | 120 | // If this is a set of MustAliases, only check to see if the pointer aliases |
| 121 | // SOME value in the set... |
Chris Lattner | 31a9d18 | 2003-02-26 22:11:00 +0000 | [diff] [blame] | 122 | HashNodePair *SomePtr = getSomePointer(); |
Chris Lattner | 9971ac4 | 2003-02-24 20:37:56 +0000 | [diff] [blame] | 123 | assert(SomePtr && "Empty must-alias set??"); |
Chris Lattner | 31a9d18 | 2003-02-26 22:11:00 +0000 | [diff] [blame] | 124 | return AA.alias(SomePtr->first, SomePtr->second.getSize(), Ptr, Size); |
Chris Lattner | 9971ac4 | 2003-02-24 20:37:56 +0000 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | // If this is a may-alias set, we have to check all of the pointers in the set |
| 128 | // to be sure it doesn't alias the set... |
| 129 | for (iterator I = begin(), E = end(); I != E; ++I) |
Chris Lattner | 31a9d18 | 2003-02-26 22:11:00 +0000 | [diff] [blame] | 130 | if (AA.alias(Ptr, Size, I->first, I->second.getSize())) |
Chris Lattner | 9971ac4 | 2003-02-24 20:37:56 +0000 | [diff] [blame] | 131 | return true; |
| 132 | |
| 133 | // Check the call sites list and invoke list... |
| 134 | if (!CallSites.empty()) |
| 135 | // FIXME: this is pessimistic! |
Chris Lattner | 009cc3d | 2002-09-26 21:49:07 +0000 | [diff] [blame] | 136 | return true; |
Chris Lattner | 9971ac4 | 2003-02-24 20:37:56 +0000 | [diff] [blame] | 137 | |
Chris Lattner | 009cc3d | 2002-09-26 21:49:07 +0000 | [diff] [blame] | 138 | return false; |
| 139 | } |
| 140 | |
Chris Lattner | 9971ac4 | 2003-02-24 20:37:56 +0000 | [diff] [blame] | 141 | bool AliasSet::aliasesCallSite(CallSite CS, AliasAnalysis &AA) const { |
Chris Lattner | 5b5f7c1 | 2004-03-15 04:08:36 +0000 | [diff] [blame] | 142 | // FIXME: Use mod/ref information to prune this better! |
| 143 | if (Function *F = CS.getCalledFunction()) |
| 144 | if (AA.doesNotAccessMemory(F)) |
| 145 | return false; |
| 146 | |
Chris Lattner | 9971ac4 | 2003-02-24 20:37:56 +0000 | [diff] [blame] | 147 | return true; |
Chris Lattner | 009cc3d | 2002-09-26 21:49:07 +0000 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | |
Chris Lattner | 009cc3d | 2002-09-26 21:49:07 +0000 | [diff] [blame] | 151 | /// findAliasSetForPointer - Given a pointer, find the one alias set to put the |
| 152 | /// instruction referring to the pointer into. If there are multiple alias sets |
| 153 | /// that may alias the pointer, merge them together and return the unified set. |
| 154 | /// |
Chris Lattner | 31a9d18 | 2003-02-26 22:11:00 +0000 | [diff] [blame] | 155 | AliasSet *AliasSetTracker::findAliasSetForPointer(const Value *Ptr, |
| 156 | unsigned Size) { |
Chris Lattner | 009cc3d | 2002-09-26 21:49:07 +0000 | [diff] [blame] | 157 | AliasSet *FoundSet = 0; |
Chris Lattner | 9971ac4 | 2003-02-24 20:37:56 +0000 | [diff] [blame] | 158 | for (iterator I = begin(), E = end(); I != E; ++I) |
Chris Lattner | 31a9d18 | 2003-02-26 22:11:00 +0000 | [diff] [blame] | 159 | if (!I->Forward && I->aliasesPointer(Ptr, Size, AA)) { |
Chris Lattner | 009cc3d | 2002-09-26 21:49:07 +0000 | [diff] [blame] | 160 | if (FoundSet == 0) { // If this is the first alias set ptr can go into... |
Chris Lattner | 9971ac4 | 2003-02-24 20:37:56 +0000 | [diff] [blame] | 161 | FoundSet = I; // Remember it. |
Chris Lattner | 009cc3d | 2002-09-26 21:49:07 +0000 | [diff] [blame] | 162 | } else { // Otherwise, we must merge the sets... |
Chris Lattner | 9971ac4 | 2003-02-24 20:37:56 +0000 | [diff] [blame] | 163 | FoundSet->mergeSetIn(*I); // Merge in contents... |
Chris Lattner | 009cc3d | 2002-09-26 21:49:07 +0000 | [diff] [blame] | 164 | } |
| 165 | } |
Chris Lattner | 9971ac4 | 2003-02-24 20:37:56 +0000 | [diff] [blame] | 166 | |
| 167 | return FoundSet; |
| 168 | } |
| 169 | |
| 170 | AliasSet *AliasSetTracker::findAliasSetForCallSite(CallSite CS) { |
| 171 | AliasSet *FoundSet = 0; |
| 172 | for (iterator I = begin(), E = end(); I != E; ++I) |
Chris Lattner | 2d0a4a4 | 2003-02-26 19:28:57 +0000 | [diff] [blame] | 173 | if (!I->Forward && I->aliasesCallSite(CS, AA)) { |
Chris Lattner | 9971ac4 | 2003-02-24 20:37:56 +0000 | [diff] [blame] | 174 | if (FoundSet == 0) { // If this is the first alias set ptr can go into... |
| 175 | FoundSet = I; // Remember it. |
Chris Lattner | 2d0a4a4 | 2003-02-26 19:28:57 +0000 | [diff] [blame] | 176 | } else if (!I->Forward) { // Otherwise, we must merge the sets... |
Chris Lattner | 9971ac4 | 2003-02-24 20:37:56 +0000 | [diff] [blame] | 177 | FoundSet->mergeSetIn(*I); // Merge in contents... |
| 178 | } |
| 179 | } |
Chris Lattner | 009cc3d | 2002-09-26 21:49:07 +0000 | [diff] [blame] | 180 | |
| 181 | return FoundSet; |
| 182 | } |
| 183 | |
| 184 | |
Chris Lattner | 009cc3d | 2002-09-26 21:49:07 +0000 | [diff] [blame] | 185 | |
Chris Lattner | 9971ac4 | 2003-02-24 20:37:56 +0000 | [diff] [blame] | 186 | |
| 187 | /// getAliasSetForPointer - Return the alias set that the specified pointer |
| 188 | /// lives in... |
Chris Lattner | 31a9d18 | 2003-02-26 22:11:00 +0000 | [diff] [blame] | 189 | AliasSet &AliasSetTracker::getAliasSetForPointer(Value *Pointer, unsigned Size){ |
Chris Lattner | 9971ac4 | 2003-02-24 20:37:56 +0000 | [diff] [blame] | 190 | AliasSet::HashNodePair &Entry = getEntryFor(Pointer); |
| 191 | |
| 192 | // Check to see if the pointer is already known... |
Chris Lattner | 31a9d18 | 2003-02-26 22:11:00 +0000 | [diff] [blame] | 193 | if (Entry.second.hasAliasSet() && Size <= Entry.second.getSize()) { |
Chris Lattner | 9971ac4 | 2003-02-24 20:37:56 +0000 | [diff] [blame] | 194 | // Return the set! |
| 195 | return *Entry.second.getAliasSet(*this)->getForwardedTarget(*this); |
Chris Lattner | 31a9d18 | 2003-02-26 22:11:00 +0000 | [diff] [blame] | 196 | } else if (AliasSet *AS = findAliasSetForPointer(Pointer, Size)) { |
Chris Lattner | 9971ac4 | 2003-02-24 20:37:56 +0000 | [diff] [blame] | 197 | // Add it to the alias set it aliases... |
Chris Lattner | 31a9d18 | 2003-02-26 22:11:00 +0000 | [diff] [blame] | 198 | AS->addPointer(*this, Entry, Size); |
Chris Lattner | 9971ac4 | 2003-02-24 20:37:56 +0000 | [diff] [blame] | 199 | return *AS; |
Chris Lattner | 009cc3d | 2002-09-26 21:49:07 +0000 | [diff] [blame] | 200 | } else { |
Chris Lattner | 9971ac4 | 2003-02-24 20:37:56 +0000 | [diff] [blame] | 201 | // Otherwise create a new alias set to hold the loaded pointer... |
Chris Lattner | 009cc3d | 2002-09-26 21:49:07 +0000 | [diff] [blame] | 202 | AliasSets.push_back(AliasSet()); |
Chris Lattner | 31a9d18 | 2003-02-26 22:11:00 +0000 | [diff] [blame] | 203 | AliasSets.back().addPointer(*this, Entry, Size); |
Chris Lattner | 9971ac4 | 2003-02-24 20:37:56 +0000 | [diff] [blame] | 204 | return AliasSets.back(); |
Chris Lattner | 009cc3d | 2002-09-26 21:49:07 +0000 | [diff] [blame] | 205 | } |
| 206 | } |
| 207 | |
Chris Lattner | 9971ac4 | 2003-02-24 20:37:56 +0000 | [diff] [blame] | 208 | void AliasSetTracker::add(LoadInst *LI) { |
Chris Lattner | e260924 | 2003-12-14 04:52:11 +0000 | [diff] [blame] | 209 | AliasSet &AS = |
| 210 | addPointer(LI->getOperand(0), |
| 211 | AA.getTargetData().getTypeSize(LI->getType()), AliasSet::Refs); |
| 212 | if (LI->isVolatile()) AS.setVolatile(); |
Chris Lattner | 9971ac4 | 2003-02-24 20:37:56 +0000 | [diff] [blame] | 213 | } |
| 214 | |
Chris Lattner | 009cc3d | 2002-09-26 21:49:07 +0000 | [diff] [blame] | 215 | void AliasSetTracker::add(StoreInst *SI) { |
Chris Lattner | e260924 | 2003-12-14 04:52:11 +0000 | [diff] [blame] | 216 | AliasSet &AS = |
| 217 | addPointer(SI->getOperand(1), |
| 218 | AA.getTargetData().getTypeSize(SI->getOperand(0)->getType()), |
| 219 | AliasSet::Mods); |
| 220 | if (SI->isVolatile()) AS.setVolatile(); |
Chris Lattner | 009cc3d | 2002-09-26 21:49:07 +0000 | [diff] [blame] | 221 | } |
| 222 | |
Chris Lattner | e260924 | 2003-12-14 04:52:11 +0000 | [diff] [blame] | 223 | |
Chris Lattner | 9971ac4 | 2003-02-24 20:37:56 +0000 | [diff] [blame] | 224 | void AliasSetTracker::add(CallSite CS) { |
| 225 | AliasSet *AS = findAliasSetForCallSite(CS); |
| 226 | if (!AS) { |
| 227 | AliasSets.push_back(AliasSet()); |
| 228 | AS = &AliasSets.back(); |
| 229 | } |
Chris Lattner | 5b5f7c1 | 2004-03-15 04:08:36 +0000 | [diff] [blame] | 230 | AS->addCallSite(CS, AA); |
Chris Lattner | 009cc3d | 2002-09-26 21:49:07 +0000 | [diff] [blame] | 231 | } |
| 232 | |
Chris Lattner | 9971ac4 | 2003-02-24 20:37:56 +0000 | [diff] [blame] | 233 | void AliasSetTracker::add(Instruction *I) { |
| 234 | // Dispatch to one of the other add methods... |
| 235 | if (LoadInst *LI = dyn_cast<LoadInst>(I)) |
| 236 | add(LI); |
| 237 | else if (StoreInst *SI = dyn_cast<StoreInst>(I)) |
| 238 | add(SI); |
| 239 | else if (CallInst *CI = dyn_cast<CallInst>(I)) |
| 240 | add(CI); |
| 241 | else if (InvokeInst *II = dyn_cast<InvokeInst>(I)) |
| 242 | add(II); |
Chris Lattner | 009cc3d | 2002-09-26 21:49:07 +0000 | [diff] [blame] | 243 | } |
| 244 | |
Chris Lattner | 319d05b | 2003-03-03 23:28:05 +0000 | [diff] [blame] | 245 | void AliasSetTracker::add(BasicBlock &BB) { |
| 246 | for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E; ++I) |
| 247 | add(I); |
| 248 | } |
| 249 | |
| 250 | void AliasSetTracker::add(const AliasSetTracker &AST) { |
| 251 | assert(&AA == &AST.AA && |
| 252 | "Merging AliasSetTracker objects with different Alias Analyses!"); |
| 253 | |
| 254 | // Loop over all of the alias sets in AST, adding the pointers contained |
| 255 | // therein into the current alias sets. This can cause alias sets to be |
| 256 | // merged together in the current AST. |
| 257 | for (const_iterator I = AST.begin(), E = AST.end(); I != E; ++I) |
| 258 | if (!I->Forward) { // Ignore forwarding alias sets |
| 259 | AliasSet &AS = const_cast<AliasSet&>(*I); |
| 260 | |
| 261 | // If there are any call sites in the alias set, add them to this AST. |
| 262 | for (unsigned i = 0, e = AS.CallSites.size(); i != e; ++i) |
| 263 | add(AS.CallSites[i]); |
| 264 | |
| 265 | // Loop over all of the pointers in this alias set... |
| 266 | AliasSet::iterator I = AS.begin(), E = AS.end(); |
| 267 | for (; I != E; ++I) |
| 268 | addPointer(I->first, I->second.getSize(), |
| 269 | (AliasSet::AccessType)AS.AccessTy); |
| 270 | } |
| 271 | } |
| 272 | |
Chris Lattner | 2cffeec | 2003-12-18 08:11:56 +0000 | [diff] [blame] | 273 | |
| 274 | // remove method - This method is used to remove a pointer value from the |
| 275 | // AliasSetTracker entirely. It should be used when an instruction is deleted |
| 276 | // from the program to update the AST. If you don't use this, you would have |
| 277 | // dangling pointers to deleted instructions. |
| 278 | // |
| 279 | void AliasSetTracker::remove(Value *PtrVal) { |
| 280 | // First, look up the PointerRec for this pointer... |
| 281 | hash_map<Value*, AliasSet::PointerRec>::iterator I = PointerMap.find(PtrVal); |
| 282 | if (I == PointerMap.end()) return; // Noop |
| 283 | |
| 284 | // If we found one, remove the pointer from the alias set it is in. |
| 285 | AliasSet::HashNodePair &PtrValEnt = *I; |
| 286 | AliasSet *AS = PtrValEnt.second.getAliasSet(*this); |
| 287 | |
| 288 | // Unlink from the list of values... |
| 289 | PtrValEnt.second.removeFromList(); |
| 290 | // Stop using the alias set |
| 291 | if (--AS->RefCount == 0) |
| 292 | AS->removeFromTracker(*this); |
| 293 | |
| 294 | PointerMap.erase(I); |
| 295 | } |
| 296 | |
| 297 | |
Chris Lattner | 9971ac4 | 2003-02-24 20:37:56 +0000 | [diff] [blame] | 298 | //===----------------------------------------------------------------------===// |
| 299 | // AliasSet/AliasSetTracker Printing Support |
| 300 | //===----------------------------------------------------------------------===// |
| 301 | |
| 302 | void AliasSet::print(std::ostream &OS) const { |
| 303 | OS << " AliasSet[" << (void*)this << "," << RefCount << "] "; |
| 304 | OS << (AliasTy == MustAlias ? "must" : "may ") << " alias, "; |
| 305 | switch (AccessTy) { |
| 306 | case NoModRef: OS << "No access "; break; |
| 307 | case Refs : OS << "Ref "; break; |
| 308 | case Mods : OS << "Mod "; break; |
| 309 | case ModRef : OS << "Mod/Ref "; break; |
| 310 | default: assert(0 && "Bad value for AccessTy!"); |
Chris Lattner | 009cc3d | 2002-09-26 21:49:07 +0000 | [diff] [blame] | 311 | } |
Chris Lattner | e260924 | 2003-12-14 04:52:11 +0000 | [diff] [blame] | 312 | if (isVolatile()) OS << "[volatile] "; |
Chris Lattner | 9971ac4 | 2003-02-24 20:37:56 +0000 | [diff] [blame] | 313 | if (Forward) |
| 314 | OS << " forwarding to " << (void*)Forward; |
| 315 | |
| 316 | |
| 317 | if (begin() != end()) { |
| 318 | OS << "Pointers: "; |
| 319 | for (iterator I = begin(), E = end(); I != E; ++I) { |
| 320 | if (I != begin()) OS << ", "; |
Chris Lattner | 31a9d18 | 2003-02-26 22:11:00 +0000 | [diff] [blame] | 321 | WriteAsOperand(OS << "(", I->first); |
| 322 | OS << ", " << I->second.getSize() << ")"; |
Chris Lattner | 9971ac4 | 2003-02-24 20:37:56 +0000 | [diff] [blame] | 323 | } |
| 324 | } |
| 325 | if (!CallSites.empty()) { |
| 326 | OS << "\n " << CallSites.size() << " Call Sites: "; |
| 327 | for (unsigned i = 0, e = CallSites.size(); i != e; ++i) { |
| 328 | if (i) OS << ", "; |
| 329 | WriteAsOperand(OS, CallSites[i].getCalledValue()); |
| 330 | } |
| 331 | } |
| 332 | OS << "\n"; |
| 333 | } |
| 334 | |
| 335 | void AliasSetTracker::print(std::ostream &OS) const { |
| 336 | OS << "Alias Set Tracker: " << AliasSets.size() << " alias sets for " |
| 337 | << PointerMap.size() << " pointer values.\n"; |
| 338 | for (const_iterator I = begin(), E = end(); I != E; ++I) |
| 339 | I->print(OS); |
| 340 | OS << "\n"; |
| 341 | } |
| 342 | |
| 343 | void AliasSet::dump() const { print (std::cerr); } |
| 344 | void AliasSetTracker::dump() const { print(std::cerr); } |
| 345 | |
Chris Lattner | 9971ac4 | 2003-02-24 20:37:56 +0000 | [diff] [blame] | 346 | //===----------------------------------------------------------------------===// |
| 347 | // AliasSetPrinter Pass |
| 348 | //===----------------------------------------------------------------------===// |
| 349 | |
| 350 | namespace { |
| 351 | class AliasSetPrinter : public FunctionPass { |
| 352 | AliasSetTracker *Tracker; |
| 353 | public: |
| 354 | virtual void getAnalysisUsage(AnalysisUsage &AU) const { |
| 355 | AU.setPreservesAll(); |
| 356 | AU.addRequired<AliasAnalysis>(); |
| 357 | } |
| 358 | |
| 359 | virtual bool runOnFunction(Function &F) { |
| 360 | Tracker = new AliasSetTracker(getAnalysis<AliasAnalysis>()); |
| 361 | |
| 362 | for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) |
| 363 | Tracker->add(*I); |
| 364 | return false; |
| 365 | } |
| 366 | |
| 367 | /// print - Convert to human readable form |
| 368 | virtual void print(std::ostream &OS) const { |
| 369 | Tracker->print(OS); |
| 370 | } |
| 371 | |
| 372 | virtual void releaseMemory() { |
| 373 | delete Tracker; |
| 374 | } |
| 375 | }; |
| 376 | RegisterPass<AliasSetPrinter> X("print-alias-sets", "Alias Set Printer", |
| 377 | PassInfo::Analysis | PassInfo::Optimization); |
Chris Lattner | 009cc3d | 2002-09-26 21:49:07 +0000 | [diff] [blame] | 378 | } |