AliasAnalysis.h revision 6d8eb156e6be727570b300bac7712f745a318c7d
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; 511c56b730a6313886076d7b293a126ae5576f5288Chris Lattner 521c56b730a6313886076d7b293a126ae5576f5288Chris Lattnerclass AliasAnalysis { 531c56b730a6313886076d7b293a126ae5576f5288Chris Lattnerprotected: 54ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner const TargetData *TD; 55cb74993bdc37681ddbb80fa361575107afae1350Dan Gohman 56cb74993bdc37681ddbb80fa361575107afae1350Dan Gohmanprivate: 57ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner AliasAnalysis *AA; // Previous Alias Analysis to chain to. 58ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner 59cb74993bdc37681ddbb80fa361575107afae1350Dan Gohmanprotected: 601c56b730a6313886076d7b293a126ae5576f5288Chris Lattner /// InitializeAliasAnalysis - Subclasses must call this method to initialize 611c56b730a6313886076d7b293a126ae5576f5288Chris Lattner /// the AliasAnalysis interface before any other methods are called. This is 621c56b730a6313886076d7b293a126ae5576f5288Chris Lattner /// typically called by the run* methods of these subclasses. This may be 631c56b730a6313886076d7b293a126ae5576f5288Chris Lattner /// called multiple times. 641c56b730a6313886076d7b293a126ae5576f5288Chris Lattner /// 651c56b730a6313886076d7b293a126ae5576f5288Chris Lattner void InitializeAliasAnalysis(Pass *P); 669769ab22265b313171d201b5928688524a01bd87Misha Brukman 6764d237cfae6bcb11157d525c79b5a5335e30370bDan Gohman /// getAnalysisUsage - All alias analysis implementations should invoke this 68fc2a3ed0c9e32cf7edaf5030fa0972b916cc5f0bDan Gohman /// directly (using AliasAnalysis::getAnalysisUsage(AU)). 691c56b730a6313886076d7b293a126ae5576f5288Chris Lattner virtual void getAnalysisUsage(AnalysisUsage &AU) const; 701c56b730a6313886076d7b293a126ae5576f5288Chris Lattner 711c56b730a6313886076d7b293a126ae5576f5288Chris Lattnerpublic: 721997473cf72957d0e70322e2fe6fe2ab141c58a6Devang Patel static char ID; // Class identification, replacement for typeinfo 73ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner AliasAnalysis() : TD(0), AA(0) {} 741c56b730a6313886076d7b293a126ae5576f5288Chris Lattner virtual ~AliasAnalysis(); // We want to be subclassed 751c56b730a6313886076d7b293a126ae5576f5288Chris Lattner 76ef1cfac9e50def9097cd3e3ab3c5cad7f4c758ccDan Gohman /// UnknownSize - This is a special value which can be used with the 77ef1cfac9e50def9097cd3e3ab3c5cad7f4c758ccDan Gohman /// size arguments in alias queries to indicate that the caller does not 78ef1cfac9e50def9097cd3e3ab3c5cad7f4c758ccDan Gohman /// know the sizes of the potential memory references. 793da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman static uint64_t const UnknownSize = ~UINT64_C(0); 80ef1cfac9e50def9097cd3e3ab3c5cad7f4c758ccDan Gohman 81fc2a3ed0c9e32cf7edaf5030fa0972b916cc5f0bDan Gohman /// getTargetData - Return a pointer to the current TargetData object, or 82fc2a3ed0c9e32cf7edaf5030fa0972b916cc5f0bDan Gohman /// null if no TargetData object is available. 83dd298c8c6eb036baf35bf5a559c59d2afd2c7944Misha Brukman /// 84fc2a3ed0c9e32cf7edaf5030fa0972b916cc5f0bDan Gohman const TargetData *getTargetData() const { return TD; } 85fc2a3ed0c9e32cf7edaf5030fa0972b916cc5f0bDan Gohman 86fc2a3ed0c9e32cf7edaf5030fa0972b916cc5f0bDan Gohman /// getTypeStoreSize - Return the TargetData store size for the given type, 87fc2a3ed0c9e32cf7edaf5030fa0972b916cc5f0bDan Gohman /// if known, or a conservative value otherwise. 88fc2a3ed0c9e32cf7edaf5030fa0972b916cc5f0bDan Gohman /// 893da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman uint64_t getTypeStoreSize(const Type *Ty); 904df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner 911c56b730a6313886076d7b293a126ae5576f5288Chris Lattner //===--------------------------------------------------------------------===// 921c56b730a6313886076d7b293a126ae5576f5288Chris Lattner /// Alias Queries... 931c56b730a6313886076d7b293a126ae5576f5288Chris Lattner /// 944df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner 95b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// Location - A description of a memory location. 96b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman struct Location { 97b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// Ptr - The address of the start of the location. 98b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman const Value *Ptr; 996c25c920e66aa2d8f6b48454bc9770087ff7939aDan Gohman /// Size - The maximum size of the location, or UnknownSize if the size is 1006c25c920e66aa2d8f6b48454bc9770087ff7939aDan Gohman /// not known. Note that an unknown size does not mean the pointer aliases 1016c25c920e66aa2d8f6b48454bc9770087ff7939aDan Gohman /// the entire virtual address space, because there are restrictions on 1026c25c920e66aa2d8f6b48454bc9770087ff7939aDan Gohman /// stepping out of one object and into another. 1036c25c920e66aa2d8f6b48454bc9770087ff7939aDan Gohman /// See http://llvm.org/docs/LangRef.html#pointeraliasing 1043da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman uint64_t Size; 105b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// TBAATag - The metadata node which describes the TBAA type of 1066c25c920e66aa2d8f6b48454bc9770087ff7939aDan Gohman /// the location, or null if there is no known unique tag. 107b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman const MDNode *TBAATag; 108b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman 109b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman explicit Location(const Value *P = 0, 1103da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman uint64_t S = UnknownSize, 111b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman const MDNode *N = 0) 112b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman : Ptr(P), Size(S), TBAATag(N) {} 1139f27074f42f03af640977006dc7c05005fb77991Dan Gohman 1149f27074f42f03af640977006dc7c05005fb77991Dan Gohman Location getWithNewPtr(const Value *NewPtr) const { 1159f27074f42f03af640977006dc7c05005fb77991Dan Gohman Location Copy(*this); 1169f27074f42f03af640977006dc7c05005fb77991Dan Gohman Copy.Ptr = NewPtr; 1179f27074f42f03af640977006dc7c05005fb77991Dan Gohman return Copy; 1189f27074f42f03af640977006dc7c05005fb77991Dan Gohman } 1199f27074f42f03af640977006dc7c05005fb77991Dan Gohman 120075fb5d68fcb55d26e44c48f07dfdbbfa21ccb2aDan Gohman Location getWithNewSize(uint64_t NewSize) const { 121075fb5d68fcb55d26e44c48f07dfdbbfa21ccb2aDan Gohman Location Copy(*this); 122075fb5d68fcb55d26e44c48f07dfdbbfa21ccb2aDan Gohman Copy.Size = NewSize; 123075fb5d68fcb55d26e44c48f07dfdbbfa21ccb2aDan Gohman return Copy; 124075fb5d68fcb55d26e44c48f07dfdbbfa21ccb2aDan Gohman } 125075fb5d68fcb55d26e44c48f07dfdbbfa21ccb2aDan Gohman 1269f27074f42f03af640977006dc7c05005fb77991Dan Gohman Location getWithoutTBAATag() const { 1279f27074f42f03af640977006dc7c05005fb77991Dan Gohman Location Copy(*this); 1289f27074f42f03af640977006dc7c05005fb77991Dan Gohman Copy.TBAATag = 0; 1299f27074f42f03af640977006dc7c05005fb77991Dan Gohman return Copy; 1309f27074f42f03af640977006dc7c05005fb77991Dan Gohman } 131b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman }; 132b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman 1336d8eb156e6be727570b300bac7712f745a318c7dDan Gohman /// getLocation - Fill in Loc with information about the memory reference by 1346d8eb156e6be727570b300bac7712f745a318c7dDan Gohman /// the given instruction. 1356d8eb156e6be727570b300bac7712f745a318c7dDan Gohman Location getLocation(const LoadInst *LI); 1366d8eb156e6be727570b300bac7712f745a318c7dDan Gohman Location getLocation(const StoreInst *SI); 1376d8eb156e6be727570b300bac7712f745a318c7dDan Gohman Location getLocation(const VAArgInst *VI); 1386d8eb156e6be727570b300bac7712f745a318c7dDan Gohman 139f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner /// Alias analysis result - Either we know for sure that it does not alias, we 140f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner /// know for sure it must alias, or we don't know anything: The two pointers 141f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner /// _might_ alias. This enum is designed so you can do things like: 142f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner /// if (AA.alias(P1, P2)) { ... } 143f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner /// to check to see if two pointers might alias. 144f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner /// 145e53e3772f3c8b4cba69b7d77c8b2148a080fe9aeDan Gohman /// See docs/AliasAnalysis.html for more information on the specific meanings 146e53e3772f3c8b4cba69b7d77c8b2148a080fe9aeDan Gohman /// of these values. 147e53e3772f3c8b4cba69b7d77c8b2148a080fe9aeDan Gohman /// 14817e8078ae14ed71f657d59c77efa3bedf171161aDan Gohman enum AliasResult { 14917e8078ae14ed71f657d59c77efa3bedf171161aDan Gohman NoAlias = 0, ///< No dependencies. 15017e8078ae14ed71f657d59c77efa3bedf171161aDan Gohman MayAlias = 1, ///< Anything goes. 15117e8078ae14ed71f657d59c77efa3bedf171161aDan Gohman MustAlias = 2 ///< Pointers are equal. 15217e8078ae14ed71f657d59c77efa3bedf171161aDan Gohman }; 1534df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner 154f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner /// alias - The main low level interface to the alias analysis implementation. 1556c25c920e66aa2d8f6b48454bc9770087ff7939aDan Gohman /// Returns an AliasResult indicating whether the two pointers are aliased to 1566c25c920e66aa2d8f6b48454bc9770087ff7939aDan Gohman /// each other. This is the interface that must be implemented by specific 1576c25c920e66aa2d8f6b48454bc9770087ff7939aDan Gohman /// alias analysis implementations. 158b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman virtual AliasResult alias(const Location &LocA, const Location &LocB); 1594df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner 160b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// alias - A convenience wrapper. 1613da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman AliasResult alias(const Value *V1, uint64_t V1Size, 1623da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman const Value *V2, uint64_t V2Size) { 163b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman return alias(Location(V1, V1Size), Location(V2, V2Size)); 164b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman } 165b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman 166b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// alias - A convenience wrapper. 167847a84efd23a2c7d90429b82f6e0f19d1f913d9aDan Gohman AliasResult alias(const Value *V1, const Value *V2) { 168ef1cfac9e50def9097cd3e3ab3c5cad7f4c758ccDan Gohman return alias(V1, UnknownSize, V2, UnknownSize); 169847a84efd23a2c7d90429b82f6e0f19d1f913d9aDan Gohman } 170847a84efd23a2c7d90429b82f6e0f19d1f913d9aDan Gohman 171c46530b6a32a53edf0d6d32bcd09ea5d76940472Chris Lattner /// isNoAlias - A trivial helper function to check to see if the specified 172c46530b6a32a53edf0d6d32bcd09ea5d76940472Chris Lattner /// pointers are no-alias. 173b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman bool isNoAlias(const Location &LocA, const Location &LocB) { 174b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman return alias(LocA, LocB) == NoAlias; 175b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman } 176b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman 177b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// isNoAlias - A convenience wrapper. 1783da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman bool isNoAlias(const Value *V1, uint64_t V1Size, 1793da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman const Value *V2, uint64_t V2Size) { 180b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman return isNoAlias(Location(V1, V1Size), Location(V2, V2Size)); 181c46530b6a32a53edf0d6d32bcd09ea5d76940472Chris Lattner } 182c46530b6a32a53edf0d6d32bcd09ea5d76940472Chris Lattner 183a25e5dbcc2371352386a01e3c1b8e76dd890272bDan Gohman /// pointsToConstantMemory - If the specified memory location is 184a25e5dbcc2371352386a01e3c1b8e76dd890272bDan Gohman /// known to be constant, return true. If OrLocal is true and the 185a25e5dbcc2371352386a01e3c1b8e76dd890272bDan Gohman /// specified memory location is known to be "local" (derived from 186a25e5dbcc2371352386a01e3c1b8e76dd890272bDan Gohman /// an alloca), return true. Otherwise return false. 187a25e5dbcc2371352386a01e3c1b8e76dd890272bDan Gohman virtual bool pointsToConstantMemory(const Location &Loc, 188a25e5dbcc2371352386a01e3c1b8e76dd890272bDan Gohman bool OrLocal = false); 189b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman 190b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// pointsToConstantMemory - A convenient wrapper. 191a25e5dbcc2371352386a01e3c1b8e76dd890272bDan Gohman bool pointsToConstantMemory(const Value *P, bool OrLocal = false) { 192a25e5dbcc2371352386a01e3c1b8e76dd890272bDan Gohman return pointsToConstantMemory(Location(P), OrLocal); 193b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman } 19462b5c167de0ca5883a7ad5eb0900eb0c15ad3707Chris Lattner 195248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner //===--------------------------------------------------------------------===// 196248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner /// Simple mod/ref information... 197248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner /// 198248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner 199248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner /// ModRefResult - Represent the result of a mod/ref query. Mod and Ref are 200248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner /// bits which may be or'd together. 201248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner /// 202248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner enum ModRefResult { NoModRef = 0, Ref = 1, Mod = 2, ModRef = 3 }; 2039769ab22265b313171d201b5928688524a01bd87Misha Brukman 20442c31a70735e55bf82e66a9315c97d1821c9a798Dan Gohman /// These values define additional bits used to define the 20542c31a70735e55bf82e66a9315c97d1821c9a798Dan Gohman /// ModRefBehavior values. 20642c31a70735e55bf82e66a9315c97d1821c9a798Dan Gohman enum { Nowhere = 0, ArgumentPointees = 4, Anywhere = 8 | ArgumentPointees }; 2079769ab22265b313171d201b5928688524a01bd87Misha Brukman 208248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner /// ModRefBehavior - Summary of how a function affects memory in the program. 209248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner /// Loads from constant globals are not considered memory accesses for this 210248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner /// interface. Also, functions may freely modify stack space local to their 211248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner /// invocation without having to report it through these interfaces. 212248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner enum ModRefBehavior { 21350a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// DoesNotAccessMemory - This function does not perform any non-local loads 21450a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// or stores to memory. 21550a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// 21650a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// This property corresponds to the GCC 'const' attribute. 21750a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// This property corresponds to the LLVM IR 'readnone' attribute. 21850a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// This property corresponds to the IntrNoMem LLVM intrinsic flag. 21942c31a70735e55bf82e66a9315c97d1821c9a798Dan Gohman DoesNotAccessMemory = Nowhere | NoModRef, 2209769ab22265b313171d201b5928688524a01bd87Misha Brukman 221e88ccb545d0e03fd4445d361100fc95f350c6663Dan Gohman /// OnlyReadsArgumentPointees - The only memory references in this function 222e88ccb545d0e03fd4445d361100fc95f350c6663Dan Gohman /// (if it has any) are non-volatile loads from objects pointed to by its 223e88ccb545d0e03fd4445d361100fc95f350c6663Dan Gohman /// pointer-typed arguments, with arbitrary offsets. 22450a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// 22550a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// This property corresponds to the IntrReadArgMem LLVM intrinsic flag. 226e88ccb545d0e03fd4445d361100fc95f350c6663Dan Gohman OnlyReadsArgumentPointees = ArgumentPointees | Ref, 227db78c4873ea8c4b3dce90d761a1ad59d5bcdd6e7Dan Gohman 228e88ccb545d0e03fd4445d361100fc95f350c6663Dan Gohman /// OnlyAccessesArgumentPointees - The only memory references in this 229e88ccb545d0e03fd4445d361100fc95f350c6663Dan Gohman /// function (if it has any) are non-volatile loads and stores from objects 230e88ccb545d0e03fd4445d361100fc95f350c6663Dan Gohman /// pointed to by its pointer-typed arguments, with arbitrary offsets. 23150a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// 23250a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// This property corresponds to the IntrReadWriteArgMem LLVM intrinsic flag. 233e88ccb545d0e03fd4445d361100fc95f350c6663Dan Gohman OnlyAccessesArgumentPointees = ArgumentPointees | ModRef, 2349769ab22265b313171d201b5928688524a01bd87Misha Brukman 23550a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// OnlyReadsMemory - This function does not perform any non-local stores or 23650a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// volatile loads, but may read from any memory location. 23750a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// 23850a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// This property corresponds to the GCC 'pure' attribute. 23950a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// This property corresponds to the LLVM IR 'readonly' attribute. 24050a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// This property corresponds to the IntrReadMem LLVM intrinsic flag. 24142c31a70735e55bf82e66a9315c97d1821c9a798Dan Gohman OnlyReadsMemory = Anywhere | Ref, 2429769ab22265b313171d201b5928688524a01bd87Misha Brukman 24350a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// UnknownModRefBehavior - This indicates that the function could not be 24450a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// classified into one of the behaviors above. 24542c31a70735e55bf82e66a9315c97d1821c9a798Dan Gohman UnknownModRefBehavior = Anywhere | ModRef 246248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner }; 2479769ab22265b313171d201b5928688524a01bd87Misha Brukman 248dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// getModRefBehavior - Return the behavior when calling the given call site. 249a41af344c2964573318a77e2b43eafd4d3804003Dan Gohman virtual ModRefBehavior getModRefBehavior(ImmutableCallSite CS); 250dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands 251dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// getModRefBehavior - Return the behavior when calling the given function. 252dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// For use when the call site is not known. 253a41af344c2964573318a77e2b43eafd4d3804003Dan Gohman virtual ModRefBehavior getModRefBehavior(const Function *F); 254dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands 255dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// doesNotAccessMemory - If the specified call is known to never read or 256dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// write memory, return true. If the call only reads from known-constant 257dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// memory, it is also legal to return true. Calls that unwind the stack 258dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// are legal for this predicate. 2593e295b1b59e47916c8ae5d42eb27a23bd580cabeChris Lattner /// 260dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// Many optimizations (such as CSE and LICM) can be performed on such calls 261dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// without worrying about aliasing properties, and many calls have this 262dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// property (e.g. calls to 'sin' and 'cos'). 2633e295b1b59e47916c8ae5d42eb27a23bd580cabeChris Lattner /// 2643e295b1b59e47916c8ae5d42eb27a23bd580cabeChris Lattner /// This property corresponds to the GCC 'const' attribute. 2653e295b1b59e47916c8ae5d42eb27a23bd580cabeChris Lattner /// 26679fca6fea87be7221843031870bbf2c9ae1fc555Dan Gohman bool doesNotAccessMemory(ImmutableCallSite CS) { 267652f7ea955bb433d6b7a4d33685dca9485fd7b8bEvan Cheng return getModRefBehavior(CS) == DoesNotAccessMemory; 268dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands } 269dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands 270dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// doesNotAccessMemory - If the specified function is known to never read or 271dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// write memory, return true. For use when the call site is not known. 272dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// 27379fca6fea87be7221843031870bbf2c9ae1fc555Dan Gohman bool doesNotAccessMemory(const Function *F) { 274dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands return getModRefBehavior(F) == DoesNotAccessMemory; 275248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner } 2763e295b1b59e47916c8ae5d42eb27a23bd580cabeChris Lattner 277dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// onlyReadsMemory - If the specified call is known to only read from 278dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// non-volatile memory (or not access memory at all), return true. Calls 279dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// that unwind the stack are legal for this predicate. 2803e295b1b59e47916c8ae5d42eb27a23bd580cabeChris Lattner /// 2813e295b1b59e47916c8ae5d42eb27a23bd580cabeChris Lattner /// This property allows many common optimizations to be performed in the 2823e295b1b59e47916c8ae5d42eb27a23bd580cabeChris Lattner /// absence of interfering store instructions, such as CSE of strlen calls. 2833e295b1b59e47916c8ae5d42eb27a23bd580cabeChris Lattner /// 2843e295b1b59e47916c8ae5d42eb27a23bd580cabeChris Lattner /// This property corresponds to the GCC 'pure' attribute. 2853e295b1b59e47916c8ae5d42eb27a23bd580cabeChris Lattner /// 28679fca6fea87be7221843031870bbf2c9ae1fc555Dan Gohman bool onlyReadsMemory(ImmutableCallSite CS) { 287467a0adfc8b6bd4b114e024c200c159497a4cd86Dan Gohman return onlyReadsMemory(getModRefBehavior(CS)); 288dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands } 289dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands 290dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// onlyReadsMemory - If the specified function is known to only read from 291dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// non-volatile memory (or not access memory at all), return true. For use 292dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// when the call site is not known. 293dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// 29479fca6fea87be7221843031870bbf2c9ae1fc555Dan Gohman bool onlyReadsMemory(const Function *F) { 295467a0adfc8b6bd4b114e024c200c159497a4cd86Dan Gohman return onlyReadsMemory(getModRefBehavior(F)); 296467a0adfc8b6bd4b114e024c200c159497a4cd86Dan Gohman } 297467a0adfc8b6bd4b114e024c200c159497a4cd86Dan Gohman 298432d08cbdb9ceaa333f1d6eab4f8b542fdddf9dbDan Gohman /// onlyReadsMemory - Return true if functions with the specified behavior are 299432d08cbdb9ceaa333f1d6eab4f8b542fdddf9dbDan Gohman /// known to only read from non-volatile memory (or not access memory at all). 300467a0adfc8b6bd4b114e024c200c159497a4cd86Dan Gohman /// 301467a0adfc8b6bd4b114e024c200c159497a4cd86Dan Gohman static bool onlyReadsMemory(ModRefBehavior MRB) { 30242c31a70735e55bf82e66a9315c97d1821c9a798Dan Gohman return !(MRB & Mod); 303248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner } 3044df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner 305432d08cbdb9ceaa333f1d6eab4f8b542fdddf9dbDan Gohman /// onlyAccessesArgPointees - Return true if functions with the specified 306b395e4a0262c36b17b18aa33514b2daf2a85e9a3Dan Gohman /// behavior are known to read and write at most from objects pointed to by 307b395e4a0262c36b17b18aa33514b2daf2a85e9a3Dan Gohman /// their pointer-typed arguments (with arbitrary offsets). 308432d08cbdb9ceaa333f1d6eab4f8b542fdddf9dbDan Gohman /// 309432d08cbdb9ceaa333f1d6eab4f8b542fdddf9dbDan Gohman static bool onlyAccessesArgPointees(ModRefBehavior MRB) { 310432d08cbdb9ceaa333f1d6eab4f8b542fdddf9dbDan Gohman return !(MRB & Anywhere & ~ArgumentPointees); 311432d08cbdb9ceaa333f1d6eab4f8b542fdddf9dbDan Gohman } 312432d08cbdb9ceaa333f1d6eab4f8b542fdddf9dbDan Gohman 31368a6056dafd4913ce42606353ab1ff7208215ff2Dan Gohman /// doesAccessArgPointees - Return true if functions with the specified 31468a6056dafd4913ce42606353ab1ff7208215ff2Dan Gohman /// behavior are known to potentially read or write from objects pointed 31568a6056dafd4913ce42606353ab1ff7208215ff2Dan Gohman /// to be their pointer-typed arguments (with arbitrary offsets). 31668a6056dafd4913ce42606353ab1ff7208215ff2Dan Gohman /// 31768a6056dafd4913ce42606353ab1ff7208215ff2Dan Gohman static bool doesAccessArgPointees(ModRefBehavior MRB) { 31868a6056dafd4913ce42606353ab1ff7208215ff2Dan Gohman return (MRB & ModRef) && (MRB & ArgumentPointees); 31968a6056dafd4913ce42606353ab1ff7208215ff2Dan Gohman } 32068a6056dafd4913ce42606353ab1ff7208215ff2Dan Gohman 3211c56b730a6313886076d7b293a126ae5576f5288Chris Lattner /// getModRefInfo - Return information about whether or not an instruction may 322b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// read or write the specified memory location. An instruction 3231c56b730a6313886076d7b293a126ae5576f5288Chris Lattner /// that doesn't read or write memory may be trivially LICM'd for example. 324fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman ModRefResult getModRefInfo(const Instruction *I, 325b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman const Location &Loc) { 326fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman switch (I->getOpcode()) { 327b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman case Instruction::VAArg: return getModRefInfo((const VAArgInst*)I, Loc); 328b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman case Instruction::Load: return getModRefInfo((const LoadInst*)I, Loc); 329b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman case Instruction::Store: return getModRefInfo((const StoreInst*)I, Loc); 330b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman case Instruction::Call: return getModRefInfo((const CallInst*)I, Loc); 331b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman case Instruction::Invoke: return getModRefInfo((const InvokeInst*)I,Loc); 332fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman default: return NoModRef; 333fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman } 334fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman } 3351c56b730a6313886076d7b293a126ae5576f5288Chris Lattner 336b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// getModRefInfo - A convenience wrapper. 337b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman ModRefResult getModRefInfo(const Instruction *I, 3383da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman const Value *P, uint64_t Size) { 339b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman return getModRefInfo(I, Location(P, Size)); 340b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman } 341b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman 3421c56b730a6313886076d7b293a126ae5576f5288Chris Lattner /// getModRefInfo (for call sites) - Return whether information about whether 343b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// a particular call site modifies or reads the specified memory location. 34479fca6fea87be7221843031870bbf2c9ae1fc555Dan Gohman virtual ModRefResult getModRefInfo(ImmutableCallSite CS, 345b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman const Location &Loc); 346b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman 347b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// getModRefInfo (for call sites) - A convenience wrapper. 348b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman ModRefResult getModRefInfo(ImmutableCallSite CS, 3493da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman const Value *P, uint64_t Size) { 350b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman return getModRefInfo(CS, Location(P, Size)); 351b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman } 3521c56b730a6313886076d7b293a126ae5576f5288Chris Lattner 353fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman /// getModRefInfo (for calls) - Return whether information about whether 354b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// a particular call modifies or reads the specified memory location. 355b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman ModRefResult getModRefInfo(const CallInst *C, const Location &Loc) { 356b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman return getModRefInfo(ImmutableCallSite(C), Loc); 357b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman } 358b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman 359b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// getModRefInfo (for calls) - A convenience wrapper. 3603da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman ModRefResult getModRefInfo(const CallInst *C, const Value *P, uint64_t Size) { 361b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman return getModRefInfo(C, Location(P, Size)); 3621c56b730a6313886076d7b293a126ae5576f5288Chris Lattner } 363fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman 364fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman /// getModRefInfo (for invokes) - Return whether information about whether 365b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// a particular invoke modifies or reads the specified memory location. 366b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman ModRefResult getModRefInfo(const InvokeInst *I, 367b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman const Location &Loc) { 368b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman return getModRefInfo(ImmutableCallSite(I), Loc); 369b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman } 370b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman 371b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// getModRefInfo (for invokes) - A convenience wrapper. 37279fca6fea87be7221843031870bbf2c9ae1fc555Dan Gohman ModRefResult getModRefInfo(const InvokeInst *I, 3733da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman const Value *P, uint64_t Size) { 374b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman return getModRefInfo(I, Location(P, Size)); 3751c56b730a6313886076d7b293a126ae5576f5288Chris Lattner } 376fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman 377fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman /// getModRefInfo (for loads) - Return whether information about whether 378b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// a particular load modifies or reads the specified memory location. 379b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman ModRefResult getModRefInfo(const LoadInst *L, const Location &Loc); 380b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman 381b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// getModRefInfo (for loads) - A convenience wrapper. 3823da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman ModRefResult getModRefInfo(const LoadInst *L, const Value *P, uint64_t Size) { 383b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman return getModRefInfo(L, Location(P, Size)); 384b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman } 385fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman 386fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman /// getModRefInfo (for stores) - Return whether information about whether 387b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// a particular store modifies or reads the specified memory location. 388b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman ModRefResult getModRefInfo(const StoreInst *S, const Location &Loc); 389b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman 390b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// getModRefInfo (for stores) - A convenience wrapper. 3913da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman ModRefResult getModRefInfo(const StoreInst *S, const Value *P, uint64_t Size) { 392b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman return getModRefInfo(S, Location(P, Size)); 393b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman } 394fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman 395fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman /// getModRefInfo (for va_args) - Return whether information about whether 396b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// a particular va_arg modifies or reads the specified memory location. 397b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman ModRefResult getModRefInfo(const VAArgInst* I, const Location &Loc); 398b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman 399b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// getModRefInfo (for va_args) - A convenience wrapper. 4003da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman ModRefResult getModRefInfo(const VAArgInst* I, const Value* P, uint64_t Size) { 401b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman return getModRefInfo(I, Location(P, Size)); 402b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman } 403fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman 404fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman /// getModRefInfo - Return information about whether two call sites may refer 405fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman /// to the same set of memory locations. See 406fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman /// http://llvm.org/docs/AliasAnalysis.html#ModRefInfo 407fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman /// for details. 408fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman virtual ModRefResult getModRefInfo(ImmutableCallSite CS1, 409fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman ImmutableCallSite CS2); 4104df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner 411ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner //===--------------------------------------------------------------------===// 412ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// Higher level methods for querying mod/ref information. 413ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// 414ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner 415f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner /// canBasicBlockModify - Return true if it is possible for execution of the 416f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner /// specified basic block to modify the value pointed to by Ptr. 417b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman bool canBasicBlockModify(const BasicBlock &BB, const Location &Loc); 418b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman 419b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// canBasicBlockModify - A convenience wrapper. 4203da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman bool canBasicBlockModify(const BasicBlock &BB, const Value *P, uint64_t Size){ 421b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman return canBasicBlockModify(BB, Location(P, Size)); 422b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman } 4234df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner 424f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner /// canInstructionRangeModify - Return true if it is possible for the 425f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner /// execution of the specified instructions to modify the value pointed to by 426f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner /// Ptr. The instructions to consider are all of the instructions in the 427f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner /// range of [I1,I2] INCLUSIVE. I1 and I2 must be in the same basic block. 4284df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner bool canInstructionRangeModify(const Instruction &I1, const Instruction &I2, 429b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman const Location &Loc); 430b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman 431b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// canInstructionRangeModify - A convenience wrapper. 432b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman bool canInstructionRangeModify(const Instruction &I1, const Instruction &I2, 4333da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman const Value *Ptr, uint64_t Size) { 434b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman return canInstructionRangeModify(I1, I2, Location(Ptr, Size)); 435b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman } 436ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner 437ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner //===--------------------------------------------------------------------===// 438ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// Methods that clients should call when they transform the program to allow 439ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// alias analyses to update their internal data structures. Note that these 440ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// methods may be called on any instruction, regardless of whether or not 441ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// they have pointer-analysis implications. 442ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// 443ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner 444ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// deleteValue - This method should be called whenever an LLVM Value is 445ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// deleted from the program, for example when an instruction is found to be 446ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// redundant and is eliminated. 447ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// 448ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner virtual void deleteValue(Value *V); 449ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner 450ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// copyValue - This method should be used whenever a preexisting value in the 451ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// program is copied or cloned, introducing a new value. Note that analysis 452ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// implementations should tolerate clients that use this method to introduce 453ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// the same value multiple times: if the analysis already knows about a 454ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// value, it should ignore the request. 455ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// 456ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner virtual void copyValue(Value *From, Value *To); 457ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner 458ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// replaceWithNewValue - This method is the obvious combination of the two 459ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// above, and it provided as a helper to simplify client code. 460ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// 461ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner void replaceWithNewValue(Value *Old, Value *New) { 462ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner copyValue(Old, New); 463ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner deleteValue(Old); 464ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner } 4654df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner}; 4664df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner 467a5f81bba4ab18d6129774d4d67495f14b6f64375Dan Gohman/// isNoAliasCall - Return true if this pointer is returned by a noalias 468a5f81bba4ab18d6129774d4d67495f14b6f64375Dan Gohman/// function. 469a5f81bba4ab18d6129774d4d67495f14b6f64375Dan Gohmanbool isNoAliasCall(const Value *V); 470a5f81bba4ab18d6129774d4d67495f14b6f64375Dan Gohman 4713311a1f8f0d8a2c6d940802bbb95eba0b801a615Dan Gohman/// isIdentifiedObject - Return true if this pointer refers to a distinct and 472a5f81bba4ab18d6129774d4d67495f14b6f64375Dan Gohman/// identifiable object. This returns true for: 4735753a4a0033da4add45f2e9930a4e1159d92a869Dan Gohman/// Global Variables and Functions (but not Global Aliases) 474a5f81bba4ab18d6129774d4d67495f14b6f64375Dan Gohman/// Allocas and Mallocs 4759e86f4364b912ae743490ba01d6989acfd12c046Dan Gohman/// ByVal and NoAlias Arguments 4769e86f4364b912ae743490ba01d6989acfd12c046Dan Gohman/// NoAlias returns 4773311a1f8f0d8a2c6d940802bbb95eba0b801a615Dan Gohman/// 4789e86f4364b912ae743490ba01d6989acfd12c046Dan Gohmanbool isIdentifiedObject(const Value *V); 4793311a1f8f0d8a2c6d940802bbb95eba0b801a615Dan Gohman 4804f1bd9e9963239c119db70070db1d68286b3de7eReid Spencer} // End llvm namespace 4814f1bd9e9963239c119db70070db1d68286b3de7eReid Spencer 4824df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner#endif 483