[Mlir-commits] [mlir] baca3b3 - [MLIR] Simplify logic in `parseDynamicIndexList` (NFC)

Lorenzo Chelini llvmlistbot at llvm.org
Mon Nov 28 02:02:16 PST 2022


Author: Lorenzo Chelini
Date: 2022-11-28T11:02:09+01:00
New Revision: baca3b382b09aa2488d3e619478b9c96f67b40b8

URL: https://github.com/llvm/llvm-project/commit/baca3b382b09aa2488d3e619478b9c96f67b40b8
DIFF: https://github.com/llvm/llvm-project/commit/baca3b382b09aa2488d3e619478b9c96f67b40b8.diff

LOG: [MLIR] Simplify logic in `parseDynamicIndexList` (NFC)

We can use `parseCommaSeparatedList` to simplify the logic of
`parseDynamicIndexList`. We don't need to explicitly check delimiters
and comma anymore, this is done for us by `parseCommaSeparatedList`.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D138694

Added: 
    

Modified: 
    mlir/lib/Interfaces/ViewLikeInterface.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Interfaces/ViewLikeInterface.cpp b/mlir/lib/Interfaces/ViewLikeInterface.cpp
index 9a39a217bf442..d3c8fde35ef88 100644
--- a/mlir/lib/Interfaces/ViewLikeInterface.cpp
+++ b/mlir/lib/Interfaces/ViewLikeInterface.cpp
@@ -91,16 +91,9 @@ ParseResult mlir::parseDynamicIndexList(
     OpAsmParser &parser,
     SmallVectorImpl<OpAsmParser::UnresolvedOperand> &values,
     DenseI64ArrayAttr &integers) {
-  if (failed(parser.parseLSquare()))
-    return failure();
-  // 0-D.
-  if (succeeded(parser.parseOptionalRSquare())) {
-    integers = parser.getBuilder().getDenseI64ArrayAttr({});
-    return success();
-  }
 
   SmallVector<int64_t, 4> integerVals;
-  while (true) {
+  auto parseIntegerOrValue = [&]() {
     OpAsmParser::UnresolvedOperand operand;
     auto res = parser.parseOptionalOperand(operand);
     if (res.has_value() && succeeded(res.value())) {
@@ -109,17 +102,16 @@ ParseResult mlir::parseDynamicIndexList(
     } else {
       int64_t integer;
       if (failed(parser.parseInteger(integer)))
-        return parser.emitError(parser.getNameLoc())
-               << "expected SSA value or integer";
+        return failure();
       integerVals.push_back(integer);
     }
-
-    if (succeeded(parser.parseOptionalComma()))
-      continue;
-    if (failed(parser.parseRSquare()))
-      return failure();
-    break;
-  }
+    return success();
+  };
+  if (parser.parseCommaSeparatedList(OpAsmParser::Delimiter::Square,
+                                     parseIntegerOrValue,
+                                     " in dynamic index list"))
+    return parser.emitError(parser.getNameLoc())
+           << "expected SSA value or integer";
   integers = parser.getBuilder().getDenseI64ArrayAttr(integerVals);
   return success();
 }


        


More information about the Mlir-commits mailing list