From fff6296b62008d89edfbf9d4afd2496b53d7d2cd Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 3 Dec 2022 18:27:18 +0000 Subject: Destruct landing_pad return value before passing it to cg_ssa --- compiler/rustc_codegen_ssa/src/mir/block.rs | 27 +++++++----------------- compiler/rustc_codegen_ssa/src/traits/builder.rs | 4 ++-- 2 files changed, 10 insertions(+), 21 deletions(-) (limited to 'compiler/rustc_codegen_ssa') diff --git a/compiler/rustc_codegen_ssa/src/mir/block.rs b/compiler/rustc_codegen_ssa/src/mir/block.rs index 03d833fbba8..1ef5217a2da 100644 --- a/compiler/rustc_codegen_ssa/src/mir/block.rs +++ b/compiler/rustc_codegen_ssa/src/mir/block.rs @@ -289,16 +289,13 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { bx.cleanup_ret(funclet, None); } else { let slot = self.get_personality_slot(bx); - let lp0 = slot.project_field(bx, 0); - let lp0 = bx.load_operand(lp0).immediate(); - let lp1 = slot.project_field(bx, 1); - let lp1 = bx.load_operand(lp1).immediate(); + let exn0 = slot.project_field(bx, 0); + let exn0 = bx.load_operand(exn0).immediate(); + let exn1 = slot.project_field(bx, 1); + let exn1 = bx.load_operand(exn1).immediate(); slot.storage_dead(bx); - let mut lp = bx.const_undef(self.landing_pad_type()); - lp = bx.insert_value(lp, lp0, 0); - lp = bx.insert_value(lp, lp1, 1); - bx.resume(lp); + bx.resume(exn0, exn1); } } @@ -1635,24 +1632,17 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { let mut cleanup_bx = Bx::build(self.cx, cleanup_llbb); let llpersonality = self.cx.eh_personality(); - let llretty = self.landing_pad_type(); - let lp = cleanup_bx.cleanup_landing_pad(llretty, llpersonality); + let (exn0, exn1) = cleanup_bx.cleanup_landing_pad(llpersonality); let slot = self.get_personality_slot(&mut cleanup_bx); slot.storage_live(&mut cleanup_bx); - Pair(cleanup_bx.extract_value(lp, 0), cleanup_bx.extract_value(lp, 1)) - .store(&mut cleanup_bx, slot); + Pair(exn0, exn1).store(&mut cleanup_bx, slot); cleanup_bx.br(llbb); cleanup_llbb } } - fn landing_pad_type(&self) -> Bx::Type { - let cx = self.cx; - cx.type_struct(&[cx.type_i8p(), cx.type_i32()], false) - } - fn unreachable_block(&mut self) -> Bx::BasicBlock { self.unreachable_block.unwrap_or_else(|| { let llbb = Bx::append_block(self.cx, self.llfn, "unreachable"); @@ -1672,8 +1662,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { self.set_debug_loc(&mut bx, mir::SourceInfo::outermost(self.mir.span)); let llpersonality = self.cx.eh_personality(); - let llretty = self.landing_pad_type(); - bx.cleanup_landing_pad(llretty, llpersonality); + bx.cleanup_landing_pad(llpersonality); let (fn_abi, fn_ptr) = common::build_langcall(&bx, None, LangItem::PanicNoUnwind); let fn_ty = bx.fn_decl_backend_type(&fn_abi); diff --git a/compiler/rustc_codegen_ssa/src/traits/builder.rs b/compiler/rustc_codegen_ssa/src/traits/builder.rs index bc679a5dc87..194768d9466 100644 --- a/compiler/rustc_codegen_ssa/src/traits/builder.rs +++ b/compiler/rustc_codegen_ssa/src/traits/builder.rs @@ -271,8 +271,8 @@ pub trait BuilderMethods<'a, 'tcx>: fn set_personality_fn(&mut self, personality: Self::Value); // These are used by everyone except msvc - fn cleanup_landing_pad(&mut self, ty: Self::Type, pers_fn: Self::Value) -> Self::Value; - fn resume(&mut self, exn: Self::Value); + fn cleanup_landing_pad(&mut self, pers_fn: Self::Value) -> (Self::Value, Self::Value); + fn resume(&mut self, exn0: Self::Value, exn1: Self::Value); // These are used only by msvc fn cleanup_pad(&mut self, parent: Option, args: &[Self::Value]) -> Self::Funclet; -- cgit 1.4.1-3-g733a5 From b2e0db93e7befa23eacb42a121f64c1eb659e8bb Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 3 Dec 2022 18:27:43 +0000 Subject: Directly return loaded value from type_checked_load --- compiler/rustc_codegen_llvm/src/intrinsic.rs | 4 +++- compiler/rustc_codegen_ssa/src/meth.rs | 3 +-- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'compiler/rustc_codegen_ssa') diff --git a/compiler/rustc_codegen_llvm/src/intrinsic.rs b/compiler/rustc_codegen_llvm/src/intrinsic.rs index 2f5dd519b26..907517bf6ce 100644 --- a/compiler/rustc_codegen_llvm/src/intrinsic.rs +++ b/compiler/rustc_codegen_llvm/src/intrinsic.rs @@ -424,7 +424,9 @@ impl<'ll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'_, 'll, 'tcx> { typeid: &'ll Value, ) -> Self::Value { let vtable_byte_offset = self.const_i32(vtable_byte_offset as i32); - self.call_intrinsic("llvm.type.checked.load", &[llvtable, vtable_byte_offset, typeid]) + let type_checked_load = + self.call_intrinsic("llvm.type.checked.load", &[llvtable, vtable_byte_offset, typeid]); + self.extract_value(type_checked_load, 0) } fn va_start(&mut self, va_list: &'ll Value) -> &'ll Value { diff --git a/compiler/rustc_codegen_ssa/src/meth.rs b/compiler/rustc_codegen_ssa/src/meth.rs index cae46ebd2e9..d96ca921f1f 100644 --- a/compiler/rustc_codegen_ssa/src/meth.rs +++ b/compiler/rustc_codegen_ssa/src/meth.rs @@ -31,8 +31,7 @@ impl<'a, 'tcx> VirtualIndex { let typeid = bx.typeid_metadata(typeid_for_trait_ref(bx.tcx(), expect_dyn_trait_in_self(ty))); let vtable_byte_offset = self.0 * bx.data_layout().pointer_size.bytes(); - let type_checked_load = bx.type_checked_load(llvtable, vtable_byte_offset, typeid); - let func = bx.extract_value(type_checked_load, 0); + let func = bx.type_checked_load(llvtable, vtable_byte_offset, typeid); bx.pointercast(func, llty) } else { let ptr_align = bx.tcx().data_layout.pointer_align.abi; -- cgit 1.4.1-3-g733a5 From 262ace528425e6e22ccc0a5afd6321a566ab18d7 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 4 Dec 2022 12:53:46 +0000 Subject: Avoid from_immediate_or_packed_pair in ThreadLocalRef codegen --- compiler/rustc_codegen_ssa/src/mir/rvalue.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'compiler/rustc_codegen_ssa') diff --git a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs index 9ad96f7a447..23196c8cbae 100644 --- a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs +++ b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs @@ -462,7 +462,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { assert!(bx.cx().tcx().is_static(def_id)); let static_ = bx.get_static(def_id); let layout = bx.layout_of(bx.cx().tcx().static_ptr_ty(def_id)); - OperandRef::from_immediate_or_packed_pair(bx, static_, layout) + OperandRef { val: OperandValue::Immediate(static_), layout } } mir::Rvalue::Use(ref operand) => self.codegen_operand(bx, operand), mir::Rvalue::Repeat(..) | mir::Rvalue::Aggregate(..) => { -- cgit 1.4.1-3-g733a5