diff --git a/compiler/rustc_attr_data_structures/src/attributes.rs b/compiler/rustc_attr_data_structures/src/attributes.rs index 969bce7ae20a6..8a426cab4527d 100644 --- a/compiler/rustc_attr_data_structures/src/attributes.rs +++ b/compiler/rustc_attr_data_structures/src/attributes.rs @@ -12,6 +12,7 @@ use crate::{DefaultBodyStability, PartialConstStability, PrintAttribute, RustcVe pub enum InlineAttr { None, Hint, + Usually, Always, Never, /// `#[rustc_force_inline]` forces inlining to happen in the MIR inliner - it reports an error @@ -27,7 +28,7 @@ impl InlineAttr { pub fn always(&self) -> bool { match self { InlineAttr::Always | InlineAttr::Force { .. } => true, - InlineAttr::None | InlineAttr::Hint | InlineAttr::Never => false, + InlineAttr::None | InlineAttr::Hint | InlineAttr::Usually | InlineAttr::Never => false, } } } diff --git a/compiler/rustc_codegen_gcc/src/attributes.rs b/compiler/rustc_codegen_gcc/src/attributes.rs index 69b04dd579693..ac08ab94aee66 100644 --- a/compiler/rustc_codegen_gcc/src/attributes.rs +++ b/compiler/rustc_codegen_gcc/src/attributes.rs @@ -19,7 +19,7 @@ fn inline_attr<'gcc, 'tcx>( inline: InlineAttr, ) -> Option> { match inline { - InlineAttr::Hint => Some(FnAttribute::Inline), + InlineAttr::Hint | InlineAttr::Usually => Some(FnAttribute::Inline), InlineAttr::Always | InlineAttr::Force { .. } => Some(FnAttribute::AlwaysInline), InlineAttr::Never => { if cx.sess().target.arch != "amdgpu" { diff --git a/compiler/rustc_codegen_llvm/src/attributes.rs b/compiler/rustc_codegen_llvm/src/attributes.rs index e8c42d16733ec..7cb863e1cd819 100644 --- a/compiler/rustc_codegen_llvm/src/attributes.rs +++ b/compiler/rustc_codegen_llvm/src/attributes.rs @@ -40,6 +40,9 @@ fn inline_attr<'ll>(cx: &CodegenCx<'ll, '_>, inline: InlineAttr) -> Option<&'ll InlineAttr::Always | InlineAttr::Force { .. } => { Some(AttributeKind::AlwaysInline.create_attr(cx.llcx)) } + InlineAttr::Usually => { + Some(llvm::CreateAttrStringValue(cx.llcx, "function-inline-cost", "0")) + } InlineAttr::Never => { if cx.sess().target.arch != "amdgpu" { Some(AttributeKind::NoInline.create_attr(cx.llcx)) diff --git a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs index ddb6118898334..7577b3be4a17f 100644 --- a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs +++ b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs @@ -486,6 +486,8 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { InlineAttr::Always } else if item.has_name(sym::never) { InlineAttr::Never + } else if item.has_name(sym::usually) { + InlineAttr::Usually } else { tcx.dcx().emit_err(errors::InvalidArgument { span: items[0].span() }); diff --git a/compiler/rustc_mir_transform/src/cross_crate_inline.rs b/compiler/rustc_mir_transform/src/cross_crate_inline.rs index 4f45d9588a890..689673cf479ce 100644 --- a/compiler/rustc_mir_transform/src/cross_crate_inline.rs +++ b/compiler/rustc_mir_transform/src/cross_crate_inline.rs @@ -46,7 +46,9 @@ fn cross_crate_inlinable(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool { // #[inline(never)] to force code generation. match codegen_fn_attrs.inline { InlineAttr::Never => return false, - InlineAttr::Hint | InlineAttr::Always | InlineAttr::Force { .. } => return true, + InlineAttr::Hint | InlineAttr::Usually | InlineAttr::Always | InlineAttr::Force { .. } => { + return true; + } _ => {} } diff --git a/compiler/rustc_mir_transform/src/inline.rs b/compiler/rustc_mir_transform/src/inline.rs index 0ab24e48d443c..ba4bde9456af4 100644 --- a/compiler/rustc_mir_transform/src/inline.rs +++ b/compiler/rustc_mir_transform/src/inline.rs @@ -309,7 +309,10 @@ impl<'tcx> Inliner<'tcx> for NormalInliner<'tcx> { changed: false, caller_is_inline_forwarder: matches!( codegen_fn_attrs.inline, - InlineAttr::Hint | InlineAttr::Always | InlineAttr::Force { .. } + InlineAttr::Hint + | InlineAttr::Usually + | InlineAttr::Always + | InlineAttr::Force { .. } ) && body_is_forwarder(body), } } diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 6bf74303724bc..114541c1ae35b 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -2244,6 +2244,7 @@ symbols! { usize_legacy_fn_max_value, usize_legacy_fn_min_value, usize_legacy_mod, + usually, v8plus, va_arg, va_copy,