]> git.lizzy.rs Git - rust.git/blobdiff - src/analyze.rs
Move cached_context out of CodegenCx
[rust.git] / src / analyze.rs
index d118665b92bb30edc8867bf40788a696b15211b1..35b89358b1984ee40a2c184a38753987ffbd46f7 100644 (file)
@@ -1,29 +1,37 @@
+//! SSA analysis
+
 use crate::prelude::*;
 
-use rustc::mir::StatementKind::*;
 use rustc_index::vec::IndexVec;
+use rustc_middle::mir::StatementKind::*;
 
 #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
-pub enum SsaKind {
+pub(crate) enum SsaKind {
     NotSsa,
     Ssa,
 }
 
-pub fn analyze(fx: &FunctionCx<'_, '_, impl Backend>) -> IndexVec<Local, SsaKind> {
-    let mut flag_map = fx.mir.local_decls.iter().map(|local_decl| {
-        if fx.clif_type(local_decl.ty).is_some() {
-            SsaKind::Ssa
-        } else {
-            SsaKind::NotSsa
-        }
-    }).collect::<IndexVec<Local, SsaKind>>();
+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) => {
-                        analyze_non_ssa_place(&mut flag_map, place);
+                    Rvalue::Ref(_, _, place) | Rvalue::AddressOf(_, place) => {
+                        not_ssa(&mut flag_map, place.local)
                     }
                     _ => {}
                 },
@@ -35,13 +43,6 @@ pub fn analyze(fx: &FunctionCx<'_, '_, impl Backend>) -> IndexVec<Local, SsaKind
     flag_map
 }
 
-fn analyze_non_ssa_place(flag_map: &mut IndexVec<Local, SsaKind>, place: &Place) {
-    match place.base {
-        PlaceBase::Local(local) => not_ssa(flag_map, local),
-        _ => {}
-    }
-}
-
 fn not_ssa(flag_map: &mut IndexVec<Local, SsaKind>, local: Local) {
     flag_map[local] = SsaKind::NotSsa;
 }