68#define DEBUG_TYPE "amdgpu-rewrite-undef-for-phi"
72class AMDGPURewriteUndefForPHILegacy :
public FunctionPass {
78 return "AMDGPU Rewrite Undef for PHI";
90char AMDGPURewriteUndefForPHILegacy::ID = 0;
93 "Rewrite undef for PHI",
false,
false)
103 for (
auto &
PHI : BB.phis()) {
104 if (UA.isDivergentAtDef(&
PHI))
108 Value *UniqueDefinedIncoming =
nullptr;
115 for (
unsigned i = 0; i <
PHI.getNumIncomingValues(); i++) {
116 Value *Incoming =
PHI.getIncomingValue(i);
119 if (Incoming == &
PHI)
124 if (!DT->dominates(&BB, IncomingBB))
129 if (!UniqueDefinedIncoming) {
130 UniqueDefinedIncoming = Incoming;
131 DominateBB = IncomingBB;
132 }
else if (Incoming == UniqueDefinedIncoming) {
134 if (DT->dominates(IncomingBB, DominateBB))
135 DominateBB = IncomingBB;
137 UniqueDefinedIncoming =
nullptr;
145 if (!UniqueDefinedIncoming || Undefs.
empty() ||
154 return DT->dominates(DominateBB, UD);
156 PHI.replaceAllUsesWith(UniqueDefinedIncoming);
163 for (
auto *
PHI : ToBeDeleted)
164 PHI->eraseFromParent();
169bool AMDGPURewriteUndefForPHILegacy::runOnFunction(
Function &
F) {
171 getAnalysis<UniformityInfoWrapperPass>().getUniformityInfo();
172 DominatorTree *DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
191 return new AMDGPURewriteUndefForPHILegacy();
Rewrite undef for false bool rewritePHIs(Function &F, UniformityInfo &UA, DominatorTree *DT)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static bool runOnFunction(Function &F, bool PostInlining)
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
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.
AnalysisUsage & addRequired()
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
LLVM Basic Block Representation.
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction; assumes that the block is well-formed.
Represents analyses that only rely on functions' control flow.
Analysis pass which computes a DominatorTree.
Legacy analysis pass which computes a DominatorTree.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
FunctionPass class - This class is used to implement most global optimizations.
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.
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
LLVM Value Representation.
This is an optimization pass for GlobalISel generic memory operations.
GenericUniformityInfo< SSAContext > UniformityInfo
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
FunctionPass * createAMDGPURewriteUndefForPHILegacyPass()
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.