about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbjorn3 <bjorn3@users.noreply.github.com>2020-09-16 18:45:19 +0200
committerbjorn3 <bjorn3@users.noreply.github.com>2020-09-16 18:45:19 +0200
commit552991e17e34ec971631e8dffdfb4a84c8d69eda (patch)
treeae4b3fefb40a0cb1e73572e372ff71472a8101c9 /src
parenta18a1948e04dcd619e5112724d37eb81b35a6687 (diff)
downloadrust-552991e17e34ec971631e8dffdfb4a84c8d69eda.tar.gz
rust-552991e17e34ec971631e8dffdfb4a84c8d69eda.zip
Replace FxHashMap with IndexVec for local_map
Fixes #745
Diffstat (limited to 'src')
-rw-r--r--src/abi/mod.rs18
-rw-r--r--src/abi/returning.rs32
-rw-r--r--src/base.rs2
-rw-r--r--src/common.rs4
-rw-r--r--src/debuginfo/mod.rs8
5 files changed, 31 insertions, 33 deletions
diff --git a/src/abi/mod.rs b/src/abi/mod.rs
index d0215ba94dd..7065eefe170 100644
--- a/src/abi/mod.rs
+++ b/src/abi/mod.rs
@@ -325,7 +325,7 @@ impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> {
     }
 }
 
-fn local_place<'tcx>(
+fn make_local_place<'tcx>(
     fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
     local: Local,
     layout: TyAndLayout<'tcx>,
@@ -344,9 +344,7 @@ fn local_place<'tcx>(
     #[cfg(debug_assertions)]
     self::comments::add_local_place_comments(fx, place, local);
 
-    let prev_place = fx.local_map.insert(local, place);
-    debug_assert!(prev_place.is_none());
-    fx.local_map[&local]
+    place
 }
 
 pub(crate) fn codegen_fn_prelude<'tcx>(
@@ -358,7 +356,8 @@ pub(crate) fn codegen_fn_prelude<'tcx>(
     #[cfg(debug_assertions)]
     self::comments::add_args_header_comment(fx);
 
-    self::returning::codegen_return_param(fx, &ssa_analyzed, start_block);
+    let ret_place = self::returning::codegen_return_param(fx, &ssa_analyzed, start_block);
+    assert_eq!(fx.local_map.push(ret_place), RETURN_PLACE);
 
     // None means pass_mode == NoPass
     enum ArgKind<'tcx> {
@@ -441,8 +440,7 @@ pub(crate) fn codegen_fn_prelude<'tcx>(
                         #[cfg(debug_assertions)]
                         self::comments::add_local_place_comments(fx, place, local);
 
-                        let prev_place = fx.local_map.insert(local, place);
-                        debug_assert!(prev_place.is_none());
+                        assert_eq!(fx.local_map.push(place), local);
                         continue;
                     }
                 }
@@ -450,7 +448,8 @@ pub(crate) fn codegen_fn_prelude<'tcx>(
             _ => {}
         }
 
-        let place = local_place(fx, local, layout, is_ssa);
+        let place = make_local_place(fx, local, layout, is_ssa);
+        assert_eq!(fx.local_map.push(place), local);
 
         match arg_kind {
             ArgKind::Normal(param) => {
@@ -476,7 +475,8 @@ pub(crate) fn codegen_fn_prelude<'tcx>(
 
         let is_ssa = ssa_analyzed[local] == crate::analyze::SsaKind::Ssa;
 
-        local_place(fx, local, layout, is_ssa);
+        let place = make_local_place(fx, local, layout, is_ssa);
+        assert_eq!(fx.local_map.push(place), local);
     }
 
     fx.bcx
diff --git a/src/abi/returning.rs b/src/abi/returning.rs
index dfb16b5fe4c..690f5cd5cba 100644
--- a/src/abi/returning.rs
+++ b/src/abi/returning.rs
@@ -16,34 +16,28 @@ pub(crate) fn can_return_to_ssa_var<'tcx>(
     }
 }
 
-pub(super) fn codegen_return_param(
-    fx: &mut FunctionCx<'_, '_, impl Backend>,
+pub(super) fn codegen_return_param<'tcx>(
+    fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
     ssa_analyzed: &rustc_index::vec::IndexVec<Local, crate::analyze::SsaKind>,
     start_block: Block,
-) {
+) -> CPlace<'tcx> {
     let ret_layout = return_layout(fx);
     let ret_pass_mode = get_pass_mode(fx.tcx, ret_layout);
