1 //===- llvm/Analysis/AliasAnalysis.h - Alias Analysis Interface -*- C++ -*-===// 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 defines the generic AliasAnalysis interface, which is used as the 11 // common interface used by all clients of alias analysis information, and 12 // implemented by all alias analysis implementations. Mod/Ref information is 13 // also captured by this interface. 14 // 15 // Implementations of this interface must implement the various virtual methods, 16 // which automatically provides functionality for the entire suite of client 17 // APIs. 18 // 19 // This API identifies memory regions with the Location class. The pointer 20 // component specifies the base memory address of the region. The Size specifies 21 // the maximum size (in address units) of the memory region, or UnknownSize if 22 // the size is not known. The TBAA tag identifies the "type" of the memory 23 // reference; see the TypeBasedAliasAnalysis class for details. 24 // 25 // Some non-obvious details include: 26 // - Pointers that point to two completely different objects in memory never 27 // alias, regardless of the value of the Size component. 28 // - NoAlias doesn't imply inequal pointers. The most obvious example of this 29 // is two pointers to constant memory. Even if they are equal, constant 30 // memory is never stored to, so there will never be any dependencies. 31 // In this and other situations, the pointers may be both NoAlias and 32 // MustAlias at the same time. The current API can only return one result, 33 // though this is rarely a problem in practice. 34 // 35 //===----------------------------------------------------------------------===// 36 37 #ifndef LLVM_ANALYSIS_ALIASANALYSIS_H 38 #define LLVM_ANALYSIS_ALIASANALYSIS_H 39 40 #include "llvm/ADT/DenseMap.h" 41 #include "llvm/IR/CallSite.h" 42 #include "llvm/IR/Metadata.h" 43 44 namespace llvm { 45 46 class LoadInst; 47 class StoreInst; 48 class VAArgInst; 49 class DataLayout; 50 class TargetLibraryInfo; 51 class Pass; 52 class AnalysisUsage; 53 class MemTransferInst; 54 class MemIntrinsic; 55 class DominatorTree; 56 57 class AliasAnalysis { 58 protected: 59 const DataLayout *DL; 60 const TargetLibraryInfo *TLI; 61 62 private: 63 AliasAnalysis *AA; // Previous Alias Analysis to chain to. 64 65 protected: 66 /// InitializeAliasAnalysis - Subclasses must call this method to initialize 67 /// the AliasAnalysis interface before any other methods are called. This is 68 /// typically called by the run* methods of these subclasses. This may be 69 /// called multiple times. 70 /// 71 void InitializeAliasAnalysis(Pass *P, const DataLayout *DL); 72 73 /// getAnalysisUsage - All alias analysis implementations should invoke this 74 /// directly (using AliasAnalysis::getAnalysisUsage(AU)). 75 virtual void getAnalysisUsage(AnalysisUsage &AU) const; 76 77 public: 78 static char ID; // Class identification, replacement for typeinfo AliasAnalysis()79 AliasAnalysis() : DL(nullptr), TLI(nullptr), AA(nullptr) {} 80 virtual ~AliasAnalysis(); // We want to be subclassed 81 82 /// UnknownSize - This is a special value which can be used with the 83 /// size arguments in alias queries to indicate that the caller does not 84 /// know the sizes of the potential memory references. 85 static uint64_t const UnknownSize = ~UINT64_C(0); 86 87 /// getTargetLibraryInfo - Return a pointer to the current TargetLibraryInfo 88 /// object, or null if no TargetLibraryInfo object is available. 89 /// getTargetLibraryInfo()90 const TargetLibraryInfo *getTargetLibraryInfo() const { return TLI; } 91 92 /// getTypeStoreSize - Return the DataLayout store size for the given type, 93 /// if known, or a conservative value otherwise. 94 /// 95 uint64_t getTypeStoreSize(Type *Ty); 96 97 //===--------------------------------------------------------------------===// 98 /// Alias Queries... 99 /// 100 101 /// Location - A description of a memory location. 102 struct Location { 103 /// Ptr - The address of the start of the location. 104 const Value *Ptr; 105 /// Size - The maximum size of the location, in address-units, or 106 /// UnknownSize if the size is not known. Note that an unknown size does 107 /// not mean the pointer aliases the entire virtual address space, because 108 /// there are restrictions on stepping out of one object and into another. 109 /// See http://llvm.org/docs/LangRef.html#pointeraliasing 110 uint64_t Size; 111 /// AATags - The metadata nodes which describes the aliasing of the 112 /// location (each member is null if that kind of information is 113 /// unavailable).. 114 AAMDNodes AATags; 115 116 explicit Location(const Value *P = nullptr, uint64_t S = UnknownSize, 117 const AAMDNodes &N = AAMDNodes()) PtrLocation118 : Ptr(P), Size(S), AATags(N) {} 119 getWithNewPtrLocation120 Location getWithNewPtr(const Value *NewPtr) const { 121 Location Copy(*this); 122 Copy.Ptr = NewPtr; 123 return Copy; 124 } 125 getWithNewSizeLocation126 Location getWithNewSize(uint64_t NewSize) const { 127 Location Copy(*this); 128 Copy.Size = NewSize; 129 return Copy; 130 } 131 getWithoutAATagsLocation132 Location getWithoutAATags() const { 133 Location Copy(*this); 134 Copy.AATags = AAMDNodes(); 135 return Copy; 136 } 137 }; 138 139 /// getLocation - Fill in Loc with information about the memory reference by 140 /// the given instruction. 141 Location getLocation(const LoadInst *LI); 142 Location getLocation(const StoreInst *SI); 143 Location getLocation(const VAArgInst *VI); 144 Location getLocation(const AtomicCmpXchgInst *CXI); 145 Location getLocation(const AtomicRMWInst *RMWI); 146 static Location getLocationForSource(const MemTransferInst *MTI); 147 static Location getLocationForDest(const MemIntrinsic *MI); getLocation(const Instruction * Inst)148 Location getLocation(const Instruction *Inst) { 149 if (auto *I = dyn_cast<LoadInst>(Inst)) 150 return getLocation(I); 151 else if (auto *I = dyn_cast<StoreInst>(Inst)) 152 return getLocation(I); 153 else if (auto *I = dyn_cast<VAArgInst>(Inst)) 154 return getLocation(I); 155 else if (auto *I = dyn_cast<AtomicCmpXchgInst>(Inst)) 156 return getLocation(I); 157 else if (auto *I = dyn_cast<AtomicRMWInst>(Inst)) 158 return getLocation(I); 159 llvm_unreachable("unsupported memory instruction"); 160 } 161 162 /// Alias analysis result - Either we know for sure that it does not alias, we 163 /// know for sure it must alias, or we don't know anything: The two pointers 164 /// _might_ alias. This enum is designed so you can do things like: 165 /// if (AA.alias(P1, P2)) { ... } 166 /// to check to see if two pointers might alias. 167 /// 168 /// See docs/AliasAnalysis.html for more information on the specific meanings 169 /// of these values. 170 /// 171 enum AliasResult { 172 NoAlias = 0, ///< No dependencies. 173 MayAlias, ///< Anything goes. 174 PartialAlias, ///< Pointers differ, but pointees overlap. 175 MustAlias ///< Pointers are equal. 176 }; 177 178 /// alias - The main low level interface to the alias analysis implementation. 179 /// Returns an AliasResult indicating whether the two pointers are aliased to 180 /// each other. This is the interface that must be implemented by specific 181 /// alias analysis implementations. 182 virtual AliasResult alias(const Location &LocA, const Location &LocB); 183 184 /// alias - A convenience wrapper. alias(const Value * V1,uint64_t V1Size,const Value * V2,uint64_t V2Size)185 AliasResult alias(const Value *V1, uint64_t V1Size, 186 const Value *V2, uint64_t V2Size) { 187 return alias(Location(V1, V1Size), Location(V2, V2Size)); 188 } 189 190 /// alias - A convenience wrapper. alias(const Value * V1,const Value * V2)191 AliasResult alias(const Value *V1, const Value *V2) { 192 return alias(V1, UnknownSize, V2, UnknownSize); 193 } 194 195 /// isNoAlias - A trivial helper function to check to see if the specified 196 /// pointers are no-alias. isNoAlias(const Location & LocA,const Location & LocB)197 bool isNoAlias(const Location &LocA, const Location &LocB) { 198 return alias(LocA, LocB) == NoAlias; 199 } 200 201 /// isNoAlias - A convenience wrapper. isNoAlias(const Value * V1,uint64_t V1Size,const Value * V2,uint64_t V2Size)202 bool isNoAlias(const Value *V1, uint64_t V1Size, 203 const Value *V2, uint64_t V2Size) { 204 return isNoAlias(Location(V1, V1Size), Location(V2, V2Size)); 205 } 206 207 /// isNoAlias - A convenience wrapper. isNoAlias(const Value * V1,const Value * V2)208 bool isNoAlias(const Value *V1, const Value *V2) { 209 return isNoAlias(Location(V1), Location(V2)); 210 } 211 212 /// isMustAlias - A convenience wrapper. isMustAlias(const Location & LocA,const Location & LocB)213 bool isMustAlias(const Location &LocA, const Location &LocB) { 214 return alias(LocA, LocB) == MustAlias; 215 } 216 217 /// isMustAlias - A convenience wrapper. isMustAlias(const Value * V1,const Value * V2)218 bool isMustAlias(const Value *V1, const Value *V2) { 219 return alias(V1, 1, V2, 1) == MustAlias; 220 } 221 222 /// pointsToConstantMemory - If the specified memory location is 223 /// known to be constant, return true. If OrLocal is true and the 224 /// specified memory location is known to be "local" (derived from 225 /// an alloca), return true. Otherwise return false. 226 virtual bool pointsToConstantMemory(const Location &Loc, 227 bool OrLocal = false); 228 229 /// pointsToConstantMemory - A convenient wrapper. 230 bool pointsToConstantMemory(const Value *P, bool OrLocal = false) { 231 return pointsToConstantMemory(Location(P), OrLocal); 232 } 233 234 //===--------------------------------------------------------------------===// 235 /// Simple mod/ref information... 236 /// 237 238 /// ModRefResult - Represent the result of a mod/ref query. Mod and Ref are 239 /// bits which may be or'd together. 240 /// 241 enum ModRefResult { NoModRef = 0, Ref = 1, Mod = 2, ModRef = 3 }; 242 243 /// These values define additional bits used to define the 244 /// ModRefBehavior values. 245 enum { Nowhere = 0, ArgumentPointees = 4, Anywhere = 8 | ArgumentPointees }; 246 247 /// ModRefBehavior - Summary of how a function affects memory in the program. 248 /// Loads from constant globals are not considered memory accesses for this 249 /// interface. Also, functions may freely modify stack space local to their 250 /// invocation without having to report it through these interfaces. 251 enum ModRefBehavior { 252 /// DoesNotAccessMemory - This function does not perform any non-local loads 253 /// or stores to memory. 254 /// 255 /// This property corresponds to the GCC 'const' attribute. 256 /// This property corresponds to the LLVM IR 'readnone' attribute. 257 /// This property corresponds to the IntrNoMem LLVM intrinsic flag. 258 DoesNotAccessMemory = Nowhere | NoModRef, 259 260 /// OnlyReadsArgumentPointees - The only memory references in this function 261 /// (if it has any) are non-volatile loads from objects pointed to by its 262 /// pointer-typed arguments, with arbitrary offsets. 263 /// 264 /// This property corresponds to the IntrReadArgMem LLVM intrinsic flag. 265 OnlyReadsArgumentPointees = ArgumentPointees | Ref, 266 267 /// OnlyAccessesArgumentPointees - The only memory references in this 268 /// function (if it has any) are non-volatile loads and stores from objects 269 /// pointed to by its pointer-typed arguments, with arbitrary offsets. 270 /// 271 /// This property corresponds to the IntrReadWriteArgMem LLVM intrinsic flag. 272 OnlyAccessesArgumentPointees = ArgumentPointees | ModRef, 273 274 /// OnlyReadsMemory - This function does not perform any non-local stores or 275 /// volatile loads, but may read from any memory location. 276 /// 277 /// This property corresponds to the GCC 'pure' attribute. 278 /// This property corresponds to the LLVM IR 'readonly' attribute. 279 /// This property corresponds to the IntrReadMem LLVM intrinsic flag. 280 OnlyReadsMemory = Anywhere | Ref, 281 282 /// UnknownModRefBehavior - This indicates that the function could not be 283 /// classified into one of the behaviors above. 284 UnknownModRefBehavior = Anywhere | ModRef 285 }; 286 287 /// Get the location associated with a pointer argument of a callsite. 288 /// The mask bits are set to indicate the allowed aliasing ModRef kinds. 289 /// Note that these mask bits do not necessarily account for the overall 290 /// behavior of the function, but rather only provide additional 291 /// per-argument information. 292 virtual Location getArgLocation(ImmutableCallSite CS, unsigned ArgIdx, 293 ModRefResult &Mask); 294 295 /// getModRefBehavior - Return the behavior when calling the given call site. 296 virtual ModRefBehavior getModRefBehavior(ImmutableCallSite CS); 297 298 /// getModRefBehavior - Return the behavior when calling the given function. 299 /// For use when the call site is not known. 300 virtual ModRefBehavior getModRefBehavior(const Function *F); 301 302 /// doesNotAccessMemory - If the specified call is known to never read or 303 /// write memory, return true. If the call only reads from known-constant 304 /// memory, it is also legal to return true. Calls that unwind the stack 305 /// are legal for this predicate. 306 /// 307 /// Many optimizations (such as CSE and LICM) can be performed on such calls 308 /// without worrying about aliasing properties, and many calls have this 309 /// property (e.g. calls to 'sin' and 'cos'). 310 /// 311 /// This property corresponds to the GCC 'const' attribute. 312 /// doesNotAccessMemory(ImmutableCallSite CS)313 bool doesNotAccessMemory(ImmutableCallSite CS) { 314 return getModRefBehavior(CS) == DoesNotAccessMemory; 315 } 316 317 /// doesNotAccessMemory - If the specified function is known to never read or 318 /// write memory, return true. For use when the call site is not known. 319 /// doesNotAccessMemory(const Function * F)320 bool doesNotAccessMemory(const Function *F) { 321 return getModRefBehavior(F) == DoesNotAccessMemory; 322 } 323 324 /// onlyReadsMemory - If the specified call is known to only read from 325 /// non-volatile memory (or not access memory at all), return true. Calls 326 /// that unwind the stack are legal for this predicate. 327 /// 328 /// This property allows many common optimizations to be performed in the 329 /// absence of interfering store instructions, such as CSE of strlen calls. 330 /// 331 /// This property corresponds to the GCC 'pure' attribute. 332 /// onlyReadsMemory(ImmutableCallSite CS)333 bool onlyReadsMemory(ImmutableCallSite CS) { 334 return onlyReadsMemory(getModRefBehavior(CS)); 335 } 336 337 /// onlyReadsMemory - If the specified function is known to only read from 338 /// non-volatile memory (or not access memory at all), return true. For use 339 /// when the call site is not known. 340 /// onlyReadsMemory(const Function * F)341 bool onlyReadsMemory(const Function *F) { 342 return onlyReadsMemory(getModRefBehavior(F)); 343 } 344 345 /// onlyReadsMemory - Return true if functions with the specified behavior are 346 /// known to only read from non-volatile memory (or not access memory at all). 347 /// onlyReadsMemory(ModRefBehavior MRB)348 static bool onlyReadsMemory(ModRefBehavior MRB) { 349 return !(MRB & Mod); 350 } 351 352 /// onlyAccessesArgPointees - Return true if functions with the specified 353 /// behavior are known to read and write at most from objects pointed to by 354 /// their pointer-typed arguments (with arbitrary offsets). 355 /// onlyAccessesArgPointees(ModRefBehavior MRB)356 static bool onlyAccessesArgPointees(ModRefBehavior MRB) { 357 return !(MRB & Anywhere & ~ArgumentPointees); 358 } 359 360 /// doesAccessArgPointees - Return true if functions with the specified 361 /// behavior are known to potentially read or write from objects pointed 362 /// to be their pointer-typed arguments (with arbitrary offsets). 363 /// doesAccessArgPointees(ModRefBehavior MRB)364 static bool doesAccessArgPointees(ModRefBehavior MRB) { 365 return (MRB & ModRef) && (MRB & ArgumentPointees); 366 } 367 368 /// getModRefInfo - Return information about whether or not an 369 /// instruction may read or write memory (without regard to a 370 /// specific location) getModRefInfo(const Instruction * I)371 ModRefResult getModRefInfo(const Instruction *I) { 372 if (auto CS = ImmutableCallSite(I)) { 373 auto MRB = getModRefBehavior(CS); 374 if (MRB & ModRef) 375 return ModRef; 376 else if (MRB & Ref) 377 return Ref; 378 else if (MRB & Mod) 379 return Mod; 380 return NoModRef; 381 } 382 383 return getModRefInfo(I, Location()); 384 } 385 386 /// getModRefInfo - Return information about whether or not an instruction may 387 /// read or write the specified memory location. An instruction 388 /// that doesn't read or write memory may be trivially LICM'd for example. getModRefInfo(const Instruction * I,const Location & Loc)389 ModRefResult getModRefInfo(const Instruction *I, 390 const Location &Loc) { 391 switch (I->getOpcode()) { 392 case Instruction::VAArg: return getModRefInfo((const VAArgInst*)I, Loc); 393 case Instruction::Load: return getModRefInfo((const LoadInst*)I, Loc); 394 case Instruction::Store: return getModRefInfo((const StoreInst*)I, Loc); 395 case Instruction::Fence: return getModRefInfo((const FenceInst*)I, Loc); 396 case Instruction::AtomicCmpXchg: 397 return getModRefInfo((const AtomicCmpXchgInst*)I, Loc); 398 case Instruction::AtomicRMW: 399 return getModRefInfo((const AtomicRMWInst*)I, Loc); 400 case Instruction::Call: return getModRefInfo((const CallInst*)I, Loc); 401 case Instruction::Invoke: return getModRefInfo((const InvokeInst*)I,Loc); 402 default: return NoModRef; 403 } 404 } 405 406 /// getModRefInfo - A convenience wrapper. getModRefInfo(const Instruction * I,const Value * P,uint64_t Size)407 ModRefResult getModRefInfo(const Instruction *I, 408 const Value *P, uint64_t Size) { 409 return getModRefInfo(I, Location(P, Size)); 410 } 411 412 /// getModRefInfo (for call sites) - Return information about whether 413 /// a particular call site modifies or reads the specified memory location. 414 virtual ModRefResult getModRefInfo(ImmutableCallSite CS, 415 const Location &Loc); 416 417 /// getModRefInfo (for call sites) - A convenience wrapper. getModRefInfo(ImmutableCallSite CS,const Value * P,uint64_t Size)418 ModRefResult getModRefInfo(ImmutableCallSite CS, 419 const Value *P, uint64_t Size) { 420 return getModRefInfo(CS, Location(P, Size)); 421 } 422 423 /// getModRefInfo (for calls) - Return information about whether 424 /// a particular call modifies or reads the specified memory location. getModRefInfo(const CallInst * C,const Location & Loc)425 ModRefResult getModRefInfo(const CallInst *C, const Location &Loc) { 426 return getModRefInfo(ImmutableCallSite(C), Loc); 427 } 428 429 /// getModRefInfo (for calls) - A convenience wrapper. getModRefInfo(const CallInst * C,const Value * P,uint64_t Size)430 ModRefResult getModRefInfo(const CallInst *C, const Value *P, uint64_t Size) { 431 return getModRefInfo(C, Location(P, Size)); 432 } 433 434 /// getModRefInfo (for invokes) - Return information about whether 435 /// a particular invoke modifies or reads the specified memory location. getModRefInfo(const InvokeInst * I,const Location & Loc)436 ModRefResult getModRefInfo(const InvokeInst *I, 437 const Location &Loc) { 438 return getModRefInfo(ImmutableCallSite(I), Loc); 439 } 440 441 /// getModRefInfo (for invokes) - A convenience wrapper. getModRefInfo(const InvokeInst * I,const Value * P,uint64_t Size)442 ModRefResult getModRefInfo(const InvokeInst *I, 443 const Value *P, uint64_t Size) { 444 return getModRefInfo(I, Location(P, Size)); 445 } 446 447 /// getModRefInfo (for loads) - Return information about whether 448 /// a particular load modifies or reads the specified memory location. 449 ModRefResult getModRefInfo(const LoadInst *L, const Location &Loc); 450 451 /// getModRefInfo (for loads) - A convenience wrapper. getModRefInfo(const LoadInst * L,const Value * P,uint64_t Size)452 ModRefResult getModRefInfo(const LoadInst *L, const Value *P, uint64_t Size) { 453 return getModRefInfo(L, Location(P, Size)); 454 } 455 456 /// getModRefInfo (for stores) - Return information about whether 457 /// a particular store modifies or reads the specified memory location. 458 ModRefResult getModRefInfo(const StoreInst *S, const Location &Loc); 459 460 /// getModRefInfo (for stores) - A convenience wrapper. getModRefInfo(const StoreInst * S,const Value * P,uint64_t Size)461 ModRefResult getModRefInfo(const StoreInst *S, const Value *P, uint64_t Size){ 462 return getModRefInfo(S, Location(P, Size)); 463 } 464 465 /// getModRefInfo (for fences) - Return information about whether 466 /// a particular store modifies or reads the specified memory location. getModRefInfo(const FenceInst * S,const Location & Loc)467 ModRefResult getModRefInfo(const FenceInst *S, const Location &Loc) { 468 // Conservatively correct. (We could possibly be a bit smarter if 469 // Loc is a alloca that doesn't escape.) 470 return ModRef; 471 } 472 473 /// getModRefInfo (for fences) - A convenience wrapper. getModRefInfo(const FenceInst * S,const Value * P,uint64_t Size)474 ModRefResult getModRefInfo(const FenceInst *S, const Value *P, uint64_t Size){ 475 return getModRefInfo(S, Location(P, Size)); 476 } 477 478 /// getModRefInfo (for cmpxchges) - Return information about whether 479 /// a particular cmpxchg modifies or reads the specified memory location. 480 ModRefResult getModRefInfo(const AtomicCmpXchgInst *CX, const Location &Loc); 481 482 /// getModRefInfo (for cmpxchges) - A convenience wrapper. getModRefInfo(const AtomicCmpXchgInst * CX,const Value * P,unsigned Size)483 ModRefResult getModRefInfo(const AtomicCmpXchgInst *CX, 484 const Value *P, unsigned Size) { 485 return getModRefInfo(CX, Location(P, Size)); 486 } 487 488 /// getModRefInfo (for atomicrmws) - Return information about whether 489 /// a particular atomicrmw modifies or reads the specified memory location. 490 ModRefResult getModRefInfo(const AtomicRMWInst *RMW, const Location &Loc); 491 492 /// getModRefInfo (for atomicrmws) - A convenience wrapper. getModRefInfo(const AtomicRMWInst * RMW,const Value * P,unsigned Size)493 ModRefResult getModRefInfo(const AtomicRMWInst *RMW, 494 const Value *P, unsigned Size) { 495 return getModRefInfo(RMW, Location(P, Size)); 496 } 497 498 /// getModRefInfo (for va_args) - Return information about whether 499 /// a particular va_arg modifies or reads the specified memory location. 500 ModRefResult getModRefInfo(const VAArgInst* I, const Location &Loc); 501 502 /// getModRefInfo (for va_args) - A convenience wrapper. getModRefInfo(const VAArgInst * I,const Value * P,uint64_t Size)503 ModRefResult getModRefInfo(const VAArgInst* I, const Value* P, uint64_t Size){ 504 return getModRefInfo(I, Location(P, Size)); 505 } 506 /// getModRefInfo - Return information about whether a call and an instruction 507 /// may refer to the same memory locations. 508 ModRefResult getModRefInfo(Instruction *I, 509 ImmutableCallSite Call); 510 511 /// getModRefInfo - Return information about whether two call sites may refer 512 /// to the same set of memory locations. See 513 /// http://llvm.org/docs/AliasAnalysis.html#ModRefInfo 514 /// for details. 515 virtual ModRefResult getModRefInfo(ImmutableCallSite CS1, 516 ImmutableCallSite CS2); 517 518 /// callCapturesBefore - Return information about whether a particular call 519 /// site modifies or reads the specified memory location. 520 ModRefResult callCapturesBefore(const Instruction *I, 521 const AliasAnalysis::Location &MemLoc, 522 DominatorTree *DT); 523 524 /// callCapturesBefore - A convenience wrapper. callCapturesBefore(const Instruction * I,const Value * P,uint64_t Size,DominatorTree * DT)525 ModRefResult callCapturesBefore(const Instruction *I, const Value *P, 526 uint64_t Size, DominatorTree *DT) { 527 return callCapturesBefore(I, Location(P, Size), DT); 528 } 529 530 //===--------------------------------------------------------------------===// 531 /// Higher level methods for querying mod/ref information. 532 /// 533 534 /// canBasicBlockModify - Return true if it is possible for execution of the 535 /// specified basic block to modify the location Loc. 536 bool canBasicBlockModify(const BasicBlock &BB, const Location &Loc); 537 538 /// canBasicBlockModify - A convenience wrapper. canBasicBlockModify(const BasicBlock & BB,const Value * P,uint64_t Size)539 bool canBasicBlockModify(const BasicBlock &BB, const Value *P, uint64_t Size){ 540 return canBasicBlockModify(BB, Location(P, Size)); 541 } 542 543 /// canInstructionRangeModRef - Return true if it is possible for the 544 /// execution of the specified instructions to mod\ref (according to the 545 /// mode) the location Loc. The instructions to consider are all 546 /// of the instructions in the range of [I1,I2] INCLUSIVE. 547 /// I1 and I2 must be in the same basic block. 548 bool canInstructionRangeModRef(const Instruction &I1, 549 const Instruction &I2, const Location &Loc, 550 const ModRefResult Mode); 551 552 /// canInstructionRangeModRef - A convenience wrapper. canInstructionRangeModRef(const Instruction & I1,const Instruction & I2,const Value * Ptr,uint64_t Size,const ModRefResult Mode)553 bool canInstructionRangeModRef(const Instruction &I1, 554 const Instruction &I2, const Value *Ptr, 555 uint64_t Size, const ModRefResult Mode) { 556 return canInstructionRangeModRef(I1, I2, Location(Ptr, Size), Mode); 557 } 558 559 //===--------------------------------------------------------------------===// 560 /// Methods that clients should call when they transform the program to allow 561 /// alias analyses to update their internal data structures. Note that these 562 /// methods may be called on any instruction, regardless of whether or not 563 /// they have pointer-analysis implications. 564 /// 565 566 /// deleteValue - This method should be called whenever an LLVM Value is 567 /// deleted from the program, for example when an instruction is found to be 568 /// redundant and is eliminated. 569 /// 570 virtual void deleteValue(Value *V); 571 572 /// copyValue - This method should be used whenever a preexisting value in the 573 /// program is copied or cloned, introducing a new value. Note that analysis 574 /// implementations should tolerate clients that use this method to introduce 575 /// the same value multiple times: if the analysis already knows about a 576 /// value, it should ignore the request. 577 /// 578 virtual void copyValue(Value *From, Value *To); 579 580 /// addEscapingUse - This method should be used whenever an escaping use is 581 /// added to a pointer value. Analysis implementations may either return 582 /// conservative responses for that value in the future, or may recompute 583 /// some or all internal state to continue providing precise responses. 584 /// 585 /// Escaping uses are considered by anything _except_ the following: 586 /// - GEPs or bitcasts of the pointer 587 /// - Loads through the pointer 588 /// - Stores through (but not of) the pointer 589 virtual void addEscapingUse(Use &U); 590 591 /// replaceWithNewValue - This method is the obvious combination of the two 592 /// above, and it provided as a helper to simplify client code. 593 /// replaceWithNewValue(Value * Old,Value * New)594 void replaceWithNewValue(Value *Old, Value *New) { 595 copyValue(Old, New); 596 deleteValue(Old); 597 } 598 }; 599 600 // Specialize DenseMapInfo for Location. 601 template<> 602 struct DenseMapInfo<AliasAnalysis::Location> { 603 static inline AliasAnalysis::Location getEmptyKey() { 604 return AliasAnalysis::Location(DenseMapInfo<const Value *>::getEmptyKey(), 605 0); 606 } 607 static inline AliasAnalysis::Location getTombstoneKey() { 608 return AliasAnalysis::Location( 609 DenseMapInfo<const Value *>::getTombstoneKey(), 0); 610 } 611 static unsigned getHashValue(const AliasAnalysis::Location &Val) { 612 return DenseMapInfo<const Value *>::getHashValue(Val.Ptr) ^ 613 DenseMapInfo<uint64_t>::getHashValue(Val.Size) ^ 614 DenseMapInfo<AAMDNodes>::getHashValue(Val.AATags); 615 } 616 static bool isEqual(const AliasAnalysis::Location &LHS, 617 const AliasAnalysis::Location &RHS) { 618 return LHS.Ptr == RHS.Ptr && 619 LHS.Size == RHS.Size && 620 LHS.AATags == RHS.AATags; 621 } 622 }; 623 624 /// isNoAliasCall - Return true if this pointer is returned by a noalias 625 /// function. 626 bool isNoAliasCall(const Value *V); 627 628 /// isNoAliasArgument - Return true if this is an argument with the noalias 629 /// attribute. 630 bool isNoAliasArgument(const Value *V); 631 632 /// isIdentifiedObject - Return true if this pointer refers to a distinct and 633 /// identifiable object. This returns true for: 634 /// Global Variables and Functions (but not Global Aliases) 635 /// Allocas 636 /// ByVal and NoAlias Arguments 637 /// NoAlias returns (e.g. calls to malloc) 638 /// 639 bool isIdentifiedObject(const Value *V); 640 641 /// isIdentifiedFunctionLocal - Return true if V is umabigously identified 642 /// at the function-level. Different IdentifiedFunctionLocals can't alias. 643 /// Further, an IdentifiedFunctionLocal can not alias with any function 644 /// arguments other than itself, which is not necessarily true for 645 /// IdentifiedObjects. 646 bool isIdentifiedFunctionLocal(const Value *V); 647 648 } // End llvm namespace 649 650 #endif 651