Skip to content

Commit 3069aa6

Browse files
committed
Implement inline(usually)
1 parent 81d8c74 commit 3069aa6

File tree

7 files changed

+16
-4
lines changed

7 files changed

+16
-4
lines changed

compiler/rustc_attr_data_structures/src/attributes.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::{DefaultBodyStability, PartialConstStability, PrintAttribute, RustcVe
1212
pub enum InlineAttr {
1313
None,
1414
Hint,
15+
Usually,
1516
Always,
1617
Never,
1718
/// `#[rustc_force_inline]` forces inlining to happen in the MIR inliner - it reports an error
@@ -27,7 +28,7 @@ impl InlineAttr {
2728
pub fn always(&self) -> bool {
2829
match self {
2930
InlineAttr::Always | InlineAttr::Force { .. } => true,
30-
InlineAttr::None | InlineAttr::Hint | InlineAttr::Never => false,
31+
InlineAttr::None | InlineAttr::Hint | InlineAttr::Usually | InlineAttr::Never => false,
3132
}
3233
}
3334
}

compiler/rustc_codegen_gcc/src/attributes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn inline_attr<'gcc, 'tcx>(
1919
inline: InlineAttr,
2020
) -> Option<FnAttribute<'gcc>> {
2121
match inline {
22-
InlineAttr::Hint => Some(FnAttribute::Inline),
22+
InlineAttr::Hint | InlineAttr::Usually => Some(FnAttribute::Inline),
2323
InlineAttr::Always | InlineAttr::Force { .. } => Some(FnAttribute::AlwaysInline),
2424
InlineAttr::Never => {
2525
if cx.sess().target.arch != "amdgpu" {

compiler/rustc_codegen_llvm/src/attributes.rs

+3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ fn inline_attr<'ll>(cx: &CodegenCx<'ll, '_>, inline: InlineAttr) -> Option<&'ll
4040
InlineAttr::Always | InlineAttr::Force { .. } => {
4141
Some(AttributeKind::AlwaysInline.create_attr(cx.llcx))
4242
}
43+
InlineAttr::Usually => {
44+
Some(llvm::CreateAttrStringValue(cx.llcx, "function-inline-cost", "0"))
45+
}
4346
InlineAttr::Never => {
4447
if cx.sess().target.arch != "amdgpu" {
4548
Some(AttributeKind::NoInline.create_attr(cx.llcx))

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

+2
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,8 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
486486
InlineAttr::Always
487487
} else if item.has_name(sym::never) {
488488
InlineAttr::Never
489+
} else if item.has_name(sym::usually) {
490+
InlineAttr::Usually
489491
} else {
490492
tcx.dcx().emit_err(errors::InvalidArgument { span: items[0].span() });
491493

compiler/rustc_mir_transform/src/cross_crate_inline.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ fn cross_crate_inlinable(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
4646
// #[inline(never)] to force code generation.
4747
match codegen_fn_attrs.inline {
4848
InlineAttr::Never => return false,
49-
InlineAttr::Hint | InlineAttr::Always | InlineAttr::Force { .. } => return true,
49+
InlineAttr::Hint | InlineAttr::Usually | InlineAttr::Always | InlineAttr::Force { .. } => {
50+
return true;
51+
}
5052
_ => {}
5153
}
5254

compiler/rustc_mir_transform/src/inline.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,10 @@ impl<'tcx> Inliner<'tcx> for NormalInliner<'tcx> {
309309
changed: false,
310310
caller_is_inline_forwarder: matches!(
311311
codegen_fn_attrs.inline,
312-
InlineAttr::Hint | InlineAttr::Always | InlineAttr::Force { .. }
312+
InlineAttr::Hint
313+
| InlineAttr::Usually
314+
| InlineAttr::Always
315+
| InlineAttr::Force { .. }
313316
) && body_is_forwarder(body),
314317
}
315318
}

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2244,6 +2244,7 @@ symbols! {
22442244
usize_legacy_fn_max_value,
22452245
usize_legacy_fn_min_value,
22462246
usize_legacy_mod,
2247+
usually,
22472248
v8plus,
22482249
va_arg,
22492250
va_copy,

0 commit comments

Comments
 (0)