diff options
| author | bors <bors@rust-lang.org> | 2022-07-29 07:11:50 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-07-29 07:11:50 +0000 |
| commit | 7dfdd64433b07239fbac50b8227b6e03a0ba8f30 (patch) | |
| tree | e8e6a57c31f957d3df90aac8cc738c772e75b791 /compiler/rustc_mir_dataflow/src | |
| parent | ea6ab1bd845790fb31ba790d2c7aec898f89fe62 (diff) | |
| parent | bd24b4006c98425aa994763acf7f7e18607c7df1 (diff) | |
| download | rust-7dfdd64433b07239fbac50b8227b6e03a0ba8f30.tar.gz rust-7dfdd64433b07239fbac50b8227b6e03a0ba8f30.zip | |
Auto merge of #99667 - ouz-a:some_branch, r=oli-obk
Optimize `UnDerefer` Addresses the performance [issues](https://github.com/rust-lang/rust/pull/98145#issuecomment-1183548597) faced here. r? `@oli-obk`
Diffstat (limited to 'compiler/rustc_mir_dataflow/src')
| -rw-r--r-- | compiler/rustc_mir_dataflow/src/move_paths/builder.rs | 18 | ||||
| -rw-r--r-- | compiler/rustc_mir_dataflow/src/move_paths/mod.rs | 3 | ||||
| -rw-r--r-- | compiler/rustc_mir_dataflow/src/rustc_peek.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_mir_dataflow/src/un_derefer.rs | 16 |
4 files changed, 17 insertions, 22 deletions
diff --git a/compiler/rustc_mir_dataflow/src/move_paths/builder.rs b/compiler/rustc_mir_dataflow/src/move_paths/builder.rs index 19aa71d7bc7..116e5c1f3ce 100644 --- a/compiler/rustc_mir_dataflow/src/move_paths/builder.rs +++ b/compiler/rustc_mir_dataflow/src/move_paths/builder.rs @@ -1,3 +1,4 @@ +use crate::move_paths::FxHashMap; use crate::un_derefer::UnDerefer; use rustc_index::vec::IndexVec; use rustc_middle::mir::tcx::RvalueInitializationState; @@ -206,10 +207,13 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> { } } +pub type MoveDat<'tcx> = Result< + (FxHashMap<Local, Place<'tcx>>, MoveData<'tcx>), + (MoveData<'tcx>, Vec<(Place<'tcx>, MoveError<'tcx>)>), +>; + impl<'a, 'tcx> MoveDataBuilder<'a, 'tcx> { - fn finalize( - self, - ) -> Result<MoveData<'tcx>, (MoveData<'tcx>, Vec<(Place<'tcx>, MoveError<'tcx>)>)> { + fn finalize(self) -> MoveDat<'tcx> { debug!("{}", { debug!("moves for {:?}:", self.body.span); for (j, mo) in self.data.moves.iter_enumerated() { @@ -222,7 +226,11 @@ impl<'a, 'tcx> MoveDataBuilder<'a, 'tcx> { "done dumping moves" }); - if !self.errors.is_empty() { Err((self.data, self.errors)) } else { Ok(self.data) } + if self.errors.is_empty() { + Ok((self.un_derefer.derefer_sidetable, self.data)) + } else { + Err((self.data, self.errors)) + } } } @@ -230,7 +238,7 @@ pub(super) fn gather_moves<'tcx>( body: &Body<'tcx>, tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>, -) -> Result<MoveData<'tcx>, (MoveData<'tcx>, Vec<(Place<'tcx>, MoveError<'tcx>)>)> { +) -> MoveDat<'tcx> { let mut builder = MoveDataBuilder::new(body, tcx, param_env); builder.gather_args(); diff --git a/compiler/rustc_mir_dataflow/src/move_paths/mod.rs b/compiler/rustc_mir_dataflow/src/move_paths/mod.rs index 1af789b4885..a951c5b0b1c 100644 --- a/compiler/rustc_mir_dataflow/src/move_paths/mod.rs +++ b/compiler/rustc_mir_dataflow/src/move_paths/mod.rs @@ -1,3 +1,4 @@ +use crate::move_paths::builder::MoveDat; use rustc_data_structures::fx::FxHashMap; use rustc_index::vec::IndexVec; use rustc_middle::mir::*; @@ -386,7 +387,7 @@ impl<'tcx> MoveData<'tcx> { body: &Body<'tcx>, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, - ) -> Result<Self, (Self, Vec<(Place<'tcx>, MoveError<'tcx>)>)> { + ) -> MoveDat<'tcx> { builder::gather_moves(body, tcx, param_env) } diff --git a/compiler/rustc_mir_dataflow/src/rustc_peek.rs b/compiler/rustc_mir_dataflow/src/rustc_peek.rs index e1df482786f..f2471f37a52 100644 --- a/compiler/rustc_mir_dataflow/src/rustc_peek.rs +++ b/compiler/rustc_mir_dataflow/src/rustc_peek.rs @@ -30,7 +30,7 @@ impl<'tcx> MirPass<'tcx> for SanityCheck { } let param_env = tcx.param_env(def_id); - let move_data = MoveData::gather_moves(body, tcx, param_env).unwrap(); + let (_, move_data) = MoveData::gather_moves(body, tcx, param_env).unwrap(); let mdpe = MoveDataParamEnv { move_data, param_env }; if has_rustc_mir_with(tcx, def_id, sym::rustc_peek_maybe_init).is_some() { diff --git a/compiler/rustc_mir_dataflow/src/un_derefer.rs b/compiler/rustc_mir_dataflow/src/un_derefer.rs index 2ab7eddcac9..7e6e25cc603 100644 --- a/compiler/rustc_mir_dataflow/src/un_derefer.rs +++ b/compiler/rustc_mir_dataflow/src/un_derefer.rs @@ -9,6 +9,7 @@ pub struct UnDerefer<'tcx> { } impl<'tcx> UnDerefer<'tcx> { + #[inline] pub fn derefer(&self, place: PlaceRef<'tcx>, body: &Body<'tcx>) -> Option<Place<'tcx>> { let reffed = self.derefer_sidetable.get(&place.local)?; @@ -18,19 +19,4 @@ impl<'tcx> UnDerefer<'tcx> { } Some(new_place) } - - pub fn ref_finder(&mut self, body: &Body<'tcx>) { - for (_bb, data) in body.basic_blocks().iter_enumerated() { - for stmt in data.statements.iter() { - match stmt.kind { - StatementKind::Assign(box (place, Rvalue::CopyForDeref(reffed))) => { - if body.local_decls[place.local].is_deref_temp() { - self.derefer_sidetable.insert(place.local, reffed); - } - } - _ => (), - } - } - } - } } |
