]>
Commit | Line | Data |
---|---|---|
ba9703b0 | 1 | use rustc_index::bit_set::BitSet; |
5869c6ff | 2 | use rustc_middle::mir::{self, Local}; |
ba9703b0 XL |
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 | #[derive(Debug, Clone)] | |
11 | pub struct AlwaysLiveLocals(BitSet<Local>); | |
12 | ||
13 | impl AlwaysLiveLocals { | |
14 | pub fn new(body: &mir::Body<'tcx>) -> Self { | |
5869c6ff XL |
15 | let mut always_live_locals = AlwaysLiveLocals(BitSet::new_filled(body.local_decls.len())); |
16 | ||
17 | for block in body.basic_blocks() { | |
18 | for statement in &block.statements { | |
19 | use mir::StatementKind::{StorageDead, StorageLive}; | |
20 | if let StorageLive(l) | StorageDead(l) = statement.kind { | |
21 | always_live_locals.0.remove(l); | |
22 | } | |
23 | } | |
24 | } | |
ba9703b0 | 25 | |
5869c6ff | 26 | always_live_locals |
ba9703b0 XL |
27 | } |
28 | ||
29 | pub fn into_inner(self) -> BitSet<Local> { | |
30 | self.0 | |
31 | } | |
32 | } | |
33 | ||
34 | impl std::ops::Deref for AlwaysLiveLocals { | |
35 | type Target = BitSet<Local>; | |
36 | ||
6a06907d | 37 | #[inline] |
ba9703b0 XL |
38 | fn deref(&self) -> &Self::Target { |
39 | &self.0 | |
40 | } | |
41 | } |