Skip to content

Commit a778930

Browse files
authored
[mlir][linalg] Create a dedicated target for LinalgRelayoutInterface (llvm#128485)
Creates an interface target for `LinalgRelayoutInterface`. This is primarily to reduce the dependency of `Tensor` on `Linalg` to the required minimum. For context and rationale, see: * llvm#127668 Note, I also took the liberty of renaming `LinalgRelayoutInterface` as `RelayoutOpInterface` (removed `Linalg`, added `Op`).
1 parent 67056c2 commit a778930

File tree

7 files changed

+65
-11
lines changed

7 files changed

+65
-11
lines changed

mlir/include/mlir/Dialect/Linalg/IR/CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,22 @@ function(add_linalg_ods_yaml_gen yaml_ast_file output_file)
2525
set(LLVM_TARGET_DEPENDS ${LLVM_TARGET_DEPENDS} PARENT_SCOPE)
2626
endfunction()
2727

28+
# NOTE: `add_mlir_interface(interface)` adds `interface` as a dependency of
29+
# mlir-generic-headers, i.e.:
30+
# * mlir-generic-headers -> interface
31+
# In addition, we have an existing MLIR-wide dependency of:
32+
# * mlir-headers -> mlir-generic-headers.
33+
# Now, observe that:
34+
# 1. The targets below define _new_ dependencies for mlir-headers.
35+
# 2. Before the new targets are defined, `add_linalg_ods_yaml_gen` updates
36+
# LLVM_TARGET_DEPENDS.
37+
# 3. All tablegen targets pick-up LLVM_TARGET_DEPENDS.
38+
# In order to avoid cyclic dependencies, we need to invoke
39+
# `add_mlir_interface` (and update `mlir-generic-headers`) _before_
40+
# LLVM_TARGET_DEPENDS is updated and new dependencies for `mlir-headers` are
41+
# defined + added.
42+
add_mlir_interface(RelayoutOpInterface)
43+
2844
# NOTE: LLVM_TARGET_DEPENDS gets picked up by tablegen targets to add file
2945
# level dependencies. This is gross but CMake requires depending on both
3046
# targets and generated files, and it must be done when the custom target is
@@ -77,3 +93,4 @@ mlir_tablegen(LinalgInterfaces.h.inc -gen-op-interface-decls)
7793
mlir_tablegen(LinalgInterfaces.cpp.inc -gen-op-interface-defs)
7894
add_public_tablegen_target(MLIRLinalgInterfacesIncGen)
7995
add_dependencies(mlir-headers MLIRLinalgInterfacesIncGen)
96+

mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,4 +221,7 @@ LogicalResult verifyStructuredOpInterface(Operation *op);
221221
/// Include the generated interface declarations.
222222
#include "mlir/Dialect/Linalg/IR/LinalgInterfaces.h.inc"
223223

224+
/// Include the generated relayout interface declarations.
225+
#include "mlir/Dialect/Linalg/IR/RelayoutOpInterface.h.inc"
226+
224227
#endif // MLIR_DIALECT_LINALG_IR_LINALGINTERFACES_H_

mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.td

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -178,16 +178,6 @@ def LinalgConvolutionOpInterface : OpInterface<"ConvolutionOpInterface"> {
178178
];
179179
}
180180

181-
def LinalgRelayoutOpInterface : OpInterface<"RelayoutOpInterface"> {
182-
let description = [{
183-
A Linalg relayout-op is either linalg.pack or linalg.unpack.
184-
185-
While we could extend this interface with methods from Linalg_RelayoutOp,
186-
this is currently not needed and left as a TODO.
187-
}];
188-
let cppNamespace = "::mlir::linalg";
189-
}
190-
191181
def LinalgFillOpInterface : OpInterface<"FillOpInterface"> {
192182
let description = [{
193183
A fill operation is defined in general terms:

mlir/include/mlir/Dialect/Linalg/IR/LinalgRelayoutOps.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ include "mlir/Interfaces/DestinationStyleOpInterface.td"
2323
include "mlir/Interfaces/SideEffectInterfaces.td"
2424
include "mlir/Interfaces/InferTypeOpInterface.td"
2525
include "mlir/Dialect/Linalg/IR/LinalgInterfaces.td"
26+
include "mlir/Dialect/Linalg/IR/RelayoutOpInterface.td"
2627
include "mlir/IR/OpAsmInterface.td"
2728

2829
//===----------------------------------------------------------------------===//
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//===- RelayoutOpInterface.h - Relayout op interface ----------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file implements the operation interface for relayout ops.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef MLIR_DIALECT_RELAYOUTOPINTERFACE_H_
14+
#define MLIR_DIALECT_RELAYOUTOPINTERFACE_H_
15+
16+
#include "mlir/Dialect/Linalg/IR/RelayoutOpInterface.h.inc"
17+
18+
#endif // MLIR_DIALECT_RELAYOUTOPINTERFACE_H_
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//===- RelayoutOpInterface.td ----- Intrerface Declaration -*- tablegen -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LINALG_IR_RELAYOUTOPINTERFACE
10+
#define LINALG_IR_RELAYOUTOPINTERFACE
11+
12+
include "mlir/Interfaces/DestinationStyleOpInterface.td"
13+
include "mlir/IR/OpBase.td"
14+
15+
def LinalgRelayoutOpInterface : OpInterface<"RelayoutOpInterface"> {
16+
let description = [{
17+
A Linalg relayout-op is either linalg.pack or linalg.unpack.
18+
19+
While we could extend this interface with methods from Linalg_RelayoutOp,
20+
this is currently not needed and left as a TODO.
21+
}];
22+
let cppNamespace = "::mlir::linalg";
23+
}
24+
25+
#endif // LINALG_IR_RELAYOUTOPINTERFACE

mlir/lib/Dialect/Tensor/IR/TensorOps.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "mlir/Dialect/Arith/IR/Arith.h"
1111
#include "mlir/Dialect/Arith/Utils/Utils.h"
1212
#include "mlir/Dialect/Complex/IR/Complex.h"
13-
#include "mlir/Dialect/Linalg/IR/LinalgInterfaces.h"
13+
#include "mlir/Dialect/Linalg/IR/RelayoutOpInterface.h"
1414
#include "mlir/Dialect/Tensor/IR/Tensor.h"
1515
#include "mlir/Dialect/Utils/IndexingUtils.h"
1616
#include "mlir/Dialect/Utils/ReshapeOpsUtils.h"

0 commit comments

Comments
 (0)