68#define DEBUG_TYPE "amdgpu-rewrite-undef-for-phi"
80 return "AMDGPU Rewrite Undef for PHI";
94char AMDGPURewriteUndefForPHI::ID = 0;
97 "Rewrite undef for PHI",
false,
false)
104 bool Changed =
false;
107 for (
auto &
PHI : BB.phis()) {
108 if (UA.isDivergent(&
PHI))
112 Value *UniqueDefinedIncoming =
nullptr;
119 for (
unsigned i = 0; i <
PHI.getNumIncomingValues(); i++) {
120 Value *Incoming =
PHI.getIncomingValue(i);
123 if (Incoming == &
PHI)
126 if (isa<UndefValue>(Incoming)) {
128 if (!DT->dominates(&BB, IncomingBB))
133 if (!UniqueDefinedIncoming) {
134 UniqueDefinedIncoming = Incoming;
135 DominateBB = IncomingBB;
136 }
else if (Incoming == UniqueDefinedIncoming) {
138 if (DT->dominates(IncomingBB, DominateBB))
139 DominateBB = IncomingBB;
141 UniqueDefinedIncoming =
nullptr;
149 if (!UniqueDefinedIncoming || Undefs.
empty() ||
158 return DT->dominates(DominateBB, UD);
160 PHI.replaceAllUsesWith(UniqueDefinedIncoming);
167 for (
auto *
PHI : ToBeDeleted)
168 PHI->eraseFromParent();
173bool AMDGPURewriteUndefForPHI::runOnFunction(
Function &
F) {
175 getAnalysis<UniformityInfoWrapperPass>().getUniformityInfo();
176 DominatorTree *DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
181 return new AMDGPURewriteUndefForPHI();
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...
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
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 if the block is well formed or null if the block is not well forme...
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.
virtual bool runOnFunction(Function &F)=0
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
virtual void getAnalysisUsage(AnalysisUsage &) const
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
LLVM Value Representation.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
This is an optimization pass for GlobalISel generic memory operations.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
void initializeAMDGPURewriteUndefForPHIPass(PassRegistry &)
FunctionPass * createAMDGPURewriteUndefForPHIPass()