Files
clang-p2996/mlir/test/IR/parser_dialect_loading.mlir
Jeremy Kun 07c157a435 [mlir] load dialect in parser for optional parameters (#96667)
https://github.com/llvm/llvm-project/pull/96242 fixed an issue where the
auto-generated parsers were not loading dialects whose namespaces are
not present in the textual IR. This required the attribute parameter to
be a tablegen def with its dialect information attached.

This fails when using parameter wrapper classes like
`OptionalParameter`. This came up because `RingAttr` uses
`OptionalParameter` for its second and third attributes.
`OptionalParameter` takes as input the C++ type as a string instead of
the tablegen def, and so it doesn't have a dialect member value to
trigger the fix from https://github.com/llvm/llvm-project/pull/96242.
The docs on this topic say the appropriate solution as overloading
`FieldParser` for a particular type.

This PR updates `FieldParser` for generic attributes to load the dialect
on demand. This requires `mlir-tblgen` to emit a `dialectName` static
field on the generated attribute class, and check for it with template
metaprogramming, since not all attribute types go through `mlir-tblgen`.

---------

Co-authored-by: Jeremy Kun <j2kun@users.noreply.github.com>
Co-authored-by: Oleksandr "Alex" Zinenko <ftynse@gmail.com>
2024-07-07 09:44:07 -07:00

20 lines
583 B
MLIR

// RUN: mlir-opt -allow-unregistered-dialect --split-input-file %s | FileCheck %s
// This is a testing that a non-qualified attribute in a custom format
// correctly preload the dialect before creating the attribute.
#attr = #test.nested_polynomial<poly=<1 + x**2>>
// CHECK-LABEL: @parse_correctly
llvm.func @parse_correctly() {
test.containing_int_polynomial_attr #attr
llvm.return
}
// -----
#attr2 = #test.nested_polynomial2<poly=<1 + x**2>>
// CHECK-LABEL: @parse_correctly_2
llvm.func @parse_correctly_2() {
test.containing_int_polynomial_attr2 #attr2
llvm.return
}