1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
14 use dataflow::BitDenotation;
16 #[derive(Copy, Clone)]
17 pub struct MaybeStorageLive<'a, 'tcx: 'a> {
21 impl<'a, 'tcx: 'a> MaybeStorageLive<'a, 'tcx> {
22 pub fn new(mir: &'a Mir<'tcx>)
24 MaybeStorageLive { mir: mir }
27 pub fn mir(&self) -> &Mir<'tcx> {
32 impl<'a, 'tcx> BitDenotation for MaybeStorageLive<'a, 'tcx> {
34 fn name() -> &'static str { "maybe_storage_live" }
35 fn bits_per_block(&self) -> usize {
36 self.mir.local_decls.len()
39 fn start_block_effect(&self, _sets: &mut BitSet<Local>) {
40 // Nothing is live on function entry
43 fn statement_effect(&self,
44 sets: &mut BlockSets<Local>,
46 let stmt = &self.mir[loc.block].statements[loc.statement_index];
49 StatementKind::StorageLive(l) => sets.gen(l),
50 StatementKind::StorageDead(l) => sets.kill(l),
55 fn terminator_effect(&self,
56 _sets: &mut BlockSets<Local>,
58 // Terminators have no effect
61 fn propagate_call_return(&self,
62 _in_out: &mut BitSet<Local>,
63 _call_bb: mir::BasicBlock,
64 _dest_bb: mir::BasicBlock,
65 _dest_place: &mir::Place) {
66 // Nothing to do when a call returns successfully
70 impl<'a, 'tcx> BitSetOperator for MaybeStorageLive<'a, 'tcx> {
72 fn join<T: Idx>(&self, inout_set: &mut BitSet<T>, in_set: &BitSet<T>) -> bool {
73 inout_set.union(in_set) // "maybe" means we union effects of both preds
77 impl<'a, 'tcx> InitialFlow for MaybeStorageLive<'a, 'tcx> {
79 fn bottom_value() -> bool {
80 false // bottom = dead