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| {
|
2020-02-07 13:27:37 -06:00
|
|
|
if fx.clif_type(fx.monomorphize(&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) => {
|
2020-01-13 14:38:46 -06:00
|
|
|
not_ssa(&mut flag_map, place.local)
|
2019-09-14 04:21:18 -05:00
|
|
|
}
|
2018-10-10 12:07:13 -05:00
|
|
|
_ => {}
|
|
|
|
},
|
2018-08-09 03:46:56 -05:00
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
2019-12-23 08:48:43 -06: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) {
|
2020-01-13 14:38:46 -06:00
|
|
|
not_ssa(&mut flag_map, dest_place.local)
|
2019-12-23 08:48:43 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
2018-08-09 03:46:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
flag_map
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|