LLVM API Documentation
00001 //===- AliasSetTracker.cpp - Alias Sets Tracker implementation-------------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file implements the AliasSetTracker and AliasSet classes. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #include "llvm/Analysis/AliasSetTracker.h" 00015 #include "llvm/Analysis/AliasAnalysis.h" 00016 #include "llvm/Instructions.h" 00017 #include "llvm/IntrinsicInst.h" 00018 #include "llvm/Pass.h" 00019 #include "llvm/Type.h" 00020 #include "llvm/Target/TargetData.h" 00021 #include "llvm/Assembly/Writer.h" 00022 #include "llvm/Support/Compiler.h" 00023 #include "llvm/Support/ErrorHandling.h" 00024 #include "llvm/Support/InstIterator.h" 00025 #include "llvm/Support/Streams.h" 00026 using namespace llvm; 00027 00028 /// mergeSetIn - Merge the specified alias set into this alias set. 00029 /// 00030 void AliasSet::mergeSetIn(AliasSet &AS, AliasSetTracker &AST) { 00031 assert(!AS.Forward && "Alias set is already forwarding!"); 00032 assert(!Forward && "This set is a forwarding set!!"); 00033 00034 // Update the alias and access types of this set... 00035 AccessTy |= AS.AccessTy; 00036 AliasTy |= AS.AliasTy; 00037 00038 if (AliasTy == MustAlias) { 00039 // Check that these two merged sets really are must aliases. Since both 00040 // used to be must-alias sets, we can just check any pointer from each set 00041 // for aliasing. 00042 AliasAnalysis &AA = AST.getAliasAnalysis(); 00043 PointerRec *L = getSomePointer(); 00044 PointerRec *R = AS.getSomePointer(); 00045 00046 // If the pointers are not a must-alias pair, this set becomes a may alias. 00047 if (AA.alias(L->getValue(), L->getSize(), R->getValue(), R->getSize()) 00048 != AliasAnalysis::MustAlias) 00049 AliasTy = MayAlias; 00050 } 00051 00052 if (CallSites.empty()) { // Merge call sites... 00053 if (!AS.CallSites.empty()) 00054 std::swap(CallSites, AS.CallSites); 00055 } else if (!AS.CallSites.empty()) { 00056 CallSites.insert(CallSites.end(), AS.CallSites.begin(), AS.CallSites.end()); 00057 AS.CallSites.clear(); 00058 } 00059 00060 AS.Forward = this; // Forward across AS now... 00061 addRef(); // AS is now pointing to us... 00062 00063 // Merge the list of constituent pointers... 00064 if (AS.PtrList) { 00065 *PtrListEnd = AS.PtrList; 00066 AS.PtrList->setPrevInList(PtrListEnd); 00067 PtrListEnd = AS.PtrListEnd; 00068 00069 AS.PtrList = 0; 00070 AS.PtrListEnd = &AS.PtrList; 00071 assert(*AS.PtrListEnd == 0 && "End of list is not null?"); 00072 } 00073 } 00074 00075 void AliasSetTracker::removeAliasSet(AliasSet *AS) { 00076 if (AliasSet *Fwd = AS->Forward) { 00077 Fwd->dropRef(*this); 00078 AS->Forward = 0; 00079 } 00080 AliasSets.erase(AS); 00081 } 00082 00083 void AliasSet::removeFromTracker(AliasSetTracker &AST) { 00084 assert(RefCount == 0 && "Cannot remove non-dead alias set from tracker!"); 00085 AST.removeAliasSet(this); 00086 } 00087 00088 void AliasSet::addPointer(AliasSetTracker &AST, PointerRec &Entry, 00089 unsigned Size, bool KnownMustAlias) { 00090 assert(!Entry.hasAliasSet() && "Entry already in set!"); 00091 00092 // Check to see if we have to downgrade to _may_ alias. 00093 if (isMustAlias() && !KnownMustAlias) 00094 if (PointerRec *P = getSomePointer()) { 00095 AliasAnalysis &AA = AST.getAliasAnalysis(); 00096 AliasAnalysis::AliasResult Result = 00097 AA.alias(P->getValue(), P->getSize(), Entry.getValue(), Size); 00098 if (Result == AliasAnalysis::MayAlias) 00099 AliasTy = MayAlias; 00100 else // First entry of must alias must have maximum size! 00101 P->updateSize(Size); 00102 assert(Result != AliasAnalysis::NoAlias && "Cannot be part of must set!"); 00103 } 00104 00105 Entry.setAliasSet(this); 00106 Entry.updateSize(Size); 00107 00108 // Add it to the end of the list... 00109 assert(*PtrListEnd == 0 && "End of list is not null?"); 00110 *PtrListEnd = &Entry; 00111 PtrListEnd = Entry.setPrevInList(PtrListEnd); 00112 assert(*PtrListEnd == 0 && "End of list is not null?"); 00113 addRef(); // Entry points to alias set... 00114 } 00115 00116 void AliasSet::addCallSite(CallSite CS, AliasAnalysis &AA) { 00117 CallSites.push_back(CS); 00118 00119 AliasAnalysis::ModRefBehavior Behavior = AA.getModRefBehavior(CS); 00120 if (Behavior == AliasAnalysis::DoesNotAccessMemory) 00121 return; 00122 else if (Behavior == AliasAnalysis::OnlyReadsMemory) { 00123 AliasTy = MayAlias; 00124 AccessTy |= Refs; 00125 return; 00126 } 00127 00128 // FIXME: This should use mod/ref information to make this not suck so bad 00129 AliasTy = MayAlias; 00130 AccessTy = ModRef; 00131 } 00132 00133 /// aliasesPointer - Return true if the specified pointer "may" (or must) 00134 /// alias one of the members in the set. 00135 /// 00136 bool AliasSet::aliasesPointer(const Value *Ptr, unsigned Size, 00137 AliasAnalysis &AA) const { 00138 if (AliasTy == MustAlias) { 00139 assert(CallSites.empty() && "Illegal must alias set!"); 00140 00141 // If this is a set of MustAliases, only check to see if the pointer aliases 00142 // SOME value in the set... 00143 PointerRec *SomePtr = getSomePointer(); 00144 assert(SomePtr && "Empty must-alias set??"); 00145 return AA.alias(SomePtr->getValue(), SomePtr->getSize(), Ptr, Size); 00146 } 00147 00148 // If this is a may-alias set, we have to check all of the pointers in the set 00149 // to be sure it doesn't alias the set... 00150 for (iterator I = begin(), E = end(); I != E; ++I) 00151 if (AA.alias(Ptr, Size, I.getPointer(), I.getSize())) 00152 return true; 00153 00154 // Check the call sites list and invoke list... 00155 if (!CallSites.empty()) { 00156 if (AA.hasNoModRefInfoForCalls()) 00157 return true; 00158 00159 for (unsigned i = 0, e = CallSites.size(); i != e; ++i) 00160 if (AA.getModRefInfo(CallSites[i], const_cast<Value*>(Ptr), Size) 00161 != AliasAnalysis::NoModRef) 00162 return true; 00163 } 00164 00165 return false; 00166 } 00167 00168 bool AliasSet::aliasesCallSite(CallSite CS, AliasAnalysis &AA) const { 00169 if (AA.doesNotAccessMemory(CS)) 00170 return false; 00171 00172 if (AA.hasNoModRefInfoForCalls()) 00173 return true; 00174 00175 for (unsigned i = 0, e = CallSites.size(); i != e; ++i) 00176 if (AA.getModRefInfo(CallSites[i], CS) != AliasAnalysis::NoModRef || 00177 AA.getModRefInfo(CS, CallSites[i]) != AliasAnalysis::NoModRef) 00178 return true; 00179 00180 for (iterator I = begin(), E = end(); I != E; ++I) 00181 if (AA.getModRefInfo(CS, I.getPointer(), I.getSize()) != 00182 AliasAnalysis::NoModRef) 00183 return true; 00184 00185 return false; 00186 } 00187 00188 void AliasSetTracker::clear() { 00189 // Delete all the PointerRec entries. 00190 for (PointerMapType::iterator I = PointerMap.begin(), E = PointerMap.end(); 00191 I != E; ++I) 00192 I->second->eraseFromList(); 00193 00194 PointerMap.clear(); 00195 00196 // The alias sets should all be clear now. 00197 AliasSets.clear(); 00198 } 00199 00200 00201 /// findAliasSetForPointer - Given a pointer, find the one alias set to put the 00202 /// instruction referring to the pointer into. If there are multiple alias sets 00203 /// that may alias the pointer, merge them together and return the unified set. 00204 /// 00205 AliasSet *AliasSetTracker::findAliasSetForPointer(const Value *Ptr, 00206 unsigned Size) { 00207 AliasSet *FoundSet = 0; 00208 for (iterator I = begin(), E = end(); I != E; ++I) 00209 if (!I->Forward && I->aliasesPointer(Ptr, Size, AA)) { 00210 if (FoundSet == 0) { // If this is the first alias set ptr can go into. 00211 FoundSet = I; // Remember it. 00212 } else { // Otherwise, we must merge the sets. 00213 FoundSet->mergeSetIn(*I, *this); // Merge in contents. 00214 } 00215 } 00216 00217 return FoundSet; 00218 } 00219 00220 /// containsPointer - Return true if the specified location is represented by 00221 /// this alias set, false otherwise. This does not modify the AST object or 00222 /// alias sets. 00223 bool AliasSetTracker::containsPointer(Value *Ptr, unsigned Size) const { 00224 for (const_iterator I = begin(), E = end(); I != E; ++I) 00225 if (!I->Forward && I->aliasesPointer(Ptr, Size, AA)) 00226 return true; 00227 return false; 00228 } 00229 00230 00231 00232 AliasSet *AliasSetTracker::findAliasSetForCallSite(CallSite CS) { 00233 AliasSet *FoundSet = 0; 00234 for (iterator I = begin(), E = end(); I != E; ++I) 00235 if (!I->Forward && I->aliasesCallSite(CS, AA)) { 00236 if (FoundSet == 0) { // If this is the first alias set ptr can go into. 00237 FoundSet = I; // Remember it. 00238 } else if (!I->Forward) { // Otherwise, we must merge the sets. 00239 FoundSet->mergeSetIn(*I, *this); // Merge in contents. 00240 } 00241 } 00242 00243 return FoundSet; 00244 } 00245 00246 00247 00248 00249 /// getAliasSetForPointer - Return the alias set that the specified pointer 00250 /// lives in. 00251 AliasSet &AliasSetTracker::getAliasSetForPointer(Value *Pointer, unsigned Size, 00252 bool *New) { 00253 AliasSet::PointerRec &Entry = getEntryFor(Pointer); 00254 00255 // Check to see if the pointer is already known... 00256 if (Entry.hasAliasSet()) { 00257 Entry.updateSize(Size); 00258 // Return the set! 00259 return *Entry.getAliasSet(*this)->getForwardedTarget(*this); 00260 } else if (AliasSet *AS = findAliasSetForPointer(Pointer, Size)) { 00261 // Add it to the alias set it aliases... 00262 AS->addPointer(*this, Entry, Size); 00263 return *AS; 00264 } else { 00265 if (New) *New = true; 00266 // Otherwise create a new alias set to hold the loaded pointer... 00267 AliasSets.push_back(new AliasSet()); 00268 AliasSets.back().addPointer(*this, Entry, Size); 00269 return AliasSets.back(); 00270 } 00271 } 00272 00273 bool AliasSetTracker::add(Value *Ptr, unsigned Size) { 00274 bool NewPtr; 00275 addPointer(Ptr, Size, AliasSet::NoModRef, NewPtr); 00276 return NewPtr; 00277 } 00278 00279 00280 bool AliasSetTracker::add(LoadInst *LI) { 00281 bool NewPtr; 00282 AliasSet &AS = addPointer(LI->getOperand(0), 00283 AA.getTypeStoreSize(LI->getType()), 00284 AliasSet::Refs, NewPtr); 00285 if (LI->isVolatile()) AS.setVolatile(); 00286 return NewPtr; 00287 } 00288 00289 bool AliasSetTracker::add(StoreInst *SI) { 00290 bool NewPtr; 00291 Value *Val = SI->getOperand(0); 00292 AliasSet &AS = addPointer(SI->getOperand(1), 00293 AA.getTypeStoreSize(Val->getType()), 00294 AliasSet::Mods, NewPtr); 00295 if (SI->isVolatile()) AS.setVolatile(); 00296 return NewPtr; 00297 } 00298 00299 bool AliasSetTracker::add(FreeInst *FI) { 00300 bool NewPtr; 00301 addPointer(FI->getOperand(0), ~0, AliasSet::Mods, NewPtr); 00302 return NewPtr; 00303 } 00304 00305 bool AliasSetTracker::add(VAArgInst *VAAI) { 00306 bool NewPtr; 00307 addPointer(VAAI->getOperand(0), ~0, AliasSet::ModRef, NewPtr); 00308 return NewPtr; 00309 } 00310 00311 00312 bool AliasSetTracker::add(CallSite CS) { 00313 if (isa<DbgInfoIntrinsic>(CS.getInstruction())) 00314 return true; // Ignore DbgInfo Intrinsics. 00315 if (AA.doesNotAccessMemory(CS)) 00316 return true; // doesn't alias anything 00317 00318 AliasSet *AS = findAliasSetForCallSite(CS); 00319 if (!AS) { 00320 AliasSets.push_back(new AliasSet()); 00321 AS = &AliasSets.back(); 00322 AS->addCallSite(CS, AA); 00323 return true; 00324 } else { 00325 AS->addCallSite(CS, AA); 00326 return false; 00327 } 00328 } 00329 00330 bool AliasSetTracker::add(Instruction *I) { 00331 // Dispatch to one of the other add methods... 00332 if (LoadInst *LI = dyn_cast<LoadInst>(I)) 00333 return add(LI); 00334 else if (StoreInst *SI = dyn_cast<StoreInst>(I)) 00335 return add(SI); 00336 else if (CallInst *CI = dyn_cast<CallInst>(I)) 00337 return add(CI); 00338 else if (InvokeInst *II = dyn_cast<InvokeInst>(I)) 00339 return add(II); 00340 else if (FreeInst *FI = dyn_cast<FreeInst>(I)) 00341 return add(FI); 00342 else if (VAArgInst *VAAI = dyn_cast<VAArgInst>(I)) 00343 return add(VAAI); 00344 return true; 00345 } 00346 00347 void AliasSetTracker::add(BasicBlock &BB) { 00348 for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E; ++I) 00349 add(I); 00350 } 00351 00352 void AliasSetTracker::add(const AliasSetTracker &AST) { 00353 assert(&AA == &AST.AA && 00354 "Merging AliasSetTracker objects with different Alias Analyses!"); 00355 00356 // Loop over all of the alias sets in AST, adding the pointers contained 00357 // therein into the current alias sets. This can cause alias sets to be 00358 // merged together in the current AST. 00359 for (const_iterator I = AST.begin(), E = AST.end(); I != E; ++I) 00360 if (!I->Forward) { // Ignore forwarding alias sets 00361 AliasSet &AS = const_cast<AliasSet&>(*I); 00362 00363 // If there are any call sites in the alias set, add them to this AST. 00364 for (unsigned i = 0, e = AS.CallSites.size(); i != e; ++i) 00365 add(AS.CallSites[i]); 00366 00367 // Loop over all of the pointers in this alias set... 00368 AliasSet::iterator I = AS.begin(), E = AS.end(); 00369 bool X; 00370 for (; I != E; ++I) { 00371 AliasSet &NewAS = addPointer(I.getPointer(), I.getSize(), 00372 (AliasSet::AccessType)AS.AccessTy, X); 00373 if (AS.isVolatile()) NewAS.setVolatile(); 00374 } 00375 } 00376 } 00377 00378 /// remove - Remove the specified (potentially non-empty) alias set from the 00379 /// tracker. 00380 void AliasSetTracker::remove(AliasSet &AS) { 00381 // Drop all call sites. 00382 AS.CallSites.clear(); 00383 00384 // Clear the alias set. 00385 unsigned NumRefs = 0; 00386 while (!AS.empty()) { 00387 AliasSet::PointerRec *P = AS.PtrList; 00388 00389 Value *ValToRemove = P->getValue(); 00390 00391 // Unlink and delete entry from the list of values. 00392 P->eraseFromList(); 00393 00394 // Remember how many references need to be dropped. 00395 ++NumRefs; 00396 00397 // Finally, remove the entry. 00398 PointerMap.erase(ValToRemove); 00399 } 00400 00401 // Stop using the alias set, removing it. 00402 AS.RefCount -= NumRefs; 00403 if (AS.RefCount == 0) 00404 AS.removeFromTracker(*this); 00405 } 00406 00407 bool AliasSetTracker::remove(Value *Ptr, unsigned Size) { 00408 AliasSet *AS = findAliasSetForPointer(Ptr, Size); 00409 if (!AS) return false; 00410 remove(*AS); 00411 return true; 00412 } 00413 00414 bool AliasSetTracker::remove(LoadInst *LI) { 00415 unsigned Size = AA.getTypeStoreSize(LI->getType()); 00416 AliasSet *AS = findAliasSetForPointer(LI->getOperand(0), Size); 00417 if (!AS) return false; 00418 remove(*AS); 00419 return true; 00420 } 00421 00422 bool AliasSetTracker::remove(StoreInst *SI) { 00423 unsigned Size = AA.getTypeStoreSize(SI->getOperand(0)->getType()); 00424 AliasSet *AS = findAliasSetForPointer(SI->getOperand(1), Size); 00425 if (!AS) return false; 00426 remove(*AS); 00427 return true; 00428 } 00429 00430 bool AliasSetTracker::remove(FreeInst *FI) { 00431 AliasSet *AS = findAliasSetForPointer(FI->getOperand(0), ~0); 00432 if (!AS) return false; 00433 remove(*AS); 00434 return true; 00435 } 00436 00437 bool AliasSetTracker::remove(VAArgInst *VAAI) { 00438 AliasSet *AS = findAliasSetForPointer(VAAI->getOperand(0), ~0); 00439 if (!AS) return false; 00440 remove(*AS); 00441 return true; 00442 } 00443 00444 bool AliasSetTracker::remove(CallSite CS) { 00445 if (AA.doesNotAccessMemory(CS)) 00446 return false; // doesn't alias anything 00447 00448 AliasSet *AS = findAliasSetForCallSite(CS); 00449 if (!AS) return false; 00450 remove(*AS); 00451 return true; 00452 } 00453 00454 bool AliasSetTracker::remove(Instruction *I) { 00455 // Dispatch to one of the other remove methods... 00456 if (LoadInst *LI = dyn_cast<LoadInst>(I)) 00457 return remove(LI); 00458 else if (StoreInst *SI = dyn_cast<StoreInst>(I)) 00459 return remove(SI); 00460 else if (CallInst *CI = dyn_cast<CallInst>(I)) 00461 return remove(CI); 00462 else if (FreeInst *FI = dyn_cast<FreeInst>(I)) 00463 return remove(FI); 00464 else if (VAArgInst *VAAI = dyn_cast<VAArgInst>(I)) 00465 return remove(VAAI); 00466 return true; 00467 } 00468 00469 00470 // deleteValue method - This method is used to remove a pointer value from the 00471 // AliasSetTracker entirely. It should be used when an instruction is deleted 00472 // from the program to update the AST. If you don't use this, you would have 00473 // dangling pointers to deleted instructions. 00474 // 00475 void AliasSetTracker::deleteValue(Value *PtrVal) { 00476 // Notify the alias analysis implementation that this value is gone. 00477 AA.deleteValue(PtrVal); 00478 00479 // If this is a call instruction, remove the callsite from the appropriate 00480 // AliasSet. 00481 CallSite CS = CallSite::get(PtrVal); 00482 if (CS.getInstruction()) 00483 if (!AA.doesNotAccessMemory(CS)) 00484 if (AliasSet *AS = findAliasSetForCallSite(CS)) 00485 AS->removeCallSite(CS); 00486 00487 // First, look up the PointerRec for this pointer. 00488 PointerMapType::iterator I = PointerMap.find(PtrVal); 00489 if (I == PointerMap.end()) return; // Noop 00490 00491 // If we found one, remove the pointer from the alias set it is in. 00492 AliasSet::PointerRec *PtrValEnt = I->second; 00493 AliasSet *AS = PtrValEnt->getAliasSet(*this); 00494 00495 // Unlink and delete from the list of values. 00496 PtrValEnt->eraseFromList(); 00497 00498 // Stop using the alias set. 00499 AS->dropRef(*this); 00500 00501 PointerMap.erase(I); 00502 } 00503 00504 // copyValue - This method should be used whenever a preexisting value in the 00505 // program is copied or cloned, introducing a new value. Note that it is ok for 00506 // clients that use this method to introduce the same value multiple times: if 00507 // the tracker already knows about a value, it will ignore the request. 00508 // 00509 void AliasSetTracker::copyValue(Value *From, Value *To) { 00510 // Notify the alias analysis implementation that this value is copied. 00511 AA.copyValue(From, To); 00512 00513 // First, look up the PointerRec for this pointer. 00514 PointerMapType::iterator I = PointerMap.find(From); 00515 if (I == PointerMap.end()) 00516 return; // Noop 00517 assert(I->second->hasAliasSet() && "Dead entry?"); 00518 00519 AliasSet::PointerRec &Entry = getEntryFor(To); 00520 if (Entry.hasAliasSet()) return; // Already in the tracker! 00521 00522 // Add it to the alias set it aliases... 00523 I = PointerMap.find(From); 00524 AliasSet *AS = I->second->getAliasSet(*this); 00525 AS->addPointer(*this, Entry, I->second->getSize(), true); 00526 } 00527 00528 00529 00530 //===----------------------------------------------------------------------===// 00531 // AliasSet/AliasSetTracker Printing Support 00532 //===----------------------------------------------------------------------===// 00533 00534 void AliasSet::print(std::ostream &OS) const { 00535 OS << " AliasSet[" << (void*)this << "," << RefCount << "] "; 00536 OS << (AliasTy == MustAlias ? "must" : "may") << " alias, "; 00537 switch (AccessTy) { 00538 case NoModRef: OS << "No access "; break; 00539 case Refs : OS << "Ref "; break; 00540 case Mods : OS << "Mod "; break; 00541 case ModRef : OS << "Mod/Ref "; break; 00542 default: llvm_unreachable("Bad value for AccessTy!"); 00543 } 00544 if (isVolatile()) OS << "[volatile] "; 00545 if (Forward) 00546 OS << " forwarding to " << (void*)Forward; 00547 00548 00549 if (!empty()) { 00550 OS << "Pointers: "; 00551 for (iterator I = begin(), E = end(); I != E; ++I) { 00552 if (I != begin()) OS << ", "; 00553 WriteAsOperand(OS << "(", I.getPointer()); 00554 OS << ", " << I.getSize() << ")"; 00555 } 00556 } 00557 if (!CallSites.empty()) { 00558 OS << "\n " << CallSites.size() << " Call Sites: "; 00559 for (unsigned i = 0, e = CallSites.size(); i != e; ++i) { 00560 if (i) OS << ", "; 00561 WriteAsOperand(OS, CallSites[i].getCalledValue()); 00562 } 00563 } 00564 OS << "\n"; 00565 } 00566 00567 void AliasSetTracker::print(std::ostream &OS) const { 00568 OS << "Alias Set Tracker: " << AliasSets.size() << " alias sets for " 00569 << PointerMap.size() << " pointer values.\n"; 00570 for (const_iterator I = begin(), E = end(); I != E; ++I) 00571 I->print(OS); 00572 OS << "\n"; 00573 } 00574 00575 void AliasSet::dump() const { print (cerr); } 00576 void AliasSetTracker::dump() const { print(cerr); } 00577 00578 //===----------------------------------------------------------------------===// 00579 // ASTCallbackVH Class Implementation 00580 //===----------------------------------------------------------------------===// 00581 00582 void AliasSetTracker::ASTCallbackVH::deleted() { 00583 assert(AST && "ASTCallbackVH called with a null AliasSetTracker!"); 00584 AST->deleteValue(getValPtr()); 00585 // this now dangles! 00586 } 00587 00588 AliasSetTracker::ASTCallbackVH::ASTCallbackVH(Value *V, AliasSetTracker *ast) 00589 : CallbackVH(V), AST(ast) {} 00590 00591 AliasSetTracker::ASTCallbackVH & 00592 AliasSetTracker::ASTCallbackVH::operator=(Value *V) { 00593 return *this = ASTCallbackVH(V, AST); 00594 } 00595 00596 //===----------------------------------------------------------------------===// 00597 // AliasSetPrinter Pass 00598 //===----------------------------------------------------------------------===// 00599 00600 namespace { 00601 class VISIBILITY_HIDDEN AliasSetPrinter : public FunctionPass { 00602 AliasSetTracker *Tracker; 00603 public: 00604 static char ID; // Pass identification, replacement for typeid 00605 AliasSetPrinter() : FunctionPass(&ID) {} 00606 00607 virtual void getAnalysisUsage(AnalysisUsage &AU) const { 00608 AU.setPreservesAll(); 00609 AU.addRequired<AliasAnalysis>(); 00610 } 00611 00612 virtual bool runOnFunction(Function &F) { 00613 Tracker = new AliasSetTracker(getAnalysis<AliasAnalysis>()); 00614 00615 for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) 00616 Tracker->add(&*I); 00617 Tracker->print(cerr); 00618 delete Tracker; 00619 return false; 00620 } 00621 }; 00622 } 00623 00624 char AliasSetPrinter::ID = 0; 00625 static RegisterPass<AliasSetPrinter> 00626 X("print-alias-sets", "Alias Set Printer", false, true);