[Mlir-commits] [mlir] 8f5c5bb - [mlir][ods] Fix substitutions for op custom string literals

Jeff Niu llvmlistbot at llvm.org
Fri Oct 14 09:33:18 PDT 2022


Author: Jeff Niu
Date: 2022-10-14T09:33:07-07:00
New Revision: 8f5c5bbe71639e8dd44f16b53d4ba9603dc1ed89

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

LOG: [mlir][ods] Fix substitutions for op custom string literals

The context and builder did not receive the correct substitutes in the
printers. Also, the tests were incorrect (d'oh!)

Reviewed By: rriddle

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

Added: 
    

Modified: 
    mlir/test/mlir-tblgen/op-format.td
    mlir/tools/mlir-tblgen/OpFormatGen.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/test/mlir-tblgen/op-format.td b/mlir/test/mlir-tblgen/op-format.td
index cfa8dbcbf183..5a7656ee60fe 100644
--- a/mlir/test/mlir-tblgen/op-format.td
+++ b/mlir/test/mlir-tblgen/op-format.td
@@ -20,7 +20,7 @@ class TestFormat_Op<string fmt, list<Trait> traits = []>
 // CHECK-LABEL: CustomStringLiteralA::parse
 // CHECK: parseFoo({{.*}}, parser.getBuilder().getI1Type())
 // CHECK-LABEL: CustomStringLiteralA::print
-// CHECK: printFoo({{.*}}, parser.getBuilder().getI1Type())
+// CHECK: printFoo({{.*}}, ::mlir::Builder(getContext()).getI1Type())
 def CustomStringLiteralA : TestFormat_Op<[{
   custom<Foo>("$_builder.getI1Type()") attr-dict
 }]>;
@@ -28,7 +28,7 @@ def CustomStringLiteralA : TestFormat_Op<[{
 // CHECK-LABEL: CustomStringLiteralB::parse
 // CHECK: parseFoo({{.*}}, IndexType::get(parser.getContext()))
 // CHECK-LABEL: CustomStringLiteralB::print
-// CHECK: printFoo({{.*}}, IndexType::get(parser.getContext()))
+// CHECK: printFoo({{.*}}, IndexType::get(getContext()))
 def CustomStringLiteralB : TestFormat_Op<[{
   custom<Foo>("IndexType::get($_ctxt)") attr-dict
 }]>;
@@ -36,7 +36,7 @@ def CustomStringLiteralB : TestFormat_Op<[{
 // CHECK-LABEL: CustomStringLiteralC::parse
 // CHECK: parseFoo({{.*}}, parser.getBuilder().getStringAttr("foo"))
 // CHECK-LABEL: CustomStringLiteralC::print
-// CHECK: printFoo({{.*}}, parser.getBuilder().getStringAttr("foo"))
+// CHECK: printFoo({{.*}}, ::mlir::Builder(getContext()).getStringAttr("foo"))
 def CustomStringLiteralC : TestFormat_Op<[{
   custom<Foo>("$_builder.getStringAttr(\"foo\")") attr-dict
 }]>;

diff  --git a/mlir/tools/mlir-tblgen/OpFormatGen.cpp b/mlir/tools/mlir-tblgen/OpFormatGen.cpp
index 83d6794e730e..0079600928a6 100644
--- a/mlir/tools/mlir-tblgen/OpFormatGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpFormatGen.cpp
@@ -1724,8 +1724,8 @@ static void genCustomDirectiveParameterPrinter(FormatElement *element,
 
   } else if (auto *string = dyn_cast<StringElement>(element)) {
     FmtContext ctx;
-    ctx.withBuilder("parser.getBuilder()");
-    ctx.addSubst("_ctxt", "parser.getContext()");
+    ctx.withBuilder("::mlir::Builder(getContext())");
+    ctx.addSubst("_ctxt", "getContext()");
     body << tgfmt(string->getValue(), &ctx);
 
   } else {


        


More information about the Mlir-commits mailing list