@@ -3,8 +3,9 @@ use std::ptr;
33use rustc_ast:: expand:: autodiff_attrs:: { AutoDiffAttrs , DiffActivity , DiffMode } ;
44use rustc_codegen_ssa:: common:: TypeKind ;
55use rustc_codegen_ssa:: traits:: { BaseTypeCodegenMethods , BuilderMethods } ;
6- use rustc_middle:: ty:: { PseudoCanonicalInput , Ty , TyCtxt , TypingEnv } ;
6+ use rustc_middle:: ty:: { Instance , PseudoCanonicalInput , TyCtxt , TypingEnv } ;
77use rustc_middle:: { bug, ty} ;
8+ use rustc_target:: callconv:: PassMode ;
89use tracing:: debug;
910
1011use crate :: builder:: { Builder , PlaceRef , UNNAMED } ;
@@ -16,9 +17,12 @@ use crate::value::Value;
1617
1718pub ( crate ) fn adjust_activity_to_abi < ' tcx > (
1819 tcx : TyCtxt < ' tcx > ,
19- fn_ty : Ty < ' tcx > ,
20+ instance : Instance < ' tcx > ,
21+ typing_env : TypingEnv < ' tcx > ,
2022 da : & mut Vec < DiffActivity > ,
2123) {
24+ let fn_ty = instance. ty ( tcx, typing_env) ;
25+
2226 if !matches ! ( fn_ty. kind( ) , ty:: FnDef ( ..) ) {
2327 bug ! ( "expected fn def for autodiff, got {:?}" , fn_ty) ;
2428 }
@@ -27,6 +31,13 @@ pub(crate) fn adjust_activity_to_abi<'tcx>(
2731 // All we do is decide how to handle the arguments.
2832 let sig = fn_ty. fn_sig ( tcx) . skip_binder ( ) ;
2933
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+
3041 let mut new_activities = vec ! [ ] ;
3142 let mut new_positions = vec ! [ ] ;
3243 let mut del_activities = 0 ;
@@ -91,10 +102,13 @@ pub(crate) fn adjust_activity_to_abi<'tcx>(
91102 }
92103 } ;
93104
105+ let pass_mode = & fn_abi. args [ i] . mode ;
106+
94107 // For ZST, just ignore and don't add its activity, as this arg won't be present
95108 // 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
96110 // FIXME(Sa4dUs): Enforce ZST corresponding diff activity be `Const`
97- if layout . is_zst ( ) {
111+ if * pass_mode == PassMode :: Ignore {
98112 del_activities += 1 ;
99113 da. remove ( i) ;
100114 }
0 commit comments