24 #define DEBUG_TYPE "flattencfg"
153 if (UnCondBlock || !PP || (Preds.count(PP) == 0) ||
166 if (!PC || !PC->hasOneUse())
169 if (PP && Preds.count(PP)) {
189 FirstCondBlock = Pred;
197 int CIdx = (PS1 == BB) ? 0 : 1;
201 else if (CIdx != Idx)
206 if (Preds.count(PS) == 0) {
208 LastCondBlock = Pred;
214 LastCondBlock = Pred;
219 if (!FirstCondBlock || !LastCondBlock || (FirstCondBlock == LastCondBlock))
233 if (!PBI2 || !PBI2->isUnconditional() ||
239 bool EverChanged =
false;
240 for (;CurrBlock != FirstCondBlock;
270 bool Iteration =
true;
294 if (CB == LastCondBlock)
302 DEBUG(
dbgs() <<
"Use parallel and/or in:\n" << *FirstCondBlock);
319 bool eq1 = (Block1 == Head1);
320 bool eq2 = (Block2 == Head2);
340 if (!iter1->isIdenticalTo(&*iter2))
345 if (iter1->mayHaveSideEffects()) {
354 if (iter1->mayReadFromMemory())
357 if (iter1->mayWriteToMemory()) {
361 if (!AA || AA->alias(&*iter1, &*BI))
391 Instruction *CInst2 = dyn_cast_or_null<Instruction>(IfCond2);
401 Instruction *CInst1 = dyn_cast_or_null<Instruction>(IfCond1);
408 if ((IfTrue1 != FirstEntryBlock) && (IfFalse1 != FirstEntryBlock))
410 if ((IfTrue2 != SecondEntryBlock) && (IfFalse2 != SecondEntryBlock))
416 if (!CompareIfRegionBlock(FirstEntryBlock, SecondEntryBlock, IfTrue1,
420 if (!CompareIfRegionBlock(FirstEntryBlock, SecondEntryBlock, IfFalse1,
447 if (IfTrue1 != FirstEntryBlock) {
453 if (IfFalse1 != FirstEntryBlock) {
461 DEBUG(
dbgs() <<
"If conditions merged into:\n" << *FirstEntryBlock);
471 if (FlattenParallelAndOr(BB, Builder) || MergeIfRegion(BB, Builder))
481 return FlattenCFGOpt(AA).run(BB);
This class is the base class for the comparison instructions.
BasicBlock::iterator GetInsertPoint() const
bool isVolatile() const
Return true if this is a store to a volatile memory location.
void swapSuccessors()
Swap the successors of this branch instruction.
Predicate getInversePredicate() const
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
bool mayHaveSideEffects() const
Return true if the instruction may have side effects.
const Function * getParent() const
Return the enclosing method, or null if none.
const Instruction & front() const
iterator begin()
Instruction iterator methods.
bool isUnconditional() const
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
bool hasAddressTaken() const
Returns true if there are any uses of this basic block other than direct branches, switches, etc.
bool mayReadFromMemory() const
Return true if this instruction may read memory.
BasicBlock * getSuccessor(unsigned i) 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="")
Subclasses of this class are all able to terminate a basic block.
LLVM Basic Block Representation.
BasicBlock * getSuccessor(unsigned idx) const
Return the specified successor.
Conditional or Unconditional Branch instruction.
This function has undefined behavior.
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)
const InstListType & getInstList() const
Return the underlying instruction list container.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Interval::pred_iterator pred_end(Interval *I)
self_iterator getIterator()
bool mayWriteToMemory() const
Return true if this instruction may modify memory.
bool isConditional() const
SmallPtrSetIterator - This implements a const_iterator for SmallPtrSet.
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.
BasicBlock * GetInsertBlock() const
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
BasicBlock * getSinglePredecessor()
Return the predecessor of this block if it has a single predecessor block.
Value * getCondition() const
SymbolTableList< BasicBlock >::iterator eraseFromParent()
Unlink 'this' from the containing function and delete it.
TerminatorInst * getTerminator()
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
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)
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVMContext & getContext() const
Get the context in which this basic block lives.
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.
const BasicBlock * getParent() const
void dropAllReferences()
Cause all subinstructions to "let go" of all the references that said subinstructions are maintaining...