Skip to content

Commit 999f176

Browse files
Ariel Ben-Yehudaarielb1
authored andcommitted
add -Z mir-opt-level to disable MIR optimizations
setting -Z mir-opt-level=0 will disable all MIR optimizations for easier debugging
1 parent addc653 commit 999f176

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/librustc/session/config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ pub struct Options {
138138
pub no_trans: bool,
139139
pub error_format: ErrorOutputType,
140140
pub treat_err_as_bug: bool,
141+
pub mir_opt_level: usize,
141142

142143
/// if true, build up the dep-graph
143144
pub build_dep_graph: bool,
@@ -254,6 +255,7 @@ pub fn basic_options() -> Options {
254255
parse_only: false,
255256
no_trans: false,
256257
treat_err_as_bug: false,
258+
mir_opt_level: 1,
257259
build_dep_graph: false,
258260
dump_dep_graph: false,
259261
no_analysis: false,
@@ -655,6 +657,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
655657
"show spans for compiler debugging (expr|pat|ty)"),
656658
print_trans_items: Option<String> = (None, parse_opt_string,
657659
"print the result of the translation item collection pass"),
660+
mir_opt_level: Option<usize> = (None, parse_opt_uint,
661+
"set the MIR optimization level (0-3)"),
658662
}
659663

660664
pub fn default_lib_output() -> CrateType {
@@ -988,6 +992,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
988992
let parse_only = debugging_opts.parse_only;
989993
let no_trans = debugging_opts.no_trans;
990994
let treat_err_as_bug = debugging_opts.treat_err_as_bug;
995+
let mir_opt_level = debugging_opts.mir_opt_level.unwrap_or(1);
991996
let incremental_compilation = debugging_opts.incr_comp;
992997
let dump_dep_graph = debugging_opts.dump_dep_graph;
993998
let no_analysis = debugging_opts.no_analysis;
@@ -1166,6 +1171,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
11661171
parse_only: parse_only,
11671172
no_trans: no_trans,
11681173
treat_err_as_bug: treat_err_as_bug,
1174+
mir_opt_level: mir_opt_level,
11691175
build_dep_graph: incremental_compilation || dump_dep_graph,
11701176
dump_dep_graph: dump_dep_graph,
11711177
no_analysis: no_analysis,

src/librustc_mir/mir_map.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,11 @@ impl<'a, 'm, 'tcx> Visitor<'tcx> for InnerDump<'a,'m,'tcx> {
148148

149149
match build_mir(Cx::new(&infcx), implicit_arg_tys, id, span, decl, body) {
150150
Ok(mut mir) => {
151-
simplify_cfg::SimplifyCfg::new().run_on_mir(&mut mir, self.tcx);
152151
type_check::TypeckMir::new(&infcx).run_on_mir(&mut mir, self.tcx);
153152
no_landing_pads::NoLandingPads.run_on_mir(&mut mir, self.tcx);
154-
153+
if self.tcx.sess.opts.mir_opt_level > 0 {
154+
simplify_cfg::SimplifyCfg::new().run_on_mir(&mut mir, self.tcx);
155+
}
155156
let meta_item_list = self.attr
156157
.iter()
157158
.flat_map(|a| a.meta_item_list())

0 commit comments

Comments
 (0)