Apply clang-tidy fixes for performance-for-range-copy to MLIR (NFC)
authorMehdi Amini <joker.eph@gmail.com>
Thu, 23 Dec 2021 22:13:06 +0000 (22:13 +0000)
committerMehdi Amini <joker.eph@gmail.com>
Sun, 2 Jan 2022 01:13:42 +0000 (01:13 +0000)
Differential Revision: https://reviews.llvm.org/D116248

16 files changed:
mlir/lib/Dialect/Async/Transforms/AsyncRuntimeRefCounting.cpp
mlir/lib/Dialect/Math/Transforms/PolynomialApproximation.cpp
mlir/lib/Dialect/StandardOps/Transforms/DecomposeCallGraphTypes.cpp
mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
mlir/lib/Dialect/Tosa/Transforms/TosaInferShapes.cpp
mlir/lib/Dialect/Utils/ReshapeOpsUtils.cpp
mlir/test/lib/Dialect/Test/TestPatterns.cpp
mlir/test/lib/IR/TestPrintDefUse.cpp
mlir/test/lib/IR/TestSlicing.cpp
mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-yaml-gen.cpp
mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
mlir/tools/mlir-tblgen/AttrOrTypeFormatGen.cpp
mlir/tools/mlir-tblgen/LLVMIRIntrinsicGen.cpp
mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
mlir/tools/mlir-tblgen/OpDocGen.cpp
mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp

index 4b4217a..81fa424 100644 (file)
@@ -418,7 +418,7 @@ AsyncRuntimeRefCountingPass::addDropRefInDivergentLivenessSuccessor(
         continue;
 
       // Update terminator `successor` block to `refCountingBlock`.
-      for (auto pair : llvm::enumerate(terminator->getSuccessors()))
+      for (const auto &pair : llvm::enumerate(terminator->getSuccessors()))
         if (pair.value() == successor)
           terminator->setSuccessor(refCountingBlock, pair.index());
     }
