Skip to content

Commit

Permalink
use correct NoFree list (#2024)
Browse files Browse the repository at this point in the history
* use correct NoFree list

* Revert "Add Rust Eprintln support (#2022)"

This reverts commit 6ed6b5e.

* re-add demangled eprint name

* add rust eprintln test

* undo unnecessary cxa_atexit addition

* add opaque-ptr flag

* fun

* more fun

* more fun
  • Loading branch information
ZuseZ4 authored Aug 1, 2024
1 parent 7b1c34c commit 9d6a86b
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 4 deletions.
1 change: 0 additions & 1 deletion enzyme/Enzyme/ActivityAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ static const StringSet<> InactiveGlobals = {
"ompi_request_null",
"ompi_mpi_double",
"ompi_mpi_comm_world",
"__cxa_thread_atexit_impl",
"stderr",
"stdout",
"stdin",
Expand Down
5 changes: 2 additions & 3 deletions enzyme/Enzyme/EnzymeLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6068,9 +6068,6 @@ llvm::Value *EnzymeLogic::CreateNoFree(RequestContext context,
"std::basic_ostream<char, std::char_traits<char>>::operator<<",
"std::ostream::operator<<",
"std::ostream& std::ostream::_M_insert",
// Rust
"std::io::stdio::_eprint",
"__cxa_thread_atexit_impl",
};
// clang-format on

Expand Down Expand Up @@ -6336,6 +6333,8 @@ llvm::Function *EnzymeLogic::CreateNoFree(RequestContext context, Function *F) {
"std::basic_streambuf<char, std::char_traits<char>>::sputn",
"std::istream& std::istream::_M_extract",
"std::ctype<char>::widen",
//Rust
"std::io::stdio::_eprint",
};

StringSet<> NoFrees = {"mpfr_greater_p",
Expand Down
65 changes: 65 additions & 0 deletions enzyme/test/Enzyme/ReverseMode/rust-eprintln.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
; RUN: if [ %llvmver -eq 15 ]; then %opt < %s %loadEnzyme -enzyme -opaque-pointers=1 -S | FileCheck %s; fi
; RUN: if [ %llvmver -ge 15 ]; then %opt < %s %newLoadEnzyme -passes="enzyme" -opaque-pointers=1 -S | FileCheck %s; fi

; ModuleID = 'out.ll'
source_filename = "ad.ab3e8598fedbb3bd-cgu.0"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@anon.a6304942fd3c743a92a7245cba3cd4a6.2 = external hidden unnamed_addr constant <{ ptr, [8 x i8] }>, align 8
@anon.a6304942fd3c743a92a7245cba3cd4a6.3 = external hidden unnamed_addr constant <{}>, align 8

; Function Attrs: noinline nonlazybind sanitize_hwaddress uwtable
define dso_local "enzyme_type"="{}" void @eprintfunc() unnamed_addr #0 {
%1 = alloca { { ptr, i64 }, { ptr, i64 }, { ptr, i64 } }, align 8
call void @llvm.lifetime.start.p0(i64 48, ptr nonnull %1)
store ptr @anon.a6304942fd3c743a92a7245cba3cd4a6.2, ptr %1, align 8
%2 = getelementptr inbounds { ptr, i64 }, ptr %1, i64 0, i32 1
store i64 1, ptr %2, align 8
%3 = getelementptr inbounds { { ptr, i64 }, { ptr, i64 }, { ptr, i64 } }, ptr %1, i64 0, i32 2
store ptr null, ptr %3, align 8
%4 = getelementptr inbounds { { ptr, i64 }, { ptr, i64 }, { ptr, i64 } }, ptr %1, i64 0, i32 1
store ptr @anon.a6304942fd3c743a92a7245cba3cd4a6.3, ptr %4, align 8
%5 = getelementptr inbounds { { ptr, i64 }, { ptr, i64 }, { ptr, i64 } }, ptr %1, i64 0, i32 1, i32 1
store i64 0, ptr %5, align 8
call void @_ZN3std2io5stdio7_eprint17h557bd237e67376ddE(ptr noalias nocapture noundef nonnull align 8 dereferenceable(48) %1)
call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %1)
ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nonlazybind sanitize_hwaddress uwtable
declare hidden void @_ZN3std2io5stdio7_eprint17h557bd237e67376ddE(ptr noalias nocapture noundef readonly align 8 dereferenceable(48)) unnamed_addr #2

declare void @__enzyme_autodiff(...)

define void @enzyme_opt_helper_0() {
call void (...) @__enzyme_autodiff(ptr @eprintfunc)
ret void
}

attributes #0 = { noinline nonlazybind sanitize_hwaddress uwtable "probe-stack"="inline-asm" "target-cpu"="x86-64" }
attributes #1 = { nocallback nofree nosync nounwind willreturn }
attributes #2 = { nonlazybind sanitize_hwaddress uwtable "probe-stack"="inline-asm" "target-cpu"="x86-64" }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4}

!0 = !{i32 8, !"PIC Level", i32 2}
!1 = !{i32 7, !"PIE Level", i32 2}
!2 = !{i32 2, !"RtLibUseGOT", i32 1}
!3 = !{i32 1, !"LTOPostLink", i32 1}
!4 = !{!"rustc version 1.77.0-nightly (e3875bc6d 2024-07-26)"}

; CHECK: define internal void @diffeeprintfunc()
; CHECK: call void @_ZN3std2io5stdio7_eprint17h557bd237e67376ddE(ptr noalias nocapture noundef nonnull align 8 dereferenceable(48) %1) #4
; CHECK: br label %invert

; CHECK: invert: ; preds = %0
; CHECK-NEXT: ret void
; CHECK-NEXT: }

0 comments on commit 9d6a86b

Please sign in to comment.