1
Fork 0

Auto merge of #98872 - JakobDegen:no-invalidate, r=davidtwco

Add method to mutate MIR body without invalidating CFG caches.

In addition to adding this method, a handful of passes are updated to use it. There's still quite a few passes that could in principle make use of this as well, but do not at the moment because they use `VisitorMut` or `MirPatch`, which needs additional support for this.

The method name is slightly unwieldy, but I don't expect anyone to be writing it a lot, and at least it says what it does. If anyone has a suggestion for a better name though, would be happy to rename.

r? rust-lang/mir-opt
This commit is contained in:
bors 2022-07-05 04:04:04 +00:00
commit 880646ca9c
7 changed files with 47 additions and 15 deletions

View file

@ -66,7 +66,7 @@ pub fn eliminate<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>, borrowed: &BitS
return;
}
let bbs = body.basic_blocks_mut();
let bbs = body.basic_blocks_local_decls_mut_and_var_debug_info_no_invalidate().0;
for Location { block, statement_index } in patch {
bbs[block].statements[statement_index].make_nop();
}

View file

@ -11,7 +11,8 @@ impl<'tcx> MirPass<'tcx> for Deaggregator {
}
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
let (basic_blocks, local_decls) = body.basic_blocks_and_local_decls_mut();
let (basic_blocks, local_decls, _) =
body.basic_blocks_local_decls_mut_and_var_debug_info_no_invalidate();
let local_decls = &*local_decls;
for bb in basic_blocks {
bb.expand_statements(|stmt| {

View file

@ -26,7 +26,9 @@ pub fn lower_slice_len_calls<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
return;
};
let (basic_blocks, local_decls) = body.basic_blocks_and_local_decls_mut();
// The one successor remains unchanged, so no need to invalidate
let (basic_blocks, local_decls, _) =
body.basic_blocks_local_decls_mut_and_var_debug_info_no_invalidate();
for block in basic_blocks {
// lower `<[_]>::len` calls

View file

@ -32,7 +32,9 @@ impl<'tcx> MirPass<'tcx> for NormalizeArrayLen {
}
pub fn normalize_array_len_calls<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
let (basic_blocks, local_decls) = body.basic_blocks_and_local_decls_mut();
// We don't ever touch terminators, so no need to invalidate the CFG cache
let (basic_blocks, local_decls, _) =
body.basic_blocks_local_decls_mut_and_var_debug_info_no_invalidate();
// do a preliminary analysis to see if we ever have locals of type `[T;N]` or `&[T;N]`
let mut interesting_locals = BitSet::new_empty(local_decls.len());

View file

@ -17,7 +17,7 @@ impl<'tcx> MirPass<'tcx> for RemoveStorageMarkers {
}
trace!("Running RemoveStorageMarkers on {:?}", body.source);
for data in body.basic_blocks_mut() {
for data in body.basic_blocks_local_decls_mut_and_var_debug_info_no_invalidate().0 {
data.statements.retain(|statement| match statement.kind {
StatementKind::StorageLive(..)
| StatementKind::StorageDead(..)

View file

@ -18,7 +18,8 @@ impl<'tcx> MirPass<'tcx> for RemoveZsts {
return;
}
let param_env = tcx.param_env(body.source.def_id());
let (basic_blocks, local_decls) = body.basic_blocks_and_local_decls_mut();
let (basic_blocks, local_decls, _) =
body.basic_blocks_local_decls_mut_and_var_debug_info_no_invalidate();
for block in basic_blocks.iter_mut() {
for statement in block.statements.iter_mut() {
if let StatementKind::Assign(box (place, _)) | StatementKind::Deinit(box place) =