|
| 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. |
| 4 | +// |
| 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. |
| 10 | + |
| 11 | +pub use super::*; |
| 12 | + |
| 13 | +use rustc::mir::*; |
| 14 | +use dataflow::BitDenotation; |
| 15 | + |
| 16 | +#[derive(Copy, Clone)] |
| 17 | +pub struct MaybeStorageLive<'a, 'tcx: 'a> { |
| 18 | + mir: &'a Mir<'tcx>, |
| 19 | +} |
| 20 | + |
| 21 | +impl<'a, 'tcx: 'a> MaybeStorageLive<'a, 'tcx> { |
| 22 | + pub fn new(mir: &'a Mir<'tcx>) |
| 23 | + -> Self { |
| 24 | + MaybeStorageLive { mir: mir } |
| 25 | + } |
| 26 | + |
| 27 | + pub fn mir(&self) -> &Mir<'tcx> { |
| 28 | + self.mir |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +impl<'a, 'tcx> BitDenotation for MaybeStorageLive<'a, 'tcx> { |
| 33 | + type Idx = Local; |
| 34 | + fn name() -> &'static str { "maybe_storage_live" } |
| 35 | + fn bits_per_block(&self) -> usize { |
| 36 | + self.mir.local_decls.len() |
| 37 | + } |
| 38 | + |
| 39 | + fn start_block_effect(&self, _sets: &mut BlockSets<Local>) { |
| 40 | + // Nothing is live on function entry |
| 41 | + } |
| 42 | + |
| 43 | + fn statement_effect(&self, |
| 44 | + sets: &mut BlockSets<Local>, |
| 45 | + loc: Location) { |
| 46 | + let stmt = &self.mir[loc.block].statements[loc.statement_index]; |
| 47 | + |
| 48 | + match stmt.kind { |
| 49 | + StatementKind::StorageLive(l) => sets.gen(&l), |
| 50 | + StatementKind::StorageDead(l) => sets.kill(&l), |
| 51 | + _ => (), |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + fn terminator_effect(&self, |
| 56 | + _sets: &mut BlockSets<Local>, |
| 57 | + _loc: Location) { |
| 58 | + // Terminators have no effect |
| 59 | + } |
| 60 | + |
| 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 |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +impl<'a, 'tcx> BitwiseOperator for MaybeStorageLive<'a, 'tcx> { |
| 71 | + #[inline] |
| 72 | + fn join(&self, pred1: usize, pred2: usize) -> usize { |
| 73 | + pred1 | pred2 // "maybe" means we union effects of both preds |
| 74 | + } |
| 75 | +} |
| 76 | + |
| 77 | +impl<'a, 'tcx> DataflowOperator for MaybeStorageLive<'a, 'tcx> { |
| 78 | + #[inline] |
| 79 | + fn bottom_value() -> bool { |
| 80 | + false // bottom = dead |
| 81 | + } |
| 82 | +} |
0 commit comments