From 5bc0e7b73cd95db40105b51b3a39596610a52566 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sat, 30 Jul 2022 10:35:52 -0700 Subject: [PATCH] Convert for_each to range-based for loops (NFC) --- clang-tools-extra/pseudo/lib/grammar/GrammarBNF.cpp | 8 ++++---- flang/lib/Optimizer/Builder/FIRBuilder.cpp | 3 +-- llvm/tools/llvm-exegesis/lib/Clustering.cpp | 9 ++++----- mlir/lib/ExecutionEngine/JitRunner.cpp | 3 ++- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/clang-tools-extra/pseudo/lib/grammar/GrammarBNF.cpp b/clang-tools-extra/pseudo/lib/grammar/GrammarBNF.cpp index 43fba22..410b151 100644 --- a/clang-tools-extra/pseudo/lib/grammar/GrammarBNF.cpp +++ b/clang-tools-extra/pseudo/lib/grammar/GrammarBNF.cpp @@ -64,10 +64,10 @@ public: 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, @@ -77,10 +77,10 @@ public: // 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() == ""); diff --git a/flang/lib/Optimizer/Builder/FIRBuilder.cpp b/flang/lib/Optimizer/Builder/FIRBuilder.cpp index 6ff9425..6c3d4bd 100644 --- a/flang/lib/Optimizer/Builder/FIRBuilder.cpp +++ b/flang/lib/Optimizer/Builder/FIRBuilder.cpp @@ -166,9 +166,8 @@ mlir::Value fir::FirOpBuilder::allocateLocal( llvm::SmallVector 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 attrs; if (asTarget) diff --git a/llvm/tools/llvm-exegesis/lib/Clustering.cpp b/llvm/tools/llvm-exegesis/lib/Clustering.cpp index 08646aa..4c4efd3 100644 --- a/llvm/tools/llvm-exegesis/lib/Clustering.cpp +++ b/llvm/tools/llvm-exegesis/lib/Clustering.cpp @@ -63,13 +63,13 @@ bool InstructionBenchmarkClustering::areAllNeighbours( ArrayRef 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 Measurements = Points_[P].Measurements; if (Measurements.empty()) // Error point. - return; + continue; G.addPoint(Measurements); - }); + } const std::vector Centroid = G.getAsPoint(); // Since we will be comparing with the centroid, we need to halve the epsilon. @@ -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(), diff --git a/mlir/lib/ExecutionEngine/JitRunner.cpp b/mlir/lib/ExecutionEngine/JitRunner.cpp index 53fdde6..94c86a5 100644 --- a/mlir/lib/ExecutionEngine/JitRunner.cpp +++ b/mlir/lib/ExecutionEngine/JitRunner.cpp @@ -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(); } -- 2.7.4