Skip to content

Commit 50cccb5

Browse files
committed
Pass PlaceRef rather than Bx::Value to codegen_intrinsic_call
1 parent b9ffffd commit 50cccb5

File tree

5 files changed

+38
-45
lines changed

5 files changed

+38
-45
lines changed

compiler/rustc_codegen_gcc/src/intrinsic/mod.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use rustc_codegen_ssa::traits::{
2222
};
2323
use rustc_middle::bug;
2424
#[cfg(feature = "master")]
25-
use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt};
25+
use rustc_middle::ty::layout::FnAbiOf;
2626
use rustc_middle::ty::layout::{HasTypingEnv, LayoutOf};
2727
use rustc_middle::ty::{self, Instance, Ty};
2828
use rustc_span::{Span, Symbol, sym};
@@ -202,7 +202,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
202202
instance: Instance<'tcx>,
203203
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
204204
args: &[OperandRef<'tcx, RValue<'gcc>>],
205-
llresult: RValue<'gcc>,
205+
result: PlaceRef<'tcx, RValue<'gcc>>,
206206
span: Span,
207207
) -> Result<(), Instance<'tcx>> {
208208
let tcx = self.tcx;
@@ -221,7 +221,6 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
221221
let name_str = name.as_str();
222222

223223
let llret_ty = self.layout_of(ret_ty).gcc_type(self);
224-
let result = PlaceRef::new_sized(llresult, fn_abi.ret.layout);
225224

