[llvm] be37475 - [Transforms/IPO] Use range-based for loops (NFC)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 3 20:42:00 PST 2021
Author: Kazu Hirata
Date: 2021-02-03T20:41:20-08:00
New Revision: be37475897c1efe00c632de4896e31bcfec62585
URL: https://github.com/llvm/llvm-project/commit/be37475897c1efe00c632de4896e31bcfec62585
DIFF: https://github.com/llvm/llvm-project/commit/be37475897c1efe00c632de4896e31bcfec62585.diff
LOG: [Transforms/IPO] Use range-based for loops (NFC)
Added:
Modified:
llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
llvm/lib/Transforms/IPO/HotColdSplitting.cpp
llvm/lib/Transforms/IPO/MergeFunctions.cpp
llvm/lib/Transforms/IPO/PartialInlining.cpp
llvm/lib/Transforms/IPO/SampleProfile.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp b/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
index 7998a1ae5c6e..d34634111ecf 100644
--- a/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
+++ b/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
@@ -446,9 +446,8 @@ doPromotion(Function *F, SmallPtrSetImpl<Argument *> &ArgsToPromote,
"GEPs without uses should be cleaned up already");
IndicesVector Operands;
Operands.reserve(GEP->getNumIndices());
- for (User::op_iterator II = GEP->idx_begin(), IE = GEP->idx_end();
- II != IE; ++II)
- Operands.push_back(cast<ConstantInt>(*II)->getSExtValue());
+ for (const Use &Idx : GEP->indices())
+ Operands.push_back(cast<ConstantInt>(Idx)->getSExtValue());
// GEPs with a single 0 index can be merged with direct loads
if (Operands.size() == 1 && Operands.front() == 0)
@@ -634,9 +633,8 @@ static bool isSafeToPromoteArgument(Argument *Arg, Type *ByValTy, AAResults &AAR
if (V == Arg) {
// This load actually loads (part of) Arg? Check the indices then.
Indices.reserve(GEP->getNumIndices());
- for (User::op_iterator II = GEP->idx_begin(), IE = GEP->idx_end();
- II != IE; ++II)
- if (ConstantInt *CI = dyn_cast<ConstantInt>(*II))
+ for (Use &Idx : GEP->indices())
+ if (ConstantInt *CI = dyn_cast<ConstantInt>(Idx))
Indices.push_back(CI->getSExtValue());
else
// We found a non-constant GEP index for this argument? Bail out
@@ -689,9 +687,8 @@ static bool isSafeToPromoteArgument(Argument *Arg, Type *ByValTy, AAResults &AAR
return false;
// Ensure that all of the indices are constants.
- for (User::op_iterator i = GEP->idx_begin(), e = GEP->idx_end(); i != e;
- ++i)
- if (ConstantInt *C = dyn_cast<ConstantInt>(*i))
+ for (Use &Idx : GEP->indices())
+ if (ConstantInt *C = dyn_cast<ConstantInt>(Idx))
Operands.push_back(C->getSExtValue());
else
return false; // Not a constant operand GEP!
diff --git a/llvm/lib/Transforms/IPO/HotColdSplitting.cpp b/llvm/lib/Transforms/IPO/HotColdSplitting.cpp
index aa708ee520b1..8dc480f28105 100644
--- a/llvm/lib/Transforms/IPO/HotColdSplitting.cpp
+++ b/llvm/lib/Transforms/IPO/HotColdSplitting.cpp
@@ -698,9 +698,7 @@ bool HotColdSplitting::outlineColdRegions(Function &F, bool HasProfileSummary) {
bool HotColdSplitting::run(Module &M) {
bool Changed = false;
bool HasProfileSummary = (M.getProfileSummary(/* IsCS */ false) != nullptr);
- for (auto It = M.begin(), End = M.end(); It != End; ++It) {
- Function &F = *It;
-
+ for (Function &F : M) {
// Do not touch declarations.
if (F.isDeclaration())
continue;
diff --git a/llvm/lib/Transforms/IPO/MergeFunctions.cpp b/llvm/lib/Transforms/IPO/MergeFunctions.cpp
index b3427741903d..91af6e0cb72e 100644
--- a/llvm/lib/Transforms/IPO/MergeFunctions.cpp
+++ b/llvm/lib/Transforms/IPO/MergeFunctions.cpp
@@ -529,10 +529,9 @@ void MergeFunctions::eraseInstsUnrelatedToPDI(
// Reduce G to its entry block.
void MergeFunctions::eraseTail(Function *G) {
std::vector<BasicBlock *> WorklistBB;
- for (Function::iterator BBI = std::next(G->begin()), BBE = G->end();
- BBI != BBE; ++BBI) {
- BBI->dropAllReferences();
- WorklistBB.push_back(&*BBI);
+ for (BasicBlock &BB : drop_begin(*G)) {
+ BB.dropAllReferences();
+ WorklistBB.push_back(&BB);
}
while (!WorklistBB.empty()) {
BasicBlock *BB = WorklistBB.back();
@@ -634,18 +633,15 @@ void MergeFunctions::filterInstsUnrelatedToPDI(
LLVM_DEBUG(
dbgs()
<< " Report parameter debug info related/related instructions: {\n");
- for (BasicBlock::iterator BI = GEntryBlock->begin(), BE = GEntryBlock->end();
- BI != BE; ++BI) {
-
- Instruction *I = &*BI;
- if (PDIRelated.find(I) == PDIRelated.end()) {
+ for (Instruction &I : *GEntryBlock) {
+ if (PDIRelated.find(&I) == PDIRelated.end()) {
LLVM_DEBUG(dbgs() << " !PDIRelated: ");
- LLVM_DEBUG(I->print(dbgs()));
+ LLVM_DEBUG(I.print(dbgs()));
LLVM_DEBUG(dbgs() << "\n");
- PDIUnrelatedWL.push_back(I);
+ PDIUnrelatedWL.push_back(&I);
} else {
LLVM_DEBUG(dbgs() << " PDIRelated: ");
- LLVM_DEBUG(I->print(dbgs()));
+ LLVM_DEBUG(I.print(dbgs()));
LLVM_DEBUG(dbgs() << "\n");
}
}
diff --git a/llvm/lib/Transforms/IPO/PartialInlining.cpp b/llvm/lib/Transforms/IPO/PartialInlining.cpp
index 2bbf4bf110ae..5dfb8dab7948 100644
--- a/llvm/lib/Transforms/IPO/PartialInlining.cpp
+++ b/llvm/lib/Transforms/IPO/PartialInlining.cpp
@@ -418,12 +418,12 @@ PartialInlinerImpl::computeOutliningColdRegionsInfo(
[&ORE](SmallVectorImpl<BasicBlock *> &BlockList) -> BasicBlock * {
BasicBlock *ExitBlock = nullptr;
for (auto *Block : BlockList) {
- for (auto SI = succ_begin(Block); SI != succ_end(Block); ++SI) {
- if (!is_contained(BlockList, *SI)) {
+ for (BasicBlock *Succ : successors(Block)) {
+ if (!is_contained(BlockList, Succ)) {
if (ExitBlock) {
ORE.emit([&]() {
return OptimizationRemarkMissed(DEBUG_TYPE, "MultiExitRegion",
- &SI->front())
+ &Succ->front())
<< "Region dominated by "
<< ore::NV("Block", BlockList.front()->getName())
<< " has more than one region exit edge.";
diff --git a/llvm/lib/Transforms/IPO/SampleProfile.cpp b/llvm/lib/Transforms/IPO/SampleProfile.cpp
index a6f303428b62..f20c34be8b19 100644
--- a/llvm/lib/Transforms/IPO/SampleProfile.cpp
+++ b/llvm/lib/Transforms/IPO/SampleProfile.cpp
@@ -1907,21 +1907,17 @@ void SampleProfileLoader::buildEdges(Function &F) {
SmallPtrSet<BasicBlock *, 16> Visited;
if (!Predecessors[B1].empty())
llvm_unreachable("Found a stale predecessors list in a basic block.");
- for (pred_iterator PI = pred_begin(B1), PE = pred_end(B1); PI != PE; ++PI) {
- BasicBlock *B2 = *PI;
+ for (BasicBlock *B2 : predecessors(B1))
if (Visited.insert(B2).second)
Predecessors[B1].push_back(B2);
- }
// Add successors for B1.
Visited.clear();
if (!Successors[B1].empty())
llvm_unreachable("Found a stale successors list in a basic block.");
- for (succ_iterator SI = succ_begin(B1), SE = succ_end(B1); SI != SE; ++SI) {
- BasicBlock *B2 = *SI;
+ for (BasicBlock *B2 : successors(B1))
if (Visited.insert(B2).second)
Successors[B1].push_back(B2);
- }
}
}
More information about the llvm-commits
mailing list