|
| 1 | +use rustc_index::bit_set::BitSet; |
| 2 | +use rustc_middle::mir; |
| 3 | +use rustc_mir_dataflow::{AnalysisDomain, CallReturnPlaces, GenKill, GenKillAnalysis}; |
| 4 | + |
| 5 | +/// Determines liveness of each local purely based on `StorageLive`/`Dead`. |
| 6 | +#[derive(Copy, Clone)] |
| 7 | +pub struct MaybeStorageLive; |
| 8 | + |
| 9 | +impl<'tcx> AnalysisDomain<'tcx> for MaybeStorageLive { |
| 10 | + type Domain = BitSet<mir::Local>; |
| 11 | + const NAME: &'static str = "maybe_storage_live"; |
| 12 | + |
| 13 | + fn bottom_value(&self, body: &mir::Body<'tcx>) -> Self::Domain { |
| 14 | + // bottom = dead |
| 15 | + BitSet::new_empty(body.local_decls.len()) |
| 16 | + } |
| 17 | + |
| 18 | + fn initialize_start_block(&self, body: &mir::Body<'tcx>, state: &mut Self::Domain) { |
| 19 | + for arg in body.args_iter() { |
| 20 | + state.insert(arg); |
| 21 | + } |
| 22 | + } |
| 23 | +} |
| 24 | + |
| 25 | +impl<'tcx> GenKillAnalysis<'tcx> for MaybeStorageLive { |
| 26 | + type Idx = mir::Local; |
| 27 | + |
| 28 | + fn statement_effect(&self, trans: &mut impl GenKill<Self::Idx>, stmt: &mir::Statement<'tcx>, _: mir::Location) { |
| 29 | + match stmt.kind { |
| 30 | + mir::StatementKind::StorageLive(l) => trans.gen(l), |
| 31 | + mir::StatementKind::StorageDead(l) => trans.kill(l), |
| 32 | + _ => (), |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + fn terminator_effect( |
| 37 | + &self, |
| 38 | + _trans: &mut impl GenKill<Self::Idx>, |
| 39 | + _terminator: &mir::Terminator<'tcx>, |
| 40 | + _loc: mir::Location, |
| 41 | + ) { |
| 42 | + } |
| 43 | + |
| 44 | + fn call_return_effect( |
| 45 | + &self, |
| 46 | + _trans: &mut impl GenKill<Self::Idx>, |
| 47 | + _block: mir::BasicBlock, |
| 48 | + _return_places: CallReturnPlaces<'_, 'tcx>, |
| 49 | + ) { |
| 50 | + // Nothing to do when a call returns successfully |
| 51 | + } |
| 52 | +} |
0 commit comments