Auto merge of #81440 - tmiasko:always-live-locals, r=matthewjasper
Visit only statements in always live locals No functional changes intended.
This commit is contained in:
commit
099f27b6cb
1 changed files with 11 additions and 18 deletions
|
@ -1,6 +1,5 @@
|
||||||
use rustc_index::bit_set::BitSet;
|
use rustc_index::bit_set::BitSet;
|
||||||
use rustc_middle::mir::visit::Visitor;
|
use rustc_middle::mir::{self, Local};
|
||||||
use rustc_middle::mir::{self, Local, Location};
|
|
||||||
|
|
||||||
/// The set of locals in a MIR body that do not have `StorageLive`/`StorageDead` annotations.
|
/// 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 {
|
impl AlwaysLiveLocals {
|
||||||
pub fn new(body: &mir::Body<'tcx>) -> Self {
|
pub fn new(body: &mir::Body<'tcx>) -> Self {
|
||||||
let mut ret = AlwaysLiveLocals(BitSet::new_filled(body.local_decls.len()));
|
let mut always_live_locals = AlwaysLiveLocals(BitSet::new_filled(body.local_decls.len()));
|
||||||
|
|
||||||
let mut vis = StorageAnnotationVisitor(&mut ret);
|
for block in body.basic_blocks() {
|
||||||
vis.visit_body(body);
|
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> {
|
pub fn into_inner(self) -> BitSet<Local> {
|
||||||
|
@ -33,15 +38,3 @@ impl std::ops::Deref for AlwaysLiveLocals {
|
||||||
&self.0
|
&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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue