Skip to content
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

Update the mir inline costs #69934

Merged
merged 1 commit into from
Mar 21, 2020
Merged
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
19 changes: 17 additions & 2 deletions src/librustc_mir/transform/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const HINT_THRESHOLD: usize = 100;

const INSTR_COST: usize = 5;
const CALL_PENALTY: usize = 25;
const LANDINGPAD_PENALTY: usize = 50;
const RESUME_PENALTY: usize = 45;

const UNKNOWN_SIZE_COST: usize = 10;

Expand Down Expand Up @@ -328,6 +330,7 @@ impl Inliner<'tcx> {
if ty.needs_drop(tcx, param_env) {
cost += CALL_PENALTY;
if let Some(unwind) = unwind {
cost += LANDINGPAD_PENALTY;
work_list.push(unwind);
}
} else {
Expand All @@ -343,7 +346,7 @@ impl Inliner<'tcx> {
threshold = 0;
}

TerminatorKind::Call { func: Operand::Constant(ref f), .. } => {
TerminatorKind::Call { func: Operand::Constant(ref f), cleanup, .. } => {
if let ty::FnDef(def_id, _) = f.literal.ty.kind {
// Don't give intrinsics the extra penalty for calls
let f = tcx.fn_sig(def_id);
Expand All @@ -352,9 +355,21 @@ impl Inliner<'tcx> {
} else {
cost += CALL_PENALTY;
}
} else {
cost += CALL_PENALTY;
}
if cleanup.is_some() {
cost += LANDINGPAD_PENALTY;
}
}
TerminatorKind::Assert { cleanup, .. } => {
cost += CALL_PENALTY;

if cleanup.is_some() {
cost += LANDINGPAD_PENALTY;
}
}
TerminatorKind::Assert { .. } => cost += CALL_PENALTY,
TerminatorKind::Resume => cost += RESUME_PENALTY,
_ => cost += INSTR_COST,
}

Expand Down