48 #define DEBUG_TYPE "amdgpu-unify-divergent-exit-nodes" 52 class AMDGPUUnifyDivergentExitNodes :
public FunctionPass {
72 "Unify divergent function exit nodes",
false,
false)
78 void AMDGPUUnifyDivergentExitNodes::getAnalysisUsage(
AnalysisUsage &AU)
const{
107 while (!Stack.
empty()) {
113 if (Visited.
insert(Pred).second)
126 if (Intrin->getIntrinsicID() == Intrinsic::amdgcn_exp) {
127 Intrin->setArgOperand(6, BoolFalse);
128 }
else if (Intrin->getIntrinsicID() == Intrinsic::amdgcn_exp_compr) {
129 Intrin->setArgOperand(4, BoolFalse);
154 B.CreateIntrinsic(Intrinsic::amdgcn_exp, { B.getFloatTy() },
181 PN->
addIncoming(BB->getTerminator()->getOperand(0), BB);
184 BB->getTerminator()->eraseFromParent();
197 auto &PDT = getAnalysis<PostDominatorTreeWrapperPass>().getPostDomTree();
198 if (PDT.getRoots().size() <= 1)
211 bool InsertExport =
false;
214 if (isa<ReturnInst>(BB->getTerminator())) {
216 ReturningBlocks.push_back(BB);
217 }
else if (isa<UnreachableInst>(BB->getTerminator())) {
220 }
else if (
BranchInst *BI = dyn_cast<BranchInst>(BB->getTerminator())) {
223 if (DummyReturnBB ==
nullptr) {
225 "DummyReturnBlock", &
F);
259 ReturningBlocks.push_back(DummyReturnBB);
262 if (BI->isUnconditional()) {
263 BasicBlock *LoopHeaderBB = BI->getSuccessor(0);
279 if (!UnreachableBlocks.
empty()) {
282 if (UnreachableBlocks.
size() == 1) {
283 UnreachableBlock = UnreachableBlocks.
front();
286 "UnifiedUnreachableBlock", &
F);
296 if (!ReturningBlocks.empty()) {
316 ReturningBlocks.push_back(UnreachableBlock);
321 if (ReturningBlocks.empty())
324 if (ReturningBlocks.size() == 1)
328 = getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F);
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
static ConstantInt * getFalse(LLVMContext &Context)
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
This class represents lattice values for constants.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
void push_back(const T &Elt)
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...
static ReturnInst * Create(LLVMContext &C, Value *retVal=nullptr, Instruction *InsertBefore=nullptr)
static bool isUniformlyReached(const LegacyDivergenceAnalysis &DA, BasicBlock &BB)
#define INITIALIZE_PASS_DEPENDENCY(depName)
virtual void getAnalysisUsage(AnalysisUsage &) const
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
static BasicBlock * unifyReturnBlockSet(Function &F, ArrayRef< BasicBlock *> ReturningBlocks, bool InsertExport, const TargetTransformInfo &TTI, StringRef Name)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Function * getDeclaration(Module *M, ID id, ArrayRef< Type *> Tys=None)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
bool isVoidTy() const
Return true if this is 'void'.
static bool runOnFunction(Function &F, bool PostInlining)
Type * getReturnType() const
Returns the type of the ret val.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
Conditional or Unconditional Branch instruction.
char & BreakCriticalEdgesID
size_t size() const
size - Get the array size.
This function has undefined behavior.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
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 BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
INITIALIZE_PASS_BEGIN(AMDGPUUnifyDivergentExitNodes, DEBUG_TYPE, "Unify divergent function exit nodes", false, false) INITIALIZE_PASS_END(AMDGPUUnifyDivergentExitNodes
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
This is the shared class of boolean and integer constants.
char & AMDGPUUnifyDivergentExitNodesID
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Calling convention used for Mesa/AMDPAL pixel shaders.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
LLVM_NODISCARD T pop_back_val()
static BranchInst * Create(BasicBlock *IfTrue, Instruction *InsertBefore=nullptr)
pred_range predecessors(BasicBlock *BB)
static ConstantInt * getTrue(LLVMContext &Context)
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
iterator_range< typename GraphTraits< GraphType >::nodes_iterator > nodes(const GraphType &G)
LLVM_NODISCARD bool empty() const
SymbolTableList< BasicBlock >::iterator eraseFromParent()
Unlink 'this' from the containing function and delete it.
BasicBlock * splitBasicBlock(iterator I, const Twine &BBName="")
Split the basic block into two basic blocks at the specified instruction.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
bool isUniform(const Value *V) const
print Print MemDeps of function
StringRef - Represent a constant reference to a string, i.e.
static void removeDoneExport(Function &F)
bool simplifyCFG(BasicBlock *BB, const TargetTransformInfo &TTI, const SimplifyCFGOptions &Options={}, SmallPtrSetImpl< BasicBlock *> *LoopHeaders=nullptr)
This function is used to do simplification of a CFG.
void initializeAMDGPUUnifyDivergentExitNodesPass(PassRegistry &)
A wrapper class for inspecting calls to intrinsic functions.