[mlir] Allow to override type/attr aliases from various hooks
authorVladislav Vinogradov <vlad.vinogradov@intel.com>
Tue, 3 Aug 2021 14:23:31 +0000 (17:23 +0300)
committerVladislav Vinogradov <vlad.vinogradov@intel.com>
Fri, 6 Aug 2021 09:05:31 +0000 (12:05 +0300)
commit59f59d1c621cf6844c41fd92ad32a897fc9d10bd
treeb6c49d68ae276c83a8be47e13a6012cc28309068
parent0fd03feb4ba5d86835ac386eebe16cbc3cfb36ec
[mlir] Allow to override type/attr aliases from various hooks

Use new return type for `OpAsmDialectInterface::getAlias`:

* `AliasResult::NoAlias` if an alias was not provided.
* `AliasResult::OverridableAlias` if an alias was provided, but it might be overriden by other hook.
* `AliasResult::FinalAlias` if an alias was provided and it should be used (no other hooks will be checked).

In that case `AsmPrinter` will use either the first alias with `FinalAlias` result or
the last alias with `OverridableAlias` result (it depends on dialect array order).

Used `OverridableAlias` result for `BuiltinOpAsmDialectInterface`.

Use case: provide more informative alias for built-in attributes like `AffineMapAttr`
instead of generic "map<N>".

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D107437
mlir/include/mlir/IR/OpImplementation.h
mlir/lib/IR/AsmPrinter.cpp
mlir/lib/IR/BuiltinDialect.cpp
mlir/test/IR/print-attr-type-aliases.mlir
mlir/test/lib/Dialect/Test/TestDialect.cpp