From e142cdf4f6c3d18cb8f2f9ecfa386873a1910050 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 18 Feb 2022 15:20:19 +0100 Subject: [PATCH] Remove FunctionCx::new_block --- compiler/rustc_codegen_ssa/src/mir/block.rs | 46 +++++++++++---------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/mir/block.rs b/compiler/rustc_codegen_ssa/src/mir/block.rs index 1979bbdb859..f3d41f3f86c 100644 --- a/compiler/rustc_codegen_ssa/src/mir/block.rs +++ b/compiler/rustc_codegen_ssa/src/mir/block.rs @@ -96,9 +96,10 @@ fn llblock>( debug!("llblock: creating cleanup trampoline for {:?}", target); let name = &format!("{:?}_cleanup_trampoline_{:?}", self.bb, target); - let mut trampoline = fx.new_block(name); - trampoline.cleanup_ret(self.funclet(fx).unwrap(), Some(lltarget)); - trampoline.llbb() + let trampoline = Bx::append_block(fx.cx, fx.llfn, name); + let mut trampoline_bx = Bx::build(fx.cx, trampoline); + trampoline_bx.cleanup_ret(self.funclet(fx).unwrap(), Some(lltarget)); + trampoline } else { lltarget } @@ -1358,16 +1359,20 @@ fn landing_pad_for_uncached(&mut self, bb: mir::BasicBlock) -> Bx::BasicBlock { // bar(); // } Some(&mir::TerminatorKind::Abort) => { - let mut cs_bx = self.new_block(&format!("cs_funclet{:?}", bb)); - let mut cp_bx = self.new_block(&format!("cp_funclet{:?}", bb)); - ret_llbb = cs_bx.llbb(); + let cs_bb = + Bx::append_block(self.cx, self.llfn, &format!("cs_funclet{:?}", bb)); + let cp_bb = + Bx::append_block(self.cx, self.llfn, &format!("cp_funclet{:?}", bb)); + ret_llbb = cs_bb; - let cs = cs_bx.catch_switch(None, None, &[cp_bx.llbb()]); + let mut cs_bx = Bx::build(self.cx, cs_bb); + let cs = cs_bx.catch_switch(None, None, &[cp_bb]); // The "null" here is actually a RTTI type descriptor for the // C++ personality function, but `catch (...)` has no type so // it's null. The 64 here is actually a bitfield which // represents that this is a catch-all block. + let mut cp_bx = Bx::build(self.cx, cp_bb); let null = cp_bx.const_null( cp_bx.type_i8p_ext(cp_bx.cx().data_layout().instruction_address_space), ); @@ -1376,8 +1381,10 @@ fn landing_pad_for_uncached(&mut self, bb: mir::BasicBlock) -> Bx::BasicBlock { cp_bx.br(llbb); } _ => { - let mut cleanup_bx = self.new_block(&format!("funclet_{:?}", bb)); - ret_llbb = cleanup_bx.llbb(); + let cleanup_bb = + Bx::append_block(self.cx, self.llfn, &format!("funclet_{:?}", bb)); + ret_llbb = cleanup_bb; + let mut cleanup_bx = Bx::build(self.cx, cleanup_bb); funclet = cleanup_bx.cleanup_pad(None, &[]); cleanup_bx.br(llbb); } @@ -1385,7 +1392,8 @@ fn landing_pad_for_uncached(&mut self, bb: mir::BasicBlock) -> Bx::BasicBlock { self.funclets[bb] = Some(funclet); ret_llbb } else { - let mut bx = self.new_block("cleanup"); + let bb = Bx::append_block(self.cx, self.llfn, "cleanup"); + let mut bx = Bx::build(self.cx, bb); let llpersonality = self.cx.eh_personality(); let llretty = self.landing_pad_type(); @@ -1407,10 +1415,11 @@ fn landing_pad_type(&self) -> Bx::Type { fn unreachable_block(&mut self) -> Bx::BasicBlock { self.unreachable_block.unwrap_or_else(|| { - let mut bx = self.new_block("unreachable"); + let llbb = Bx::append_block(self.cx, self.llfn, "unreachable"); + let mut bx = Bx::build(self.cx, llbb); bx.unreachable(); - self.unreachable_block = Some(bx.llbb()); - bx.llbb() + self.unreachable_block = Some(llbb); + llbb }) } @@ -1418,7 +1427,8 @@ fn double_unwind_guard(&mut self) -> Bx::BasicBlock { self.double_unwind_guard.unwrap_or_else(|| { assert!(!base::wants_msvc_seh(self.cx.sess())); - let mut bx = self.new_block("abort"); + let llbb = Bx::append_block(self.cx, self.llfn, "abort"); + let mut bx = Bx::build(self.cx, llbb); self.set_debug_loc(&mut bx, mir::SourceInfo::outermost(self.mir.span)); let llpersonality = self.cx.eh_personality(); @@ -1436,20 +1446,12 @@ fn double_unwind_guard(&mut self) -> Bx::BasicBlock { bx.apply_attrs_to_cleanup_callsite(llret); bx.unreachable(); - let llbb = bx.llbb(); self.double_unwind_guard = Some(llbb); llbb }) } - // FIXME(eddyb) replace with `append_sibling_block` - // (which requires having a `Bx` already, and not all callers do). - fn new_block(&self, name: &str) -> Bx { - let llbb = Bx::append_block(self.cx, self.llfn, name); - Bx::build(self.cx, llbb) - } - /// Get the backend `BasicBlock` for a MIR `BasicBlock`, either already /// cached in `self.cached_llbbs`, or created on demand (and cached). // FIXME(eddyb) rename `llbb` and other `ll`-prefixed things to use a