]> git.lizzy.rs Git - rust.git/blob - src/librustc_mir/dataflow/impls/storage_liveness.rs
d7575b0f441e6dd45785e35a2dbfeb5f82557447
[rust.git] / src / librustc_mir / dataflow / impls / storage_liveness.rs
1 pub use super::*;
2
3 use rustc::mir::*;
4 use crate::dataflow::BitDenotation;
5
6 #[derive(Copy, Clone)]
7 pub struct MaybeStorageLive<'a, 'tcx> {
8     body: &'a Body<'tcx>,
9 }
10
11 impl<'a, 'tcx> MaybeStorageLive<'a, 'tcx> {
12     pub fn new(body: &'a Body<'tcx>)
13                -> Self {
14         MaybeStorageLive { body }
15     }
16
17     pub fn body(&self) -> &Body<'tcx> {
18         self.body
19     }
20 }
21
22 impl<'a, 'tcx> BitDenotation<'tcx> for MaybeStorageLive<'a, 'tcx> {
23     type Idx = Local;
24     fn name() -> &'static str { "maybe_storage_live" }
25     fn bits_per_block(&self) -> usize {
26         self.body.local_decls.len()
27     }
28
29     fn start_block_effect(&self, _sets: &mut BitSet<Local>) {
30         // Nothing is live on function entry
31     }
32
33     fn statement_effect(&self,
34                         sets: &mut BlockSets<'_, Local>,
35                         loc: Location) {
36         let stmt = &self.body[loc.block].statements[loc.statement_index];
37
38         match stmt.kind {
39             StatementKind::StorageLive(l) => sets.gen(l),
40             StatementKind::StorageDead(l) => sets.kill(l),
41             _ => (),
42         }
43     }
44
45     fn terminator_effect(&self,
46                          _sets: &mut BlockSets<'_, Local>,
47                          _loc: Location) {
48         // Terminators have no effect
49     }
50
51     fn propagate_call_return(
52         &self,
53         _in_out: &mut BitSet<Local>,
54         _call_bb: mir::BasicBlock,
55         _dest_bb: mir::BasicBlock,
56         _dest_place: &mir::Place<'tcx>,
57     ) {
58         // Nothing to do when a call returns successfully
59     }
60 }
61
62 impl<'a, 'tcx> BitSetOperator for MaybeStorageLive<'a, 'tcx> {
63     #[inline]
64     fn join<T: Idx>(&self, inout_set: &mut BitSet<T>, in_set: &BitSet<T>) -> bool {
65         inout_set.union(in_set) // "maybe" means we union effects of both preds
66     }
67 }
68
69 impl<'a, 'tcx> InitialFlow for MaybeStorageLive<'a, 'tcx> {
70     #[inline]
71     fn bottom_value() -> bool {
72         false // bottom = dead
73     }
74 }