AliasAnalysis.h revision 17e8078ae14ed71f657d59c77efa3bedf171161a
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// 191c56b730a6313886076d7b293a126ae5576f5288Chris Lattner// This API represents memory as a (Pointer, Size) pair. The Pointer component 201c56b730a6313886076d7b293a126ae5576f5288Chris Lattner// specifies the base memory address of the region, the Size specifies how large 21e53e3772f3c8b4cba69b7d77c8b2148a080fe9aeDan Gohman// of an area is being queried, or UnknownSize if the size is not known. 22e53e3772f3c8b4cba69b7d77c8b2148a080fe9aeDan Gohman// Pointers that point to two completely different objects in memory never 23e53e3772f3c8b4cba69b7d77c8b2148a080fe9aeDan Gohman// alias, regardless of the value of the Size component. 241c56b730a6313886076d7b293a126ae5576f5288Chris Lattner// 254df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner//===----------------------------------------------------------------------===// 264df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner 274df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner#ifndef LLVM_ANALYSIS_ALIAS_ANALYSIS_H 284df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner#define LLVM_ANALYSIS_ALIAS_ANALYSIS_H 294df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner 301c56b730a6313886076d7b293a126ae5576f5288Chris Lattner#include "llvm/Support/CallSite.h" 3136f78c8935da34074ccd06d5674e45b9cd45da8bChris Lattner#include <vector> 32d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke 33d0fde30ce850b78371fd1386338350591f9ff494Brian Gaekenamespace llvm { 34d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke 351c56b730a6313886076d7b293a126ae5576f5288Chris Lattnerclass LoadInst; 361c56b730a6313886076d7b293a126ae5576f5288Chris Lattnerclass StoreInst; 3714f1703ae33e13dbcadd701603fd4d7a6f7010b9Andrew Lenharthclass VAArgInst; 381c56b730a6313886076d7b293a126ae5576f5288Chris Lattnerclass TargetData; 396df60a9effe4d20a48cfd9d105c0ab3c5dc3e690Reid Spencerclass Pass; 406df60a9effe4d20a48cfd9d105c0ab3c5dc3e690Reid Spencerclass AnalysisUsage; 411c56b730a6313886076d7b293a126ae5576f5288Chris Lattner 421c56b730a6313886076d7b293a126ae5576f5288Chris Lattnerclass AliasAnalysis { 431c56b730a6313886076d7b293a126ae5576f5288Chris Lattnerprotected: 44ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner const TargetData *TD; 45cb74993bdc37681ddbb80fa361575107afae1350Dan Gohman 46cb74993bdc37681ddbb80fa361575107afae1350Dan Gohmanprivate: 47ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner AliasAnalysis *AA; // Previous Alias Analysis to chain to. 48ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner 49cb74993bdc37681ddbb80fa361575107afae1350Dan Gohmanprotected: 501c56b730a6313886076d7b293a126ae5576f5288Chris Lattner /// InitializeAliasAnalysis - Subclasses must call this method to initialize 511c56b730a6313886076d7b293a126ae5576f5288Chris Lattner /// the AliasAnalysis interface before any other methods are called. This is 521c56b730a6313886076d7b293a126ae5576f5288Chris Lattner /// typically called by the run* methods of these subclasses. This may be 531c56b730a6313886076d7b293a126ae5576f5288Chris Lattner /// called multiple times. 541c56b730a6313886076d7b293a126ae5576f5288Chris Lattner /// 551c56b730a6313886076d7b293a126ae5576f5288Chris Lattner void InitializeAliasAnalysis(Pass *P); 569769ab22265b313171d201b5928688524a01bd87Misha Brukman 5764d237cfae6bcb11157d525c79b5a5335e30370bDan Gohman /// getAnalysisUsage - All alias analysis implementations should invoke this 58fc2a3ed0c9e32cf7edaf5030fa0972b916cc5f0bDan Gohman /// directly (using AliasAnalysis::getAnalysisUsage(AU)). 591c56b730a6313886076d7b293a126ae5576f5288Chris Lattner virtual void getAnalysisUsage(AnalysisUsage &AU) const; 601c56b730a6313886076d7b293a126ae5576f5288Chris Lattner 611c56b730a6313886076d7b293a126ae5576f5288Chris Lattnerpublic: 621997473cf72957d0e70322e2fe6fe2ab141c58a6Devang Patel static char ID; // Class identification, replacement for typeinfo 63ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner AliasAnalysis() : TD(0), AA(0) {} 641c56b730a6313886076d7b293a126ae5576f5288Chris Lattner virtual ~AliasAnalysis(); // We want to be subclassed 651c56b730a6313886076d7b293a126ae5576f5288Chris Lattner 66ef1cfac9e50def9097cd3e3ab3c5cad7f4c758ccDan Gohman /// UnknownSize - This is a special value which can be used with the 67ef1cfac9e50def9097cd3e3ab3c5cad7f4c758ccDan Gohman /// size arguments in alias queries to indicate that the caller does not 68ef1cfac9e50def9097cd3e3ab3c5cad7f4c758ccDan Gohman /// know the sizes of the potential memory references. 693da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman static uint64_t const UnknownSize = ~UINT64_C(0); 70ef1cfac9e50def9097cd3e3ab3c5cad7f4c758ccDan Gohman 71fc2a3ed0c9e32cf7edaf5030fa0972b916cc5f0bDan Gohman /// getTargetData - Return a pointer to the current TargetData object, or 72fc2a3ed0c9e32cf7edaf5030fa0972b916cc5f0bDan Gohman /// null if no TargetData object is available. 73dd298c8c6eb036baf35bf5a559c59d2afd2c7944Misha Brukman /// 74fc2a3ed0c9e32cf7edaf5030fa0972b916cc5f0bDan Gohman const TargetData *getTargetData() const { return TD; } 75fc2a3ed0c9e32cf7edaf5030fa0972b916cc5f0bDan Gohman 76fc2a3ed0c9e32cf7edaf5030fa0972b916cc5f0bDan Gohman /// getTypeStoreSize - Return the TargetData store size for the given type, 77fc2a3ed0c9e32cf7edaf5030fa0972b916cc5f0bDan Gohman /// if known, or a conservative value otherwise. 78fc2a3ed0c9e32cf7edaf5030fa0972b916cc5f0bDan Gohman /// 793da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman uint64_t getTypeStoreSize(const Type *Ty); 804df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner 811c56b730a6313886076d7b293a126ae5576f5288Chris Lattner //===--------------------------------------------------------------------===// 821c56b730a6313886076d7b293a126ae5576f5288Chris Lattner /// Alias Queries... 831c56b730a6313886076d7b293a126ae5576f5288Chris Lattner /// 844df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner 85b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// Location - A description of a memory location. 86b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman struct Location { 87b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// Ptr - The address of the start of the location. 88b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman const Value *Ptr; 896c25c920e66aa2d8f6b48454bc9770087ff7939aDan Gohman /// Size - The maximum size of the location, or UnknownSize if the size is 906c25c920e66aa2d8f6b48454bc9770087ff7939aDan Gohman /// not known. Note that an unknown size does not mean the pointer aliases 916c25c920e66aa2d8f6b48454bc9770087ff7939aDan Gohman /// the entire virtual address space, because there are restrictions on 926c25c920e66aa2d8f6b48454bc9770087ff7939aDan Gohman /// stepping out of one object and into another. 936c25c920e66aa2d8f6b48454bc9770087ff7939aDan Gohman /// See http://llvm.org/docs/LangRef.html#pointeraliasing 943da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman uint64_t Size; 95b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// TBAATag - The metadata node which describes the TBAA type of 966c25c920e66aa2d8f6b48454bc9770087ff7939aDan Gohman /// the location, or null if there is no known unique tag. 97b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman const MDNode *TBAATag; 98b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman 99b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman explicit Location(const Value *P = 0, 1003da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman uint64_t S = UnknownSize, 101b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman const MDNode *N = 0) 102b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman : Ptr(P), Size(S), TBAATag(N) {} 1039f27074f42f03af640977006dc7c05005fb77991Dan Gohman 1049f27074f42f03af640977006dc7c05005fb77991Dan Gohman Location getWithNewPtr(const Value *NewPtr) const { 1059f27074f42f03af640977006dc7c05005fb77991Dan Gohman Location Copy(*this); 1069f27074f42f03af640977006dc7c05005fb77991Dan Gohman Copy.Ptr = NewPtr; 1079f27074f42f03af640977006dc7c05005fb77991Dan Gohman return Copy; 1089f27074f42f03af640977006dc7c05005fb77991Dan Gohman } 1099f27074f42f03af640977006dc7c05005fb77991Dan Gohman 110075fb5d68fcb55d26e44c48f07dfdbbfa21ccb2aDan Gohman Location getWithNewSize(uint64_t NewSize) const { 111075fb5d68fcb55d26e44c48f07dfdbbfa21ccb2aDan Gohman Location Copy(*this); 112075fb5d68fcb55d26e44c48f07dfdbbfa21ccb2aDan Gohman Copy.Size = NewSize; 113075fb5d68fcb55d26e44c48f07dfdbbfa21ccb2aDan Gohman return Copy; 114075fb5d68fcb55d26e44c48f07dfdbbfa21ccb2aDan Gohman } 115075fb5d68fcb55d26e44c48f07dfdbbfa21ccb2aDan Gohman 1169f27074f42f03af640977006dc7c05005fb77991Dan Gohman Location getWithoutTBAATag() const { 1179f27074f42f03af640977006dc7c05005fb77991Dan Gohman Location Copy(*this); 1189f27074f42f03af640977006dc7c05005fb77991Dan Gohman Copy.TBAATag = 0; 1199f27074f42f03af640977006dc7c05005fb77991Dan Gohman return Copy; 1209f27074f42f03af640977006dc7c05005fb77991Dan Gohman } 121b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman }; 122b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman 123f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner /// Alias analysis result - Either we know for sure that it does not alias, we 124f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner /// know for sure it must alias, or we don't know anything: The two pointers 125f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner /// _might_ alias. This enum is designed so you can do things like: 126f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner /// if (AA.alias(P1, P2)) { ... } 127f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner /// to check to see if two pointers might alias. 128f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner /// 129e53e3772f3c8b4cba69b7d77c8b2148a080fe9aeDan Gohman /// See docs/AliasAnalysis.html for more information on the specific meanings 130e53e3772f3c8b4cba69b7d77c8b2148a080fe9aeDan Gohman /// of these values. 131e53e3772f3c8b4cba69b7d77c8b2148a080fe9aeDan Gohman /// 13217e8078ae14ed71f657d59c77efa3bedf171161aDan Gohman enum AliasResult { 13317e8078ae14ed71f657d59c77efa3bedf171161aDan Gohman NoAlias = 0, ///< No dependencies. 13417e8078ae14ed71f657d59c77efa3bedf171161aDan Gohman MayAlias = 1, ///< Anything goes. 13517e8078ae14ed71f657d59c77efa3bedf171161aDan Gohman MustAlias = 2 ///< Pointers are equal. 13617e8078ae14ed71f657d59c77efa3bedf171161aDan Gohman }; 1374df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner 138f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner /// alias - The main low level interface to the alias analysis implementation. 1396c25c920e66aa2d8f6b48454bc9770087ff7939aDan Gohman /// Returns an AliasResult indicating whether the two pointers are aliased to 1406c25c920e66aa2d8f6b48454bc9770087ff7939aDan Gohman /// each other. This is the interface that must be implemented by specific 1416c25c920e66aa2d8f6b48454bc9770087ff7939aDan Gohman /// alias analysis implementations. 142b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman virtual AliasResult alias(const Location &LocA, const Location &LocB); 1434df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner 144b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// alias - A convenience wrapper. 1453da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman AliasResult alias(const Value *V1, uint64_t V1Size, 1463da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman const Value *V2, uint64_t V2Size) { 147b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman return alias(Location(V1, V1Size), Location(V2, V2Size)); 148b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman } 149b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman 150b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// alias - A convenience wrapper. 151847a84efd23a2c7d90429b82f6e0f19d1f913d9aDan Gohman AliasResult alias(const Value *V1, const Value *V2) { 152ef1cfac9e50def9097cd3e3ab3c5cad7f4c758ccDan Gohman return alias(V1, UnknownSize, V2, UnknownSize); 153847a84efd23a2c7d90429b82f6e0f19d1f913d9aDan Gohman } 154847a84efd23a2c7d90429b82f6e0f19d1f913d9aDan Gohman 155c46530b6a32a53edf0d6d32bcd09ea5d76940472Chris Lattner /// isNoAlias - A trivial helper function to check to see if the specified 156c46530b6a32a53edf0d6d32bcd09ea5d76940472Chris Lattner /// pointers are no-alias. 157b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman bool isNoAlias(const Location &LocA, const Location &LocB) { 158b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman return alias(LocA, LocB) == NoAlias; 159b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman } 160b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman 161b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// isNoAlias - A convenience wrapper. 1623da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman bool isNoAlias(const Value *V1, uint64_t V1Size, 1633da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman const Value *V2, uint64_t V2Size) { 164b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman return isNoAlias(Location(V1, V1Size), Location(V2, V2Size)); 165c46530b6a32a53edf0d6d32bcd09ea5d76940472Chris Lattner } 166c46530b6a32a53edf0d6d32bcd09ea5d76940472Chris Lattner 167a25e5dbcc2371352386a01e3c1b8e76dd890272bDan Gohman /// pointsToConstantMemory - If the specified memory location is 168a25e5dbcc2371352386a01e3c1b8e76dd890272bDan Gohman /// known to be constant, return true. If OrLocal is true and the 169a25e5dbcc2371352386a01e3c1b8e76dd890272bDan Gohman /// specified memory location is known to be "local" (derived from 170a25e5dbcc2371352386a01e3c1b8e76dd890272bDan Gohman /// an alloca), return true. Otherwise return false. 171a25e5dbcc2371352386a01e3c1b8e76dd890272bDan Gohman virtual bool pointsToConstantMemory(const Location &Loc, 172a25e5dbcc2371352386a01e3c1b8e76dd890272bDan Gohman bool OrLocal = false); 173b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman 174b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// pointsToConstantMemory - A convenient wrapper. 175a25e5dbcc2371352386a01e3c1b8e76dd890272bDan Gohman bool pointsToConstantMemory(const Value *P, bool OrLocal = false) { 176a25e5dbcc2371352386a01e3c1b8e76dd890272bDan Gohman return pointsToConstantMemory(Location(P), OrLocal); 177b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman } 17862b5c167de0ca5883a7ad5eb0900eb0c15ad3707Chris Lattner 179248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner //===--------------------------------------------------------------------===// 180248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner /// Simple mod/ref information... 181248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner /// 182248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner 183248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner /// ModRefResult - Represent the result of a mod/ref query. Mod and Ref are 184248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner /// bits which may be or'd together. 185248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner /// 186248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner enum ModRefResult { NoModRef = 0, Ref = 1, Mod = 2, ModRef = 3 }; 1879769ab22265b313171d201b5928688524a01bd87Misha Brukman 18842c31a70735e55bf82e66a9315c97d1821c9a798Dan Gohman /// These values define additional bits used to define the 18942c31a70735e55bf82e66a9315c97d1821c9a798Dan Gohman /// ModRefBehavior values. 19042c31a70735e55bf82e66a9315c97d1821c9a798Dan Gohman enum { Nowhere = 0, ArgumentPointees = 4, Anywhere = 8 | ArgumentPointees }; 1919769ab22265b313171d201b5928688524a01bd87Misha Brukman 192248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner /// ModRefBehavior - Summary of how a function affects memory in the program. 193248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner /// Loads from constant globals are not considered memory accesses for this 194248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner /// interface. Also, functions may freely modify stack space local to their 195248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner /// invocation without having to report it through these interfaces. 196248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner enum ModRefBehavior { 19750a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// DoesNotAccessMemory - This function does not perform any non-local loads 19850a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// or stores to memory. 19950a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// 20050a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// This property corresponds to the GCC 'const' attribute. 20150a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// This property corresponds to the LLVM IR 'readnone' attribute. 20250a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// This property corresponds to the IntrNoMem LLVM intrinsic flag. 20342c31a70735e55bf82e66a9315c97d1821c9a798Dan Gohman DoesNotAccessMemory = Nowhere | NoModRef, 2049769ab22265b313171d201b5928688524a01bd87Misha Brukman 205e88ccb545d0e03fd4445d361100fc95f350c6663Dan Gohman /// OnlyReadsArgumentPointees - The only memory references in this function 206e88ccb545d0e03fd4445d361100fc95f350c6663Dan Gohman /// (if it has any) are non-volatile loads from objects pointed to by its 207e88ccb545d0e03fd4445d361100fc95f350c6663Dan Gohman /// pointer-typed arguments, with arbitrary offsets. 20850a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// 20950a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// This property corresponds to the IntrReadArgMem LLVM intrinsic flag. 210e88ccb545d0e03fd4445d361100fc95f350c6663Dan Gohman OnlyReadsArgumentPointees = ArgumentPointees | Ref, 211db78c4873ea8c4b3dce90d761a1ad59d5bcdd6e7Dan Gohman 212e88ccb545d0e03fd4445d361100fc95f350c6663Dan Gohman /// OnlyAccessesArgumentPointees - The only memory references in this 213e88ccb545d0e03fd4445d361100fc95f350c6663Dan Gohman /// function (if it has any) are non-volatile loads and stores from objects 214e88ccb545d0e03fd4445d361100fc95f350c6663Dan Gohman /// pointed to by its pointer-typed arguments, with arbitrary offsets. 21550a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// 21650a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// This property corresponds to the IntrReadWriteArgMem LLVM intrinsic flag. 217e88ccb545d0e03fd4445d361100fc95f350c6663Dan Gohman OnlyAccessesArgumentPointees = ArgumentPointees | ModRef, 2189769ab22265b313171d201b5928688524a01bd87Misha Brukman 21950a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// OnlyReadsMemory - This function does not perform any non-local stores or 22050a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// volatile loads, but may read from any memory location. 22150a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// 22250a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// This property corresponds to the GCC 'pure' attribute. 22350a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// This property corresponds to the LLVM IR 'readonly' attribute. 22450a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// This property corresponds to the IntrReadMem LLVM intrinsic flag. 22542c31a70735e55bf82e66a9315c97d1821c9a798Dan Gohman OnlyReadsMemory = Anywhere | Ref, 2269769ab22265b313171d201b5928688524a01bd87Misha Brukman 22750a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// UnknownModRefBehavior - This indicates that the function could not be 22850a04d067f8803d52cababdabe5c188844c5c210Dan Gohman /// classified into one of the behaviors above. 22942c31a70735e55bf82e66a9315c97d1821c9a798Dan Gohman UnknownModRefBehavior = Anywhere | ModRef 230248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner }; 2319769ab22265b313171d201b5928688524a01bd87Misha Brukman 232dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// getModRefBehavior - Return the behavior when calling the given call site. 233a41af344c2964573318a77e2b43eafd4d3804003Dan Gohman virtual ModRefBehavior getModRefBehavior(ImmutableCallSite CS); 234dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands 235dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// getModRefBehavior - Return the behavior when calling the given function. 236dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// For use when the call site is not known. 237a41af344c2964573318a77e2b43eafd4d3804003Dan Gohman virtual ModRefBehavior getModRefBehavior(const Function *F); 238dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands 239dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// doesNotAccessMemory - If the specified call is known to never read or 240dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// write memory, return true. If the call only reads from known-constant 241dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// memory, it is also legal to return true. Calls that unwind the stack 242dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// are legal for this predicate. 2433e295b1b59e47916c8ae5d42eb27a23bd580cabeChris Lattner /// 244dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// Many optimizations (such as CSE and LICM) can be performed on such calls 245dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// without worrying about aliasing properties, and many calls have this 246dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// property (e.g. calls to 'sin' and 'cos'). 2473e295b1b59e47916c8ae5d42eb27a23bd580cabeChris Lattner /// 2483e295b1b59e47916c8ae5d42eb27a23bd580cabeChris Lattner /// This property corresponds to the GCC 'const' attribute. 2493e295b1b59e47916c8ae5d42eb27a23bd580cabeChris Lattner /// 25079fca6fea87be7221843031870bbf2c9ae1fc555Dan Gohman bool doesNotAccessMemory(ImmutableCallSite CS) { 251652f7ea955bb433d6b7a4d33685dca9485fd7b8bEvan Cheng return getModRefBehavior(CS) == DoesNotAccessMemory; 252dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands } 253dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands 254dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// doesNotAccessMemory - If the specified function is known to never read or 255dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// write memory, return true. For use when the call site is not known. 256dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// 25779fca6fea87be7221843031870bbf2c9ae1fc555Dan Gohman bool doesNotAccessMemory(const Function *F) { 258dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands return getModRefBehavior(F) == DoesNotAccessMemory; 259248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner } 2603e295b1b59e47916c8ae5d42eb27a23bd580cabeChris Lattner 261dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// onlyReadsMemory - If the specified call is known to only read from 262dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// non-volatile memory (or not access memory at all), return true. Calls 263dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// that unwind the stack are legal for this predicate. 2643e295b1b59e47916c8ae5d42eb27a23bd580cabeChris Lattner /// 2653e295b1b59e47916c8ae5d42eb27a23bd580cabeChris Lattner /// This property allows many common optimizations to be performed in the 2663e295b1b59e47916c8ae5d42eb27a23bd580cabeChris Lattner /// absence of interfering store instructions, such as CSE of strlen calls. 2673e295b1b59e47916c8ae5d42eb27a23bd580cabeChris Lattner /// 2683e295b1b59e47916c8ae5d42eb27a23bd580cabeChris Lattner /// This property corresponds to the GCC 'pure' attribute. 2693e295b1b59e47916c8ae5d42eb27a23bd580cabeChris Lattner /// 27079fca6fea87be7221843031870bbf2c9ae1fc555Dan Gohman bool onlyReadsMemory(ImmutableCallSite CS) { 271467a0adfc8b6bd4b114e024c200c159497a4cd86Dan Gohman return onlyReadsMemory(getModRefBehavior(CS)); 272dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands } 273dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands 274dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// onlyReadsMemory - If the specified function is known to only read from 275dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// non-volatile memory (or not access memory at all), return true. For use 276dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// when the call site is not known. 277dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands /// 27879fca6fea87be7221843031870bbf2c9ae1fc555Dan Gohman bool onlyReadsMemory(const Function *F) { 279467a0adfc8b6bd4b114e024c200c159497a4cd86Dan Gohman return onlyReadsMemory(getModRefBehavior(F)); 280467a0adfc8b6bd4b114e024c200c159497a4cd86Dan Gohman } 281467a0adfc8b6bd4b114e024c200c159497a4cd86Dan Gohman 282432d08cbdb9ceaa333f1d6eab4f8b542fdddf9dbDan Gohman /// onlyReadsMemory - Return true if functions with the specified behavior are 283432d08cbdb9ceaa333f1d6eab4f8b542fdddf9dbDan Gohman /// known to only read from non-volatile memory (or not access memory at all). 284467a0adfc8b6bd4b114e024c200c159497a4cd86Dan Gohman /// 285467a0adfc8b6bd4b114e024c200c159497a4cd86Dan Gohman static bool onlyReadsMemory(ModRefBehavior MRB) { 28642c31a70735e55bf82e66a9315c97d1821c9a798Dan Gohman return !(MRB & Mod); 287248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner } 2884df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner 289432d08cbdb9ceaa333f1d6eab4f8b542fdddf9dbDan Gohman /// onlyAccessesArgPointees - Return true if functions with the specified 290b395e4a0262c36b17b18aa33514b2daf2a85e9a3Dan Gohman /// behavior are known to read and write at most from objects pointed to by 291b395e4a0262c36b17b18aa33514b2daf2a85e9a3Dan Gohman /// their pointer-typed arguments (with arbitrary offsets). 292432d08cbdb9ceaa333f1d6eab4f8b542fdddf9dbDan Gohman /// 293432d08cbdb9ceaa333f1d6eab4f8b542fdddf9dbDan Gohman static bool onlyAccessesArgPointees(ModRefBehavior MRB) { 294432d08cbdb9ceaa333f1d6eab4f8b542fdddf9dbDan Gohman return !(MRB & Anywhere & ~ArgumentPointees); 295432d08cbdb9ceaa333f1d6eab4f8b542fdddf9dbDan Gohman } 296432d08cbdb9ceaa333f1d6eab4f8b542fdddf9dbDan Gohman 29768a6056dafd4913ce42606353ab1ff7208215ff2Dan Gohman /// doesAccessArgPointees - Return true if functions with the specified 29868a6056dafd4913ce42606353ab1ff7208215ff2Dan Gohman /// behavior are known to potentially read or write from objects pointed 29968a6056dafd4913ce42606353ab1ff7208215ff2Dan Gohman /// to be their pointer-typed arguments (with arbitrary offsets). 30068a6056dafd4913ce42606353ab1ff7208215ff2Dan Gohman /// 30168a6056dafd4913ce42606353ab1ff7208215ff2Dan Gohman static bool doesAccessArgPointees(ModRefBehavior MRB) { 30268a6056dafd4913ce42606353ab1ff7208215ff2Dan Gohman return (MRB & ModRef) && (MRB & ArgumentPointees); 30368a6056dafd4913ce42606353ab1ff7208215ff2Dan Gohman } 30468a6056dafd4913ce42606353ab1ff7208215ff2Dan Gohman 3051c56b730a6313886076d7b293a126ae5576f5288Chris Lattner /// getModRefInfo - Return information about whether or not an instruction may 306b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// read or write the specified memory location. An instruction 3071c56b730a6313886076d7b293a126ae5576f5288Chris Lattner /// that doesn't read or write memory may be trivially LICM'd for example. 308fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman ModRefResult getModRefInfo(const Instruction *I, 309b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman const Location &Loc) { 310fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman switch (I->getOpcode()) { 311b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman case Instruction::VAArg: return getModRefInfo((const VAArgInst*)I, Loc); 312b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman case Instruction::Load: return getModRefInfo((const LoadInst*)I, Loc); 313b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman case Instruction::Store: return getModRefInfo((const StoreInst*)I, Loc); 314b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman case Instruction::Call: return getModRefInfo((const CallInst*)I, Loc); 315b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman case Instruction::Invoke: return getModRefInfo((const InvokeInst*)I,Loc); 316fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman default: return NoModRef; 317fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman } 318fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman } 3191c56b730a6313886076d7b293a126ae5576f5288Chris Lattner 320b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// getModRefInfo - A convenience wrapper. 321b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman ModRefResult getModRefInfo(const Instruction *I, 3223da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman const Value *P, uint64_t Size) { 323b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman return getModRefInfo(I, Location(P, Size)); 324b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman } 325b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman 3261c56b730a6313886076d7b293a126ae5576f5288Chris Lattner /// getModRefInfo (for call sites) - Return whether information about whether 327b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// a particular call site modifies or reads the specified memory location. 32879fca6fea87be7221843031870bbf2c9ae1fc555Dan Gohman virtual ModRefResult getModRefInfo(ImmutableCallSite CS, 329b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman const Location &Loc); 330b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman 331b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// getModRefInfo (for call sites) - A convenience wrapper. 332b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman ModRefResult getModRefInfo(ImmutableCallSite CS, 3333da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman const Value *P, uint64_t Size) { 334b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman return getModRefInfo(CS, Location(P, Size)); 335b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman } 3361c56b730a6313886076d7b293a126ae5576f5288Chris Lattner 337fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman /// getModRefInfo (for calls) - Return whether information about whether 338b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// a particular call modifies or reads the specified memory location. 339b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman ModRefResult getModRefInfo(const CallInst *C, const Location &Loc) { 340b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman return getModRefInfo(ImmutableCallSite(C), Loc); 341b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman } 342b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman 343b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// getModRefInfo (for calls) - A convenience wrapper. 3443da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman ModRefResult getModRefInfo(const CallInst *C, const Value *P, uint64_t Size) { 345b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman return getModRefInfo(C, Location(P, Size)); 3461c56b730a6313886076d7b293a126ae5576f5288Chris Lattner } 347fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman 348fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman /// getModRefInfo (for invokes) - Return whether information about whether 349b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// a particular invoke modifies or reads the specified memory location. 350b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman ModRefResult getModRefInfo(const InvokeInst *I, 351b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman const Location &Loc) { 352b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman return getModRefInfo(ImmutableCallSite(I), Loc); 353b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman } 354b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman 355b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// getModRefInfo (for invokes) - A convenience wrapper. 35679fca6fea87be7221843031870bbf2c9ae1fc555Dan Gohman ModRefResult getModRefInfo(const InvokeInst *I, 3573da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman const Value *P, uint64_t Size) { 358b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman return getModRefInfo(I, Location(P, Size)); 3591c56b730a6313886076d7b293a126ae5576f5288Chris Lattner } 360fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman 361fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman /// getModRefInfo (for loads) - Return whether information about whether 362b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// a particular load modifies or reads the specified memory location. 363b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman ModRefResult getModRefInfo(const LoadInst *L, const Location &Loc); 364b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman 365b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// getModRefInfo (for loads) - A convenience wrapper. 3663da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman ModRefResult getModRefInfo(const LoadInst *L, const Value *P, uint64_t Size) { 367b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman return getModRefInfo(L, Location(P, Size)); 368b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman } 369fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman 370fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman /// getModRefInfo (for stores) - Return whether information about whether 371b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// a particular store modifies or reads the specified memory location. 372b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman ModRefResult getModRefInfo(const StoreInst *S, const Location &Loc); 373b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman 374b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// getModRefInfo (for stores) - A convenience wrapper. 3753da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman ModRefResult getModRefInfo(const StoreInst *S, const Value *P, uint64_t Size) { 376b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman return getModRefInfo(S, Location(P, Size)); 377b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman } 378fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman 379fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman /// getModRefInfo (for va_args) - Return whether information about whether 380b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// a particular va_arg modifies or reads the specified memory location. 381b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman ModRefResult getModRefInfo(const VAArgInst* I, const Location &Loc); 382b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman 383b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// getModRefInfo (for va_args) - A convenience wrapper. 3843da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman ModRefResult getModRefInfo(const VAArgInst* I, const Value* P, uint64_t Size) { 385b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman return getModRefInfo(I, Location(P, Size)); 386b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman } 387fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman 388fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman /// getModRefInfo - Return information about whether two call sites may refer 389fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman /// to the same set of memory locations. See 390fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman /// http://llvm.org/docs/AliasAnalysis.html#ModRefInfo 391fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman /// for details. 392fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman virtual ModRefResult getModRefInfo(ImmutableCallSite CS1, 393fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman ImmutableCallSite CS2); 3944df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner 395ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner //===--------------------------------------------------------------------===// 396ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// Higher level methods for querying mod/ref information. 397ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// 398ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner 399f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner /// canBasicBlockModify - Return true if it is possible for execution of the 400f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner /// specified basic block to modify the value pointed to by Ptr. 401b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman bool canBasicBlockModify(const BasicBlock &BB, const Location &Loc); 402b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman 403b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// canBasicBlockModify - A convenience wrapper. 4043da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman bool canBasicBlockModify(const BasicBlock &BB, const Value *P, uint64_t Size){ 405b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman return canBasicBlockModify(BB, Location(P, Size)); 406b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman } 4074df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner 408f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner /// canInstructionRangeModify - Return true if it is possible for the 409f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner /// execution of the specified instructions to modify the value pointed to by 410f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner /// Ptr. The instructions to consider are all of the instructions in the 411f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner /// range of [I1,I2] INCLUSIVE. I1 and I2 must be in the same basic block. 4124df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner bool canInstructionRangeModify(const Instruction &I1, const Instruction &I2, 413b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman const Location &Loc); 414b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman 415b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman /// canInstructionRangeModify - A convenience wrapper. 416b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman bool canInstructionRangeModify(const Instruction &I1, const Instruction &I2, 4173da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman const Value *Ptr, uint64_t Size) { 418b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman return canInstructionRangeModify(I1, I2, Location(Ptr, Size)); 419b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman } 420ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner 421ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner //===--------------------------------------------------------------------===// 422ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// Methods that clients should call when they transform the program to allow 423ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// alias analyses to update their internal data structures. Note that these 424ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// methods may be called on any instruction, regardless of whether or not 425ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// they have pointer-analysis implications. 426ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// 427ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner 428ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// deleteValue - This method should be called whenever an LLVM Value is 429ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// deleted from the program, for example when an instruction is found to be 430ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// redundant and is eliminated. 431ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// 432ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner virtual void deleteValue(Value *V); 433ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner 434ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// copyValue - This method should be used whenever a preexisting value in the 435ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// program is copied or cloned, introducing a new value. Note that analysis 436ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// implementations should tolerate clients that use this method to introduce 437ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// the same value multiple times: if the analysis already knows about a 438ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// value, it should ignore the request. 439ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// 440ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner virtual void copyValue(Value *From, Value *To); 441ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner 442ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// replaceWithNewValue - This method is the obvious combination of the two 443ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// above, and it provided as a helper to simplify client code. 444ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner /// 445ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner void replaceWithNewValue(Value *Old, Value *New) { 446ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner copyValue(Old, New); 447ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner deleteValue(Old); 448ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner } 4494df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner}; 4504df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner 451a5f81bba4ab18d6129774d4d67495f14b6f64375Dan Gohman/// isNoAliasCall - Return true if this pointer is returned by a noalias 452a5f81bba4ab18d6129774d4d67495f14b6f64375Dan Gohman/// function. 453a5f81bba4ab18d6129774d4d67495f14b6f64375Dan Gohmanbool isNoAliasCall(const Value *V); 454a5f81bba4ab18d6129774d4d67495f14b6f64375Dan Gohman 4553311a1f8f0d8a2c6d940802bbb95eba0b801a615Dan Gohman/// isIdentifiedObject - Return true if this pointer refers to a distinct and 456a5f81bba4ab18d6129774d4d67495f14b6f64375Dan Gohman/// identifiable object. This returns true for: 4575753a4a0033da4add45f2e9930a4e1159d92a869Dan Gohman/// Global Variables and Functions (but not Global Aliases) 458a5f81bba4ab18d6129774d4d67495f14b6f64375Dan Gohman/// Allocas and Mallocs 4599e86f4364b912ae743490ba01d6989acfd12c046Dan Gohman/// ByVal and NoAlias Arguments 4609e86f4364b912ae743490ba01d6989acfd12c046Dan Gohman/// NoAlias returns 4613311a1f8f0d8a2c6d940802bbb95eba0b801a615Dan Gohman/// 4629e86f4364b912ae743490ba01d6989acfd12c046Dan Gohmanbool isIdentifiedObject(const Value *V); 4633311a1f8f0d8a2c6d940802bbb95eba0b801a615Dan Gohman 4644f1bd9e9963239c119db70070db1d68286b3de7eReid Spencer} // End llvm namespace 4654f1bd9e9963239c119db70070db1d68286b3de7eReid Spencer 4664df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner#endif 467