index dc92436..2dbee7e 100644 (file)
@@ -134,7 +134,7 @@ handleMultidimensionalVectors(ImplicitLocOpBuilder &builder,
     auto offsets = delinearize(strides, i);
 
     SmallVector<Value> extracted(expandedOperands.size());
-    for (auto tuple : llvm::enumerate(expandedOperands))
+    for (const auto &tuple : llvm::enumerate(expandedOperands))
       extracted[tuple.index()] =
           builder.create<vector::ExtractOp>(tuple.value(), offsets);
 
index 3686568..f9d9c5c 100644 (file)
@@ -67,7 +67,7 @@ struct DecomposeCallGraphTypesForFuncArgs
 
     // Convert function arguments using the provided TypeConverter.
     TypeConverter::SignatureConversion conversion(functionType.getNumInputs());
-    for (auto argType : llvm::enumerate(functionType.getInputs())) {
+    for (const auto &argType : llvm::enumerate(functionType.getInputs())) {
       SmallVector<Type, 2> decomposedTypes;
       if (failed(typeConverter->convertType(argType.value(), decomposedTypes)))
         return failure();
index e56f83b..69da41c 100644 (file)
@@ -1791,7 +1791,7 @@ LogicalResult IfOp::inferReturnTypeComponents(
     if (resultKnowledge.size() != yieldOp.getNumOperands())
       return failure();
 
-    for (auto it : llvm::enumerate(yieldOp.getOperands())) {
+    for (const auto &it : llvm::enumerate(yieldOp.getOperands())) {
       int32_t index = it.index();
       auto meet = ValueKnowledge::meet(
           resultKnowledge[index],
@@ -1835,7 +1835,7 @@ LogicalResult WhileOp::inferReturnTypeComponents(
     if (resultKnowledge.size() != yieldOp.getNumOperands())
       return failure();
 
-    for (auto it : llvm::enumerate(yieldOp.getOperands())) {
+    for (const auto &it : llvm::enumerate(yieldOp.getOperands())) {
       int32_t index = it.index();
       if (auto meet = ValueKnowledge::meet(
               resultKnowledge[index],
index 34d480c..3a50336 100644 (file)
@@ -132,7 +132,7 @@ void propagateShapesToTosaWhile(
     }
 
     for (auto yieldOp : yieldOps) {
-      for (auto it : llvm::enumerate(yieldOp.getOperands())) {
+      for (const auto &it : llvm::enumerate(yieldOp.getOperands())) {
         auto newKnowledge =
             ValueKnowledge::getKnowledgeFromType(it.value().getType());
         yieldTypeInfo[it.index()] =
index f1acfb3..ddba1d3 100644 (file)
@@ -253,7 +253,7 @@ bool mlir::isReassociationValid(ArrayRef<AffineMap> reassociation,
     return true;
   unsigned nDims = reassociation[0].getNumDims();
   unsigned nextExpectedDim = 0;
-  for (auto it : llvm::enumerate(reassociation)) {
+  for (const auto &it : llvm::enumerate(reassociation)) {
     auto m = it.value();
     if (m.getNumDims() != nDims || m.getNumSymbols() != 0) {
       if (invalidIndex)
index 2f06d82..17a5871 100644 (file)
@@ -182,7 +182,7 @@ static void reifyReturnShape(Operation *op) {
   if (failed(shapedOp.reifyReturnTypeShapes(b, op->getOperands(), shapes)) ||
       !llvm::hasSingleElement(shapes))
     return;
-  for (auto it : llvm::enumerate(shapes)) {
+  for (const auto &it : llvm::enumerate(shapes)) {
     op->emitRemark() << "value " << it.index() << ": "
                      << it.value().getDefiningOp();
   }
index 6fa37b9..8a854e6 100644 (file)
@@ -41,7 +41,7 @@ struct TestPrintDefUsePass
 
       // Print information about the user of each of the result.
       llvm::outs() << "Has " << op->getNumResults() << " results:\n";
-      for (auto indexedResult : llvm::enumerate(op->getResults())) {
+      for (const auto &indexedResult : llvm::enumerate(op->getResults())) {
         Value result = indexedResult.value();
         llvm::outs() << "  - Result " << indexedResult.index();
         if (result.use_empty()) {
index 2489b14..a253c59 100644 (file)
@@ -33,7 +33,7 @@ static LogicalResult createBackwardSliceFunction(Operation *op,
       builder.create<FuncOp>(loc, clonedFuncOpName, parentFuncOp.getType());
   BlockAndValueMapping mapper;
   builder.setInsertionPointToEnd(clonedFuncOp.addEntryBlock());
-  for (auto arg : enumerate(parentFuncOp.getArguments()))
+  for (const auto &arg : enumerate(parentFuncOp.getArguments()))
     mapper.map(arg.value(), clonedFuncOp.getArgument(arg.index()));
   SetVector<Operation *> slice;
   getBackwardSlice(op, &slice);
index a07ada3..ed0b5f4 100644 (file)
@@ -360,7 +360,7 @@ static std::string interleaveToString(Container &container,
 
 static Optional<int>
 findTensorDefArgIndex(StringRef name, SmallVectorImpl<LinalgOperandDef> &args) {
-  for (auto it : llvm::enumerate(args)) {
+  for (const auto &it : llvm::enumerate(args)) {
     if (it.value().name == name)
       return it.index();
   }
@@ -381,7 +381,7 @@ findTypeValue(StringRef typeVar, SmallVectorImpl<LinalgOperandDef> &args) {
     return std::string("helper.getFloat64Type()");
 
   // Search all argument types.
-  for (auto it : llvm::enumerate(args)) {
+  for (const auto &it : llvm::enumerate(args)) {
     if (it.value().typeVar == typeVar)
       return llvm::formatv("block.getArgument({0}).getType()", it.index())
           .str();
index eac8e56..d90adbc 100644 (file)
@@ -561,7 +561,7 @@ void DefGen::emitConstruct() {
       MethodParameter("const KeyTy &", "tblgenKey"));
   if (!def.hasStorageCustomConstructor()) {
     auto &body = construct->body().indent();
-    for (auto it : llvm::enumerate(params)) {
+    for (const auto &it : llvm::enumerate(params)) {
       body << formatv("auto {0} = std::get<{1}>(tblgenKey);\n",
                       it.value().getName(), it.index());
     }
index 8042ecc..4a07157 100644 (file)
@@ -661,7 +661,7 @@ FailureOr<std::unique_ptr<Element>> FormatParser::parseParamsDirective() {
   /// Collect all of the attribute's or type's parameters.
   SmallVector<std::unique_ptr<Element>> vars;
   /// Ensure that none of the parameters have already been captured.
-  for (auto it : llvm::enumerate(def.getParameters())) {
+  for (const auto &it : llvm::enumerate(def.getParameters())) {
     if (seenParams.test(it.index())) {
       return emitError("`params` captures duplicate parameter: " +
                        it.value().getName());
index 18315ec..646527d 100644 (file)
@@ -65,7 +65,7 @@ static IndicesTy getOverloadableTypeIdxs(const llvm::Record &record,
                                          const char *listName) {
   auto results = record.getValueAsListOfDefs(listName);
   IndicesTy overloadedOps(results.size());
-  for (auto r : llvm::enumerate(results)) {
+  for (const auto &r : llvm::enumerate(results)) {
     llvm::MVT::SimpleValueType vt = getValueType(r.value());
     switch (vt) {
     case llvm::MVT::iAny:
index 484bb23..f27b537 100644 (file)
@@ -2267,7 +2267,7 @@ void OpEmitter::genOperandResultVerifier(MethodBody &body,
 
   body << "  {\n    unsigned index = 0; (void)index;\n";
 
-  for (auto staticValue : llvm::enumerate(values)) {
+  for (const auto &staticValue : llvm::enumerate(values)) {
     const NamedTypeConstraint &value = staticValue.value();
 
     bool hasPredicate = value.hasPredicate();
@@ -2332,7 +2332,7 @@ void OpEmitter::genRegionVerifier(MethodBody &body) {
     return;
 
   body << "  {\n    unsigned index = 0; (void)index;\n";
-  for (auto it : llvm::enumerate(regions)) {
+  for (const auto &it : llvm::enumerate(regions)) {
     const auto &region = it.value();
     if (canSkip(region))
       continue;
index fc2f814..3025df1 100644 (file)
@@ -235,7 +235,7 @@ static void emitAttrOrTypeDefAssemblyFormat(const AttrOrTypeDef &def,
 
   os << "\nSyntax:\n\n```\n!" << def.getDialect().getName() << "."
      << def.getMnemonic() << "<\n";
-  for (auto it : llvm::enumerate(parameters)) {
+  for (const auto &it : llvm::enumerate(parameters)) {
     const AttrOrTypeParameter &param = it.value();
     os << "  " << param.getSyntax();
     if (it.index() < (parameters.size() - 1))
index fb634a1..16fccff 100644 (file)
@@ -916,7 +916,7 @@ static void emitRegionAttributes(const Operator &op, raw_ostream &os) {
 
 /// Emits named accessors to regions.
 static void emitRegionAccessors(const Operator &op, raw_ostream &os) {
-  for (auto en : llvm::enumerate(op.getRegions())) {
+  for (const auto &en : llvm::enumerate(op.getRegions())) {
     const NamedRegion &region = en.value();
     if (region.name.empty())
       continue;