@@ -4,7 +4,7 @@ use std::path::{Path, PathBuf};
4
4
use std:: sync:: Arc ;
5
5
use std:: { fs, slice, str} ;
6
6
7
- use libc:: { c_char, c_int, c_uint , c_void, size_t} ;
7
+ use libc:: { c_char, c_int, c_void, size_t} ;
8
8
use llvm:: {
9
9
LLVMRustLLVMHasZlibCompressionForDebugSymbols , LLVMRustLLVMHasZstdCompressionForDebugSymbols ,
10
10
} ;
@@ -41,14 +41,8 @@ use crate::errors::{
41
41
CopyBitcode , FromLlvmDiag , FromLlvmOptimizationDiag , LlvmError , UnknownCompression ,
42
42
WithLlvmError , WriteBytecode ,
43
43
} ;
44
- use crate :: llvm:: AttributePlace :: Function ;
45
44
use 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 } ;
52
46
use crate :: type_:: Type ;
53
47
use crate :: { LlvmCodegenBackend , ModuleLlvm , base, common, llvm_util} ;
54
48
@@ -689,39 +683,8 @@ pub(crate) fn differentiate(
689
683
crate :: builder:: generate_enzyme_call ( llmod, llcx, fn_def, fn_target, item. attrs . clone ( ) ) ;
690
684
}
691
685
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.
725
688
726
689
if let Some ( opt_level) = config. opt_level {
727
690
let opt_stage = match cgcx. lto {
@@ -773,35 +736,8 @@ pub(crate) unsafe fn optimize(
773
736
unsafe { llvm:: LLVMWriteBitcodeToFile ( llmod, out. as_ptr ( ) ) } ;
774
737
}
775
738
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.
805
741
806
742
if let Some ( opt_level) = config. opt_level {
807
743
let opt_stage = match cgcx. lto {
0 commit comments