AliasAnalysis.h revision 42c31a70735e55bf82e66a9315c97d1821c9a798
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
1109f27074f42f03af640977006dc7c05005fb77991Dan Gohman    Location getWithoutTBAATag() const {
1119f27074f42f03af640977006dc7c05005fb77991Dan Gohman      Location Copy(*this);
1129f27074f42f03af640977006dc7c05005fb77991Dan Gohman      Copy.TBAATag = 0;
1139f27074f42f03af640977006dc7c05005fb77991Dan Gohman      return Copy;
1149f27074f42f03af640977006dc7c05005fb77991Dan Gohman    }
115b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman  };
116b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman
117f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner  /// Alias analysis result - Either we know for sure that it does not alias, we
118f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner  /// know for sure it must alias, or we don't know anything: The two pointers
119f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner  /// _might_ alias.  This enum is designed so you can do things like:
120f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner  ///     if (AA.alias(P1, P2)) { ... }
121f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner  /// to check to see if two pointers might alias.
122f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner  ///
123e53e3772f3c8b4cba69b7d77c8b2148a080fe9aeDan Gohman  /// See docs/AliasAnalysis.html for more information on the specific meanings
124e53e3772f3c8b4cba69b7d77c8b2148a080fe9aeDan Gohman  /// of these values.
125e53e3772f3c8b4cba69b7d77c8b2148a080fe9aeDan Gohman  ///
1261c56b730a6313886076d7b293a126ae5576f5288Chris Lattner  enum AliasResult { NoAlias = 0, MayAlias = 1, MustAlias = 2 };
1274df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner
128f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner  /// alias - The main low level interface to the alias analysis implementation.
1296c25c920e66aa2d8f6b48454bc9770087ff7939aDan Gohman  /// Returns an AliasResult indicating whether the two pointers are aliased to
1306c25c920e66aa2d8f6b48454bc9770087ff7939aDan Gohman  /// each other.  This is the interface that must be implemented by specific
1316c25c920e66aa2d8f6b48454bc9770087ff7939aDan Gohman  /// alias analysis implementations.
132b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman  virtual AliasResult alias(const Location &LocA, const Location &LocB);
1334df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner
134b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman  /// alias - A convenience wrapper.
1353da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman  AliasResult alias(const Value *V1, uint64_t V1Size,
1363da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman                    const Value *V2, uint64_t V2Size) {
137b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman    return alias(Location(V1, V1Size), Location(V2, V2Size));
138b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman  }
139b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman
140b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman  /// alias - A convenience wrapper.
141847a84efd23a2c7d90429b82f6e0f19d1f913d9aDan Gohman  AliasResult alias(const Value *V1, const Value *V2) {
142ef1cfac9e50def9097cd3e3ab3c5cad7f4c758ccDan Gohman    return alias(V1, UnknownSize, V2, UnknownSize);
143847a84efd23a2c7d90429b82f6e0f19d1f913d9aDan Gohman  }
144847a84efd23a2c7d90429b82f6e0f19d1f913d9aDan Gohman
145c46530b6a32a53edf0d6d32bcd09ea5d76940472Chris Lattner  /// isNoAlias - A trivial helper function to check to see if the specified
146c46530b6a32a53edf0d6d32bcd09ea5d76940472Chris Lattner  /// pointers are no-alias.
147b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman  bool isNoAlias(const Location &LocA, const Location &LocB) {
148b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman    return alias(LocA, LocB) == NoAlias;
149b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman  }
150b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman
151b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman  /// isNoAlias - A convenience wrapper.
1523da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman  bool isNoAlias(const Value *V1, uint64_t V1Size,
1533da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman                 const Value *V2, uint64_t V2Size) {
154b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman    return isNoAlias(Location(V1, V1Size), Location(V2, V2Size));
155c46530b6a32a53edf0d6d32bcd09ea5d76940472Chris Lattner  }
156c46530b6a32a53edf0d6d32bcd09ea5d76940472Chris Lattner
157a25e5dbcc2371352386a01e3c1b8e76dd890272bDan Gohman  /// pointsToConstantMemory - If the specified memory location is
158a25e5dbcc2371352386a01e3c1b8e76dd890272bDan Gohman  /// known to be constant, return true. If OrLocal is true and the
159a25e5dbcc2371352386a01e3c1b8e76dd890272bDan Gohman  /// specified memory location is known to be "local" (derived from
160a25e5dbcc2371352386a01e3c1b8e76dd890272bDan Gohman  /// an alloca), return true. Otherwise return false.
161a25e5dbcc2371352386a01e3c1b8e76dd890272bDan Gohman  virtual bool pointsToConstantMemory(const Location &Loc,
162a25e5dbcc2371352386a01e3c1b8e76dd890272bDan Gohman                                      bool OrLocal = false);
163b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman
164b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman  /// pointsToConstantMemory - A convenient wrapper.
165a25e5dbcc2371352386a01e3c1b8e76dd890272bDan Gohman  bool pointsToConstantMemory(const Value *P, bool OrLocal = false) {
166a25e5dbcc2371352386a01e3c1b8e76dd890272bDan Gohman    return pointsToConstantMemory(Location(P), OrLocal);
167b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman  }
16862b5c167de0ca5883a7ad5eb0900eb0c15ad3707Chris Lattner
169248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner  //===--------------------------------------------------------------------===//
170248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner  /// Simple mod/ref information...
171248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner  ///
172248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner
173248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner  /// ModRefResult - Represent the result of a mod/ref query.  Mod and Ref are
174248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner  /// bits which may be or'd together.
175248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner  ///
176248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner  enum ModRefResult { NoModRef = 0, Ref = 1, Mod = 2, ModRef = 3 };
1779769ab22265b313171d201b5928688524a01bd87Misha Brukman
17842c31a70735e55bf82e66a9315c97d1821c9a798Dan Gohman  /// These values define additional bits used to define the
17942c31a70735e55bf82e66a9315c97d1821c9a798Dan Gohman  /// ModRefBehavior values.
18042c31a70735e55bf82e66a9315c97d1821c9a798Dan Gohman  enum { Nowhere = 0, ArgumentPointees = 4, Anywhere = 8 | ArgumentPointees };
1819769ab22265b313171d201b5928688524a01bd87Misha Brukman
182248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner  /// ModRefBehavior - Summary of how a function affects memory in the program.
183248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner  /// Loads from constant globals are not considered memory accesses for this
184248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner  /// interface.  Also, functions may freely modify stack space local to their
185248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner  /// invocation without having to report it through these interfaces.
186248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner  enum ModRefBehavior {
18750a04d067f8803d52cababdabe5c188844c5c210Dan Gohman    /// DoesNotAccessMemory - This function does not perform any non-local loads
18850a04d067f8803d52cababdabe5c188844c5c210Dan Gohman    /// or stores to memory.
18950a04d067f8803d52cababdabe5c188844c5c210Dan Gohman    ///
19050a04d067f8803d52cababdabe5c188844c5c210Dan Gohman    /// This property corresponds to the GCC 'const' attribute.
19150a04d067f8803d52cababdabe5c188844c5c210Dan Gohman    /// This property corresponds to the LLVM IR 'readnone' attribute.
19250a04d067f8803d52cababdabe5c188844c5c210Dan Gohman    /// This property corresponds to the IntrNoMem LLVM intrinsic flag.
19342c31a70735e55bf82e66a9315c97d1821c9a798Dan Gohman    DoesNotAccessMemory = Nowhere | NoModRef,
1949769ab22265b313171d201b5928688524a01bd87Misha Brukman
19550a04d067f8803d52cababdabe5c188844c5c210Dan Gohman    /// AccessesArgumentsReadonly - This function loads through function
19650a04d067f8803d52cababdabe5c188844c5c210Dan Gohman    /// arguments and does not perform any non-local stores or volatile
19750a04d067f8803d52cababdabe5c188844c5c210Dan Gohman    /// loads.
19850a04d067f8803d52cababdabe5c188844c5c210Dan Gohman    ///
19950a04d067f8803d52cababdabe5c188844c5c210Dan Gohman    /// This property corresponds to the IntrReadArgMem LLVM intrinsic flag.
20042c31a70735e55bf82e66a9315c97d1821c9a798Dan Gohman    AccessesArgumentsReadonly = ArgumentPointees | Ref,
201db78c4873ea8c4b3dce90d761a1ad59d5bcdd6e7Dan Gohman
20250a04d067f8803d52cababdabe5c188844c5c210Dan Gohman    /// AccessesArguments - This function accesses function arguments in well
20350a04d067f8803d52cababdabe5c188844c5c210Dan Gohman    /// known (possibly volatile) ways, but does not access any other memory.
20450a04d067f8803d52cababdabe5c188844c5c210Dan Gohman    ///
20550a04d067f8803d52cababdabe5c188844c5c210Dan Gohman    /// This property corresponds to the IntrReadWriteArgMem LLVM intrinsic flag.
20642c31a70735e55bf82e66a9315c97d1821c9a798Dan Gohman    AccessesArguments = ArgumentPointees | ModRef,
2079769ab22265b313171d201b5928688524a01bd87Misha Brukman
20850a04d067f8803d52cababdabe5c188844c5c210Dan Gohman    /// OnlyReadsMemory - This function does not perform any non-local stores or
20950a04d067f8803d52cababdabe5c188844c5c210Dan Gohman    /// volatile loads, but may read from any memory location.
21050a04d067f8803d52cababdabe5c188844c5c210Dan Gohman    ///
21150a04d067f8803d52cababdabe5c188844c5c210Dan Gohman    /// This property corresponds to the GCC 'pure' attribute.
21250a04d067f8803d52cababdabe5c188844c5c210Dan Gohman    /// This property corresponds to the LLVM IR 'readonly' attribute.
21350a04d067f8803d52cababdabe5c188844c5c210Dan Gohman    /// This property corresponds to the IntrReadMem LLVM intrinsic flag.
21442c31a70735e55bf82e66a9315c97d1821c9a798Dan Gohman    OnlyReadsMemory = Anywhere | Ref,
2159769ab22265b313171d201b5928688524a01bd87Misha Brukman
21650a04d067f8803d52cababdabe5c188844c5c210Dan Gohman    /// UnknownModRefBehavior - This indicates that the function could not be
21750a04d067f8803d52cababdabe5c188844c5c210Dan Gohman    /// classified into one of the behaviors above.
21842c31a70735e55bf82e66a9315c97d1821c9a798Dan Gohman    UnknownModRefBehavior = Anywhere | ModRef
219248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner  };
2209769ab22265b313171d201b5928688524a01bd87Misha Brukman
221dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands  /// getModRefBehavior - Return the behavior when calling the given call site.
222a41af344c2964573318a77e2b43eafd4d3804003Dan Gohman  virtual ModRefBehavior getModRefBehavior(ImmutableCallSite CS);
223dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands
224dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands  /// getModRefBehavior - Return the behavior when calling the given function.
225dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands  /// For use when the call site is not known.
226a41af344c2964573318a77e2b43eafd4d3804003Dan Gohman  virtual ModRefBehavior getModRefBehavior(const Function *F);
227dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands
228dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands  /// doesNotAccessMemory - If the specified call is known to never read or
229dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands  /// write memory, return true.  If the call only reads from known-constant
230dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands  /// memory, it is also legal to return true.  Calls that unwind the stack
231dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands  /// are legal for this predicate.
2323e295b1b59e47916c8ae5d42eb27a23bd580cabeChris Lattner  ///
233dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands  /// Many optimizations (such as CSE and LICM) can be performed on such calls
234dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands  /// without worrying about aliasing properties, and many calls have this
235dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands  /// property (e.g. calls to 'sin' and 'cos').
2363e295b1b59e47916c8ae5d42eb27a23bd580cabeChris Lattner  ///
2373e295b1b59e47916c8ae5d42eb27a23bd580cabeChris Lattner  /// This property corresponds to the GCC 'const' attribute.
2383e295b1b59e47916c8ae5d42eb27a23bd580cabeChris Lattner  ///
23979fca6fea87be7221843031870bbf2c9ae1fc555Dan Gohman  bool doesNotAccessMemory(ImmutableCallSite CS) {
240652f7ea955bb433d6b7a4d33685dca9485fd7b8bEvan Cheng    return getModRefBehavior(CS) == DoesNotAccessMemory;
241dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands  }
242dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands
243dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands  /// doesNotAccessMemory - If the specified function is known to never read or
244dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands  /// write memory, return true.  For use when the call site is not known.
245dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands  ///
24679fca6fea87be7221843031870bbf2c9ae1fc555Dan Gohman  bool doesNotAccessMemory(const Function *F) {
247dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands    return getModRefBehavior(F) == DoesNotAccessMemory;
248248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner  }
2493e295b1b59e47916c8ae5d42eb27a23bd580cabeChris Lattner
250dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands  /// onlyReadsMemory - If the specified call is known to only read from
251dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands  /// non-volatile memory (or not access memory at all), return true.  Calls
252dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands  /// that unwind the stack are legal for this predicate.
2533e295b1b59e47916c8ae5d42eb27a23bd580cabeChris Lattner  ///
2543e295b1b59e47916c8ae5d42eb27a23bd580cabeChris Lattner  /// This property allows many common optimizations to be performed in the
2553e295b1b59e47916c8ae5d42eb27a23bd580cabeChris Lattner  /// absence of interfering store instructions, such as CSE of strlen calls.
2563e295b1b59e47916c8ae5d42eb27a23bd580cabeChris Lattner  ///
2573e295b1b59e47916c8ae5d42eb27a23bd580cabeChris Lattner  /// This property corresponds to the GCC 'pure' attribute.
2583e295b1b59e47916c8ae5d42eb27a23bd580cabeChris Lattner  ///
25979fca6fea87be7221843031870bbf2c9ae1fc555Dan Gohman  bool onlyReadsMemory(ImmutableCallSite CS) {
260467a0adfc8b6bd4b114e024c200c159497a4cd86Dan Gohman    return onlyReadsMemory(getModRefBehavior(CS));
261dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands  }
262dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands
263dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands  /// onlyReadsMemory - If the specified function is known to only read from
264dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands  /// non-volatile memory (or not access memory at all), return true.  For use
265dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands  /// when the call site is not known.
266dff6710717b159f089c76a07eda074eb6347eb92Duncan Sands  ///
26779fca6fea87be7221843031870bbf2c9ae1fc555Dan Gohman  bool onlyReadsMemory(const Function *F) {
268467a0adfc8b6bd4b114e024c200c159497a4cd86Dan Gohman    return onlyReadsMemory(getModRefBehavior(F));
269467a0adfc8b6bd4b114e024c200c159497a4cd86Dan Gohman  }
270467a0adfc8b6bd4b114e024c200c159497a4cd86Dan Gohman
271467a0adfc8b6bd4b114e024c200c159497a4cd86Dan Gohman  /// onlyReadsMemory - If the functions with the specified behavior are known
272467a0adfc8b6bd4b114e024c200c159497a4cd86Dan Gohman  /// to only read from non-volatile memory (or not access memory at all), return
273467a0adfc8b6bd4b114e024c200c159497a4cd86Dan Gohman  /// true.  For use when the call site is not known.
274467a0adfc8b6bd4b114e024c200c159497a4cd86Dan Gohman  ///
275467a0adfc8b6bd4b114e024c200c159497a4cd86Dan Gohman  static bool onlyReadsMemory(ModRefBehavior MRB) {
27642c31a70735e55bf82e66a9315c97d1821c9a798Dan Gohman    return !(MRB & Mod);
277248e8ebeff834db9b78917b1531eeee7035eb113Chris Lattner  }
2784df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner
2791c56b730a6313886076d7b293a126ae5576f5288Chris Lattner  /// getModRefInfo - Return information about whether or not an instruction may
280b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman  /// read or write the specified memory location.  An instruction
2811c56b730a6313886076d7b293a126ae5576f5288Chris Lattner  /// that doesn't read or write memory may be trivially LICM'd for example.
282fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman  ModRefResult getModRefInfo(const Instruction *I,
283b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman                             const Location &Loc) {
284fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman    switch (I->getOpcode()) {
285b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman    case Instruction::VAArg:  return getModRefInfo((const VAArgInst*)I, Loc);
286b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman    case Instruction::Load:   return getModRefInfo((const LoadInst*)I,  Loc);
287b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman    case Instruction::Store:  return getModRefInfo((const StoreInst*)I, Loc);
288b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman    case Instruction::Call:   return getModRefInfo((const CallInst*)I,  Loc);
289b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman    case Instruction::Invoke: return getModRefInfo((const InvokeInst*)I,Loc);
290fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman    default:                  return NoModRef;
291fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman    }
292fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman  }
2931c56b730a6313886076d7b293a126ae5576f5288Chris Lattner
294b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman  /// getModRefInfo - A convenience wrapper.
295b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman  ModRefResult getModRefInfo(const Instruction *I,
2963da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman                             const Value *P, uint64_t Size) {
297b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman    return getModRefInfo(I, Location(P, Size));
298b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman  }
299b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman
3001c56b730a6313886076d7b293a126ae5576f5288Chris Lattner  /// getModRefInfo (for call sites) - Return whether information about whether
301b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman  /// a particular call site modifies or reads the specified memory location.
30279fca6fea87be7221843031870bbf2c9ae1fc555Dan Gohman  virtual ModRefResult getModRefInfo(ImmutableCallSite CS,
303b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman                                     const Location &Loc);
304b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman
305b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman  /// getModRefInfo (for call sites) - A convenience wrapper.
306b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman  ModRefResult getModRefInfo(ImmutableCallSite CS,
3073da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman                             const Value *P, uint64_t Size) {
308b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman    return getModRefInfo(CS, Location(P, Size));
309b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman  }
3101c56b730a6313886076d7b293a126ae5576f5288Chris Lattner
311fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman  /// getModRefInfo (for calls) - Return whether information about whether
312b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman  /// a particular call modifies or reads the specified memory location.
313b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman  ModRefResult getModRefInfo(const CallInst *C, const Location &Loc) {
314b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman    return getModRefInfo(ImmutableCallSite(C), Loc);
315b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman  }
316b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman
317b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman  /// getModRefInfo (for calls) - A convenience wrapper.
3183da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman  ModRefResult getModRefInfo(const CallInst *C, const Value *P, uint64_t Size) {
319b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman    return getModRefInfo(C, Location(P, Size));
3201c56b730a6313886076d7b293a126ae5576f5288Chris Lattner  }
321fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman
322fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman  /// getModRefInfo (for invokes) - Return whether information about whether
323b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman  /// a particular invoke modifies or reads the specified memory location.
324b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman  ModRefResult getModRefInfo(const InvokeInst *I,
325b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman                             const Location &Loc) {
326b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman    return getModRefInfo(ImmutableCallSite(I), Loc);
327b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman  }
328b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman
329b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman  /// getModRefInfo (for invokes) - A convenience wrapper.
33079fca6fea87be7221843031870bbf2c9ae1fc555Dan Gohman  ModRefResult getModRefInfo(const InvokeInst *I,
3313da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman                             const Value *P, uint64_t Size) {
332b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman    return getModRefInfo(I, Location(P, Size));
3331c56b730a6313886076d7b293a126ae5576f5288Chris Lattner  }
334fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman
335fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman  /// getModRefInfo (for loads) - Return whether information about whether
336b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman  /// a particular load modifies or reads the specified memory location.
337b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman  ModRefResult getModRefInfo(const LoadInst *L, const Location &Loc);
338b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman
339b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman  /// getModRefInfo (for loads) - A convenience wrapper.
3403da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman  ModRefResult getModRefInfo(const LoadInst *L, const Value *P, uint64_t Size) {
341b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman    return getModRefInfo(L, Location(P, Size));
342b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman  }
343fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman
344fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman  /// getModRefInfo (for stores) - Return whether information about whether
345b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman  /// a particular store modifies or reads the specified memory location.
346b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman  ModRefResult getModRefInfo(const StoreInst *S, const Location &Loc);
347b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman
348b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman  /// getModRefInfo (for stores) - A convenience wrapper.
3493da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman  ModRefResult getModRefInfo(const StoreInst *S, const Value *P, uint64_t Size) {
350b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman    return getModRefInfo(S, Location(P, Size));
351b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman  }
352fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman
353fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman  /// getModRefInfo (for va_args) - Return whether information about whether
354b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman  /// a particular va_arg modifies or reads the specified memory location.
355b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman  ModRefResult getModRefInfo(const VAArgInst* I, const Location &Loc);
356b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman
357b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman  /// getModRefInfo (for va_args) - A convenience wrapper.
3583da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman  ModRefResult getModRefInfo(const VAArgInst* I, const Value* P, uint64_t Size) {
359b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman    return getModRefInfo(I, Location(P, Size));
360b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman  }
361fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman
362fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman  /// getModRefInfo - Return information about whether two call sites may refer
363fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman  /// to the same set of memory locations.  See
364fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman  ///   http://llvm.org/docs/AliasAnalysis.html#ModRefInfo
365fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman  /// for details.
366fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman  virtual ModRefResult getModRefInfo(ImmutableCallSite CS1,
367fa6cb8d8211579f1370e80b7bac54ebe3fbe35c8Dan Gohman                                     ImmutableCallSite CS2);
3684df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner
369ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner  //===--------------------------------------------------------------------===//
370ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner  /// Higher level methods for querying mod/ref information.
371ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner  ///
372ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner
373f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner  /// canBasicBlockModify - Return true if it is possible for execution of the
374f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner  /// specified basic block to modify the value pointed to by Ptr.
375b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman  bool canBasicBlockModify(const BasicBlock &BB, const Location &Loc);
376b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman
377b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman  /// canBasicBlockModify - A convenience wrapper.
3783da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman  bool canBasicBlockModify(const BasicBlock &BB, const Value *P, uint64_t Size){
379b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman    return canBasicBlockModify(BB, Location(P, Size));
380b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman  }
3814df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner
382f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner  /// canInstructionRangeModify - Return true if it is possible for the
383f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner  /// execution of the specified instructions to modify the value pointed to by
384f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner  /// Ptr.  The instructions to consider are all of the instructions in the
385f12c2c28bd72091f2d7fff5718265c5ad52e7af8Chris Lattner  /// range of [I1,I2] INCLUSIVE.  I1 and I2 must be in the same basic block.
3864df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner  bool canInstructionRangeModify(const Instruction &I1, const Instruction &I2,
387b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman                                 const Location &Loc);
388b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman
389b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman  /// canInstructionRangeModify - A convenience wrapper.
390b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman  bool canInstructionRangeModify(const Instruction &I1, const Instruction &I2,
3913da848bbda62b25c12335998aaa44ab361f0bf15Dan Gohman                                 const Value *Ptr, uint64_t Size) {
392b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman    return canInstructionRangeModify(I1, I2, Location(Ptr, Size));
393b2143b6247901ae4eca2192ee134564c4f5f7853Dan Gohman  }
394ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner
395ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner  //===--------------------------------------------------------------------===//
396ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner  /// Methods that clients should call when they transform the program to allow
397ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner  /// alias analyses to update their internal data structures.  Note that these
398ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner  /// methods may be called on any instruction, regardless of whether or not
399ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner  /// they have pointer-analysis implications.
400ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner  ///
401ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner
402ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner  /// deleteValue - This method should be called whenever an LLVM Value is
403ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner  /// deleted from the program, for example when an instruction is found to be
404ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner  /// redundant and is eliminated.
405ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner  ///
406ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner  virtual void deleteValue(Value *V);
407ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner
408ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner  /// copyValue - This method should be used whenever a preexisting value in the
409ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner  /// program is copied or cloned, introducing a new value.  Note that analysis
410ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner  /// implementations should tolerate clients that use this method to introduce
411ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner  /// the same value multiple times: if the analysis already knows about a
412ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner  /// value, it should ignore the request.
413ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner  ///
414ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner  virtual void copyValue(Value *From, Value *To);
415ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner
416ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner  /// replaceWithNewValue - This method is the obvious combination of the two
417ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner  /// above, and it provided as a helper to simplify client code.
418ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner  ///
419ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner  void replaceWithNewValue(Value *Old, Value *New) {
420ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner    copyValue(Old, New);
421ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner    deleteValue(Old);
422ab8c565768ff7485f40cbb65e2914f9046e743d4Chris Lattner  }
4234df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner};
4244df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner
425a5f81bba4ab18d6129774d4d67495f14b6f64375Dan Gohman/// isNoAliasCall - Return true if this pointer is returned by a noalias
426a5f81bba4ab18d6129774d4d67495f14b6f64375Dan Gohman/// function.
427a5f81bba4ab18d6129774d4d67495f14b6f64375Dan Gohmanbool isNoAliasCall(const Value *V);
428a5f81bba4ab18d6129774d4d67495f14b6f64375Dan Gohman
4293311a1f8f0d8a2c6d940802bbb95eba0b801a615Dan Gohman/// isIdentifiedObject - Return true if this pointer refers to a distinct and
430a5f81bba4ab18d6129774d4d67495f14b6f64375Dan Gohman/// identifiable object.  This returns true for:
4315753a4a0033da4add45f2e9930a4e1159d92a869Dan Gohman///    Global Variables and Functions (but not Global Aliases)
432a5f81bba4ab18d6129774d4d67495f14b6f64375Dan Gohman///    Allocas and Mallocs
4339e86f4364b912ae743490ba01d6989acfd12c046Dan Gohman///    ByVal and NoAlias Arguments
4349e86f4364b912ae743490ba01d6989acfd12c046Dan Gohman///    NoAlias returns
4353311a1f8f0d8a2c6d940802bbb95eba0b801a615Dan Gohman///
4369e86f4364b912ae743490ba01d6989acfd12c046Dan Gohmanbool isIdentifiedObject(const Value *V);
4373311a1f8f0d8a2c6d940802bbb95eba0b801a615Dan Gohman
4384f1bd9e9963239c119db70070db1d68286b3de7eReid Spencer} // End llvm namespace
4394f1bd9e9963239c119db70070db1d68286b3de7eReid Spencer
4404df22c0100fe27f19e6f4874f24eedd0742b9cf4Chris Lattner#endif
441