Skip to content

Commit

Permalink
[mlir][ods] Fix substitutions for op custom string literals
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Mogball committed Oct 14, 2022
1 parent 8b0e84a commit 8f5c5bb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions mlir/test/mlir-tblgen/op-format.td
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,23 @@ 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
}]>;

// 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
}]>;

// 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
}]>;
Expand Down
4 changes: 2 additions & 2 deletions mlir/tools/mlir-tblgen/OpFormatGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 8f5c5bb

Please sign in to comment.