Hello, I am new to MLIR, and I am trying to determine whether the following behavior is intended or a bug.
Defining an assembly format using TableGen (i.e., struct(params)) for a nested attribute results in different behaviors between the parser and the printer.
Reproduction
I defined an internal attribute (InternalAttr) with integer parameters and an external attribute (ExternalAttr) that contains a list of InternalAttr as a parameter.
//===----------------------------------------------------------------------===//
// Test
//===----------------------------------------------------------------------===//
def InternalAttr : OpenMP_Attr<"Internal", "internal"> {
let parameters = (ins
"int64_t":$key,
"int64_t":$value
);
let assemblyFormat = "`<` struct(params) `>`";
}
def ExternalAttr : OpenMP_Attr<"External", "external"> {
let parameters = (ins
ArrayRefParameter<"InternalAttr">:$internals
);
let assemblyFormat = "`<` `[` struct(params) `]` `>`";
}
Behavior
The parser expects the following format:
module attributes {omp.internal = #omp.internal<key = 8, value = 9>} {}
module attributes {omp.external = #omp.external<[internals = #omp.internal<key = 1, value = 2>, #omp.internal<key = 8, value = 9>]>} {}
The parser for external attribute requires the mnemonic (#omp.internal) to be explicitly present for each InternalAttr inside ExternalAttr.
However, the printer prints the following format:
// RUN: mlir-opt %s
module attributes {omp.internal = #omp.internal<key = 8, value = 9>} {
}
module attributes {omp.external = #omp.external<[internals = <key = 1, value = 2>, <key = 8, value = 9>]>} {
}
Unlike the parser, the printer omits the mnemonic (#omp.internal) for InternalAttr inside ExternalAttr.
It seems to me that either:
- The printer should retain the
#omp.internalmnemonic, ensuring consistency with the parser, or - The parser should not require the
#omp.internalmnemonic when parsing, sinceExternalAttris a well-defined closed type.
Could you clarify whether this behavior is intentional? If not, what would be the correct approach to ensure consistency between parsing and printing?
Thanks in advance for your guidance!