forked from OSchip/llvm-project
parent
c4acbae63f
commit
5781d840dd
|
@ -175,10 +175,9 @@ static bool SafeToMergeTerminators(TerminatorInst *SI1, TerminatorInst *SI2) {
|
|||
BasicBlock *SI2BB = SI2->getParent();
|
||||
SmallPtrSet<BasicBlock*, 16> SI1Succs(succ_begin(SI1BB), succ_end(SI1BB));
|
||||
|
||||
for (succ_iterator I = succ_begin(SI2BB), E = succ_end(SI2BB); I != E; ++I)
|
||||
if (SI1Succs.count(*I))
|
||||
for (BasicBlock::iterator BBI = (*I)->begin();
|
||||
isa<PHINode>(BBI); ++BBI) {
|
||||
for (BasicBlock *Succ : successors(SI2BB))
|
||||
if (SI1Succs.count(Succ))
|
||||
for (BasicBlock::iterator BBI = Succ->begin(); isa<PHINode>(BBI); ++BBI) {
|
||||
PHINode *PN = cast<PHINode>(BBI);
|
||||
if (PN->getIncomingValueForBlock(SI1BB) !=
|
||||
PN->getIncomingValueForBlock(SI2BB))
|
||||
|
@ -214,10 +213,9 @@ static bool isProfitableToFoldUnconditional(BranchInst *SI1,
|
|||
BasicBlock *SI1BB = SI1->getParent();
|
||||
BasicBlock *SI2BB = SI2->getParent();
|
||||
SmallPtrSet<BasicBlock*, 16> SI1Succs(succ_begin(SI1BB), succ_end(SI1BB));
|
||||
for (succ_iterator I = succ_begin(SI2BB), E = succ_end(SI2BB); I != E; ++I)
|
||||
if (SI1Succs.count(*I))
|
||||
for (BasicBlock::iterator BBI = (*I)->begin();
|
||||
isa<PHINode>(BBI); ++BBI) {
|
||||
for (BasicBlock *Succ : successors(SI2BB))
|
||||
if (SI1Succs.count(Succ))
|
||||
for (BasicBlock::iterator BBI = Succ->begin(); isa<PHINode>(BBI); ++BBI) {
|
||||
PHINode *PN = cast<PHINode>(BBI);
|
||||
if (PN->getIncomingValueForBlock(SI1BB) != Cond ||
|
||||
!isa<ConstantInt>(PN->getIncomingValueForBlock(SI2BB)))
|
||||
|
@ -236,8 +234,7 @@ static void AddPredecessorToBlock(BasicBlock *Succ, BasicBlock *NewPred,
|
|||
if (!isa<PHINode>(Succ->begin())) return; // Quick exit if nothing to do
|
||||
|
||||
PHINode *PN;
|
||||
for (BasicBlock::iterator I = Succ->begin();
|
||||
(PN = dyn_cast<PHINode>(I)); ++I)
|
||||
for (BasicBlock::iterator I = Succ->begin(); (PN = dyn_cast<PHINode>(I)); ++I)
|
||||
PN->addIncoming(PN->getIncomingValueForBlock(ExistPred), NewPred);
|
||||
}
|
||||
|
||||
|
@ -779,9 +776,9 @@ SimplifyEqualityComparisonWithOnlyPredecessor(TerminatorInst *TI,
|
|||
|
||||
// Remove PHI node entries for dead edges.
|
||||
BasicBlock *CheckEdge = TheRealDest;
|
||||
for (succ_iterator SI = succ_begin(TIBB), e = succ_end(TIBB); SI != e; ++SI)
|
||||
if (*SI != CheckEdge)
|
||||
(*SI)->removePredecessor(TIBB);
|
||||
for (BasicBlock *Succ : successors(TIBB))
|
||||
if (Succ != CheckEdge)
|
||||
Succ->removePredecessor(TIBB);
|
||||
else
|
||||
CheckEdge = nullptr;
|
||||
|
||||
|
@ -1073,9 +1070,9 @@ bool SimplifyCFGOpt::FoldValueComparisonIntoPredecessors(TerminatorInst *TI,
|
|||
// can't hoist the invoke, as there is nowhere to put the select in this case.
|
||||
static bool isSafeToHoistInvoke(BasicBlock *BB1, BasicBlock *BB2,
|
||||
Instruction *I1, Instruction *I2) {
|
||||
for (succ_iterator SI = succ_begin(BB1), E = succ_end(BB1); SI != E; ++SI) {
|
||||
for (BasicBlock *Succ : successors(BB1)) {
|
||||
PHINode *PN;
|
||||
for (BasicBlock::iterator BBI = SI->begin();
|
||||
for (BasicBlock::iterator BBI = Succ->begin();
|
||||
(PN = dyn_cast<PHINode>(BBI)); ++BBI) {
|
||||
Value *BB1V = PN->getIncomingValueForBlock(BB1);
|
||||
Value *BB2V = PN->getIncomingValueForBlock(BB2);
|
||||
|
@ -1168,9 +1165,9 @@ HoistTerminator:
|
|||
if (isa<InvokeInst>(I1) && !isSafeToHoistInvoke(BB1, BB2, I1, I2))
|
||||
return Changed;
|
||||
|
||||
for (succ_iterator SI = succ_begin(BB1), E = succ_end(BB1); SI != E; ++SI) {
|
||||
for (BasicBlock *Succ : successors(BB1)) {
|
||||
PHINode *PN;
|
||||
for (BasicBlock::iterator BBI = SI->begin();
|
||||
for (BasicBlock::iterator BBI = Succ->begin();
|
||||
(PN = dyn_cast<PHINode>(BBI)); ++BBI) {
|
||||
Value *BB1V = PN->getIncomingValueForBlock(BB1);
|
||||
Value *BB2V = PN->getIncomingValueForBlock(BB2);
|
||||
|
@ -1205,9 +1202,9 @@ HoistTerminator:
|
|||
// them. If they do, all PHI entries for BB1/BB2 must agree for all PHI
|
||||
// nodes, so we insert select instruction to compute the final result.
|
||||
std::map<std::pair<Value*,Value*>, SelectInst*> InsertedSelects;
|
||||
for (succ_iterator SI = succ_begin(BB1), E = succ_end(BB1); SI != E; ++SI) {
|
||||
for (BasicBlock *Succ : successors(BB1)) {
|
||||
PHINode *PN;
|
||||
for (BasicBlock::iterator BBI = SI->begin();
|
||||
for (BasicBlock::iterator BBI = Succ->begin();
|
||||
(PN = dyn_cast<PHINode>(BBI)); ++BBI) {
|
||||
Value *BB1V = PN->getIncomingValueForBlock(BB1);
|
||||
Value *BB2V = PN->getIncomingValueForBlock(BB2);
|
||||
|
@ -1229,8 +1226,8 @@ HoistTerminator:
|
|||
}
|
||||
|
||||
// Update any PHI nodes in our new successors.
|
||||
for (succ_iterator SI = succ_begin(BB1), E = succ_end(BB1); SI != E; ++SI)
|
||||
AddPredecessorToBlock(*SI, BIParent, BB1);
|
||||
for (BasicBlock *Succ : successors(BB1))
|
||||
AddPredecessorToBlock(Succ, BIParent, BB1);
|
||||
|
||||
EraseTerminatorInstAndDCECond(BI);
|
||||
return true;
|
||||
|
|
Loading…
Reference in New Issue