-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add support for leaf function frame pointer elimination #86652
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ use rustc_middle::ty::{self, TyCtxt}; | |
use rustc_session::config::OptLevel; | ||
use rustc_session::Session; | ||
use rustc_target::spec::abi::Abi; | ||
use rustc_target::spec::{SanitizerSet, StackProbeType}; | ||
use rustc_target::spec::{FramePointer, SanitizerSet, StackProbeType}; | ||
|
||
use crate::attributes; | ||
use crate::llvm::AttributePlace::Function; | ||
|
@@ -69,15 +69,25 @@ fn naked(val: &'ll Value, is_naked: bool) { | |
Attribute::Naked.toggle_llfn(Function, val, is_naked); | ||
} | ||
|
||
pub fn set_frame_pointer_elimination(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) { | ||
if cx.sess().must_not_eliminate_frame_pointers() { | ||
llvm::AddFunctionAttrStringValue( | ||
llfn, | ||
llvm::AttributePlace::Function, | ||
cstr!("frame-pointer"), | ||
cstr!("all"), | ||
); | ||
pub fn set_frame_pointer_type(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) { | ||
let mut fp = cx.sess().target.frame_pointer; | ||
// "mcount" function relies on stack pointer. | ||
// See <https://sourceware.org/binutils/docs/gprof/Implementation.html>. | ||
if cx.sess().instrument_mcount() || matches!(cx.sess().opts.cg.force_frame_pointers, Some(true)) | ||
{ | ||
fp = FramePointer::Always; | ||
Comment on lines
+76
to
+78
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ...and only consult the CLI's opinion if it demands them. |
||
} | ||
let attr_value = match fp { | ||
FramePointer::Always => cstr!("all"), | ||
FramePointer::NonLeaf => cstr!("non-leaf"), | ||
FramePointer::MayOmit => return, | ||
}; | ||
llvm::AddFunctionAttrStringValue( | ||
llfn, | ||
llvm::AttributePlace::Function, | ||
cstr!("frame-pointer"), | ||
attr_value, | ||
); | ||
} | ||
|
||
/// Tell LLVM what instrument function to insert. | ||
|
@@ -254,7 +264,7 @@ pub fn from_fn_attrs(cx: &CodegenCx<'ll, 'tcx>, llfn: &'ll Value, instance: ty:: | |
} | ||
|
||
// FIXME: none of these three functions interact with source level attributes. | ||
set_frame_pointer_elimination(cx, llfn); | ||
set_frame_pointer_type(cx, llfn); | ||
set_instrument_function(cx, llfn); | ||
set_probestack(cx, llfn); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -792,18 +792,6 @@ impl Session { | |
!self.target.is_like_windows && !self.target.is_like_osx | ||
} | ||
|
||
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 | ||
} | ||
} | ||
|
||
Comment on lines
-795
to
-806
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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... |
||
pub fn must_emit_unwind_tables(&self) -> bool { | ||
// This is used to control the emission of the `uwtable` attribute on | ||
// LLVM functions. | ||
|
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.
...but in this place, the behavior is now to take the target frame pointer first...