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 BlockSets<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 IdxSet<Local>,
63 _call_bb: mir::BasicBlock,
64 _dest_bb: mir::BasicBlock,
65 _dest_lval: &mir::Lvalue) {
66 // Nothing to do when a call returns successfully
70 impl<'a, 'tcx> BitwiseOperator for MaybeStorageLive<'a, 'tcx> {
72 fn join(&self, pred1: usize, pred2: usize) -> usize {
73 pred1 | pred2 // "maybe" means we union effects of both preds
77 impl<'a, 'tcx> DataflowOperator for MaybeStorageLive<'a, 'tcx> {
79 fn bottom_value() -> bool {
80 false // bottom = dead