Skip to content

Commit afa940b

Browse files
committed
Update the mir inline costs
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.
1 parent c20d7ee commit afa940b

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/librustc_mir/transform/inline.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ const HINT_THRESHOLD: usize = 100;
2525

2626
const INSTR_COST: usize = 5;
2727
const CALL_PENALTY: usize = 25;
28+
const LANDINGPAD_PENALTY: usize = 50;
29+
const RESUME_PENALTY: usize = 45;
2830

2931
const UNKNOWN_SIZE_COST: usize = 10;
3032

@@ -328,6 +330,7 @@ impl Inliner<'tcx> {
328330
if ty.needs_drop(tcx, param_env) {
329331
cost += CALL_PENALTY;
330332
if let Some(unwind) = unwind {
333+
cost += LANDINGPAD_PENALTY;
331334
work_list.push(unwind);
332335
}
333336
} else {
@@ -343,7 +346,7 @@ impl Inliner<'tcx> {
343346
threshold = 0;
344347
}
345348

346-
TerminatorKind::Call { func: Operand::Constant(ref f), .. } => {
349+
TerminatorKind::Call { func: Operand::Constant(ref f), cleanup, .. } => {
347350
if let ty::FnDef(def_id, _) = f.literal.ty.kind {
348351
// Don't give intrinsics the extra penalty for calls
349352
let f = tcx.fn_sig(def_id);
@@ -352,9 +355,21 @@ impl Inliner<'tcx> {
352355
} else {
353356
cost += CALL_PENALTY;
354357
}
358+
} else {
359+
cost += CALL_PENALTY;
360+
}
361+
if cleanup.is_some() {
362+
cost += LANDINGPAD_PENALTY;
363+
}
364+
}
365+
TerminatorKind::Assert { cleanup, .. } => {
366+
cost += CALL_PENALTY;
367+
368+
if cleanup.is_some() {
369+
cost += LANDINGPAD_PENALTY;
355370
}
356371
}
357-
TerminatorKind::Assert { .. } => cost += CALL_PENALTY,
372+
TerminatorKind::Resume => cost += RESUME_PENALTY,
358373
_ => cost += INSTR_COST,
359374
}
360375

0 commit comments

Comments
 (0)