Skip to content

[mlir] add noinline attribute to func.func/call #119970

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions mlir/include/mlir/Dialect/Func/IR/FuncOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def CallOp : Func_Op<"call",
```
}];

let arguments = (ins FlatSymbolRefAttr:$callee, Variadic<AnyType>:$operands);
let arguments = (ins FlatSymbolRefAttr:$callee, Variadic<AnyType>:$operands,
UnitAttr:$no_inline);
let results = (outs Variadic<AnyType>);

let builders = [
Expand Down Expand Up @@ -270,7 +271,8 @@ def FuncOp : Func_Op<"func", [
TypeAttrOf<FunctionType>:$function_type,
OptionalAttr<StrAttr>:$sym_visibility,
OptionalAttr<DictArrayAttr>:$arg_attrs,
OptionalAttr<DictArrayAttr>:$res_attrs);
OptionalAttr<DictArrayAttr>:$res_attrs,
UnitAttr:$no_inline);
let regions = (region AnyRegion:$body);

let builders = [OpBuilder<(ins
Expand Down
10 changes: 7 additions & 3 deletions mlir/lib/Dialect/Func/Extensions/InlinerExtension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,22 @@ struct FuncInlinerInterface : public DialectInlinerInterface {
// Analysis Hooks
//===--------------------------------------------------------------------===//

/// All call operations can be inlined.
/// Call operations can be inlined unless specified otherwise by attributes
/// on either the call or the callbale.
bool isLegalToInline(Operation *call, Operation *callable,
bool wouldBeCloned) const final {
return true;
auto callOp = dyn_cast<func::CallOp>(call);
auto funcOp = dyn_cast<func::FuncOp>(callable);
return !(callOp && callOp.getNoInline()) &&
!(funcOp && funcOp.getNoInline());
}

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

/// All functions can be inlined.
/// All function bodies can be inlined.
bool isLegalToInline(Region *, Region *, bool, IRMapping &) const final {
return true;
}
Expand Down
23 changes: 23 additions & 0 deletions mlir/test/Transforms/inlining.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,29 @@ func.func @inline_with_arg(%arg0 : i32) -> i32 {
return %0 : i32
}

// CHECK-LABEL: func @noinline_with_arg
func.func @noinline_with_arg(%arg0 : i32) -> i32 {
// CHECK-NEXT: func_with_arg
// CHECK-NEXT: return

%0 = call @func_with_arg(%arg0) {no_inline} : (i32) -> i32
return %0 : i32
}

func.func @non_inlinable_func_with_arg(%c : i32) -> i32 attributes {no_inline} {
%b = arith.addi %c, %c : i32
return %b : i32
}

// CHECK-LABEL: func @noinline_with_func_arg
func.func @noinline_with_func_arg(%arg0 : i32) -> i32 {
// CHECK-NEXT: non_inlinable_func_with_arg
// CHECK-NEXT: return

%0 = call @non_inlinable_func_with_arg(%arg0) : (i32) -> i32
return %0 : i32
}

// Inline a function that has multiple return operations.
func.func @func_with_multi_return(%a : i1) -> (i32) {
cf.cond_br %a, ^bb1, ^bb2
Expand Down
Loading