[llvm] 7787a8f - [llvm] Use llvm::reverse (NFC)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 13 21:55:01 PST 2021
Author: Kazu Hirata
Date: 2021-12-13T21:54:51-08:00
New Revision: 7787a8f1b7077d9efb53f5023fe044b70ad527b4
URL: https://github.com/llvm/llvm-project/commit/7787a8f1b7077d9efb53f5023fe044b70ad527b4
DIFF: https://github.com/llvm/llvm-project/commit/7787a8f1b7077d9efb53f5023fe044b70ad527b4.diff
LOG: [llvm] Use llvm::reverse (NFC)
Added:
Modified:
llvm/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
llvm/lib/Transforms/AggressiveInstCombine/TruncInstCombine.cpp
llvm/lib/Transforms/Scalar/ConstantHoisting.cpp
llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
llvm/lib/Transforms/Scalar/LoopRerollPass.cpp
llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
llvm/tools/llvm-mca/Views/BottleneckAnalysis.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 993cb1de8c02c..7df4788116960 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -6733,10 +6733,10 @@ llvm::getBitcodeFileContents(MemoryBufferRef Buffer) {
// not have its own string table. A bitcode file may have multiple
// string tables if it was created by binary concatenation, for example
// with "llvm-cat -b".
- for (auto I = F.Mods.rbegin(), E = F.Mods.rend(); I != E; ++I) {
- if (!I->Strtab.empty())
+ for (BitcodeModule &I : llvm::reverse(F.Mods)) {
+ if (!I.Strtab.empty())
break;
- I->Strtab = *Strtab;
+ I.Strtab = *Strtab;
}
// Similarly, the string table is used by every preceding symbol table;
// normally there will be just one unless the bitcode file was created
diff --git a/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp b/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
index 711d32c88f583..df4f1a1873d7b 100644
--- a/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
+++ b/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
@@ -310,8 +310,7 @@ static UseListOrderStack predictUseListOrder(const Module &M) {
// We want to visit the functions backward now so we can list function-local
// constants in the last Function they're used in. Module-level constants
// have already been visited above.
- for (auto I = M.rbegin(), E = M.rend(); I != E; ++I) {
- const Function &F = *I;
+ for (const Function &F : llvm::reverse(M)) {
if (F.isDeclaration())
continue;
for (const BasicBlock &BB : F)
diff --git a/llvm/lib/Transforms/AggressiveInstCombine/TruncInstCombine.cpp b/llvm/lib/Transforms/AggressiveInstCombine/TruncInstCombine.cpp
index abac3f801a22f..4624b735bef8c 100644
--- a/llvm/lib/Transforms/AggressiveInstCombine/TruncInstCombine.cpp
+++ b/llvm/lib/Transforms/AggressiveInstCombine/TruncInstCombine.cpp
@@ -475,12 +475,12 @@ void TruncInstCombine::ReduceExpressionDag(Type *SclTy) {
// any of its operands, this way, when we get to the operand, we already
// removed the instructions (from the expression dag) that uses it.
CurrentTruncInst->eraseFromParent();
- for (auto I = InstInfoMap.rbegin(), E = InstInfoMap.rend(); I != E; ++I) {
+ for (auto &I : llvm::reverse(InstInfoMap)) {
// We still need to check that the instruction has no users before we erase
// it, because {SExt, ZExt}Inst Instruction might have other users that was
// not reduced, in such case, we need to keep that instruction.
- if (I->first->use_empty())
- I->first->eraseFromParent();
+ if (I.first->use_empty())
+ I.first->eraseFromParent();
}
}
diff --git a/llvm/lib/Transforms/Scalar/ConstantHoisting.cpp b/llvm/lib/Transforms/Scalar/ConstantHoisting.cpp
index 27f54f8026e12..37a7053d778e0 100644
--- a/llvm/lib/Transforms/Scalar/ConstantHoisting.cpp
+++ b/llvm/lib/Transforms/Scalar/ConstantHoisting.cpp
@@ -271,8 +271,7 @@ static void findBestInsertionSet(DominatorTree &DT, BlockFrequencyInfo &BFI,
// subtree of BB (subtree not including the BB itself).
DenseMap<BasicBlock *, InsertPtsCostPair> InsertPtsMap;
InsertPtsMap.reserve(Orders.size() + 1);
- for (auto RIt = Orders.rbegin(); RIt != Orders.rend(); RIt++) {
- BasicBlock *Node = *RIt;
+ for (BasicBlock *Node : llvm::reverse(Orders)) {
bool NodeInBBs = BBs.count(Node);
auto &InsertPts = InsertPtsMap[Node].first;
BlockFrequency &InsertPtsFreq = InsertPtsMap[Node].second;
diff --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
index a28a9ac9f4e5c..757461bbd43b5 100644
--- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
@@ -1701,8 +1701,7 @@ struct DSEState {
LLVM_DEBUG(
dbgs()
<< "Trying to eliminate MemoryDefs at the end of the function\n");
- for (int I = MemDefs.size() - 1; I >= 0; I--) {
- MemoryDef *Def = MemDefs[I];
+ for (MemoryDef *Def : llvm::reverse(MemDefs)) {
if (SkipStores.contains(Def) || !isRemovable(Def->getMemoryInst()))
continue;
diff --git a/llvm/lib/Transforms/Scalar/LoopRerollPass.cpp b/llvm/lib/Transforms/Scalar/LoopRerollPass.cpp
index 56d66b93dd691..9d22eceb987f6 100644
--- a/llvm/lib/Transforms/Scalar/LoopRerollPass.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopRerollPass.cpp
@@ -1456,16 +1456,12 @@ void LoopReroll::DAGRootTracker::replace(const SCEV *BackedgeTakenCount) {
}
// Remove instructions associated with non-base iterations.
- for (BasicBlock::reverse_iterator J = Header->rbegin(), JE = Header->rend();
- J != JE;) {
- unsigned I = Uses[&*J].find_first();
+ for (Instruction &Inst : llvm::make_early_inc_range(llvm::reverse(*Header))) {
+ unsigned I = Uses[&Inst].find_first();
if (I > 0 && I < IL_All) {
- LLVM_DEBUG(dbgs() << "LRR: removing: " << *J << "\n");
- J++->eraseFromParent();
- continue;
+ LLVM_DEBUG(dbgs() << "LRR: removing: " << Inst << "\n");
+ Inst.eraseFromParent();
}
-
- ++J;
}
// Rewrite each BaseInst using SCEV.
diff --git a/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp b/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
index ffa2f9adb9788..d23925042b0ae 100644
--- a/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
+++ b/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
@@ -648,13 +648,13 @@ Value *ConstantOffsetExtractor::applyExts(Value *V) {
Value *Current = V;
// ExtInsts is built in the use-def order. Therefore, we apply them to V
// in the reversed order.
- for (auto I = ExtInsts.rbegin(), E = ExtInsts.rend(); I != E; ++I) {
+ for (CastInst *I : llvm::reverse(ExtInsts)) {
if (Constant *C = dyn_cast<Constant>(Current)) {
// If Current is a constant, apply s/zext using ConstantExpr::getCast.
// ConstantExpr::getCast emits a ConstantInt if C is a ConstantInt.
- Current = ConstantExpr::getCast((*I)->getOpcode(), C, (*I)->getType());
+ Current = ConstantExpr::getCast(I->getOpcode(), C, I->getType());
} else {
- Instruction *Ext = (*I)->clone();
+ Instruction *Ext = I->clone();
Ext->setOperand(0, Current);
Ext->insertBefore(IP);
Current = Ext;
diff --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
index 71c15d5c51fc6..c840ee85795f7 100644
--- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
+++ b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
@@ -1047,9 +1047,9 @@ bool SCEVExpander::hoistIVInc(Instruction *IncV, Instruction *InsertPos) {
if (SE.DT.dominates(IncV, InsertPos))
break;
}
- for (auto I = IVIncs.rbegin(), E = IVIncs.rend(); I != E; ++I) {
- fixupInsertPoints(*I);
- (*I)->moveBefore(InsertPos);
+ for (Instruction *I : llvm::reverse(IVIncs)) {
+ fixupInsertPoints(I);
+ I->moveBefore(InsertPos);
}
return true;
}
diff --git a/llvm/tools/llvm-mca/Views/BottleneckAnalysis.cpp b/llvm/tools/llvm-mca/Views/BottleneckAnalysis.cpp
index 5b110d6602df0..dc0a07e75e480 100644
--- a/llvm/tools/llvm-mca/Views/BottleneckAnalysis.cpp
+++ b/llvm/tools/llvm-mca/Views/BottleneckAnalysis.cpp
@@ -275,9 +275,9 @@ void DependencyGraph::getCriticalSequence(
[](const DGNode &Lhs, const DGNode &Rhs) { return Lhs.Cost < Rhs.Cost; });
unsigned IID = std::distance(Nodes.begin(), It);
Seq.resize(Nodes[IID].Depth);
- for (unsigned I = Seq.size(), E = 0; I > E; --I) {
+ for (const DependencyEdge *&DE : llvm::reverse(Seq)) {
const DGNode &N = Nodes[IID];
- Seq[I - 1] = &N.CriticalPredecessor;
+ DE = &N.CriticalPredecessor;
IID = N.CriticalPredecessor.FromIID;
}
}
More information about the llvm-commits
mailing list