[llvm] 87e53a0 - [llvm] Use make_early_inc_range (NFC)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 5 19:39:14 PDT 2021
Author: Kazu Hirata
Date: 2021-11-05T19:39:07-07:00
New Revision: 87e53a0ad8557162bc074e982df914beb9afa84d
URL: https://github.com/llvm/llvm-project/commit/87e53a0ad8557162bc074e982df914beb9afa84d
DIFF: https://github.com/llvm/llvm-project/commit/87e53a0ad8557162bc074e982df914beb9afa84d.diff
LOG: [llvm] Use make_early_inc_range (NFC)
Added:
Modified:
llvm/lib/Analysis/MemorySSAUpdater.cpp
llvm/lib/CodeGen/InlineSpiller.cpp
llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
llvm/lib/IR/DebugInfo.cpp
llvm/lib/IR/Value.cpp
llvm/lib/Linker/LinkModules.cpp
llvm/lib/Transforms/IPO/IROutliner.cpp
llvm/tools/bugpoint/CrashDebugger.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/MemorySSAUpdater.cpp b/llvm/lib/Analysis/MemorySSAUpdater.cpp
index d7ebe0e884e0..8de0adc0fd28 100644
--- a/llvm/lib/Analysis/MemorySSAUpdater.cpp
+++ b/llvm/lib/Analysis/MemorySSAUpdater.cpp
@@ -1135,11 +1135,7 @@ void MemorySSAUpdater::applyInsertUpdates(ArrayRef<CFGUpdate> Updates,
if (auto DefsList = MSSA->getWritableBlockDefs(BlockWithDefsToReplace)) {
for (auto &DefToReplaceUses : *DefsList) {
BasicBlock *DominatingBlock = DefToReplaceUses.getBlock();
- Value::use_iterator UI = DefToReplaceUses.use_begin(),
- E = DefToReplaceUses.use_end();
- for (; UI != E;) {
- Use &U = *UI;
- ++UI;
+ for (Use &U : llvm::make_early_inc_range(DefToReplaceUses.uses())) {
MemoryAccess *Usr = cast<MemoryAccess>(U.getUser());
if (MemoryPhi *UsrPhi = dyn_cast<MemoryPhi>(Usr)) {
BasicBlock *DominatedBlock = UsrPhi->getIncomingBlock(U);
diff --git a/llvm/lib/CodeGen/InlineSpiller.cpp b/llvm/lib/CodeGen/InlineSpiller.cpp
index 992b2e628742..5b84f8787c9e 100644
--- a/llvm/lib/CodeGen/InlineSpiller.cpp
+++ b/llvm/lib/CodeGen/InlineSpiller.cpp
@@ -341,9 +341,8 @@ void InlineSpiller::collectRegsToSpill() {
if (Original == Reg)
return;
- for (MachineRegisterInfo::reg_instr_iterator
- RI = MRI.reg_instr_begin(Reg), E = MRI.reg_instr_end(); RI != E; ) {
- MachineInstr &MI = *RI++;
+ for (MachineInstr &MI :
+ llvm::make_early_inc_range(MRI.reg_instructions(Reg))) {
Register SnipReg = isFullCopyOf(MI, Reg);
if (!isSibling(SnipReg))
continue;
diff --git a/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp b/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
index ee81f59b52b6..4d1449bc2751 100644
--- a/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
@@ -196,10 +196,8 @@ void FastISel::flushLocalValueMap() {
EmitStartPt ? MachineBasicBlock::reverse_iterator(EmitStartPt)
: FuncInfo.MBB->rend();
MachineBasicBlock::reverse_iterator RI(LastLocalValue);
- for (; RI != RE;) {
- MachineInstr &LocalMI = *RI;
- // Increment before erasing what it points to.
- ++RI;
+ for (MachineInstr &LocalMI :
+ llvm::make_early_inc_range(llvm::make_range(RI, RE))) {
Register DefReg = findLocalRegDef(LocalMI);
if (!DefReg)
continue;
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index af4e473aa12e..96673897d0e6 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -9819,21 +9819,20 @@ unsigned SelectionDAG::AssignTopologicalOrder() {
// before SortedPos will contain the topological sort index, and the
// Node Id fields for nodes At SortedPos and after will contain the
// count of outstanding operands.
- for (allnodes_iterator I = allnodes_begin(),E = allnodes_end(); I != E; ) {
- SDNode *N = &*I++;
- checkForCycles(N, this);
- unsigned Degree = N->getNumOperands();
+ for (SDNode &N : llvm::make_early_inc_range(allnodes())) {
+ checkForCycles(&N, this);
+ unsigned Degree = N.getNumOperands();
if (Degree == 0) {
// A node with no uses, add it to the result array immediately.
- N->setNodeId(DAGSize++);
- allnodes_iterator Q(N);
+ N.setNodeId(DAGSize++);
+ allnodes_iterator Q(&N);
if (Q != SortedPos)
SortedPos = AllNodes.insert(SortedPos, AllNodes.remove(Q));
assert(SortedPos != AllNodes.end() && "Overran node list");
++SortedPos;
} else {
// Temporarily use the Node Id as scratch space for the degree count.
- N->setNodeId(Degree);
+ N.setNodeId(Degree);
}
}
diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp
index 6e36400d8d67..7c69fbf7085d 100644
--- a/llvm/lib/IR/DebugInfo.cpp
+++ b/llvm/lib/IR/DebugInfo.cpp
@@ -447,8 +447,7 @@ bool llvm::stripDebugInfo(Function &F) {
DenseMap<MDNode *, MDNode *> LoopIDsMap;
for (BasicBlock &BB : F) {
- for (auto II = BB.begin(), End = BB.end(); II != End;) {
- Instruction &I = *II++; // We may delete the instruction, increment now.
+ for (Instruction &I : llvm::make_early_inc_range(BB)) {
if (isa<DbgInfoIntrinsic>(&I)) {
I.eraseFromParent();
Changed = true;
diff --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp
index 4136a9afc9cf..b475c8327874 100644
--- a/llvm/lib/IR/Value.cpp
+++ b/llvm/lib/IR/Value.cpp
@@ -546,9 +546,7 @@ void Value::replaceUsesWithIf(Value *New,
SmallVector<TrackingVH<Constant>, 8> Consts;
SmallPtrSet<Constant *, 8> Visited;
- for (use_iterator UI = use_begin(), E = use_end(); UI != E;) {
- Use &U = *UI;
- ++UI;
+ for (Use &U : llvm::make_early_inc_range(uses())) {
if (!ShouldReplace(U))
continue;
// Must handle Constants specially, we cannot call replaceUsesOfWith on a
diff --git a/llvm/lib/Linker/LinkModules.cpp b/llvm/lib/Linker/LinkModules.cpp
index 77e5c85cfc19..f9f51bf17d95 100644
--- a/llvm/lib/Linker/LinkModules.cpp
+++ b/llvm/lib/Linker/LinkModules.cpp
@@ -485,20 +485,14 @@ bool ModuleLinker::run() {
// Alias have to go first, since we are not able to find their comdats
// otherwise.
- for (auto I = DstM.alias_begin(), E = DstM.alias_end(); I != E;) {
- GlobalAlias &GV = *I++;
+ for (GlobalAlias &GV : llvm::make_early_inc_range(DstM.aliases()))
dropReplacedComdat(GV, ReplacedDstComdats);
- }
- for (auto I = DstM.global_begin(), E = DstM.global_end(); I != E;) {
- GlobalVariable &GV = *I++;
+ for (GlobalVariable &GV : llvm::make_early_inc_range(DstM.globals()))
dropReplacedComdat(GV, ReplacedDstComdats);
- }
- for (auto I = DstM.begin(), E = DstM.end(); I != E;) {
- Function &GV = *I++;
+ for (Function &GV : llvm::make_early_inc_range(DstM))
dropReplacedComdat(GV, ReplacedDstComdats);
- }
for (GlobalVariable &GV : SrcM->globals())
if (GV.hasLinkOnceLinkage())
diff --git a/llvm/lib/Transforms/IPO/IROutliner.cpp b/llvm/lib/Transforms/IPO/IROutliner.cpp
index 9eae08842cfa..bd3012c576dd 100644
--- a/llvm/lib/Transforms/IPO/IROutliner.cpp
+++ b/llvm/lib/Transforms/IPO/IROutliner.cpp
@@ -523,23 +523,20 @@ Function *IROutliner::createFunction(Module &M, OutlinableGroup &Group,
/// \param [out] NewEnds - The return blocks of the new overall function.
static void moveFunctionData(Function &Old, Function &New,
DenseMap<Value *, BasicBlock *> &NewEnds) {
- Function::iterator CurrBB, NextBB, FinalBB;
- for (CurrBB = Old.begin(), FinalBB = Old.end(); CurrBB != FinalBB;
- CurrBB = NextBB) {
- NextBB = std::next(CurrBB);
- CurrBB->removeFromParent();
- CurrBB->insertInto(&New);
- Instruction *I = CurrBB->getTerminator();
+ for (BasicBlock &CurrBB : llvm::make_early_inc_range(Old)) {
+ CurrBB.removeFromParent();
+ CurrBB.insertInto(&New);
+ Instruction *I = CurrBB.getTerminator();
// For each block we find a return instruction is, it is a potential exit
// path for the function. We keep track of each block based on the return
// value here.
if (ReturnInst *RI = dyn_cast<ReturnInst>(I))
- NewEnds.insert(std::make_pair(RI->getReturnValue(), &(*CurrBB)));
+ NewEnds.insert(std::make_pair(RI->getReturnValue(), &CurrBB));
std::vector<Instruction *> DebugInsts;
- for (Instruction &Val : *CurrBB) {
+ for (Instruction &Val : CurrBB) {
// We must handle the scoping of called functions
diff erently than
// other outlined instructions.
if (!isa<CallInst>(&Val)) {
diff --git a/llvm/tools/bugpoint/CrashDebugger.cpp b/llvm/tools/bugpoint/CrashDebugger.cpp
index 5a4528e9fa86..451e1cd98ee8 100644
--- a/llvm/tools/bugpoint/CrashDebugger.cpp
+++ b/llvm/tools/bugpoint/CrashDebugger.cpp
@@ -786,14 +786,13 @@ bool ReduceCrashingInstructions::TestInsts(
for (Module::iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI)
for (Function::iterator FI = MI->begin(), FE = MI->end(); FI != FE; ++FI)
- for (BasicBlock::iterator I = FI->begin(), E = FI->end(); I != E;) {
- Instruction *Inst = &*I++;
- if (!Instructions.count(Inst) && !Inst->isTerminator() &&
- !Inst->isEHPad() && !Inst->getType()->isTokenTy() &&
- !Inst->isSwiftError()) {
- if (!Inst->getType()->isVoidTy())
- Inst->replaceAllUsesWith(UndefValue::get(Inst->getType()));
- Inst->eraseFromParent();
+ for (Instruction &Inst : llvm::make_early_inc_range(*FI)) {
+ if (!Instructions.count(&Inst) && !Inst.isTerminator() &&
+ !Inst.isEHPad() && !Inst.getType()->isTokenTy() &&
+ !Inst.isSwiftError()) {
+ if (!Inst.getType()->isVoidTy())
+ Inst.replaceAllUsesWith(UndefValue::get(Inst.getType()));
+ Inst.eraseFromParent();
}
}
More information about the llvm-commits
mailing list