]> git.lizzy.rs Git - rust.git/blob - src/analyze.rs
FunctionCx: WIP: Fix syntax error on sed codegen_cx -> .codegen_cx
[rust.git] / src / analyze.rs
1 use crate::prelude::*;
2
3 use rustc_middle::mir::StatementKind::*;
4 use rustc_index::vec::IndexVec;
5
6 #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
7 pub(crate) enum SsaKind {
8     NotSsa,
9     Ssa,
10 }
11
12 pub(crate) fn analyze(fx: &FunctionCx<'_, '_, impl Backend>) -> IndexVec<Local, SsaKind> {
13     let mut flag_map = fx.mir.local_decls.iter().map(|local_decl| {
14         let ty = fx.monomorphize(&local_decl.ty);
15         if fx.clif_type(ty).is_some() || fx.clif_pair_type(ty).is_some() {
16             SsaKind::Ssa
17         } else {
18             SsaKind::NotSsa
19         }
20     }).collect::<IndexVec<Local, SsaKind>>();
21
22     for bb in fx.mir.basic_blocks().iter() {
23         for stmt in bb.statements.iter() {
24             match &stmt.kind {
25                 Assign(place_and_rval) => match &place_and_rval.1 {
26                     Rvalue::Ref(_, _, place) | Rvalue::AddressOf(_, place)=> {
27                         not_ssa(&mut flag_map, place.local)
28                     }
29                     _ => {}
30                 },
31                 _ => {}
32             }
33         }
34
35         match &bb.terminator().kind {
36             TerminatorKind::Call { destination, .. } => {
37                 if let Some((dest_place, _dest_bb)) = destination {
38                     let dest_layout = fx.layout_of(fx.monomorphize(&dest_place.ty(&fx.mir.local_decls, fx.codegen_cx.tcx).ty));
39                     if !crate::abi::can_return_to_ssa_var(fx.codegen_cx.tcx, dest_layout) {
40                         not_ssa(&mut flag_map, dest_place.local)
41                     }
42                 }
43             }
44             _ => {}
45         }
46     }
47
48     flag_map
49 }
50
51 fn not_ssa(flag_map: &mut IndexVec<Local, SsaKind>, local: Local) {
52     flag_map[local] = SsaKind::NotSsa;
53 }