38 #define DEBUG_TYPE "amdgpu-unify-divergent-exit-nodes"
42 class AMDGPUUnifyDivergentExitNodes :
public FunctionPass {
58 "Unify divergent function exit nodes",
false,
false)
66 void AMDGPUUnifyDivergentExitNodes::getAnalysisUsage(
AnalysisUsage &AU)
const{
95 while (!Stack.
empty()) {
101 if (Visited.
insert(Pred).second)
137 PN->addIncoming(BB->getTerminator()->getOperand(0), BB);
139 BB->getInstList().pop_back();
151 bool AMDGPUUnifyDivergentExitNodes::runOnFunction(
Function &
F) {
152 auto &PDT = getAnalysis<PostDominatorTreeWrapperPass>().getPostDomTree();
153 if (PDT.getRoots().size() <= 1)
165 if (isa<ReturnInst>(BB->getTerminator())) {
168 }
else if (isa<UnreachableInst>(BB->getTerminator())) {
174 if (!UnreachableBlocks.
empty()) {
177 if (UnreachableBlocks.
size() == 1) {
178 UnreachableBlock = UnreachableBlocks.
front();
181 "UnifiedUnreachableBlock", &
F);
185 BB->getInstList().pop_back();
190 if (!ReturningBlocks.empty()) {
209 ReturningBlocks.push_back(UnreachableBlock);
214 if (ReturningBlocks.empty())
217 if (ReturningBlocks.size() == 1)
221 = getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F);
void push_back(const T &Elt)
char & AMDGPUUnifyDivergentExitNodesID
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
INITIALIZE_PASS_BEGIN(AMDGPUUnifyDivergentExitNodes, DEBUG_TYPE,"Unify divergent function exit nodes", false, false) INITIALIZE_PASS_END(AMDGPUUnifyDivergentExitNodes
virtual void getAnalysisUsage(AnalysisUsage &) const
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
static ReturnInst * Create(LLVMContext &C, Value *retVal=nullptr, Instruction *InsertBefore=nullptr)
#define INITIALIZE_PASS_DEPENDENCY(depName)
LLVM_NODISCARD bool empty() const
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.
size_t size() const
size - Get the array size.
Type * getReturnType() const
Returns the type of the ret val.
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
char & BreakCriticalEdgesID
This function has undefined behavior.
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.
const InstListType & getInstList() const
Return the underlying instruction list container.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE,"Assign register bank of generic virtual registers", false, false) RegBankSelect
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.
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
static bool isUniformlyReached(const DivergenceAnalysis &DA, BasicBlock &BB)
bool isUniform(const Value *V) const
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
static BasicBlock * unifyReturnBlockSet(Function &F, ArrayRef< BasicBlock * > ReturningBlocks, const TargetTransformInfo &TTI, StringRef Name)
static CallInst * Create(Value *Func, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > Bundles=None, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
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)
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
pred_range predecessors(BasicBlock *BB)
void push_back(pointer val)
Unify divergent function exit false
iterator_range< typename GraphTraits< GraphType >::nodes_iterator > nodes(const GraphType &G)
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
print Print MemDeps of function
StringRef - Represent a constant reference to a string, i.e.
const TerminatorInst * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
void initializeAMDGPUUnifyDivergentExitNodesPass(PassRegistry &)
bool SimplifyCFG(BasicBlock *BB, const TargetTransformInfo &TTI, unsigned BonusInstThreshold, AssumptionCache *AC=nullptr, SmallPtrSetImpl< BasicBlock * > *LoopHeaders=nullptr, bool LateSimplifyCFG=false)
This function is used to do simplification of a CFG.
bool isVoidTy() const
Return true if this is 'void'.