[Mlir-commits] [mlir] [mlir] Add dialect hooks for registering custom type and attribute alias printers (PR #173091)

Fabian Mora llvmlistbot at llvm.org
Mon Dec 22 10:11:28 PST 2025


fabianmcg wrote:

> This kind of cross-dialect interactions have too many pitfalls.

Could you elaborate in the pitfalls? So far you've only mentioned about being misleading when a someone reads the IR.

> This cross-dialect implicit aliasing (aliases aren't printed in the IR) isn't clearly desirable to me still

It should be possible to add a header listing all the aliases. However, I don't see much benefit of it, because it makes sugaring much more verbose (the one thing this patch pretends to minimize), and to me it's mostly users reading docs. Further, it makes it more similar to the existing aliasing mechanism.

To me, the user concerns for visualizing the IR can be solved by:
1. The user reads the docs and understands it is a dialect alias, and we define dialect aliases in the lang ref for the textual form. This is the option in this patch. Note that aliases can be deactivated, so the sugaring is optional.
2. We print an optional header with all the aliases. But most of it remains option 1.
3. We make the header non-optional. But it's again mostly option 1, and the header is just for users to not be confused.

The reason something like traditional aliases don't cut it, is parameters. Also, something like:

```mlir
alias<x> !llvm.ptr<x> = !ptr.ptr<#llvm.address_space<x>> // This doesn't work because what it is `x`
alias<i32 x> !llvm.ptr<x> = !ptr.ptr<#llvm.address_space<x>>
```

Would need an incredible amount of complexity, probably not that enormously far of parsing templates in C++. This also means, a lot whole of things would need to be added, for example we would need to add a type system for parameters.

Another important things to note are:
1. The current aliasing mechanism is not scoped to its own entities. For example, it's possible to specify aliases for types outside the dialect: https://github.com/llvm/llvm-project/blob/main/mlir/test/IR/print-attr-type-aliases.mlir#L30
2. We already allow text sugaring to hide bits of the internal state. For example, we don't always print `attr_segment_sizes`.

https://github.com/llvm/llvm-project/pull/173091


More information about the Mlir-commits mailing list