diff --git a/enzyme/Enzyme/ActivityAnalysis.cpp b/enzyme/Enzyme/ActivityAnalysis.cpp index 4e3ffac63bb8..7db1b544198c 100644 --- a/enzyme/Enzyme/ActivityAnalysis.cpp +++ b/enzyme/Enzyme/ActivityAnalysis.cpp @@ -1536,6 +1536,7 @@ bool ActivityAnalyzer::isConstantValue(TypeResults const &TR, Value *Val) { if (directions & DOWN && (funcName == "malloc" || funcName == "calloc" || funcName == "_Znwm" || funcName == "julia.gc_alloc_obj" || + funcName == "??2@YAPAXI@Z" || funcName == "??2@YAPEAX_K@Z" || funcName == "jl_gc_alloc_typed" || funcName == "ijl_gc_alloc_typed")) { std::shared_ptr Hypothesis = diff --git a/enzyme/Enzyme/AdjointGenerator.h b/enzyme/Enzyme/AdjointGenerator.h index 998efb80675c..17d55a02e416 100644 --- a/enzyme/Enzyme/AdjointGenerator.h +++ b/enzyme/Enzyme/AdjointGenerator.h @@ -8813,7 +8813,9 @@ class AdjointGenerator Attribute::NonNull); #endif - if (funcName == "malloc" || funcName == "_Znwm") { + if (funcName == "malloc" || funcName == "_Znwm" || + funcName == "??2@YAPAXI@Z" || + funcName == "??2@YAPEAX_K@Z") { if (auto ci = dyn_cast(args[0])) { unsigned derefBytes = ci->getLimitedValue(); CallInst *cal = diff --git a/enzyme/Enzyme/CMakeLists.txt b/enzyme/Enzyme/CMakeLists.txt index 7260b1b7c5ca..fc5be885ba6d 100644 --- a/enzyme/Enzyme/CMakeLists.txt +++ b/enzyme/Enzyme/CMakeLists.txt @@ -98,7 +98,7 @@ if (${Clang_FOUND}) DEPENDS intrinsics_gen PLUGIN_TOOL - opt + clang ) target_compile_definitions(ClangEnzyme-${LLVM_VERSION_MAJOR} PUBLIC ENZYME_RUNPASS) endif() diff --git a/enzyme/Enzyme/GradientUtils.cpp b/enzyme/Enzyme/GradientUtils.cpp index b2f936cb09d5..aa49ff7f2984 100644 --- a/enzyme/Enzyme/GradientUtils.cpp +++ b/enzyme/Enzyme/GradientUtils.cpp @@ -4383,10 +4383,14 @@ Constant *GradientUtils::GetOrCreateShadowConstant( NewOps.push_back(i == 0 ? C : arg->getOperand(i)); return arg->getWithOperands(NewOps); } + } else if (auto arg = dyn_cast(oval)) { + return GetOrCreateShadowConstant(Logic, TLI, TA, arg->getAliasee(), mode, + width, AtomicAdd); } else if (auto arg = dyn_cast(oval)) { if (arg->getName() == "_ZTVN10__cxxabiv120__si_class_type_infoE" || arg->getName() == "_ZTVN10__cxxabiv117__class_type_infoE" || - arg->getName() == "_ZTVN10__cxxabiv121__vmi_class_type_infoE") + arg->getName() == "_ZTVN10__cxxabiv121__vmi_class_type_infoE" || + arg->getName().startswith("??_R")) // any of the MS RTTI manglings return arg; if (hasMetadata(arg, "enzyme_shadow")) { @@ -8979,15 +8983,21 @@ llvm::CallInst *freeKnownAllocation(llvm::IRBuilder<> &builder, freefunc = LibFunc_ZdaPv; break; + case LibFunc_msvc_new_longlong: // new(unsigned long long); + case LibFunc_msvc_new_longlong_nothrow: // new(unsigned long long, nothrow); + freefunc = LibFunc_msvc_delete_ptr64_longlong; + break; + + case LibFunc_msvc_new_array_longlong: // new[](unsigned long long); + case LibFunc_msvc_new_array_longlong_nothrow: // new[](unsigned long long, + // nothrow); + freefunc = LibFunc_msvc_delete_array_ptr64_longlong; + break; + case LibFunc_msvc_new_int: // new(unsigned int); case LibFunc_msvc_new_int_nothrow: // new(unsigned int, nothrow); - case LibFunc_msvc_new_longlong: // new(unsigned long long); - case LibFunc_msvc_new_longlong_nothrow: // new(unsigned long long, nothrow); case LibFunc_msvc_new_array_int: // new[](unsigned int); case LibFunc_msvc_new_array_int_nothrow: // new[](unsigned int, nothrow); - case LibFunc_msvc_new_array_longlong: // new[](unsigned long long); - case LibFunc_msvc_new_array_longlong_nothrow: // new[](unsigned long long, - // nothrow); llvm_unreachable("msvc deletion not handled"); default: diff --git a/enzyme/test/Integration/ForwardMode/fwdandrev.cpp b/enzyme/test/Integration/ForwardMode/fwdandrev.cpp index 6218d868ad20..997b08d80a67 100644 --- a/enzyme/test/Integration/ForwardMode/fwdandrev.cpp +++ b/enzyme/test/Integration/ForwardMode/fwdandrev.cpp @@ -8,6 +8,7 @@ // RUN: %clang++ -std=c++14 -fno-exceptions -O3 %s -S -emit-llvm -o - | %opt - %OPloadEnzyme %enzyme -enzyme-inline=1 -S | %lli - #include +#include "test_utils.h" template struct tensor; @@ -28,10 +29,6 @@ struct tensor { tensor value[first]; }; -int enzyme_dup; -int enzyme_out; -int enzyme_const; - template return_type __enzyme_autodiff(Args...); diff --git a/enzyme/test/Integration/ForwardMode/nofn.cpp b/enzyme/test/Integration/ForwardMode/nofn.cpp index 293415969451..8092bb5f5446 100644 --- a/enzyme/test/Integration/ForwardMode/nofn.cpp +++ b/enzyme/test/Integration/ForwardMode/nofn.cpp @@ -4,10 +4,6 @@ #include -int enzyme_dup; -int enzyme_out; -int enzyme_const; - template < typename return_type, typename ... T > extern return_type __enzyme_fwddiff(void*, T ... ); diff --git a/enzyme/test/Integration/ForwardMode/rosenbrock.cpp b/enzyme/test/Integration/ForwardMode/rosenbrock.cpp index fd02a29a67cd..434ae89af89d 100644 --- a/enzyme/test/Integration/ForwardMode/rosenbrock.cpp +++ b/enzyme/test/Integration/ForwardMode/rosenbrock.cpp @@ -11,10 +11,6 @@ #include #include -int enzyme_dup; -int enzyme_out; -int enzyme_const; - using std::vector; template T rosenbrock2(const vector &control) { diff --git a/enzyme/test/Integration/ForwardMode/rwrloop.c b/enzyme/test/Integration/ForwardMode/rwrloop.c index ddf43f9b9498..d1b0a1a10b4b 100644 --- a/enzyme/test/Integration/ForwardMode/rwrloop.c +++ b/enzyme/test/Integration/ForwardMode/rwrloop.c @@ -13,7 +13,6 @@ #include "test_utils.h" -int enzyme_const, enzyme_dup; double __enzyme_fwddiff(void*, ...); double alldiv(double* __restrict__ a, int *__restrict__ N) { diff --git a/enzyme/test/Integration/ForwardMode/test_utils.h b/enzyme/test/Integration/ForwardMode/test_utils.h index aa95132f7950..afcf87d4471b 100644 --- a/enzyme/test/Integration/ForwardMode/test_utils.h +++ b/enzyme/test/Integration/ForwardMode/test_utils.h @@ -3,6 +3,13 @@ #include #include +extern +#ifdef __cplusplus +"C" +#endif +int enzyme_allocated, enzyme_const, enzyme_dup, enzyme_dupnoneed, enzyme_out, + enzyme_tape; + /* #ifdef __cplusplus extern "C" { diff --git a/enzyme/test/Integration/ReverseMode/MSinput.ll b/enzyme/test/Integration/ReverseMode/MSinput.ll new file mode 100644 index 000000000000..93b297d21c1d --- /dev/null +++ b/enzyme/test/Integration/ReverseMode/MSinput.ll @@ -0,0 +1,180 @@ +; RUN: if [ %llvmver -ge 15 ]; then %opt < %s %newLoadEnzyme -enzyme -S | FileCheck %s; fi + +%rtti.CompleteObjectLocator = type { i32, i32, i32, i32, i32, i32 } +%rtti.TypeDescriptor13 = type { ptr, ptr, [14 x i8] } +%rtti.ClassHierarchyDescriptor = type { i32, i32, i32, i32 } +%rtti.BaseClassDescriptor = type { i32, i32, i32, i32, i32, i32, i32 } +%rtti.TypeDescriptor12 = type { ptr, ptr, [13 x i8] } +%struct.Object = type { ptr, double } + +$"?eval@Object1@@UEAANN@Z" = comdat any + +$"??_7Object1@@6B@" = comdat largest + +$"??_R4Object1@@6B@" = comdat any + +$"??_R0?AUObject1@@@8" = comdat any + +$"??_R3Object1@@8" = comdat any + +$"??_R2Object1@@8" = comdat any + +$"??_R1A@?0A@EA@Object1@@8" = comdat any + +$"??_R1A@?0A@EA@Object@@8" = comdat any + +$"??_R0?AUObject@@@8" = comdat any + +$"??_R3Object@@8" = comdat any + +$"??_R2Object@@8" = comdat any + +$"??_7Object@@6B@" = comdat largest + +$"??_R4Object@@6B@" = comdat any + +@0 = private unnamed_addr constant { [2 x ptr] } { [2 x ptr] [ptr @"??_7Object1@@6B@", ptr @"?eval@Object1@@UEAANN@Z"] }, comdat($"??_7Object1@@6B@") +@"??_R4Object1@@6B@" = linkonce_odr constant %rtti.CompleteObjectLocator { i32 1, i32 0, i32 0, i32 trunc (i64 sub nuw nsw (i64 ptrtoint (ptr @"??_R0?AUObject1@@@8" to i64), i64 ptrtoint (ptr @__ImageBase to i64)) to i32), i32 trunc (i64 sub nuw nsw (i64 ptrtoint (ptr @"??_R3Object1@@8" to i64), i64 ptrtoint (ptr @__ImageBase to i64)) to i32), i32 trunc (i64 sub nuw nsw (i64 ptrtoint (ptr @"??_R4Object1@@6B@" to i64), i64 ptrtoint (ptr @__ImageBase to i64)) to i32) }, comdat +@"??_7type_info@@6B@" = external constant ptr +@"??_R0?AUObject1@@@8" = linkonce_odr global %rtti.TypeDescriptor13 { ptr @"??_7type_info@@6B@", ptr null, [14 x i8] c".?AUObject1@@\00" }, comdat +@__ImageBase = external dso_local constant i8 +@"??_R3Object1@@8" = linkonce_odr constant %rtti.ClassHierarchyDescriptor { i32 0, i32 0, i32 2, i32 trunc (i64 sub nuw nsw (i64 ptrtoint (ptr @"??_R2Object1@@8" to i64), i64 ptrtoint (ptr @__ImageBase to i64)) to i32) }, comdat +@"??_R2Object1@@8" = linkonce_odr constant [3 x i32] [i32 trunc (i64 sub nuw nsw (i64 ptrtoint (ptr @"??_R1A@?0A@EA@Object1@@8" to i64), i64 ptrtoint (ptr @__ImageBase to i64)) to i32), i32 trunc (i64 sub nuw nsw (i64 ptrtoint (ptr @"??_R1A@?0A@EA@Object@@8" to i64), i64 ptrtoint (ptr @__ImageBase to i64)) to i32), i32 0], comdat +@"??_R1A@?0A@EA@Object1@@8" = linkonce_odr constant %rtti.BaseClassDescriptor { i32 trunc (i64 sub nuw nsw (i64 ptrtoint (ptr @"??_R0?AUObject1@@@8" to i64), i64 ptrtoint (ptr @__ImageBase to i64)) to i32), i32 1, i32 0, i32 -1, i32 0, i32 64, i32 trunc (i64 sub nuw nsw (i64 ptrtoint (ptr @"??_R3Object1@@8" to i64), i64 ptrtoint (ptr @__ImageBase to i64)) to i32) }, comdat +@"??_R1A@?0A@EA@Object@@8" = linkonce_odr constant %rtti.BaseClassDescriptor { i32 trunc (i64 sub nuw nsw (i64 ptrtoint (ptr @"??_R0?AUObject@@@8" to i64), i64 ptrtoint (ptr @__ImageBase to i64)) to i32), i32 0, i32 0, i32 -1, i32 0, i32 64, i32 trunc (i64 sub nuw nsw (i64 ptrtoint (ptr @"??_R3Object@@8" to i64), i64 ptrtoint (ptr @__ImageBase to i64)) to i32) }, comdat +@"??_R0?AUObject@@@8" = linkonce_odr constant %rtti.TypeDescriptor12 { ptr @"??_7type_info@@6B@", ptr null, [13 x i8] c".?AUObject@@\00" }, comdat +@"??_R3Object@@8" = linkonce_odr constant %rtti.ClassHierarchyDescriptor { i32 0, i32 0, i32 1, i32 trunc (i64 sub nuw nsw (i64 ptrtoint (ptr @"??_R2Object@@8" to i64), i64 ptrtoint (ptr @__ImageBase to i64)) to i32)}, comdat +@"??_R2Object@@8" = linkonce_odr constant [2 x i32] [i32 trunc (i64 sub nuw nsw (i64 ptrtoint (ptr @"??_R1A@?0A@EA@Object@@8" to i64), i64 ptrtoint (ptr @__ImageBase to i64)) to i32), i32 0], comdat +@1 = private unnamed_addr constant { [2 x ptr] } { [2 x ptr] [ptr @"??_R4Object@@6B@", ptr @_purecall] }, comdat($"??_7Object@@6B@") +@"??_R4Object@@6B@" = linkonce_odr constant %rtti.CompleteObjectLocator { i32 1, i32 0, i32 0, i32 trunc (i64 sub nuw nsw (i64 ptrtoint (ptr @"??_R0?AUObject@@@8" to i64), i64 ptrtoint (ptr @__ImageBase to i64)) to i32), i32 trunc (i64 sub nuw nsw (i64 ptrtoint (ptr @"??_R3Object@@8" to i64), i64 ptrtoint( ptr @__ImageBase to i64)) to i32), i32 trunc (i64 sub nuw nsw (i64 ptrtoint (ptr @"??_R4Object@@6B@" to i64), i64 ptrtoint (ptr @__ImageBase to i64)) to i32) }, comdat + +@"??_7Object1@@6B@" = unnamed_addr alias ptr, getelementptr inbounds ({ [2 x ptr] }, ptr @0, i32 0, i32 0, i32 1) +@"??_7Object@@6B@" = unnamed_addr alias ptr, getelementptr inbounds ({ [2 x ptr] }, ptr @1, i32 0, i32 0, i32 1) + +; Function Attrs: mustprogress nounwind uwtable +define dso_local noundef double @"?new_delete_test@@YANPEAN_K@Z"(ptr nocapture noundef readonly %x, i64 noundef %n) #0 { +entry: + %0 = tail call {i64, i1} @llvm.umul.with.overflow.i64(i64 %n, i64 8) + %1 = extractvalue { i64, i1 } %0, 1 + %2 = extractvalue { i64, i1 } %0, 0 + %3 = select i1 %1, i64 -1, i64 %2 + %call = tail call noalias noundef nonnull ptr @"??_U@YAPEAX_K@Z"(i64 noundef %3) #6 + br label %do.body + +do.body: ; preds = %do.body, %entry + %indvars.iv = phi i64 [ %indvars.iv.next, %do.body ], [ 0, %entry ] + %call1 = tail call noalias noundef nonnull dereferenceable(8) ptr @"??2@YAPEAX_K@Z"(i64 noundef 8) #6 + %arrayidx = getelementptr inbounds ptr, ptr %call, i64 %indvars.iv + store ptr %call1, ptr %arrayidx, align 8, !tbaa !5 + %arrayidx3 = getelementptr inbounds double, ptr %x, i64 %indvars.iv + %4 = load double, ptr %arrayidx3, align 8, !tbaa !9 + %mul = fmul double %4, %4 + store double %mul, ptr %arrayidx3, align 8, !tbaa !9 + %indvars.iv.next = add nuw i64 %indvars.iv, 1 + %cmp = icmp ult i64 %indvars.iv.next, %n + br i1 %cmp, label %do.body, label %do.body8.preheader, !llvm.loop !11 + +do.body8.preheader: ; preds = %do.body + %sext = shl i64 %indvars.iv.next, 32 + %5 = ashr exact i64 %sext, 32 + br label %do.body8 + +do.body8: ; preds = %do.body8.preheader, %do.body8 + %indvars.iv38 = phi i64 [ %5, %do.body8.preheader ], [ %indvars.iv.next39, %do.body8 ] + %res.0 = phi double [ 0.000000e+00, %do.body8.preheader ], [ %add, %do.body8 ] + %arrayidx10 = getelementptr inbounds ptr, ptr %call, i64 %indvars.iv38 + %6 = load ptr, ptr %arrayidx10, align 8, !tbaa !5 + %7 = load double, ptr %6, align 8, !tbaa !9 + %add = fadd double %res.0, %7 + tail call void @"??3@YAXPEAX@Z"(ptr noundef %6) #7 + %indvars.iv.next39 = add i64 %indvars.iv38, 1 + %cmp16 = icmp ult i64 %indvars.iv.next39, %n + br i1 %cmp16, label %do.body8, label %delete.notnull19, !llvm.loop !14 + +delete.notnull19: + tail call void @"??_V@YAXPEAX@Z"(ptr noundef nonnull %call) #7 + ret double %add +} + +; Function Attrs: mustprogress nocallback nofree nosync nounwind readnone speculatable willreturn +declare { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64) #1 + +; Function Attrs: nobuiltin allocsize(0) +declare dso_local noundef nonnull ptr @"??_U@YAPEAX_K@Z"(i64 noundef) local_unnamed_addr #2 + +; Function Attrs: nobuiltin allocsize(0) +declare dso_local noundef nonnull ptr @"??2@YAPEAX_K@Z"(i64 noundef) local_unnamed_addr #2 + +; Function Attrs: nobuiltin nounwind +declare dso_local void @"??3@YAXPEAX@Z"(ptr noundef ) local_unnamed_addr #3 + +; Function Attrs: nobuiltin nounwind +declare dso_local void @"??_V@YAXPEAX@Z"(ptr noundef ) local_unnamed_addr #3 + +; Function Attrs: mustprogress nounwind uwtable +define dso_local void @"?new_delete_test_b@@YEAXPEAN0_K@Z"(ptr noundef %x, ptr noundef %x_b, i64 noundef %n) local_unnamed_addr #0 { +entry: + tail call void @"??$__enzyme_autodiff@XPEANPEAN_K@@YAXPEAXPEAN1_K@Z"(ptr noundef nonnull@"?new_delete_test@@YANPEAN_K@Z", ptr noundef %x, ptr noundef %x_b, i64 noundef %n) #8 + ret void +} + +declare dso_local void @"??$__enzyme_autodiff@XPEANPEAN_K@@YAXPEAXPEAN1_K@Z"(ptr noundef, ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #4 + +; Function Attrs: mustprogress nounwind uwtable +define dso_local noundef double @"?eval@@YANAEAUObject@@N@Z"(ptr noundef nonnull align 8 dereferenceable(16) %o, double noundef %v) local_unnamed_addr #0 { +entry: + %vtable = load ptr, ptr %o, align 8, !tbaa !15 + %0 = load ptr, ptr %vtable, align 8 + %call = tail call noundef double %0(ptr noundef nonnull align 8 dereferenceable(16) %o, double noundef %v) #8 + ret double %call +} + +; Function Attrs: nounwind uwtable +define dso_local void @"?aliased_rtti_test@@YAXN@Z"(double noundef %v) local_unnamed_addr #5 { +entry: + %call4 = tail call noundef ptr @"??$__enzyme_virtualreverse@PEAX@@YAPEAXPEAX@Z"(ptr noundef nonnull @"??_7Object1@@6B@") #8 + ret void +} + +declare dso_local noundef ptr @"??$__enzyme_virtualreverse@PEAX@@YAPEAXPEAX@Z"(ptr noundef) local_unnamed_addr #4 + +; Function Attrs: mustprogress nounwind uwtable +define linkonce_odr dso_local noundef double @"?eval@Object1@@UEAANN@Z"(ptr noundef nonnull align 8 dereferenceable(16) %this, double noundef %v) unnamed_addr #0 comdat align 2 { +entry: + %val = getelementptr inbounds %struct.Object, ptr %this, i64 0, i32 1 + %0 = load double, ptr %val, align 8, !tbaa !17 + %mul = fmul double %0, %v + ret double %mul +} + +declare dso_local void @_purecall() unnamed_addr + +attributes #0 = { mustprogress nounwind uwtable "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } +attributes #1 = { mustprogress nocallback nofree nosync nounwind readnone speculatable willreturn } +attributes #2 = { nobuiltin allocsize(0) "frame-pointer"="none" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } +attributes #3 = { nobuiltin nounwind "frame-pointer"="none" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } +attributes #4 = { "frame-pointer"="none" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } +attributes #5 = { nounwind uwtable "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } +attributes #6 = { builtin nounwind allocsize(0) } +attributes #7 = { builtin nounwind } +attributes #8 = { nounwind } + + +!5 = !{!6, !6, i64 0} +!6 = !{!"any pointer", !7, i64 0} +!7 = !{!"omnipotent char", !8, i64 0} +!8 = !{!"Simple C++ TBAA"} +!9 = !{!10, !10, i64 0} +!10 = !{!"double", !7, i64 0} +!11 = distinct !{!11, !12, !13} +!12 = !{!"llvm.loop.mustprogress"} +!13 = !{!"llvm.loop.unroll.disable"} +!14 = distinct !{!14, !12, !13} +!15 = !{!16, !16, i64 0} +!16 = !{!"vtable pointer", !8, i64 0} +!17 = !{!18, !10, i64 8} +!18 = !{!"?AUObject@@", !10, i64 8} + +; CHECK: %rtti.CompleteObjectLocator = type { i32, i32, i32, i32, i32, i32 } +; CHECK: define internal void @"diffe?new_delete_test@@YANPEAN_K@Z" +; CHECK: define internal { double } @"diffe?eval@Object1@@UEAANN@Z" diff --git a/enzyme/test/Integration/ReverseMode/allocatedtape.c b/enzyme/test/Integration/ReverseMode/allocatedtape.c index b29ba9a7dd6c..0fd02521e0dd 100644 --- a/enzyme/test/Integration/ReverseMode/allocatedtape.c +++ b/enzyme/test/Integration/ReverseMode/allocatedtape.c @@ -19,7 +19,6 @@ #include "test_utils.h" -extern int enzyme_dup, enzyme_allocated, enzyme_tape; void __enzyme_autodiff(void*, ...); void* __enzyme_augmentfwd(void*, ...); void __enzyme_reverse(void*, ...); diff --git a/enzyme/test/Integration/ReverseMode/allocatedtape_err.c b/enzyme/test/Integration/ReverseMode/allocatedtape_err.c index ecd030fd00a8..f3ee53a65d09 100644 --- a/enzyme/test/Integration/ReverseMode/allocatedtape_err.c +++ b/enzyme/test/Integration/ReverseMode/allocatedtape_err.c @@ -8,8 +8,8 @@ // RUN: if [ %llvmver -ge 12 ]; then %clang -std=c11 -g -O3 %s -S -emit-llvm -o - %newLoadClangEnzyme -Xclang -verify; fi #include +#include "test_utils.h" -extern int enzyme_allocated, enzyme_tape; void __enzyme_reverse(void*, ...); void f(double* x) { diff --git a/enzyme/test/Integration/ReverseMode/cmplx.cpp b/enzyme/test/Integration/ReverseMode/cmplx.cpp index d318088eaf62..5970d4cf94ae 100644 --- a/enzyme/test/Integration/ReverseMode/cmplx.cpp +++ b/enzyme/test/Integration/ReverseMode/cmplx.cpp @@ -17,10 +17,6 @@ #include #include // std::complex, std::abs, std::arg -int enzyme_dup; -int enzyme_out; -int enzyme_const; - void __enzyme_autodiff(...); using namespace std; @@ -62,4 +58,4 @@ int main () APPROX_EQ(imag(dc), 8.0, 1e-7); return 0; -} \ No newline at end of file +} diff --git a/enzyme/test/Integration/ReverseMode/map.cpp b/enzyme/test/Integration/ReverseMode/map.cpp index 5a90f7b745e0..36357c293860 100644 --- a/enzyme/test/Integration/ReverseMode/map.cpp +++ b/enzyme/test/Integration/ReverseMode/map.cpp @@ -15,8 +15,6 @@ #include #include -int enzyme_dup; - using dictSU = std::unordered_map; using dictCU = std::unordered_map; diff --git a/enzyme/test/Integration/ReverseMode/metarwr.c b/enzyme/test/Integration/ReverseMode/metarwr.c index d1d447cfeb97..923a710dd6b8 100644 --- a/enzyme/test/Integration/ReverseMode/metarwr.c +++ b/enzyme/test/Integration/ReverseMode/metarwr.c @@ -29,8 +29,6 @@ void alldiv(double* __restrict__ a, long** meta) { a[0] = 0; } -int enzyme_dup, enzyme_const; - int main(int argc, char** argv) { long meta[2] = { 198, 200 }; diff --git a/enzyme/test/Integration/ReverseMode/omp3.c b/enzyme/test/Integration/ReverseMode/omp3.c index bba86fe46b17..d6431f3e3953 100644 --- a/enzyme/test/Integration/ReverseMode/omp3.c +++ b/enzyme/test/Integration/ReverseMode/omp3.c @@ -11,7 +11,7 @@ # include # include - +#include "test_utils.h" void msg(double* in, int *len, unsigned int slen) { if (slen != 0) { @@ -28,8 +28,6 @@ void msg(double* in, int *len, unsigned int slen) { } } -int enzyme_dup, enzyme_const; - void __enzyme_autodiff(void*, ...); int main ( int argc, char *argv[] ) { diff --git a/enzyme/test/Integration/ReverseMode/perturbation.cpp b/enzyme/test/Integration/ReverseMode/perturbation.cpp index 0286966d2b34..34639d614499 100644 --- a/enzyme/test/Integration/ReverseMode/perturbation.cpp +++ b/enzyme/test/Integration/ReverseMode/perturbation.cpp @@ -18,8 +18,6 @@ static double f(double x, double y) { return x * y; } -extern int enzyme_const; - static double df(double x) { return x * __enzyme_autodiff1((void*)f, enzyme_const, x, 3.0); } diff --git a/enzyme/test/Integration/ReverseMode/remat.c b/enzyme/test/Integration/ReverseMode/remat.c index 3c01ed6238c2..aec85a951f9b 100644 --- a/enzyme/test/Integration/ReverseMode/remat.c +++ b/enzyme/test/Integration/ReverseMode/remat.c @@ -30,7 +30,7 @@ void square(double** p_delv, double** p_e, int ** idx, int numReg, int numElemRe free(tmp); } } -int enzyme_dup, enzyme_const; + int main() { int numReg = 100; double *delv = (double*)malloc(sizeof(double)*numReg); diff --git a/enzyme/test/Integration/ReverseMode/rwrloop.c b/enzyme/test/Integration/ReverseMode/rwrloop.c index 747e2b9aaa26..547d990a04c4 100644 --- a/enzyme/test/Integration/ReverseMode/rwrloop.c +++ b/enzyme/test/Integration/ReverseMode/rwrloop.c @@ -28,8 +28,6 @@ double alldiv(double* __restrict__ a, int *__restrict__ N) { return sum; } -int enzyme_dup, enzyme_const; - int main(int argc, char** argv) { int N = 10; diff --git a/enzyme/test/Integration/ReverseMode/test_utils.h b/enzyme/test/Integration/ReverseMode/test_utils.h index 99a659248460..8d15bfe10719 100644 --- a/enzyme/test/Integration/ReverseMode/test_utils.h +++ b/enzyme/test/Integration/ReverseMode/test_utils.h @@ -3,6 +3,13 @@ #include #include +extern +#ifdef __cplusplus +"C" +#endif +int enzyme_allocated, enzyme_const, enzyme_dup, enzyme_dupnoneed, enzyme_out, + enzyme_tape; + /* #ifdef __cplusplus extern "C" { diff --git a/enzyme/test/Integration/ReverseMode/virtualshadow3.cpp b/enzyme/test/Integration/ReverseMode/virtualshadow3.cpp index ed2eeeb6d8a4..96366a6a3b98 100644 --- a/enzyme/test/Integration/ReverseMode/virtualshadow3.cpp +++ b/enzyme/test/Integration/ReverseMode/virtualshadow3.cpp @@ -11,8 +11,6 @@ void __enzyme_autodiff(...); template double __enzyme_autodiff(void *, Args...); -int enzyme_dup, enzyme_const, enzyme_out, enzyme_dupnoneed; - struct Object { virtual double eval(double v) = 0;