-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Add flags customizing behaviour of MIR inlining #78873
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Checks that inlining threshold can be controlled with | ||
// inline-mir-threshold and inline-hint-threshold options. | ||
// | ||
// compile-flags: -Zinline-mir-threshold=90 | ||
// compile-flags: -Zinline-mir-hint-threshold=50 | ||
|
||
// EMIT_MIR inline_options.main.Inline.after.mir | ||
fn main() { | ||
not_inlined(); | ||
inlined::<u32>(); | ||
} | ||
|
||
// Cost is approximately 3 * 25 + 5 = 80. | ||
#[inline] | ||
pub fn not_inlined() { g(); g(); g(); } | ||
pub fn inlined<T>() { g(); g(); g(); } | ||
|
||
#[inline(never)] | ||
fn g() {} |
56 changes: 56 additions & 0 deletions
56
src/test/mir-opt/inline/inline_options.main.Inline.after.mir
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// MIR for `main` after Inline | ||
|
||
fn main() -> () { | ||
let mut _0: (); // return place in scope 0 at $DIR/inline-options.rs:8:11: 8:11 | ||
let _1: (); // in scope 0 at $DIR/inline-options.rs:9:5: 9:18 | ||
let _2: (); // in scope 0 at $DIR/inline-options.rs:10:5: 10:21 | ||
scope 1 (inlined inlined::<u32>) { // at $DIR/inline-options.rs:10:5: 10:21 | ||
let _3: (); // in scope 1 at $DIR/inline-options.rs:10:5: 10:21 | ||
let _4: (); // in scope 1 at $DIR/inline-options.rs:10:5: 10:21 | ||
let _5: (); // in scope 1 at $DIR/inline-options.rs:10:5: 10:21 | ||
} | ||
|
||
bb0: { | ||
StorageLive(_1); // scope 0 at $DIR/inline-options.rs:9:5: 9:18 | ||
_1 = not_inlined() -> bb1; // scope 0 at $DIR/inline-options.rs:9:5: 9:18 | ||
// mir::Constant | ||
// + span: $DIR/inline-options.rs:9:5: 9:16 | ||
// + literal: Const { ty: fn() {not_inlined}, val: Value(Scalar(<ZST>)) } | ||
} | ||
|
||
bb1: { | ||
StorageDead(_1); // scope 0 at $DIR/inline-options.rs:9:18: 9:19 | ||
StorageLive(_2); // scope 0 at $DIR/inline-options.rs:10:5: 10:21 | ||
StorageLive(_3); // scope 1 at $DIR/inline-options.rs:10:5: 10:21 | ||
_3 = g() -> bb2; // scope 1 at $DIR/inline-options.rs:10:5: 10:21 | ||
// mir::Constant | ||
// + span: $DIR/inline-options.rs:10:5: 10:21 | ||
// + literal: Const { ty: fn() {g}, val: Value(Scalar(<ZST>)) } | ||
} | ||
|
||
bb2: { | ||
StorageDead(_3); // scope 1 at $DIR/inline-options.rs:10:5: 10:21 | ||
StorageLive(_4); // scope 1 at $DIR/inline-options.rs:10:5: 10:21 | ||
_4 = g() -> bb3; // scope 1 at $DIR/inline-options.rs:10:5: 10:21 | ||
// mir::Constant | ||
// + span: $DIR/inline-options.rs:10:5: 10:21 | ||
// + literal: Const { ty: fn() {g}, val: Value(Scalar(<ZST>)) } | ||
} | ||
|
||
bb3: { | ||
StorageDead(_4); // scope 1 at $DIR/inline-options.rs:10:5: 10:21 | ||
StorageLive(_5); // scope 1 at $DIR/inline-options.rs:10:5: 10:21 | ||
_5 = g() -> bb4; // scope 1 at $DIR/inline-options.rs:10:5: 10:21 | ||
// mir::Constant | ||
// + span: $DIR/inline-options.rs:10:5: 10:21 | ||
// + literal: Const { ty: fn() {g}, val: Value(Scalar(<ZST>)) } | ||
} | ||
|
||
bb4: { | ||
StorageDead(_5); // scope 1 at $DIR/inline-options.rs:10:5: 10:21 | ||
_2 = const (); // scope 1 at $DIR/inline-options.rs:10:5: 10:21 | ||
StorageDead(_2); // scope 0 at $DIR/inline-options.rs:10:21: 10:22 | ||
_0 = const (); // scope 0 at $DIR/inline-options.rs:8:11: 11:2 | ||
return; // scope 0 at $DIR/inline-options.rs:11:2: 11:2 | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since there are lots more "constants" (and we may want to change them in the future), maybe we could create a more general solution: A way to pass a key/value pair list to specific optimizations. This way we don't have to (re)create a command line flag for every tiny thing, but can just parse arbitrary things out of the key/value pair list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about something like the above? Or do you have other ideas for generalizing configurable mir optimizations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also consider add new category of flags dedicated for MIR optimizations. I don't know if we need a completely different mechanism, especially with those flags being the first of a kind.
As far as enabling / disabling specific pass this might be better handled in context of #77665, so I could leave this out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fair. So we'll revisit once we get more than like 5 flags in total or sth.
If your work is blocked on this, we can merge it now and remove it again later, but otherwise leaving it out for #77665 would be best. It may just take a bit for that to happen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modified the PR to add threshold flag only for now.