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 DepthMap[Phi] = std::min(DepthMap[Phi], OpDepthNumber);
73 TrackedValues.insert(PhiValuesCallbackVH(PhiOp,
this));
82 if (DepthMap[Phi] == RootDepthNumber) {
86 ConstValueSet &Reachable = ReachableMap[RootDepthNumber];
89 Reachable.insert(ComponentPhi);
92 if (
PHINode *PhiOp = dyn_cast<PHINode>(
Op)) {
97 unsigned int OpDepthNumber = DepthMap[PhiOp];
98 if (OpDepthNumber != RootDepthNumber) {
99 auto It = ReachableMap.find(OpDepthNumber);
100 if (It != ReachableMap.end())
101 Reachable.insert(It->second.begin(), It->second.end());
104 Reachable.insert(
Op);
110 unsigned int &ComponentDepthNumber = DepthMap[
Stack.back()];
111 if (ComponentDepthNumber < RootDepthNumber)
114 ComponentDepthNumber = RootDepthNumber;
118 ValueSet &NonPhi = NonPhiReachableMap[RootDepthNumber];
119 for (
const Value *V : Reachable)
120 if (!isa<PHINode>(V))
121 NonPhi.insert(
const_cast<Value *
>(V));
126 unsigned int DepthNumber = DepthMap.lookup(PN);
127 if (DepthNumber == 0) {
129 processPhi(PN, Stack);
130 DepthNumber = DepthMap.lookup(PN);
134 return NonPhiReachableMap[DepthNumber];
140 for (
auto &Pair : ReachableMap)
141 if (Pair.second.count(V))
144 for (
unsigned int N : InvalidComponents) {
145 for (
const Value *V : ReachableMap[
N])
146 if (
const PHINode *PN = dyn_cast<PHINode>(V))
148 NonPhiReachableMap.erase(
N);
149 ReachableMap.erase(
N);
152 auto It = TrackedValues.find_as(V);
153 if (It != TrackedValues.end())
154 TrackedValues.erase(It);
159 NonPhiReachableMap.clear();
160 ReachableMap.clear();
167 for (
const PHINode &PN : BB.phis()) {
169 PN.printAsOperand(
OS,
false);
170 OS <<
" has values:\n";
171 unsigned int N = DepthMap.lookup(&PN);
172 auto It = NonPhiReachableMap.find(
N);
173 if (It == NonPhiReachableMap.end())
175 else if (It->second.empty())
178 for (
Value *V : It->second)
185 OS <<
" " << *V <<
"\n";
197 OS <<
"PHI Values for function: " <<
F.getName() <<
"\n";
200 for (
const PHINode &PN : BB.phis())
216 Result->releaseMemory();
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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()
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
The analysis pass which yields a PhiValues.
PhiValues run(Function &F, FunctionAnalysisManager &)
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.
void invalidateValue(const Value *V)
Notify PhiValues that the cached information using V is no longer valid.
const ValueSet & getValuesForPhi(const PHINode *PN)
Get the underlying values of a phi.
SmallSetVector< Value *, 4 > ValueSet
bool invalidate(Function &, const PreservedAnalyses &, FunctionAnalysisManager::Invalidator &)
Handle invalidation events in the new pass manager.
void releaseMemory()
Free the memory used by this class.
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.
void initializePhiValuesWrapperPassPass(PassRegistry &)
A special type used by analysis passes to provide an address that identifies that particular analysis...