2020-09-23 15:13:49 +02:00
|
|
|
//! SSA analysis
|
|
|
|
|
2018-08-09 10:46:56 +02:00
|
|
|
use crate::prelude::*;
|
|
|
|
|
2019-12-17 17:49:12 +01:00
|
|
|
use rustc_index::vec::IndexVec;
|
2020-08-28 12:10:48 +02:00
|
|
|
use rustc_middle::mir::StatementKind::*;
|
2018-08-09 10:46:56 +02:00
|
|
|
|
2019-10-06 17:52:23 +02:00
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
|
2020-03-27 12:14:45 +01:00
|
|
|
pub(crate) enum SsaKind {
|
2019-10-06 17:52:23 +02:00
|
|
|
NotSsa,
|
|
|
|
Ssa,
|
2018-08-09 10:46:56 +02:00
|
|
|
}
|
|
|
|
|
2021-03-05 19:12:59 +01:00
|
|
|
pub(crate) fn analyze(fx: &FunctionCx<'_, '_, '_>) -> IndexVec<Local, SsaKind> {
|
2020-08-28 12:10:48 +02:00
|
|
|
let mut flag_map = fx
|
|
|
|
.mir
|
|
|
|
.local_decls
|
|
|
|
.iter()
|
|
|
|
.map(|local_decl| {
|
2020-10-28 08:25:06 +01:00
|
|
|
let ty = fx.monomorphize(local_decl.ty);
|
2020-08-28 12:10:48 +02:00
|
|
|
if fx.clif_type(ty).is_some() || fx.clif_pair_type(ty).is_some() {
|
|
|
|
SsaKind::Ssa
|
|
|
|
} else {
|
|
|
|
SsaKind::NotSsa
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.collect::<IndexVec<Local, SsaKind>>();
|
2018-08-09 10:46:56 +02:00
|
|
|
|
|
|
|
for bb in fx.mir.basic_blocks().iter() {
|
|
|
|
for stmt in bb.statements.iter() {
|
|
|
|
match &stmt.kind {
|
2019-09-14 11:21:18 +02:00
|
|
|
Assign(place_and_rval) => match &place_and_rval.1 {
|
2020-08-28 12:10:48 +02:00
|
|
|
Rvalue::Ref(_, _, place) | Rvalue::AddressOf(_, place) => {
|
2020-01-13 21:38:46 +01:00
|
|
|
not_ssa(&mut flag_map, place.local)
|
2019-09-14 11:21:18 +02:00
|
|
|
}
|
2018-10-10 19:07:13 +02:00
|
|
|
_ => {}
|
|
|
|
},
|
2018-08-09 10:46:56 +02:00
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
2019-12-23 15:48:43 +01:00
|
|
|
|
|
|
|
match &bb.terminator().kind {
|
2021-03-05 19:12:59 +01:00
|
|
|
TerminatorKind::Call { destination, func, args, .. } => {
|
2019-12-23 15:48:43 +01:00
|
|
|
if let Some((dest_place, _dest_bb)) = destination {
|
2021-02-01 10:11:46 +01:00
|
|
|
if !crate::abi::can_return_to_ssa_var(fx, func, args) {
|
2020-01-13 21:38:46 +01:00
|
|
|
not_ssa(&mut flag_map, dest_place.local)
|
2019-12-23 15:48:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
2018-08-09 10:46:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
flag_map
|
|
|
|
}
|
|
|
|
|
2019-12-17 17:49:12 +01:00
|
|
|
fn not_ssa(flag_map: &mut IndexVec<Local, SsaKind>, local: Local) {
|
|
|
|
flag_map[local] = SsaKind::NotSsa;
|
2018-08-09 11:25:14 +02:00
|
|
|
}
|