[Mlir-commits] [mlir] [mlir][linalg] Create a dedicated target for LinalgRelayoutInterface (PR #127541)

Andrzej WarzyƄski llvmlistbot at llvm.org
Mon Feb 17 12:19:07 PST 2025


https://github.com/banach-space created https://github.com/llvm/llvm-project/pull/127541

For context and rationale, see:
  * https://github.com/llvm/llvm-project/pull/127533


>From ead6574b3de9ec752c7a87a5af8449296657c769 Mon Sep 17 00:00:00 2001
From: Andrzej Warzynski <andrzej.warzynski at arm.com>
Date: Mon, 17 Feb 2025 20:17:28 +0000
Subject: [PATCH] [mlir][linalg] Create a dedicated target for
 LinalgRelayoutInterface

For context and rationale, see:
  * https://github.com/llvm/llvm-project/pull/127533
---
 .../mlir/Dialect/Linalg/IR/CMakeLists.txt     |  6 +++++
 .../mlir/Dialect/Linalg/IR/LinalgInterfaces.h |  3 +++
 .../Dialect/Linalg/IR/LinalgInterfaces.td     | 10 --------
 .../Linalg/IR/LinalgRelayoutInterface.td      | 25 +++++++++++++++++++
 .../Dialect/Linalg/IR/LinalgRelayoutOps.td    |  1 +
 mlir/lib/Dialect/Tensor/IR/TensorOps.cpp      |  2 +-
 6 files changed, 36 insertions(+), 11 deletions(-)
 create mode 100644 mlir/include/mlir/Dialect/Linalg/IR/LinalgRelayoutInterface.td

diff --git a/mlir/include/mlir/Dialect/Linalg/IR/CMakeLists.txt b/mlir/include/mlir/Dialect/Linalg/IR/CMakeLists.txt
index efd708c5e5a11..103d9dee43df5 100644
--- a/mlir/include/mlir/Dialect/Linalg/IR/CMakeLists.txt
+++ b/mlir/include/mlir/Dialect/Linalg/IR/CMakeLists.txt
@@ -72,6 +72,12 @@ add_public_tablegen_target(MLIRLinalgRelayoutOpsIncGen)
 add_dependencies(MLIRLinalgRelayoutOpsIncGen LinalgOdsGen)
 add_dependencies(mlir-headers MLIRLinalgRelayoutOpsIncGen)
 
+set(LLVM_TARGET_DEFINITIONS LinalgRelayoutInterface.td)
+mlir_tablegen(LinalgRelayoutInterface.h.inc -gen-op-interface-decls)
+mlir_tablegen(LinalgRelayoutInterface.cpp.inc -gen-op-interface-defs)
+add_public_tablegen_target(MLIRLinalgRelayoutInterfaceIncGen)
+add_dependencies(mlir-headers MLIRLinalgRelayoutInterfaceIncGen)
+
 set(LLVM_TARGET_DEFINITIONS LinalgInterfaces.td)
 mlir_tablegen(LinalgInterfaces.h.inc -gen-op-interface-decls)
 mlir_tablegen(LinalgInterfaces.cpp.inc -gen-op-interface-defs)
diff --git a/mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.h b/mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.h
index 6f1c243cc4396..530d6451b0a1e 100644
--- a/mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.h
+++ b/mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.h
@@ -221,4 +221,7 @@ LogicalResult verifyStructuredOpInterface(Operation *op);
 /// Include the generated interface declarations.
 #include "mlir/Dialect/Linalg/IR/LinalgInterfaces.h.inc"
 
+/// Include the generated relayout interface declarations.
+#include "mlir/Dialect/Linalg/IR/LinalgRelayoutInterface.h.inc"
+
 #endif // MLIR_DIALECT_LINALG_IR_LINALGINTERFACES_H_
diff --git a/mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.td b/mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.td
index 247afc141c180..dbc1ac60e0973 100644
--- a/mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.td
+++ b/mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.td
@@ -178,16 +178,6 @@ def LinalgConvolutionOpInterface : OpInterface<"ConvolutionOpInterface"> {
   ];
 }
 
-def LinalgRelayoutOpInterface : OpInterface<"RelayoutOpInterface"> {
-  let description = [{
-    A Linalg relayout-op is either linalg.pack or linalg.unpack.
-
-    While we could extend this interface with methods from Linalg_RelayoutOp,
-    this is currently not needed and left as a TODO.
-  }];
-  let cppNamespace = "::mlir::linalg";
-}
-
 def LinalgFillOpInterface : OpInterface<"FillOpInterface"> {
   let description = [{
     A fill operation is defined in general terms:
diff --git a/mlir/include/mlir/Dialect/Linalg/IR/LinalgRelayoutInterface.td b/mlir/include/mlir/Dialect/Linalg/IR/LinalgRelayoutInterface.td
new file mode 100644
index 0000000000000..0e925a6a832e0
--- /dev/null
+++ b/mlir/include/mlir/Dialect/Linalg/IR/LinalgRelayoutInterface.td
@@ -0,0 +1,25 @@
+//===- LinalgInterfaces.td - Linalg Interfaces Declaration -*- 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LINALG_IR_LINALGRELAYOUTINTERFACE
+#define LINALG_IR_LINALGRELAYOUTINTERFACE
+
+include "mlir/Interfaces/DestinationStyleOpInterface.td"
+include "mlir/IR/OpBase.td"
+
+def LinalgRelayoutOpInterface : OpInterface<"RelayoutOpInterface"> {
+  let description = [{
+    A Linalg relayout-op is either linalg.pack or linalg.unpack.
+
+    While we could extend this interface with methods from Linalg_RelayoutOp,
+    this is currently not needed and left as a TODO.
+  }];
+  let cppNamespace = "::mlir::linalg";
+}
+
+#endif // LINALG_IR_LINALGRELAYOUTINTERFACE
diff --git a/mlir/include/mlir/Dialect/Linalg/IR/LinalgRelayoutOps.td b/mlir/include/mlir/Dialect/Linalg/IR/LinalgRelayoutOps.td
index a08a778fc25e1..7743b8c00886f 100644
--- a/mlir/include/mlir/Dialect/Linalg/IR/LinalgRelayoutOps.td
+++ b/mlir/include/mlir/Dialect/Linalg/IR/LinalgRelayoutOps.td
@@ -23,6 +23,7 @@ include "mlir/Interfaces/DestinationStyleOpInterface.td"
 include "mlir/Interfaces/SideEffectInterfaces.td"
 include "mlir/Interfaces/InferTypeOpInterface.td"
 include "mlir/Dialect/Linalg/IR/LinalgInterfaces.td"
+include "mlir/Dialect/Linalg/IR/LinalgRelayoutInterface.td"
 include "mlir/IR/OpAsmInterface.td"
 
 //===----------------------------------------------------------------------===//
diff --git a/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp b/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp
index e741144647043..7aad4611fbfaf 100644
--- a/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp
+++ b/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp
@@ -10,7 +10,7 @@
 #include "mlir/Dialect/Arith/IR/Arith.h"
 #include "mlir/Dialect/Arith/Utils/Utils.h"
 #include "mlir/Dialect/Complex/IR/Complex.h"
-#include "mlir/Dialect/Linalg/IR/Linalg.h"
+#include "mlir/Dialect/Linalg/IR/LinalgRelayoutInterface.h.inc"
 #include "mlir/Dialect/Tensor/IR/Tensor.h"
 #include "mlir/Dialect/Tensor/Utils/Utils.h"
 #include "mlir/Dialect/Utils/IndexingUtils.h"



More information about the Mlir-commits mailing list