Visit only terminators when removing landing pads

No functional changes intended
This commit is contained in:
Tomasz Miąsko 2021-01-18 00:00:00 +00:00
parent 73f233b3ad
commit 96e9562a7e
3 changed files with 9 additions and 24 deletions

View file

@ -81,7 +81,7 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> Body<'
MirPhase::Const, MirPhase::Const,
&[&[ &[&[
&add_moves_for_packed_drops::AddMovesForPackedDrops, &add_moves_for_packed_drops::AddMovesForPackedDrops,
&no_landing_pads::NoLandingPads::new(tcx), &no_landing_pads::NoLandingPads,
&remove_noop_landing_pads::RemoveNoopLandingPads, &remove_noop_landing_pads::RemoveNoopLandingPads,
&simplify::SimplifyCfg::new("make_shim"), &simplify::SimplifyCfg::new("make_shim"),
&add_call_guards::CriticalCallEdges, &add_call_guards::CriticalCallEdges,

View file

@ -433,7 +433,7 @@ fn run_post_borrowck_cleanup_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tc
let post_borrowck_cleanup: &[&dyn MirPass<'tcx>] = &[ let post_borrowck_cleanup: &[&dyn MirPass<'tcx>] = &[
// Remove all things only needed by analysis // Remove all things only needed by analysis
&no_landing_pads::NoLandingPads::new(tcx), &no_landing_pads::NoLandingPads,
&simplify_branches::SimplifyBranches::new("initial"), &simplify_branches::SimplifyBranches::new("initial"),
&remove_noop_landing_pads::RemoveNoopLandingPads, &remove_noop_landing_pads::RemoveNoopLandingPads,
&cleanup_post_borrowck::CleanupNonCodegenStatements, &cleanup_post_borrowck::CleanupNonCodegenStatements,
@ -441,7 +441,7 @@ fn run_post_borrowck_cleanup_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tc
// These next passes must be executed together // These next passes must be executed together
&add_call_guards::CriticalCallEdges, &add_call_guards::CriticalCallEdges,
&elaborate_drops::ElaborateDrops, &elaborate_drops::ElaborateDrops,
&no_landing_pads::NoLandingPads::new(tcx), &no_landing_pads::NoLandingPads,
// AddMovesForPackedDrops needs to run after drop // AddMovesForPackedDrops needs to run after drop
// elaboration. // elaboration.
&add_moves_for_packed_drops::AddMovesForPackedDrops, &add_moves_for_packed_drops::AddMovesForPackedDrops,

View file

@ -2,42 +2,27 @@
//! specified. //! specified.
use crate::transform::MirPass; use crate::transform::MirPass;
use rustc_middle::mir::visit::MutVisitor;
use rustc_middle::mir::*; use rustc_middle::mir::*;
use rustc_middle::ty::TyCtxt; use rustc_middle::ty::TyCtxt;
use rustc_target::spec::PanicStrategy; use rustc_target::spec::PanicStrategy;
pub struct NoLandingPads<'tcx> { pub struct NoLandingPads;
tcx: TyCtxt<'tcx>,
}
impl<'tcx> NoLandingPads<'tcx> { impl<'tcx> MirPass<'tcx> for NoLandingPads {
pub fn new(tcx: TyCtxt<'tcx>) -> Self {
NoLandingPads { tcx }
}
}
impl<'tcx> MirPass<'tcx> for NoLandingPads<'tcx> {
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
no_landing_pads(tcx, body) no_landing_pads(tcx, body)
} }
} }
pub fn no_landing_pads<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { pub fn no_landing_pads<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
if tcx.sess.panic_strategy() == PanicStrategy::Abort { if tcx.sess.panic_strategy() != PanicStrategy::Abort {
NoLandingPads::new(tcx).visit_body(body); return;
}
}
impl<'tcx> MutVisitor<'tcx> for NoLandingPads<'tcx> {
fn tcx(&self) -> TyCtxt<'tcx> {
self.tcx
} }
fn visit_terminator(&mut self, terminator: &mut Terminator<'tcx>, location: Location) { for block in body.basic_blocks_mut() {
let terminator = block.terminator_mut();
if let Some(unwind) = terminator.kind.unwind_mut() { if let Some(unwind) = terminator.kind.unwind_mut() {
unwind.take(); unwind.take();
} }
self.super_terminator(terminator, location);
} }
} }