]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_mir_dataflow/src/storage.rs
Auto merge of #95685 - oxidecomputer:restore-static-dwarf, r=pnkfelix
[rust.git] / compiler / rustc_mir_dataflow / src / storage.rs
1 use rustc_index::bit_set::BitSet;
2 use rustc_middle::mir::{self, Local};
3
4 /// The set of locals in a MIR body that do not have `StorageLive`/`StorageDead` annotations.
5 ///
6 /// These locals have fixed storage for the duration of the body.
7 //
8 // FIXME: Currently, we need to traverse the entire MIR to compute this. We should instead store it
9 // as a field in the `LocalDecl` for each `Local`.
10 pub fn always_storage_live_locals(body: &mir::Body<'_>) -> BitSet<Local> {
11     let mut always_live_locals = BitSet::new_filled(body.local_decls.len());
12
13     for block in body.basic_blocks() {
14         for statement in &block.statements {
15             use mir::StatementKind::{StorageDead, StorageLive};
16             if let StorageLive(l) | StorageDead(l) = statement.kind {
17                 always_live_locals.remove(l);
18             }
19         }
20     }
21
22     always_live_locals
23 }