1
- use std:: ffi:: CString ;
2
1
use std:: ptr;
3
2
4
3
use rustc_ast:: expand:: autodiff_attrs:: { AutoDiffAttrs , AutoDiffItem , DiffActivity , DiffMode } ;
5
4
use rustc_codegen_ssa:: ModuleCodegen ;
6
5
use 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 } ;
10
7
use rustc_errors:: FatalError ;
11
8
use rustc_middle:: ty:: TyCtxt ;
12
9
use rustc_session:: config:: Lto ;
@@ -141,11 +138,11 @@ fn generate_enzyme_call<'ll, 'tcx>(
141
138
let mut args = Vec :: with_capacity ( num_args as usize + 1 ) ;
142
139
args. push ( fn_to_diff) ;
143
140
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 ( ) ;
149
146
150
147
match output {
151
148
DiffActivity :: Dual => {
@@ -239,8 +236,7 @@ fn generate_enzyme_call<'ll, 'tcx>(
239
236
}
240
237
}
241
238
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 ) ;
244
240
245
241
// This part is a bit iffy. LLVM requires that a call to an inlineable function has some
246
242
// metadata attachted to it, but we just created this code oota. Given that the
@@ -250,8 +246,9 @@ fn generate_enzyme_call<'ll, 'tcx>(
250
246
// FIXME(ZuseZ4): Work with Enzyme core devs to clarify what debug metadata issues we have,
251
247
// and how to best improve it for enzyme core and rust-enzyme.
252
248
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" ) ;
255
252
let md_todiff = cx. get_metadata_value ( md) ;
256
253
llvm:: LLVMSetMetadata ( call, md_ty, md_todiff) ;
257
254
} else {
0 commit comments