@@ -267,7 +267,6 @@ void *jl_create_native_impl(jl_array_t *methods, LLVMOrcThreadSafeModuleRef llvm
267
267
jl_method_instance_t *mi = NULL ;
268
268
jl_code_info_t *src = NULL ;
269
269
JL_GC_PUSH1 (&src);
270
- JL_LOCK (&jl_codegen_lock);
271
270
auto ct = jl_current_task;
272
271
ct->reentrant_codegen ++;
273
272
orc::ThreadSafeContext ctx;
@@ -278,16 +277,18 @@ void *jl_create_native_impl(jl_array_t *methods, LLVMOrcThreadSafeModuleRef llvm
278
277
}
279
278
orc::ThreadSafeModule &clone = llvmmod ? *unwrap (llvmmod) : backing;
280
279
auto ctxt = clone.getContext ();
281
- jl_codegen_params_t params (ctxt);
282
- params.params = cgparams;
280
+
283
281
uint64_t compiler_start_time = 0 ;
284
282
uint8_t measure_compile_time_enabled = jl_atomic_load_relaxed (&jl_measure_compile_time_enabled);
285
283
if (measure_compile_time_enabled)
286
284
compiler_start_time = jl_hrtime ();
287
285
288
- params.imaging = imaging;
289
-
290
286
// compile all methods for the current world and type-inference world
287
+
288
+ JL_LOCK (&jl_codegen_lock);
289
+ jl_codegen_params_t params (ctxt);
290
+ params.params = cgparams;
291
+ params.imaging = imaging;
291
292
size_t compile_for[] = { jl_typeinf_world, jl_atomic_load_acquire (&jl_world_counter) };
292
293
for (int worlds = 0 ; worlds < 2 ; worlds++) {
293
294
params.world = compile_for[worlds];
@@ -332,15 +333,18 @@ void *jl_create_native_impl(jl_array_t *methods, LLVMOrcThreadSafeModuleRef llvm
332
333
// finally, make sure all referenced methods also get compiled or fixed up
333
334
jl_compile_workqueue (emitted, *clone.getModuleUnlocked (), params, policy);
334
335
}
336
+ JL_UNLOCK (&jl_codegen_lock); // Might GC
335
337
JL_GC_POP ();
336
338
337
339
// process the globals array, before jl_merge_module destroys them
338
- std::vector<std::string> gvars;
340
+ std::vector<std::string> gvars (params. globals . size ()) ;
339
341
data->jl_value_to_llvm .resize (params.globals .size ());
340
342
343
+ size_t idx = 0 ;
341
344
for (auto &global : params.globals ) {
342
- data->jl_value_to_llvm .at (gvars.size ()) = global.first ;
343
- gvars.push_back (std::string (global.second ->getName ()));
345
+ gvars[idx] = global.second ->getName ().str ();
346
+ data->jl_value_to_llvm [idx] = global.first ;
347
+ idx++;
344
348
}
345
349
CreateNativeMethods += emitted.size ();
346
350
@@ -423,7 +427,6 @@ void *jl_create_native_impl(jl_array_t *methods, LLVMOrcThreadSafeModuleRef llvm
423
427
jl_ExecutionEngine->releaseContext (std::move (ctx));
424
428
}
425
429
ct->reentrant_codegen --;
426
- JL_UNLOCK (&jl_codegen_lock); // Might GC
427
430
return (void *)data;
428
431
}
429
432
@@ -1013,17 +1016,18 @@ void jl_get_llvmf_defn_impl(jl_llvmf_dump_t* dump, jl_method_instance_t *mi, siz
1013
1016
1014
1017
// emit this function into a new llvm module
1015
1018
if (src && jl_is_code_info (src)) {
1016
- JL_LOCK (&jl_codegen_lock);
1017
1019
auto ctx = jl_ExecutionEngine->getContext ();
1018
- jl_codegen_params_t output (*ctx);
1019
- output.world = world;
1020
- output.params = ¶ms;
1021
- orc::ThreadSafeModule m = jl_create_llvm_module (name_from_method_instance (mi), output.tsctx , output.imaging );
1020
+ orc::ThreadSafeModule m = jl_create_llvm_module (name_from_method_instance (mi), *ctx, imaging_default ());
1022
1021
uint64_t compiler_start_time = 0 ;
1023
1022
uint8_t measure_compile_time_enabled = jl_atomic_load_relaxed (&jl_measure_compile_time_enabled);
1024
1023
if (measure_compile_time_enabled)
1025
1024
compiler_start_time = jl_hrtime ();
1025
+ JL_LOCK (&jl_codegen_lock);
1026
+ jl_codegen_params_t output (*ctx);
1027
+ output.world = world;
1028
+ output.params = ¶ms;
1026
1029
auto decls = jl_emit_code (m, mi, src, jlrettype, output);
1030
+ JL_UNLOCK (&jl_codegen_lock); // Might GC
1027
1031
1028
1032
Function *F = NULL ;
1029
1033
if (m) {
@@ -1059,7 +1063,6 @@ void jl_get_llvmf_defn_impl(jl_llvmf_dump_t* dump, jl_method_instance_t *mi, siz
1059
1063
JL_GC_POP ();
1060
1064
if (measure_compile_time_enabled)
1061
1065
jl_atomic_fetch_add_relaxed (&jl_cumulative_compile_time, (jl_hrtime () - compiler_start_time));
1062
- JL_UNLOCK (&jl_codegen_lock); // Might GC
1063
1066
if (F) {
1064
1067
dump->TSM = wrap (new orc::ThreadSafeModule (std::move (m)));
1065
1068
dump->F = wrap (F);
0 commit comments