]> git.proxmox.com Git - rustc.git/blame - compiler/rustc_codegen_cranelift/src/analyze.rs
Update upstream source from tag 'upstream/1.70.0+dfsg1'
[rustc.git] / compiler / rustc_codegen_cranelift / src / analyze.rs
CommitLineData
29967ef6
XL
1//! SSA analysis
2
3use crate::prelude::*;
4
5use rustc_index::vec::IndexVec;
6use rustc_middle::mir::StatementKind::*;
353b0b11 7use rustc_middle::ty::Ty;
29967ef6
XL
8
9#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
10pub(crate) enum SsaKind {
11 NotSsa,
353b0b11
FG
12 MaybeSsa,
13}
14
15impl SsaKind {
16 pub(crate) fn is_ssa<'tcx>(self, fx: &FunctionCx<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool {
17 self == SsaKind::MaybeSsa && (fx.clif_type(ty).is_some() || fx.clif_pair_type(ty).is_some())
18 }
29967ef6
XL
19}
20
6a06907d 21pub(crate) fn analyze(fx: &FunctionCx<'_, '_, '_>) -> IndexVec<Local, SsaKind> {
353b0b11
FG
22 let mut flag_map =
23 fx.mir.local_decls.iter().map(|_| SsaKind::MaybeSsa).collect::<IndexVec<Local, SsaKind>>();
29967ef6 24
f2b60f7d 25 for bb in fx.mir.basic_blocks.iter() {
29967ef6
XL
26 for stmt in bb.statements.iter() {
27 match &stmt.kind {
28 Assign(place_and_rval) => match &place_and_rval.1 {
29 Rvalue::Ref(_, _, place) | Rvalue::AddressOf(_, place) => {
353b0b11 30 flag_map[place.local] = SsaKind::NotSsa;
29967ef6
XL
31 }
32 _ => {}
33 },
34 _ => {}
35 }
36 }
29967ef6
XL
37 }
38
39 flag_map
40}