Convert for_each to range-based for loops (NFC)
authorKazu Hirata <kazu@google.com>
Sat, 30 Jul 2022 17:35:52 +0000 (10:35 -0700)
committerKazu Hirata <kazu@google.com>
Sat, 30 Jul 2022 17:35:52 +0000 (10:35 -0700)
clang-tools-extra/pseudo/lib/grammar/GrammarBNF.cpp
flang/lib/Optimizer/Builder/FIRBuilder.cpp
llvm/tools/llvm-exegesis/lib/Clustering.cpp
mlir/lib/ExecutionEngine/JitRunner.cpp

index 43fba22..410b151 100644 (file)
@@ -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() == "");
 
index 6ff9425..6c3d4bd 100644 (file)
@@ -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)
index 08646aa..4c4efd3 100644 (file)
@@ -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.
@@ -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(),
index 53fdde6..94c86a5 100644 (file)
@@ -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();
 }