rust/src/analyze.rs

48 lines
1.2 KiB
Rust
Raw Normal View History

2018-08-09 03:46:56 -05:00
use crate::prelude::*;
use rustc::mir::StatementKind::*;
use rustc_index::vec::IndexVec;
2018-08-09 03:46:56 -05:00
2019-10-06 10:52:23 -05:00
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum SsaKind {
NotSsa,
Ssa,
2018-08-09 03:46:56 -05:00
}
pub fn analyze(fx: &FunctionCx<'_, '_, impl Backend>) -> IndexVec<Local, SsaKind> {
let mut flag_map = fx.mir.local_decls.iter().map(|local_decl| {
2019-10-06 10:52:23 -05:00
if fx.clif_type(local_decl.ty).is_some() {
SsaKind::Ssa
2019-10-06 10:52:23 -05:00
} else {
SsaKind::NotSsa
2018-08-09 03:46:56 -05:00
}
}).collect::<IndexVec<Local, SsaKind>>();
2018-08-09 03:46:56 -05:00
for bb in fx.mir.basic_blocks().iter() {
for stmt in bb.statements.iter() {
match &stmt.kind {
Assign(place_and_rval) => match &place_and_rval.1 {
Rvalue::Ref(_, _, place) => {
analyze_non_ssa_place(&mut flag_map, place);
}
2018-10-10 12:07:13 -05:00
_ => {}
},
2018-08-09 03:46:56 -05:00
_ => {}
}
}
}
flag_map
}
fn analyze_non_ssa_place(flag_map: &mut IndexVec<Local, SsaKind>, place: &Place) {
match place.base {
PlaceBase::Local(local) => not_ssa(flag_map, local),
2018-08-09 03:46:56 -05:00
_ => {}
}
}
fn not_ssa(flag_map: &mut IndexVec<Local, SsaKind>, local: Local) {
flag_map[local] = SsaKind::NotSsa;
2018-08-09 04:25:14 -05:00
}