Add support for default-valued attributes as optional-group anchors. The
attribute is considered present if it holds a non-default value.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
mlir/tools/mlir-tblgen/OpFormatGen.cpp | ||
---|---|---|
1261–1262 | I didn't really understand the existing logic, it seemed odd to me to parse as optional under Normal context, but not under Optional context, but maybe I'm misunderstanding what "context" means here. I switched the use of GenContext so that genContext == Optional whenever the attribute should be optionally parsed (currently this is only for the first element of the then group). |
mlir/tools/mlir-tblgen/OpFormatGen.cpp | ||
---|---|---|
1261–1262 | GenContext::Optional means the element is inside an optional group, not whether the element should be optionally parsed. |
mlir/tools/mlir-tblgen/OpFormatGen.cpp | ||
---|---|---|
1261–1262 | I see, is there supposed to be a difference to how things are parsed in optional groups (other than the first element)? The only place I see genCtx used is this line, and it seems like it's allowing optional attributes to be optionally parsed when outside an optional group, but that just ends up breaking in the printer: https://github.com/llvm/llvm-project/issues/58064 |
mlir/tools/mlir-tblgen/OpFormatGen.cpp | ||
---|---|---|
1261–1262 | Not really. Only that certain elements are prohibited in optional groups (e.g. nested optional groups). The issue you linked just looks like a bug to me. I think the feature you are adding is useful but I'd prefer not to fiddle with the gen context |
mlir/test/lib/Dialect/Test/TestOps.td | ||
---|---|---|
2178 | there's a DefaultValuedStrAttr that lets you drop the quotes |
fix default-valued symbol and enum attrs, use DefaultValuedStrAttr
mlir/tools/mlir-tblgen/OpFormatGen.cpp | ||
---|---|---|
1096 | i switched these over to use parseAsOptional; otherwise default-valued symbols and enums break |
there's a DefaultValuedStrAttr that lets you drop the quotes