[Mlir-commits] [mlir] [mlir] Add the concept of ASM dialect aliases (PR #86033)

Markus Böck llvmlistbot at llvm.org
Thu Mar 28 05:48:22 PDT 2024


================
@@ -0,0 +1,60 @@
+//===- AsmInterfaces.td - Asm Interfaces -------------------*- tablegen -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file contains interfaces and other utilities for interacting with the
+// AsmParser and AsmPrinter.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef MLIR_IR_ASMINTERFACES_TD
+#define MLIR_IR_ASMINTERFACES_TD
+
+include "mlir/IR/AttrTypeBase.td"
+include "mlir/IR/OpBase.td"
+
+//===----------------------------------------------------------------------===//
+// AttrAsmAliasAttrInterface
+//===----------------------------------------------------------------------===//
+
+def AttrAsmAliasAttrInterface : AttrInterface<"AttrAsmAliasAttrInterface"> {
+  let cppNamespace = "::mlir";
+  let description = [{
+    This interface allows aliasing an attribute between dialects, allowing
+    custom printing of an attribute by an external dialect.
+  }];
+  let methods = [
+    InterfaceMethod<[{
+        Returns the dialect responsible for printing and parsing the attribute
+        instance.
+      }],
+      "Dialect*", "getAliasDialect", (ins), [{}], [{}]
+    >
+  ];
+}
+
+//===----------------------------------------------------------------------===//
+// TypeAsmAliasTypeInterface
+//===----------------------------------------------------------------------===//
+
+def TypeAsmAliasTypeInterface : TypeInterface<"TypeAsmAliasTypeInterface"> {
+  let cppNamespace = "::mlir";
+  let description = [{
+    This interface allows aliasing a type between dialects, allowing custom
+    printing of a type by an external dialect.
+  }];
+  let methods = [
+    InterfaceMethod<[{
+        Returns the dialect responsible for printing and parsing the type
+        instance.
+      }],
+      "Dialect*", "getAliasDialect", (ins), [{}], [{}]
----------------
zero9178 wrote:

The default implementation here creates code causing undefiend behaviour by default, which is probably undesirable. 
I think it'd make sense for either 1) there not being a default, forcing types to implement this method (given its the only method, this seems to make the most sense to me, 2) return nullptr and e.g. document that this signifies no change in dialect (or whatever other meaning you think makes sense) or 3) return `&this->getDialect()` by default

https://github.com/llvm/llvm-project/pull/86033


More information about the Mlir-commits mailing list