Skip to content

Commit e26c9a4

Browse files
committed
Cache feature unsized locals + use smallvec.
1 parent 05c4eef commit e26c9a4

File tree

1 file changed

+7
-3
lines changed
  • compiler/rustc_mir_transform/src

1 file changed

+7
-3
lines changed

compiler/rustc_mir_transform/src/gvn.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ use rustc_middle::ty::{self, Ty, TyCtxt, TypeAndMut};
9999
use rustc_span::def_id::DefId;
100100
use rustc_span::DUMMY_SP;
101101
use rustc_target::abi::{self, Abi, Size, VariantIdx, FIRST_VARIANT};
102+
use smallvec::SmallVec;
102103
use std::borrow::Cow;
103104

104105
use crate::dataflow_const_prop::DummyMachine;
@@ -241,13 +242,15 @@ struct VnState<'body, 'tcx> {
241242
/// Locals that are assigned that value.
242243
// This vector does not hold all the values of `VnIndex` that we create.
243244
// It stops at the largest value created in the first phase of collecting assignments.
244-
rev_locals: IndexVec<VnIndex, Vec<Local>>,
245+
rev_locals: IndexVec<VnIndex, SmallVec<[Local; 1]>>,
245246
values: FxIndexSet<Value<'tcx>>,
246247
/// Values evaluated as constants if possible.
247248
evaluated: IndexVec<VnIndex, Option<OpTy<'tcx>>>,
248249
/// Counter to generate different values.
249250
/// This is an option to stop creating opaques during replacement.
250251
next_opaque: Option<usize>,
252+
/// Cache the value of the `unsized_locals` features, to avoid fetching it repeatedly in a loop.
253+
feature_unsized_locals: bool,
251254
ssa: &'body SsaLocals,
252255
dominators: &'body Dominators<BasicBlock>,
253256
reused_locals: BitSet<Local>,
@@ -271,6 +274,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
271274
values: FxIndexSet::default(),
272275
evaluated: IndexVec::new(),
273276
next_opaque: Some(0),
277+
feature_unsized_locals: tcx.features().unsized_locals,
274278
ssa,
275279
dominators,
276280
reused_locals: BitSet::new_empty(local_decls.len()),
@@ -318,10 +322,10 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
318322
self.locals[local] = Some(value);
319323

320324
// Only register the value if its type is `Sized`, as we will emit copies of it.
321-
let is_sized = !self.tcx.features().unsized_locals
325+
let is_sized = !self.feature_unsized_locals
322326
|| self.local_decls[local].ty.is_sized(self.tcx, self.param_env);
323327
if is_sized {
324-
self.rev_locals.ensure_contains_elem(value, Vec::new);
328+
self.rev_locals.ensure_contains_elem(value, SmallVec::new);
325329
self.rev_locals[value].push(local);
326330
}
327331
}

0 commit comments

Comments
 (0)