Skip to content

Commit

Permalink
Convert for_each to range-based for loops (NFC)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazutakahirata committed Jul 30, 2022
1 parent f081ec2 commit 5bc0e7b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
8 changes: 4 additions & 4 deletions clang-tools-extra/pseudo/lib/grammar/GrammarBNF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ class GrammarBuilder {
UniqueAttributeValues.insert(KV.second);
}
}
llvm::for_each(UniqueNonterminals, [&T](llvm::StringRef Name) {
for (llvm::StringRef Name : UniqueNonterminals) {
T->Nonterminals.emplace_back();
T->Nonterminals.back().Name = Name.str();
});
}
assert(T->Nonterminals.size() < (1 << (SymbolBits - 1)) &&
"Too many nonterminals to fit in SymbolID bits!");
llvm::sort(T->Nonterminals, [](const GrammarTable::Nonterminal &L,
Expand All @@ -77,10 +77,10 @@ class GrammarBuilder {
// Add an empty string for the corresponding sentinel unset attribute.
T->AttributeValues.push_back("");
UniqueAttributeValues.erase("");
llvm::for_each(UniqueAttributeValues, [&T](llvm::StringRef Name) {
for (llvm::StringRef Name : UniqueAttributeValues) {
T->AttributeValues.emplace_back();
T->AttributeValues.back() = Name.str();
});
}
llvm::sort(T->AttributeValues);
assert(T->AttributeValues.front() == "");

Expand Down
3 changes: 1 addition & 2 deletions flang/lib/Optimizer/Builder/FIRBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,8 @@ mlir::Value fir::FirOpBuilder::allocateLocal(
llvm::SmallVector<mlir::Value> elidedLenParams =
elideLengthsAlreadyInType(ty, lenParams);
auto idxTy = getIndexType();
llvm::for_each(elidedShape, [&](mlir::Value sh) {
for (mlir::Value sh : elidedShape)
indices.push_back(createConvert(loc, idxTy, sh));
});
// Add a target attribute, if needed.
llvm::SmallVector<mlir::NamedAttribute> attrs;
if (asTarget)
Expand Down
9 changes: 4 additions & 5 deletions llvm/tools/llvm-exegesis/lib/Clustering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ bool InstructionBenchmarkClustering::areAllNeighbours(
ArrayRef<size_t> Pts) const {
// First, get the centroid of this group of points. This is O(N).
SchedClassClusterCentroid G;
for_each(Pts, [this, &G](size_t P) {
for (size_t P : Pts) {
assert(P < Points_.size());
ArrayRef<BenchmarkMeasure> Measurements = Points_[P].Measurements;
if (Measurements.empty()) // Error point.
return;
continue;
G.addPoint(Measurements);
});
}
const std::vector<BenchmarkMeasure> Centroid = G.getAsPoint();

// Since we will be comparing with the centroid, we need to halve the epsilon.
Expand Down Expand Up @@ -226,9 +226,8 @@ void InstructionBenchmarkClustering::clusterizeNaive(
/*IsUnstable=*/!areAllNeighbours(PointsOfSchedClass)));
Cluster &CurrentCluster = Clusters_.back();
// Mark points as belonging to the new cluster.
for_each(PointsOfSchedClass, [this, &CurrentCluster](size_t P) {
for (size_t P : PointsOfSchedClass)
ClusterIdForPoint_[P] = CurrentCluster.Id;
});
// And add all the points of this opcode's sched class to the new cluster.
CurrentCluster.PointIndices.reserve(PointsOfSchedClass.size());
CurrentCluster.PointIndices.assign(PointsOfSchedClass.begin(),
Expand Down
3 changes: 2 additions & 1 deletion mlir/lib/ExecutionEngine/JitRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ static Error compileAndExecute(Options &options, ModuleOp module,
(*fptr)(args);

// Run all dynamic library destroy callbacks to prepare for the shutdown.
llvm::for_each(destroyFns, [](MlirRunnerDestroyFn destroy) { destroy(); });
for (MlirRunnerDestroyFn destroy : destroyFns)
destroy();

return Error::success();
}
Expand Down

0 comments on commit 5bc0e7b

Please sign in to comment.