24 #define DEBUG_TYPE "flattencfg"
155 if (UnCondBlock || !PP || (Preds.count(PP) == 0) ||
168 if (!PC || !PC->hasOneUse())
171 if (PP && Preds.count(PP)) {
190 FirstCondBlock = Pred;
198 int CIdx = (PS1 == BB) ? 0 : 1;
202 else if (CIdx != Idx)
207 if (Preds.count(PS) == 0) {
209 LastCondBlock = Pred;
215 LastCondBlock = Pred;
220 if (!FirstCondBlock || !LastCondBlock || (FirstCondBlock == LastCondBlock))
234 if (!PBI2 || !PBI2->isUnconditional() ||
240 bool EverChanged =
false;
241 for (;CurrBlock != FirstCondBlock;
271 bool Iteration =
true;
295 if (CB == LastCondBlock)
303 DEBUG(
dbgs() <<
"Use parallel and/or in:\n" << *FirstCondBlock);
320 bool eq1 = (Block1 == Head1);
321 bool eq2 = (Block2 == Head2);
341 if (!iter1->isIdenticalTo(iter2))
346 if (iter1->mayHaveSideEffects()) {
355 if (iter1->mayReadFromMemory())
358 if (iter1->mayWriteToMemory()) {
362 if (!AA || AA->alias(iter1, BI))
393 Instruction *CInst2 = dyn_cast_or_null<Instruction>(IfCond2);
403 Instruction *CInst1 = dyn_cast_or_null<Instruction>(IfCond1);
410 if ((IfTrue1 != FirstEntryBlock) && (IfFalse1 != FirstEntryBlock))
412 if ((IfTrue2 != SecondEntryBlock) && (IfFalse2 != SecondEntryBlock))
418 if (!CompareIfRegionBlock(FirstEntryBlock, SecondEntryBlock, IfTrue1,
422 if (!CompareIfRegionBlock(FirstEntryBlock, SecondEntryBlock, IfFalse1,
449 if (IfTrue1 != FirstEntryBlock) {
455 if (IfFalse1 != FirstEntryBlock) {
463 DEBUG(
dbgs() <<
"If conditions merged into:\n" << *FirstEntryBlock);
468 bool Changed =
false;
469 assert(BB && BB->
getParent() &&
"Block not embedded in function!");
470 assert(BB->
getTerminator() &&
"Degenerate basic block encountered!");
474 if (FlattenParallelAndOr(BB, Builder))
477 if (MergeIfRegion(BB, Builder))
488 return FlattenCFGOpt(AA).run(BB);
Pass interface - Implemented by all 'passes'.
This class is the base class for the comparison instructions.
BasicBlock::iterator GetInsertPoint() const
bool isVolatile() const
isVolatile - 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
mayHaveSideEffects - Return true if the instruction may have side effects.
const Function * getParent() const
Return the enclosing method, or null if none.
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.
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
bool mayReadFromMemory() const
mayReadFromMemory - Return true if this instruction may read memory.
Value * CreateOr(Value *LHS, Value *RHS, const Twine &Name="")
BasicBlock * getSuccessor(unsigned i) const
StoreInst - an instruction for storing to memory.
bool FlattenCFG(BasicBlock *BB, AliasAnalysis *AA=nullptr)
FlatternCFG - 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.
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.
BranchInst - Conditional or Unconditional Branch instruction.
UnreachableInst - 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...
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)
bool mayWriteToMemory() const
mayWriteToMemory - Return true if this instruction may modify memory.
bool isConditional() const
SmallPtrSetIterator - This implements a const_iterator for SmallPtrSet.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
Value * GetIfCondition(BasicBlock *BB, BasicBlock *&IfTrue, BasicBlock *&IfFalse)
GetIfCondition - Check whether BB is the merge point of a if-region.
BasicBlock * GetInsertBlock() const
void splice(iterator where, iplist &L2)
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.
LLVM_ATTRIBUTE_UNUSED_RESULT std::enable_if< !is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Value * getCondition() const
iplist< 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
LLVMContext & getContext() const
Get the context in which this basic block lives.
LLVM Value Representation.
bool isSafeToSpeculativelyExecute(const Value *V, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, const TargetLibraryInfo *TLI=nullptr)
isSafeToSpeculativelyExecute - Return true if the instruction does not have any effects besides calcu...
const BasicBlock * getParent() const
void dropAllReferences()
Cause all subinstructions to "let go" of all the references that said subinstructions are maintaining...