Skip to content

Commit 22e2b80

Browse files
authored
[MLIR][UB] Add inliner interface for UB dialect (llvm#67115)
This revision adds an inliner interface to the UB dialect that allows inlining of `ub.poison` operations.
1 parent ec1d811 commit 22e2b80

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

mlir/lib/Dialect/UB/IR/UBOps.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "mlir/Dialect/UB/IR/UBOps.h"
10+
#include "mlir/Transforms/InliningUtils.h"
1011

1112
#include "mlir/IR/Builders.h"
1213
#include "mlir/IR/DialectImplementation.h"
@@ -17,6 +18,19 @@
1718
using namespace mlir;
1819
using namespace mlir::ub;
1920

21+
namespace {
22+
/// This class defines the interface for handling inlining with UB
23+
/// operations.
24+
struct UBInlinerInterface : public DialectInlinerInterface {
25+
using DialectInlinerInterface::DialectInlinerInterface;
26+
27+
/// All UB ops can be inlined.
28+
bool isLegalToInline(Operation *, Region *, bool, IRMapping &) const final {
29+
return true;
30+
}
31+
};
32+
} // namespace
33+
2034
//===----------------------------------------------------------------------===//
2135
// UBDialect
2236
//===----------------------------------------------------------------------===//
@@ -30,6 +44,7 @@ void UBDialect::initialize() {
3044
#define GET_ATTRDEF_LIST
3145
#include "mlir/Dialect/UB/IR/UBOpsAttributes.cpp.inc"
3246
>();
47+
addInterfaces<UBInlinerInterface>();
3348
}
3449

3550
Operation *UBDialect::materializeConstant(OpBuilder &builder, Attribute value,

mlir/test/Dialect/UB/inlining.mlir

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: mlir-opt %s -inline -split-input-file | FileCheck %s
2+
3+
func.func @func() -> i32 {
4+
%0 = ub.poison : i32
5+
return %0 : i32
6+
}
7+
8+
// CHECK-LABEL: func @test_inline
9+
func.func @test_inline(%ptr : !llvm.ptr) -> i32 {
10+
// CHECK-NOT: call
11+
%0 = call @func() : () -> i32
12+
return %0 : i32
13+
}

0 commit comments

Comments
 (0)