diff --git a/mlir/lib/Dialect/Func/IR/FuncOps.cpp b/mlir/lib/Dialect/Func/IR/FuncOps.cpp --- a/mlir/lib/Dialect/Func/IR/FuncOps.cpp +++ b/mlir/lib/Dialect/Func/IR/FuncOps.cpp @@ -48,7 +48,7 @@ /// All call operations can be inlined. bool isLegalToInline(Operation *call, Operation *callable, bool wouldBeCloned) const final { - return true; + return !call->hasAttr("noinline"); } /// All operations can be inlined. diff --git a/mlir/test/Dialect/Func/inlining.mlir b/mlir/test/Dialect/Func/inlining.mlir new file mode 100644 --- /dev/null +++ b/mlir/test/Dialect/Func/inlining.mlir @@ -0,0 +1,40 @@ +// RUN: mlir-opt -split-input-file -inline %s | FileCheck %s + +// CHECK-LABEL: func.func @foo() -> memref<32x8xf32> { +// CHECK: %[[VAL_0:.*]] = call @bar() {noinline} : () -> memref<32x8xf32> +// CHECK: return %[[VAL_0]] : memref<32x8xf32> +// CHECK: } + +// CHECK-LABEL: func.func private @bar() -> memref<32x8xf32> { +// CHECK: %[[VAL_0:.*]] = memref.alloc() : memref<32x8xf32> +// CHECK: return %[[VAL_0]] : memref<32x8xf32> +// CHECK: } + +module { + func.func @foo() -> memref<32x8xf32> { + %0 = call @bar() {noinline} : () -> memref<32x8xf32> + return %0 : memref<32x8xf32> + } + func.func private @bar() -> memref<32x8xf32> { + %0 = memref.alloc() : memref<32x8xf32> + return %0 : memref<32x8xf32> + } +} + +// ----- + +// CHECK-LABEL: func.func @foo() -> memref<32x8xf32> { +// CHECK: %[[VAL_0:.*]] = memref.alloc() : memref<32x8xf32> +// CHECK: return %[[VAL_0]] : memref<32x8xf32> +// CHECK: } + +module { + func.func @foo() -> memref<32x8xf32> { + %0 = call @bar() : () -> memref<32x8xf32> + return %0 : memref<32x8xf32> + } + func.func private @bar() -> memref<32x8xf32> { + %0 = memref.alloc() : memref<32x8xf32> + return %0 : memref<32x8xf32> + } +}