2020-03-29 16:15:41 -05:00
|
|
|
use rustc_index::bit_set::BitSet;
|
2021-01-26 18:00:00 -06:00
|
|
|
use rustc_middle::mir::{self, Local};
|
2020-03-29 16:15:41 -05:00
|
|
|
|
|
|
|
/// The set of locals in a MIR body that do not have `StorageLive`/`StorageDead` annotations.
|
|
|
|
///
|
|
|
|
/// These locals have fixed storage for the duration of the body.
|
2022-07-07 12:34:33 -05:00
|
|
|
pub fn always_storage_live_locals(body: &mir::Body<'_>) -> BitSet<Local> {
|
2022-06-02 19:00:00 -05:00
|
|
|
let mut always_live_locals = BitSet::new_filled(body.local_decls.len());
|
2020-03-29 16:15:41 -05:00
|
|
|
|
2022-06-02 19:00:00 -05:00
|
|
|
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.remove(l);
|
2021-01-26 18:00:00 -06:00
|
|
|
}
|
|
|
|
}
|
2020-03-29 16:15:41 -05:00
|
|
|
}
|
|
|
|
|
2022-06-02 19:00:00 -05:00
|
|
|
always_live_locals
|
2020-03-29 16:15:41 -05:00
|
|
|
}
|