Auto merge of #121298 - nikic:writable, r=cuviper
Set writable and dead_on_unwind attributes for sret arguments Set the `writable` and `dead_on_unwind` attributes for `sret` arguments. This allows call slot optimization to remove more memcpy's. See https://llvm.org/docs/LangRef.html#parameter-attributes for the specification of these attributes. In short, the statement we're making here is that: * The return slot is writable. * The return slot will not be read if the function unwinds. Fixes https://github.com/rust-lang/rust/issues/90595.
This commit is contained in:
commit
284f94f9c0
7 changed files with 33 additions and 4 deletions
|
@ -2,6 +2,7 @@ use crate::attributes;
|
|||
use crate::builder::Builder;
|
||||
use crate::context::CodegenCx;
|
||||
use crate::llvm::{self, Attribute, AttributePlace};
|
||||
use crate::llvm_util;
|
||||
use crate::type_::Type;
|
||||
use crate::type_of::LayoutLlvmExt;
|
||||
use crate::value::Value;
|
||||
|
@ -425,6 +426,18 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
|
|||
cx.type_array(cx.type_i8(), self.ret.layout.size.bytes()),
|
||||
);
|
||||
attributes::apply_to_llfn(llfn, llvm::AttributePlace::Argument(i), &[sret]);
|
||||
if cx.sess().opts.optimize != config::OptLevel::No
|
||||
&& llvm_util::get_version() >= (18, 0, 0)
|
||||
{
|
||||
attributes::apply_to_llfn(
|
||||
llfn,
|
||||
llvm::AttributePlace::Argument(i),
|
||||
&[
|
||||
llvm::AttributeKind::Writable.create_attr(cx.llcx),
|
||||
llvm::AttributeKind::DeadOnUnwind.create_attr(cx.llcx),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
PassMode::Cast { cast, pad_i32: _ } => {
|
||||
cast.attrs.apply_attrs_to_llfn(llvm::AttributePlace::ReturnValue, cx, llfn);
|
||||
|
|
|
@ -200,6 +200,8 @@ pub enum AttributeKind {
|
|||
AllocAlign = 39,
|
||||
SanitizeSafeStack = 40,
|
||||
FnRetThunkExtern = 41,
|
||||
Writable = 42,
|
||||
DeadOnUnwind = 43,
|
||||
}
|
||||
|
||||
/// LLVMIntPredicate
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue