AliasAnalysis.h revision 55f4ab84e567ac101d70f052771d1bc67a7560e3
1f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)//===- llvm/Analysis/AliasAnalysis.h - Alias Analysis Interface -*- C++ -*-===// 2f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// 3f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// The LLVM Compiler Infrastructure 4f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// 5f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// This file is distributed under the University of Illinois Open Source 6f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// License. See LICENSE.TXT for details. 7f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// 803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)//===----------------------------------------------------------------------===// 9a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// 10a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// This file defines the generic AliasAnalysis interface, which is used as the 116e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// common interface used by all clients of alias analysis information, and 120529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// implemented by all alias analysis implementations. Mod/Ref information is 135c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// also captured by this interface. 14a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// 155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Implementations of this interface must implement the various virtual methods, 165c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// which automatically provides functionality for the entire suite of client 17f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// APIs. 18a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// 19a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// This API identifies memory regions with the Location class. The pointer 20a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// component specifies the base memory address of the region. The Size specifies 21a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// the maximum size (in address units) of the memory region, or UnknownSize if 22a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// the size is not known. The TBAA tag identifies the "type" of the memory 23f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// reference; see the TypeBasedAliasAnalysis class for details. 24f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// 25f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Some non-obvious details include: 265f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// - Pointers that point to two completely different objects in memory never 275f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// alias, regardless of the value of the Size component. 285f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// - NoAlias doesn't imply inequal pointers. The most obvious example of this 295f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// is two pointers to constant memory. Even if they are equal, constant 300529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// memory is never stored to, so there will never be any dependencies. 310529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// In this and other situations, the pointers may be both NoAlias and 320529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// MustAlias at the same time. The current API can only return one result, 330529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// though this is rarely a problem in practice. 340529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// 350529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch//===----------------------------------------------------------------------===// 360529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 370529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#ifndef LLVM_ANALYSIS_ALIAS_ANALYSIS_H 380529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#define LLVM_ANALYSIS_ALIAS_ANALYSIS_H 390529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 400529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#include "llvm/Support/CallSite.h" 41116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "llvm/ADT/DenseMap.h" 420529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 430529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochnamespace llvm { 440529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 450529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochclass LoadInst; 460529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochclass StoreInst; 470529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochclass VAArgInst; 480529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochclass TargetData; 490529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochclass Pass; 50116680a4aac90f2aa7413d9095a592090648e557Ben Murdochclass AnalysisUsage; 51116680a4aac90f2aa7413d9095a592090648e557Ben Murdochclass MemTransferInst; 520529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochclass MemIntrinsic; 53116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 540529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochclass AliasAnalysis { 550529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochprotected: 560529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch const TargetData *TD; 570529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 580529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochprivate: 590529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch AliasAnalysis *AA; // Previous Alias Analysis to chain to. 600529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 61116680a4aac90f2aa7413d9095a592090648e557Ben Murdochprotected: 620529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch /// InitializeAliasAnalysis - Subclasses must call this method to initialize 630529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch /// the AliasAnalysis interface before any other methods are called. This is 640529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch /// typically called by the run* methods of these subclasses. This may be 650529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch /// called multiple times. 660529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch /// 670529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch void InitializeAliasAnalysis(Pass *P); 680529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 690529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch /// getAnalysisUsage - All alias analysis implementations should invoke this 700529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch /// directly (using AliasAnalysis::getAnalysisUsage(AU)). 710529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch virtual void getAnalysisUsage(AnalysisUsage &AU) const; 720529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 73116680a4aac90f2aa7413d9095a592090648e557Ben Murdochpublic: 740529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch static char ID; // Class identification, replacement for typeinfo 75116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch AliasAnalysis() : TD(0), AA(0) {} 76116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual ~AliasAnalysis(); // We want to be subclassed 770529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 780529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch /// UnknownSize - This is a special value which can be used with the 790529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch /// size arguments in alias queries to indicate that the caller does not 80116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// know the sizes of the potential memory references. 810529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch static uint64_t const UnknownSize = ~UINT64_C(0); 820529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 830529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch /// getTargetData - Return a pointer to the current TargetData object, or 84f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) /// null if no TargetData object is available. 85a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) /// 8603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) const TargetData *getTargetData() const { return TD; } 8703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 8803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) /// getTypeStoreSize - Return the TargetData store size for the given type, 8903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) /// if known, or a conservative value otherwise. 905c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu /// 91cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) uint64_t getTypeStoreSize(Type *Ty); 92cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 93cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) //===--------------------------------------------------------------------===// 94116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// Alias Queries... 956e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) /// 966e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 976e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) /// Location - A description of a memory location. 986e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) struct Location { 996e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) /// Ptr - The address of the start of the location. 1006e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) const Value *Ptr; 1011320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci /// Size - The maximum size of the location, in address-units, or 1021320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci /// UnknownSize if the size is not known. Note that an unknown size does 103116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// not mean the pointer aliases the entire virtual address space, because 1040529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch /// there are restrictions on stepping out of one object and into another. 1050529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch /// See http://llvm.org/docs/LangRef.html#pointeraliasing 1066e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) uint64_t Size; 1075c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu /// TBAATag - The metadata node which describes the TBAA type of 1085c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu /// the location, or null if there is no known unique tag. 109f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) const MDNode *TBAATag; 110116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 111116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch explicit Location(const Value *P = 0, uint64_t S = UnknownSize, 112116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch const MDNode *N = 0) 113116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch : Ptr(P), Size(S), TBAATag(N) {} 114116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 115116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch Location getWithNewPtr(const Value *NewPtr) const { 1165f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) Location Copy(*this); 1175f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) Copy.Ptr = NewPtr; 1186e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) return Copy; 1196e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) } 120116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 121116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch Location getWithNewSize(uint64_t NewSize) const { 122116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch Location Copy(*this); 123116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch Copy.Size = NewSize; 124116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch return Copy; 1256e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) } 126116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 127116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch Location getWithoutTBAATag() const { 128116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch Location Copy(*this); 129c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch Copy.TBAATag = 0; 1300529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch return Copy; 1310529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch } 1320529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch }; 1330529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 1340529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch /// getLocation - Fill in Loc with information about the memory reference by 135cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) /// the given instruction. 136c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch Location getLocation(const LoadInst *LI); 137f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) Location getLocation(const StoreInst *SI); 138f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) Location getLocation(const VAArgInst *VI); 139f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) Location getLocation(const AtomicCmpXchgInst *CXI); 140f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) Location getLocation(const AtomicRMWInst *RMWI); 141f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) static Location getLocationForSource(const MemTransferInst *MTI); 142f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) static Location getLocationForDest(const MemIntrinsic *MI); 143f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 144f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) /// Alias analysis result - Either we know for sure that it does not alias, we 145f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) /// know for sure it must alias, or we don't know anything: The two pointers 146f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) /// _might_ alias. This enum is designed so you can do things like: 147f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) /// if (AA.alias(P1, P2)) { ... } 148f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) /// to check to see if two pointers might alias. 149f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) /// 150f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) /// See docs/AliasAnalysis.html for more information on the specific meanings 151f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) /// of these values. 152116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// 153f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) enum AliasResult { 154f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) NoAlias = 0, ///< No dependencies. 155f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) MayAlias, ///< Anything goes. 156f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) PartialAlias, ///< Pointers differ, but pointees overlap. 157f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) MustAlias ///< Pointers are equal. 158f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) }; 159f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 160f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) /// alias - The main low level interface to the alias analysis implementation. 161f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) /// Returns an AliasResult indicating whether the two pointers are aliased to 162f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) /// each other. This is the interface that must be implemented by specific 163f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) /// alias analysis implementations. 164f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) virtual AliasResult alias(const Location &LocA, const Location &LocB); 165f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 166116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// alias - A convenience wrapper. 167116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch AliasResult alias(const Value *V1, uint64_t V1Size, 168f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) const Value *V2, uint64_t V2Size) { 169f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return alias(Location(V1, V1Size), Location(V2, V2Size)); 1700529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch } 1710529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 172116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// alias - A convenience wrapper. 1730529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch AliasResult alias(const Value *V1, const Value *V2) { 1740529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch return alias(V1, UnknownSize, V2, UnknownSize); 175a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } 176a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 177a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) /// isNoAlias - A trivial helper function to check to see if the specified 178a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch /// pointers are no-alias. 179a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) bool isNoAlias(const Location &LocA, const Location &LocB) { 180a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return alias(LocA, LocB) == NoAlias; 181116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch } 182116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 183116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// isNoAlias - A convenience wrapper. 184116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch bool isNoAlias(const Value *V1, uint64_t V1Size, 185116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch const Value *V2, uint64_t V2Size) { 186116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch return isNoAlias(Location(V1, V1Size), Location(V2, V2Size)); 187a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } 1885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) /// isMustAlias - A convenience wrapper. 1905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool isMustAlias(const Location &LocA, const Location &LocB) { 1911320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci return alias(LocA, LocB) == MustAlias; 1925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 1935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 194cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) /// isMustAlias - A convenience wrapper. 1955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool isMustAlias(const Value *V1, const Value *V2) { 196a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) return alias(V1, 1, V2, 1) == MustAlias; 197a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } 198a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 199a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) /// pointsToConstantMemory - If the specified memory location is 200a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) /// known to be constant, return true. If OrLocal is true and the 201a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) /// specified memory location is known to be "local" (derived from 202116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// an alloca), return true. Otherwise return false. 203116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual bool pointsToConstantMemory(const Location &Loc, 204116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch bool OrLocal = false); 205116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 206a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) /// pointsToConstantMemory - A convenient wrapper. 207cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) bool pointsToConstantMemory(const Value *P, bool OrLocal = false) { 208cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) return pointsToConstantMemory(Location(P), OrLocal); 209cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) } 210cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 211cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) //===--------------------------------------------------------------------===// 212cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) /// Simple mod/ref information... 213a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) /// 214a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 2155f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) /// ModRefResult - Represent the result of a mod/ref query. Mod and Ref are 2165f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) /// bits which may be or'd together. 2175f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) /// 2185f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) enum ModRefResult { NoModRef = 0, Ref = 1, Mod = 2, ModRef = 3 }; 2195f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 2205f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) /// These values define additional bits used to define the 2215f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) /// ModRefBehavior values. 2225f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) enum { Nowhere = 0, ArgumentPointees = 4, Anywhere = 8 | ArgumentPointees }; 223a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 224cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) /// ModRefBehavior - Summary of how a function affects memory in the program. 225a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) /// Loads from constant globals are not considered memory accesses for this 2265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) /// interface. Also, functions may freely modify stack space local to their 227c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch /// invocation without having to report it through these interfaces. 228c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch enum ModRefBehavior { 2295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) /// DoesNotAccessMemory - This function does not perform any non-local loads 230c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch /// or stores to memory. 231c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch /// 232c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch /// This property corresponds to the GCC 'const' attribute. 233c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch /// This property corresponds to the LLVM IR 'readnone' attribute. 234c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch /// This property corresponds to the IntrNoMem LLVM intrinsic flag. 235a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) DoesNotAccessMemory = Nowhere | NoModRef, 236a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 237c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch /// OnlyReadsArgumentPointees - The only memory references in this function 238c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch /// (if it has any) are non-volatile loads from objects pointed to by its 239c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch /// pointer-typed arguments, with arbitrary offsets. 240c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch /// 241c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch /// This property corresponds to the IntrReadArgMem LLVM intrinsic flag. 2421320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci OnlyReadsArgumentPointees = ArgumentPointees | Ref, 243cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 244cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) /// OnlyAccessesArgumentPointees - The only memory references in this 245cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) /// function (if it has any) are non-volatile loads and stores from objects 246cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) /// pointed to by its pointer-typed arguments, with arbitrary offsets. 247cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) /// 248cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) /// This property corresponds to the IntrReadWriteArgMem LLVM intrinsic flag. 249cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) OnlyAccessesArgumentPointees = ArgumentPointees | ModRef, 250cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 251cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) /// OnlyReadsMemory - This function does not perform any non-local stores or 252cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) /// volatile loads, but may read from any memory location. 2531320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci /// 254cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) /// This property corresponds to the GCC 'pure' attribute. 255cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) /// This property corresponds to the LLVM IR 'readonly' attribute. 256cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) /// This property corresponds to the IntrReadMem LLVM intrinsic flag. 257c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch OnlyReadsMemory = Anywhere | Ref, 258c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch 259c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch /// UnknownModRefBehavior - This indicates that the function could not be 260c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch /// classified into one of the behaviors above. 261c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch UnknownModRefBehavior = Anywhere | ModRef 262c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch }; 263c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch 264c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch /// getModRefBehavior - Return the behavior when calling the given call site. 265c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch virtual ModRefBehavior getModRefBehavior(ImmutableCallSite CS); 266c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch 267c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch /// getModRefBehavior - Return the behavior when calling the given function. 268c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch /// For use when the call site is not known. 269c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch virtual ModRefBehavior getModRefBehavior(const Function *F); 270c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch 271c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch /// doesNotAccessMemory - If the specified call is known to never read or 272c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch /// write memory, return true. If the call only reads from known-constant 273c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch /// memory, it is also legal to return true. Calls that unwind the stack 274c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch /// are legal for this predicate. 275c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch /// 276c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch /// Many optimizations (such as CSE and LICM) can be performed on such calls 277c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch /// without worrying about aliasing properties, and many calls have this 278c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch /// property (e.g. calls to 'sin' and 'cos'). 279c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch /// 280c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch /// This property corresponds to the GCC 'const' attribute. 281c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch /// 282c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch bool doesNotAccessMemory(ImmutableCallSite CS) { 283c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch return getModRefBehavior(CS) == DoesNotAccessMemory; 2840529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch } 285c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch 286c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch /// doesNotAccessMemory - If the specified function is known to never read or 287c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch /// write memory, return true. For use when the call site is not known. 288c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch /// 289a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) bool doesNotAccessMemory(const Function *F) { 290a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) return getModRefBehavior(F) == DoesNotAccessMemory; 291cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) } 292cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 293cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) /// onlyReadsMemory - If the specified call is known to only read from 294cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) /// non-volatile memory (or not access memory at all), return true. Calls 295cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) /// that unwind the stack are legal for this predicate. 296cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) /// 297cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) /// This property allows many common optimizations to be performed in the 298cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) /// absence of interfering store instructions, such as CSE of strlen calls. 299cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) /// 300cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) /// This property corresponds to the GCC 'pure' attribute. 301cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) /// 302cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) bool onlyReadsMemory(ImmutableCallSite CS) { 303cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) return onlyReadsMemory(getModRefBehavior(CS)); 304cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) } 305cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 306cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) /// onlyReadsMemory - If the specified function is known to only read from 307cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) /// non-volatile memory (or not access memory at all), return true. For use 308cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) /// when the call site is not known. 309cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) /// 310cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) bool onlyReadsMemory(const Function *F) { 311cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) return onlyReadsMemory(getModRefBehavior(F)); 312cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) } 313cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 314cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) /// onlyReadsMemory - Return true if functions with the specified behavior are 315a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch /// known to only read from non-volatile memory (or not access memory at all). 316a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch /// 317a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch static bool onlyReadsMemory(ModRefBehavior MRB) { 318a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch return !(MRB & Mod); 3196e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) } 3206e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 3216e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) /// onlyAccessesArgPointees - Return true if functions with the specified 3226e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) /// behavior are known to read and write at most from objects pointed to by 323116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// their pointer-typed arguments (with arbitrary offsets). 324116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// 325116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch static bool onlyAccessesArgPointees(ModRefBehavior MRB) { 326116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch return !(MRB & Anywhere & ~ArgumentPointees); 327116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch } 328116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 329116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// doesAccessArgPointees - Return true if functions with the specified 330116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// behavior are known to potentially read or write from objects pointed 331116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// to be their pointer-typed arguments (with arbitrary offsets). 332116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// 333116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch static bool doesAccessArgPointees(ModRefBehavior MRB) { 334116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch return (MRB & ModRef) && (MRB & ArgumentPointees); 335116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch } 3366e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 3376e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) /// getModRefInfo - Return information about whether or not an instruction may 33803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) /// read or write the specified memory location. An instruction 3396e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) /// that doesn't read or write memory may be trivially LICM'd for example. 3406e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) ModRefResult getModRefInfo(const Instruction *I, 3416e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) const Location &Loc) { 3426e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) switch (I->getOpcode()) { 3436e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) case Instruction::VAArg: return getModRefInfo((const VAArgInst*)I, Loc); 3446e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) case Instruction::Load: return getModRefInfo((const LoadInst*)I, Loc); 3450529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch case Instruction::Store: return getModRefInfo((const StoreInst*)I, Loc); 3461320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci case Instruction::Fence: return getModRefInfo((const FenceInst*)I, Loc); 3470529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch case Instruction::AtomicCmpXchg: 3480529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch return getModRefInfo((const AtomicCmpXchgInst*)I, Loc); 3490529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch case Instruction::AtomicRMW: 3500529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch return getModRefInfo((const AtomicRMWInst*)I, Loc); 3510529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch case Instruction::Call: return getModRefInfo((const CallInst*)I, Loc); 3520529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch case Instruction::Invoke: return getModRefInfo((const InvokeInst*)I,Loc); 3530529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch default: return NoModRef; 3540529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch } 3551320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci } 3560529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 3570529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch /// getModRefInfo - A convenience wrapper. 3580529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch ModRefResult getModRefInfo(const Instruction *I, 3590529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch const Value *P, uint64_t Size) { 3600529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch return getModRefInfo(I, Location(P, Size)); 3610529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch } 3620529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 3630529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch /// getModRefInfo (for call sites) - Return whether information about whether 3640529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch /// a particular call site modifies or reads the specified memory location. 3651320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci virtual ModRefResult getModRefInfo(ImmutableCallSite CS, 3660529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch const Location &Loc); 3670529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 3680529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch /// getModRefInfo (for call sites) - A convenience wrapper. 3690529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch ModRefResult getModRefInfo(ImmutableCallSite CS, 3700529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch const Value *P, uint64_t Size) { 3710529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch return getModRefInfo(CS, Location(P, Size)); 3720529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch } 3730529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 3740529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch /// getModRefInfo (for calls) - Return whether information about whether 3750529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch /// a particular call modifies or reads the specified memory location. 3760529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch ModRefResult getModRefInfo(const CallInst *C, const Location &Loc) { 3771320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci return getModRefInfo(ImmutableCallSite(C), Loc); 3780529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch } 3790529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 3800529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch /// getModRefInfo (for calls) - A convenience wrapper. 3810529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch ModRefResult getModRefInfo(const CallInst *C, const Value *P, uint64_t Size) { 3820529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch return getModRefInfo(C, Location(P, Size)); 3830529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch } 3840529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 3850529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch /// getModRefInfo (for invokes) - Return whether information about whether 3860529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch /// a particular invoke modifies or reads the specified memory location. 3870529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch ModRefResult getModRefInfo(const InvokeInst *I, 3880529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch const Location &Loc) { 3890529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch return getModRefInfo(ImmutableCallSite(I), Loc); 3900529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch } 3910529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 3920529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch /// getModRefInfo (for invokes) - A convenience wrapper. 3930529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch ModRefResult getModRefInfo(const InvokeInst *I, 3940529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch const Value *P, uint64_t Size) { 3951320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci return getModRefInfo(I, Location(P, Size)); 3960529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch } 3970529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 3980529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch /// getModRefInfo (for loads) - Return whether information about whether 3990529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch /// a particular load modifies or reads the specified memory location. 4000529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch ModRefResult getModRefInfo(const LoadInst *L, const Location &Loc); 4010529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 4020529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch /// getModRefInfo (for loads) - A convenience wrapper. 4030529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch ModRefResult getModRefInfo(const LoadInst *L, const Value *P, uint64_t Size) { 4040529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch return getModRefInfo(L, Location(P, Size)); 4050529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch } 406cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 4071320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci /// getModRefInfo (for stores) - Return whether information about whether 4081320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci /// a particular store modifies or reads the specified memory location. 4091320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ModRefResult getModRefInfo(const StoreInst *S, const Location &Loc); 410cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 411cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) /// getModRefInfo (for stores) - A convenience wrapper. 412f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) ModRefResult getModRefInfo(const StoreInst *S, const Value *P, uint64_t Size){ 413 return getModRefInfo(S, Location(P, Size)); 414 } 415 416 /// getModRefInfo (for fences) - Return whether information about whether 417 /// a particular store modifies or reads the specified memory location. 418 ModRefResult getModRefInfo(const FenceInst *S, const Location &Loc) { 419 // Conservatively correct. (We could possibly be a bit smarter if 420 // Loc is a alloca that doesn't escape.) 421 return ModRef; 422 } 423 424 /// getModRefInfo (for fences) - A convenience wrapper. 425 ModRefResult getModRefInfo(const FenceInst *S, const Value *P, uint64_t Size){ 426 return getModRefInfo(S, Location(P, Size)); 427 } 428 429 /// getModRefInfo (for cmpxchges) - Return whether information about whether 430 /// a particular cmpxchg modifies or reads the specified memory location. 431 ModRefResult getModRefInfo(const AtomicCmpXchgInst *CX, const Location &Loc); 432 433 /// getModRefInfo (for cmpxchges) - A convenience wrapper. 434 ModRefResult getModRefInfo(const AtomicCmpXchgInst *CX, 435 const Value *P, unsigned Size) { 436 return getModRefInfo(CX, Location(P, Size)); 437 } 438 439 /// getModRefInfo (for atomicrmws) - Return whether information about whether 440 /// a particular atomicrmw modifies or reads the specified memory location. 441 ModRefResult getModRefInfo(const AtomicRMWInst *RMW, const Location &Loc); 442 443 /// getModRefInfo (for atomicrmws) - A convenience wrapper. 444 ModRefResult getModRefInfo(const AtomicRMWInst *RMW, 445 const Value *P, unsigned Size) { 446 return getModRefInfo(RMW, Location(P, Size)); 447 } 448 449 /// getModRefInfo (for va_args) - Return whether information about whether 450 /// a particular va_arg modifies or reads the specified memory location. 451 ModRefResult getModRefInfo(const VAArgInst* I, const Location &Loc); 452 453 /// getModRefInfo (for va_args) - A convenience wrapper. 454 ModRefResult getModRefInfo(const VAArgInst* I, const Value* P, uint64_t Size){ 455 return getModRefInfo(I, Location(P, Size)); 456 } 457 458 /// getModRefInfo - Return information about whether two call sites may refer 459 /// to the same set of memory locations. See 460 /// http://llvm.org/docs/AliasAnalysis.html#ModRefInfo 461 /// for details. 462 virtual ModRefResult getModRefInfo(ImmutableCallSite CS1, 463 ImmutableCallSite CS2); 464 465 //===--------------------------------------------------------------------===// 466 /// Higher level methods for querying mod/ref information. 467 /// 468 469 /// canBasicBlockModify - Return true if it is possible for execution of the 470 /// specified basic block to modify the value pointed to by Ptr. 471 bool canBasicBlockModify(const BasicBlock &BB, const Location &Loc); 472 473 /// canBasicBlockModify - A convenience wrapper. 474 bool canBasicBlockModify(const BasicBlock &BB, const Value *P, uint64_t Size){ 475 return canBasicBlockModify(BB, Location(P, Size)); 476 } 477 478 /// canInstructionRangeModify - Return true if it is possible for the 479 /// execution of the specified instructions to modify the value pointed to by 480 /// Ptr. The instructions to consider are all of the instructions in the 481 /// range of [I1,I2] INCLUSIVE. I1 and I2 must be in the same basic block. 482 bool canInstructionRangeModify(const Instruction &I1, const Instruction &I2, 483 const Location &Loc); 484 485 /// canInstructionRangeModify - A convenience wrapper. 486 bool canInstructionRangeModify(const Instruction &I1, const Instruction &I2, 487 const Value *Ptr, uint64_t Size) { 488 return canInstructionRangeModify(I1, I2, Location(Ptr, Size)); 489 } 490 491 //===--------------------------------------------------------------------===// 492 /// Methods that clients should call when they transform the program to allow 493 /// alias analyses to update their internal data structures. Note that these 494 /// methods may be called on any instruction, regardless of whether or not 495 /// they have pointer-analysis implications. 496 /// 497 498 /// deleteValue - This method should be called whenever an LLVM Value is 499 /// deleted from the program, for example when an instruction is found to be 500 /// redundant and is eliminated. 501 /// 502 virtual void deleteValue(Value *V); 503 504 /// copyValue - This method should be used whenever a preexisting value in the 505 /// program is copied or cloned, introducing a new value. Note that analysis 506 /// implementations should tolerate clients that use this method to introduce 507 /// the same value multiple times: if the analysis already knows about a 508 /// value, it should ignore the request. 509 /// 510 virtual void copyValue(Value *From, Value *To); 511 512 /// addEscapingUse - This method should be used whenever an escaping use is 513 /// added to a pointer value. Analysis implementations may either return 514 /// conservative responses for that value in the future, or may recompute 515 /// some or all internal state to continue providing precise responses. 516 /// 517 /// Escaping uses are considered by anything _except_ the following: 518 /// - GEPs or bitcasts of the pointer 519 /// - Loads through the pointer 520 /// - Stores through (but not of) the pointer 521 virtual void addEscapingUse(Use &U); 522 523 /// replaceWithNewValue - This method is the obvious combination of the two 524 /// above, and it provided as a helper to simplify client code. 525 /// 526 void replaceWithNewValue(Value *Old, Value *New) { 527 copyValue(Old, New); 528 deleteValue(Old); 529 } 530}; 531 532// Specialize DenseMapInfo for Location. 533template<> 534struct DenseMapInfo<AliasAnalysis::Location> { 535 static inline AliasAnalysis::Location getEmptyKey() { 536 return 537 AliasAnalysis::Location(DenseMapInfo<const Value *>::getEmptyKey(), 538 0, 0); 539 } 540 static inline AliasAnalysis::Location getTombstoneKey() { 541 return 542 AliasAnalysis::Location(DenseMapInfo<const Value *>::getTombstoneKey(), 543 0, 0); 544 } 545 static unsigned getHashValue(const AliasAnalysis::Location &Val) { 546 return DenseMapInfo<const Value *>::getHashValue(Val.Ptr) ^ 547 DenseMapInfo<uint64_t>::getHashValue(Val.Size) ^ 548 DenseMapInfo<const MDNode *>::getHashValue(Val.TBAATag); 549 } 550 static bool isEqual(const AliasAnalysis::Location &LHS, 551 const AliasAnalysis::Location &RHS) { 552 return LHS.Ptr == RHS.Ptr && 553 LHS.Size == RHS.Size && 554 LHS.TBAATag == RHS.TBAATag; 555 } 556}; 557 558/// isNoAliasCall - Return true if this pointer is returned by a noalias 559/// function. 560bool isNoAliasCall(const Value *V); 561 562/// isIdentifiedObject - Return true if this pointer refers to a distinct and 563/// identifiable object. This returns true for: 564/// Global Variables and Functions (but not Global Aliases) 565/// Allocas and Mallocs 566/// ByVal and NoAlias Arguments 567/// NoAlias returns 568/// 569bool isIdentifiedObject(const Value *V); 570 571/// isKnownNonNull - Return true if this pointer couldn't possibly be null by 572/// its definition. This returns true for allocas, non-extern-weak globals and 573/// byval arguments. 574bool isKnownNonNull(const Value *V); 575 576} // End llvm namespace 577 578#endif 579