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