diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2023-04-12 18:39:56 +0000 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2023-09-24 09:09:04 +0000 |
| commit | 5f9d64d72f043ccf5bfe99a1fbd570b0256ab4db (patch) | |
| tree | 7aac84d7fd56cb6822badfd1710bf922b6ae9f9e /compiler/rustc_mir_transform/src/ssa.rs | |
| parent | 33115367404c7e860853054c53e7ad613258516b (diff) | |
| download | rust-5f9d64d72f043ccf5bfe99a1fbd570b0256ab4db.tar.gz rust-5f9d64d72f043ccf5bfe99a1fbd570b0256ab4db.zip | |
Embed simplification into VnState.
Diffstat (limited to 'compiler/rustc_mir_transform/src/ssa.rs')
| -rw-r--r-- | compiler/rustc_mir_transform/src/ssa.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/compiler/rustc_mir_transform/src/ssa.rs b/compiler/rustc_mir_transform/src/ssa.rs index d16ef712a38..3a675752fba 100644 --- a/compiler/rustc_mir_transform/src/ssa.rs +++ b/compiler/rustc_mir_transform/src/ssa.rs @@ -164,6 +164,24 @@ impl SsaLocals { }) } + pub fn for_each_assignment_mut<'tcx>( + &self, + basic_blocks: &mut BasicBlocks<'tcx>, + mut f: impl FnMut(Local, &mut Rvalue<'tcx>, Location), + ) { + for &local in &self.assignment_order { + if let Set1::One(LocationExtended::Plain(loc)) = self.assignments[local] { + // `loc` must point to a direct assignment to `local`. + let bbs = basic_blocks.as_mut_preserves_cfg(); + let bb = &mut bbs[loc.block]; + let stmt = &mut bb.statements[loc.statement_index]; + let StatementKind::Assign(box (target, ref mut rvalue)) = stmt.kind else { bug!() }; + assert_eq!(target.as_local(), Some(local)); + f(local, rvalue, loc) + } + } + } + /// Compute the equivalence classes for locals, based on copy statements. /// /// The returned vector maps each local to the one it copies. In the following case: |
