Skip to content

Commit 6261869

Browse files
committed
[experiment] Try using a very simple heuristic for the inliner
r? @ghost
1 parent f5f86be commit 6261869

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/librustc_mir/transform/inline.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,19 @@ struct CallSite<'tcx> {
3939

4040
impl<'tcx> MirPass<'tcx> for Inline {
4141
fn run_pass(&self, tcx: TyCtxt<'tcx>, source: MirSource<'tcx>, body: &mut BodyAndCache<'tcx>) {
42-
if tcx.sess.opts.debugging_opts.mir_opt_level >= 2 {
43-
Inliner { tcx, source }.run_pass(body);
42+
let mir_opt_level = tcx.sess.opts.debugging_opts.mir_opt_level;
43+
if mir_opt_level == 0 {
44+
return;
4445
}
46+
47+
Inliner { tcx, source, use_simple_heuristic: mir_opt_level == 1 }.run_pass(body);
4548
}
4649
}
4750

4851
struct Inliner<'tcx> {
4952
tcx: TyCtxt<'tcx>,
5053
source: MirSource<'tcx>,
54+
use_simple_heuristic: bool,
5155
}
5256

5357
impl Inliner<'tcx> {
@@ -251,6 +255,10 @@ impl Inliner<'tcx> {
251255
}
252256
}
253257

258+
if self.use_simple_heuristic {
259+
return callee_body.basic_blocks().len() == 1 && callee_body.basic_blocks()[BasicBlock::from_u32(0)].statements.len() < 10;
260+
}
261+
254262
let mut threshold = if hinted { HINT_THRESHOLD } else { DEFAULT_THRESHOLD };
255263

256264
// Significantly lower the threshold for inlining cold functions

0 commit comments

Comments
 (0)