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