@@ -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 ;
@@ -1138,6 +1140,14 @@ fn codegen_enzyme_autodiff<'ll, 'tcx>(
1138
1140
args : & [ OperandRef < ' tcx , & ' ll Value > ] ,
1139
1141
result : PlaceRef < ' tcx , & ' ll Value > ,
1140
1142
) {
1143
+ if !tcx. sess . opts . unstable_opts . autodiff . contains ( & rustc_session:: config:: AutoDiff :: Enable ) {
1144
+ let _ = tcx. dcx ( ) . emit_almost_fatal ( AutoDiffWithoutEnable ) ;
1145
+ }
1146
+
1147
+ if tcx. sess . lto ( ) != Lto :: Fat {
1148
+ let _ = tcx. dcx ( ) . emit_almost_fatal ( AutoDiffWithoutLTO ) ;
1149
+ }
1150
+
1141
1151
let fn_args = instance. args ;
1142
1152
let callee_ty = instance. ty ( tcx, bx. typing_env ( ) ) ;
1143
1153
0 commit comments