1
1
#[ cfg( debug_assertions) ]
2
2
mod comments;
3
- mod returning;
4
3
mod pass_mode;
4
+ mod returning;
5
5
6
6
use rustc_target:: spec:: abi:: Abi ;
7
7
8
- use crate :: prelude:: * ;
9
8
use self :: pass_mode:: * ;
9
+ use crate :: prelude:: * ;
10
10
11
11
pub use self :: returning:: codegen_return;
12
12
13
- fn clif_sig_from_fn_sig < ' tcx > ( tcx : TyCtxt < ' tcx > , sig : FnSig < ' tcx > , is_vtable_fn : bool ) -> Signature {
13
+ fn clif_sig_from_fn_sig < ' tcx > (
14
+ tcx : TyCtxt < ' tcx > ,
15
+ sig : FnSig < ' tcx > ,
16
+ is_vtable_fn : bool ,
17
+ ) -> Signature {
14
18
let abi = match sig. abi {
15
19
Abi :: System => {
16
20
if tcx. sess . target . target . options . is_like_windows {
@@ -47,12 +51,18 @@ fn clif_sig_from_fn_sig<'tcx>(tcx: TyCtxt<'tcx>, sig: FnSig<'tcx>, is_vtable_fn:
47
51
if i == 0 && is_vtable_fn {
48
52
// Virtual calls turn their self param into a thin pointer.
49
53
// See https://github.com/rust-lang/rust/blob/37b6a5e5e82497caf5353d9d856e4eb5d14cbe06/src/librustc/ty/layout.rs#L2519-L2572 for more info
50
- layout = tcx. layout_of ( ParamEnv :: reveal_all ( ) . and ( tcx. mk_mut_ptr ( tcx. mk_unit ( ) ) ) ) . unwrap ( ) ;
54
+ layout = tcx
55
+ . layout_of ( ParamEnv :: reveal_all ( ) . and ( tcx. mk_mut_ptr ( tcx. mk_unit ( ) ) ) )
56
+ . unwrap ( ) ;
51
57
}
52
58
get_pass_mode ( tcx, layout) . get_param_ty ( tcx) . into_iter ( )
53
- } ) . flatten ( ) ;
59
+ } )
60
+ . flatten ( ) ;
54
61
55
- let ( params, returns) = match get_pass_mode ( tcx, tcx. layout_of ( ParamEnv :: reveal_all ( ) . and ( output) ) . unwrap ( ) ) {
62
+ let ( params, returns) = match get_pass_mode (
63
+ tcx,
64
+ tcx. layout_of ( ParamEnv :: reveal_all ( ) . and ( output) ) . unwrap ( ) ,
65
+ ) {
56
66
PassMode :: NoPass => ( inputs. map ( AbiParam :: new) . collect ( ) , vec ! [ ] ) ,
57
67
PassMode :: ByVal ( ret_ty) => (
58
68
inputs. map ( AbiParam :: new) . collect ( ) ,
@@ -87,7 +97,8 @@ pub fn get_function_name_and_sig<'tcx>(
87
97
support_vararg : bool ,
88
98
) -> ( String , Signature ) {
89
99
assert ! ( !inst. substs. needs_infer( ) && !inst. substs. has_param_types( ) ) ;
90
- let fn_sig = tcx. normalize_erasing_late_bound_regions ( ParamEnv :: reveal_all ( ) , & inst. fn_sig ( tcx) ) ;
100
+ let fn_sig =
101
+ tcx. normalize_erasing_late_bound_regions ( ParamEnv :: reveal_all ( ) , & inst. fn_sig ( tcx) ) ;
91
102
if fn_sig. c_variadic && !support_vararg {
92
103
unimpl ! ( "Variadic function definitions are not yet supported" ) ;
93
104
}
@@ -141,7 +152,8 @@ impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> {
141
152
. module
142
153
. declare_func_in_func ( func_id, & mut self . bcx . func ) ;
143
154
let call_inst = self . bcx . ins ( ) . call ( func_ref, args) ;
144
- #[ cfg( debug_assertions) ] {
155
+ #[ cfg( debug_assertions) ]
156
+ {
145
157
self . add_comment ( call_inst, format ! ( "easy_call {}" , name) ) ;
146
158
}
147
159
let results = self . bcx . inst_results ( call_inst) ;
@@ -185,7 +197,10 @@ impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> {
185
197
}
186
198
187
199
fn self_sig ( & self ) -> FnSig < ' tcx > {
188
- self . tcx . normalize_erasing_late_bound_regions ( ParamEnv :: reveal_all ( ) , & self . instance . fn_sig ( self . tcx ) )
200
+ self . tcx . normalize_erasing_late_bound_regions (
201
+ ParamEnv :: reveal_all ( ) ,
202
+ & self . instance . fn_sig ( self . tcx ) ,
203
+ )
189
204
}
190
205
191
206
fn return_layout ( & self ) -> TyLayout < ' tcx > {
@@ -213,10 +228,7 @@ fn local_place<'tcx>(
213
228
fx. local_map [ & local]
214
229
}
215
230
216
- pub fn codegen_fn_prelude (
217
- fx : & mut FunctionCx < ' _ , ' _ , impl Backend > ,
218
- start_ebb : Ebb ,
219
- ) {
231
+ pub fn codegen_fn_prelude ( fx : & mut FunctionCx < ' _ , ' _ , impl Backend > , start_ebb : Ebb ) {
220
232
let ssa_analyzed = crate :: analyze:: analyze ( fx) ;
221
233
222
234
#[ cfg( debug_assertions) ]
@@ -250,20 +262,13 @@ pub fn codegen_fn_prelude(
250
262
251
263
let mut params = Vec :: new ( ) ;
252
264
for ( i, arg_ty) in tupled_arg_tys. types ( ) . enumerate ( ) {
253
- let param = cvalue_for_param (
254
- fx,
255
- start_ebb,
256
- local,
257
- Some ( i) ,
258
- arg_ty,
259
- ) ;
265
+ let param = cvalue_for_param ( fx, start_ebb, local, Some ( i) , arg_ty) ;
260
266
params. push ( param) ;
261
267
}
262
268
263
269
( local, ArgKind :: Spread ( params) , arg_ty)
264
270
} else {
265
- let param =
266
- cvalue_for_param ( fx, start_ebb, local, None , arg_ty) ;
271
+ let param = cvalue_for_param ( fx, start_ebb, local, None , arg_ty) ;
267
272
( local, ArgKind :: Normal ( param) , arg_ty)
268
273
}
269
274
} )
@@ -354,7 +359,9 @@ pub fn codegen_terminator_call<'tcx>(
354
359
destination : & Option < ( Place < ' tcx > , BasicBlock ) > ,
355
360
) {
356
361
let fn_ty = fx. monomorphize ( & func. ty ( fx. mir , fx. tcx ) ) ;
357
- let sig = fx. tcx . normalize_erasing_late_bound_regions ( ParamEnv :: reveal_all ( ) , & fn_ty. fn_sig ( fx. tcx ) ) ;
362
+ let sig = fx
363
+ . tcx
364
+ . normalize_erasing_late_bound_regions ( ParamEnv :: reveal_all ( ) , & fn_ty. fn_sig ( fx. tcx ) ) ;
358
365
359
366
let destination = destination
360
367
. as_ref ( )
@@ -365,7 +372,13 @@ pub fn codegen_terminator_call<'tcx>(
365
372
ty:: Instance :: resolve ( fx. tcx , ty:: ParamEnv :: reveal_all ( ) , def_id, substs) . unwrap ( ) ;
366
373
367
374
if fx. tcx . symbol_name ( instance) . as_str ( ) . starts_with ( "llvm." ) {
368
- crate :: llvm_intrinsics:: codegen_llvm_intrinsic_call ( fx, & fx. tcx . symbol_name ( instance) . as_str ( ) , substs, args, destination) ;
375
+ crate :: llvm_intrinsics:: codegen_llvm_intrinsic_call (
376
+ fx,
377
+ & fx. tcx . symbol_name ( instance) . as_str ( ) ,
378
+ substs,
379
+ args,
380
+ destination,
381
+ ) ;
369
382
return ;
370
383
}
371
384
@@ -430,7 +443,9 @@ fn codegen_call_inner<'tcx>(
430
443
args : Vec < CValue < ' tcx > > ,
431
444
ret_place : Option < CPlace < ' tcx > > ,
432
445
) {
433
- let fn_sig = fx. tcx . normalize_erasing_late_bound_regions ( ParamEnv :: reveal_all ( ) , & fn_ty. fn_sig ( fx. tcx ) ) ;
446
+ let fn_sig = fx
447
+ . tcx
448
+ . normalize_erasing_late_bound_regions ( ParamEnv :: reveal_all ( ) , & fn_ty. fn_sig ( fx. tcx ) ) ;
434
449
435
450
let instance = match fn_ty. sty {
436
451
ty:: FnDef ( def_id, substs) => {
@@ -453,15 +468,24 @@ fn codegen_call_inner<'tcx>(
453
468
let nop_inst = fx. bcx . ins ( ) . nop ( ) ;
454
469
fx. add_comment (
455
470
nop_inst,
456
- format ! ( "virtual call; self arg pass mode: {:?}" , get_pass_mode( fx. tcx, args[ 0 ] . layout( ) ) ) ,
471
+ format ! (
472
+ "virtual call; self arg pass mode: {:?}" ,
473
+ get_pass_mode( fx. tcx, args[ 0 ] . layout( ) )
474
+ ) ,
457
475
) ;
458
476
}
459
477
let ( ptr, method) = crate :: vtable:: get_ptr_and_method_ref ( fx, args[ 0 ] , idx) ;
460
478
( Some ( method) , Single ( ptr) , true )
461
479
}
462
480
463
481
// Normal call
464
- Some ( _) => ( None , args. get ( 0 ) . map ( |arg| adjust_arg_for_abi ( fx, * arg) ) . unwrap_or ( Empty ) , false ) ,
482
+ Some ( _) => (
483
+ None ,
484
+ args. get ( 0 )
485
+ . map ( |arg| adjust_arg_for_abi ( fx, * arg) )
486
+ . unwrap_or ( Empty ) ,
487
+ false ,
488
+ ) ,
465
489
466
490
// Indirect call
467
491
None => {
@@ -474,36 +498,40 @@ fn codegen_call_inner<'tcx>(
474
498
. load_scalar ( fx) ;
475
499
(
476
500
Some ( func) ,
477
- args. get ( 0 ) . map ( |arg| adjust_arg_for_abi ( fx, * arg) ) . unwrap_or ( Empty ) ,
501
+ args. get ( 0 )
502
+ . map ( |arg| adjust_arg_for_abi ( fx, * arg) )
503
+ . unwrap_or ( Empty ) ,
478
504
false ,
479
505
)
480
506
}
481
507
} ;
482
508
483
- let ( call_inst, call_args) = self :: returning:: codegen_with_call_return_arg ( fx, fn_sig, ret_place, |fx, return_ptr| {
484
- let call_args: Vec < Value > = return_ptr
485
- . into_iter ( )
486
- . chain ( first_arg. into_iter ( ) )
487
- . chain (
488
- args. into_iter ( )
489
- . skip ( 1 )
490
- . map ( |arg| adjust_arg_for_abi ( fx, arg) . into_iter ( ) )
491
- . flatten ( ) ,
492
- )
493
- . collect :: < Vec < _ > > ( ) ;
509
+ let ( call_inst, call_args) =
510
+ self :: returning:: codegen_with_call_return_arg ( fx, fn_sig, ret_place, |fx, return_ptr| {
511
+ let call_args: Vec < Value > = return_ptr
512
+ . into_iter ( )
513
+ . chain ( first_arg. into_iter ( ) )
514
+ . chain (
515
+ args. into_iter ( )
516
+ . skip ( 1 )
517
+ . map ( |arg| adjust_arg_for_abi ( fx, arg) . into_iter ( ) )
518
+ . flatten ( ) ,
519
+ )
520
+ . collect :: < Vec < _ > > ( ) ;
494
521
495
- let call_inst = if let Some ( func_ref) = func_ref {
496
- let sig = fx
497
- . bcx
498
- . import_signature ( clif_sig_from_fn_sig ( fx. tcx , fn_sig, is_virtual_call) ) ;
499
- fx. bcx . ins ( ) . call_indirect ( sig, func_ref, & call_args)
500
- } else {
501
- let func_ref = fx. get_function_ref ( instance. expect ( "non-indirect call on non-FnDef type" ) ) ;
502
- fx. bcx . ins ( ) . call ( func_ref, & call_args)
503
- } ;
522
+ let call_inst = if let Some ( func_ref) = func_ref {
523
+ let sig =
524
+ fx. bcx
525
+ . import_signature ( clif_sig_from_fn_sig ( fx. tcx , fn_sig, is_virtual_call) ) ;
526
+ fx. bcx . ins ( ) . call_indirect ( sig, func_ref, & call_args)
527
+ } else {
528
+ let func_ref =
529
+ fx. get_function_ref ( instance. expect ( "non-indirect call on non-FnDef type" ) ) ;
530
+ fx. bcx . ins ( ) . call ( func_ref, & call_args)
531
+ } ;
504
532
505
- ( call_inst, call_args)
506
- } ) ;
533
+ ( call_inst, call_args)
534
+ } ) ;
507
535
508
536
// FIXME find a cleaner way to support varargs
509
537
if fn_sig. c_variadic {
@@ -526,10 +554,7 @@ fn codegen_call_inner<'tcx>(
526
554
}
527
555
}
528
556
529
- pub fn codegen_drop < ' tcx > (
530
- fx : & mut FunctionCx < ' _ , ' tcx , impl Backend > ,
531
- drop_place : CPlace < ' tcx > ,
532
- ) {
557
+ pub fn codegen_drop < ' tcx > ( fx : & mut FunctionCx < ' _ , ' tcx , impl Backend > , drop_place : CPlace < ' tcx > ) {
533
558
let ty = drop_place. layout ( ) . ty ;
534
559
let drop_fn = Instance :: resolve_drop_in_place ( fx. tcx , ty) ;
535
560
@@ -542,7 +567,10 @@ pub fn codegen_drop<'tcx>(
542
567
let ( ptr, vtable) = drop_place. to_addr_maybe_unsized ( fx) ;
543
568
let drop_fn = crate :: vtable:: drop_fn_of_obj ( fx, vtable. unwrap ( ) ) ;
544
569
545
- let fn_sig = fx. tcx . normalize_erasing_late_bound_regions ( ParamEnv :: reveal_all ( ) , & drop_fn_ty. fn_sig ( fx. tcx ) ) ;
570
+ let fn_sig = fx. tcx . normalize_erasing_late_bound_regions (
571
+ ParamEnv :: reveal_all ( ) ,
572
+ & drop_fn_ty. fn_sig ( fx. tcx ) ,
573
+ ) ;
546
574
547
575
assert_eq ! ( fn_sig. output( ) , fx. tcx. mk_unit( ) ) ;
548
576
@@ -564,13 +592,7 @@ pub fn codegen_drop<'tcx>(
564
592
) ;
565
593
drop_place. write_place_ref ( fx, arg_place) ;
566
594
let arg_value = arg_place. to_cvalue ( fx) ;
567
- codegen_call_inner (
568
- fx,
569
- None ,
570
- drop_fn_ty,
571
- vec ! [ arg_value] ,
572
- None ,
573
- ) ;
595
+ codegen_call_inner ( fx, None , drop_fn_ty, vec ! [ arg_value] , None ) ;
574
596
}
575
597
}
576
598
}
0 commit comments