Skip to content

Commit b9449a3

Browse files
committed
Add option enabling MIR inlining independently of mir-opt-level
1 parent 3e826bb commit b9449a3

File tree

4 files changed

+23
-15
lines changed

4 files changed

+23
-15
lines changed

compiler/rustc_interface/src/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,7 @@ fn test_debugging_options_tracking_hash() {
556556
tracked!(function_sections, Some(false));
557557
tracked!(human_readable_cgu_names, true);
558558
tracked!(inline_in_all_cgus, Some(true));
559+
tracked!(inline_mir, Some(true));
559560
tracked!(inline_mir_threshold, 123);
560561
tracked!(inline_mir_hint_threshold, 123);
561562
tracked!(insert_sideeffect, true);

compiler/rustc_mir/src/transform/inline.rs

+19-13
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,27 @@ struct CallSite<'tcx> {
3737
source_info: SourceInfo,
3838
}
3939

40+
/// Returns true if MIR inlining is enabled in the current compilation session.
41+
crate fn is_enabled(tcx: TyCtxt<'_>) -> bool {
42+
if tcx.sess.opts.debugging_opts.instrument_coverage {
43+
// Since `Inline` happens after `InstrumentCoverage`, the function-specific coverage
44+
// counters can be invalidated, such as by merging coverage counter statements from
45+
// a pre-inlined function into a different function. This kind of change is invalid,
46+
// so inlining must be skipped. Note: This check is performed here so inlining can
47+
// be disabled without preventing other optimizations (regardless of `mir_opt_level`).
48+
return false;
49+
}
50+
51+
if let Some(enabled) = tcx.sess.opts.debugging_opts.inline_mir {
52+
return enabled;
53+
}
54+
55+
tcx.sess.opts.debugging_opts.mir_opt_level >= 2
56+
}
57+
4058
impl<'tcx> MirPass<'tcx> for Inline {
4159
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
42-
// If you change this optimization level, also change the level in
43-
// `mir_drops_elaborated_and_const_checked` for the call to `mir_inliner_callees`.
44-
// Otherwise you will get an ICE about stolen MIR.
45-
if tcx.sess.opts.debugging_opts.mir_opt_level < 2 {
46-
return;
47-
}
48-
49-
if tcx.sess.opts.debugging_opts.instrument_coverage {
50-
// Since `Inline` happens after `InstrumentCoverage`, the function-specific coverage
51-
// counters can be invalidated, such as by merging coverage counter statements from
52-
// a pre-inlined function into a different function. This kind of change is invalid,
53-
// so inlining must be skipped. Note: This check is performed here so inlining can
54-
// be disabled without preventing other optimizations (regardless of `mir_opt_level`).
60+
if !is_enabled(tcx) {
5561
return;
5662
}
5763

compiler/rustc_mir/src/transform/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -427,8 +427,7 @@ fn mir_drops_elaborated_and_const_checked<'tcx>(
427427
let def = ty::WithOptConstParam::unknown(did);
428428

429429
// Do not compute the mir call graph without said call graph actually being used.
430-
// Keep this in sync with the mir inliner's optimization level.
431-
if tcx.sess.opts.debugging_opts.mir_opt_level >= 2 {
430+
if inline::is_enabled(tcx) {
432431
let _ = tcx.mir_inliner_callees(ty::InstanceDef::Item(def));
433432
}
434433
}

compiler/rustc_session/src/options.rs

+2
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
956956
(default: no)"),
957957
incremental_verify_ich: bool = (false, parse_bool, [UNTRACKED],
958958
"verify incr. comp. hashes of green query instances (default: no)"),
959+
inline_mir: Option<bool> = (None, parse_opt_bool, [TRACKED],
960+
"enable MIR inlining (default: no)"),
959961
inline_mir_threshold: usize = (50, parse_uint, [TRACKED],
960962
"a default MIR inlining threshold (default: 50)"),
961963
inline_mir_hint_threshold: usize = (100, parse_uint, [TRACKED],

0 commit comments

Comments
 (0)