[Mlir-commits] [mlir] [mlir] Add dialect hooks for registering custom type and attribute alias printers (PR #173091)
Fabian Mora
llvmlistbot at llvm.org
Sat Dec 20 12:14:12 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 {
+ }
----------------
fabianmcg wrote:
Note, that the current mechanism https://github.com/llvm/llvm-project/blob/main/mlir/lib/IR/AsmPrinter.cpp#L1223-L1233 is not scoped to its own entities.
The pattern you describe can be included, but it wouldn't help the `ptr` situation. So perhaps it makes more sense to settle the `!llvm.ptr` discussion first, and then comeback to this.
https://github.com/llvm/llvm-project/pull/173091
More information about the Mlir-commits
mailing list