Skip to content

Commit 198fc5d

Browse files
committed
Hack together inline-always-overrides
1 parent 8392220 commit 198fc5d

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

compiler/rustc_codegen_llvm/src/attributes.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ pub(crate) fn inline_attr<'ll, 'tcx>(
3535
tcx: TyCtxt<'tcx>,
3636
instance: ty::Instance<'tcx>,
3737
) -> Option<&'ll Attribute> {
38+
if tcx.has_inline_always_override(instance) {
39+
eprintln!("Applying override");
40+
return Some(AttributeKind::AlwaysInline.create_attr(cx.llcx));
41+
}
42+
3843
// `optnone` requires `noinline`
3944
let codegen_fn_attrs = tcx.codegen_fn_attrs(instance.def_id());
4045
let inline = match (codegen_fn_attrs.inline, &codegen_fn_attrs.optimize) {

compiler/rustc_middle/src/mir/mono.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ impl<'tcx> MonoItem<'tcx> {
206206
if codegen_fn_attrs.inline.always() {
207207
return InstantiationMode::LocalCopy;
208208
}
209+
// FIXME: Ideally we'd check has_inline_always_override here, but we can't because symbol names
210+
// depend on instantiation mode so instantiation mode can't depend on symbol name.
209211

210212
// #[inline(never)] functions in general are poor candidates for inlining and thus since
211213
// LocalCopy generally increases code size for the benefit of optimizations from inlining,

compiler/rustc_middle/src/ty/context.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ use crate::traits::solve::{
8080
use crate::ty::predicate::ExistentialPredicateStableCmpExt as _;
8181
use crate::ty::{
8282
self, AdtDef, AdtDefData, AdtKind, Binder, Clause, Clauses, Const, GenericArg, GenericArgs,
83-
GenericArgsRef, GenericParamDefKind, List, ListWithCachedTypeInfo, ParamConst, ParamTy,
84-
Pattern, PatternKind, PolyExistentialPredicate, PolyFnSig, Predicate, PredicateKind,
83+
GenericArgsRef, GenericParamDefKind, Instance, List, ListWithCachedTypeInfo, ParamConst,
84+
ParamTy, Pattern, PatternKind, PolyExistentialPredicate, PolyFnSig, Predicate, PredicateKind,
8585
PredicatePolarity, Region, RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind, TyVid,
8686
ValTree, ValTreeKind, Visibility,
8787
};
@@ -3552,6 +3552,14 @@ impl<'tcx> TyCtxt<'tcx> {
35523552
self.get_diagnostic_attr(def_id, sym::do_not_recommend).is_some()
35533553
}
35543554

3555+
pub fn has_inline_always_override(self, instance: Instance<'tcx>) -> bool {
3556+
let Some(overrides) = &self.sess.opts.unstable_opts.inline_always_overrides else {
3557+
return false;
3558+
};
3559+
let symbol_name = self.symbol_name(instance).name;
3560+
overrides.iter().any(|o| symbol_name.starts_with(o))
3561+
}
3562+
35553563
/// Whether this def is one of the special bin crate entrypoint functions that must have a
35563564
/// monomorphization and also not be internalized in the bin crate.
35573565
pub fn is_entrypoint(self, def_id: DefId) -> bool {

compiler/rustc_session/src/options.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2368,6 +2368,9 @@ options! {
23682368
- hash collisions when creating dep-nodes"),
23692369
indirect_branch_cs_prefix: bool = (false, parse_bool, [TRACKED TARGET_MODIFIER],
23702370
"add `cs` prefix to `call` and `jmp` to indirect thunks (default: no)"),
2371+
inline_always_overrides: Option<Vec<String>> = (None, parse_opt_comma_list, [TRACKED],
2372+
"comma-separated list of full paths to functions to treat as if they are inline(always)"
2373+
),
23712374
inline_llvm: bool = (true, parse_bool, [TRACKED],
23722375
"enable LLVM inlining (default: yes)"),
23732376
inline_mir: Option<bool> = (None, parse_opt_bool, [TRACKED],

0 commit comments

Comments
 (0)