diff options
| author | bors <bors@rust-lang.org> | 2021-01-29 06:56:29 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-01-29 06:56:29 +0000 |
| commit | 099f27b6cbf10e31d41e4a2e6cb55ec39dbb0527 (patch) | |
| tree | 1e11c0eb1e08b0ed273f36829fb4dbd784521359 | |
| parent | c6bc46227ab57a844fc7a9ed3a6c9efb35c725a9 (diff) | |
| parent | 56865936a721da731cb5b61512b2d0756df09299 (diff) | |
| download | rust-099f27b6cbf10e31d41e4a2e6cb55ec39dbb0527.tar.gz rust-099f27b6cbf10e31d41e4a2e6cb55ec39dbb0527.zip | |
Auto merge of #81440 - tmiasko:always-live-locals, r=matthewjasper
Visit only statements in always live locals No functional changes intended.
| -rw-r--r-- | compiler/rustc_mir/src/util/storage.rs | 31 |
1 files changed, 12 insertions, 19 deletions
diff --git a/compiler/rustc_mir/src/util/storage.rs b/compiler/rustc_mir/src/util/storage.rs index 0b7b1c29537..4e1696cd716 100644 --- a/compiler/rustc_mir/src/util/storage.rs +++ b/compiler/rustc_mir/src/util/storage.rs @@ -1,6 +1,5 @@ use rustc_index::bit_set::BitSet; -use rustc_middle::mir::visit::Visitor; -use rustc_middle::mir::{self, Local, Location}; +use rustc_middle::mir::{self, Local}; /// The set of locals in a MIR body that do not have `StorageLive`/`StorageDead` annotations. /// @@ -13,12 +12,18 @@ pub struct AlwaysLiveLocals(BitSet<Local>); impl AlwaysLiveLocals { pub fn new(body: &mir::Body<'tcx>) -> Self { - let mut ret = AlwaysLiveLocals(BitSet::new_filled(body.local_decls.len())); - - let mut vis = StorageAnnotationVisitor(&mut ret); - vis.visit_body(body); + let mut always_live_locals = AlwaysLiveLocals(BitSet::new_filled(body.local_decls.len())); + + for block in body.basic_blocks() { + for statement in &block.statements { + use mir::StatementKind::{StorageDead, StorageLive}; + if let StorageLive(l) | StorageDead(l) = statement.kind { + always_live_locals.0.remove(l); + } + } + } - ret + always_live_locals } pub fn into_inner(self) -> BitSet<Local> { @@ -33,15 +38,3 @@ impl std::ops::Deref for AlwaysLiveLocals { &self.0 } } - -/// Removes locals that have `Storage*` annotations from `AlwaysLiveLocals`. -struct StorageAnnotationVisitor<'a>(&'a mut AlwaysLiveLocals); - -impl Visitor<'tcx> for StorageAnnotationVisitor<'_> { - fn visit_statement(&mut self, statement: &mir::Statement<'tcx>, _location: Location) { - use mir::StatementKind::{StorageDead, StorageLive}; - if let StorageLive(l) | StorageDead(l) = statement.kind { - (self.0).0.remove(l); - } - } -} |
