1- use std:: ffi:: CString ;
21use std:: ptr;
32
43use rustc_ast:: expand:: autodiff_attrs:: { AutoDiffAttrs , AutoDiffItem , DiffActivity , DiffMode } ;
54use rustc_codegen_ssa:: ModuleCodegen ;
65use rustc_codegen_ssa:: back:: write:: ModuleConfig ;
7- use rustc_codegen_ssa:: traits:: {
8- BaseTypeCodegenMethods , BuilderMethods , TypeMembershipCodegenMethods ,
9- } ;
6+ use rustc_codegen_ssa:: traits:: { BaseTypeCodegenMethods , BuilderMethods } ;
107use rustc_errors:: FatalError ;
118use rustc_middle:: ty:: TyCtxt ;
129use rustc_session:: config:: Lto ;
@@ -141,11 +138,11 @@ fn generate_enzyme_call<'ll, 'tcx>(
141138 let mut args = Vec :: with_capacity ( num_args as usize + 1 ) ;
142139 args. push ( fn_to_diff) ;
143140
144- let enzyme_const = cx. typeid_metadata ( "enzyme_const" . to_string ( ) ) . unwrap ( ) ;
145- let enzyme_out = cx. typeid_metadata ( "enzyme_out" . to_string ( ) ) . unwrap ( ) ;
146- let enzyme_dup = cx. typeid_metadata ( "enzyme_dup" . to_string ( ) ) . unwrap ( ) ;
147- let enzyme_dupnoneed = cx. typeid_metadata ( "enzyme_dupnoneed" . to_string ( ) ) . unwrap ( ) ;
148- let enzyme_primal_ret = cx. typeid_metadata ( "enzyme_primal_return" . to_string ( ) ) . unwrap ( ) ;
141+ let enzyme_const = cx. create_metadata ( "enzyme_const" . to_string ( ) ) . unwrap ( ) ;
142+ let enzyme_out = cx. create_metadata ( "enzyme_out" . to_string ( ) ) . unwrap ( ) ;
143+ let enzyme_dup = cx. create_metadata ( "enzyme_dup" . to_string ( ) ) . unwrap ( ) ;
144+ let enzyme_dupnoneed = cx. create_metadata ( "enzyme_dupnoneed" . to_string ( ) ) . unwrap ( ) ;
145+ let enzyme_primal_ret = cx. create_metadata ( "enzyme_primal_return" . to_string ( ) ) . unwrap ( ) ;
149146
150147 match output {
151148 DiffActivity :: Dual => {
@@ -239,8 +236,7 @@ fn generate_enzyme_call<'ll, 'tcx>(
239236 }
240237 }
241238
242- let c_ad_name = CString :: new ( ad_name. clone ( ) ) . unwrap ( ) ;
243- let call = builder. call2 ( enzyme_ty, ad_fn, & args, & c_ad_name) ;
239+ let call = builder. call ( enzyme_ty, None , None , ad_fn, & args, None , None ) ;
244240
245241 // This part is a bit iffy. LLVM requires that a call to an inlineable function has some
246242 // metadata attachted to it, but we just created this code oota. Given that the
@@ -250,8 +246,9 @@ fn generate_enzyme_call<'ll, 'tcx>(
250246 // FIXME(ZuseZ4): Work with Enzyme core devs to clarify what debug metadata issues we have,
251247 // and how to best improve it for enzyme core and rust-enzyme.
252248 let md_ty = cx. get_md_kind_id ( "dbg" ) ;
253- if llvm:: LLVMRustHasMetadata ( last_inst, md_ty) {
254- let md = llvm:: LLVMRustDIGetInstMetadata ( last_inst) ;
249+ if llvm:: LLVMRustHasMetadata ( last_inst, md_ty) == True {
250+ let md = llvm:: LLVMRustDIGetInstMetadata ( last_inst)
251+ . expect ( "failed to get instruction metadata" ) ;
255252 let md_todiff = cx. get_metadata_value ( md) ;
256253 llvm:: LLVMSetMetadata ( call, md_ty, md_todiff) ;
257254 } else {
0 commit comments