I’m experimenting with debug information attached to ops. One thing I’d like to play around with is having custom LocationAttr
subclasses, because locations are generally well-preserved across optimizations.
Here’s what I have so far (modeled after BuiltinLocationAttributes.td
):
def Magic : AttrDef<DebugDialect, "MagicLoc", [], "::mlir::LocationAttr"> {
let parameters = (ins "StringAttr":$name, "LocationAttr":$childLoc);
let mnemonic = "magic";
let assemblyFormat = "`<` $name `,` $childLoc `>`";
}
But using that attribute as a location causes the parser to error out. The printed error message are all a result of dyn_cast<LocationAttr>(...)
returing null on my location subclass.
For example, the following errors in OperationParser::parseLocationAlias
:
#loc1 = #dbg.magic<"hello", loc(unknown)>
unrealized_conversion_cast to i1 loc(#loc1)
error: expected location, but found '#dbg.magic<"hello", loc(unknown)>'
unrealized_conversion_cast to i1 loc(#loc1)
^
And the following errors in Parser::parseLocationInstance
:
#loc2 = loc(#dbg.magic<"hello", loc(unknown)>)
error: expected location attribute, but got#dbg.magic<"hello", loc(unknown)>
#loc2 = loc(#dbg.magic<"hello", loc(unknown)>)
^
Are you even supposed to be able to have custom location attributes?