Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/librustc_mir/transform/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -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
Expand Down