@@ -4,7 +4,7 @@ use std::path::{Path, PathBuf};
44use std:: sync:: Arc ;
55use std:: { fs, slice, str} ;
66
7- use libc:: { c_char, c_int, c_uint , c_void, size_t} ;
7+ use libc:: { c_char, c_int, c_void, size_t} ;
88use llvm:: {
99 LLVMRustLLVMHasZlibCompressionForDebugSymbols , LLVMRustLLVMHasZstdCompressionForDebugSymbols ,
1010} ;
@@ -41,14 +41,8 @@ use crate::errors::{
4141 CopyBitcode , FromLlvmDiag , FromLlvmOptimizationDiag , LlvmError , UnknownCompression ,
4242 WithLlvmError , WriteBytecode ,
4343} ;
44- use crate :: llvm:: AttributePlace :: Function ;
4544use crate :: llvm:: diagnostic:: OptimizationDiagnosticKind :: * ;
46- use crate :: llvm:: {
47- self , AttributeKind , DiagnosticInfo , LLVMGetFirstFunction ,
48- LLVMGetNextFunction , LLVMGetStringAttributeAtIndex , LLVMIsEnumAttribute , LLVMIsStringAttribute ,
49- LLVMRemoveStringAttributeAtIndex , LLVMRustGetEnumAttributeAtIndex ,
50- LLVMRustRemoveEnumAttributeAtIndex , PassManager ,
51- } ;
45+ use crate :: llvm:: { self , DiagnosticInfo , PassManager } ;
5246use crate :: type_:: Type ;
5347use crate :: { LlvmCodegenBackend , ModuleLlvm , base, common, llvm_util} ;
5448
@@ -689,39 +683,8 @@ pub(crate) fn differentiate(
689683 crate :: builder:: generate_enzyme_call ( llmod, llcx, fn_def, fn_target, item. attrs . clone ( ) ) ;
690684 }
691685
692- // We needed the SanitizeHWAddress attribute to prevent LLVM from optimizing enums in a way
693- // which Enzyme doesn't understand.
694- unsafe {
695- let mut f = LLVMGetFirstFunction ( llmod) ;
696- loop {
697- if let Some ( lf) = f {
698- f = LLVMGetNextFunction ( lf) ;
699- let myhwattr = "enzyme_hw" ;
700- let attr = LLVMGetStringAttributeAtIndex (
701- lf,
702- c_uint:: MAX ,
703- myhwattr. as_ptr ( ) as * const c_char ,
704- myhwattr. as_bytes ( ) . len ( ) as c_uint ,
705- ) ;
706- if LLVMIsStringAttribute ( attr) {
707- LLVMRemoveStringAttributeAtIndex (
708- lf,
709- c_uint:: MAX ,
710- myhwattr. as_ptr ( ) as * const c_char ,
711- myhwattr. as_bytes ( ) . len ( ) as c_uint ,
712- ) ;
713- } else {
714- LLVMRustRemoveEnumAttributeAtIndex (
715- lf,
716- c_uint:: MAX ,
717- AttributeKind :: SanitizeHWAddress ,
718- ) ;
719- }
720- } else {
721- break ;
722- }
723- }
724- }
686+ // FIXME(ZuseZ4): In the following upstream PR, we want to add code to handle SanitizeHWAddress,
687+ // to prevent some illegal/unsupported optimizations.
725688
726689 if let Some ( opt_level) = config. opt_level {
727690 let opt_stage = match cgcx. lto {
@@ -773,35 +736,8 @@ pub(crate) unsafe fn optimize(
773736 unsafe { llvm:: LLVMWriteBitcodeToFile ( llmod, out. as_ptr ( ) ) } ;
774737 }
775738
776- // This code enables Enzyme to differentiate code containing Rust enums.
777- // By adding the SanitizeHWAddress attribute we prevent LLVM from Optimizing
778- // away the enums and allows Enzyme to understand why a value can be of different types in
779- // different code sections. We remove this attribute after Enzyme is done, to not affect the
780- // rest of the compilation.
781- //#[cfg(llvm_enzyme)]
782- unsafe {
783- let mut f = LLVMGetFirstFunction ( llmod) ;
784- loop {
785- if let Some ( lf) = f {
786- f = LLVMGetNextFunction ( lf) ;
787- let myhwattr = "enzyme_hw" ;
788- let prevattr = LLVMRustGetEnumAttributeAtIndex (
789- lf,
790- c_uint:: MAX ,
791- AttributeKind :: SanitizeHWAddress ,
792- ) ;
793- if LLVMIsEnumAttribute ( prevattr) {
794- let attr = llvm:: CreateAttrString ( llcx, myhwattr) ;
795- crate :: attributes:: apply_to_llfn ( lf, Function , & [ attr] ) ;
796- } else {
797- let attr = AttributeKind :: SanitizeHWAddress . create_attr ( llcx) ;
798- crate :: attributes:: apply_to_llfn ( lf, Function , & [ attr] ) ;
799- }
800- } else {
801- break ;
802- }
803- }
804- }
739+ // FIXME(ZuseZ4): In the following PR, we have to add code to apply the sanitize_hwaddress
740+ // attribute to all functions in the module, to prevent some illegal/unsupported optimizations.
805741
806742 if let Some ( opt_level) = config. opt_level {
807743 let opt_stage = match cgcx. lto {
0 commit comments