mirror of
https://github.com/rust-lang/rust.git
synced 2025-10-27 11:05:06 +00:00
24 lines
856 B
Rust
24 lines
856 B
Rust
use rustc_index::bit_set::BitSet;
|
|
use rustc_middle::mir::{self, Local};
|
|
|
|
/// 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.
|
|
//
|
|
// FIXME: Currently, we need to traverse the entire MIR to compute this. We should instead store it
|
|
// as a field in the `LocalDecl` for each `Local`.
|
|
pub fn always_live_locals(body: &mir::Body<'_>) -> BitSet<Local> {
|
|
let mut always_live_locals = 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.remove(l);
|
|
}
|
|
}
|
|
}
|
|
|
|
always_live_locals
|
|
}
|