226225
let simple = get_simple_intrinsic(self, name);
227226
let simple_func = get_simple_function(self, name);
@@ -271,7 +270,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
271270
args[0].immediate(),
272271
args[1].immediate(),
273272
args[2].immediate(),
274-
llresult,
273+
result,
275274
);
276275
return Ok(());
277276
}
@@ -1230,14 +1229,13 @@ fn try_intrinsic<'a, 'b, 'gcc, 'tcx>(
12301229
try_func: RValue<'gcc>,
12311230
data: RValue<'gcc>,
12321231
_catch_func: RValue<'gcc>,
1233-
dest: RValue<'gcc>,
1232+
dest: PlaceRef<'tcx, RValue<'gcc>>,
12341233
) {
12351234
if bx.sess().panic_strategy() == PanicStrategy::Abort {
12361235
bx.call(bx.type_void(), None, None, try_func, &[data], None, None);
12371236
// Return 0 unconditionally from the intrinsic call;
12381237
// we can never unwind.
1239-
let ret_align = bx.tcx.data_layout.i32_align.abi;
1240-
bx.store(bx.const_i32(0), dest, ret_align);
1238+
OperandValue::Immediate(bx.const_i32(0)).store(bx, dest);
12411239
} else {
12421240
if wants_msvc_seh(bx.sess()) {
12431241
unimplemented!();
@@ -1261,12 +1259,12 @@ fn try_intrinsic<'a, 'b, 'gcc, 'tcx>(
12611259
// functions in play. By calling a shim we're guaranteed that our shim will have
12621260
// the right personality function.
12631261
#[cfg(feature = "master")]
1264-
fn codegen_gnu_try<'gcc>(
1265-
bx: &mut Builder<'_, 'gcc, '_>,
1262+
fn codegen_gnu_try<'gcc, 'tcx>(
1263+
bx: &mut Builder<'_, 'gcc, 'tcx>,
12661264
try_func: RValue<'gcc>,
12671265
data: RValue<'gcc>,
12681266
catch_func: RValue<'gcc>,
1269-
dest: RValue<'gcc>,
1267+
dest: PlaceRef<'tcx, RValue<'gcc>>,
12701268
) {
12711269
let cx: &CodegenCx<'gcc, '_> = bx.cx;
12721270
let (llty, func) = get_rust_try_fn(cx, &mut |mut bx| {
@@ -1322,8 +1320,7 @@ fn codegen_gnu_try<'gcc>(
13221320
// Note that no invoke is used here because by definition this function
13231321
// can't panic (that's what it's catching).
13241322
let ret = bx.call(llty, None, None, func, &[try_func, data, catch_func], None, None);
1325-
let i32_align = bx.tcx().data_layout.i32_align.abi;
1326-
bx.store(ret, dest, i32_align);
1323+
OperandValue::Immediate(ret).store(bx, dest);
13271324
}
13281325

13291326
// Helper function used to get a handle to the `__rust_try` function used to

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
167167
instance: ty::Instance<'tcx>,
168168
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
169169
args: &[OperandRef<'tcx, &'ll Value>],
170-
llresult: &'ll Value,
170+
result: PlaceRef<'tcx, &'ll Value>,
171171
span: Span,
172172
) -> Result<(), ty::Instance<'tcx>> {
173173
let tcx = self.tcx;
@@ -184,7 +184,6 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
184184
let name = tcx.item_name(def_id);
185185

186186
let llret_ty = self.layout_of(ret_ty).llvm_type(self);
187-
let result = PlaceRef::new_sized(llresult, fn_abi.ret.layout);
188187

189188
let simple = get_simple_intrinsic(self, name);
190189
let llval = match name {
@@ -255,7 +254,7 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
255254
args[0].immediate(),
256255
args[1].immediate(),
257256
args[2].immediate(),
258-
llresult,
257+
result,
259258
);
260259
return Ok(());
261260
}
@@ -688,20 +687,19 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
688687
}
689688
}
690689

691-
fn catch_unwind_intrinsic<'ll>(
692-
bx: &mut Builder<'_, 'll, '_>,
690+
fn catch_unwind_intrinsic<'ll, 'tcx>(
691+
bx: &mut Builder<'_, 'll, 'tcx>,
693692
try_func: &'ll Value,
694693
data: &'ll Value,
695694
catch_func: &'ll Value,
696-
dest: &'ll Value,
695+
dest: PlaceRef<'tcx, &'ll Value>,
697696
) {
698697
if bx.sess().panic_strategy() == PanicStrategy::Abort {
699698
let try_func_ty = bx.type_func(&[bx.type_ptr()], bx.type_void());
700699
bx.call(try_func_ty, None, None, try_func, &[data], None, None);
701700
// Return 0 unconditionally from the intrinsic call;
702701
// we can never unwind.
703-
let ret_align = bx.tcx().data_layout.i32_align.abi;
704-
bx.store(bx.const_i32(0), dest, ret_align);
702+
OperandValue::Immediate(bx.const_i32(0)).store(bx, dest);
705703
} else if wants_msvc_seh(bx.sess()) {
706704
codegen_msvc_try(bx, try_func, data, catch_func, dest);
707705
} else if wants_wasm_eh(bx.sess()) {
@@ -720,12 +718,12 @@ fn catch_unwind_intrinsic<'ll>(
720718
// instructions are meant to work for all targets, as of the time of this
721719
// writing, however, LLVM does not recommend the usage of these new instructions
722720
// as the old ones are still more optimized.
723-
fn codegen_msvc_try<'ll>(
724-
bx: &mut Builder<'_, 'll, '_>,
721+
fn codegen_msvc_try<'ll, 'tcx>(
722+
bx: &mut Builder<'_, 'll, 'tcx>,
725723
try_func: &'ll Value,
726724
data: &'ll Value,
727725
catch_func: &'ll Value,
728-
dest: &'ll Value,
726+
dest: PlaceRef<'tcx, &'ll Value>,
729727
) {
730728
let (llty, llfn) = get_rust_try_fn(bx, &mut |mut bx| {
731729
bx.set_personality_fn(bx.eh_personality());
@@ -865,17 +863,16 @@ fn codegen_msvc_try<'ll>(
865863
// Note that no invoke is used here because by definition this function
866864
// can't panic (that's what it's catching).
867865
let ret = bx.call(llty, None, None, llfn, &[try_func, data, catch_func], None, None);
868-
let i32_align = bx.tcx().data_layout.i32_align.abi;
869-
bx.store(ret, dest, i32_align);
866+
OperandValue::Immediate(ret).store(bx, dest);
870867
}
871868

872869
// WASM's definition of the `rust_try` function.
873-
fn codegen_wasm_try<'ll>(
874-
bx: &mut Builder<'_, 'll, '_>,
870+
fn codegen_wasm_try<'ll, 'tcx>(
871+
bx: &mut Builder<'_, 'll, 'tcx>,
875872
try_func: &'ll Value,
876873
data: &'ll Value,
877874
catch_func: &'ll Value,
878-
dest: &'ll Value,
875+
dest: PlaceRef<'tcx, &'ll Value>,
879876
) {
880877
let (llty, llfn) = get_rust_try_fn(bx, &mut |mut bx| {
881878
bx.set_personality_fn(bx.eh_personality());
@@ -939,8 +936,7 @@ fn codegen_wasm_try<'ll>(
939936
// Note that no invoke is used here because by definition this function
940937
// can't panic (that's what it's catching).
941938
let ret = bx.call(llty, None, None, llfn, &[try_func, data, catch_func], None, None);
942-
let i32_align = bx.tcx().data_layout.i32_align.abi;
943-
bx.store(ret, dest, i32_align);
939+
OperandValue::Immediate(ret).store(bx, dest);
944940
}
945941

946942
// Definition of the standard `try` function for Rust using the GNU-like model
@@ -954,12 +950,12 @@ fn codegen_wasm_try<'ll>(
954950
// function calling it, and that function may already have other personality
955951
// functions in play. By calling a shim we're guaranteed that our shim will have
956952
// the right personality function.
957-
fn codegen_gnu_try<'ll>(
958-
bx: &mut Builder<'_, 'll, '_>,
953+
fn codegen_gnu_try<'ll, 'tcx>(
954+
bx: &mut Builder<'_, 'll, 'tcx>,
959955
try_func: &'ll Value,
960956
data: &'ll Value,
961957
catch_func: &'ll Value,
962-
dest: &'ll Value,
958+
dest: PlaceRef<'tcx, &'ll Value>,
963959
) {
964960
let (llty, llfn) = get_rust_try_fn(bx, &mut |mut bx| {
965961
// Codegens the shims described above:
@@ -1006,19 +1002,18 @@ fn codegen_gnu_try<'ll>(
10061002
// Note that no invoke is used here because by definition this function
10071003
// can't panic (that's what it's catching).
10081004
let ret = bx.call(llty, None, None, llfn, &[try_func, data, catch_func], None, None);
1009-
let i32_align = bx.tcx().data_layout.i32_align.abi;
1010-
bx.store(ret, dest, i32_align);
1005+
OperandValue::Immediate(ret).store(bx, dest);
10111006
}
10121007

10131008
// Variant of codegen_gnu_try used for emscripten where Rust panics are
10141009
// implemented using C++ exceptions. Here we use exceptions of a specific type
10151010
// (`struct rust_panic`) to represent Rust panics.
1016-
fn codegen_emcc_try<'ll>(
1017-
bx: &mut Builder<'_, 'll, '_>,
1011+
fn codegen_emcc_try<'ll, 'tcx>(
1012+
bx: &mut Builder<'_, 'll, 'tcx>,
10181013
try_func: &'ll Value,
10191014
data: &'ll Value,
10201015
catch_func: &'ll Value,
1021-
dest: &'ll Value,
1016+
dest: PlaceRef<'tcx, &'ll Value>,
10221017
) {
10231018
let (llty, llfn) = get_rust_try_fn(bx, &mut |mut bx| {
10241019
// Codegens the shims described above:
@@ -1089,8 +1084,7 @@ fn codegen_emcc_try<'ll>(
10891084
// Note that no invoke is used here because by definition this function
10901085
// can't panic (that's what it's catching).
10911086
let ret = bx.call(llty, None, None, llfn, &[try_func, data, catch_func], None, None);
1092-
let i32_align = bx.tcx().data_layout.i32_align.abi;
1093-
bx.store(ret, dest, i32_align);
1087+
OperandValue::Immediate(ret).store(bx, dest);
10941088
}
10951089

10961090
// Helper function to give a Block to a closure to codegen a shim function.

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -965,12 +965,14 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
965965
let args: Vec<_> =
966966
args.iter().map(|arg| self.codegen_operand(bx, &arg.node)).collect();
967967

968+
let result = PlaceRef::new_sized(dest, fn_abi.ret.layout);
969+
968970
match self.codegen_intrinsic_call(
969971
bx,
970972
instance,
971973
fn_abi,
972974
&args,
973-
dest,
975+
result,
974976
source_info,
975977
) {
976978
Ok(()) => {

compiler/rustc_codegen_ssa/src/mir/intrinsic.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
5858
instance: ty::Instance<'tcx>,
5959
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
6060
args: &[OperandRef<'tcx, Bx::Value>],
61-
llresult: Bx::Value,
61+
result: PlaceRef<'tcx, Bx::Value>,
6262
source_info: SourceInfo,
6363
) -> Result<(), ty::Instance<'tcx>> {
6464
let span = source_info.span;
@@ -100,7 +100,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
100100
}
101101

102102
let llret_ty = bx.backend_type(bx.layout_of(ret_ty));
103-
let result = PlaceRef::new_sized(llresult, fn_abi.ret.layout);
104103

105104
let llval = match name {
106105
sym::abort => {
@@ -537,7 +536,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
537536

538537
_ => {
539538
// Need to use backend-specific things in the implementation.
540-
return bx.codegen_intrinsic_call(instance, fn_abi, args, llresult, span);
539+
return bx.codegen_intrinsic_call(instance, fn_abi, args, result, span);
541540
}
542541
};
543542

compiler/rustc_codegen_ssa/src/traits/intrinsic.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use rustc_target::callconv::FnAbi;
44

55
use super::BackendTypes;
66
use crate::mir::operand::OperandRef;
7+
use crate::mir::place::PlaceRef;
78

89
pub trait IntrinsicCallBuilderMethods<'tcx>: BackendTypes {
910
/// Remember to add all intrinsics here, in `compiler/rustc_hir_analysis/src/check/mod.rs`,
@@ -16,7 +17,7 @@ pub trait IntrinsicCallBuilderMethods<'tcx>: BackendTypes {
1617
instance: ty::Instance<'tcx>,
1718
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
1819
args: &[OperandRef<'tcx, Self::Value>],
19-
llresult: Self::Value,
20+
result: PlaceRef<'tcx, Self::Value>,
2021
span: Span,
2122
) -> Result<(), ty::Instance<'tcx>>;
2223

0 commit comments

Comments
 (0)