32 #define DEBUG_TYPE "flattencfg" 166 if (UnCondBlock || !PP || (Preds.
count(PP) == 0) ||
179 if (!PC || !PC->hasOneUse())
182 if (PP && Preds.
count(PP)) {
202 FirstCondBlock = Pred;
210 int CIdx = (PS1 == BB) ? 0 : 1;
214 else if (CIdx != Idx)
219 if (Preds.
count(PS) == 0) {
221 LastCondBlock = Pred;
227 LastCondBlock = Pred;
232 if (!FirstCondBlock || !LastCondBlock || (FirstCondBlock == LastCondBlock))
246 if (!PBI2 || !PBI2->isUnconditional() ||
252 bool EverChanged =
false;
253 for (; CurrBlock != FirstCondBlock;
283 bool Iteration =
true;
307 if (CB == LastCondBlock)
315 LLVM_DEBUG(
dbgs() <<
"Use parallel and/or in:\n" << *FirstCondBlock);
331 bool eq1 = (Block1 == Head1);
332 bool eq2 = (Block2 == Head2);
352 if (!iter1->isIdenticalTo(&*iter2))
357 if (iter1->mayHaveSideEffects()) {
366 if (iter1->mayReadFromMemory())
369 if (iter1->mayWriteToMemory()) {
371 if (BI->mayReadFromMemory() || BI->mayWriteToMemory()) {
373 if (!AA || AA->alias(&*iter1, &*BI))
402 Instruction *CInst2 = dyn_cast_or_null<Instruction>(IfCond2);
412 Instruction *CInst1 = dyn_cast_or_null<Instruction>(IfCond1);
419 if ((IfTrue1 != FirstEntryBlock) && (IfFalse1 != FirstEntryBlock))
421 if ((IfTrue2 != SecondEntryBlock) && (IfFalse2 != SecondEntryBlock))
427 if (!CompareIfRegionBlock(FirstEntryBlock, SecondEntryBlock, IfTrue1,
431 if (!CompareIfRegionBlock(FirstEntryBlock, SecondEntryBlock, IfFalse1,
458 if (IfTrue1 != FirstEntryBlock) {
464 if (IfFalse1 != FirstEntryBlock) {
472 LLVM_DEBUG(
dbgs() <<
"If conditions merged into:\n" << *FirstEntryBlock);
482 if (FlattenParallelAndOr(BB, Builder) || MergeIfRegion(BB, Builder))
491 return FlattenCFGOpt(AA).run(BB);
This class is the base class for the comparison instructions.
This class represents lattice values for constants.
void swapSuccessors()
Swap the successors of this branch instruction.
BasicBlock * getSuccessor(unsigned Idx) const
Return the specified successor. This instruction must be a terminator.
BasicBlock * getSuccessor(unsigned i) const
Value * getCondition() const
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...
LLVMContext & getContext() const
Get the context in which this basic block lives.
iterator begin()
Instruction iterator methods.
Predicate getInversePredicate() const
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
BasicBlock * GetInsertBlock() const
An instruction for storing to memory.
bool FlattenCFG(BasicBlock *BB, AliasAnalysis *AA=nullptr)
This function is used to flatten a CFG.
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block...
void replaceUsesOfWith(Value *From, Value *To)
Replace uses of one Value with another.
Value * CreateOr(Value *LHS, Value *RHS, const Twine &Name="")
const BasicBlock * getSinglePredecessor() const
Return the predecessor of this block if it has a single predecessor block.
LLVM Basic Block Representation.
Conditional or Unconditional Branch instruction.
This function has undefined behavior.
const Instruction & front() const
bool mayHaveSideEffects() const
Return true if the instruction may have side effects.
Interval::pred_iterator pred_begin(Interval *I)
pred_begin/pred_end - define methods so that Intervals may be used just like BasicBlocks can with the...
void splice(iterator where, iplist_impl &L2)
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Interval::pred_iterator pred_end(Interval *I)
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
self_iterator getIterator()
SmallPtrSetIterator - This implements a const_iterator for SmallPtrSet.
bool hasAddressTaken() const
Returns true if there are any uses of this basic block other than direct branches, switches, etc.
const InstListType & getInstList() const
Return the underlying instruction list container.
Iterator for intrusive lists based on ilist_node.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
Value * GetIfCondition(BasicBlock *BB, BasicBlock *&IfTrue, BasicBlock *&IfFalse)
Check whether BB is the merge point of a if-region.
bool isConditional() const
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool isVolatile() const
Return true if this is a store to a volatile memory location.
const Function * getParent() const
Return the enclosing method, or null if none.
SymbolTableList< BasicBlock >::iterator eraseFromParent()
Unlink 'this' from the containing function and delete it.
0 1 1 0 True if ordered and operands are unequal
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
bool isUnconditional() const
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool isSafeToSpeculativelyExecute(const Value *V, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr)
Return true if the instruction does not have any effects besides calculating the result and does not ...
LLVM Value Representation.
BasicBlock::iterator GetInsertPoint() const
void dropAllReferences()
Cause all subinstructions to "let go" of all the references that said subinstructions are maintaining...
const BasicBlock * getParent() const