]> git.lizzy.rs Git - rust.git/blob - src/librustc_mir/dataflow/impls/storage_liveness.rs
Remove `MaybeRequiresStorage`
[rust.git] / src / librustc_mir / dataflow / impls / storage_liveness.rs
1 pub use super::*;
2
3 use crate::dataflow::BottomValue;
4 use crate::dataflow::{self, GenKill};
5 use crate::util::storage::AlwaysLiveLocals;
6 use rustc_middle::mir::*;
7
8 #[derive(Clone)]
9 pub struct MaybeStorageLive {
10     always_live_locals: AlwaysLiveLocals,
11 }
12
13 impl MaybeStorageLive {
14     pub fn new(always_live_locals: AlwaysLiveLocals) -> Self {
15         MaybeStorageLive { always_live_locals }
16     }
17 }
18
19 impl dataflow::AnalysisDomain<'tcx> for MaybeStorageLive {
20     type Idx = Local;
21
22     const NAME: &'static str = "maybe_storage_live";
23
24     fn bits_per_block(&self, body: &mir::Body<'tcx>) -> usize {
25         body.local_decls.len()
26     }
27
28     fn initialize_start_block(&self, body: &mir::Body<'tcx>, on_entry: &mut BitSet<Self::Idx>) {
29         assert_eq!(body.local_decls.len(), self.always_live_locals.domain_size());
30         for local in self.always_live_locals.iter() {
31             on_entry.insert(local);
32         }
33
34         for arg in body.args_iter() {
35             on_entry.insert(arg);
36         }
37     }
38 }
39
40 impl dataflow::GenKillAnalysis<'tcx> for MaybeStorageLive {
41     fn statement_effect(
42         &self,
43         trans: &mut impl GenKill<Self::Idx>,
44         stmt: &mir::Statement<'tcx>,
45         _: Location,
46     ) {
47         match stmt.kind {
48             StatementKind::StorageLive(l) => trans.gen(l),
49             StatementKind::StorageDead(l) => trans.kill(l),
50             _ => (),
51         }
52     }
53
54     fn terminator_effect(
55         &self,
56         _trans: &mut impl GenKill<Self::Idx>,
57         _: &mir::Terminator<'tcx>,
58         _: Location,
59     ) {
60         // Terminators have no effect
61     }
62
63     fn call_return_effect(
64         &self,
65         _trans: &mut impl GenKill<Self::Idx>,
66         _block: BasicBlock,
67         _func: &mir::Operand<'tcx>,
68         _args: &[mir::Operand<'tcx>],
69         _return_place: mir::Place<'tcx>,
70     ) {
71         // Nothing to do when a call returns successfully
72     }
73 }
74
75 impl BottomValue for MaybeStorageLive {
76     /// bottom = dead
77     const BOTTOM_VALUE: bool = false;
78 }