LLVM: lib/Analysis/PhiValues.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
13
14using namespace llvm;
15
16void PhiValues::PhiValuesCallbackVH::deleted() {
18}
19
20void PhiValues::PhiValuesCallbackVH::allUsesReplacedWith(Value *) {
21
22
23 PV->invalidateValue(getValPtr());
24}
25
27 FunctionAnalysisManager::Invalidator &) {
28
31}
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49void PhiValues::processPhi(const PHINode *Phi,
51
52 assert(DepthMap.lookup(Phi) == 0);
53 assert(NextDepthNumber != UINT_MAX);
54 unsigned int RootDepthNumber = ++NextDepthNumber;
55 DepthMap[Phi] = RootDepthNumber;
56
57
58 TrackedValues.insert(PhiValuesCallbackVH(const_cast<PHINode *>(Phi), this));
59 for (Value *PhiOp : Phi->incoming_values()) {
61
62 unsigned int OpDepthNumber = DepthMap.lookup(PhiPhiOp);
63 if (OpDepthNumber == 0) {
65 OpDepthNumber = DepthMap.lookup(PhiPhiOp);
66 assert(OpDepthNumber != 0);
67 }
68
69
70 if (!ReachableMap.count(OpDepthNumber)) {
71 unsigned &Depth = DepthMap[Phi];
72 Depth = std::min(Depth, OpDepthNumber);
73 }
74 } else {
75 TrackedValues.insert(PhiValuesCallbackVH(PhiOp, this));
76 }
77 }
78
79
80 Stack.push_back(Phi);
81
82
83
84 if (DepthMap[Phi] == RootDepthNumber) {
85
86
87
88 ConstValueSet &Reachable = ReachableMap[RootDepthNumber];
89 while (true) {
90 const PHINode *ComponentPhi = Stack.pop_back_val();
91 Reachable.insert(ComponentPhi);
92
95
96
97
98
99 unsigned int OpDepthNumber = DepthMap[PhiOp];
100 if (OpDepthNumber != RootDepthNumber) {
101 auto It = ReachableMap.find(OpDepthNumber);
102 if (It != ReachableMap.end())
103 Reachable.insert_range(It->second);
104 }
105 } else
106 Reachable.insert(Op);
107 }
108
109 if (Stack.empty())
110 break;
111
112 unsigned int &ComponentDepthNumber = DepthMap[Stack.back()];
113 if (ComponentDepthNumber < RootDepthNumber)
114 break;
115
116 ComponentDepthNumber = RootDepthNumber;
117 }
118
119
120 ValueSet &NonPhi = NonPhiReachableMap[RootDepthNumber];
121 for (const Value *V : Reachable)
123 NonPhi.insert(const_cast<Value *>(V));
124 }
125}
126
128 unsigned int DepthNumber = DepthMap.lookup(PN);
129 if (DepthNumber == 0) {
131 processPhi(PN, Stack);
132 DepthNumber = DepthMap.lookup(PN);
133 assert(Stack.empty());
134 assert(DepthNumber != 0);
135 }
136 return NonPhiReachableMap[DepthNumber];
137}
138
140
142 for (auto &Pair : ReachableMap)
143 if (Pair.second.count(V))
144 InvalidComponents.push_back(Pair.first);
145
146 for (unsigned int N : InvalidComponents) {
147 for (const Value *V : ReachableMap[N])
149 DepthMap.erase(PN);
150 NonPhiReachableMap.erase(N);
151 ReachableMap.erase(N);
152 }
153
154 auto It = TrackedValues.find_as(V);
155 if (It != TrackedValues.end())
156 TrackedValues.erase(It);
157}
158
160 DepthMap.clear();
161 NonPhiReachableMap.clear();
162 ReachableMap.clear();
163}
164
166
167
169 for (const PHINode &PN : BB.phis()) {
170 OS << "PHI ";
171 PN.printAsOperand(OS, false);
172 OS << " has values:\n";
173 unsigned int N = DepthMap.lookup(&PN);
174 auto It = NonPhiReachableMap.find(N);
175 if (It == NonPhiReachableMap.end())
176 OS << " UNKNOWN\n";
177 else if (It->second.empty())
178 OS << " NONE\n";
179 else
180 for (Value *V : It->second)
181
182
183
185 OS << *I << "\n";
186 else
187 OS << " " << *V << "\n";
188 }
189 }
190}
191
196
199 OS << "PHI Values for function: " << F.getName() << "\n";
202 for (const PHINode &PN : BB.phis())
206}
207
209
214
216 Result->releaseMemory();
217}
218
222
224
226 true)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static bool processPhi(PHINode &Phi, const TargetLibraryInfo &TLI, AliasAnalysis &AA, DomTreeUpdater &DTU)
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This file defines the SmallVector class.
This templated class represents "all analyses that operate over " (e....
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represent the analysis usage information of a pass.
void setPreservesAll()
Set by analyses that do not transform their input at all.
LLVM Basic Block Representation.
op_range incoming_values()
The analysis pass which yields a PhiValues.
LLVM_ABI PhiValues run(Function &F, FunctionAnalysisManager &)
Definition PhiValues.cpp:193
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
Definition PhiValues.cpp:197
Wrapper pass for the legacy pass manager.
PhiValuesWrapperPass()
Definition PhiValues.cpp:208
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
Definition PhiValues.cpp:215
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass.
Definition PhiValues.cpp:210
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Definition PhiValues.cpp:219
Class for calculating and caching the underlying values of phis in a function.
LLVM_ABI void invalidateValue(const Value *V)
Notify PhiValues that the cached information using V is no longer valid.
Definition PhiValues.cpp:139
LLVM_ABI const ValueSet & getValuesForPhi(const PHINode *PN)
Get the underlying values of a phi.
Definition PhiValues.cpp:127
SmallSetVector< Value *, 4 > ValueSet
LLVM_ABI bool invalidate(Function &, const PreservedAnalyses &, FunctionAnalysisManager::Invalidator &)
Handle invalidation events in the new pass manager.
Definition PhiValues.cpp:26
LLVM_ABI void releaseMemory()
Free the memory used by this class.
Definition PhiValues.cpp:159
LLVM_ABI void print(raw_ostream &OS) const
Print out the values currently in the cache.
Definition PhiValues.cpp:165
PhiValues(const Function &F)
Construct an empty PhiValues.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalysisChecker getChecker() const
Build a checker for this PreservedAnalyses and the specified analysis type.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Value * getValPtr() const
LLVM Value Representation.
This class implements an extremely fast bulk output stream that can only output to a stream.
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr Value
decltype(auto) dyn_cast(const From &Val)
dyn_cast - Return the argument parameter cast to the specified type.
bool isa(const From &Val)
isa - Return true if the parameter to the template is an instance of one of the template type argu...
DWARFExpression::Operation Op
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
A special type used by analysis passes to provide an address that identifies that particular analysis...