@@ -923,25 +923,30 @@ jl_llvm_functions_t jl_compile_linfo(jl_method_instance_t *li, jl_code_info_t *s
923
923
f = (Function*)decls.functionObject ;
924
924
specf = (Function*)decls.specFunctionObject ;
925
925
926
- // Step 4. Prepare debug info to receive this function
927
- // record that this function name came from this linfo,
928
- // so we can build a reverse mapping for debug-info.
929
- bool toplevel = li->def == NULL ;
930
- if (!toplevel) {
931
- const DataLayout &DL =
932
- #if JL_LLVM_VERSION >= 30500
933
- m->getDataLayout ();
934
- #else
935
- *jl_data_layout;
936
- #endif
937
- // but don't remember toplevel thunks because
938
- // they may not be rooted in the gc for the life of the program,
939
- // and the runtime doesn't notify us when the code becomes unreachable :(
940
- jl_add_linfo_in_flight ((specf ? specf : f)->getName (), li, DL);
941
- }
942
926
943
- // Step 5. Add the result to the execution engine now
944
- jl_finalize_module (m.release (), !toplevel);
927
+ if (JL_HOOK_TEST (params, module_activation)) {
928
+ JL_HOOK_CALL1 (params, module_activation, jl_box_voidpointer (wrap (m.release ())));
929
+ } else {
930
+ // Step 4. Prepare debug info to receive this function
931
+ // record that this function name came from this linfo,
932
+ // so we can build a reverse mapping for debug-info.
933
+ bool toplevel = li->def == NULL ;
934
+ if (!toplevel) {
935
+ const DataLayout &DL =
936
+ #if JL_LLVM_VERSION >= 30500
937
+ m->getDataLayout ();
938
+ #else
939
+ *jl_data_layout;
940
+ #endif
941
+ // but don't remember toplevel thunks because
942
+ // they may not be rooted in the gc for the life of the program,
943
+ // and the runtime doesn't notify us when the code becomes unreachable :(
944
+ jl_add_linfo_in_flight ((specf ? specf : f)->getName (), li, DL);
945
+ }
946
+
947
+ // Step 5. Add the result to the execution engine now
948
+ jl_finalize_module (m.release (), !toplevel);
949
+ }
945
950
946
951
if (li->jlcall_api != 2 ) {
947
952
// if not inlineable, code won't be needed again
@@ -988,8 +993,13 @@ static Value *getModuleFlag(Module *m, StringRef Key)
988
993
#define getModuleFlag (m,str ) m->getModuleFlag (str)
989
994
#endif
990
995
991
- static void jl_setup_module (Module *m)
996
+ static void jl_setup_module (Module *m, jl_cgparams_t *params = &jl_default_cgparams )
992
997
{
998
+ if (JL_HOOK_TEST (params, module_setup)) {
999
+ JL_HOOK_CALL1 (params, module_setup, jl_box_voidpointer (wrap (m)));
1000
+ return ;
1001
+ }
1002
+
993
1003
// Some linkers (*cough* OS X) don't understand DWARF v4, so we use v2 in
994
1004
// imaging mode. The structure of v4 is slightly nicer for debugging JIT
995
1005
// code.
@@ -1256,8 +1266,9 @@ void jl_extern_c(jl_function_t *f, jl_value_t *rt, jl_value_t *argt, char *name)
1256
1266
// this is paired with jl_dump_function_ir and jl_dump_function_asm in particular ways:
1257
1267
// misuse will leak memory or cause read-after-free
1258
1268
extern " C" JL_DLLEXPORT
1259
- void *jl_get_llvmf_defn (jl_method_instance_t *linfo, bool getwrapper, bool optimize, jl_cgparams_t params)
1269
+ void *jl_get_llvmf_defn (jl_method_instance_t *linfo, bool getwrapper, bool optimize, jl_cgparams_t params, jl_cghooks_t _hooks )
1260
1270
{
1271
+ params.hooks = _hooks; // ccall doesn't know how to pass the nested jl_cghooks_t
1261
1272
// `source` is `NULL` for generated functions.
1262
1273
// The `isstaged` check can be removed if that is not the case anymore.
1263
1274
if (linfo->def && linfo->def ->source == NULL && !linfo->def ->isstaged ) {
@@ -1338,8 +1349,9 @@ void *jl_get_llvmf_defn(jl_method_instance_t *linfo, bool getwrapper, bool optim
1338
1349
1339
1350
1340
1351
extern " C" JL_DLLEXPORT
1341
- void *jl_get_llvmf_decl (jl_method_instance_t *linfo, bool getwrapper, jl_cgparams_t params)
1352
+ void *jl_get_llvmf_decl (jl_method_instance_t *linfo, bool getwrapper, jl_cgparams_t params, jl_cghooks_t _hooks )
1342
1353
{
1354
+ params.hooks = _hooks; // ccall doesn't know how to pass the nested jl_cghooks_t
1343
1355
// `source` is `NULL` for generated functions.
1344
1356
// The `isstaged` check can be removed if that is not the case anymore.
1345
1357
if (linfo->def && linfo->def ->source == NULL && !linfo->def ->isstaged ) {
@@ -1397,9 +1409,9 @@ void *jl_get_llvmf(jl_tupletype_t *tt, bool getwrapper, bool getdeclarations)
1397
1409
}
1398
1410
void *f;
1399
1411
if (getdeclarations)
1400
- f = jl_get_llvmf_decl (linfo, getwrapper, jl_default_cgparams);
1412
+ f = jl_get_llvmf_decl (linfo, getwrapper, jl_default_cgparams, jl_no_cghooks );
1401
1413
else
1402
- f = jl_get_llvmf_defn (linfo, getwrapper, true , jl_default_cgparams);
1414
+ f = jl_get_llvmf_defn (linfo, getwrapper, true , jl_default_cgparams, jl_no_cghooks );
1403
1415
JL_GC_POP ();
1404
1416
return f;
1405
1417
}
@@ -4207,7 +4219,7 @@ static std::unique_ptr<Module> emit_function(jl_method_instance_t *lam, jl_code_
4207
4219
4208
4220
ctx.sret = false ;
4209
4221
Module *M = new Module (ctx.name , jl_LLVMContext);
4210
- jl_setup_module (M);
4222
+ jl_setup_module (M, params );
4211
4223
if (specsig) { // assumes !va and !needsparams
4212
4224
std::vector<Type*> fsig (0 );
4213
4225
Type *rt;
0 commit comments