@@ -250,9 +250,12 @@ static void makeSafeName(GlobalObject &G)
250250
251251
252252// takes the running content that has collected in the shadow module and dump it to disk
253- // this builds the object file portion of the sysimage files for fast startup
253+ // this builds the object file portion of the sysimage files for fast startup, and can
254+ // also be used be extern consumers like GPUCompiler.jl to obtain a module containing
255+ // all reachable & inferrrable functions. The `policy` flag switches between the defaul
256+ // mode `0` and the extern mode `1`.
254257extern " C" JL_DLLEXPORT
255- void *jl_create_native (jl_array_t *methods, const jl_cgparams_t cgparams)
258+ void *jl_create_native (jl_array_t *methods, const jl_cgparams_t cgparams, int _policy )
256259{
257260 jl_native_code_desc_t *data = new jl_native_code_desc_t ;
258261 jl_codegen_params_t params;
@@ -263,12 +266,17 @@ void *jl_create_native(jl_array_t *methods, const jl_cgparams_t cgparams)
263266 JL_GC_PUSH1 (&src);
264267 JL_LOCK (&codegen_lock);
265268
269+ CompilationPolicy policy = (CompilationPolicy) _policy;
270+
266271 // compile all methods for the current world and type-inference world
267272 size_t compile_for[] = { jl_typeinf_world, jl_world_counter };
268273 for (int worlds = 0 ; worlds < 2 ; worlds++) {
269274 params.world = compile_for[worlds];
270275 if (!params.world )
271276 continue ;
277+ // Don't emit methods for the typeinf_world with extern policy
278+ if (policy == CompilationPolicy::Extern && params.world == jl_typeinf_world)
279+ continue ;
272280 size_t i, l;
273281 for (i = 0 , l = jl_array_len (methods); i < l; i++) {
274282 // each item in this list is either a MethodInstance indicating something
@@ -311,8 +319,9 @@ void *jl_create_native(jl_array_t *methods, const jl_cgparams_t cgparams)
311319 }
312320 }
313321 }
322+
314323 // finally, make sure all referenced methods also get compiled or fixed up
315- jl_compile_workqueue (emitted, params);
324+ jl_compile_workqueue (emitted, params, policy );
316325 }
317326 JL_GC_POP ();
318327
0 commit comments