about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAndreas Jonson <andjo403@users.noreply.github.com>2020-03-11 19:18:22 +0100
committerAndreas Jonson <andjo403@users.noreply.github.com>2020-03-11 19:18:22 +0100
commitafa940b900c2003228ea7f5d9f8d78906d84c135 (patch)
treefb9294a65b70a1b6070126a0734b1826b8d1e101
parentc20d7eecbc0928b57da8fe30b2ef8528e2bdd5be (diff)
downloadrust-afa940b900c2003228ea7f5d9f8d78906d84c135.tar.gz
rust-afa940b900c2003228ea7f5d9f8d78906d84c135.zip
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.
-rw-r--r--src/librustc_mir/transform/inline.rs19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/librustc_mir/transform/inline.rs b/src/librustc_mir/transform/inline.rs
index b6802505df7..7cdebf62670 100644
--- a/src/librustc_mir/transform/inline.rs
+++ b/src/librustc_mir/transform/inline.rs
@@ -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;
 
@@ -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 {
@@ -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);
@@ -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,
             }