summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_codegen_cranelift/src/analyze.rs
blob: 35b89358b1984ee40a2c184a38753987ffbd46f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//! SSA analysis

use crate::prelude::*;

use rustc_index::vec::IndexVec;
use rustc_middle::mir::StatementKind::*;

#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub(crate) enum SsaKind {
    NotSsa,
    Ssa,
}

pub(crate) fn analyze(fx: &FunctionCx<'_, '_, '_>) -> IndexVec<Local, SsaKind> {
    let mut flag_map = fx
        .mir
        .local_decls
        .iter()
        .map(|local_decl| {
            let ty = fx.monomorphize(local_decl.ty);
            if fx.clif_type(ty).is_some() || fx.clif_pair_type(ty).is_some() {
                SsaKind::Ssa
            } else {
                SsaKind::NotSsa
            }
        })
        .collect::<IndexVec<Local, SsaKind>>();

    for bb in fx.mir.basic_blocks().iter() {
        for stmt in bb.statements.iter() {
            match &stmt.kind {
                Assign(place_and_rval) => match &place_and_rval.1 {
                    Rvalue::Ref(_, _, place) | Rvalue::AddressOf(_, place) => {
                        not_ssa(&mut flag_map, place.local)
                    }
                    _ => {}
                },
                _ => {}
            }
        }
    }

    flag_map
}

fn not_ssa(flag_map: &mut IndexVec<Local, SsaKind>, local: Local) {
    flag_map[local] = SsaKind::NotSsa;
}