Skip to content

Commit 240672b

Browse files
committed
Add no-inline attribute
1 parent 1cb8314 commit 240672b

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

mlir/include/mlir/Dialect/Func/IR/FuncOps.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ def CallOp : Func_Op<"call",
9898
void setCalleeFromCallable(CallInterfaceCallable callee) {
9999
(*this)->setAttr("callee", callee.get<SymbolRefAttr>());
100100
}
101+
102+
bool legalToInline() {
103+
return !(*this)->hasAttr("noinline");
104+
}
101105
}];
102106

103107
let assemblyFormat = [{

mlir/include/mlir/Interfaces/CallInterfaces.td

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ def CallOpInterface : OpInterface<"CallOpInterface"> {
8080
/*methodBody=*/[{}], /*defaultImplementation=*/[{
8181
return ::mlir::call_interface_impl::resolveCallable($_op);
8282
}]
83+
>,
84+
InterfaceMethod<[{
85+
Return whether a given call is legal to inline or not (assuming all other requirements are met,
86+
like the callee is direct, the parent region supports multiple blocks and the resolved, etc).
87+
This can be used to implement a `noinline`-like attribute.
88+
}],
89+
"bool", "legalToInline", (ins),
90+
/*methodBody=*/[{}], /*defaultImplementation=*/[{
91+
return true;
92+
}]
8393
>
8494
];
8595
}

mlir/lib/Transforms/Utils/Inliner.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,10 @@ bool Inliner::Impl::shouldInline(ResolvedCall &resolvedCall) {
712712
if (resolvedCall.call->hasTrait<OpTrait::IsTerminator>())
713713
return false;
714714

715+
// Don't inline calls which explicitly forbit inlining.
716+
if (!resolvedCall.call.legalToInline())
717+
return false;
718+
715719
// Don't allow inlining if the target is a self-recursive function.
716720
if (llvm::count_if(*resolvedCall.targetNode,
717721
[&](CallGraphNode::Edge const &edge) -> bool {

mlir/test/Transforms/inlining.mlir

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ func.func @inline_with_arg(%arg0 : i32) -> i32 {
1919
return %0 : i32
2020
}
2121

22+
// CHECK-LABEL: func @noinline_with_arg
23+
func.func @noinline_with_arg(%arg0 : i32) -> i32 {
24+
// CHECK-NEXT: func_with_arg
25+
// CHECK-NEXT: return
26+
27+
%0 = call @func_with_arg(%arg0) {"noinline"=""} : (i32) -> i32
28+
return %0 : i32
29+
}
30+
2231
// Inline a function that has multiple return operations.
2332
func.func @func_with_multi_return(%a : i1) -> (i32) {
2433
cf.cond_br %a, ^bb1, ^bb2

0 commit comments

Comments
 (0)