68#define DEBUG_TYPE "amdgpu-rewrite-undef-for-phi"
72class AMDGPURewriteUndefForPHILegacy :
public FunctionPass {
78 return "AMDGPU Rewrite Undef for PHI";
91char AMDGPURewriteUndefForPHILegacy::ID = 0;
94 "Rewrite undef for PHI",
false,
false)
101 bool Changed =
false;
104 for (
auto &
PHI : BB.phis()) {
105 if (UA.isDivergent(&
PHI))
109 Value *UniqueDefinedIncoming =
nullptr;
116 for (
unsigned i = 0; i <
PHI.getNumIncomingValues(); i++) {
130 if (!UniqueDefinedIncoming) {
132 DominateBB = IncomingBB;
133 }
else if (
Incoming == UniqueDefinedIncoming) {
135 if (DT->
dominates(IncomingBB, DominateBB))
136 DominateBB = IncomingBB;
138 UniqueDefinedIncoming =
nullptr;
146 if (!UniqueDefinedIncoming || Undefs.
empty() ||
157 PHI.replaceAllUsesWith(UniqueDefinedIncoming);
164 for (
auto *
PHI : ToBeDeleted)
165 PHI->eraseFromParent();
170bool AMDGPURewriteUndefForPHILegacy::runOnFunction(
Function &
F) {
172 getAnalysis<UniformityInfoWrapperPass>().getUniformityInfo();
173 DominatorTree *DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
192 return new AMDGPURewriteUndefForPHILegacy();
for(const MachineOperand &MO :llvm::drop_begin(OldMI.operands(), Desc.getNumOperands()))
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)
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
A container for analyses that lazily runs them and caches their results.
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()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
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 if the block is well formed or null if the block is not well forme...
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.
LLVM_ABI bool dominates(const BasicBlock *BB, const Use &U) const
Return true if the (end of the) basic block BB dominates the use U.
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.
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.
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.
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.
FunctionPass * createAMDGPURewriteUndefForPHILegacyPass()
Incoming for lane maks phi as machine instruction, incoming register Reg and incoming block Block are...