]> git.proxmox.com Git - rustc.git/blame_incremental - 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
1//! SSA analysis
2
3use crate::prelude::*;
4
5use rustc_index::vec::IndexVec;
6use rustc_middle::mir::StatementKind::*;
7use rustc_middle::ty::Ty;
8
9#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
10pub(crate) enum SsaKind {
11 NotSsa,
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 }
19}
20
21pub(crate) fn analyze(fx: &FunctionCx<'_, '_, '_>) -> IndexVec<Local, SsaKind> {
22 let mut flag_map =
23 fx.mir.local_decls.iter().map(|_| SsaKind::MaybeSsa).collect::<IndexVec<Local, SsaKind>>();
24
25 for bb in fx.mir.basic_blocks.iter() {
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) => {
30 flag_map[place.local] = SsaKind::NotSsa;
31 }
32 _ => {}
33 },
34 _ => {}
35 }
36 }
37 }
38
39 flag_map
40}