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