aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/CodeGenPrepare.cpp
diff options
context:
space:
mode:
authorKazu Hirata <kazu@google.com>2021-02-11 23:31:30 -0800
committerKazu Hirata <kazu@google.com>2021-02-11 23:31:31 -0800
commitd61b4cb9d8de946fd564707c2e4c32ce1d152eaf (patch)
treed937e45827521b4c7ad8a8dbb602e9396c5480d2 /llvm/lib/CodeGen/CodeGenPrepare.cpp
parent9dc62d1dc1479d4f831aebebe8a849061a5103a2 (diff)
downloadllvm-d61b4cb9d8de946fd564707c2e4c32ce1d152eaf.zip
llvm-d61b4cb9d8de946fd564707c2e4c32ce1d152eaf.tar.gz
llvm-d61b4cb9d8de946fd564707c2e4c32ce1d152eaf.tar.bz2
[CodeGen] Use range-based for loops (NFC)
Diffstat (limited to 'llvm/lib/CodeGen/CodeGenPrepare.cpp')
-rw-r--r--llvm/lib/CodeGen/CodeGenPrepare.cpp46
1 files changed, 19 insertions, 27 deletions
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index 492d3d0..6f9475d 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -566,10 +566,9 @@ bool CodeGenPrepare::runOnFunction(Function &F) {
MadeChange |= ConstantFoldTerminator(&BB, true);
if (!MadeChange) continue;
- for (SmallVectorImpl<BasicBlock*>::iterator
- II = Successors.begin(), IE = Successors.end(); II != IE; ++II)
- if (pred_empty(*II))
- WorkList.insert(*II);
+ for (BasicBlock *Succ : Successors)
+ if (pred_empty(Succ))
+ WorkList.insert(Succ);
}
// Delete the dead blocks and any of their dead successors.
@@ -580,10 +579,9 @@ bool CodeGenPrepare::runOnFunction(Function &F) {
DeleteDeadBlock(BB);
- for (SmallVectorImpl<BasicBlock*>::iterator
- II = Successors.begin(), IE = Successors.end(); II != IE; ++II)
- if (pred_empty(*II))
- WorkList.insert(*II);
+ for (BasicBlock *Succ : Successors)
+ if (pred_empty(Succ))
+ WorkList.insert(Succ);
}
// Merge pairs of basic blocks with unconditional branches, connected by
@@ -780,8 +778,8 @@ bool CodeGenPrepare::isMergingEmptyBlockProfitable(BasicBlock *BB,
// Skip merging if the block's successor is also a successor to any callbr
// that leads to this block.
// FIXME: Is this really needed? Is this a correctness issue?
- for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) {
- if (auto *CBI = dyn_cast<CallBrInst>((*PI)->getTerminator()))
+ for (BasicBlock *Pred : predecessors(BB)) {
+ if (auto *CBI = dyn_cast<CallBrInst>((Pred)->getTerminator()))
for (unsigned i = 0, e = CBI->getNumSuccessors(); i != e; ++i)
if (DestBB == CBI->getSuccessor(i))
return false;
@@ -822,9 +820,7 @@ bool CodeGenPrepare::isMergingEmptyBlockProfitable(BasicBlock *BB,
// Find all other incoming blocks from which incoming values of all PHIs in
// DestBB are the same as the ones from BB.
- for (pred_iterator PI = pred_begin(DestBB), E = pred_end(DestBB); PI != E;
- ++PI) {
- BasicBlock *DestBBPred = *PI;
+ for (BasicBlock *DestBBPred : predecessors(DestBB)) {
if (DestBBPred == BB)
continue;
@@ -964,8 +960,8 @@ void CodeGenPrepare::eliminateMostlyEmptyBlock(BasicBlock *BB) {
for (unsigned i = 0, e = BBPN->getNumIncomingValues(); i != e; ++i)
PN.addIncoming(InVal, BBPN->getIncomingBlock(i));
} else {
- for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI)
- PN.addIncoming(InVal, *PI);
+ for (BasicBlock *Pred : predecessors(BB))
+ PN.addIncoming(InVal, Pred);
}
}
}
@@ -2315,14 +2311,14 @@ bool CodeGenPrepare::dupRetToEnableTailCallOpts(BasicBlock *BB, bool &ModifiedDT
}
} else {
SmallPtrSet<BasicBlock*, 4> VisitedBBs;
- for (pred_iterator PI = pred_begin(BB), PE = pred_end(BB); PI != PE; ++PI) {
- if (!VisitedBBs.insert(*PI).second)
+ for (BasicBlock *Pred : predecessors(BB)) {
+ if (!VisitedBBs.insert(Pred).second)
continue;
- if (Instruction *I = (*PI)->rbegin()->getPrevNonDebugInstruction(true)) {
+ if (Instruction *I = Pred->rbegin()->getPrevNonDebugInstruction(true)) {
CallInst *CI = dyn_cast<CallInst>(I);
if (CI && CI->use_empty() && TLI->mayBeEmittedAsTailCall(CI) &&
attributesPermitTailCall(F, CI, RetI, *TLI))
- TailCallBBs.push_back(*PI);
+ TailCallBBs.push_back(Pred);
}
}
}
@@ -2837,11 +2833,8 @@ class TypePromotionTransaction {
/// Reassign the original uses of Inst to Inst.
void undo() override {
LLVM_DEBUG(dbgs() << "Undo: UsersReplacer: " << *Inst << "\n");
- for (use_iterator UseIt = OriginalUses.begin(),
- EndIt = OriginalUses.end();
- UseIt != EndIt; ++UseIt) {
- UseIt->Inst->setOperand(UseIt->Idx, Inst);
- }
+ for (InstructionAndIdx &Use : OriginalUses)
+ Use.Inst->setOperand(Use.Idx, Inst);
// RAUW has replaced all original uses with references to the new value,
// including the debug uses. Since we are undoing the replacements,
// the original debug uses must also be reinstated to maintain the
@@ -3020,9 +3013,8 @@ TypePromotionTransaction::getRestorationPoint() const {
}
bool TypePromotionTransaction::commit() {
- for (CommitPt It = Actions.begin(), EndIt = Actions.end(); It != EndIt;
- ++It)
- (*It)->commit();
+ for (std::unique_ptr<TypePromotionAction> &Action : Actions)
+ Action->commit();
bool Modified = !Actions.empty();
Actions.clear();
return Modified;