14 #define DEBUG_TYPE "flattencfg"
153 if (UnCondBlock || !PP || (Preds.count(PP) == 0) ||
166 if (!PC || !PC->hasOneUse())
169 if (PP && Preds.count(PP)) {
188 FirstCondBlock = Pred;
196 int CIdx = (PS1 == BB) ? 0 : 1;
200 else if (CIdx != Idx)
205 if (Preds.count(PS) == 0) {
207 LastCondBlock = Pred;
213 LastCondBlock = Pred;
218 if (!FirstCondBlock || !LastCondBlock || (FirstCondBlock == LastCondBlock))
232 if (!PBI2 || !PBI2->isUnconditional() ||
238 bool EverChanged =
false;
249 if (CurrBlock == FirstCondBlock)
268 bool Iteration =
true;
292 if (CB == LastCondBlock)
300 DEBUG(
dbgs() <<
"Use parallel and/or in:\n" << *FirstCondBlock);
317 bool eq1 = (Block1 == Head1);
318 bool eq2 = (Block2 == Head2);
338 if (!iter1->isIdenticalTo(iter2))
343 if (iter1->mayHaveSideEffects()) {
352 if (iter1->mayReadFromMemory())
355 if (iter1->mayWriteToMemory()) {
359 if (!AA || AA->alias(iter1, BI))
390 Instruction *CInst2 = dyn_cast_or_null<Instruction>(IfCond2);
400 Instruction *CInst1 = dyn_cast_or_null<Instruction>(IfCond1);
407 if ((IfTrue1 != FirstEntryBlock) && (IfFalse1 != FirstEntryBlock))
409 if ((IfTrue2 != SecondEntryBlock) && (IfFalse2 != SecondEntryBlock))
415 if (!CompareIfRegionBlock(FirstEntryBlock, SecondEntryBlock, IfTrue1,
419 if (!CompareIfRegionBlock(FirstEntryBlock, SecondEntryBlock, IfFalse1,
446 if (IfTrue1 != FirstEntryBlock) {
452 if (IfFalse1 != FirstEntryBlock) {
460 DEBUG(
dbgs() <<
"If conditions merged into:\n" << *FirstEntryBlock);
465 bool Changed =
false;
466 assert(BB && BB->
getParent() &&
"Block not embedded in function!");
467 assert(BB->
getTerminator() &&
"Degenerate basic block encountered!");
471 if (FlattenParallelAndOr(BB, Builder))
474 if (MergeIfRegion(BB, Builder))
485 return FlattenCFGOpt(AA).run(BB);
bool FlattenCFG(BasicBlock *BB, AliasAnalysis *AA=0)
Abstract base class of comparison instructions.
BasicBlock::iterator GetInsertPoint() const
void swapSuccessors()
Swap the successors of this branch instruction.
enable_if_c<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Predicate getInversePredicate() const
Return the inverse of the instruction's predicate.
bool mayHaveSideEffects() const
const Function * getParent() const
Return the enclosing method, or null if none.
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. to it.
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
bool mayReadFromMemory() const
Value * CreateOr(Value *LHS, Value *RHS, const Twine &Name="")
BasicBlock * getSuccessor(unsigned i) const
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)
LLVM Basic Block Representation.
BasicBlock * getSuccessor(unsigned idx) const
Interval::pred_iterator pred_begin(Interval *I)
const InstListType & getInstList() const
Return the underlying instruction list container.
Interval::pred_iterator pred_end(Interval *I)
bool mayWriteToMemory() const
bool isConditional() const
bool isSafeToSpeculativelyExecute(const Value *V, const DataLayout *TD=0)
SmallPtrSetIterator - This implements a const_iterator for SmallPtrSet.
void eraseFromParent()
Unlink 'this' from the containing function and delete it.
Value * GetIfCondition(BasicBlock *BB, BasicBlock *&IfTrue, BasicBlock *&IfFalse)
BasicBlock * GetInsertBlock() const
void splice(iterator where, iplist &L2)
raw_ostream & dbgs()
dbgs - Return a circular-buffered debug stream.
BasicBlock * getSinglePredecessor()
Return this block if it has a single predecessor block. Otherwise return a null pointer.
Value * getCondition() const
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.
const BasicBlock * getParent() const
void dropAllReferences()
Cause all subinstructions to "let go" of all the references that said subinstructions are maintaining...