2020-09-23 08:13:49 -05:00
|
|
|
//! SSA analysis
|
|
|
|
|
2023-04-19 05:57:17 -05:00
|
|
|
use rustc_index::IndexVec;
|
2020-08-28 05:10:48 -05:00
|
|
|
use rustc_middle::mir::StatementKind::*;
|
2018-08-09 03:46:56 -05:00
|
|
|
|
2023-10-09 03:52:46 -05:00
|
|
|
use crate::prelude::*;
|
|
|
|
|
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,
|
2023-03-15 09:41:48 -05: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 03:46:56 -05:00
|
|
|
}
|
|
|
|
|
2021-03-05 12:12:59 -06:00
|
|
|
pub(crate) fn analyze(fx: &FunctionCx<'_, '_, '_>) -> IndexVec<Local, SsaKind> {
|
2023-03-15 09:41:48 -05:00
|
|
|
let mut flag_map =
|
|
|
|
fx.mir.local_decls.iter().map(|_| SsaKind::MaybeSsa).collect::<IndexVec<Local, SsaKind>>();
|
2018-08-09 03:46:56 -05:00
|
|
|
|
2022-07-04 19:00:00 -05:00
|
|
|
for bb in fx.mir.basic_blocks.iter() {
|
2018-08-09 03:46:56 -05:00
|
|
|
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) => {
|
2023-03-15 09:41:48 -05:00
|
|
|
flag_map[place.local] = SsaKind::NotSsa;
|
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
|
|
|
|
}
|