From 38fa06bc9528d88b2eaf2b082514368a96654f3e Mon Sep 17 00:00:00 2001 From: Piotr Czarnecki Date: Mon, 8 Feb 2016 23:08:47 +0100 Subject: [PATCH] Cleanup based on review by @nagisa * We don't have SEH-based unwinding yet. For this reason we don't need operand bundles in MIR trans. * Refactored some uses of fcx. * Refactored some calls to `with_block`. --- src/librustc_trans/trans/cleanup.rs | 6 ++-- src/librustc_trans/trans/common.rs | 17 +++------- src/librustc_trans/trans/mir/block.rs | 47 ++++++++++---------------- src/librustc_trans/trans/mir/mod.rs | 27 +++++---------- src/librustc_trans/trans/mir/rvalue.rs | 6 ++-- 5 files changed, 36 insertions(+), 67 deletions(-) diff --git a/src/librustc_trans/trans/cleanup.rs b/src/librustc_trans/trans/cleanup.rs index 1b69784c0966a..683d5e0ead452 100644 --- a/src/librustc_trans/trans/cleanup.rs +++ b/src/librustc_trans/trans/cleanup.rs @@ -740,7 +740,7 @@ impl<'blk, 'tcx> CleanupHelperMethods<'blk, 'tcx> for FunctionContext<'blk, 'tcx UnwindExit(val) => { // Generate a block that will resume unwinding to the // calling function - let bcx = self.new_block("resume", None, None); + let bcx = self.new_block("resume", None); match val { UnwindKind::LandingPad => { let addr = self.landingpad_alloca.get() @@ -830,7 +830,7 @@ impl<'blk, 'tcx> CleanupHelperMethods<'blk, 'tcx> for FunctionContext<'blk, 'tcx let name = scope.block_name("clean"); debug!("generating cleanups for {}", name); - let bcx_in = self.new_block(&name[..], None, None); + let bcx_in = self.new_block(&name[..], None); let exit_label = label.start(bcx_in); let mut bcx_out = bcx_in; let len = scope.cleanups.len(); @@ -873,7 +873,7 @@ impl<'blk, 'tcx> CleanupHelperMethods<'blk, 'tcx> for FunctionContext<'blk, 'tcx Some(llbb) => return llbb, None => { let name = last_scope.block_name("unwind"); - pad_bcx = self.new_block(&name[..], None, None); + pad_bcx = self.new_block(&name[..], None); last_scope.cached_landing_pad = Some(pad_bcx.llbb); } } diff --git a/src/librustc_trans/trans/common.rs b/src/librustc_trans/trans/common.rs index 20c48357719db..ec33046e5d914 100644 --- a/src/librustc_trans/trans/common.rs +++ b/src/librustc_trans/trans/common.rs @@ -434,19 +434,14 @@ impl<'a, 'tcx> FunctionContext<'a, 'tcx> { pub fn new_block(&'a self, name: &str, - opt_node_id: Option, - landing_pad: Option) + opt_node_id: Option) -> Block<'a, 'tcx> { unsafe { let name = CString::new(name).unwrap(); let llbb = llvm::LLVMAppendBasicBlockInContext(self.ccx.llcx(), self.llfn, name.as_ptr()); - let block = BlockS::new(llbb, opt_node_id, self); - if let Some(landing_pad) = landing_pad { - block.lpad.set(Some(self.lpad_arena.alloc(landing_pad))); - } - block + BlockS::new(llbb, opt_node_id, self) } } @@ -454,13 +449,13 @@ impl<'a, 'tcx> FunctionContext<'a, 'tcx> { name: &str, node_id: ast::NodeId) -> Block<'a, 'tcx> { - self.new_block(name, Some(node_id), None) + self.new_block(name, Some(node_id)) } pub fn new_temp_block(&'a self, name: &str) -> Block<'a, 'tcx> { - self.new_block(name, None, None) + self.new_block(name, None) } pub fn join_blocks(&'a self, @@ -759,10 +754,6 @@ impl<'blk, 'tcx> BlockAndBuilder<'blk, 'tcx> { self.bcx.llbb } - pub fn lpad(&self) -> Option<&'blk LandingPad> { - self.bcx.lpad() - } - pub fn mir(&self) -> &'blk Mir<'tcx> { self.bcx.mir() } diff --git a/src/librustc_trans/trans/mir/block.rs b/src/librustc_trans/trans/mir/block.rs index 6c1a5ac74d013..b3b8214a9a70d 100644 --- a/src/librustc_trans/trans/mir/block.rs +++ b/src/librustc_trans/trans/mir/block.rs @@ -16,7 +16,7 @@ use trans::adt; use trans::attributes; use trans::base; use trans::build; -use trans::common::{self, Block, BlockAndBuilder, LandingPad}; +use trans::common::{self, Block, BlockAndBuilder}; use trans::debuginfo::DebugLoc; use trans::Disr; use trans::foreign; @@ -119,16 +119,14 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> { if let Some(unwind) = unwind { let uwbcx = self.bcx(unwind); let unwind = self.make_landing_pad(uwbcx); - let bundle = bcx.lpad().and_then(|b| b.bundle()); bcx.invoke(drop_fn, &[llvalue], self.llblock(target), unwind.llbb(), - bundle, + None, None); } else { - let bundle = bcx.lpad().and_then(|b| b.bundle()); - bcx.call(drop_fn, &[llvalue], bundle, None); + bcx.call(drop_fn, &[llvalue], None, None); bcx.br(self.llblock(target)); } } @@ -190,28 +188,26 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> { let cleanup = self.bcx(cleanup); let landingpad = self.make_landing_pad(cleanup); let unreachable_blk = self.unreachable_block(); - let bundle = bcx.lpad().and_then(|b| b.bundle()); bcx.invoke(callee.immediate(), &llargs[..], unreachable_blk.llbb, landingpad.llbb(), - bundle, + None, Some(attrs)); }, (false, false, &Some(cleanup), &Some((_, success))) => { let cleanup = self.bcx(cleanup); let landingpad = self.make_landing_pad(cleanup); let (target, postinvoke) = if must_copy_dest { - (bcx.fcx().new_block("", None, None).build(), Some(self.bcx(success))) + (bcx.fcx().new_block("", None).build(), Some(self.bcx(success))) } else { (self.bcx(success), None) }; - let bundle = bcx.lpad().and_then(|b| b.bundle()); let invokeret = bcx.invoke(callee.immediate(), &llargs[..], target.llbb(), landingpad.llbb(), - bundle, + None, Some(attrs)); if let Some(postinvoketarget) = postinvoke { // We translate the copy into a temporary block. The temporary block is @@ -247,15 +243,13 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> { } }, (false, _, _, &None) => { - let bundle = bcx.lpad().and_then(|b| b.bundle()); - bcx.call(callee.immediate(), &llargs[..], bundle, Some(attrs)); + bcx.call(callee.immediate(), &llargs[..], None, Some(attrs)); bcx.unreachable(); } (false, _, _, &Some((_, target))) => { - let bundle = bcx.lpad().and_then(|b| b.bundle()); let llret = bcx.call(callee.immediate(), &llargs[..], - bundle, + None, Some(attrs)); if must_copy_dest { let (ret_dest, ret_ty) = ret_dest_ty @@ -294,14 +288,12 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> { slot } else { let llretty = Type::struct_(ccx, &[Type::i8p(ccx), Type::i32(ccx)], false); - let slot = bcx.with_block(|bcx| { - base::alloca(bcx, llretty, "personalityslot") - }); - self.llpersonalityslot = Some(slot); bcx.with_block(|bcx| { + let slot = base::alloca(bcx, llretty, "personalityslot"); + self.llpersonalityslot = Some(slot); base::call_lifetime_start(bcx, slot); - }); - slot + slot + }) } } @@ -309,25 +301,22 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> { cleanup: BlockAndBuilder<'bcx, 'tcx>) -> BlockAndBuilder<'bcx, 'tcx> { - let cleanup_llbb = cleanup.llbb(); - let bcx = cleanup.map_block(|cleanup| { - // FIXME(#30941) this doesn't handle msvc-style exceptions - cleanup.fcx.new_block("cleanup", None, Some(LandingPad::gnu())) - }); + // FIXME(#30941) this doesn't handle msvc-style exceptions + let bcx = self.fcx.new_block("cleanup", None).build(); let ccx = bcx.ccx(); - let llpersonality = bcx.fcx().eh_personality(); + let llpersonality = self.fcx.eh_personality(); let llretty = Type::struct_(ccx, &[Type::i8p(ccx), Type::i32(ccx)], false); - let llretval = bcx.landing_pad(llretty, llpersonality, 1, bcx.fcx().llfn); + let llretval = bcx.landing_pad(llretty, llpersonality, 1, self.fcx.llfn); bcx.set_cleanup(llretval); let slot = self.get_personality_slot(&bcx); bcx.store(llretval, slot); - bcx.br(cleanup_llbb); + bcx.br(cleanup.llbb()); bcx } fn unreachable_block(&mut self) -> Block<'bcx, 'tcx> { self.unreachable_block.unwrap_or_else(|| { - let bl = self.fcx.new_block("unreachable", None, None); + let bl = self.fcx.new_block("unreachable", None); bl.build().unreachable(); self.unreachable_block = Some(bl); bl diff --git a/src/librustc_trans/trans/mir/mod.rs b/src/librustc_trans/trans/mir/mod.rs index e93c920d9a3b9..972340e7f5afd 100644 --- a/src/librustc_trans/trans/mir/mod.rs +++ b/src/librustc_trans/trans/mir/mod.rs @@ -13,7 +13,7 @@ use llvm::{self, ValueRef}; use rustc::mir::repr as mir; use rustc::mir::tcx::LvalueTy; use trans::base; -use trans::common::{self, Block, BlockAndBuilder, LandingPad}; +use trans::common::{self, Block, BlockAndBuilder}; use trans::expr; use trans::type_of; @@ -115,12 +115,7 @@ pub fn trans_mir<'bcx, 'tcx>(bcx: BlockAndBuilder<'bcx, 'tcx>) { mir_blocks.iter() .map(|&bb|{ // FIXME(#30941) this doesn't handle msvc-style exceptions - let lpad = if mir.basic_block_data(bb).is_cleanup { - Some(LandingPad::gnu()) - } else { - None - }; - fcx.new_block(&format!("{:?}", bb), None, lpad) + fcx.new_block(&format!("{:?}", bb), None) }) .collect(); @@ -175,11 +170,9 @@ fn arg_value_refs<'bcx, 'tcx>(bcx: &BlockAndBuilder<'bcx, 'tcx>, let lldata = llvm::get_param(fcx.llfn, idx); let llextra = llvm::get_param(fcx.llfn, idx + 1); idx += 2; - let lltemp = bcx.with_block(|bcx| { - base::alloc_ty(bcx, arg_ty, &format!("arg{}", arg_index)) - }); - let (dataptr, meta) = bcx.with_block(|bcx| { - (expr::get_dataptr(bcx, lltemp), expr::get_meta(bcx, lltemp)) + let (lltemp, dataptr, meta) = bcx.with_block(|bcx| { + let lltemp = base::alloc_ty(bcx, arg_ty, &format!("arg{}", arg_index)); + (lltemp, expr::get_dataptr(bcx, lltemp), expr::get_meta(bcx, lltemp)) }); bcx.store(lldata, dataptr); bcx.store(llextra, meta); @@ -189,13 +182,11 @@ fn arg_value_refs<'bcx, 'tcx>(bcx: &BlockAndBuilder<'bcx, 'tcx>, // temporary and store it there let llarg = llvm::get_param(fcx.llfn, idx); idx += 1; - let lltemp = bcx.with_block(|bcx| { - base::alloc_ty(bcx, arg_ty, &format!("arg{}", arg_index)) - }); bcx.with_block(|bcx| { - base::store_ty(bcx, llarg, lltemp, arg_ty) - }); - lltemp + let lltemp = base::alloc_ty(bcx, arg_ty, &format!("arg{}", arg_index)); + base::store_ty(bcx, llarg, lltemp, arg_ty); + lltemp + }) }; LvalueRef::new_sized(llval, LvalueTy::from_ty(arg_ty)) }) diff --git a/src/librustc_trans/trans/mir/rvalue.rs b/src/librustc_trans/trans/mir/rvalue.rs index 5debb76aa6c0d..ab0c299af05ce 100644 --- a/src/librustc_trans/trans/mir/rvalue.rs +++ b/src/librustc_trans/trans/mir/rvalue.rs @@ -497,12 +497,10 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> { if input_ty == tcx.types.f32 { let lllhs = bcx.fpext(lhs, f64t); let llrhs = bcx.fpext(rhs, f64t); - let bundle = bcx.lpad().and_then(|b| b.bundle()); - let llres = bcx.call(llfn, &[lllhs, llrhs], bundle, None); + let llres = bcx.call(llfn, &[lllhs, llrhs], None, None); bcx.fptrunc(llres, Type::f32(bcx.ccx())) } else { - let bundle = bcx.lpad().and_then(|b| b.bundle()); - bcx.call(llfn, &[lhs, rhs], bundle, None) + bcx.call(llfn, &[lhs, rhs], None, None) } } else { bcx.frem(lhs, rhs)