Changeset View
Changeset View
Standalone View
Standalone View
llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
Show First 20 Lines • Show All 5,650 Lines • ▼ Show 20 Lines | for (BasicBlock *OtherPred : predecessors(Succ)) { | ||||
return true; | return true; | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
bool SimplifyCFGOpt::SimplifyUncondBranch(BranchInst *BI, | bool SimplifyCFGOpt::SimplifyUncondBranch(BranchInst *BI, | ||||
IRBuilder<> &Builder) { | IRBuilder<> &Builder) { | ||||
BasicBlock *BB = BI->getParent(); | BasicBlock *BB = BI->getParent(); | ||||
BasicBlock *Succ = BI->getSuccessor(0); | |||||
if (SinkCommon && SinkThenElseCodeToEnd(BI)) | if (SinkCommon && SinkThenElseCodeToEnd(BI)) | ||||
return true; | return true; | ||||
// If the Terminator is the only non-phi instruction, simplify the block. | // If the Terminator is the only non-phi instruction, simplify the block. | ||||
// if LoopHeader is provided, check if the block is a loop header | // if LoopHeader is provided, check if the block or its successor is a loop | ||||
// (This is for early invocations before loop simplify and vectorization | // header (This is for early invocations before loop simplify and | ||||
// to keep canonical loop forms for nested loops. | // vectorization to keep canonical loop forms for nested loops. These blocks | ||||
// These blocks can be eliminated when the pass is invoked later | // can be eliminated when the pass is invoked later in the back-end.) | ||||
// in the back-end.) | bool NeedCanonicalLoop = | ||||
!LateSimplifyCFG && | |||||
(LoopHeaders && (LoopHeaders->count(BB) || LoopHeaders->count(Succ))); | |||||
BasicBlock::iterator I = BB->getFirstNonPHIOrDbg()->getIterator(); | BasicBlock::iterator I = BB->getFirstNonPHIOrDbg()->getIterator(); | ||||
if (I->isTerminator() && BB != &BB->getParent()->getEntryBlock() && | if (I->isTerminator() && BB != &BB->getParent()->getEntryBlock() && | ||||
(!LoopHeaders || !LoopHeaders->count(BB)) && | !NeedCanonicalLoop && TryToSimplifyUncondBranchFromEmptyBlock(BB)) | ||||
TryToSimplifyUncondBranchFromEmptyBlock(BB)) | |||||
return true; | return true; | ||||
// If the only instruction in the block is a seteq/setne comparison | // If the only instruction in the block is a seteq/setne comparison | ||||
// against a constant, try to simplify the block. | // against a constant, try to simplify the block. | ||||
if (ICmpInst *ICI = dyn_cast<ICmpInst>(I)) | if (ICmpInst *ICI = dyn_cast<ICmpInst>(I)) | ||||
if (ICI->isEquality() && isa<ConstantInt>(ICI->getOperand(1))) { | if (ICI->isEquality() && isa<ConstantInt>(ICI->getOperand(1))) { | ||||
for (++I; isa<DbgInfoIntrinsic>(I); ++I) | for (++I; isa<DbgInfoIntrinsic>(I); ++I) | ||||
; | ; | ||||
▲ Show 20 Lines • Show All 316 Lines • Show Last 20 Lines |