Skip to content

Commit 426a4cc

Browse files
authored
Rollup merge of #69934 - andjo403:inlinecost, r=wesleywiser
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. r? @wesleywiser
2 parents 9adfb18 + afa940b commit 426a4cc

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
@@ -22,6 +22,8 @@ const HINT_THRESHOLD: usize = 100;
2222

2323
const INSTR_COST: usize = 5;
2424
const CALL_PENALTY: usize = 25;
25+
const LANDINGPAD_PENALTY: usize = 50;
26+
const RESUME_PENALTY: usize = 45;
2527

2628
const UNKNOWN_SIZE_COST: usize = 10;
2729

@@ -325,6 +327,7 @@ impl Inliner<'tcx> {
325327
if ty.needs_drop(tcx, param_env) {
326328
cost += CALL_PENALTY;
327329
if let Some(unwind) = unwind {
330+
cost += LANDINGPAD_PENALTY;
328331
work_list.push(unwind);
329332
}
330333
} else {
@@ -340,7 +343,7 @@ impl Inliner<'tcx> {
340343
threshold = 0;
341344
}
342345

343-
TerminatorKind::Call { func: Operand::Constant(ref f), .. } => {
346+
TerminatorKind::Call { func: Operand::Constant(ref f), cleanup, .. } => {
344347
if let ty::FnDef(def_id, _) = f.literal.ty.kind {
345348
// Don't give intrinsics the extra penalty for calls
346349
let f = tcx.fn_sig(def_id);
@@ -349,9 +352,21 @@ impl Inliner<'tcx> {
349352
} else {
350353
cost += CALL_PENALTY;
351354
}
355+
} else {
356+
cost += CALL_PENALTY;
357+
}
358+
if cleanup.is_some() {
359+
cost += LANDINGPAD_PENALTY;
360+
}
361+
}
362+
TerminatorKind::Assert { cleanup, .. } => {
363+
cost += CALL_PENALTY;
364+
365+
if cleanup.is_some() {
366+
cost += LANDINGPAD_PENALTY;
352367
}
353368
}
354-
TerminatorKind::Assert { .. } => cost += CALL_PENALTY,
369+
TerminatorKind::Resume => cost += RESUME_PENALTY,
355370
_ => cost += INSTR_COST,
356371
}
357372

0 commit comments

Comments
 (0)