rust/src/analyze.rs

53 lines
1.6 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| {
if fx.clif_type(fx.monomorphize(&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) => {
not_ssa(&mut flag_map, place.local)
}
2018-10-10 12:07:13 -05:00
_ => {}
},
2018-08-09 03:46:56 -05:00
_ => {}
}
}
match &bb.terminator().kind {
TerminatorKind::Call { destination, .. } => {
if let Some((dest_place, _dest_bb)) = destination {
let dest_layout = fx.layout_of(fx.monomorphize(&dest_place.ty(&fx.mir.local_decls, fx.tcx).ty));
if !crate::abi::can_return_to_ssa_var(fx.tcx, dest_layout) {
not_ssa(&mut flag_map, dest_place.local)
}
}
}
_ => {}
}
2018-08-09 03:46:56 -05:00
}
flag_map
}
fn not_ssa(flag_map: &mut IndexVec<Local, SsaKind>, local: Local) {
flag_map[local] = SsaKind::NotSsa;
2018-08-09 04:25:14 -05:00
}