@@ -3,8 +3,9 @@ use std::ptr;
3
3
use rustc_ast:: expand:: autodiff_attrs:: { AutoDiffAttrs , DiffActivity , DiffMode } ;
4
4
use rustc_codegen_ssa:: common:: TypeKind ;
5
5
use rustc_codegen_ssa:: traits:: { BaseTypeCodegenMethods , BuilderMethods } ;
6
- use rustc_middle:: ty:: { PseudoCanonicalInput , Ty , TyCtxt , TypingEnv } ;
6
+ use rustc_middle:: ty:: { Instance , PseudoCanonicalInput , TyCtxt , TypingEnv } ;
7
7
use rustc_middle:: { bug, ty} ;
8
+ use rustc_target:: callconv:: PassMode ;
8
9
use tracing:: debug;
9
10
10
11
use crate :: builder:: { Builder , PlaceRef , UNNAMED } ;
@@ -16,9 +17,12 @@ use crate::value::Value;
16
17
17
18
pub ( crate ) fn adjust_activity_to_abi < ' tcx > (
18
19
tcx : TyCtxt < ' tcx > ,
19
- fn_ty : Ty < ' tcx > ,
20
+ instance : Instance < ' tcx > ,
21
+ typing_env : TypingEnv < ' tcx > ,
20
22
da : & mut Vec < DiffActivity > ,
21
23
) {
24
+ let fn_ty = instance. ty ( tcx, typing_env) ;
25
+
22
26
if !matches ! ( fn_ty. kind( ) , ty:: FnDef ( ..) ) {
23
27
bug ! ( "expected fn def for autodiff, got {:?}" , fn_ty) ;
24
28
}
@@ -27,6 +31,13 @@ pub(crate) fn adjust_activity_to_abi<'tcx>(
27
31
// All we do is decide how to handle the arguments.
28
32
let sig = fn_ty. fn_sig ( tcx) . skip_binder ( ) ;
29
33
34
+ // FIXME(Sa4dUs): pass proper varargs once we have support for differentiating variadic functions
35
+ let Ok ( fn_abi) =
36
+ tcx. fn_abi_of_instance ( typing_env. as_query_input ( ( instance, ty:: List :: empty ( ) ) ) )
37
+ else {
38
+ bug ! ( "failed to get fn_abi of instance with empty varargs" ) ;
39
+ } ;
40
+
30
41
let mut new_activities = vec ! [ ] ;
31
42
let mut new_positions = vec ! [ ] ;
32
43
let mut del_activities = 0 ;
@@ -91,10 +102,13 @@ pub(crate) fn adjust_activity_to_abi<'tcx>(
91
102
}
92
103
} ;
93
104
105
+ let pass_mode = & fn_abi. args [ i] . mode ;
106
+
94
107
// For ZST, just ignore and don't add its activity, as this arg won't be present
95
108
// in the LLVM passed to Enzyme.
109
+ // Some targets pass ZST indirectly in the C ABI, in that case, handle it as a normal arg
96
110
// FIXME(Sa4dUs): Enforce ZST corresponding diff activity be `Const`
97
- if layout . is_zst ( ) {
111
+ if * pass_mode == PassMode :: Ignore {
98
112
del_activities += 1 ;
99
113
da. remove ( i) ;
100
114
}
0 commit comments