Skip to content

Commit ed28833

Browse files
committed
Implement inline(usually)
1 parent 124cc92 commit ed28833

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
@@ -9,6 +9,7 @@ use crate::RustcVersion;
99
pub enum InlineAttr {
1010
None,
1111
Hint,
12+
Usually,
1213
Always,
1314
Never,
1415
/// `#[rustc_force_inline]` forces inlining to happen in the MIR inliner - it reports an error
@@ -24,7 +25,7 @@ impl InlineAttr {
2425
pub fn always(&self) -> bool {
2526
match self {
2627
InlineAttr::Always | InlineAttr::Force { .. } => true,
27-
InlineAttr::None | InlineAttr::Hint | InlineAttr::Never => false,
28+
InlineAttr::None | InlineAttr::Hint | InlineAttr::Usually | InlineAttr::Never => false,
2829
}
2930
}
3031
}

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
@@ -551,6 +551,8 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
551551
InlineAttr::None
552552
} else if list_contains_name(items, sym::always) {
553553
InlineAttr::Always
554+
} else if list_contains_name(items, sym::usually) {
555+
InlineAttr::Usually
554556
} else if list_contains_name(items, sym::never) {
555557
InlineAttr::Never
556558
} else {

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
@@ -299,7 +299,10 @@ impl<'tcx> Inliner<'tcx> for NormalInliner<'tcx> {
299299
changed: false,
300300
caller_is_inline_forwarder: matches!(
301301
codegen_fn_attrs.inline,
302-
InlineAttr::Hint | InlineAttr::Always | InlineAttr::Force { .. }
302+
InlineAttr::Hint
303+
| InlineAttr::Usually
304+
| InlineAttr::Always
305+
| InlineAttr::Force { .. }
303306
) && body_is_forwarder(body),
304307
}
305308
}

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2178,6 +2178,7 @@ symbols! {
21782178
usize_legacy_fn_max_value,
21792179
usize_legacy_fn_min_value,
21802180
usize_legacy_mod,
2181+
usually,
21812182
v8plus,
21822183
va_arg,
21832184
va_copy,

0 commit comments

Comments
 (0)