[PATCH] D79004: [mlir][assemblyFormat] Fix bug when using AttrSizedOperandSegments trait with only non-buildable operand types

Martin Erhart via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 28 06:56:31 PDT 2020


maerhart created this revision.
maerhart added reviewers: rriddle, Kayjukh, grosser.
maerhart added a project: MLIR.
Herald added subscribers: llvm-commits, frgossen, grosul1, Joonsoo, liufengdb, lucyrfox, mgester, arpith-jacob, nicolasvasilache, antiagainst, shauheen, jpienaar, mehdi_amini.
Herald added a project: LLVM.

When creating an operation with the AttrSizedOperandSegments trait, two Variadic operands of types which do not have a builder attached to them, and specifying the assemblyFormat to automatically generate the parser, the `builder` variable is used, but never declared. The existing tests only use I32 and I64 types which use a builder to build the types of the operands. In this case the builder variable gets declared for that purpose and later is also used for creating the trait-specific attribute. However, in the case no operand type is buildable (e.g. when only using AnyType) this variable declaration is not added to the parser body.
This patch adds the declaration in this specific case as well as a test to verify it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D79004

Files:
  mlir/test/lib/Dialect/Test/TestOps.td
  mlir/tools/mlir-tblgen/OpFormatGen.cpp


Index: mlir/tools/mlir-tblgen/OpFormatGen.cpp
===================================================================
--- mlir/tools/mlir-tblgen/OpFormatGen.cpp
+++ mlir/tools/mlir-tblgen/OpFormatGen.cpp
@@ -866,6 +866,8 @@
 void OperationFormat::genParserVariadicSegmentResolution(Operator &op,
                                                          OpMethodBody &body) {
   if (!allOperands && op.getTrait("OpTrait::AttrSizedOperandSegments")) {
+    if (buildableTypes.empty())
+      body << "  Builder &builder = parser.getBuilder();\n";
     body << "  result.addAttribute(\"operand_segment_sizes\", "
          << "builder.getI32VectorAttr({";
     auto interleaveFn = [&](const NamedTypeConstraint &operand) {
Index: mlir/test/lib/Dialect/Test/TestOps.td
===================================================================
--- mlir/test/lib/Dialect/Test/TestOps.td
+++ mlir/test/lib/Dialect/Test/TestOps.td
@@ -1270,6 +1270,16 @@
   (`[` $variadic^ `]`)? attr-dict
 }]>;
 
+def FormatTwoVariadicOperandsNoBuildableTypeOp
+    : TEST_Op<"format_two_variadic_operands_no_buildable_type_op",
+              [AttrSizedOperandSegments]> {
+  let arguments = (ins Variadic<AnyType>:$a,
+                       Variadic<AnyType>:$b);
+  let assemblyFormat = [{
+    `(` $a `:` type($a) `)` `->` `(` $b `:` type($b) `)`  attr-dict
+  }];
+}
+
 //===----------------------------------------------------------------------===//
 // Test SideEffects
 //===----------------------------------------------------------------------===//


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79004.260614.patch
Type: text/x-patch
Size: 1527 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200428/fd3109ca/attachment.bin>


More information about the llvm-commits mailing list