From 8f5c5bbe71639e8dd44f16b53d4ba9603dc1ed89 Mon Sep 17 00:00:00 2001 From: Jeff Niu Date: Wed, 12 Oct 2022 20:03:54 -0700 Subject: [PATCH] [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 --- mlir/test/mlir-tblgen/op-format.td | 6 +++--- mlir/tools/mlir-tblgen/OpFormatGen.cpp | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/mlir/test/mlir-tblgen/op-format.td b/mlir/test/mlir-tblgen/op-format.td index cfa8dbc..5a7656e 100644 --- a/mlir/test/mlir-tblgen/op-format.td +++ b/mlir/test/mlir-tblgen/op-format.td @@ -20,7 +20,7 @@ class TestFormat_Op 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("$_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("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("$_builder.getStringAttr(\"foo\")") attr-dict }]>; diff --git a/mlir/tools/mlir-tblgen/OpFormatGen.cpp b/mlir/tools/mlir-tblgen/OpFormatGen.cpp index 83d6794..0079600 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(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 { -- 2.7.4