40 void PhiValues::processPhi(
const PHINode *Phi,
43 assert(DepthMap.lookup(Phi) == 0);
44 assert(NextDepthNumber != UINT_MAX);
45 unsigned int DepthNumber = ++NextDepthNumber;
46 DepthMap[Phi] = DepthNumber;
50 if (
PHINode *PhiPhiOp = dyn_cast<PHINode>(PhiOp)) {
52 if (DepthMap.lookup(PhiPhiOp) == 0)
53 processPhi(PhiPhiOp, Stack);
54 assert(DepthMap.lookup(PhiPhiOp) != 0);
57 if (!ReachableMap.count(DepthMap[PhiPhiOp]))
58 DepthMap[Phi] = std::min(DepthMap[Phi], DepthMap[PhiPhiOp]);
67 if (DepthMap[Phi] == DepthNumber) {
72 while (!Stack.
empty() && DepthMap[Stack.
back()] >= DepthNumber) {
74 Reachable.
insert(ComponentPhi);
75 DepthMap[ComponentPhi] = DepthNumber;
77 if (
PHINode *PhiOp = dyn_cast<PHINode>(
Op)) {
82 auto It = ReachableMap.find(DepthMap[PhiOp]);
83 if (It != ReachableMap.end())
84 Reachable.
insert(It->second.begin(), It->second.end());
90 ReachableMap.insert({DepthNumber,Reachable});
94 for (
const Value *V : Reachable)
96 NonPhi.
insert(const_cast<Value*>(V));
97 NonPhiReachableMap.insert({DepthNumber,NonPhi});
102 if (DepthMap.count(PN) == 0) {
104 processPhi(PN, Stack);
107 assert(DepthMap.lookup(PN) != 0);
108 return NonPhiReachableMap[DepthMap[PN]];
114 for (
auto &Pair : ReachableMap)
115 if (Pair.second.count(V))
118 for (
unsigned int N : InvalidComponents) {
119 for (
const Value *V : ReachableMap[
N])
120 if (
const PHINode *PN = dyn_cast<PHINode>(V))
122 NonPhiReachableMap.erase(N);
123 ReachableMap.erase(N);
129 NonPhiReachableMap.clear();
130 ReachableMap.clear();
137 for (
const PHINode &PN : BB.phis()) {
139 PN.printAsOperand(OS,
false);
140 OS <<
" has values:\n";
141 unsigned int N = DepthMap.lookup(&PN);
142 auto It = NonPhiReachableMap.find(N);
143 if (It == NonPhiReachableMap.end())
145 else if (It->second.empty())
148 for (
Value *V : It->second)
155 OS <<
" " << *V <<
"\n";
167 OS <<
"PHI Values for function: " << F.
getName() <<
"\n";
170 for (
const PHINode &PN : BB.phis())
186 Result->releaseMemory();
void releaseMemory()
Free the memory used by this class.
void push_back(const T &Elt)
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.
Compute iterated dominance frontiers using a linear time algorithm.
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.