[Mlir-commits] [mlir] 22e2b80 - [MLIR][UB] Add inliner interface for UB dialect (#67115)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Sep 22 05:07:51 PDT 2023


Author: Christian Ulmann
Date: 2023-09-22T14:07:47+02:00
New Revision: 22e2b805ef3c4caa971fad3656976b6e0017aff3

URL: https://github.com/llvm/llvm-project/commit/22e2b805ef3c4caa971fad3656976b6e0017aff3
DIFF: https://github.com/llvm/llvm-project/commit/22e2b805ef3c4caa971fad3656976b6e0017aff3.diff

LOG: [MLIR][UB] Add inliner interface for UB dialect (#67115)

This revision adds an inliner interface to the UB dialect that allows
inlining of `ub.poison` operations.

Added: 
    mlir/test/Dialect/UB/inlining.mlir

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

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/UB/IR/UBOps.cpp b/mlir/lib/Dialect/UB/IR/UBOps.cpp
index d63da90e16195f1..e0cd5dafcfa61eb 100644
--- a/mlir/lib/Dialect/UB/IR/UBOps.cpp
+++ b/mlir/lib/Dialect/UB/IR/UBOps.cpp
@@ -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"
@@ -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
 //===----------------------------------------------------------------------===//
@@ -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,

diff  --git a/mlir/test/Dialect/UB/inlining.mlir b/mlir/test/Dialect/UB/inlining.mlir
new file mode 100644
index 000000000000000..cb76750044a3b8f
--- /dev/null
+++ b/mlir/test/Dialect/UB/inlining.mlir
@@ -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
+}


        


More information about the Mlir-commits mailing list