Skip to content

Commit 24ca96a

Browse files
committed
Do partial SsaLocals analysis in unoptimized builds
1 parent 51ff895 commit 24ca96a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+429
-144
lines changed

compiler/rustc_mir_transform/src/add_retag.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ fn may_contain_reference<'tcx>(ty: Ty<'tcx>, depth: u32, tcx: TyCtxt<'tcx>) -> b
4747
}
4848

4949
impl<'tcx> crate::MirPass<'tcx> for AddRetag {
50-
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
51-
sess.opts.unstable_opts.mir_emit_retag
50+
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
51+
tcx.sess.opts.unstable_opts.mir_emit_retag
5252
}
5353

5454
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {

compiler/rustc_mir_transform/src/check_alignment.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ use rustc_middle::mir::interpret::Scalar;
44
use rustc_middle::mir::visit::PlaceContext;
55
use rustc_middle::mir::*;
66
use rustc_middle::ty::{Ty, TyCtxt};
7-
use rustc_session::Session;
87

98
use crate::check_pointers::{BorrowedFieldProjectionMode, PointerCheck, check_pointers};
109

1110
pub(super) struct CheckAlignment;
1211

1312
impl<'tcx> crate::MirPass<'tcx> for CheckAlignment {
14-
fn is_enabled(&self, sess: &Session) -> bool {
15-
sess.ub_checks()
13+
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
14+
tcx.sess.ub_checks()
1615
}
1716

1817
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {

compiler/rustc_mir_transform/src/check_enums.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use rustc_middle::mir::visit::Visitor;
66
use rustc_middle::mir::*;
77
use rustc_middle::ty::layout::PrimitiveExt;
88
use rustc_middle::ty::{self, Ty, TyCtxt, TypingEnv};
9-
use rustc_session::Session;
109
use tracing::debug;
1110

1211
/// This pass inserts checks for a valid enum discriminant where they are most
@@ -15,8 +14,8 @@ use tracing::debug;
1514
pub(super) struct CheckEnums;
1615

1716
impl<'tcx> crate::MirPass<'tcx> for CheckEnums {
18-
fn is_enabled(&self, sess: &Session) -> bool {
19-
sess.ub_checks()
17+
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
18+
tcx.sess.ub_checks()
2019
}
2120

2221
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {

compiler/rustc_mir_transform/src/check_null.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@ use rustc_index::IndexVec;
22
use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext};
33
use rustc_middle::mir::*;
44
use rustc_middle::ty::{Ty, TyCtxt};
5-
use rustc_session::Session;
65

76
use crate::check_pointers::{BorrowedFieldProjectionMode, PointerCheck, check_pointers};
87

98
pub(super) struct CheckNull;
109

1110
impl<'tcx> crate::MirPass<'tcx> for CheckNull {
12-
fn is_enabled(&self, sess: &Session) -> bool {
13-
sess.ub_checks()
11+
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
12+
tcx.sess.ub_checks()
1413
}
1514

1615
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {

compiler/rustc_mir_transform/src/copy_prop.rs

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use rustc_middle::mir::*;
55
use rustc_middle::ty::TyCtxt;
66
use tracing::{debug, instrument};
77

8-
use crate::ssa::SsaLocals;
8+
use crate::pass_manager as pm;
9+
use crate::ssa::{SsaAnalysis, SsaLocals};
910

1011
/// Unify locals that copy each other.
1112
///
@@ -17,21 +18,39 @@ use crate::ssa::SsaLocals;
1718
/// where each of the locals is only assigned once.
1819
///
1920
/// We want to replace all those locals by `_a`, either copied or moved.
20-
pub(super) struct CopyProp;
21+
pub(super) enum CopyProp {
22+
Partial,
23+
Full,
24+
}
2125

2226
impl<'tcx> crate::MirPass<'tcx> for CopyProp {
23-
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
24-
sess.mir_opt_level() >= 1
27+
fn name(&self) -> &'static str {
28+
match self {
29+
CopyProp::Partial => "CopyProp-partial",
30+
CopyProp::Full => "CopyProp",
31+
}
32+
}
33+
34+
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
35+
match self {
36+
CopyProp::Partial => {
37+
tcx.sess.mir_opt_level() == 1
38+
&& !pm::should_run_pass(tcx, &CopyProp::Full, pm::Optimizations::Allowed)
39+
}
40+
CopyProp::Full => tcx.sess.mir_opt_level() >= 2,
41+
}
2542
}
2643

2744
#[instrument(level = "trace", skip(self, tcx, body))]
2845
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
2946
debug!(def_id = ?body.source.def_id());
3047

3148
let typing_env = body.typing_env(tcx);
32-
let ssa = SsaLocals::new(tcx, body, typing_env);
33-
debug!(borrowed_locals = ?ssa.borrowed_locals());
34-
debug!(copy_classes = ?ssa.copy_classes());
49+
let ssa_analysis = match self {
50+
CopyProp::Partial => SsaAnalysis::Partial,
51+
CopyProp::Full => SsaAnalysis::Full,
52+
};
53+
let ssa = SsaLocals::new(tcx, body, typing_env, ssa_analysis);
3554

3655
let mut any_replacement = false;
3756
let mut storage_to_remove = DenseBitSet::new_empty(body.local_decls.len());

compiler/rustc_mir_transform/src/coverage/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ mod unexpand;
2424
pub(super) struct InstrumentCoverage;
2525

2626
impl<'tcx> crate::MirPass<'tcx> for InstrumentCoverage {
27-
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
28-
sess.instrument_coverage()
27+
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
28+
tcx.sess.instrument_coverage()
2929
}
3030

3131
fn run_pass(&self, tcx: TyCtxt<'tcx>, mir_body: &mut mir::Body<'tcx>) {

compiler/rustc_mir_transform/src/dataflow_const_prop.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ const PLACE_LIMIT: usize = 100;
3434
pub(super) struct DataflowConstProp;
3535

3636
impl<'tcx> crate::MirPass<'tcx> for DataflowConstProp {
37-
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
38-
sess.mir_opt_level() >= 3
37+
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
38+
tcx.sess.mir_opt_level() >= 3
3939
}
4040

4141
#[instrument(skip_all level = "debug")]

compiler/rustc_mir_transform/src/dead_store_elimination.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ impl<'tcx> crate::MirPass<'tcx> for DeadStoreElimination {
140140
}
141141
}
142142

143-
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
144-
sess.mir_opt_level() >= 2
143+
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
144+
tcx.sess.mir_opt_level() >= 2
145145
}
146146

147147
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {

compiler/rustc_mir_transform/src/dest_prop.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ use tracing::{debug, trace};
149149
pub(super) struct DestinationPropagation;
150150

151151
impl<'tcx> crate::MirPass<'tcx> for DestinationPropagation {
152-
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
152+
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
153153
// For now, only run at MIR opt level 3. Two things need to be changed before this can be
154154
// turned on by default:
155155
// 1. Because of the overeager removal of storage statements, this can cause stack space
@@ -158,7 +158,7 @@ impl<'tcx> crate::MirPass<'tcx> for DestinationPropagation {
158158
// 2. Despite being an overall perf improvement, this still causes a 30% regression in
159159
// keccak. We can temporarily fix this by bounding function size, but in the long term
160160
// we should fix this by being smarter about invalidating analysis results.
161-
sess.mir_opt_level() >= 3
161+
tcx.sess.mir_opt_level() >= 3
162162
}
163163

164164
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {

compiler/rustc_mir_transform/src/early_otherwise_branch.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ use crate::patch::MirPatch;
9393
pub(super) struct EarlyOtherwiseBranch;
9494

9595
impl<'tcx> crate::MirPass<'tcx> for EarlyOtherwiseBranch {
96-
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
97-
sess.mir_opt_level() >= 2
96+
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
97+
tcx.sess.mir_opt_level() >= 2
9898
}
9999

100100
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {

0 commit comments

Comments
 (0)