annotate include/llvm/Analysis/BasicAliasAnalysis.h @ 128:c347d3398279 default tip

fix
author mir3636
date Wed, 06 Dec 2017 14:37:17 +0900
parents 803732b1fca8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 //===- BasicAliasAnalysis.h - Stateless, local Alias Analysis ---*- C++ -*-===//
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 //
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 // The LLVM Compiler Infrastructure
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 //
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 // This file is distributed under the University of Illinois Open Source
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 // License. See LICENSE.TXT for details.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 //
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 //===----------------------------------------------------------------------===//
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 /// \file
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 /// This is the interface for LLVM's primary stateless and local alias analysis.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 ///
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 //===----------------------------------------------------------------------===//
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 #ifndef LLVM_ANALYSIS_BASICALIASANALYSIS_H
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 #define LLVM_ANALYSIS_BASICALIASANALYSIS_H
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
17 #include "llvm/ADT/DenseMap.h"
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
18 #include "llvm/ADT/Optional.h"
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 #include "llvm/ADT/SmallPtrSet.h"
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
20 #include "llvm/ADT/SmallVector.h"
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 #include "llvm/Analysis/AliasAnalysis.h"
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 #include "llvm/Analysis/AssumptionCache.h"
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
23 #include "llvm/Analysis/MemoryLocation.h"
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
24 #include "llvm/IR/CallSite.h"
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 #include "llvm/IR/PassManager.h"
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
26 #include "llvm/Pass.h"
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
27 #include <algorithm>
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
28 #include <cstdint>
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
29 #include <memory>
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
30 #include <utility>
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 namespace llvm {
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
33
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
34 struct AAMDNodes;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
35 class APInt;
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 class AssumptionCache;
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
37 class BasicBlock;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
38 class DataLayout;
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 class DominatorTree;
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
40 class Function;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
41 class GEPOperator;
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 class LoopInfo;
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
43 class PHINode;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
44 class SelectInst;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
45 class TargetLibraryInfo;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
46 class Value;
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 /// This is the AA result object for the basic, local, and stateless alias
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 /// analysis. It implements the AA query interface in an entirely stateless
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
50 /// manner. As one consequence, it is never invalidated due to IR changes.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
51 /// While it does retain some storage, that is used as an optimization and not
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
52 /// to preserve information from query to query. However it does retain handles
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
53 /// to various other analyses and must be recomputed when those analyses are.
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 class BasicAAResult : public AAResultBase<BasicAAResult> {
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 friend AAResultBase<BasicAAResult>;
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 const DataLayout &DL;
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
58 const TargetLibraryInfo &TLI;
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 AssumptionCache &AC;
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 DominatorTree *DT;
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 LoopInfo *LI;
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 public:
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 BasicAAResult(const DataLayout &DL, const TargetLibraryInfo &TLI,
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 AssumptionCache &AC, DominatorTree *DT = nullptr,
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 LoopInfo *LI = nullptr)
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
67 : AAResultBase(), DL(DL), TLI(TLI), AC(AC), DT(DT), LI(LI) {}
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 BasicAAResult(const BasicAAResult &Arg)
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
70 : AAResultBase(Arg), DL(Arg.DL), TLI(Arg.TLI), AC(Arg.AC), DT(Arg.DT),
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 LI(Arg.LI) {}
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
72 BasicAAResult(BasicAAResult &&Arg)
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
73 : AAResultBase(std::move(Arg)), DL(Arg.DL), TLI(Arg.TLI), AC(Arg.AC),
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
74 DT(Arg.DT), LI(Arg.LI) {}
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
75
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
76 /// Handle invalidation events in the new pass manager.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
77 bool invalidate(Function &F, const PreservedAnalyses &PA,
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
78 FunctionAnalysisManager::Invalidator &Inv);
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
79
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB);
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
81
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 ModRefInfo getModRefInfo(ImmutableCallSite CS, const MemoryLocation &Loc);
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
83
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 ModRefInfo getModRefInfo(ImmutableCallSite CS1, ImmutableCallSite CS2);
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
85
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 /// Chases pointers until we find a (constant global) or not.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal);
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
88
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 /// Get the location associated with a pointer argument of a callsite.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 ModRefInfo getArgModRefInfo(ImmutableCallSite CS, unsigned ArgIdx);
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
91
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 /// Returns the behavior when calling the given call site.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 FunctionModRefBehavior getModRefBehavior(ImmutableCallSite CS);
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
94
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 /// Returns the behavior when calling the given function. For use when the
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 /// call site is not known.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 FunctionModRefBehavior getModRefBehavior(const Function *F);
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
98
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 private:
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 // A linear transformation of a Value; this class represents ZExt(SExt(V,
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 // SExtBits), ZExtBits) * Scale + Offset.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 struct VariableGEPIndex {
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 // An opaque Value - we can't decompose this further.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 const Value *V;
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
105
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 // We need to track what extensions we've done as we consider the same Value
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 // with different extensions as different variables in a GEP's linear
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 // expression;
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 // e.g.: if V == -1, then sext(x) != zext(x).
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 unsigned ZExtBits;
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 unsigned SExtBits;
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
112
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 int64_t Scale;
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
114
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 bool operator==(const VariableGEPIndex &Other) const {
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 return V == Other.V && ZExtBits == Other.ZExtBits &&
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 SExtBits == Other.SExtBits && Scale == Other.Scale;
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
118 }
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
119
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 bool operator!=(const VariableGEPIndex &Other) const {
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 return !operator==(Other);
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 }
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 };
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
124
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
125 // Represents the internal structure of a GEP, decomposed into a base pointer,
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
126 // constant offsets, and variable scaled indices.
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
127 struct DecomposedGEP {
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
128 // Base pointer of the GEP
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
129 const Value *Base;
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
130 // Total constant offset w.r.t the base from indexing into structs
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
131 int64_t StructOffset;
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
132 // Total constant offset w.r.t the base from indexing through
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
133 // pointers/arrays/vectors
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
134 int64_t OtherOffset;
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
135 // Scaled variable (non-constant) indices.
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
136 SmallVector<VariableGEPIndex, 4> VarIndices;
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
137 };
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
138
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
139 /// Track alias queries to guard against recursion.
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
140 using LocPair = std::pair<MemoryLocation, MemoryLocation>;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
141 using AliasCacheTy = SmallDenseMap<LocPair, AliasResult, 8>;
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 AliasCacheTy AliasCache;
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
143
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
144 /// Tracks phi nodes we have visited.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
145 ///
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 /// When interpret "Value" pointer equality as value equality we need to make
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
147 /// sure that the "Value" is not part of a cycle. Otherwise, two uses could
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
148 /// come from different "iterations" of a cycle and see different values for
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
149 /// the same "Value" pointer.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
150 ///
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
151 /// The following example shows the problem:
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
152 /// %p = phi(%alloca1, %addr2)
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
153 /// %l = load %ptr
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
154 /// %addr1 = gep, %alloca2, 0, %l
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
155 /// %addr2 = gep %alloca2, 0, (%l + 1)
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
156 /// alias(%p, %addr1) -> MayAlias !
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
157 /// store %l, ...
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 SmallPtrSet<const BasicBlock *, 8> VisitedPhiBBs;
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
159
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
160 /// Tracks instructions visited by pointsToConstantMemory.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
161 SmallPtrSet<const Value *, 16> Visited;
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
162
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
163 static const Value *
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 GetLinearExpression(const Value *V, APInt &Scale, APInt &Offset,
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
165 unsigned &ZExtBits, unsigned &SExtBits,
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
166 const DataLayout &DL, unsigned Depth, AssumptionCache *AC,
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
167 DominatorTree *DT, bool &NSW, bool &NUW);
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
168
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
169 static bool DecomposeGEPExpression(const Value *V, DecomposedGEP &Decomposed,
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
170 const DataLayout &DL, AssumptionCache *AC, DominatorTree *DT);
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
171
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
172 static bool isGEPBaseAtNegativeOffset(const GEPOperator *GEPOp,
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
173 const DecomposedGEP &DecompGEP, const DecomposedGEP &DecompObject,
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
174 uint64_t ObjectAccessSize);
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
175
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
176 /// \brief A Heuristic for aliasGEP that searches for a constant offset
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
177 /// between the variables.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
178 ///
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
179 /// GetLinearExpression has some limitations, as generally zext(%x + 1)
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
180 /// != zext(%x) + zext(1) if the arithmetic overflows. GetLinearExpression
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 /// will therefore conservatively refuse to decompose these expressions.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
182 /// However, we know that, for all %x, zext(%x) != zext(%x + 1), even if
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
183 /// the addition overflows.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
184 bool
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
185 constantOffsetHeuristic(const SmallVectorImpl<VariableGEPIndex> &VarIndices,
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
186 uint64_t V1Size, uint64_t V2Size, int64_t BaseOffset,
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
187 AssumptionCache *AC, DominatorTree *DT);
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
188
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
189 bool isValueEqualInPotentialCycles(const Value *V1, const Value *V2);
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
190
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
191 void GetIndexDifference(SmallVectorImpl<VariableGEPIndex> &Dest,
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
192 const SmallVectorImpl<VariableGEPIndex> &Src);
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
193
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
194 AliasResult aliasGEP(const GEPOperator *V1, uint64_t V1Size,
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 const AAMDNodes &V1AAInfo, const Value *V2,
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
196 uint64_t V2Size, const AAMDNodes &V2AAInfo,
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
197 const Value *UnderlyingV1, const Value *UnderlyingV2);
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
198
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
199 AliasResult aliasPHI(const PHINode *PN, uint64_t PNSize,
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
200 const AAMDNodes &PNAAInfo, const Value *V2,
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
201 uint64_t V2Size, const AAMDNodes &V2AAInfo,
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
202 const Value *UnderV2);
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
203
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
204 AliasResult aliasSelect(const SelectInst *SI, uint64_t SISize,
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
205 const AAMDNodes &SIAAInfo, const Value *V2,
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
206 uint64_t V2Size, const AAMDNodes &V2AAInfo,
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
207 const Value *UnderV2);
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
208
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
209 AliasResult aliasCheck(const Value *V1, uint64_t V1Size, AAMDNodes V1AATag,
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
210 const Value *V2, uint64_t V2Size, AAMDNodes V2AATag,
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
211 const Value *O1 = nullptr, const Value *O2 = nullptr);
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
212 };
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
213
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
214 /// Analysis pass providing a never-invalidated alias analysis result.
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
215 class BasicAA : public AnalysisInfoMixin<BasicAA> {
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
216 friend AnalysisInfoMixin<BasicAA>;
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
217
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
218 static AnalysisKey Key;
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
219
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
220 public:
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
221 using Result = BasicAAResult;
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
222
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
223 BasicAAResult run(Function &F, FunctionAnalysisManager &AM);
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
224 };
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
225
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
226 /// Legacy wrapper pass to provide the BasicAAResult object.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
227 class BasicAAWrapperPass : public FunctionPass {
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
228 std::unique_ptr<BasicAAResult> Result;
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
229
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
230 virtual void anchor();
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
231
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
232 public:
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
233 static char ID;
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
234
100
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
235 BasicAAWrapperPass();
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
236
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
237 BasicAAResult &getResult() { return *Result; }
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
238 const BasicAAResult &getResult() const { return *Result; }
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
239
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
240 bool runOnFunction(Function &F) override;
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
241 void getAnalysisUsage(AnalysisUsage &AU) const override;
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
242 };
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
243
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
244 FunctionPass *createBasicAAWrapperPass();
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
245
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
246 /// A helper for the legacy pass manager to create a \c BasicAAResult object
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
247 /// populated to the best of our ability for a particular function when inside
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
248 /// of a \c ModulePass or a \c CallGraphSCCPass.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
249 BasicAAResult createLegacyPMBasicAAResult(Pass &P, Function &F);
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
250
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
251 /// This class is a functor to be used in legacy module or SCC passes for
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
252 /// computing AA results for a function. We store the results in fields so that
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
253 /// they live long enough to be queried, but we re-use them each time.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
254 class LegacyAARGetter {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
255 Pass &P;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
256 Optional<BasicAAResult> BAR;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
257 Optional<AAResults> AAR;
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
258
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
259 public:
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
260 LegacyAARGetter(Pass &P) : P(P) {}
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
261 AAResults &operator()(Function &F) {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
262 BAR.emplace(createLegacyPMBasicAAResult(P, F));
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
263 AAR.emplace(createLegacyPMAAResults(P, F, *BAR));
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
264 return *AAR;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
265 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
266 };
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
267
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
268 } // end namespace llvm
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
269
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
270 #endif // LLVM_ANALYSIS_BASICALIASANALYSIS_H