-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
[mlir] add noinline attribute to func.func/call #119970
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This allows for inlining to be somewhat controlled by the user instead of always inlining everything. External heuristics may be used to place `no_inline` attributes on invidiual calls or functions to prevent inlining.
@llvm/pr-subscribers-mlir-func @llvm/pr-subscribers-mlir Author: Oleksandr "Alex" Zinenko (ftynse) ChangesThis allows for inlining to be somewhat controlled by the user instead of always inlining everything. External heuristics may be used to place Full diff: https://github.com/llvm/llvm-project/pull/119970.diff 3 Files Affected:
diff --git a/mlir/include/mlir/Dialect/Func/IR/FuncOps.td b/mlir/include/mlir/Dialect/Func/IR/FuncOps.td
index 22efe15aa83a50..237a825c191042 100644
--- a/mlir/include/mlir/Dialect/Func/IR/FuncOps.td
+++ b/mlir/include/mlir/Dialect/Func/IR/FuncOps.td
@@ -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 = [
@@ -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
diff --git a/mlir/lib/Dialect/Func/Extensions/InlinerExtension.cpp b/mlir/lib/Dialect/Func/Extensions/InlinerExtension.cpp
index 719a74a29a6221..3328d58551bff1 100644
--- a/mlir/lib/Dialect/Func/Extensions/InlinerExtension.cpp
+++ b/mlir/lib/Dialect/Func/Extensions/InlinerExtension.cpp
@@ -27,10 +27,14 @@ 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.
@@ -38,7 +42,7 @@ struct FuncInlinerInterface : public DialectInlinerInterface {
return true;
}
- /// All functions can be inlined.
+ /// All function bodies can be inlined.
bool isLegalToInline(Region *, Region *, bool, IRMapping &) const final {
return true;
}
diff --git a/mlir/test/Transforms/inlining.mlir b/mlir/test/Transforms/inlining.mlir
index 79a2936b104fa1..65ffaad1fa859c 100644
--- a/mlir/test/Transforms/inlining.mlir
+++ b/mlir/test/Transforms/inlining.mlir
@@ -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
|
wsmoses
approved these changes
Dec 14, 2024
raikonenfnu
added a commit
to iree-org/llvm-project
that referenced
this pull request
Dec 17, 2024
This reverts commit d072ca1.
This was referenced Dec 17, 2024
raikonenfnu
added a commit
to iree-org/iree
that referenced
this pull request
Dec 17, 2024
Update LLVM to llvm/llvm-project@3f136f7 (#19479) Carrying the following reverts - llvm/llvm-project#116470 - llvm/llvm-project#117424 - llvm/llvm-project#119671 - llvm/llvm-project#119970 First two are carry over from previous-previous integrate. It is being fixed in #19451 . The last one is a from the previous integrate. The last one is a new error being tracked in #19498 --------- Signed-off-by: Stanley Winata <stanley.winata@amd.com>
raikonenfnu
added a commit
to raikonenfnu/iree
that referenced
this pull request
Dec 17, 2024
Update LLVM to llvm/llvm-project@b07e7b76c5d532a6 (llvm/llvm-project#120002) Carrying the following reverts - llvm/llvm-project#116470 - llvm/llvm-project#117424 - llvm/llvm-project#119671 - llvm/llvm-project#119970 First two are carry over from previous-previous integrate. It is being fixed in iree-org#19451 . The last one is a from the previous integrate. The last one is a new error being tracked in iree-org#19498 Signed-off-by: Stanley Winata <stanley.winata@amd.com>
raikonenfnu
added a commit
to raikonenfnu/iree
that referenced
this pull request
Dec 17, 2024
Update LLVM to llvm/llvm-project@b07e7b76c5d532a6 (llvm/llvm-project#120002) Carrying the following reverts - llvm/llvm-project#116470 - llvm/llvm-project#117424 - llvm/llvm-project#119671 - llvm/llvm-project#119970 First two are carry over from previous-previous integrate. It is being fixed in iree-org#19451 . The last one is a from the previous integrate. The last one is a new error being tracked in iree-org#19498 Signed-off-by: Stanley Winata <stanley.winata@amd.com>
MaheshRavishankar
pushed a commit
to iree-org/llvm-project
that referenced
this pull request
Dec 17, 2024
This reverts commit d072ca1.
raikonenfnu
added a commit
to iree-org/llvm-project
that referenced
this pull request
Dec 18, 2024
This reverts commit d072ca1.
raikonenfnu
added a commit
to iree-org/llvm-project
that referenced
this pull request
Dec 20, 2024
This reverts commit d072ca1.
raikonenfnu
added a commit
to raikonenfnu/iree
that referenced
this pull request
Dec 20, 2024
Changes in C++ mostly handle changes done in llvm/llvm-project@4b56345 that combines SCFTilingResult and SCFReductionTilingResult. This PR also carries the following reverts - llvm/llvm-project#119671 - llvm/llvm-project#119970 The first one is a from the previous integrate. The last one is a new error being tracked in iree-org#19498. Signed-off-by: Stanley Winata <stanley.winata@amd.com>
raikonenfnu
added a commit
to raikonenfnu/iree
that referenced
this pull request
Dec 20, 2024
Changes in C++ mostly handle changes done in llvm/llvm-project@4b56345 that combines SCFTilingResult and SCFReductionTilingResult. This PR also carries the following reverts - llvm/llvm-project#119671 - llvm/llvm-project#119970 The first one is a from the previous integrate. The last one is a new error being tracked in iree-org#19498. Signed-off-by: Stanley Winata <stanley.winata@amd.com>
raikonenfnu
added a commit
to raikonenfnu/iree
that referenced
this pull request
Dec 20, 2024
Changes in C++ mostly handle changes done in llvm/llvm-project@4b56345 that combines SCFTilingResult and SCFReductionTilingResult. This PR also carries the following reverts - llvm/llvm-project#119970 The issue related to the revert is being tracked in iree-org#19498. Signed-off-by: Stanley Winata <stanley.winata@amd.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This allows for inlining to be somewhat controlled by the user instead of always inlining everything. External heuristics may be used to place
no_inline
attributes on invidiual calls or functions to prevent inlining.