Skip to content
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 support for leaf function frame pointer elimination #86652

Merged
merged 1 commit into from
Jul 1, 2021

Conversation

nagisa
Copy link
Member

@nagisa nagisa commented Jun 26, 2021

This PR adds ability for the target specifications to specify frame
pointer emission type that's not just “always” or “whatever cg decides”.

In particular there's a new mode that allows omission of the frame
pointer for leaf functions (those that don't call any other functions).

We then set this new mode for Aarch64-based Apple targets.

Fixes #86196

@rust-highfive
Copy link
Collaborator

r? @jackh726

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive
Copy link
Collaborator

⚠️ Warning ⚠️

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 26, 2021
@tlyu
Copy link
Contributor

tlyu commented Jun 26, 2021

I'm not qualified to evaluate the code changes, but they look correct to me. However, I think the title of the PR is opposite to your intent, because it seems that you're wanting to have support for emitting frame pointers only for non-leaf functions, instead of eliminating frame pointers only for non-leaf functions.

(This is understandable, because the previous code spoke in terms of eliminating frame pointers.)

@nagisa nagisa changed the title Add support for non-leaf frame pointer elimination Add support for leaf function frame pointer elimination Jun 26, 2021
@tschuett
Copy link

There is no test to show that aarch64_apple_darwin gets NonLeaf and i686_apple_darwin get Always?

@nagisa nagisa force-pushed the nagisa/non-leaf-fp branch 2 times, most recently from ad52a0c to da4642b Compare June 27, 2021 14:43
@petrochenkov
Copy link
Contributor

r? @petrochenkov

@petrochenkov
Copy link
Contributor

Looks like this comment

There is no test to show that aarch64_apple_darwin gets NonLeaf and i686_apple_darwin get Always?

was addressed (but with x86_64 instead of i686).

r=me with the nit #86652 (comment) addressed.

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 30, 2021
This PR adds ability for the target specifications to specify frame
pointer emission type that's not just “always” or “whatever cg decides”.

In particular there's a new mode that allows omission of the frame
pointer for leaf functions (those that don't call any other functions).

We then set this new mode for Aarch64-based Apple targets.

Fixes rust-lang#86196
@nagisa
Copy link
Member Author

nagisa commented Jun 30, 2021

@bors r=petrochenkov

@bors
Copy link
Contributor

bors commented Jun 30, 2021

📌 Commit 9b67cba has been approved by petrochenkov

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 30, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 1, 2021
…laumeGomez

Rollup of 6 pull requests

Successful merges:

 - rust-lang#86558 (Add suggestions for "undefined reference" link errors)
 - rust-lang#86616 (rustc_span: Explicitly handle crates that differ from package names)
 - rust-lang#86652 (Add support for leaf function frame pointer elimination)
 - rust-lang#86666 (Fix misleading "impl Trait" error)
 - rust-lang#86762 (mailmap: Add my work email address)
 - rust-lang#86773 (Enable the tests developed with rust-lang#86594)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit dfd30d7 into rust-lang:master Jul 1, 2021
@rustbot rustbot added this to the 1.55.0 milestone Jul 1, 2021
nbdd0121 added a commit to nbdd0121/linux that referenced this pull request Oct 10, 2021
This option changes from boolean to three options, "always", "non-leaf"
and "may-omit" in Rust 1.55 [0].

[0]: rust-lang/rust#86652

Signed-off-by: Gary Guo <gary@garyguo.net>
Copy link
Contributor

@workingjubilee workingjubilee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand the code correctly, it seems a facet of the compiler's behavior was changed without remark in this PR. I am not certain if the current behavior is better or worse, but the change seems to have been unintentional.

Comment on lines -795 to -806
pub fn must_not_eliminate_frame_pointers(&self) -> bool {
// "mcount" function relies on stack pointer.
// See <https://sourceware.org/binutils/docs/gprof/Implementation.html>.
if self.instrument_mcount() {
true
} else if let Some(x) = self.opts.cg.force_frame_pointers {
x
} else {
!self.target.eliminate_frame_pointer
}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this PR, the behavior here seems to have been reversed: previously, the target decided the default frame pointer disposition last, and the CLI argument took precedence...

cstr!("all"),
);
pub fn set_frame_pointer_type(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) {
let mut fp = cx.sess().target.frame_pointer;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...but in this place, the behavior is now to take the target frame pointer first...

Comment on lines +76 to +78
if cx.sess().instrument_mcount() || matches!(cx.sess().opts.cg.force_frame_pointers, Some(true))
{
fp = FramePointer::Always;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...and only consult the CLI's opinion if it demands them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Apple platforms: Disabled frame pointer elimination causes perf issues and is not in line with what clang does
9 participants