[Mlir-commits] [mlir] [mlir][mesh] Use tensor shape notation for the shape of a cluster (PR #73826)

Mehdi Amini llvmlistbot at llvm.org
Wed Dec 6 21:00:29 PST 2023


================
@@ -3911,3 +3930,42 @@ void Block::printAsOperand(raw_ostream &os, AsmState &state) {
   OperationPrinter printer(os, state.getImpl());
   printer.printBlockName(this);
 }
+
+//===--------------------------------------------------------------------===//
+// Custom printers
+//===--------------------------------------------------------------------===//
+namespace mlir {
+
+void printDimensionList(OpAsmPrinter &printer, Operation *op,
+                        ArrayRef<int64_t> dimensions) {
+  if (dimensions.empty())
+    printer << "[";
+  printer.printDimensionList(dimensions);
+  if (dimensions.empty())
+    printer << "]";
+}
+
+ParseResult parseDimensionList(OpAsmParser &parser,
+                               DenseI64ArrayAttr &dimensions) {
+  bool hasOpeningSquare = succeeded(parser.parseOptionalLSquare());
+  SmallVector<int64_t> shapeArr;
+  if (failed(parser.parseDimensionList(shapeArr, true, false))) {
+    return parser.emitError(parser.getCurrentLocation())
+           << "Failed parsing dimension list.";
+  }
+  if (shapeArr.empty() && !hasOpeningSquare) {
+    return parser.emitError(parser.getCurrentLocation())
+           << "Failed parsing dimension list. Did you mean an empty list? It "
+              "must be "
+              "denoted by \"[]\".";
+  }
----------------
joker-eph wrote:

The logic in this function is convoluted to me. I don't quite get why `hasOpeningSquare` carries forward and we try to parse a DimensionList.
After line 3955 we already parsed `[]` there is nothing else to continue from here.

It is even incorrect actually, I claim that you're not **allowed** to try to parse anything else. 
Actually I'm even confused by how 3956 `parser.parseDimensionList()` can succeed in all examples...

https://github.com/llvm/llvm-project/pull/73826


More information about the Mlir-commits mailing list