Skip to content

Commit 8922a59

Browse files
committed
Tentatively revert "remove mir optimization count from session"
This reverts commit f9621f3.
1 parent f9621f3 commit 8922a59

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

compiler/rustc_mir_transform/src/pass_manager.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::cell::RefCell;
22
use std::collections::hash_map::Entry;
3-
use std::sync::atomic::{AtomicUsize, Ordering};
3+
use std::sync::atomic::Ordering;
44

55
use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
66
use rustc_middle::mir::{Body, MirDumper, MirPhase, RuntimePhase};
@@ -290,6 +290,7 @@ fn run_passes_inner<'tcx>(
290290
&& let Some(limit) = &tcx.sess.opts.unstable_opts.mir_opt_bisect_limit
291291
{
292292
if limited_by_opt_bisect(
293+
tcx,
293294
tcx.def_path_debug_str(body.source.def_id()),
294295
*limit,
295296
*pass,
@@ -380,13 +381,17 @@ fn is_optimization_stage(
380381
&& phase_change == Some(MirPhase::Runtime(RuntimePhase::Optimized))
381382
}
382383

383-
static MIR_OPT_BISECT_COUNT: AtomicUsize = AtomicUsize::new(0);
384-
385-
fn limited_by_opt_bisect<'tcx, P>(def_path: String, limit: usize, pass: &P) -> bool
384+
fn limited_by_opt_bisect<'tcx, P>(
385+
tcx: TyCtxt<'tcx>,
386+
def_path: String,
387+
limit: usize,
388+
pass: &P,
389+
) -> bool
386390
where
387391
P: MirPass<'tcx> + ?Sized,
388392
{
389-
let current_opt_bisect_count = MIR_OPT_BISECT_COUNT.fetch_add(1, Ordering::Relaxed);
393+
let current_opt_bisect_count =
394+
tcx.sess.mir_opt_bisect_eval_count.fetch_add(1, Ordering::Relaxed);
390395

391396
let can_run = current_opt_bisect_count < limit;
392397

compiler/rustc_session/src/session.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::any::Any;
22
use std::path::PathBuf;
33
use std::str::FromStr;
44
use std::sync::Arc;
5-
use std::sync::atomic::AtomicBool;
5+
use std::sync::atomic::{AtomicBool, AtomicUsize};
66
use std::{env, io};
77

88
use rand::{RngCore, rng};
@@ -158,6 +158,12 @@ pub struct Session {
158158
/// The names of intrinsics that the current codegen backend replaces
159159
/// with its own implementations.
160160
pub replaced_intrinsics: FxHashSet<Symbol>,
161+
162+
/// Global per-session counter for MIR optimization pass applications.
163+
///
164+
/// Used by `-Zmir-opt-bisect-limit` to assign an index to each
165+
/// optimization-pass execution candidate during this compilation.
166+
pub mir_opt_bisect_eval_count: AtomicUsize,
161167
}
162168

163169
#[derive(Clone, Copy)]
@@ -1097,6 +1103,7 @@ pub fn build_session(
10971103
host_filesearch,
10981104
invocation_temp,
10991105
replaced_intrinsics: FxHashSet::default(), // filled by `run_compiler`
1106+
mir_opt_bisect_eval_count: AtomicUsize::new(0),
11001107
};
11011108

11021109
validate_commandline_args_with_session_available(&sess);

0 commit comments

Comments
 (0)