Skip to content

Commit

Permalink
[MLIR][UB] Add inliner interface for UB dialect (#67115)
Browse files Browse the repository at this point in the history
This revision adds an inliner interface to the UB dialect that allows
inlining of `ub.poison` operations.
  • Loading branch information
Dinistro committed Sep 22, 2023
1 parent ec1d811 commit 22e2b80
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
15 changes: 15 additions & 0 deletions mlir/lib/Dialect/UB/IR/UBOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//

#include "mlir/Dialect/UB/IR/UBOps.h"
#include "mlir/Transforms/InliningUtils.h"

#include "mlir/IR/Builders.h"
#include "mlir/IR/DialectImplementation.h"
Expand All @@ -17,6 +18,19 @@
using namespace mlir;
using namespace mlir::ub;

namespace {
/// This class defines the interface for handling inlining with UB
/// operations.
struct UBInlinerInterface : public DialectInlinerInterface {
using DialectInlinerInterface::DialectInlinerInterface;

/// All UB ops can be inlined.
bool isLegalToInline(Operation *, Region *, bool, IRMapping &) const final {
return true;
}
};
} // namespace

//===----------------------------------------------------------------------===//
// UBDialect
//===----------------------------------------------------------------------===//
Expand All @@ -30,6 +44,7 @@ void UBDialect::initialize() {
#define GET_ATTRDEF_LIST
#include "mlir/Dialect/UB/IR/UBOpsAttributes.cpp.inc"
>();
addInterfaces<UBInlinerInterface>();
}

Operation *UBDialect::materializeConstant(OpBuilder &builder, Attribute value,
Expand Down
13 changes: 13 additions & 0 deletions mlir/test/Dialect/UB/inlining.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// RUN: mlir-opt %s -inline -split-input-file | FileCheck %s

func.func @func() -> i32 {
%0 = ub.poison : i32
return %0 : i32
}

// CHECK-LABEL: func @test_inline
func.func @test_inline(%ptr : !llvm.ptr) -> i32 {
// CHECK-NOT: call
%0 = call @func() : () -> i32
return %0 : i32
}

0 comments on commit 22e2b80

Please sign in to comment.