-    let ret_param = match ret_pass_mode {
-        PassMode::NoPass => {
-            fx.local_map
-                .insert(RETURN_PLACE, CPlace::no_place(ret_layout));
-            Empty
-        }
+    let (ret_place, ret_param) = match ret_pass_mode {
+        PassMode::NoPass => (CPlace::no_place(ret_layout), Empty),
         PassMode::ByVal(_) | PassMode::ByValPair(_, _) => {
             let is_ssa = ssa_analyzed[RETURN_PLACE] == crate::analyze::SsaKind::Ssa;
-
-            super::local_place(fx, RETURN_PLACE, ret_layout, is_ssa);
-
-            Empty
+            (
+                super::make_local_place(fx, RETURN_PLACE, ret_layout, is_ssa),
+                Empty,
+            )
         }
         PassMode::ByRef { size: Some(_) } => {
             let ret_param = fx.bcx.append_block_param(start_block, fx.pointer_type);
-            fx.local_map.insert(
-                RETURN_PLACE,
+            (
                 CPlace::for_ptr(Pointer::new(ret_param), ret_layout),
-            );
-
-            Single(ret_param)
+                Single(ret_param),
+            )
         }
         PassMode::ByRef { size: None } => todo!(),
     };
@@ -61,6 +55,8 @@ pub(super) fn codegen_return_param(
         ret_pass_mode,
         ret_layout.ty,
     );
+
+    ret_place
 }
 
 pub(super) fn codegen_with_call_return_arg<'tcx, B: Backend, T>(
diff --git a/src/base.rs b/src/base.rs
index b01fb8fe649..0d86a6010be 100644
--- a/src/base.rs
+++ b/src/base.rs
@@ -47,7 +47,7 @@ pub(crate) fn trans_fn<'tcx, B: Backend + 'static>(
 
         bcx,
         block_map,
-        local_map: FxHashMap::with_capacity_and_hasher(mir.local_decls.len(), Default::default()),
+        local_map: IndexVec::with_capacity(mir.local_decls.len()),
         caller_location: None, // set by `codegen_fn_prelude`
         cold_blocks: EntitySet::new(),
 
diff --git a/src/common.rs b/src/common.rs
index d4b5d660ba8..9ac82eaeb3d 100644
--- a/src/common.rs
+++ b/src/common.rs
@@ -297,7 +297,7 @@ pub(crate) struct FunctionCx<'clif, 'tcx, B: Backend + 'static> {
 
     pub(crate) bcx: FunctionBuilder<'clif>,
     pub(crate) block_map: IndexVec<BasicBlock, Block>,
-    pub(crate) local_map: FxHashMap<Local, CPlace<'tcx>>,
+    pub(crate) local_map: IndexVec<Local, CPlace<'tcx>>,
 
     /// When `#[track_caller]` is used, the implicit caller location is stored in this variable.
     pub(crate) caller_location: Option<CValue<'tcx>>,
@@ -383,7 +383,7 @@ impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> {
     }
 
     pub(crate) fn get_local_place(&mut self, local: Local) -> CPlace<'tcx> {
-        *self.local_map.get(&local).unwrap_or_else(|| {
+        *self.local_map.get(local).unwrap_or_else(|| {
             panic!("Local {:?} doesn't exist", local);
         })
     }
diff --git a/src/debuginfo/mod.rs b/src/debuginfo/mod.rs
index 70e0cf1a9e4..8f7d21dfb4f 100644
--- a/src/debuginfo/mod.rs
+++ b/src/debuginfo/mod.rs
@@ -4,6 +4,8 @@ mod unwind;
 
 use crate::prelude::*;
 
+use rustc_index::vec::IndexVec;
+
 use cranelift_codegen::entity::EntityRef;
 use cranelift_codegen::ir::{StackSlots, ValueLabel, ValueLoc};
 use cranelift_codegen::isa::TargetIsa;
@@ -269,7 +271,7 @@ impl<'tcx> DebugContext<'tcx> {
         isa: &dyn TargetIsa,
         context: &Context,
         source_info_set: &indexmap::IndexSet<SourceInfo>,
-        local_map: FxHashMap<mir::Local, CPlace<'tcx>>,
+        local_map: IndexVec<mir::Local, CPlace<'tcx>>,
     ) {
         let symbol = func_id.as_u32() as usize;
         let mir = self.tcx.instance_mir(instance.def);
@@ -390,7 +392,7 @@ fn place_location<'tcx>(
     isa: &dyn TargetIsa,
     symbol: usize,
     context: &Context,
-    local_map: &FxHashMap<mir::Local, CPlace<'tcx>>,
+    local_map: &IndexVec<mir::Local, CPlace<'tcx>>,
     #[allow(rustc::default_hash_types)] value_labels_ranges: &std::collections::HashMap<
         ValueLabel,
         Vec<ValueLocRange>,
@@ -399,7 +401,7 @@ fn place_location<'tcx>(
 ) -> AttributeValue {
     assert!(place.projection.is_empty()); // FIXME implement them
 
-    match local_map[&place.local].inner() {
+    match local_map[place.local].inner() {
         CPlaceInner::Var(_local, var) => {
             let value_label = cranelift_codegen::ir::ValueLabel::new(var.index());
             if let Some(value_loc_ranges) = value_labels_ranges.get(&value_label) {