2018-08-09 03:46:56 -05:00
|
|
|
use crate::prelude::*;
|
|
|
|
|
2018-11-07 06:29:38 -06:00
|
|
|
use rustc::mir::StatementKind::*;
|
2018-08-09 03:46:56 -05:00
|
|
|
|
2018-11-17 11:23:52 -06:00
|
|
|
bitflags::bitflags! {
|
2018-08-09 03:46:56 -05:00
|
|
|
pub struct Flags: u8 {
|
|
|
|
const NOT_SSA = 0b00000001;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-18 09:52:07 -05:00
|
|
|
pub fn analyze(fx: &FunctionCx<'_, '_, impl Backend>) -> HashMap<Local, Flags> {
|
2018-08-09 03:46:56 -05:00
|
|
|
let mut flag_map = HashMap::new();
|
|
|
|
|
|
|
|
for local in fx.mir.local_decls.indices() {
|
|
|
|
flag_map.insert(local, Flags::empty());
|
|
|
|
}
|
|
|
|
|
|
|
|
for (local, local_decl) in fx.mir.local_decls.iter_enumerated() {
|
2018-11-12 09:23:39 -06:00
|
|
|
if fx.clif_type(local_decl.ty).is_none() {
|
2018-08-09 03:46:56 -05:00
|
|
|
not_ssa(&mut flag_map, local);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for bb in fx.mir.basic_blocks().iter() {
|
|
|
|
for stmt in bb.statements.iter() {
|
|
|
|
match &stmt.kind {
|
2018-10-10 12:07:13 -05:00
|
|
|
Assign(_, rval) => match &**rval {
|
|
|
|
Rvalue::Ref(_, _, place) => analyze_non_ssa_place(&mut flag_map, place),
|
|
|
|
_ => {}
|
|
|
|
},
|
2018-08-09 03:46:56 -05:00
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
match &bb.terminator().kind {
|
2018-08-09 04:25:14 -05:00
|
|
|
TerminatorKind::Call {
|
|
|
|
destination: Some((place, _)),
|
|
|
|
..
|
|
|
|
} => analyze_non_ssa_place(&mut flag_map, place),
|
2018-08-09 03:46:56 -05:00
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
flag_map
|
|
|
|
}
|
|
|
|
|
|
|
|
fn analyze_non_ssa_place(flag_map: &mut HashMap<Local, Flags>, place: &Place) {
|
2019-07-24 04:56:24 -05:00
|
|
|
match place.base {
|
|
|
|
PlaceBase::Local(local) => not_ssa(flag_map, local),
|
2018-08-09 03:46:56 -05:00
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn not_ssa<L: ::std::borrow::Borrow<Local>>(flag_map: &mut HashMap<Local, Flags>, local: L) {
|
|
|
|
*flag_map.get_mut(local.borrow()).unwrap() |= Flags::NOT_SSA;
|
2018-08-09 04:25:14 -05:00
|
|
|
}
|