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