@@ -15,11 +15,10 @@ use rustc_middle::ty::{self, GenericArgsRef, Ty};
15
15
use rustc_middle:: { bug, span_bug} ;
16
16
use rustc_span:: { Span , Symbol , sym} ;
17
17
use rustc_symbol_mangling:: mangle_internal_symbol;
18
- use rustc_target:: callconv:: { FnAbi , PassMode } ;
19
18
use rustc_target:: spec:: { HasTargetSpec , PanicStrategy } ;
20
19
use tracing:: debug;
21
20
22
- use crate :: abi:: { FnAbiLlvmExt , LlvmType } ;
21
+ use crate :: abi:: FnAbiLlvmExt ;
23
22
use crate :: builder:: Builder ;
24
23
use crate :: context:: CodegenCx ;
25
24
use crate :: llvm:: { self , Metadata } ;
@@ -165,9 +164,8 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
165
164
fn codegen_intrinsic_call (
166
165
& mut self ,
167
166
instance : ty:: Instance < ' tcx > ,
168
- fn_abi : & FnAbi < ' tcx , Ty < ' tcx > > ,
169
167
args : & [ OperandRef < ' tcx , & ' ll Value > ] ,
170
- llresult : & ' ll Value ,
168
+ result : PlaceRef < ' tcx , & ' ll Value > ,
171
169
span : Span ,
172
170
) -> Result < ( ) , ty:: Instance < ' tcx > > {
173
171
let tcx = self . tcx ;
@@ -184,7 +182,6 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
184
182
let name = tcx. item_name ( def_id) ;
185
183
186
184
let llret_ty = self . layout_of ( ret_ty) . llvm_type ( self ) ;
187
- let result = PlaceRef :: new_sized ( llresult, fn_abi. ret . layout ) ;
188
185
189
186
let simple = get_simple_intrinsic ( self , name) ;
190
187
let llval = match name {
@@ -255,7 +252,7 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
255
252
args[ 0 ] . immediate ( ) ,
256
253
args[ 1 ] . immediate ( ) ,
257
254
args[ 2 ] . immediate ( ) ,
258
- llresult ,
255
+ result ,
259
256
) ;
260
257
return Ok ( ( ) ) ;
261
258
}
@@ -264,7 +261,7 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
264
261
self . call_intrinsic ( "llvm.va_copy" , & [ args[ 0 ] . immediate ( ) , args[ 1 ] . immediate ( ) ] )
265
262
}
266
263
sym:: va_arg => {
267
- match fn_abi . ret . layout . backend_repr {
264
+ match result . layout . backend_repr {
268
265
BackendRepr :: Scalar ( scalar) => {
269
266
match scalar. primitive ( ) {
270
267
Primitive :: Int ( ..) => {
@@ -299,18 +296,12 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
299
296
}
300
297
301
298
sym:: volatile_load | sym:: unaligned_volatile_load => {
302
- let tp_ty = fn_args. type_at ( 0 ) ;
303
299
let ptr = args[ 0 ] . immediate ( ) ;
304
- let load = if let PassMode :: Cast { cast : ty, pad_i32 : _ } = & fn_abi. ret . mode {
305
- let llty = ty. llvm_type ( self ) ;
306
- self . volatile_load ( llty, ptr)
307
- } else {
308
- self . volatile_load ( self . layout_of ( tp_ty) . llvm_type ( self ) , ptr)
309
- } ;
300
+ let load = self . volatile_load ( result. layout . llvm_type ( self ) , ptr) ;
310
301
let align = if name == sym:: unaligned_volatile_load {
311
302
1
312
303
} else {
313
- self . align_of ( tp_ty ) . bytes ( ) as u32
304
+ result . layout . align . abi . bytes ( ) as u32
314
305
} ;
315
306
unsafe {
316
307
llvm:: LLVMSetAlignment ( load, align) ;
@@ -629,14 +620,12 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
629
620
}
630
621
} ;
631
622
632
- if !fn_abi. ret . is_ignore ( ) {
633
- if let PassMode :: Cast { .. } = & fn_abi. ret . mode {
634
- self . store ( llval, result. val . llval , result. val . align ) ;
635
- } else {
636
- OperandRef :: from_immediate_or_packed_pair ( self , llval, result. layout )
637
- . val
638
- . store ( self , result) ;
639
- }
623
+ if result. layout . ty . is_bool ( ) {
624
+ OperandRef :: from_immediate_or_packed_pair ( self , llval, result. layout )
625
+ . val
626
+ . store ( self , result) ;
627
+ } else if !result. layout . ty . is_unit ( ) {
628
+ self . store_to_place ( llval, result. val ) ;
640
629
}
641
630
Ok ( ( ) )
642
631
}
@@ -688,20 +677,19 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
688
677
}
689
678
}
690
679
691
- fn catch_unwind_intrinsic < ' ll > (
692
- bx : & mut Builder < ' _ , ' ll , ' _ > ,
680
+ fn catch_unwind_intrinsic < ' ll , ' tcx > (
681
+ bx : & mut Builder < ' _ , ' ll , ' tcx > ,
693
682
try_func : & ' ll Value ,
694
683
data : & ' ll Value ,
695
684
catch_func : & ' ll Value ,
696
- dest : & ' ll Value ,
685
+ dest : PlaceRef < ' tcx , & ' ll Value > ,
697
686
) {
698
687
if bx. sess ( ) . panic_strategy ( ) == PanicStrategy :: Abort {
699
688
let try_func_ty = bx. type_func ( & [ bx. type_ptr ( ) ] , bx. type_void ( ) ) ;
700
689
bx. call ( try_func_ty, None , None , try_func, & [ data] , None , None ) ;
701
690
// Return 0 unconditionally from the intrinsic call;
702
691
// 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) ;
692
+ OperandValue :: Immediate ( bx. const_i32 ( 0 ) ) . store ( bx, dest) ;
705
693
} else if wants_msvc_seh ( bx. sess ( ) ) {
706
694
codegen_msvc_try ( bx, try_func, data, catch_func, dest) ;
707
695
} else if wants_wasm_eh ( bx. sess ( ) ) {
@@ -720,12 +708,12 @@ fn catch_unwind_intrinsic<'ll>(
720
708
// instructions are meant to work for all targets, as of the time of this
721
709
// writing, however, LLVM does not recommend the usage of these new instructions
722
710
// as the old ones are still more optimized.
723
- fn codegen_msvc_try < ' ll > (
724
- bx : & mut Builder < ' _ , ' ll , ' _ > ,
711
+ fn codegen_msvc_try < ' ll , ' tcx > (
712
+ bx : & mut Builder < ' _ , ' ll , ' tcx > ,
725
713
try_func : & ' ll Value ,
726
714
data : & ' ll Value ,
727
715
catch_func : & ' ll Value ,
728
- dest : & ' ll Value ,
716
+ dest : PlaceRef < ' tcx , & ' ll Value > ,
729
717
) {
730
718
let ( llty, llfn) = get_rust_try_fn ( bx, & mut |mut bx| {
731
719
bx. set_personality_fn ( bx. eh_personality ( ) ) ;
@@ -865,17 +853,16 @@ fn codegen_msvc_try<'ll>(
865
853
// Note that no invoke is used here because by definition this function
866
854
// can't panic (that's what it's catching).
867
855
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) ;
856
+ OperandValue :: Immediate ( ret) . store ( bx, dest) ;
870
857
}
871
858
872
859
// WASM's definition of the `rust_try` function.
873
- fn codegen_wasm_try < ' ll > (
874
- bx : & mut Builder < ' _ , ' ll , ' _ > ,
860
+ fn codegen_wasm_try < ' ll , ' tcx > (
861
+ bx : & mut Builder < ' _ , ' ll , ' tcx > ,
875
862
try_func : & ' ll Value ,
876
863
data : & ' ll Value ,
877
864
catch_func : & ' ll Value ,
878
- dest : & ' ll Value ,
865
+ dest : PlaceRef < ' tcx , & ' ll Value > ,
879
866
) {
880
867
let ( llty, llfn) = get_rust_try_fn ( bx, & mut |mut bx| {
881
868
bx. set_personality_fn ( bx. eh_personality ( ) ) ;
@@ -939,8 +926,7 @@ fn codegen_wasm_try<'ll>(
939
926
// Note that no invoke is used here because by definition this function
940
927
// can't panic (that's what it's catching).
941
928
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) ;
929
+ OperandValue :: Immediate ( ret) . store ( bx, dest) ;
944
930
}
945
931
946
932
// Definition of the standard `try` function for Rust using the GNU-like model
@@ -954,12 +940,12 @@ fn codegen_wasm_try<'ll>(
954
940
// function calling it, and that function may already have other personality
955
941
// functions in play. By calling a shim we're guaranteed that our shim will have
956
942
// the right personality function.
957
- fn codegen_gnu_try < ' ll > (
958
- bx : & mut Builder < ' _ , ' ll , ' _ > ,
943
+ fn codegen_gnu_try < ' ll , ' tcx > (
944
+ bx : & mut Builder < ' _ , ' ll , ' tcx > ,
959
945
try_func : & ' ll Value ,
960
946
data : & ' ll Value ,
961
947
catch_func : & ' ll Value ,
962
- dest : & ' ll Value ,
948
+ dest : PlaceRef < ' tcx , & ' ll Value > ,
963
949
) {
964
950
let ( llty, llfn) = get_rust_try_fn ( bx, & mut |mut bx| {
965
951
// Codegens the shims described above:
@@ -1006,19 +992,18 @@ fn codegen_gnu_try<'ll>(
1006
992
// Note that no invoke is used here because by definition this function
1007
993
// can't panic (that's what it's catching).
1008
994
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) ;
995
+ OperandValue :: Immediate ( ret) . store ( bx, dest) ;
1011
996
}
1012
997
1013
998
// Variant of codegen_gnu_try used for emscripten where Rust panics are
1014
999
// implemented using C++ exceptions. Here we use exceptions of a specific type
1015
1000
// (`struct rust_panic`) to represent Rust panics.
1016
- fn codegen_emcc_try < ' ll > (
1017
- bx : & mut Builder < ' _ , ' ll , ' _ > ,
1001
+ fn codegen_emcc_try < ' ll , ' tcx > (
1002
+ bx : & mut Builder < ' _ , ' ll , ' tcx > ,
1018
1003
try_func : & ' ll Value ,
1019
1004
data : & ' ll Value ,
1020
1005
catch_func : & ' ll Value ,
1021
- dest : & ' ll Value ,
1006
+ dest : PlaceRef < ' tcx , & ' ll Value > ,
1022
1007
) {
1023
1008
let ( llty, llfn) = get_rust_try_fn ( bx, & mut |mut bx| {
1024
1009
// Codegens the shims described above:
@@ -1089,8 +1074,7 @@ fn codegen_emcc_try<'ll>(
1089
1074
// Note that no invoke is used here because by definition this function
1090
1075
// can't panic (that's what it's catching).
1091
1076
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) ;
1077
+ OperandValue :: Immediate ( ret) . store ( bx, dest) ;
1094
1078
}
1095
1079
1096
1080
// Helper function to give a Block to a closure to codegen a shim function.
0 commit comments