Skip to content

Add inline(usually) #130679

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion compiler/rustc_attr_data_structures/src/attributes.rs
Original file line number Diff line number Diff line change
@@ -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,
}
}
}
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_gcc/src/attributes.rs
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ fn inline_attr<'gcc, 'tcx>(
inline: InlineAttr,
) -> Option<FnAttribute<'gcc>> {
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" {
3 changes: 3 additions & 0 deletions compiler/rustc_codegen_llvm/src/attributes.rs
Original file line number Diff line number Diff line change
@@ -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))
2 changes: 2 additions & 0 deletions compiler/rustc_codegen_ssa/src/codegen_attrs.rs
Original file line number Diff line number Diff line change
@@ -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() });

4 changes: 3 additions & 1 deletion compiler/rustc_mir_transform/src/cross_crate_inline.rs
Original file line number Diff line number Diff line change
@@ -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;
}
_ => {}
}

5 changes: 4 additions & 1 deletion compiler/rustc_mir_transform/src/inline.rs
Original file line number Diff line number Diff line change
@@ -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),
}
}
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
@@ -2244,6 +2244,7 @@ symbols! {
usize_legacy_fn_max_value,
usize_legacy_fn_min_value,
usize_legacy_mod,
usually,
v8plus,
va_arg,
va_copy,