1
Fork 0

Inline and simplify init_cpad

This commit is contained in:
Mark Simulacrum 2016-12-18 17:04:00 -07:00
parent 4c7041ea7d
commit 2bda3b7acb
2 changed files with 20 additions and 35 deletions

View file

@ -863,32 +863,6 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
bcx.llbb()
}
pub fn init_cpad(&mut self, bb: mir::BasicBlock,
funclets: &mut IndexVec<mir::BasicBlock, Option<Funclet>>) {
let bcx = self.build_block(bb);
let data = &self.mir[bb];
debug!("init_cpad({:?})", data);
match self.cleanup_kinds[bb] {
CleanupKind::NotCleanup => {
funclets[bb] = None;
}
_ if !base::wants_msvc_seh(bcx.sess()) => {
funclets[bb] = Funclet::gnu();
}
CleanupKind::Internal { funclet: _ } => {
// FIXME: is this needed?
bcx.set_personality_fn(self.fcx.eh_personality());
funclets[bb] = None;
}
CleanupKind::Funclet => {
bcx.set_personality_fn(self.fcx.eh_personality());
let cleanup_pad = bcx.cleanup_pad(None, &[]);
funclets[bb] = Funclet::msvc(cleanup_pad);
}
};
}
fn unreachable_block(&mut self) -> BasicBlockRef {
self.unreachable_block.unwrap_or_else(|| {
let bl = self.fcx.build_new_block("unreachable");
@ -898,7 +872,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
})
}
fn build_block(&self, bb: mir::BasicBlock) -> BlockAndBuilder<'a, 'tcx> {
pub fn build_block(&self, bb: mir::BasicBlock) -> BlockAndBuilder<'a, 'tcx> {
BlockAndBuilder::new(self.blocks[bb], self.fcx)
}

View file

@ -36,6 +36,7 @@ use rustc_data_structures::indexed_vec::{IndexVec, Idx};
pub use self::constant::trans_static_initializer;
use self::analyze::CleanupKind;
use self::lvalue::{LvalueRef};
use rustc::mir::traversal;
@ -315,18 +316,28 @@ pub fn trans_mir<'a, 'tcx: 'a>(
// emitting should be enabled.
debuginfo::start_emitting_source_locations(&mircx);
let mut visited = BitVector::new(mir.basic_blocks().len());
let mut rpo = traversal::reverse_postorder(&mir);
let mut funclets: IndexVec<mir::BasicBlock, Option<Funclet>> =
IndexVec::from_elem(None, mir.basic_blocks());
// Prepare each block for translation.
for (bb, _) in rpo.by_ref() {
mircx.init_cpad(bb, &mut funclets);
// If false, all funclets should be None (which is the default)
if base::wants_msvc_seh(fcx.ccx.sess()) {
for (bb, cleanup_kind) in mircx.cleanup_kinds.iter_enumerated() {
let bcx = mircx.build_block(bb);
match *cleanup_kind {
CleanupKind::Internal { .. } => {
bcx.set_personality_fn(fcx.eh_personality());
}
rpo.reset();
CleanupKind::Funclet => {
bcx.set_personality_fn(fcx.eh_personality());
funclets[bb] = Funclet::msvc(bcx.cleanup_pad(None, &[]));
}
_ => {}
}
}
}
let rpo = traversal::reverse_postorder(&mir);
let mut visited = BitVector::new(mir.basic_blocks().len());
// Translate the body of each block using reverse postorder
for (bb, _) in rpo {