Skip to content

Commit af78194

Browse files
committed
Reuse eligible_storage_live memory.
1 parent c2354aa commit af78194

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

compiler/rustc_mir_transform/src/coroutine.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,7 @@ fn compute_storage_conflicts<'mir, 'tcx>(
942942
body,
943943
saved_locals: saved_locals,
944944
local_conflicts: BitMatrix::from_row_n(&ineligible_locals, body.local_decls.len()),
945+
eligible_storage_live: BitSet::new_empty(body.local_decls.len()),
945946
};
946947

947948
requires_storage.visit_reachable_with(body, &mut visitor);
@@ -978,6 +979,8 @@ struct StorageConflictVisitor<'mir, 'tcx, 's> {
978979
// FIXME(tmandry): Consider using sparse bitsets here once we have good
979980
// benchmarks for coroutines.
980981
local_conflicts: BitMatrix<Local, Local>,
982+
// We keep this bitset as a buffer to avoid reallocating memory.
983+
eligible_storage_live: BitSet<Local>,
981984
}
982985

983986
impl<'mir, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'mir, 'tcx, R>
@@ -1009,19 +1012,19 @@ impl<'mir, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'mir, 'tcx, R>
10091012
impl StorageConflictVisitor<'_, '_, '_> {
10101013
fn apply_state(&mut self, flow_state: &BitSet<Local>, loc: Location) {
10111014
// Ignore unreachable blocks.
1012-
if self.body.basic_blocks[loc.block].terminator().kind == TerminatorKind::Unreachable {
1015+
if let TerminatorKind::Unreachable = self.body.basic_blocks[loc.block].terminator().kind {
10131016
return;
10141017
}
10151018

1016-
let mut eligible_storage_live = flow_state.clone();
1017-
eligible_storage_live.intersect(&**self.saved_locals);
1019+
self.eligible_storage_live.clone_from(flow_state);
1020+
self.eligible_storage_live.intersect(&**self.saved_locals);
10181021

1019-
for local in eligible_storage_live.iter() {
1020-
self.local_conflicts.union_row_with(&eligible_storage_live, local);
1022+
for local in self.eligible_storage_live.iter() {
1023+
self.local_conflicts.union_row_with(&self.eligible_storage_live, local);
10211024
}
10221025

1023-
if eligible_storage_live.count() > 1 {
1024-
trace!("at {:?}, eligible_storage_live={:?}", loc, eligible_storage_live);
1026+
if self.eligible_storage_live.count() > 1 {
1027+
trace!("at {:?}, eligible_storage_live={:?}", loc, self.eligible_storage_live);
10251028
}
10261029
}
10271030
}

0 commit comments

Comments
 (0)