Add option to mir::MutVisitor
to not invalidate CFG.
This also applies that option to some uses of the visitor
This commit is contained in:
parent
9ee22ff7e8
commit
7547084ff6
8 changed files with 101 additions and 72 deletions
|
@ -33,7 +33,7 @@ pub struct DeleteNonCodegenStatements<'tcx> {
|
|||
impl<'tcx> MirPass<'tcx> for CleanupNonCodegenStatements {
|
||||
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
||||
let mut delete = DeleteNonCodegenStatements { tcx };
|
||||
delete.visit_body(body);
|
||||
delete.visit_body_preserves_cfg(body);
|
||||
body.user_type_annotations.raw.clear();
|
||||
|
||||
for decl in &mut body.local_decls {
|
||||
|
|
|
@ -951,7 +951,7 @@ impl<'tcx> MutVisitor<'tcx> for ConstPropagator<'_, 'tcx> {
|
|||
}
|
||||
|
||||
fn visit_body(&mut self, body: &mut Body<'tcx>) {
|
||||
for (bb, data) in body.basic_blocks_mut().iter_enumerated_mut() {
|
||||
for (bb, data) in body.basic_blocks.as_mut_preserves_cfg().iter_enumerated_mut() {
|
||||
self.visit_basic_block_data(bb, data);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ pub fn deref_finder<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
|||
let patch = MirPatch::new(body);
|
||||
let mut checker = DerefChecker { tcx, patcher: patch, local_decls: body.local_decls.clone() };
|
||||
|
||||
for (bb, data) in body.basic_blocks_mut().iter_enumerated_mut() {
|
||||
for (bb, data) in body.basic_blocks.as_mut_preserves_cfg().iter_enumerated_mut() {
|
||||
checker.visit_basic_block_data(bb, data);
|
||||
}
|
||||
|
||||
|
|
|
@ -116,7 +116,7 @@ impl<'tcx> MirPass<'tcx> for ElaborateBoxDerefs {
|
|||
ElaborateBoxDerefVisitor { tcx, unique_did, nonnull_did, local_decls, patch };
|
||||
|
||||
for (block, BasicBlockData { statements, terminator, .. }) in
|
||||
body.basic_blocks.as_mut().iter_enumerated_mut()
|
||||
body.basic_blocks.as_mut_preserves_cfg().iter_enumerated_mut()
|
||||
{
|
||||
let mut index = 0;
|
||||
for statement in statements {
|
||||
|
|
|
@ -53,10 +53,10 @@ impl<'tcx> MirPass<'tcx> for RenameReturnPlace {
|
|||
def_id, returned_local
|
||||
);
|
||||
|
||||
RenameToReturnPlace { tcx, to_rename: returned_local }.visit_body(body);
|
||||
RenameToReturnPlace { tcx, to_rename: returned_local }.visit_body_preserves_cfg(body);
|
||||
|
||||
// Clean up the `NOP`s we inserted for statements made useless by our renaming.
|
||||
for block_data in body.basic_blocks_mut() {
|
||||
for block_data in body.basic_blocks.as_mut_preserves_cfg() {
|
||||
block_data.statements.retain(|stmt| stmt.kind != mir::StatementKind::Nop);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ impl<'tcx> MirPass<'tcx> for RevealAll {
|
|||
}
|
||||
|
||||
let param_env = tcx.param_env_reveal_all_normalized(body.source.def_id());
|
||||
RevealAllVisitor { tcx, param_env }.visit_body(body);
|
||||
RevealAllVisitor { tcx, param_env }.visit_body_preserves_cfg(body);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -412,7 +412,7 @@ pub fn simplify_locals<'tcx>(body: &mut Body<'tcx>, tcx: TyCtxt<'tcx>) {
|
|||
if map.iter().any(Option::is_none) {
|
||||
// Update references to all vars and tmps now
|
||||
let mut updater = LocalUpdater { map, tcx };
|
||||
updater.visit_body(body);
|
||||
updater.visit_body_preserves_cfg(body);
|
||||
|
||||
body.local_decls.shrink_to_fit();
|
||||
}
|
||||
|
@ -548,7 +548,7 @@ fn remove_unused_definitions(used_locals: &mut UsedLocals, body: &mut Body<'_>)
|
|||
while modified {
|
||||
modified = false;
|
||||
|
||||
for data in body.basic_blocks_mut() {
|
||||
for data in body.basic_blocks.as_mut_preserves_cfg() {
|
||||
// Remove unnecessary StorageLive and StorageDead annotations.
|
||||
data.statements.retain(|statement| {
|
||||
let keep = match &statement.kind {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue