[Mlir-commits] [mlir] [mlir] Introduce OpAsmAttrInterface for pretty-print (PR #124721)
Hongren Zheng
llvmlistbot at llvm.org
Mon Feb 3 20:45:02 PST 2025
================
@@ -1159,15 +1160,31 @@ template <typename T>
void AliasInitializer::generateAlias(T symbol, InProgressAliasInfo &alias,
bool canBeDeferred) {
SmallString<32> nameBuffer;
- for (const auto &interface : interfaces) {
- OpAsmDialectInterface::AliasResult result =
- interface.getAlias(symbol, aliasOS);
- if (result == OpAsmDialectInterface::AliasResult::NoAlias)
- continue;
- nameBuffer = std::move(aliasBuffer);
- assert(!nameBuffer.empty() && "expected valid alias name");
- if (result == OpAsmDialectInterface::AliasResult::FinalAlias)
- break;
+
+ OpAsmDialectInterface::AliasResult symbolInterfaceResult =
+ OpAsmDialectInterface::AliasResult::NoAlias;
+ if constexpr (std::is_base_of_v<Attribute, T>) {
+ if (auto symbolInterface = mlir::dyn_cast<OpAsmAttrInterface>(symbol)) {
----------------
ZenithalHourlyRate wrote:
The type variant of getAlias does exist but when we `mlir::dyn_cast<OpAsmAttrInterface>(Type)` MLIR will segfault so I guard it with `if constexpr (std::is_base_of_v<Attribute, T>)`.
When another PR introducing `getAlias` method for `OpAsmTypeInterface`, the code here would be
```cpp
if constexpr (std::is_base_of_v<Attribute, T>) {
if (auto symbolInterface = mlir::dyn_cast<OpAsmAttrInterface>(symbol)) {
...
}
} else if constexpr (std::is_base_of_v<Type, T>) {
if (auto symbolInterface = mlir::dyn_cast<OpAsmTypeInterface>(symbol)) {
...
}
}
```
https://github.com/llvm/llvm-project/pull/124721
More information about the Mlir-commits
mailing list