rust/src/analyze.rs

40 lines
1.1 KiB
Rust
Raw Normal View History

//! SSA analysis
use rustc_index::IndexVec;
use rustc_middle::mir::StatementKind::*;
2018-08-09 03:46:56 -05:00
use crate::prelude::*;
2019-10-06 10:52:23 -05:00
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub(crate) enum SsaKind {
2019-10-06 10:52:23 -05:00
NotSsa,
MaybeSsa,
}
impl SsaKind {
pub(crate) fn is_ssa<'tcx>(self, fx: &FunctionCx<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool {
self == SsaKind::MaybeSsa && (fx.clif_type(ty).is_some() || fx.clif_pair_type(ty).is_some())
}
2018-08-09 03:46:56 -05:00
}
pub(crate) fn analyze(fx: &FunctionCx<'_, '_, '_>) -> IndexVec<Local, SsaKind> {
let mut flag_map =
fx.mir.local_decls.iter().map(|_| SsaKind::MaybeSsa).collect::<IndexVec<Local, SsaKind>>();
2018-08-09 03:46:56 -05:00
for bb in fx.mir.basic_blocks.iter() {
2018-08-09 03:46:56 -05:00
for stmt in bb.statements.iter() {
match &stmt.kind {
Assign(place_and_rval) => match &place_and_rval.1 {
Rvalue::Ref(_, _, place) | Rvalue::AddressOf(_, place) => {
flag_map[place.local] = SsaKind::NotSsa;
}
2018-10-10 12:07:13 -05:00
_ => {}
},
2018-08-09 03:46:56 -05:00
_ => {}
}
}
}
flag_map
}