[Mlir-commits] [mlir] [mlir][MLProgram][NFC] Migrate to OpAsmAttrInterface for ASM alias generation (PR #130481)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sun Mar 9 04:02:20 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-mlprogram
Author: Hongren Zheng (ZenithalHourlyRate)
<details>
<summary>Changes</summary>
After the introduction of `OpAsmAttrInterface`, it is favorable to migrate code using `OpAsmDialectInterface` for ASM alias generation, which lives in `Dialect.cpp`, to use `OpAsmAttrInterface`, which lives in `Attrs.td`. In this way, attribute behavior is placed near its tablegen definition and people won't need to go through other files to know what other (unexpected) hooks comes into play.
See #<!-- -->124721 for the interface itself and #<!-- -->128191 and #<!-- -->130479 for prior migrations.
Note that `MLProgramOpAsmInterface` has no content now. However, if we delete it, a failure related to dialect resource handling will occur
```
within split at llvm-project/mlir/test/IR/invalid-file-metadata.mlir:60 offset :7:7: error: unexpected error: unexpected 'resource' section for dialect 'ml_program'
```
To support resource such interface must be registered.
---
Full diff: https://github.com/llvm/llvm-project/pull/130481.diff
2 Files Affected:
- (modified) mlir/include/mlir/Dialect/MLProgram/IR/MLProgramAttributes.td (+13-1)
- (modified) mlir/lib/Dialect/MLProgram/IR/MLProgramDialect.cpp (-8)
``````````diff
diff --git a/mlir/include/mlir/Dialect/MLProgram/IR/MLProgramAttributes.td b/mlir/include/mlir/Dialect/MLProgram/IR/MLProgramAttributes.td
index eb6e293bbf4f6..2dc5727060064 100644
--- a/mlir/include/mlir/Dialect/MLProgram/IR/MLProgramAttributes.td
+++ b/mlir/include/mlir/Dialect/MLProgram/IR/MLProgramAttributes.td
@@ -11,6 +11,7 @@
include "mlir/IR/AttrTypeBase.td"
include "mlir/IR/BuiltinAttributeInterfaces.td"
+include "mlir/IR/OpAsmInterface.td"
include "mlir/Dialect/MLProgram/IR/MLProgramBase.td"
// Base class for MLProgram dialect attributes.
@@ -23,7 +24,7 @@ class MLProgram_Attr<string name, list<Trait> traits = []>
// ExternAttr
//===----------------------------------------------------------------------===//
-def MLProgram_ExternAttr : MLProgram_Attr<"Extern", [TypedAttrInterface]> {
+def MLProgram_ExternAttr : MLProgram_Attr<"Extern", [TypedAttrInterface, OpAsmAttrInterface]> {
let summary = "Value used for a global signalling external resolution";
let description = [{
When used as the value for a GlobalOp, this indicates that the actual
@@ -40,6 +41,17 @@ def MLProgram_ExternAttr : MLProgram_Attr<"Extern", [TypedAttrInterface]> {
let parameters = (ins AttributeSelfTypeParameter<"">:$type);
let mnemonic = "extern";
let assemblyFormat = "";
+
+ let extraClassDeclaration = [{
+ //===------------------------------------------------------------------===//
+ // OpAsmAttrInterface Methods
+ //===------------------------------------------------------------------===//
+
+ ::mlir::OpAsmAliasResult getAlias(::llvm::raw_ostream &os) const {
+ os << "}] # mnemonic # [{";
+ return ::mlir::OpAsmAliasResult::OverridableAlias;
+ }
+ }];
}
#endif // MLPROGRAM_ATTRIBUTES
diff --git a/mlir/lib/Dialect/MLProgram/IR/MLProgramDialect.cpp b/mlir/lib/Dialect/MLProgram/IR/MLProgramDialect.cpp
index bda1032ed9884..0b1561213165b 100644
--- a/mlir/lib/Dialect/MLProgram/IR/MLProgramDialect.cpp
+++ b/mlir/lib/Dialect/MLProgram/IR/MLProgramDialect.cpp
@@ -39,14 +39,6 @@ struct MLProgramInlinerInterface : public DialectInlinerInterface {
struct MLProgramOpAsmDialectInterface : public OpAsmDialectInterface {
using OpAsmDialectInterface::OpAsmDialectInterface;
-
- AliasResult getAlias(Attribute attr, raw_ostream &os) const override {
- if (llvm::isa<ExternAttr>(attr)) {
- os << "extern";
- return AliasResult::OverridableAlias;
- }
- return AliasResult::NoAlias;
- }
};
} // namespace
``````````
</details>
https://github.com/llvm/llvm-project/pull/130481
More information about the Mlir-commits
mailing list