Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f73cd00

Browse files
committed
Do partial SsaLocals analysis in unoptimized builds
1 parent d8810e3 commit f73cd00

Some content is hidden

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

48 files changed

+334
-280
lines changed

‎compiler/rustc_mir_transform/src/add_retag.rs

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

5151
impl<'tcx> crate::MirPass<'tcx> for AddRetag {
52-
fn is_enabled(&self, sess:&rustc_session::Session) -> bool {
53-
sess.opts.unstable_opts.mir_emit_retag
52+
fn is_enabled(&self, tcx:TyCtxt<'tcx>) -> bool {
53+
tcx.sess.opts.unstable_opts.mir_emit_retag
5454
}
5555

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

‎compiler/rustc_mir_transform/src/check_alignment.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@ use rustc_middle::mir::interpret::Scalar;
33
use rustc_middle::mir::visit::PlaceContext;
44
use rustc_middle::mir::*;
55
use rustc_middle::ty::{Ty, TyCtxt};
6-
use rustc_session::Session;
76

87
use crate::check_pointers::{BorrowCheckMode, PointerCheck, check_pointers};
98

109
pub(super) struct CheckAlignment;
1110

1211
impl<'tcx> crate::MirPass<'tcx> for CheckAlignment {
13-
fn is_enabled(&self, sess:&Session) -> bool {
12+
fn is_enabled(&self, tcx:TyCtxt<'tcx>) -> bool {
1413
// FIXME(#112480) MSVC and rustc disagree on minimum stack alignment on x86 Windows
15-
if sess.target.llvm_target == "i686-pc-windows-msvc" {
14+
if tcx.sess.target.llvm_target == "i686-pc-windows-msvc" {
1615
return false;
1716
}
18-
sess.ub_checks()
17+
tcx.sess.ub_checks()
1918
}
2019

2120
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::{BorrowCheckMode, 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 & 5 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,19 +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);
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);
3354

3455
let fully_moved = fully_moved_locals(&ssa, body);
3556
debug!(?fully_moved);

‎compiler/rustc_mir_transform/src/coverage/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ use crate::coverage::mappings::ExtractedMappings;
3131
pub(super) struct InstrumentCoverage;
3232

3333
impl<'tcx> crate::MirPass<'tcx> for InstrumentCoverage {
34-
fn is_enabled(&self, sess:&rustc_session::Session) -> bool {
35-
sess.instrument_coverage()
34+
fn is_enabled(&self, tcx:TyCtxt<'tcx>) -> bool {
35+
tcx.sess.instrument_coverage()
3636
}
3737

3838
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
@@ -35,8 +35,8 @@ const PLACE_LIMIT: usize = 100;
3535
pub(super) struct DataflowConstProp;
3636

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

4242
#[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>) {

‎compiler/rustc_mir_transform/src/gvn.rs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,21 +107,43 @@ use rustc_span::def_id::DefId;
107107
use smallvec::SmallVec;
108108
use tracing::{debug, instrument, trace};
109109

110-
use crate::ssa::{AssignedValue, SsaLocals};
110+
use crate::pass_manager as pm;
111+
use crate::ssa::{AssignedValue, SsaAnalysis, SsaLocals};
111112

112-
pub(super) struct GVN;
113+
pub(super) enum GVN {
114+
Partial,
115+
Full,
116+
}
113117

114118
impl<'tcx> crate::MirPass<'tcx> for GVN {
115-
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
116-
sess.mir_opt_level() >= 2
119+
fn name(&self) -> &'static str {
120+
match self {
121+
GVN::Partial => "GVN-partial",
122+
GVN::Full => "GVN",
123+
}
124+
}
125+
126+
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
127+
match self {
128+
GVN::Partial => {
129+
tcx.sess.mir_opt_level() == 1
130+
&& !pm::should_run_pass(tcx, &GVN::Full, pm::Optimizations::Allowed)
131+
}
132+
GVN::Full => tcx.sess.mir_opt_level() >= 2,
133+
}
117134
}
118135

119136
#[instrument(level = "trace", skip(self, tcx, body))]
120137
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
121138
debug!(def_id = ?body.source.def_id());
139+
eprintln!("{}", body.local_decls.len() - body.arg_count - 1);
122140

123141
let typing_env = body.typing_env(tcx);
124-
let ssa = SsaLocals::new(tcx, body, typing_env);
142+
let ssa_analysis = match self {
143+
GVN::Partial => SsaAnalysis::Partial,
144+
GVN::Full => SsaAnalysis::Full,
145+
};
146+
let ssa = SsaLocals::new(tcx, body, typing_env, ssa_analysis);
125147
// Clone dominators because we need them while mutating the body.
126148
let dominators = body.basic_blocks.dominators().clone();
127149

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /