diff --git a/src/librustc_mir/transform/inline.rs b/src/librustc_mir/transform/inline.rs index 56b6fa68e1841..14bbf123a2cb0 100644 --- a/src/librustc_mir/transform/inline.rs +++ b/src/librustc_mir/transform/inline.rs @@ -39,15 +39,19 @@ struct CallSite<'tcx> { impl<'tcx> MirPass<'tcx> for Inline { fn run_pass(&self, tcx: TyCtxt<'tcx>, source: MirSource<'tcx>, body: &mut BodyAndCache<'tcx>) { - if tcx.sess.opts.debugging_opts.mir_opt_level >= 2 { - Inliner { tcx, source }.run_pass(body); + let mir_opt_level = tcx.sess.opts.debugging_opts.mir_opt_level; + if mir_opt_level == 0 { + return; } + + Inliner { tcx, source, use_simple_heuristic: mir_opt_level == 1 }.run_pass(body); } } struct Inliner<'tcx> { tcx: TyCtxt<'tcx>, source: MirSource<'tcx>, + use_simple_heuristic: bool, } impl Inliner<'tcx> { @@ -251,6 +255,19 @@ impl Inliner<'tcx> { } } + if self.use_simple_heuristic { + use rustc::mir::StatementKind::*; + + return callee_body.basic_blocks().len() == 1 + && callee_body.basic_blocks()[BasicBlock::from_u32(0)] + .statements + .iter() + .filter(|stmt| !matches!(stmt.kind, StorageLive(_) | StorageDead(_))) + .take(5) + .count() + <= 4; + } + let mut threshold = if hinted { HINT_THRESHOLD } else { DEFAULT_THRESHOLD }; // Significantly lower the threshold for inlining cold functions