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 DepthNumber = ++NextDepthNumber;
56 DepthMap[Phi] = DepthNumber;
59 TrackedValues.insert(PhiValuesCallbackVH(const_cast<PHINode *>(Phi),
this));
61 if (
PHINode *PhiPhiOp = dyn_cast<PHINode>(PhiOp)) {
63 if (DepthMap.lookup(PhiPhiOp) == 0)
64 processPhi(PhiPhiOp, Stack);
65 assert(DepthMap.lookup(PhiPhiOp) != 0);
68 if (!ReachableMap.count(DepthMap[PhiPhiOp]))
69 DepthMap[Phi] = std::min(DepthMap[Phi], DepthMap[PhiPhiOp]);
71 TrackedValues.insert(PhiValuesCallbackVH(PhiOp,
this));
80 if (DepthMap[Phi] == DepthNumber) {
85 while (!Stack.
empty() && DepthMap[Stack.
back()] >= DepthNumber) {
87 Reachable.
insert(ComponentPhi);
88 DepthMap[ComponentPhi] = DepthNumber;
90 if (
PHINode *PhiOp = dyn_cast<PHINode>(
Op)) {
95 auto It = ReachableMap.find(DepthMap[PhiOp]);
96 if (It != ReachableMap.end())
97 Reachable.
insert(It->second.begin(), It->second.end());
103 ReachableMap.insert({DepthNumber,Reachable});
107 for (
const Value *V : Reachable)
108 if (!isa<PHINode>(V))
109 NonPhi.
insert(const_cast<Value*>(V));
110 NonPhiReachableMap.insert({DepthNumber,NonPhi});
115 if (DepthMap.count(PN) == 0) {
117 processPhi(PN, Stack);
120 assert(DepthMap.lookup(PN) != 0);
121 return NonPhiReachableMap[DepthMap[PN]];
127 for (
auto &Pair : ReachableMap)
128 if (Pair.second.count(V))
131 for (
unsigned int N : InvalidComponents) {
132 for (
const Value *V : ReachableMap[
N])
133 if (
const PHINode *PN = dyn_cast<PHINode>(V))
135 NonPhiReachableMap.erase(N);
136 ReachableMap.erase(N);
139 auto It = TrackedValues.find_as(V);
140 if (It != TrackedValues.end())
141 TrackedValues.erase(It);
146 NonPhiReachableMap.clear();
147 ReachableMap.clear();
154 for (
const PHINode &PN : BB.phis()) {
156 PN.printAsOperand(OS,
false);
157 OS <<
" has values:\n";
158 unsigned int N = DepthMap.lookup(&PN);
159 auto It = NonPhiReachableMap.find(N);
160 if (It == NonPhiReachableMap.end())
162 else if (It->second.empty())
165 for (
Value *V : It->second)
172 OS <<
" " << *V <<
"\n";
184 OS <<
"PHI Values for function: " << F.
getName() <<
"\n";
187 for (
const PHINode &PN : BB.phis())
203 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.
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.