2020-09-23 08:13:49 -05:00
|
|
|
//! SSA analysis
|
|
|
|
|
2018-08-09 03:46:56 -05:00
|
|
|
use crate::prelude::*;
|
|
|
|
|
2019-12-17 10:49:12 -06:00
|
|
|
use rustc_index::vec::IndexVec;
|
2020-08-28 05:10:48 -05:00
|
|
|
use rustc_middle::mir::StatementKind::*;
|
2018-08-09 03:46:56 -05:00
|
|
|
|
2019-10-06 10:52:23 -05:00
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
|
2020-03-27 06:14:45 -05:00
|
|
|
pub(crate) enum SsaKind {
|
2019-10-06 10:52:23 -05:00
|
|
|
NotSsa,
|
|
|
|
Ssa,
|
2018-08-09 03:46:56 -05:00
|
|
|
}
|
|
|
|
|
2021-02-22 09:00:20 -06:00
|
|
|
pub(crate) fn analyze(fx: &FunctionCx<'_, '_, '_>) -> IndexVec<Local, SsaKind> {
|
2020-08-28 05:10:48 -05:00
|
|
|
let mut flag_map = fx
|
|
|
|
.mir
|
|
|
|
.local_decls
|
|
|
|
.iter()
|
|
|
|
.map(|local_decl| {
|
2020-10-28 02:25:06 -05:00
|
|
|
let ty = fx.monomorphize(local_decl.ty);
|
2020-08-28 05:10:48 -05: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 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 {
|
2020-08-28 05:10:48 -05:00
|
|
|
Rvalue::Ref(_, _, place) | Rvalue::AddressOf(_, 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
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|