Skip to content

Commit e2e9e49

Browse files
committed
Extract mir_opt_level to a method and use Option to be able to know if the value is provided or not
1 parent 476acbf commit e2e9e49

File tree

14 files changed

+34
-29
lines changed

14 files changed

+34
-29
lines changed

compiler/rustc_mir/src/transform/const_goto.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub struct ConstGoto;
2828

2929
impl<'tcx> MirPass<'tcx> for ConstGoto {
3030
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
31-
if tcx.sess.opts.debugging_opts.mir_opt_level < 3 {
31+
if tcx.sess.mir_opt_level() < 3 {
3232
return;
3333
}
3434
trace!("Running ConstGoto on {:?}", body.source);

compiler/rustc_mir/src/transform/const_prop.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
725725
return None;
726726
}
727727

728-
if self.tcx.sess.opts.debugging_opts.mir_opt_level >= 3 {
728+
if self.tcx.sess.mir_opt_level() >= 3 {
729729
self.eval_rvalue_with_identities(rvalue, place)
730730
} else {
731731
self.use_ecx(|this| this.ecx.eval_rvalue_into_place(rvalue, place))
@@ -903,7 +903,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
903903

904904
/// Returns `true` if and only if this `op` should be const-propagated into.
905905
fn should_const_prop(&mut self, op: &OpTy<'tcx>) -> bool {
906-
let mir_opt_level = self.tcx.sess.opts.debugging_opts.mir_opt_level;
906+
let mir_opt_level = self.tcx.sess.mir_opt_level();
907907

908908
if mir_opt_level == 0 {
909909
return false;
@@ -1073,7 +1073,7 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> {
10731073

10741074
// Only const prop copies and moves on `mir_opt_level=2` as doing so
10751075
// currently slightly increases compile time in some cases.
1076-
if self.tcx.sess.opts.debugging_opts.mir_opt_level >= 2 {
1076+
if self.tcx.sess.mir_opt_level() >= 2 {
10771077
self.propagate_operand(operand)
10781078
}
10791079
}

compiler/rustc_mir/src/transform/deduplicate_blocks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub struct DeduplicateBlocks;
1616

1717
impl<'tcx> MirPass<'tcx> for DeduplicateBlocks {
1818
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
19-
if tcx.sess.opts.debugging_opts.mir_opt_level < 3 {
19+
if tcx.sess.mir_opt_level() < 3 {
2020
return;
2121
}
2222
debug!("Running DeduplicateBlocks on `{:?}`", body.source);

compiler/rustc_mir/src/transform/dest_prop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ impl<'tcx> MirPass<'tcx> for DestinationPropagation {
129129
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
130130
// Only run at mir-opt-level=2 or higher for now (we don't fix up debuginfo and remove
131131
// storage statements at the moment).
132-
if tcx.sess.opts.debugging_opts.mir_opt_level <= 1 {
132+
if tcx.sess.mir_opt_level() <= 1 {
133133
return;
134134
}
135135

compiler/rustc_mir/src/transform/early_otherwise_branch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub struct EarlyOtherwiseBranch;
2626

2727
impl<'tcx> MirPass<'tcx> for EarlyOtherwiseBranch {
2828
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
29-
if tcx.sess.opts.debugging_opts.mir_opt_level < 2 {
29+
if tcx.sess.mir_opt_level() < 2 {
3030
return;
3131
}
3232
trace!("running EarlyOtherwiseBranch on {:?}", body.source);

compiler/rustc_mir/src/transform/inline.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ crate fn is_enabled(tcx: TyCtxt<'_>) -> bool {
5252
return enabled;
5353
}
5454

55-
tcx.sess.opts.debugging_opts.mir_opt_level >= 2
55+
tcx.sess.mir_opt_level() >= 2
5656
}
5757

5858
impl<'tcx> MirPass<'tcx> for Inline {

compiler/rustc_mir/src/transform/match_branches.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub struct MatchBranchSimplification;
4040
4141
impl<'tcx> MirPass<'tcx> for MatchBranchSimplification {
4242
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
43-
if tcx.sess.opts.debugging_opts.mir_opt_level <= 1 {
43+
if tcx.sess.mir_opt_level() <= 1 {
4444
return;
4545
}
4646

compiler/rustc_mir/src/transform/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ fn run_post_borrowck_cleanup_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tc
475475
}
476476

477477
fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
478-
let mir_opt_level = tcx.sess.opts.debugging_opts.mir_opt_level;
478+
let mir_opt_level = tcx.sess.mir_opt_level();
479479

480480
// Lowering generator control-flow and variables has to happen before we do anything else
481481
// to them. We run some optimizations before that, because they may be harder to do on the state

compiler/rustc_mir/src/transform/multiple_return_terminators.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub struct MultipleReturnTerminators;
1010

1111
impl<'tcx> MirPass<'tcx> for MultipleReturnTerminators {
1212
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
13-
if tcx.sess.opts.debugging_opts.mir_opt_level < 3 {
13+
if tcx.sess.mir_opt_level() < 3 {
1414
return;
1515
}
1616

compiler/rustc_mir/src/transform/nrvo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub struct RenameReturnPlace;
3434

3535
impl<'tcx> MirPass<'tcx> for RenameReturnPlace {
3636
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut mir::Body<'tcx>) {
37-
if tcx.sess.opts.debugging_opts.mir_opt_level == 0 {
37+
if tcx.sess.mir_opt_level() == 0 {
3838
return;
3939
}
4040

0 commit comments

Comments
 (0)