AliasAnalysis.h revision 2feee6454d4c9cbb3a104b0f593d31a91a14d15a
14df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner//===- llvm/Analysis/AliasAnalysis.h - Alias Analysis Interface -*- C++ -*-===// 29769ab22265b313171d201b5928688524a01bd87Misha Brukman// 36fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell// The LLVM Compiler Infrastructure 46fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell// 57ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// This file is distributed under the University of Illinois Open Source 67ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// License. See LICENSE.TXT for details. 79769ab22265b313171d201b5928688524a01bd87Misha Brukman// 86fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell//===----------------------------------------------------------------------===// 94df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner// 104df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner// This file defines the generic AliasAnalysis interface, which is used as the 114df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner// common interface used by all clients of alias analysis information, and 121c56b730a6313886076d7b293a126ae5576f5288Chris Lattner// implemented by all alias analysis implementations. Mod/Ref information is 131c56b730a6313886076d7b293a126ae5576f5288Chris Lattner// also captured by this interface. 144df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner// 154df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner// Implementations of this interface must implement the various virtual methods, 164df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner// which automatically provides functionality for the entire suite of client 174df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner// APIs. 184df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner// 198e78cc4e130a8773cc8a2be2a94c4a97317ac383Dan Gohman// This API identifies memory regions with the Location class. The pointer 208e78cc4e130a8773cc8a2be2a94c4a97317ac383Dan Gohman// component specifies the base memory address of the region. The Size specifies 218e78cc4e130a8773cc8a2be2a94c4a97317ac383Dan Gohman// the maximum size (in address units) of the memory region, or UnknownSize if 228e78cc4e130a8773cc8a2be2a94c4a97317ac383Dan Gohman// the size is not known. The TBAA tag identifies the "type" of the memory 238e78cc4e130a8773cc8a2be2a94c4a97317ac383Dan Gohman// reference; see the TypeBasedAliasAnalysis class for details. 248e78cc4e130a8773cc8a2be2a94c4a97317ac383Dan Gohman// 258e78cc4e130a8773cc8a2be2a94c4a97317ac383Dan Gohman// Some non-obvious details include: 268e78cc4e130a8773cc8a2be2a94c4a97317ac383Dan Gohman// - Pointers that point to two completely different objects in memory never 278e78cc4e130a8773cc8a2be2a94c4a97317ac383Dan Gohman// alias, regardless of the value of the Size component. 288e78cc4e130a8773cc8a2be2a94c4a97317ac383Dan Gohman// - NoAlias doesn't imply inequal pointers. The most obvious example of this 298e78cc4e130a8773cc8a2be2a94c4a97317ac383Dan Gohman// is two pointers to constant memory. Even if they are equal, constant 308e78cc4e130a8773cc8a2be2a94c4a97317ac383Dan Gohman// memory is never stored to, so there will never be any dependencies. 318e78cc4e130a8773cc8a2be2a94c4a97317ac383Dan Gohman// In this and other situations, the pointers may be both NoAlias and 328e78cc4e130a8773cc8a2be2a94c4a97317ac383Dan Gohman// MustAlias at the same time. The current API can only return one result, 338e78cc4e130a8773cc8a2be2a94c4a97317ac383Dan Gohman// though this is rarely a problem in practice. 341c56b730a6313886076d7b293a126ae5576f5288Chris Lattner// 354df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner//===----------------------------------------------------------------------===// 364df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner 374df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner#ifndef LLVM_ANALYSIS_ALIAS_ANALYSIS_H 384df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner#define LLVM_ANALYSIS_ALIAS_ANALYSIS_H 394df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner 401c56b730a6313886076d7b293a126ae5576f5288Chris Lattner#include "llvm/Support/CallSite.h" 4136f78c8935da34074ccd06d5674e45b9cd45da8bChris Lattner#include <vector> 42d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke 43d0fde30ce850b78371fd1386338350591f9ff494Brian Gaekenamespace llvm { 44d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke 451c56b730a6313886076d7b293a126ae5576f5288Chris Lattnerclass LoadInst; 461c56b730a6313886076d7b293a126ae5576f5288Chris Lattnerclass StoreInst; 4714f1703ae33e13dbcadd701603fd4d7a6f7010b9Andrew Lenharthclass VAArgInst; 481c56b730a6313886076d7b293a126ae5576f5288Chris Lattnerclass TargetData; 496df60a9effe4d20a48cfd9d105c0ab3c5dc3e690Reid Spencerclass Pass; 506df60a9effe4d20a48cfd9d105c0ab3c5dc3e690Reid Spencerclass AnalysisUsage; 51e90c5cb747631b315350e7ee7424048c7778bdf9Chris Lattnerclass MemTransferInst; 529dc9e81aa7412b329bbaf51a589a81475214802bChris Lattnerclass MemIntrinsic; 531c56b730a6313886076d7b293a126ae5576f5288Chris Lattner 541c56b730a6313886076d7b293a126ae5576f5288Chris Lattnerclass AliasAnalysis { 551c56b730a6313886076d7b293a126ae5576f5288Chris Lattnerprotected: 56ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner const TargetData *TD; 57cb74993bdc37681ddbb80fa361575107afae1350Dan Gohman 58cb74993bdc37681ddbb80fa361575107afae1350Dan Gohmanprivate: 59ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner AliasAnalysis *AA; // Previous Alias Analysis to chain to. 60ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner 61cb74993bdc37681ddbb80fa361575107afae1350Dan Gohmanprotected: 621c56b730a6313886076d7b293a126ae5576f5288Chris Lattner /// InitializeAliasAnalysis - Subclasses must call this method to initialize 631c56b730a6313886076d7b293a126ae5576f5288Chris Lattner /// the AliasAnalysis interface before any other methods are called. This is 641c56b730a6313886076d7b293a126ae5576f5288Chris Lattner /// typically called by the run* methods of these subclasses. This may be 651c56b730a6313886076d7b293a126ae5576f5288Chris Lattner /// called multiple times. 661c56b730a6313886076d7b293a126ae5576f5288Chris Lattner /// 671c56b730a6313886076d7b293a126ae5576f5288Chris Lattner void InitializeAliasAnalysis(Pass *P); 689769ab22265b313171d201b5928688524a01bd87Misha Brukman 6964d237cfae6bcb11157d525c79b5a5335e30370bDan Gohman /// getAnalysisUsage - All alias analysis implementations should invoke this 70fc2a3ed0c9e32cf7edaf5030fa0972b916cc5f0bDan Gohman /// directly (using AliasAnalysis::getAnalysisUsage(AU)). 711c56b730a6313886076d7b293a126ae5576f5288Chris Lattner virtual void getAnalysisUsage(AnalysisUsage &AU) const; 721c56b730a6313886076d7b293a126ae5576f5288Chris Lattner 731c56b730a6313886076d7b293a126ae5576f5288Chris Lattnerpublic: 741997473cf72957d0e70322e2fe6fe2ab141c58a6Devang Patel static char ID; // Class identification, replacement for typeinfo 75ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner AliasAnalysis() : TD(0), AA(0) {} 761c56b730a6313886076d7b293a126ae5576f5288Chris Lattner virtual ~AliasAnalysis(); // We want to be subclassed 771c56b730a6313886076d7b293a126ae5576f5288Chris Lattner 78ef1cfac9e50def9097cd3e3ab3c5cad7f4c758ccDan Gohman /// UnknownSize - This is a special value which can be used with the 79ef1cfac9e50def9097cd3e3ab3c5cad7f4c758ccDan Gohman /// size arguments in alias queries to indicate that the caller does not 80ef1cfac9e50def9097cd3e3ab3c5cad7f4c758ccDan Gohman /// know the sizes of the potential memory references. 813da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman static uint64_t const UnknownSize = ~UINT64_C(0); 82ef1cfac9e50def9097cd3e3ab3c5cad7f4c758ccDan Gohman 83fc2a3ed0c9e32cf7edaf5030fa0972b916cc5f0bDan Gohman /// getTargetData - Return a pointer to the current TargetData object, or 84fc2a3ed0c9e32cf7edaf5030fa0972b916cc5f0bDan Gohman /// null if no TargetData object is available. 85dd298c8c6eb036baf35bf5a559c59d2afd2c7944Misha Brukman /// 86fc2a3ed0c9e32cf7edaf5030fa0972b916cc5f0bDan Gohman const TargetData *getTargetData() const { return TD; } 87fc2a3ed0c9e32cf7edaf5030fa0972b916cc5f0bDan Gohman 88fc2a3ed0c9e32cf7edaf5030fa0972b916cc5f0bDan Gohman /// getTypeStoreSize - Return the TargetData store size for the given type, 89fc2a3ed0c9e32cf7edaf5030fa0972b916cc5f0bDan Gohman /// if known, or a conservative value otherwise. 90fc2a3ed0c9e32cf7edaf5030fa0972b916cc5f0bDan Gohman /// 913da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman uint64_t getTypeStoreSize(const Type *Ty); 924df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner 931c56b730a6313886076d7b293a126ae5576f5288Chris Lattner //===--------------------------------------------------------------------===// 941c56b730a6313886076d7b293a126ae5576f5288Chris Lattner /// Alias Queries... 951c56b730a6313886076d7b293a126ae5576f5288Chris Lattner /// 964df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner 97b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// Location - A description of a memory location. 98b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman struct Location { 99b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// Ptr - The address of the start of the location. 100b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman const Value *Ptr; 101a6d60ddbbb0c33690f7e89cad2b5e60cee84b89eDan Gohman /// Size - The maximum size of the location, in address-units, or 102a6d60ddbbb0c33690f7e89cad2b5e60cee84b89eDan Gohman /// UnknownSize if the size is not known. Note that an unknown size does 103a6d60ddbbb0c33690f7e89cad2b5e60cee84b89eDan Gohman /// not mean the pointer aliases the entire virtual address space, because 104a6d60ddbbb0c33690f7e89cad2b5e60cee84b89eDan Gohman /// there are restrictions on stepping out of one object and into another. 1056c25c920e66aa2d8f6b48454bc9770087ff7939aDan Gohman /// See http://llvm.org/docs/LangRef.html#pointeraliasing 1063da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman uint64_t Size; 107b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// TBAATag - The metadata node which describes the TBAA type of 1086c25c920e66aa2d8f6b48454bc9770087ff7939aDan Gohman /// the location, or null if there is no known unique tag. 109b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman const MDNode *TBAATag; 110b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman 111c413330c99a573ef3ffe80a46400b1d3eca2398dChris Lattner explicit Location(const Value *P = 0, uint64_t S = UnknownSize, 112b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman const MDNode *N = 0) 113b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman : Ptr(P), Size(S), TBAATag(N) {} 1149f27074f42f03af640977006dc7c05005fb77991Dan Gohman 1159f27074f42f03af640977006dc7c05005fb77991Dan Gohman Location getWithNewPtr(const Value *NewPtr) const { 1169f27074f42f03af640977006dc7c05005fb77991Dan Gohman Location Copy(*this); 1179f27074f42f03af640977006dc7c05005fb77991Dan Gohman Copy.Ptr = NewPtr; 1189f27074f42f03af640977006dc7c05005fb77991Dan Gohman return Copy; 1199f27074f42f03af640977006dc7c05005fb77991Dan Gohman } 1209f27074f42f03af640977006dc7c05005fb77991Dan Gohman 121075fb5d68fcb55d26e44c48f07dfdbbfa21ccb2aDan Gohman Location getWithNewSize(uint64_t NewSize) const { 122075fb5d68fcb55d26e44c48f07dfdbbfa21ccb2aDan Gohman Location Copy(*this); 123075fb5d68fcb55d26e44c48f07dfdbbfa21ccb2aDan Gohman Copy.Size = NewSize; 124075fb5d68fcb55d26e44c48f07dfdbbfa21ccb2aDan Gohman return Copy; 125075fb5d68fcb55d26e44c48f07dfdbbfa21ccb2aDan Gohman } 126075fb5d68fcb55d26e44c48f07dfdbbfa21ccb2aDan Gohman 1279f27074f42f03af640977006dc7c05005fb77991Dan Gohman Location getWithoutTBAATag() const { 1289f27074f42f03af640977006dc7c05005fb77991Dan Gohman Location Copy(*this); 1299f27074f42f03af640977006dc7c05005fb77991Dan Gohman Copy.TBAATag = 0; 1309f27074f42f03af640977006dc7c05005fb77991Dan Gohman return Copy; 1319f27074f42f03af640977006dc7c05005fb77991Dan Gohman } 132b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman }; 133b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman 1346d8eb156e6be727570b300bac7712f745a318c7dDan Gohman /// getLocation - Fill in Loc with information about the memory reference by 1356d8eb156e6be727570b300bac7712f745a318c7dDan Gohman /// the given instruction. 1366d8eb156e6be727570b300bac7712f745a318c7dDan Gohman Location getLocation(const LoadInst *LI); 1376d8eb156e6be727570b300bac7712f745a318c7dDan Gohman Location getLocation(const StoreInst *SI); 1386d8eb156e6be727570b300bac7712f745a318c7dDan Gohman Location getLocation(const VAArgInst *VI); 13916f7993e0df4bd0727f8535bd47a2776bec10545Chris Lattner static Location getLocationForSource(const MemTransferInst *MTI); 1409dc9e81aa7412b329bbaf51a589a81475214802bChris Lattner static Location getLocationForDest(const MemIntrinsic *MI); 1416d8eb156e6be727570b300bac7712f745a318c7dDan Gohman 142f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner /// Alias analysis result - Either we know for sure that it does not alias, we 143f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner /// know for sure it must alias, or we don't know anything: The two pointers 144f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner /// _might_ alias. This enum is designed so you can do things like: 145f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner /// if (AA.alias(P1, P2)) { ... } 146f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner /// to check to see if two pointers might alias. 147f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner /// 148e53e3772f3c8b4cba69b7d77c8b2148a080fe9aeDan Gohman /// See docs/AliasAnalysis.html for more information on the specific meanings 149e53e3772f3c8b4cba69b7d77c8b2148a080fe9aeDan Gohman /// of these values. 150e53e3772f3c8b4cba69b7d77c8b2148a080fe9aeDan Gohman /// 15117e8078ae14ed71f657d59c77efa3bedf171161aDan Gohman enum AliasResult { 15217e8078ae14ed71f657d59c77efa3bedf171161aDan Gohman NoAlias = 0, ///< No dependencies. 1534a34cbd2b9ba9efcdab4c4e656df2d7bd22e2604Dan Gohman MayAlias, ///< Anything goes. 1544a34cbd2b9ba9efcdab4c4e656df2d7bd22e2604Dan Gohman PartialAlias, ///< Pointers differ, but pointees overlap. 1554a34cbd2b9ba9efcdab4c4e656df2d7bd22e2604Dan Gohman MustAlias ///< Pointers are equal. 15617e8078ae14ed71f657d59c77efa3bedf171161aDan Gohman }; 1574df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner 158f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner /// alias - The main low level interface to the alias analysis implementation. 1596c25c920e66aa2d8f6b48454bc9770087ff7939aDan Gohman /// Returns an AliasResult indicating whether the two pointers are aliased to 1606c25c920e66aa2d8f6b48454bc9770087ff7939aDan Gohman /// each other. This is the interface that must be implemented by specific 1616c25c920e66aa2d8f6b48454bc9770087ff7939aDan Gohman /// alias analysis implementations. 162b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman virtual AliasResult alias(const Location &LocA, const Location &LocB); 1634df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner 164b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// alias - A convenience wrapper. 1653da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman AliasResult alias(const Value *V1, uint64_t V1Size, 1663da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman const Value *V2, uint64_t V2Size) { 167b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman return alias(Location(V1, V1Size), Location(V2, V2Size)); 168b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman } 169b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman 170b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// alias - A convenience wrapper. 171847a84efd23a2c7d90429b82f6e0f19d1f913d9aDan Gohman AliasResult alias(const Value *V1, const Value *V2) { 172ef1cfac9e50def9097cd3e3ab3c5cad7f4c758ccDan Gohman return alias(V1, UnknownSize, V2, UnknownSize); 173847a84efd23a2c7d90429b82f6e0f19d1f913d9aDan Gohman } 174847a84efd23a2c7d90429b82f6e0f19d1f913d9aDan Gohman 175c46530b6a32a53edf0d6d32bcd09ea5d76940472Chris Lattner /// isNoAlias - A trivial helper function to check to see if the specified 176c46530b6a32a53edf0d6d32bcd09ea5d76940472Chris Lattner /// pointers are no-alias. 177b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman bool isNoAlias(const Location &LocA, const Location &LocB) { 178b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman return alias(LocA, LocB) == NoAlias; 179b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman } 180b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman 181b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// isNoAlias - A convenience wrapper. 1823da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman bool isNoAlias(const Value *V1, uint64_t V1Size, 1833da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman const Value *V2, uint64_t V2Size) { 184b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman return isNoAlias(Location(V1, V1Size), Location(V2, V2Size)); 185c46530b6a32a53edf0d6d32bcd09ea5d76940472Chris Lattner } 18672c194a8be83d217360ebc6b1f3ad21c5ffa16a9Chris Lattner 18772c194a8be83d217360ebc6b1f3ad21c5ffa16a9Chris Lattner /// isMustAlias - A convenience wrapper. 18872c194a8be83d217360ebc6b1f3ad21c5ffa16a9Chris Lattner bool isMustAlias(const Location &LocA, const Location &LocB) { 18972c194a8be83d217360ebc6b1f3ad21c5ffa16a9Chris Lattner return alias(LocA, LocB) == MustAlias; 19072c194a8be83d217360ebc6b1f3ad21c5ffa16a9Chris Lattner } 191c46530b6a32a53edf0d6d32bcd09ea5d76940472Chris Lattner 192cc10244d7725f191bdc91cd62befff0c97257c7bChris Lattner /// isMustAlias - A convenience wrapper. 193cc10244d7725f191bdc91cd62befff0c97257c7bChris Lattner bool isMustAlias(const Value *V1, const Value *V2) { 194cc10244d7725f191bdc91cd62befff0c97257c7bChris Lattner return alias(V1, 1, V2, 1) == MustAlias; 195cc10244d7725f191bdc91cd62befff0c97257c7bChris Lattner } 196cc10244d7725f191bdc91cd62befff0c97257c7bChris Lattner 197a25e5dbcc2371352386a01e3c1b8e76dd890272bDan Gohman /// pointsToConstantMemory - If the specified memory location is 198a25e5dbcc2371352386a01e3c1b8e76dd890272bDan Gohman /// known to be constant, return true. If OrLocal is true and the 199a25e5dbcc2371352386a01e3c1b8e76dd890272bDan Gohman /// specified memory location is known to be "local" (derived from 200a25e5dbcc2371352386a01e3c1b8e76dd890272bDan Gohman /// an alloca), return true. Otherwise return false. 201a25e5dbcc2371352386a01e3c1b8e76dd890272bDan Gohman virtual bool pointsToConstantMemory(const Location &Loc, 202a25e5dbcc2371352386a01e3c1b8e76dd890272bDan Gohman bool OrLocal = false); 203b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman 204b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// pointsToConstantMemory - A convenient wrapper. 205a25e5dbcc2371352386a01e3c1b8e76dd890272bDan Gohman bool pointsToConstantMemory(const Value *P, bool OrLocal = false) { 206a25e5dbcc2371352386a01e3c1b8e76dd890272bDan Gohman return pointsToConstantMemory(Location(P), OrLocal); 207b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman } 20862b5c167de0ca5883a7ad5eb0900eb0c15ad3707Chris Lattner 209248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner //===--------------------------------------------------------------------===// 210248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner /// Simple mod/ref information... 211248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner /// 212248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner 213248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner /// ModRefResult - Represent the result of a mod/ref query. Mod and Ref are 214248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner /// bits which may be or'd together. 215248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner /// 216248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner enum ModRefResult { NoModRef = 0, Ref = 1, Mod = 2, ModRef = 3 }; 2179769ab22265b313171d201b5928688524a01bd87Misha Brukman 21842c31a70735e55bf82e66a9315c97d1821c9a798Dan Gohman /// These values define additional bits used to define the 21942c31a70735e55bf82e66a9315c97d1821c9a798Dan Gohman /// ModRefBehavior values. 22042c31a70735e55bf82e66a9315c97d1821c9a798Dan Gohman enum { Nowhere = 0, ArgumentPointees = 4, Anywhere = 8 | ArgumentPointees }; 2219769ab22265b313171d201b5928688524a01bd87Misha Brukman 222248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner /// ModRefBehavior - Summary of how a function affects memory in the program. 223248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner /// Loads from constant globals are not considered memory accesses for this 224248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner /// interface. Also, functions may freely modify stack space local to their 225248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner /// invocation without having to report it through these interfaces. 226248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner enum ModRefBehavior { 22750a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// DoesNotAccessMemory - This function does not perform any non-local loads 22850a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// or stores to memory. 22950a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// 23050a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// This property corresponds to the GCC 'const' attribute. 23150a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// This property corresponds to the LLVM IR 'readnone' attribute. 23250a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// This property corresponds to the IntrNoMem LLVM intrinsic flag. 23342c31a70735e55bf82e66a9315c97d1821c9a798Dan Gohman DoesNotAccessMemory = Nowhere | NoModRef, 2349769ab22265b313171d201b5928688524a01bd87Misha Brukman 235e88ccb545d0e03fd4445d361100fc95f350c6663Dan Gohman /// OnlyReadsArgumentPointees - The only memory references in this function 236e88ccb545d0e03fd4445d361100fc95f350c6663Dan Gohman /// (if it has any) are non-volatile loads from objects pointed to by its 237e88ccb545d0e03fd4445d361100fc95f350c6663Dan Gohman /// pointer-typed arguments, with arbitrary offsets. 23850a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// 23950a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// This property corresponds to the IntrReadArgMem LLVM intrinsic flag. 240e88ccb545d0e03fd4445d361100fc95f350c6663Dan Gohman OnlyReadsArgumentPointees = ArgumentPointees | Ref, 241db78c4873ea8c4b3dce90d761a1ad59d5bcdd6e7Dan Gohman 242e88ccb545d0e03fd4445d361100fc95f350c6663Dan Gohman /// OnlyAccessesArgumentPointees - The only memory references in this 243e88ccb545d0e03fd4445d361100fc95f350c6663Dan Gohman /// function (if it has any) are non-volatile loads and stores from objects 244e88ccb545d0e03fd4445d361100fc95f350c6663Dan Gohman /// pointed to by its pointer-typed arguments, with arbitrary offsets. 24550a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// 24650a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// This property corresponds to the IntrReadWriteArgMem LLVM intrinsic flag. 247e88ccb545d0e03fd4445d361100fc95f350c6663Dan Gohman OnlyAccessesArgumentPointees = ArgumentPointees | ModRef, 2489769ab22265b313171d201b5928688524a01bd87Misha Brukman 24950a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// OnlyReadsMemory - This function does not perform any non-local stores or 25050a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// volatile loads, but may read from any memory location. 25150a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// 25250a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// This property corresponds to the GCC 'pure' attribute. 25350a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// This property corresponds to the LLVM IR 'readonly' attribute. 25450a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// This property corresponds to the IntrReadMem LLVM intrinsic flag. 25542c31a70735e55bf82e66a9315c97d1821c9a798Dan Gohman OnlyReadsMemory = Anywhere | Ref, 2569769ab22265b313171d201b5928688524a01bd87Misha Brukman 25750a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// UnknownModRefBehavior - This indicates that the function could not be 25850a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// classified into one of the behaviors above. 25942c31a70735e55bf82e66a9315c97d1821c9a798Dan Gohman UnknownModRefBehavior = Anywhere | ModRef 260248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner }; 2619769ab22265b313171d201b5928688524a01bd87Misha Brukman 262dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// getModRefBehavior - Return the behavior when calling the given call site. 263a41af344c2964573318a77e2b43eafd4d3804003Dan Gohman virtual ModRefBehavior getModRefBehavior(ImmutableCallSite CS); 264dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands 265dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// getModRefBehavior - Return the behavior when calling the given function. 266dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// For use when the call site is not known. 267a41af344c2964573318a77e2b43eafd4d3804003Dan Gohman virtual ModRefBehavior getModRefBehavior(const Function *F); 268dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands 269dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// doesNotAccessMemory - If the specified call is known to never read or 270dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// write memory, return true. If the call only reads from known-constant 271dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// memory, it is also legal to return true. Calls that unwind the stack 272dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// are legal for this predicate. 2733e295b1b59e47916c8ae5d42eb27a23bd580cabeChris Lattner /// 274dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// Many optimizations (such as CSE and LICM) can be performed on such calls 275dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// without worrying about aliasing properties, and many calls have this 276dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// property (e.g. calls to 'sin' and 'cos'). 2773e295b1b59e47916c8ae5d42eb27a23bd580cabeChris Lattner /// 2783e295b1b59e47916c8ae5d42eb27a23bd580cabeChris Lattner /// This property corresponds to the GCC 'const' attribute. 2793e295b1b59e47916c8ae5d42eb27a23bd580cabeChris Lattner /// 28079fca6fea87be7221843031870bbf2c9ae1fc555Dan Gohman bool doesNotAccessMemory(ImmutableCallSite CS) { 281652f7ea955bb433d6b7a4d33685dca9485fd7b8bEvan Cheng return getModRefBehavior(CS) == DoesNotAccessMemory; 282dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands } 283dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands 284dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// doesNotAccessMemory - If the specified function is known to never read or 285dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// write memory, return true. For use when the call site is not known. 286dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// 28779fca6fea87be7221843031870bbf2c9ae1fc555Dan Gohman bool doesNotAccessMemory(const Function *F) { 288dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands return getModRefBehavior(F) == DoesNotAccessMemory; 289248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner } 2903e295b1b59e47916c8ae5d42eb27a23bd580cabeChris Lattner 291dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// onlyReadsMemory - If the specified call is known to only read from 292dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// non-volatile memory (or not access memory at all), return true. Calls 293dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// that unwind the stack are legal for this predicate. 2943e295b1b59e47916c8ae5d42eb27a23bd580cabeChris Lattner /// 2953e295b1b59e47916c8ae5d42eb27a23bd580cabeChris Lattner /// This property allows many common optimizations to be performed in the 2963e295b1b59e47916c8ae5d42eb27a23bd580cabeChris Lattner /// absence of interfering store instructions, such as CSE of strlen calls. 2973e295b1b59e47916c8ae5d42eb27a23bd580cabeChris Lattner /// 2983e295b1b59e47916c8ae5d42eb27a23bd580cabeChris Lattner /// This property corresponds to the GCC 'pure' attribute. 2993e295b1b59e47916c8ae5d42eb27a23bd580cabeChris Lattner /// 30079fca6fea87be7221843031870bbf2c9ae1fc555Dan Gohman bool onlyReadsMemory(ImmutableCallSite CS) { 301467a0adfc8b6bd4b114e024c200c159497a4cd86Dan Gohman return onlyReadsMemory(getModRefBehavior(CS)); 302dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands } 303dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands 304dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// onlyReadsMemory - If the specified function is known to only read from 305dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// non-volatile memory (or not access memory at all), return true. For use 306dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// when the call site is not known. 307dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// 30879fca6fea87be7221843031870bbf2c9ae1fc555Dan Gohman bool onlyReadsMemory(const Function *F) { 309467a0adfc8b6bd4b114e024c200c159497a4cd86Dan Gohman return onlyReadsMemory(getModRefBehavior(F)); 310467a0adfc8b6bd4b114e024c200c159497a4cd86Dan Gohman } 311467a0adfc8b6bd4b114e024c200c159497a4cd86Dan Gohman 312432d08cbdb9ceaa333f1d6eab4f8b542fdddf9dbDan Gohman /// onlyReadsMemory - Return true if functions with the specified behavior are 313432d08cbdb9ceaa333f1d6eab4f8b542fdddf9dbDan Gohman /// known to only read from non-volatile memory (or not access memory at all). 314467a0adfc8b6bd4b114e024c200c159497a4cd86Dan Gohman /// 315467a0adfc8b6bd4b114e024c200c159497a4cd86Dan Gohman static bool onlyReadsMemory(ModRefBehavior MRB) { 31642c31a70735e55bf82e66a9315c97d1821c9a798Dan Gohman return !(MRB & Mod); 317248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner } 3184df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner 319432d08cbdb9ceaa333f1d6eab4f8b542fdddf9dbDan Gohman /// onlyAccessesArgPointees - Return true if functions with the specified 320b395e4a0262c36b17b18aa33514b2daf2a85e9a3Dan Gohman /// behavior are known to read and write at most from objects pointed to by 321b395e4a0262c36b17b18aa33514b2daf2a85e9a3Dan Gohman /// their pointer-typed arguments (with arbitrary offsets). 322432d08cbdb9ceaa333f1d6eab4f8b542fdddf9dbDan Gohman /// 323432d08cbdb9ceaa333f1d6eab4f8b542fdddf9dbDan Gohman static bool onlyAccessesArgPointees(ModRefBehavior MRB) { 324432d08cbdb9ceaa333f1d6eab4f8b542fdddf9dbDan Gohman return !(MRB & Anywhere & ~ArgumentPointees); 325432d08cbdb9ceaa333f1d6eab4f8b542fdddf9dbDan Gohman } 326432d08cbdb9ceaa333f1d6eab4f8b542fdddf9dbDan Gohman 32768a6056dafd4913ce42606353ab1ff7208215ff2Dan Gohman /// doesAccessArgPointees - Return true if functions with the specified 32868a6056dafd4913ce42606353ab1ff7208215ff2Dan Gohman /// behavior are known to potentially read or write from objects pointed 32968a6056dafd4913ce42606353ab1ff7208215ff2Dan Gohman /// to be their pointer-typed arguments (with arbitrary offsets). 33068a6056dafd4913ce42606353ab1ff7208215ff2Dan Gohman /// 33168a6056dafd4913ce42606353ab1ff7208215ff2Dan Gohman static bool doesAccessArgPointees(ModRefBehavior MRB) { 33268a6056dafd4913ce42606353ab1ff7208215ff2Dan Gohman return (MRB & ModRef) && (MRB & ArgumentPointees); 33368a6056dafd4913ce42606353ab1ff7208215ff2Dan Gohman } 33468a6056dafd4913ce42606353ab1ff7208215ff2Dan Gohman 3351c56b730a6313886076d7b293a126ae5576f5288Chris Lattner /// getModRefInfo - Return information about whether or not an instruction may 336b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// read or write the specified memory location. An instruction 3371c56b730a6313886076d7b293a126ae5576f5288Chris Lattner /// that doesn't read or write memory may be trivially LICM'd for example. 338fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman ModRefResult getModRefInfo(const Instruction *I, 339b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman const Location &Loc) { 340fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman switch (I->getOpcode()) { 341b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman case Instruction::VAArg: return getModRefInfo((const VAArgInst*)I, Loc); 342b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman case Instruction::Load: return getModRefInfo((const LoadInst*)I, Loc); 343b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman case Instruction::Store: return getModRefInfo((const StoreInst*)I, Loc); 344b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman case Instruction::Call: return getModRefInfo((const CallInst*)I, Loc); 345b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman case Instruction::Invoke: return getModRefInfo((const InvokeInst*)I,Loc); 346fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman default: return NoModRef; 347fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman } 348fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman } 3491c56b730a6313886076d7b293a126ae5576f5288Chris Lattner 350b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// getModRefInfo - A convenience wrapper. 351b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman ModRefResult getModRefInfo(const Instruction *I, 3523da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman const Value *P, uint64_t Size) { 353b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman return getModRefInfo(I, Location(P, Size)); 354b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman } 355b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman 3561c56b730a6313886076d7b293a126ae5576f5288Chris Lattner /// getModRefInfo (for call sites) - Return whether information about whether 357b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// a particular call site modifies or reads the specified memory location. 35879fca6fea87be7221843031870bbf2c9ae1fc555Dan Gohman virtual ModRefResult getModRefInfo(ImmutableCallSite CS, 359b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman const Location &Loc); 360b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman 361b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// getModRefInfo (for call sites) - A convenience wrapper. 362b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman ModRefResult getModRefInfo(ImmutableCallSite CS, 3633da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman const Value *P, uint64_t Size) { 364b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman return getModRefInfo(CS, Location(P, Size)); 365b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman } 3661c56b730a6313886076d7b293a126ae5576f5288Chris Lattner 367fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman /// getModRefInfo (for calls) - Return whether information about whether 368b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// a particular call modifies or reads the specified memory location. 369b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman ModRefResult getModRefInfo(const CallInst *C, const Location &Loc) { 370b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman return getModRefInfo(ImmutableCallSite(C), Loc); 371b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman } 372b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman 373b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// getModRefInfo (for calls) - A convenience wrapper. 3743da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman ModRefResult getModRefInfo(const CallInst *C, const Value *P, uint64_t Size) { 375b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman return getModRefInfo(C, Location(P, Size)); 3761c56b730a6313886076d7b293a126ae5576f5288Chris Lattner } 377fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman 378fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman /// getModRefInfo (for invokes) - Return whether information about whether 379b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// a particular invoke modifies or reads the specified memory location. 380b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman ModRefResult getModRefInfo(const InvokeInst *I, 381b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman const Location &Loc) { 382b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman return getModRefInfo(ImmutableCallSite(I), Loc); 383b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman } 384b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman 385b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// getModRefInfo (for invokes) - A convenience wrapper. 38679fca6fea87be7221843031870bbf2c9ae1fc555Dan Gohman ModRefResult getModRefInfo(const InvokeInst *I, 3873da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman const Value *P, uint64_t Size) { 388b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman return getModRefInfo(I, Location(P, Size)); 3891c56b730a6313886076d7b293a126ae5576f5288Chris Lattner } 390fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman 391fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman /// getModRefInfo (for loads) - Return whether information about whether 392b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// a particular load modifies or reads the specified memory location. 393b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman ModRefResult getModRefInfo(const LoadInst *L, const Location &Loc); 394b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman 395b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// getModRefInfo (for loads) - A convenience wrapper. 3963da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman ModRefResult getModRefInfo(const LoadInst *L, const Value *P, uint64_t Size) { 397b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman return getModRefInfo(L, Location(P, Size)); 398b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman } 399fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman 400fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman /// getModRefInfo (for stores) - Return whether information about whether 401b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// a particular store modifies or reads the specified memory location. 402b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman ModRefResult getModRefInfo(const StoreInst *S, const Location &Loc); 403b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman 404b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// getModRefInfo (for stores) - A convenience wrapper. 4052feee6454d4c9cbb3a104b0f593d31a91a14d15aChris Lattner ModRefResult getModRefInfo(const StoreInst *S, const Value *P, uint64_t Size){ 406b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman return getModRefInfo(S, Location(P, Size)); 407b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman } 408fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman 409fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman /// getModRefInfo (for va_args) - Return whether information about whether 410b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// a particular va_arg modifies or reads the specified memory location. 411b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman ModRefResult getModRefInfo(const VAArgInst* I, const Location &Loc); 412b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman 413b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// getModRefInfo (for va_args) - A convenience wrapper. 4142feee6454d4c9cbb3a104b0f593d31a91a14d15aChris Lattner ModRefResult getModRefInfo(const VAArgInst* I, const Value* P, uint64_t Size){ 415b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman return getModRefInfo(I, Location(P, Size)); 416b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman } 417fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman 418fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman /// getModRefInfo - Return information about whether two call sites may refer 419fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman /// to the same set of memory locations. See 420fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman /// http://llvm.org/docs/AliasAnalysis.html#ModRefInfo 421fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman /// for details. 422fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman virtual ModRefResult getModRefInfo(ImmutableCallSite CS1, 423fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman ImmutableCallSite CS2); 4244df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner 425ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner //===--------------------------------------------------------------------===// 426ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// Higher level methods for querying mod/ref information. 427ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// 428ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner 429f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner /// canBasicBlockModify - Return true if it is possible for execution of the 430f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner /// specified basic block to modify the value pointed to by Ptr. 431b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman bool canBasicBlockModify(const BasicBlock &BB, const Location &Loc); 432b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman 433b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// canBasicBlockModify - A convenience wrapper. 4343da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman bool canBasicBlockModify(const BasicBlock &BB, const Value *P, uint64_t Size){ 435b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman return canBasicBlockModify(BB, Location(P, Size)); 436b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman } 4374df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner 438f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner /// canInstructionRangeModify - Return true if it is possible for the 439f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner /// execution of the specified instructions to modify the value pointed to by 440f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner /// Ptr. The instructions to consider are all of the instructions in the 441f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner /// range of [I1,I2] INCLUSIVE. I1 and I2 must be in the same basic block. 4424df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner bool canInstructionRangeModify(const Instruction &I1, const Instruction &I2, 443b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman const Location &Loc); 444b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman 445b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// canInstructionRangeModify - A convenience wrapper. 446b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman bool canInstructionRangeModify(const Instruction &I1, const Instruction &I2, 4473da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman const Value *Ptr, uint64_t Size) { 448b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman return canInstructionRangeModify(I1, I2, Location(Ptr, Size)); 449b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman } 450ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner 451ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner //===--------------------------------------------------------------------===// 452ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// Methods that clients should call when they transform the program to allow 453ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// alias analyses to update their internal data structures. Note that these 454ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// methods may be called on any instruction, regardless of whether or not 455ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// they have pointer-analysis implications. 456ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// 457ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner 458ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// deleteValue - This method should be called whenever an LLVM Value is 459ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// deleted from the program, for example when an instruction is found to be 460ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// redundant and is eliminated. 461ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// 462ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner virtual void deleteValue(Value *V); 463ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner 464ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// copyValue - This method should be used whenever a preexisting value in the 465ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// program is copied or cloned, introducing a new value. Note that analysis 466ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// implementations should tolerate clients that use this method to introduce 467ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// the same value multiple times: if the analysis already knows about a 468ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// value, it should ignore the request. 469ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// 470ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner virtual void copyValue(Value *From, Value *To); 471ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner 472ab6acc6ecdc4585a55059e36d81481d1c26d3ff9Owen Anderson /// addEscapingUse - This method should be used whenever an escaping use is 473ab6acc6ecdc4585a55059e36d81481d1c26d3ff9Owen Anderson /// added to a pointer value. Analysis implementations may either return 474ab6acc6ecdc4585a55059e36d81481d1c26d3ff9Owen Anderson /// conservative responses for that value in the future, or may recompute 475ab6acc6ecdc4585a55059e36d81481d1c26d3ff9Owen Anderson /// some or all internal state to continue providing precise responses. 476ab6acc6ecdc4585a55059e36d81481d1c26d3ff9Owen Anderson /// 477ab6acc6ecdc4585a55059e36d81481d1c26d3ff9Owen Anderson /// Escaping uses are considered by anything _except_ the following: 478ab6acc6ecdc4585a55059e36d81481d1c26d3ff9Owen Anderson /// - GEPs or bitcasts of the pointer 479ab6acc6ecdc4585a55059e36d81481d1c26d3ff9Owen Anderson /// - Loads through the pointer 480ab6acc6ecdc4585a55059e36d81481d1c26d3ff9Owen Anderson /// - Stores through (but not of) the pointer 481ab6acc6ecdc4585a55059e36d81481d1c26d3ff9Owen Anderson virtual void addEscapingUse(Use &U); 482ab6acc6ecdc4585a55059e36d81481d1c26d3ff9Owen Anderson 483ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// replaceWithNewValue - This method is the obvious combination of the two 484ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// above, and it provided as a helper to simplify client code. 485ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// 486ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner void replaceWithNewValue(Value *Old, Value *New) { 487ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner copyValue(Old, New); 488ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner deleteValue(Old); 489ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner } 4904df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner}; 4914df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner 492a5f81bba4ab18d6129774d4d67495f14b6f64375Dan Gohman/// isNoAliasCall - Return true if this pointer is returned by a noalias 493a5f81bba4ab18d6129774d4d67495f14b6f64375Dan Gohman/// function. 494a5f81bba4ab18d6129774d4d67495f14b6f64375Dan Gohmanbool isNoAliasCall(const Value *V); 495a5f81bba4ab18d6129774d4d67495f14b6f64375Dan Gohman 4963311a1f8f0d8a2c6d940802bbb95eba0b801a615Dan Gohman/// isIdentifiedObject - Return true if this pointer refers to a distinct and 497a5f81bba4ab18d6129774d4d67495f14b6f64375Dan Gohman/// identifiable object. This returns true for: 4985753a4a0033da4add45f2e9930a4e1159d92a869Dan Gohman/// Global Variables and Functions (but not Global Aliases) 499a5f81bba4ab18d6129774d4d67495f14b6f64375Dan Gohman/// Allocas and Mallocs 5009e86f4364b912ae743490ba01d6989acfd12c046Dan Gohman/// ByVal and NoAlias Arguments 5019e86f4364b912ae743490ba01d6989acfd12c046Dan Gohman/// NoAlias returns 5023311a1f8f0d8a2c6d940802bbb95eba0b801a615Dan Gohman/// 5039e86f4364b912ae743490ba01d6989acfd12c046Dan Gohmanbool isIdentifiedObject(const Value *V); 5043311a1f8f0d8a2c6d940802bbb95eba0b801a615Dan Gohman 5054f1bd9e9963239c119db70070db1d68286b3de7eReid Spencer} // End llvm namespace 5064f1bd9e9963239c119db70070db1d68286b3de7eReid Spencer 5074df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner#endif 508