2018-08-09 03:46:56 -05:00
|
|
|
use crate::prelude::*;
|
|
|
|
|
2018-11-07 06:29:38 -06:00
|
|
|
use rustc::mir::StatementKind::*;
|
2019-12-17 10:49:12 -06:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-12-17 10:49:12 -06: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() {
|
2019-12-17 10:49:12 -06:00
|
|
|
SsaKind::Ssa
|
2019-10-06 10:52:23 -05:00
|
|
|
} else {
|
2019-12-17 10:49:12 -06:00
|
|
|
SsaKind::NotSsa
|
2018-08-09 03:46:56 -05:00
|
|
|
}
|
2019-12-17 10:49:12 -06: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 {
|
2019-09-14 04:21:18 -05:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2019-12-17 10:49:12 -06:00
|
|
|
fn analyze_non_ssa_place(flag_map: &mut IndexVec<Local, SsaKind>, 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
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-17 10:49:12 -06: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
|
|
|
}
|