Skip to content

Commit

Permalink
add -Z mir-opt-level to disable MIR optimizations
Browse files Browse the repository at this point in the history
setting -Z mir-opt-level=0 will disable all MIR optimizations
for easier debugging
  • Loading branch information
Ariel Ben-Yehuda authored and arielb1 committed Feb 19, 2016
1 parent addc653 commit 999f176
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/librustc/session/config.rs
Expand Up @@ -138,6 +138,7 @@ pub struct Options {
pub no_trans: bool,
pub error_format: ErrorOutputType,
pub treat_err_as_bug: bool,
pub mir_opt_level: usize,

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

pub fn default_lib_output() -> CrateType {
Expand Down Expand Up @@ -988,6 +992,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
let parse_only = debugging_opts.parse_only;
let no_trans = debugging_opts.no_trans;
let treat_err_as_bug = debugging_opts.treat_err_as_bug;
let mir_opt_level = debugging_opts.mir_opt_level.unwrap_or(1);
let incremental_compilation = debugging_opts.incr_comp;
let dump_dep_graph = debugging_opts.dump_dep_graph;
let no_analysis = debugging_opts.no_analysis;
Expand Down Expand Up @@ -1166,6 +1171,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
parse_only: parse_only,
no_trans: no_trans,
treat_err_as_bug: treat_err_as_bug,
mir_opt_level: mir_opt_level,
build_dep_graph: incremental_compilation || dump_dep_graph,
dump_dep_graph: dump_dep_graph,
no_analysis: no_analysis,
Expand Down
5 changes: 3 additions & 2 deletions src/librustc_mir/mir_map.rs
Expand Up @@ -148,10 +148,11 @@ impl<'a, 'm, 'tcx> Visitor<'tcx> for InnerDump<'a,'m,'tcx> {

match build_mir(Cx::new(&infcx), implicit_arg_tys, id, span, decl, body) {
Ok(mut mir) => {
simplify_cfg::SimplifyCfg::new().run_on_mir(&mut mir, self.tcx);
type_check::TypeckMir::new(&infcx).run_on_mir(&mut mir, self.tcx);
no_landing_pads::NoLandingPads.run_on_mir(&mut mir, self.tcx);

if self.tcx.sess.opts.mir_opt_level > 0 {
simplify_cfg::SimplifyCfg::new().run_on_mir(&mut mir, self.tcx);
}
let meta_item_list = self.attr
.iter()
.flat_map(|a| a.meta_item_list())
Expand Down

0 comments on commit 999f176

Please sign in to comment.