Skip to content

Commit

Permalink
Update the mir inline costs
Browse files Browse the repository at this point in the history
handle that when mir is lowered to llvm-ir more code is generated.
landingpads generates 10 llvm-ir instructions
and resume 9 llvm-ir instructions.
  • Loading branch information
andjo403 committed Mar 11, 2020
1 parent c20d7ee commit afa940b
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/librustc_mir/transform/inline.rs
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

0 comments on commit afa940b

Please sign in to comment.