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