17 void PhiValues::PhiValuesCallbackVH::deleted() {
18 PV->invalidateValue(getValPtr());
21 void PhiValues::PhiValuesCallbackVH::allUsesReplacedWith(
Value *) {
24 PV->invalidateValue(getValPtr());
50 void PhiValues::processPhi(
const PHINode *Phi,
53 assert(DepthMap.lookup(Phi) == 0);
54 assert(NextDepthNumber != UINT_MAX);
55 unsigned int RootDepthNumber = ++NextDepthNumber;
56 DepthMap[Phi] = RootDepthNumber;
59 TrackedValues.insert(PhiValuesCallbackVH(const_cast<PHINode *>(Phi),
this));
61 if (
PHINode *PhiPhiOp = dyn_cast<PHINode>(PhiOp)) {
63 unsigned int OpDepthNumber = DepthMap.lookup(PhiPhiOp);
64 if (OpDepthNumber == 0) {
65 processPhi(PhiPhiOp, Stack);
66 OpDepthNumber = DepthMap.lookup(PhiPhiOp);
67 assert(OpDepthNumber != 0);
71 if (!ReachableMap.count(OpDepthNumber))
72 DepthMap[Phi] = std::min(DepthMap[Phi], OpDepthNumber);
74 TrackedValues.insert(PhiValuesCallbackVH(PhiOp,
this));
83 if (DepthMap[Phi] == RootDepthNumber) {
90 Reachable.
insert(ComponentPhi);
93 if (
PHINode *PhiOp = dyn_cast<PHINode>(
Op)) {
98 unsigned int OpDepthNumber = DepthMap[PhiOp];
99 if (OpDepthNumber != RootDepthNumber) {
100 auto It = ReachableMap.find(OpDepthNumber);
101 if (It != ReachableMap.end())
102 Reachable.
insert(It->second.begin(), It->second.end());
111 unsigned int &ComponentDepthNumber = DepthMap[Stack.
back()];
112 if (ComponentDepthNumber < RootDepthNumber)
115 ComponentDepthNumber = RootDepthNumber;
119 ValueSet &NonPhi = NonPhiReachableMap[RootDepthNumber];
120 for (
const Value *V : Reachable)
121 if (!isa<PHINode>(V))
122 NonPhi.
insert(const_cast<Value *>(V));
127 unsigned int DepthNumber = DepthMap.lookup(PN);
128 if (DepthNumber == 0) {
130 processPhi(PN, Stack);
131 DepthNumber = DepthMap.lookup(PN);
135 return NonPhiReachableMap[DepthNumber];
141 for (
auto &Pair : ReachableMap)
142 if (Pair.second.count(V))
145 for (
unsigned int N : InvalidComponents) {
146 for (
const Value *V : ReachableMap[
N])
147 if (
const PHINode *PN = dyn_cast<PHINode>(V))
149 NonPhiReachableMap.erase(N);
150 ReachableMap.erase(N);
153 auto It = TrackedValues.find_as(V);
154 if (It != TrackedValues.end())
155 TrackedValues.erase(It);
160 NonPhiReachableMap.clear();
161 ReachableMap.clear();
168 for (
const PHINode &PN : BB.phis()) {
170 PN.printAsOperand(OS,
false);
171 OS <<
" has values:\n";
172 unsigned int N = DepthMap.lookup(&PN);
173 auto It = NonPhiReachableMap.find(N);
174 if (It == NonPhiReachableMap.end())
176 else if (It->second.empty())
179 for (
Value *V : It->second)
186 OS <<
" " << *V <<
"\n";
198 OS <<
"PHI Values for function: " << F.
getName() <<
"\n";
201 for (
const PHINode &PN : BB.phis())
217 Result->releaseMemory();
void releaseMemory()
Free the memory used by this class.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
This class represents lattice values for constants.
void push_back(const T &Elt)
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
const ValueSet & getValuesForPhi(const PHINode *PN)
Get the underlying values of a phi.
The analysis pass which yields a PhiValues.
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...
Wrapper pass for the legacy pass manager.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
bool invalidate(Function &, const PreservedAnalyses &, FunctionAnalysisManager::Invalidator &)
Handle invalidation events in the new pass manager.
A set of analyses that are preserved following a run of a transformation pass.
LLVM Basic Block Representation.
void invalidateValue(const Value *V)
Notify PhiValues that the cached information using V is no longer valid.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Represent the analysis usage information of a pass.
FunctionPass class - This class is used to implement most global optimizations.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
PhiValues run(Function &F, FunctionAnalysisManager &)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass...
LLVM_NODISCARD T pop_back_val()
void setPreservesAll()
Set by analyses that do not transform their input at all.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
void print(raw_ostream &OS) const
Print out the values currently in the cache.
LLVM_NODISCARD bool empty() const
StringRef getName() const
Return a constant reference to the value's name.
Class for calculating and caching the underlying values of phis in a function.
API to communicate dependencies between analyses during invalidation.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This templated class represents "all analyses that operate over <a particular IR unit>" (e...
LLVM Value Representation.
void initializePhiValuesWrapperPassPass(PassRegistry &)
This class implements an extremely fast bulk output stream that can only output to a stream...
A container for analyses that lazily runs them and caches their results.
op_range incoming_values()
A special type used by analysis passes to provide an address that identifies that particular analysis...
PhiValues(const Function &F)
Construct an empty PhiValues.