The goal to this RFC is to expose the type and attribute names in C++ as methods in the
AbstractAttribute classes, and keep a map of names to abstract types/attributes in the
While dialect type and attributes (those not in the builtin dialect) usually have the format
"dialect.type" string is not accessible from the
Attribute class, nor it is possible to get an abstract type or attribute from this string. While for most users this is not useful, it would be quite useful for PDL or IRDL.
For instance, this would allow us to specify the constraint “match any type
cmath.complex” with only the PDL/IRDL dialect, without using additional C++. Currently, this is not possible, as there is no way to get the right
AbstractType directly from anything else than an existing type or a
TypeID. While I have the example of PDL/IRDL in mind, there are probably other areas (notably when doing meta things on MLIR) where this could be useful.
There are two main changes I would like to introduce. First, adding in the MLIRContext a field that would associate type/attribute names to their
AbstractAttribute. Second, adding a method
AbstractAttribute. These names should be in particular unique.
ODS-defined dialect types can directly emit these fields without any change, since most dialects use
mnemonic to set a name to a type/attribute. For cases where types and dialects do not have a mnemonic,
attrName can be overridden to give them a name to emit. For C+±defined types and attributes, only one new field is needed,
For most dialects, the names would be straightforward, which is
dialect.mnemonic. For builtin types and attributes, the name would be
name is the usual name (for instance
vector). However, for the case of unranked vector and unranked memrefs, the names would be
builtin.unranked_memref, as names should be unique per type. The only other example I have in mind for this kind of change is in the
quant dialect, which has two types that are parsed with
quant.uniform, so one is named
quant.uniform, and the other