@@ -68,8 +68,8 @@ void jl_dump_llvm_opt_impl(void *s)
6868 dump_llvm_opt_stream = (JL_STREAM*)s;
6969}
7070
71- static void jl_add_to_ee (std::unique_ptr<Module> m);
7271static void jl_add_to_ee (std::unique_ptr<Module> &M, StringMap<std::unique_ptr<Module>*> &NewExports);
72+ static void jl_decorate_module (Module &M);
7373static uint64_t getAddressForFunction (StringRef fname);
7474
7575void jl_link_global (GlobalVariable *GV, void *addr)
@@ -130,7 +130,7 @@ static jl_callptr_t _jl_compile_codeinst(
130130 jl_compile_workqueue (emitted, params, CompilationPolicy::Default, context);
131131
132132 if (params._shared_module )
133- jl_add_to_ee (std::unique_ptr<Module>(params._shared_module ));
133+ jl_ExecutionEngine-> addModule (std::unique_ptr<Module>(params._shared_module ));
134134 StringMap<std::unique_ptr<Module>*> NewExports;
135135 StringMap<void *> NewGlobals;
136136 for (auto &global : params.globals ) {
@@ -236,10 +236,10 @@ int jl_compile_extern_c_impl(LLVMModuleRef llvmmod, void *p, void *sysimg, jl_va
236236 jl_jit_globals (params.globals );
237237 assert (params.workqueue .empty ());
238238 if (params._shared_module )
239- jl_add_to_ee (std::unique_ptr<Module>(params._shared_module ));
239+ jl_ExecutionEngine-> addModule (std::unique_ptr<Module>(params._shared_module ));
240240 }
241241 if (success && llvmmod == NULL )
242- jl_add_to_ee (std::unique_ptr<Module>(into));
242+ jl_ExecutionEngine-> addModule (std::unique_ptr<Module>(into));
243243 }
244244 if (jl_codegen_lock.count == 1 && measure_compile_time_enabled)
245245 jl_atomic_fetch_add_relaxed (&jl_cumulative_compile_time, (jl_hrtime () - compiler_start_time));
@@ -1016,6 +1016,8 @@ void JuliaOJIT::addGlobalMapping(StringRef Name, uint64_t Addr)
10161016void JuliaOJIT::addModule (std::unique_ptr<Module> M)
10171017{
10181018 JL_TIMING (LLVM_MODULE_FINISH);
1019+ jl_decorate_module (*M);
1020+ shareStrings (*M);
10191021 std::vector<std::string> NewExports;
10201022 for (auto &F : M->global_values ()) {
10211023 if (!F.isDeclaration () && F.getLinkage () == GlobalValue::ExternalLinkage) {
@@ -1307,7 +1309,7 @@ void jl_merge_module(Module *dest, std::unique_ptr<Module> src)
13071309
13081310// optimize memory by turning long strings into memoized copies, instead of
13091311// making a copy per object file of output.
1310- void jl_jit_share_data (Module &M)
1312+ void JuliaOJIT::shareStrings (Module &M)
13111313{
13121314 std::vector<GlobalVariable*> erase;
13131315 for (auto &GV : M.globals ()) {
@@ -1320,7 +1322,7 @@ void jl_jit_share_data(Module &M)
13201322 if (data.size () > 16 ) { // only for long strings: keep short ones as values
13211323 Type *T_size = Type::getIntNTy (GV.getContext (), sizeof (void *) * 8 );
13221324 Constant *v = ConstantExpr::getIntToPtr (
1323- ConstantInt::get (T_size, (uintptr_t )data.data ()),
1325+ ConstantInt::get (T_size, (uintptr_t )(*ES. intern ( data)) .data ()),
13241326 GV.getType ());
13251327 GV.replaceAllUsesWith (v);
13261328 erase.push_back (&GV);
@@ -1330,26 +1332,21 @@ void jl_jit_share_data(Module &M)
13301332 GV->eraseFromParent ();
13311333}
13321334
1333- static void jl_add_to_ee (std::unique_ptr<Module> m)
1334- {
1335+ static void jl_decorate_module (Module &M) {
13351336#if defined(_CPU_X86_64_) && defined(_OS_WINDOWS_)
13361337 // Add special values used by debuginfo to build the UnwindData table registration for Win64
1337- Type *T_uint32 = Type::getInt32Ty (m->getContext ());
1338- ArrayType *atype = ArrayType::get (T_uint32, 3 ); // want 4-byte alignment of 12-bytes of data
1338+ ArrayType *atype = ArrayType::get (Type::getInt32Ty (M.getContext ()), 3 ); // want 4-byte alignment of 12-bytes of data
13391339 GlobalVariable *gvs[2 ] = {
1340- new GlobalVariable (*m , atype,
1340+ new GlobalVariable (M , atype,
13411341 false , GlobalVariable::InternalLinkage,
13421342 ConstantAggregateZero::get (atype), " __UnwindData" ),
1343- new GlobalVariable (*m , atype,
1343+ new GlobalVariable (M , atype,
13441344 false , GlobalVariable::InternalLinkage,
13451345 ConstantAggregateZero::get (atype), " __catchjmp" ) };
13461346 gvs[0 ]->setSection (" .text" );
13471347 gvs[1 ]->setSection (" .text" );
1348- appendToCompilerUsed (*m , makeArrayRef ((GlobalValue**)gvs, 2 ));
1348+ appendToCompilerUsed (M , makeArrayRef ((GlobalValue**)gvs, 2 ));
13491349#endif
1350- jl_jit_share_data (*m);
1351- assert (jl_ExecutionEngine);
1352- jl_ExecutionEngine->addModule (std::move (m));
13531350}
13541351
13551352static int jl_add_to_ee (
@@ -1393,7 +1390,7 @@ static int jl_add_to_ee(
13931390 Queued.erase (CM->get ());
13941391 jl_merge_module (M.get (), std::move (*CM));
13951392 }
1396- jl_add_to_ee (std::move (M));
1393+ jl_ExecutionEngine-> addModule (std::move (M));
13971394 MergeUp = 0 ;
13981395 }
13991396 else {
0 commit comments