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