Skip to content

Commit ca49739

Browse files
authored
[mlir][mesh] Introduce DialectInlinerInterface for Mesh dialect (#108297)
The inliner interface does not implement any restrictions for inlining.
1 parent b7914df commit ca49739

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

mlir/lib/Dialect/Mesh/IR/MeshOps.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "mlir/IR/Value.h"
2525
#include "mlir/Interfaces/ViewLikeInterface.h"
2626
#include "mlir/Support/LLVM.h"
27+
#include "mlir/Transforms/InliningUtils.h"
2728
#include "llvm/ADT/ArrayRef.h"
2829
#include "llvm/ADT/STLExtras.h"
2930
#include "llvm/ADT/SmallSet.h"
@@ -74,6 +75,26 @@ static DimensionSize operator*(DimensionSize lhs, DimensionSize rhs) {
7475
return lhs.value() * rhs.value();
7576
}
7677

78+
//===----------------------------------------------------------------------===//
79+
// Inliner
80+
//===----------------------------------------------------------------------===//
81+
82+
namespace {
83+
struct MeshInlinerInterface : public DialectInlinerInterface {
84+
using DialectInlinerInterface::DialectInlinerInterface;
85+
// Currently no restrictions are encoded for inlining.
86+
bool isLegalToInline(Operation *, Operation *, bool) const final {
87+
return true;
88+
}
89+
bool isLegalToInline(Region *, Region *, bool, IRMapping &) const final {
90+
return true;
91+
}
92+
bool isLegalToInline(Operation *, Region *, bool, IRMapping &) const final {
93+
return true;
94+
}
95+
};
96+
} // namespace
97+
7798
//===----------------------------------------------------------------------===//
7899
// Mesh dialect
79100
//===----------------------------------------------------------------------===//
@@ -91,6 +112,7 @@ void MeshDialect::initialize() {
91112
#define GET_TYPEDEF_LIST
92113
#include "mlir/Dialect/Mesh/IR/MeshTypes.cpp.inc"
93114
>();
115+
addInterface<MeshInlinerInterface>();
94116
}
95117

96118
Operation *MeshDialect::materializeConstant(OpBuilder &builder, Attribute value,

mlir/test/Dialect/Mesh/inlining.mlir

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: mlir-opt -inline %s | FileCheck %s
2+
3+
mesh.mesh @mesh0(shape = 4x?x2)
4+
5+
func.func private @mesh_to_inline() -> (index, index) {
6+
%0:2 = mesh.mesh_shape @mesh0 axes = [2, 1] : index, index
7+
return %0#0, %0#1 : index, index
8+
}
9+
// CHECK-LABEL: func.func @main
10+
func.func @main() -> (index, index) {
11+
// CHECK-NEXT: %[[AXIS_SIZE:.*]]:2 = mesh.mesh_shape @mesh0 axes = [2, 1] : index
12+
%0:2 = func.call @mesh_to_inline() : () -> (index, index)
13+
// CHECK-NEXT: return %[[AXIS_SIZE]]#0, %[[AXIS_SIZE]]#1
14+
return %0#0, %0#1 : index, index
15+
}

0 commit comments

Comments
 (0)