1 //===- llvm/Analysis/AliasAnalysis.h - Alias Analysis Interface -*- C++ -*-===//
3 // This file defines the generic AliasAnalysis interface, which is used as the
4 // common interface used by all clients of alias analysis information, and
5 // implemented by all alias analysis implementations. Mod/Ref information is
6 // also captured by this interface.
8 // Implementations of this interface must implement the various virtual methods,
9 // which automatically provides functionality for the entire suite of client
12 // This API represents memory as a (Pointer, Size) pair. The Pointer component
13 // specifies the base memory address of the region, the Size specifies how large
14 // of an area is being queried. If Size is 0, two pointers only alias if they
15 // are exactly equal. If size is greater than zero, but small, the two pointers
16 // alias if the areas pointed to overlap. If the size is very large (ie, ~0U),
17 // then the two pointers alias if they may be pointing to components of the same
18 // memory object. Pointers that point to two completely different objects in
19 // memory never alias, regardless of the value of the Size component.
21 //===----------------------------------------------------------------------===//
23 #ifndef LLVM_ANALYSIS_ALIAS_ANALYSIS_H
24 #define LLVM_ANALYSIS_ALIAS_ANALYSIS_H
26 #include "llvm/Support/CallSite.h"
36 /// InitializeAliasAnalysis - Subclasses must call this method to initialize
37 /// the AliasAnalysis interface before any other methods are called. This is
38 /// typically called by the run* methods of these subclasses. This may be
39 /// called multiple times.
41 void InitializeAliasAnalysis(Pass *P);
43 // getAnalysisUsage - All alias analysis implementations should invoke this
44 // directly (using AliasAnalysis::getAnalysisUsage(AU)) to make sure that
45 // TargetData is required by the pass.
46 virtual void getAnalysisUsage(AnalysisUsage &AU) const;
49 AliasAnalysis() : TD(0) {}
50 virtual ~AliasAnalysis(); // We want to be subclassed
52 /// getTargetData - Every alias analysis implementation depends on the size of
53 /// data items in the current Target. This provides a uniform way to handle
55 const TargetData &getTargetData() const { return *TD; }
57 //===--------------------------------------------------------------------===//
61 /// Alias analysis result - Either we know for sure that it does not alias, we
62 /// know for sure it must alias, or we don't know anything: The two pointers
63 /// _might_ alias. This enum is designed so you can do things like:
64 /// if (AA.alias(P1, P2)) { ... }
65 /// to check to see if two pointers might alias.
67 enum AliasResult { NoAlias = 0, MayAlias = 1, MustAlias = 2 };
69 /// alias - The main low level interface to the alias analysis implementation.
70 /// Returns a Result indicating whether the two pointers are aliased to each
71 /// other. This is the interface that must be implemented by specific alias
72 /// analysis implementations.
74 virtual AliasResult alias(const Value *V1, unsigned V1Size,
75 const Value *V2, unsigned V2Size) {
79 //===--------------------------------------------------------------------===//
80 /// Simple mod/ref information...
83 /// ModRefResult - Represent the result of a mod/ref query. Mod and Ref are
84 /// bits which may be or'd together.
86 enum ModRefResult { NoModRef = 0, Ref = 1, Mod = 2, ModRef = 3 };
88 /// getModRefInfo - Return information about whether or not an instruction may
89 /// read or write memory specified by the pointer operand. An instruction
90 /// that doesn't read or write memory may be trivially LICM'd for example.
92 /// getModRefInfo (for call sites) - Return whether information about whether
93 /// a particular call site modifies or reads the memory specified by the
96 virtual ModRefResult getModRefInfo(CallSite CS, Value *P, unsigned Size) {
100 /// getModRefInfo - Return information about whether two call sites may refer
101 /// to the same set of memory locations. This function returns NoModRef if
102 /// the two calls refer to disjoint memory locations, Ref if they both read
103 /// some of the same memory, Mod if they both write to some of the same
104 /// memory, and ModRef if they read and write to the same memory.
106 virtual ModRefResult getModRefInfo(CallSite CS1, CallSite CS2) {
110 /// Convenience functions...
111 ModRefResult getModRefInfo(LoadInst *L, Value *P, unsigned Size);
112 ModRefResult getModRefInfo(StoreInst*S, Value *P, unsigned Size);
113 ModRefResult getModRefInfo(CallInst *C, Value *P, unsigned Size) {
114 return getModRefInfo(CallSite(C), P, Size);
116 ModRefResult getModRefInfo(InvokeInst*I, Value *P, unsigned Size) {
117 return getModRefInfo(CallSite(I), P, Size);
119 ModRefResult getModRefInfo(Instruction *I, Value *P, unsigned Size) {
120 switch (I->getOpcode()) {
121 case Instruction::Load: return getModRefInfo((LoadInst*)I, P, Size);
122 case Instruction::Store: return getModRefInfo((StoreInst*)I, P, Size);
123 case Instruction::Call: return getModRefInfo((CallInst*)I, P, Size);
124 case Instruction::Invoke: return getModRefInfo((InvokeInst*)I, P, Size);
125 default: return NoModRef;
129 /// canBasicBlockModify - Return true if it is possible for execution of the
130 /// specified basic block to modify the value pointed to by Ptr.
132 bool canBasicBlockModify(const BasicBlock &BB, const Value *P, unsigned Size);
134 /// canInstructionRangeModify - Return true if it is possible for the
135 /// execution of the specified instructions to modify the value pointed to by
136 /// Ptr. The instructions to consider are all of the instructions in the
137 /// range of [I1,I2] INCLUSIVE. I1 and I2 must be in the same basic block.
139 bool canInstructionRangeModify(const Instruction &I1, const Instruction &I2,
140 const Value *Ptr, unsigned Size);