[Mlir-commits] [mlir] [mlir] Add dialect hooks for registering custom type and attribute alias printers (PR #173091)
Mehdi Amini
llvmlistbot at llvm.org
Sat Dec 20 09:35:04 PST 2025
================
@@ -1799,6 +1812,30 @@ class OpAsmDialectInterface
return AliasResult::NoAlias;
}
+ /// Hooks for registering alias printers for types and attributes. These
+ /// printers are invoked when printing types or attributes of the given
+ /// TypeID. Printers are invoked in the order they are registered, and the
+ /// first one to print an alias is used.
+ /// The precedence of these printers is as follow:
+ /// 1. The type and attribute aliases returned by `getAlias`.
+ /// 2. Dialect-specific alias printers registered here.
+ /// 3. The type and attribute printers.
+ /// The boolean argument to the printer indicates whether the stripped form
+ /// of the type or attribute is being printed.
+ /// NOTE: This mechanism caches the printed object, therefore the printer
+ /// must always produce the same output for the same input.
+ using AttributeAliasPrinter =
+ llvm::function_ref<void(Attribute, AsmPrinter &, bool)>;
+ using InsertAttrAliasPrinter =
+ llvm::function_ref<void(TypeID, AttributeAliasPrinter)>;
+ virtual void registerAttrAliasPrinter(InsertAttrAliasPrinter insertFn) const {
+ }
+ using TypeAliasPrinter = llvm::function_ref<void(Type, AsmPrinter &, bool)>;
+ using InsertTypeAliasPrinter =
+ llvm::function_ref<void(TypeID, TypeAliasPrinter)>;
+ virtual void registerTypeAliasPrinter(InsertTypeAliasPrinter insertFn) const {
+ }
----------------
joker-eph wrote:
Sure but what I'm describing is sticking to the pattern of
```
if (auto *interface = dyn_cast<OpAsmDialectInterface>(typeOrAtr->getDialect())) {
if (interface->tryPrintAlias(typeOrAttr))
return;
}
...
```
Each dialect their own entities.
https://github.com/llvm/llvm-project/pull/173091
More information about the Mlir-commits
mailing list