rustc_mir_transform/remove_storage_markers.rs
1//! This pass removes storage markers if they won't be emitted during codegen.
2
3use rustc_middle::mir::*;
4use rustc_middle::ty::TyCtxt;
5use tracing::trace;
6
7use crate::PassPolicy;
8
9pub(super) struct RemoveStorageMarkers;
10
11impl<'tcx> crate::MirPass<'tcx> for RemoveStorageMarkers {
12 fn policy(&self, sess: &rustc_session::Session) -> PassPolicy {
13 PassPolicy::optional_non_optimization(
14 sess.mir_opt_level() > 0 && !sess.emit_lifetime_markers(),
15 )
16 }
17
18 fn run_pass(&self, _tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
19 trace!("Running RemoveStorageMarkers on {:?}", body.source);
20 for data in body.basic_blocks.as_mut_preserves_cfg() {
21 data.retain_statements(|statement| match statement.kind {
22 StatementKind::StorageLive(..)
23 | StatementKind::StorageDead(..)
24 | StatementKind::Nop => false,
25 _ => true,
26 })
27 }
28 }
29}