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