Skip to content

Hack together inline-always-overrides #141055

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 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion compiler/rustc_codegen_llvm/src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,12 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
(InlineAttr::None, _) if instance.def.requires_inline(cx.tcx) => InlineAttr::Hint,
(inline, _) => inline,
};
to_add.extend(inline_attr(cx, inline));
if cx.tcx.has_inline_always_override(instance) {
eprintln!("Applying override");
to_add.extend(inline_attr(cx, InlineAttr::Always));
} else {
to_add.extend(inline_attr(cx, inline));
}

// The `uwtable` attribute according to LLVM is:
//
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_middle/src/mir/mono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ impl<'tcx> MonoItem<'tcx> {
if codegen_fn_attrs.inline.always() {
return InstantiationMode::LocalCopy;
}
// FIXME: Ideally we'd check has_inline_always_override here, but we can't because symbol names
// depend on instantiation mode so instantiation mode can't depend on symbol name.

// #[inline(never)] functions in general are poor candidates for inlining and thus since
// LocalCopy generally increases code size for the benefit of optimizations from inlining,
Expand Down
12 changes: 10 additions & 2 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ use crate::traits::solve::{
use crate::ty::predicate::ExistentialPredicateStableCmpExt as _;
use crate::ty::{
self, AdtDef, AdtDefData, AdtKind, Binder, Clause, Clauses, Const, GenericArg, GenericArgs,
GenericArgsRef, GenericParamDefKind, List, ListWithCachedTypeInfo, ParamConst, ParamTy,
Pattern, PatternKind, PolyExistentialPredicate, PolyFnSig, Predicate, PredicateKind,
GenericArgsRef, GenericParamDefKind, Instance, List, ListWithCachedTypeInfo, ParamConst,
ParamTy, Pattern, PatternKind, PolyExistentialPredicate, PolyFnSig, Predicate, PredicateKind,
PredicatePolarity, Region, RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind, TyVid,
ValTree, ValTreeKind, Visibility,
};
Expand Down Expand Up @@ -3395,6 +3395,14 @@ impl<'tcx> TyCtxt<'tcx> {
pub fn do_not_recommend_impl(self, def_id: DefId) -> bool {
self.get_diagnostic_attr(def_id, sym::do_not_recommend).is_some()
}

pub fn has_inline_always_override(self, instance: Instance<'tcx>) -> bool {
let Some(overrides) = &self.sess.opts.unstable_opts.inline_always_overrides else {
return false;
};
let symbol_name = self.symbol_name(instance).name;
overrides.iter().any(|o| symbol_name.starts_with(o))
}
}

/// Parameter attributes that can only be determined by examining the body of a function instead
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2249,6 +2249,9 @@ options! {
- hashes of green query instances
- hash collisions of query keys
- hash collisions when creating dep-nodes"),
inline_always_overrides: Option<Vec<String>> = (None, parse_opt_comma_list, [TRACKED],
"comma-separated list of full paths to functions to treat as if they are inline(always)"
),
inline_llvm: bool = (true, parse_bool, [TRACKED],
"enable LLVM inlining (default: yes)"),
inline_mir: Option<bool> = (None, parse_opt_bool, [TRACKED],
Expand Down
Loading