2020-09-23 15:13:49 +02:00
|
|
|
//! SSA analysis
|
|
|
|
|
2018-08-09 10:46:56 +02:00
|
|
|
use crate::prelude::*;
|
|
|
|
|
2023-04-19 10:57:17 +00:00
|
|
|
use rustc_index::IndexVec;
|
2020-08-28 12:10:48 +02:00
|
|
|
use rustc_middle::mir::StatementKind::*;
|
2023-03-15 14:41:48 +00:00
|
|
|
use rustc_middle::ty::Ty;
|
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,
|
2023-03-15 14:41:48 +00:00
|
|
|
MaybeSsa,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl SsaKind {
|
|
|
|
pub(crate) fn is_ssa<'tcx>(self, fx: &FunctionCx<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool {
|
|
|
|
self == SsaKind::MaybeSsa && (fx.clif_type(ty).is_some() || fx.clif_pair_type(ty).is_some())
|
|
|
|
}
|
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> {
|
2023-03-15 14:41:48 +00:00
|
|
|
let mut flag_map =
|
|
|
|
fx.mir.local_decls.iter().map(|_| SsaKind::MaybeSsa).collect::<IndexVec<Local, SsaKind>>();
|
2018-08-09 10:46:56 +02:00
|
|
|
|
2022-07-05 00:00:00 +00:00
|
|
|
for bb in fx.mir.basic_blocks.iter() {
|
2018-08-09 10:46:56 +02:00
|
|
|
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) => {
|
2023-03-15 14:41:48 +00:00
|
|
|
flag_map[place.local] = SsaKind::NotSsa;
|
2019-09-14 11:21:18 +02:00
|
|
|
}
|
2018-10-10 19:07:13 +02:00
|
|
|
_ => {}
|
|
|
|
},
|
2018-08-09 10:46:56 +02:00
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
flag_map
|
|
|
|
}
|