Skip to content

Commit 0eae43e

Browse files
committed
Auto merge of rust-lang#38307 - bluss:mir-opt-level, r=eddyb
Simplify use of mir_opt_level Remove the unused top level option by the same name, and retain the debug option. Use -Zmir-opt-level=1 as default. One pass is enabled by default but wants to be optional: - Instcombine requires mir_opt_level > 0 Copy propagation is not used by default, but used to be activated by explicit -Zmir-opt-level=1. It must move one higher to be off by default: - CopyPropagation requires mir_opt_level > 1 Deaggregate is not used by default, and used to be on a different level than CopyPropagation: - Deaggreate requires mir_opt_level > 2
2 parents 8d66181 + 6d46a21 commit 0eae43e

File tree

4 files changed

+12
-21
lines changed

4 files changed

+12
-21
lines changed

Diff for: src/librustc/session/config.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,6 @@ top_level_options!(
269269

270270
test: bool [TRACKED],
271271
error_format: ErrorOutputType [UNTRACKED],
272-
mir_opt_level: usize [TRACKED],
273272

274273
// if Some, enable incremental compilation, using the given
275274
// directory to store intermediate results
@@ -435,7 +434,6 @@ pub fn basic_options() -> Options {
435434
maybe_sysroot: None,
436435
target_triple: host_triple().to_string(),
437436
test: false,
438-
mir_opt_level: 1,
439437
incremental: None,
440438
debugging_opts: basic_debugging_options(),
441439
prints: Vec::new(),
@@ -916,8 +914,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
916914
"print layout information for each type encountered"),
917915
print_trans_items: Option<String> = (None, parse_opt_string, [UNTRACKED],
918916
"print the result of the translation item collection pass"),
919-
mir_opt_level: Option<usize> = (None, parse_opt_uint, [TRACKED],
920-
"set the MIR optimization level (0-3)"),
917+
mir_opt_level: usize = (1, parse_uint, [TRACKED],
918+
"set the MIR optimization level (0-3, default: 1)"),
921919
dump_mir: Option<String> = (None, parse_opt_string, [UNTRACKED],
922920
"dump MIR state at various points in translation"),
923921
dump_mir_dir: Option<String> = (None, parse_opt_string, [UNTRACKED],
@@ -1322,8 +1320,6 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
13221320

13231321
let debugging_opts = build_debugging_options(matches, error_format);
13241322

1325-
let mir_opt_level = debugging_opts.mir_opt_level.unwrap_or(1);
1326-
13271323
let mut output_types = BTreeMap::new();
13281324
if !debugging_opts.parse_only {
13291325
for list in matches.opt_strs("emit") {
@@ -1532,7 +1528,6 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
15321528
maybe_sysroot: sysroot_opt,
15331529
target_triple: target,
15341530
test: test,
1535-
mir_opt_level: mir_opt_level,
15361531
incremental: incremental,
15371532
debugging_opts: debugging_opts,
15381533
prints: prints,
@@ -2475,7 +2470,7 @@ mod tests {
24752470
assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
24762471

24772472
opts = reference.clone();
2478-
opts.debugging_opts.mir_opt_level = Some(1);
2473+
opts.debugging_opts.mir_opt_level = 3;
24792474
assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
24802475
}
24812476
}

Diff for: src/librustc_mir/transform/copy_prop.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,10 @@ impl<'tcx> MirPass<'tcx> for CopyPropagation {
6565
}
6666
}
6767

68-
// We only run when the MIR optimization level is at least 1. This avoids messing up debug
69-
// info.
70-
match tcx.sess.opts.debugging_opts.mir_opt_level {
71-
Some(0) | None => return,
72-
_ => {}
68+
// We only run when the MIR optimization level is > 1.
69+
// This avoids a slow pass, and messing up debug info.
70+
if tcx.sess.opts.debugging_opts.mir_opt_level <= 1 {
71+
return;
7372
}
7473

7574
loop {

Diff for: src/librustc_mir/transform/deaggregator.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,10 @@ impl<'tcx> MirPass<'tcx> for Deaggregator {
2323
let node_id = source.item_id();
2424
let node_path = tcx.item_path_str(tcx.map.local_def_id(node_id));
2525
debug!("running on: {:?}", node_path);
26-
// we only run when mir_opt_level > 1
27-
match tcx.sess.opts.debugging_opts.mir_opt_level {
28-
Some(0) |
29-
Some(1) |
30-
None => { return; },
31-
_ => {}
32-
};
26+
// we only run when mir_opt_level > 2
27+
if tcx.sess.opts.debugging_opts.mir_opt_level <= 2 {
28+
return;
29+
}
3330

3431
// Do not trigger on constants. Could be revised in future
3532
if let MirSource::Fn(_) = source {} else { return; }

Diff for: src/librustc_mir/transform/instcombine.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl<'tcx> MirPass<'tcx> for InstCombine {
3838
_: MirSource,
3939
mir: &mut Mir<'tcx>) {
4040
// We only run when optimizing MIR (at any level).
41-
if tcx.sess.opts.debugging_opts.mir_opt_level == Some(0) {
41+
if tcx.sess.opts.debugging_opts.mir_opt_level == 0 {
4242
return
4343
}
4444

0 commit comments

Comments
 (0)