Because I like being able to instantiate the cfgprinter from external projects,
[oota-llvm.git] / include / llvm / Analysis / AliasAnalysis.h
index 4ce3f4baf17ad4d3e1f9ea8aafa5b6db3aa1bffd..54ea494869930538cbe2b6c7cefe2255e7648918 100644 (file)
 #define LLVM_ANALYSIS_ALIAS_ANALYSIS_H
 
 #include "llvm/Support/CallSite.h"
+#include "llvm/Pass.h"    // Need this for IncludeFile
+
+namespace llvm {
+
 class LoadInst;
 class StoreInst;
 class TargetData;
-class AnalysisUsage;
-class Pass;
 
 class AliasAnalysis {
   const TargetData *TD;
@@ -59,6 +61,7 @@ public:
   /// getTargetData - Every alias analysis implementation depends on the size of
   /// data items in the current Target.  This provides a uniform way to handle
   /// it.
+  ///
   const TargetData &getTargetData() const { return *TD; }
 
   //===--------------------------------------------------------------------===//
@@ -91,6 +94,36 @@ public:
   ///
   virtual void getMustAliases(Value *P, std::vector<Value*> &RetVals) {}
 
+  /// pointsToConstantMemory - If the specified pointer is known to point into
+  /// constant global memory, return true.  This allows disambiguation of store
+  /// instructions from constant pointers.
+  ///
+  virtual bool pointsToConstantMemory(const Value *P) { return false; }
+
+  /// doesNotAccessMemory - If the specified function is known to never read or
+  /// write memory, return true.  If the function only reads from known-constant
+  /// memory, it is also legal to return true.  Functions that unwind the stack
+  /// are not legal for this predicate.
+  ///
+  /// Many optimizations (such as CSE and LICM) can be performed on calls to it,
+  /// without worrying about aliasing properties, and many functions have this
+  /// property (e.g. 'sin' and 'cos').
+  ///
+  /// This property corresponds to the GCC 'const' attribute.
+  ///
+  virtual bool doesNotAccessMemory(Function *F) { return false; }
+
+  /// onlyReadsMemory - If the specified function is known to only read from
+  /// non-volatile memory (or not access memory at all), return true.  Functions
+  /// that unwind the stack are not legal for this predicate.
+  ///
+  /// This property allows many common optimizations to be performed in the
+  /// absence of interfering store instructions, such as CSE of strlen calls.
+  ///
+  /// This property corresponds to the GCC 'pure' attribute.
+  ///
+  virtual bool onlyReadsMemory(Function *F) { return doesNotAccessMemory(F); }
+
 
   //===--------------------------------------------------------------------===//
   /// Simple mod/ref information...
@@ -109,27 +142,32 @@ public:
   /// a particular call site modifies or reads the memory specified by the
   /// pointer.
   ///
-  virtual ModRefResult getModRefInfo(CallSite CS, Value *P, unsigned Size) {
-    return ModRef;
-  }
+  virtual ModRefResult getModRefInfo(CallSite CS, Value *P, unsigned Size);
 
   /// getModRefInfo - Return information about whether two call sites may refer
   /// to the same set of memory locations.  This function returns NoModRef if
-  /// the two calls refer to disjoint memory locations, Ref if they both read
-  /// some of the same memory, Mod if they both write to some of the same
-  /// memory, and ModRef if they read and write to the same memory.
+  /// the two calls refer to disjoint memory locations, Ref if CS1 reads memory
+  /// written by CS2, Mod if CS1 writes to memory read or written by CS2, or
+  /// ModRef if CS1 might read or write memory accessed by CS2.
   ///
-  virtual ModRefResult getModRefInfo(CallSite CS1, CallSite CS2) {
-    return ModRef;
-  }
+  virtual ModRefResult getModRefInfo(CallSite CS1, CallSite CS2);
+
+  /// hasNoModRefInfoForCalls - Return true if the analysis has no mod/ref
+  /// information for pairs of function calls (other than "pure" and "const"
+  /// functions).  This can be used by clients to avoid many pointless queries.
+  /// Remember that if you override this and chain to another analysis, you must
+  /// make sure that it doesn't have mod/ref info either.
+  ///
+  virtual bool hasNoModRefInfoForCalls() const { return false; }
+
 
   /// Convenience functions...
   ModRefResult getModRefInfo(LoadInst *L, Value *P, unsigned Size);
-  ModRefResult getModRefInfo(StoreInst*S, Value *P, unsigned Size);
-  ModRefResult getModRefInfo(CallInst  *C, Value *P, unsigned Size) {
+  ModRefResult getModRefInfo(StoreInst *S, Value *P, unsigned Size);
+  ModRefResult getModRefInfo(CallInst *C, Value *P, unsigned Size) {
     return getModRefInfo(CallSite(C), P, Size);
   }
-  ModRefResult getModRefInfo(InvokeInst*I, Value *P, unsigned Size) {
+  ModRefResult getModRefInfo(InvokeInst *I, Value *P, unsigned Size) {
     return getModRefInfo(CallSite(I), P, Size);
   }
   ModRefResult getModRefInfo(Instruction *I, Value *P, unsigned Size) {
@@ -156,4 +194,14 @@ public:
                                  const Value *Ptr, unsigned Size);
 };
 
+// Because of the way .a files work, we must force the BasicAA implementation to
+// be pulled in if the AliasAnalysis header is included.  Otherwise we run
+// the risk of AliasAnalysis being used, but the default implementation not
+// being linked into the tool that uses it.
+//
+extern void BasicAAStub();
+static IncludeFile HDR_INCLUDE_BASICAA_CPP((void*)&BasicAAStub);
+
+} // End llvm namespace
+
 #endif