@@ -6,7 +6,7 @@ use rustc_target::spec::abi::Abi;
6
6
7
7
use crate :: prelude:: * ;
8
8
9
- #[ derive( Debug ) ]
9
+ #[ derive( Copy , Clone , Debug ) ]
10
10
enum PassMode {
11
11
NoPass ,
12
12
ByVal ( Type ) ,
@@ -306,6 +306,37 @@ fn add_local_header_comment(fx: &mut FunctionCx<impl Backend>) {
306
306
fx. add_global_comment ( format ! ( "msg loc.idx param pass mode ssa flags ty" ) ) ;
307
307
}
308
308
309
+ fn arg_place < ' a , ' tcx : ' a > (
310
+ fx : & mut FunctionCx < ' a , ' tcx , impl Backend > ,
311
+ local : Local ,
312
+ layout : TyLayout < ' tcx > ,
313
+ is_ssa : bool ,
314
+ ) -> CPlace < ' tcx > {
315
+ let place = if is_ssa {
316
+ fx. bcx . declare_var ( mir_var ( local) , fx. clif_type ( layout. ty ) . unwrap ( ) ) ;
317
+ CPlace :: Var ( local, layout)
318
+ } else {
319
+ let stack_slot = fx. bcx . create_stack_slot ( StackSlotData {
320
+ kind : StackSlotKind :: ExplicitSlot ,
321
+ size : layout. size . bytes ( ) as u32 ,
322
+ offset : None ,
323
+ } ) ;
324
+
325
+ CPlace :: from_stack_slot ( fx, stack_slot, layout. ty )
326
+ } ;
327
+
328
+ debug_assert ! ( fx. local_map. insert( local, place) . is_none( ) ) ;
329
+ fx. local_map [ & local]
330
+ }
331
+
332
+ fn param_to_cvalue < ' a , ' tcx : ' a > ( fx : & FunctionCx < ' a , ' tcx , impl Backend > , ebb_param : Value , layout : TyLayout < ' tcx > ) -> CValue < ' tcx > {
333
+ match get_pass_mode ( fx. tcx , fx. self_sig ( ) . abi , layout. ty , false ) {
334
+ PassMode :: NoPass => unimplemented ! ( "pass mode nopass" ) ,
335
+ PassMode :: ByVal ( _) => CValue :: ByVal ( ebb_param, layout) ,
336
+ PassMode :: ByRef => CValue :: ByRef ( ebb_param, layout) ,
337
+ }
338
+ }
339
+
309
340
pub fn codegen_fn_prelude < ' a , ' tcx : ' a > (
310
341
fx : & mut FunctionCx < ' a , ' tcx , impl Backend > ,
311
342
start_ebb : Ebb ,
@@ -344,19 +375,24 @@ pub fn codegen_fn_prelude<'a, 'tcx: 'a>(
344
375
} ;
345
376
346
377
let mut ebb_params = Vec :: new ( ) ;
347
- for arg_ty in tupled_arg_tys. iter ( ) {
348
- let clif_type =
349
- get_pass_mode ( fx. tcx , fx. self_sig ( ) . abi , arg_ty, false ) . get_param_ty ( fx) ;
350
- ebb_params. push ( fx. bcx . append_ebb_param ( start_ebb, clif_type) ) ;
378
+ for ( i, arg_ty) in tupled_arg_tys. iter ( ) . enumerate ( ) {
379
+ let pass_mode = get_pass_mode ( fx. tcx , fx. self_sig ( ) . abi , arg_ty, false ) ; ;
380
+ let clif_type = pass_mode. get_param_ty ( fx) ;
381
+ let ebb_param = fx. bcx . append_ebb_param ( start_ebb, clif_type) ;
382
+ add_local_comment ( fx, "arg" , local, Some ( i) , Some ( ebb_param) , Some ( pass_mode) , ssa_analyzed[ & local] , arg_ty) ;
383
+ ebb_params. push ( ebb_param) ;
351
384
}
352
385
353
386
( local, ArgKind :: Spread ( ebb_params) , arg_ty)
354
387
} else {
355
388
let clif_type =
356
389
get_pass_mode ( fx. tcx , fx. self_sig ( ) . abi , arg_ty, false ) . get_param_ty ( fx) ;
390
+ let ebb_param = fx. bcx . append_ebb_param ( start_ebb, clif_type) ;
391
+ let pass_mode = get_pass_mode ( fx. tcx , fx. self_sig ( ) . abi , arg_ty, false ) ;
392
+ add_local_comment ( fx, "arg" , local, None , Some ( ebb_param) , Some ( pass_mode) , ssa_analyzed[ & local] , arg_ty) ;
357
393
(
358
394
local,
359
- ArgKind :: Normal ( fx . bcx . append_ebb_param ( start_ebb , clif_type ) ) ,
395
+ ArgKind :: Normal ( ebb_param ) ,
360
396
arg_ty,
361
397
)
362
398
}
@@ -370,7 +406,6 @@ pub fn codegen_fn_prelude<'a, 'tcx: 'a>(
370
406
match output_pass_mode {
371
407
PassMode :: NoPass => {
372
408
let null = fx. bcx . ins ( ) . iconst ( fx. pointer_type , 0 ) ;
373
- //unimplemented!("pass mode nopass");
374
409
fx. local_map . insert (
375
410
RETURN_PLACE ,
376
411
CPlace :: Addr ( null, None , fx. layout_of ( fx. return_type ( ) ) ) ,
@@ -395,74 +430,26 @@ pub fn codegen_fn_prelude<'a, 'tcx: 'a>(
395
430
for ( local, arg_kind, ty) in func_params {
396
431
let layout = fx. layout_of ( ty) ;
397
432
433
+ let is_ssa = !ssa_analyzed
434
+ . get ( & local)
435
+ . unwrap ( )
436
+ . contains ( crate :: analyze:: Flags :: NOT_SSA ) ;
437
+
398
438
match arg_kind {
399
439
ArgKind :: Normal ( ebb_param) => {
400
- let pass_mode = get_pass_mode ( fx. tcx , fx . self_sig ( ) . abi , ty , false ) ;
401
- add_local_comment ( fx, "arg" , local, None , Some ( ebb_param ) , Some ( pass_mode ) , ssa_analyzed [ & local ] , ty ) ;
440
+ let cvalue = param_to_cvalue ( fx, ebb_param , layout ) ;
441
+ arg_place ( fx, local, layout , is_ssa ) . write_cvalue ( fx , cvalue ) ;
402
442
}
403
- ArgKind :: Spread ( ref ebb_params) => {
404
- for ( i, & ebb_param) in ebb_params. iter ( ) . enumerate ( ) {
405
- let sub_layout = layout. field ( fx, i) ;
406
- let pass_mode = get_pass_mode ( fx. tcx , fx. self_sig ( ) . abi , sub_layout. ty , false ) ;
407
- add_local_comment ( fx, "arg" , local, Some ( i) , Some ( ebb_param) , Some ( pass_mode) , ssa_analyzed[ & local] , sub_layout. ty ) ;
408
- }
409
- }
410
- }
411
-
412
- if let ArgKind :: Normal ( ebb_param) = arg_kind {
413
- if !ssa_analyzed
414
- . get ( & local)
415
- . unwrap ( )
416
- . contains ( crate :: analyze:: Flags :: NOT_SSA )
417
- {
418
- fx. bcx
419
- . declare_var ( mir_var ( local) , fx. clif_type ( ty) . unwrap ( ) ) ;
420
- match get_pass_mode ( fx. tcx , fx. self_sig ( ) . abi , ty, false ) {
421
- PassMode :: NoPass => unimplemented ! ( "pass mode nopass" ) ,
422
- PassMode :: ByVal ( _) => fx. bcx . def_var ( mir_var ( local) , ebb_param) ,
423
- PassMode :: ByRef => {
424
- let val = CValue :: ByRef ( ebb_param, fx. layout_of ( ty) ) . load_value ( fx) ;
425
- fx. bcx . def_var ( mir_var ( local) , val) ;
426
- }
427
- }
428
- fx. local_map . insert ( local, CPlace :: Var ( local, layout) ) ;
429
- continue ;
430
- }
431
- }
432
-
433
- let stack_slot = fx. bcx . create_stack_slot ( StackSlotData {
434
- kind : StackSlotKind :: ExplicitSlot ,
435
- size : layout. size . bytes ( ) as u32 ,
436
- offset : None ,
437
- } ) ;
438
-
439
- let place = CPlace :: from_stack_slot ( fx, stack_slot, ty) ;
440
-
441
- match arg_kind {
442
- ArgKind :: Normal ( ebb_param) => match get_pass_mode ( fx. tcx , fx. self_sig ( ) . abi , ty, false )
443
- {
444
- PassMode :: NoPass => unimplemented ! ( "pass mode nopass" ) ,
445
- PassMode :: ByVal ( _) => {
446
- place. write_cvalue ( fx, CValue :: ByVal ( ebb_param, place. layout ( ) ) )
447
- }
448
- PassMode :: ByRef => place. write_cvalue ( fx, CValue :: ByRef ( ebb_param, place. layout ( ) ) ) ,
449
- } ,
450
443
ArgKind :: Spread ( ebb_params) => {
444
+ let place = arg_place ( fx, local, layout, is_ssa) ;
445
+
451
446
for ( i, ebb_param) in ebb_params. into_iter ( ) . enumerate ( ) {
452
447
let sub_place = place. place_field ( fx, mir:: Field :: new ( i) ) ;
453
- match get_pass_mode ( fx. tcx , fx. self_sig ( ) . abi , sub_place. layout ( ) . ty , false ) {
454
- PassMode :: NoPass => unimplemented ! ( "pass mode nopass" ) ,
455
- PassMode :: ByVal ( _) => {
456
- sub_place. write_cvalue ( fx, CValue :: ByVal ( ebb_param, sub_place. layout ( ) ) )
457
- }
458
- PassMode :: ByRef => {
459
- sub_place. write_cvalue ( fx, CValue :: ByRef ( ebb_param, sub_place. layout ( ) ) )
460
- }
461
- }
448
+ let cvalue = param_to_cvalue ( fx, ebb_param, sub_place. layout ( ) ) ;
449
+ sub_place. write_cvalue ( fx, cvalue) ;
462
450
}
463
451
}
464
452
}
465
- fx. local_map . insert ( local, place) ;
466
453
}
467
454
468
455
for local in fx. mir . vars_and_temps_iter ( ) {
0 commit comments