[Mlir-commits] [mlir] [mlir][LLVM] Add operand bundle support (PR #108933)

Markus Böck llvmlistbot at llvm.org
Mon Sep 23 09:31:41 PDT 2024


================
@@ -220,6 +220,88 @@ static RetTy parseOptionalLLVMKeyword(OpAsmParser &parser,
   return static_cast<RetTy>(index);
 }
 
+//===----------------------------------------------------------------------===//
+// Operand bundle helpers.
+//===----------------------------------------------------------------------===//
+
+static void printOneOpBundle(OpAsmPrinter &p, OperandRange operands,
+                             TypeRange operandTypes, StringRef tag) {
+  p.printString(tag);
+  p << "(";
+  p.printOperands(operands);
+  p << " : ";
+  llvm::interleaveComma(operandTypes, p);
+  p << ")";
+}
+
+static void printOpBundles(OpAsmPrinter &p, Operation *op,
+                           OperandRangeRange opBundleOperands,
+                           TypeRangeRange opBundleOperandTypes,
+                           ArrayRef<std::string> opBundleTags) {
+  p << "[";
+  llvm::interleaveComma(
+      llvm::zip(opBundleOperands, opBundleOperandTypes, opBundleTags), p,
+      [&p](auto bundle) {
+        printOneOpBundle(p, std::get<0>(bundle), std::get<1>(bundle),
+                         std::get<2>(bundle));
+      });
+  p << "]";
+}
+
+static ParseResult parseOneOpBundle(
+    OpAsmParser &p,
+    SmallVector<SmallVector<OpAsmParser::UnresolvedOperand>> &opBundleOperands,
+    SmallVector<SmallVector<Type>> &opBundleOperandTypes,
+    SmallVector<std::string> &opBundleTags) {
+  auto currentParserLoc = p.getCurrentLocation();
+  SmallVector<OpAsmParser::UnresolvedOperand> operands;
+  SmallVector<Type> types;
+  std::string tag;
+
+  if (p.parseString(&tag))
+    return p.emitError(currentParserLoc, "expect operand bundle tag");
+
+  if (p.parseLParen())
+    return failure();
+
+  if (p.parseOperandList(operands))
+    return failure();
+  if (p.parseColon())
+    return failure();
+  if (p.parseTypeList(types))
+    return failure();
+
+  if (p.parseRParen())
+    return failure();
----------------
zero9178 wrote:

I suspect that we need logic here to handle empty operand lists.
Specifically you'll want to do a `parseOptionalRParen` right after parsing the left paren to then skip the operand list entirely.

Could you also add a test for this case?

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


More information about the Mlir-commits mailing list