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 /// getMustAliases - If there are any pointers known that must alias this
80 /// pointer, return them now. This allows alias-set based alias analyses to
81 /// perform a form a value numbering (which is exposed by load-vn). If an
82 /// alias analysis supports this, it should ADD any must aliased pointers to
83 /// the specified vector.
85 virtual void getMustAliases(Value *P, std::vector<Value*> &RetVals) {}
88 //===--------------------------------------------------------------------===//
89 /// Simple mod/ref information...
92 /// ModRefResult - Represent the result of a mod/ref query. Mod and Ref are
93 /// bits which may be or'd together.
95 enum ModRefResult { NoModRef = 0, Ref = 1, Mod = 2, ModRef = 3 };
97 /// getModRefInfo - Return information about whether or not an instruction may
98 /// read or write memory specified by the pointer operand. An instruction
99 /// that doesn't read or write memory may be trivially LICM'd for example.
101 /// getModRefInfo (for call sites) - Return whether information about whether
102 /// a particular call site modifies or reads the memory specified by the
105 virtual ModRefResult getModRefInfo(CallSite CS, Value *P, unsigned Size) {
109 /// getModRefInfo - Return information about whether two call sites may refer
110 /// to the same set of memory locations. This function returns NoModRef if
111 /// the two calls refer to disjoint memory locations, Ref if they both read
112 /// some of the same memory, Mod if they both write to some of the same
113 /// memory, and ModRef if they read and write to the same memory.
115 virtual ModRefResult getModRefInfo(CallSite CS1, CallSite CS2) {
119 /// Convenience functions...
120 ModRefResult getModRefInfo(LoadInst *L, Value *P, unsigned Size);
121 ModRefResult getModRefInfo(StoreInst*S, Value *P, unsigned Size);
122 ModRefResult getModRefInfo(CallInst *C, Value *P, unsigned Size) {
123 return getModRefInfo(CallSite(C), P, Size);
125 ModRefResult getModRefInfo(InvokeInst*I, Value *P, unsigned Size) {
126 return getModRefInfo(CallSite(I), P, Size);
128 ModRefResult getModRefInfo(Instruction *I, Value *P, unsigned Size) {
129 switch (I->getOpcode()) {
130 case Instruction::Load: return getModRefInfo((LoadInst*)I, P, Size);
131 case Instruction::Store: return getModRefInfo((StoreInst*)I, P, Size);
132 case Instruction::Call: return getModRefInfo((CallInst*)I, P, Size);
133 case Instruction::Invoke: return getModRefInfo((InvokeInst*)I, P, Size);
134 default: return NoModRef;
138 /// canBasicBlockModify - Return true if it is possible for execution of the
139 /// specified basic block to modify the value pointed to by Ptr.
141 bool canBasicBlockModify(const BasicBlock &BB, const Value *P, unsigned Size);
143 /// canInstructionRangeModify - Return true if it is possible for the
144 /// execution of the specified instructions to modify the value pointed to by
145 /// Ptr. The instructions to consider are all of the instructions in the
146 /// range of [I1,I2] INCLUSIVE. I1 and I2 must be in the same basic block.
148 bool canInstructionRangeModify(const Instruction &I1, const Instruction &I2,
149 const Value *Ptr, unsigned Size);