16void PhiValues::PhiValuesCallbackVH::deleted() {
17 PV->invalidateValue(getValPtr());
20void PhiValues::PhiValuesCallbackVH::allUsesReplacedWith(
Value *) {
23 PV->invalidateValue(getValPtr());
49void PhiValues::processPhi(
const PHINode *Phi,
52 assert(DepthMap.lookup(Phi) == 0);
53 assert(NextDepthNumber != UINT_MAX);
54 unsigned int RootDepthNumber = ++NextDepthNumber;
55 DepthMap[Phi] = RootDepthNumber;
58 TrackedValues.insert(PhiValuesCallbackVH(
const_cast<PHINode *
>(Phi),
this));
59 for (
Value *PhiOp : Phi->incoming_values()) {
60 if (
PHINode *PhiPhiOp = dyn_cast<PHINode>(PhiOp)) {
62 unsigned int OpDepthNumber = DepthMap.lookup(PhiPhiOp);
63 if (OpDepthNumber == 0) {
64 processPhi(PhiPhiOp, Stack);
65 OpDepthNumber = DepthMap.lookup(PhiPhiOp);
66 assert(OpDepthNumber != 0);
70 if (!ReachableMap.count(OpDepthNumber)) {
71 unsigned &
Depth = DepthMap[Phi];
75 TrackedValues.insert(PhiValuesCallbackVH(PhiOp,
this));
84 if (DepthMap[Phi] == RootDepthNumber) {
88 ConstValueSet &Reachable = ReachableMap[RootDepthNumber];
91 Reachable.insert(ComponentPhi);
94 if (
PHINode *PhiOp = dyn_cast<PHINode>(
Op)) {
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);
106 Reachable.insert(
Op);
112 unsigned int &ComponentDepthNumber = DepthMap[
Stack.back()];
113 if (ComponentDepthNumber < RootDepthNumber)
116 ComponentDepthNumber = RootDepthNumber;
120 ValueSet &NonPhi = NonPhiReachableMap[RootDepthNumber];
121 for (
const Value *V : Reachable)
122 if (!isa<PHINode>(V))
123 NonPhi.insert(
const_cast<Value *
>(V));
128 unsigned int DepthNumber = DepthMap.lookup(PN);
129 if (DepthNumber == 0) {
131 processPhi(PN, Stack);
132 DepthNumber = DepthMap.lookup(PN);
136 return NonPhiReachableMap[DepthNumber];
142 for (
auto &Pair : ReachableMap)
143 if (Pair.second.count(V))
146 for (
unsigned int N : InvalidComponents) {
147 for (
const Value *V : ReachableMap[
N])
148 if (
const PHINode *PN = dyn_cast<PHINode>(V))
150 NonPhiReachableMap.erase(
N);
151 ReachableMap.erase(
N);
154 auto It = TrackedValues.find_as(V);
155 if (It != TrackedValues.end())
156 TrackedValues.erase(It);
161 NonPhiReachableMap.clear();
162 ReachableMap.clear();
169 for (
const PHINode &PN : BB.phis()) {
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())
177 else if (It->second.empty())
180 for (
Value *V : It->second)
187 OS <<
" " << *V <<
"\n";
199 OS <<
"PHI Values for function: " <<
F.getName() <<
"\n";
202 for (
const PHINode &PN : BB.phis())
216 Result->releaseMemory();
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This file defines the SmallVector class.
This templated class represents "all analyses that operate over <a particular IR unit>" (e....
API to communicate dependencies between analyses during invalidation.
A container for analyses that lazily runs them and caches their results.
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.
This class represents an Operation in the Expression.
FunctionPass class - This class is used to implement most global optimizations.
op_range incoming_values()
The analysis pass which yields a PhiValues.
LLVM_ABI PhiValues run(Function &F, FunctionAnalysisManager &)
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
Wrapper pass for the legacy pass manager.
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
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.
LLVM_ABI const ValueSet & getValuesForPhi(const PHINode *PN)
Get the underlying values of a phi.
SmallSetVector< Value *, 4 > ValueSet
LLVM_ABI bool invalidate(Function &, const PreservedAnalyses &, FunctionAnalysisManager::Invalidator &)
Handle invalidation events in the new pass manager.
LLVM_ABI void releaseMemory()
Free the memory used by this class.
LLVM_ABI void print(raw_ostream &OS) const
Print out the values currently in the cache.
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.
A SetVector that performs no allocations if smaller than a certain size.
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.
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.
A special type used by analysis passes to provide an address that identifies that particular analysis...