@@ -15,6 +15,7 @@ use rustc_middle::mir::BinOp;
15
15
use rustc_middle:: ty:: layout:: { FnAbiOf , HasTyCtxt , HasTypingEnv , LayoutOf } ;
16
16
use rustc_middle:: ty:: { self , GenericArgsRef , Instance , Ty , TyCtxt , TypingEnv } ;
17
17
use rustc_middle:: { bug, span_bug} ;
18
+ use rustc_session:: config:: Lto ;
18
19
use rustc_span:: { Span , Symbol , sym} ;
19
20
use rustc_symbol_mangling:: { mangle_internal_symbol, symbol_name_for_instance_in_crate} ;
20
21
use rustc_target:: callconv:: PassMode ;
@@ -25,6 +26,7 @@ use crate::abi::FnAbiLlvmExt;
25
26
use crate :: builder:: Builder ;
26
27
use crate :: builder:: autodiff:: { adjust_activity_to_abi, generate_enzyme_call} ;
27
28
use crate :: context:: CodegenCx ;
29
+ use crate :: errors:: { AutoDiffWithoutEnable , AutoDiffWithoutLTO } ;
28
30
use crate :: llvm:: { self , Metadata } ;
29
31
use crate :: type_:: Type ;
30
32
use crate :: type_of:: LayoutLlvmExt ;
@@ -1136,6 +1138,14 @@ fn codegen_enzyme_autodiff<'ll, 'tcx>(
1136
1138
args : & [ OperandRef < ' tcx , & ' ll Value > ] ,
1137
1139
result : PlaceRef < ' tcx , & ' ll Value > ,
1138
1140
) {
1141
+ if !tcx. sess . opts . unstable_opts . autodiff . contains ( & rustc_session:: config:: AutoDiff :: Enable ) {
1142
+ let _ = tcx. dcx ( ) . emit_almost_fatal ( AutoDiffWithoutEnable ) ;
1143
+ }
1144
+
1145
+ if tcx. sess . lto ( ) != Lto :: Fat {
1146
+ let _ = tcx. dcx ( ) . emit_almost_fatal ( AutoDiffWithoutLTO ) ;
1147
+ }
1148
+
1139
1149
let fn_args = instance. args ;
1140
1150
let callee_ty = instance. ty ( tcx, bx. typing_env ( ) ) ;
1141
1151
0 commit comments