@@ -71,6 +71,13 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
7171 codegen_fn_attrs. flags |= CodegenFnAttrFlags :: TRACK_CALLER ;
7272 }
7373
74+ // If our rustc version supports autodiff/enzyme, then we call our handler
75+ // to check for any `#[rustc_autodiff(...)]` attributes.
76+ //if cfg!(llvm_enzyme) {
77+ // let ad = autodiff_attrs(tcx, did.into());
78+ // codegen_fn_attrs.autodiff_item = ad;
79+ //}
80+
7481 // When `no_builtins` is applied at the crate level, we should add the
7582 // `no-builtins` attribute to each function to ensure it takes effect in LTO.
7683 let crate_attrs = tcx. hir ( ) . attrs ( rustc_hir:: CRATE_HIR_ID ) ;
@@ -867,7 +874,7 @@ impl<'a> MixedExportNameAndNoMangleState<'a> {
867874/// being differentiated). The other form is #[rustc_autodiff(Mode, ActivityList)] on top of the
868875/// placeholder functions. We wrote the rustc_autodiff attributes ourself, so this should never
869876/// panic, unless we introduced a bug when parsing the autodiff macro.
870- fn autodiff_attrs ( tcx : TyCtxt < ' _ > , id : DefId ) -> AutoDiffAttrs {
877+ fn autodiff_attrs ( tcx : TyCtxt < ' _ > , id : DefId ) -> Option < AutoDiffAttrs > {
871878 let attrs = tcx. get_attrs ( id, sym:: rustc_autodiff) ;
872879
873880 let attrs =
@@ -878,7 +885,7 @@ fn autodiff_attrs(tcx: TyCtxt<'_>, id: DefId) -> AutoDiffAttrs {
878885 // FIXME(ZuseZ4): re-enable this check. Currently we add multiple, which doesn't cause harm but
879886 // looks strange e.g. under cargo-expand.
880887 let attr = match & attrs[ ..] {
881- [ ] => return AutoDiffAttrs :: error ( ) ,
888+ [ ] => return None ,
882889 [ attr] => attr,
883890 // These two attributes are the same and unfortunately duplicated due to a previous bug.
884891 [ attr, _attr2] => attr,
@@ -893,7 +900,7 @@ fn autodiff_attrs(tcx: TyCtxt<'_>, id: DefId) -> AutoDiffAttrs {
893900
894901 // empty autodiff attribute macros (i.e. `#[autodiff]`) are used to mark source functions
895902 if list. is_empty ( ) {
896- return AutoDiffAttrs :: source ( ) ;
903+ return Some ( AutoDiffAttrs :: source ( ) ) ;
897904 }
898905
899906 let [ mode, input_activities @ .., ret_activity] = & list[ ..] else {
@@ -962,10 +969,10 @@ fn autodiff_attrs(tcx: TyCtxt<'_>, id: DefId) -> AutoDiffAttrs {
962969 span_bug ! ( attr. span, "Invalid return activity {} for {} mode" , ret_activity, mode) ;
963970 }
964971
965- AutoDiffAttrs { mode, ret_activity, input_activity : arg_activities }
972+ Some ( AutoDiffAttrs { mode, ret_activity, input_activity : arg_activities } )
966973}
967974
968975pub ( crate ) fn provide ( providers : & mut Providers ) {
969976 * providers =
970- Providers { codegen_fn_attrs, should_inherit_track_caller, autodiff_attrs , ..* providers } ;
977+ Providers { codegen_fn_attrs, should_inherit_track_caller, ..* providers } ;
971978}
0 commit comments