1
- use rustc_abi:: HasDataLayout ;
2
1
use rustc_ast:: expand:: autodiff_attrs:: { AutoDiffItem , DiffActivity } ;
3
2
use rustc_hir:: def_id:: LOCAL_CRATE ;
4
3
use rustc_middle:: bug;
@@ -17,7 +16,6 @@ fn adjust_activity_to_abi<'tcx>(tcx: TyCtxt<'tcx>, fn_ty: Ty<'tcx>, da: &mut Vec
17
16
// We don't actually pass the types back into the type system.
18
17
// All we do is decide how to handle the arguments.
19
18
let sig = fn_ty. fn_sig ( tcx) . skip_binder ( ) ;
20
- let pointer_size = tcx. data_layout ( ) . pointer_size ;
21
19
22
20
let mut new_activities = vec ! [ ] ;
23
21
let mut new_positions = vec ! [ ] ;
@@ -82,18 +80,12 @@ fn adjust_activity_to_abi<'tcx>(tcx: TyCtxt<'tcx>, fn_ty: Ty<'tcx>, da: &mut Vec
82
80
}
83
81
} ;
84
82
85
- let is_product = |t : Ty < ' tcx > | matches ! ( t. kind( ) , ty:: Tuple ( _) | ty:: Adt ( _, _) ) ;
86
-
87
- // NOTE: When an ADT (Algebraic Data Type) has fewer than two fields and a total size less than pointer_size * 2,
88
- // LLVM will pass its fields separately instead of as a single aggregate.
89
- if layout. size ( ) <= pointer_size * 2 && is_product ( * ty) {
90
- let n_scalars = count_leaf_fields ( tcx, * ty) ;
91
- if n_scalars <= 2 {
92
- for _ in 0 ..n_scalars. saturating_sub ( 1 ) {
93
- new_activities. push ( da[ i] . clone ( ) ) ;
94
- new_positions. push ( i + 1 ) ;
95
- }
83
+ match layout. backend_repr ( ) {
84
+ rustc_abi:: BackendRepr :: ScalarPair ( _, _) => {
85
+ new_activities. push ( da[ i] . clone ( ) ) ;
86
+ new_positions. push ( i + 1 ) ;
96
87
}
88
+ _ => { }
97
89
}
98
90
}
99
91
// now add the extra activities coming from slices
@@ -105,29 +97,6 @@ fn adjust_activity_to_abi<'tcx>(tcx: TyCtxt<'tcx>, fn_ty: Ty<'tcx>, da: &mut Vec
105
97
}
106
98
}
107
99
108
- fn count_leaf_fields < ' tcx > ( tcx : TyCtxt < ' tcx > , ty : Ty < ' tcx > ) -> usize {
109
- match ty. kind ( ) {
110
- ty:: Bool | ty:: Char | ty:: Int ( _) | ty:: Uint ( _) | ty:: Float ( _) | ty:: FnPtr ( _, _) => 1 ,
111
- ty:: RawPtr ( ty, _) => count_leaf_fields ( tcx, * ty) ,
112
- ty:: Ref ( _, ty, _) => count_leaf_fields ( tcx, * ty) ,
113
- ty:: Array ( ty, len) => {
114
- if let Some ( len) = len. try_to_target_usize ( tcx) {
115
- count_leaf_fields ( tcx, * ty) * len as usize
116
- } else {
117
- 1 // Not sure about how to handle this case
118
- }
119
- }
120
- ty:: Adt ( def, substs) if def. is_struct ( ) => def
121
- . non_enum_variant ( )
122
- . fields
123
- . iter ( )
124
- . map ( |f| count_leaf_fields ( tcx, f. ty ( tcx, substs) ) )
125
- . sum ( ) ,
126
- ty:: Tuple ( substs) => substs. iter ( ) . map ( |t| count_leaf_fields ( tcx, t) ) . sum ( ) ,
127
- _ => 0 ,
128
- }
129
- }
130
-
131
100
pub ( crate ) fn find_autodiff_source_functions < ' tcx > (
132
101
tcx : TyCtxt < ' tcx > ,
133
102
usage_map : & UsageMap < ' tcx > ,
0 commit comments