Skip to content

Commit 62685fc

Browse files
committed
delete jl_gen_llvm_gv_array GlobalVariables, so that jl_dump_objfile still works after calling jl_dump_bitcode
1 parent 7700bf1 commit 62685fc

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

src/cgutils.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -226,45 +226,45 @@ extern "C" {
226226
extern void jl_cpuid(int32_t CPUInfo[4], int32_t InfoType);
227227
}
228228

229-
static void jl_gen_llvm_gv_array(llvm::Module *mod)
229+
static void jl_gen_llvm_gv_array(llvm::Module *mod, SmallVector<GlobalVariable*, 8> &globalvars)
230230
{
231-
// emit the variable table into the code image (can only call this once)
232-
// used just before dumping bitcode
231+
// emit the variable table into the code image. used just before dumping bitcode.
232+
// afterwards, call eraseFromParent on everything in globalvars to reset code generator.
233233
ArrayType *atype = ArrayType::get(T_psize,jl_sysimg_gvars.size());
234-
new GlobalVariable(
234+
globalvars.push_back(new GlobalVariable(
235235
*mod,
236236
atype,
237237
true,
238238
GlobalVariable::ExternalLinkage,
239239
ConstantArray::get(atype, ArrayRef<Constant*>(jl_sysimg_gvars)),
240-
"jl_sysimg_gvars");
241-
new GlobalVariable(
240+
"jl_sysimg_gvars"));
241+
globalvars.push_back(new GlobalVariable(
242242
*mod,
243243
T_size,
244244
true,
245245
GlobalVariable::ExternalLinkage,
246246
ConstantInt::get(T_size,globalUnique+1),
247-
"jl_globalUnique");
247+
"jl_globalUnique"));
248248

249249
Constant *feature_string = ConstantDataArray::getString(jl_LLVMContext, jl_cpu_string);
250-
new GlobalVariable(*mod,
250+
globalvars.push_back(new GlobalVariable(*mod,
251251
feature_string->getType(),
252252
true,
253253
GlobalVariable::ExternalLinkage,
254254
feature_string,
255-
"jl_sysimg_cpu_target");
255+
"jl_sysimg_cpu_target"));
256256

257257
// For native also store the cpuid
258258
if (strcmp(jl_cpu_string,"native") == 0) {
259259
uint32_t info[4];
260260

261261
jl_cpuid((int32_t*)info, 1);
262-
new GlobalVariable(*mod,
262+
globalvars.push_back(new GlobalVariable(*mod,
263263
T_int64,
264264
true,
265265
GlobalVariable::ExternalLinkage,
266266
ConstantInt::get(T_int64,((uint64_t)info[2])|(((uint64_t)info[3])<<32)),
267-
"jl_sysimg_cpu_cpuid");
267+
"jl_sysimg_cpu_cpuid"));
268268
}
269269
}
270270

src/codegen.cpp

+13-5
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ struct jl_varinfo_t {
338338
};
339339

340340
// --- helpers for reloading IR image
341-
static void jl_gen_llvm_gv_array(llvm::Module *mod);
341+
static void jl_gen_llvm_gv_array(llvm::Module *mod, SmallVector<GlobalVariable*, 8> &globalvars);
342342

343343
extern "C"
344344
void jl_dump_bitcode(char *fname)
@@ -354,13 +354,17 @@ void jl_dump_bitcode(char *fname)
354354
std::string err;
355355
raw_fd_ostream OS(fname, err);
356356
#endif
357+
SmallVector<GlobalVariable*, 8> globalvars;
357358
#ifdef USE_MCJIT
358-
jl_gen_llvm_gv_array(shadow_module);
359+
jl_gen_llvm_gv_array(shadow_module, globalvars);
359360
WriteBitcodeToFile(shadow_module, OS);
360361
#else
361-
jl_gen_llvm_gv_array(jl_Module);
362+
jl_gen_llvm_gv_array(jl_Module, globalvars);
362363
WriteBitcodeToFile(jl_Module, OS);
363364
#endif
365+
for (SmallVectorImpl<GlobalVariable>::iterator *I = globalvars.begin(), *E = globalvars.end(); I != E; ++I) {
366+
(*I)->eraseFromParent();
367+
}
364368
}
365369

366370
extern "C"
@@ -418,13 +422,17 @@ void jl_dump_objfile(char *fname, int jit_model)
418422
jl_error("Could not generate obj file for this target");
419423
}
420424

425+
SmallVector<GlobalVariable*, 8> globalvars;
421426
#ifdef USE_MCJIT
422-
jl_gen_llvm_gv_array(shadow_module);
427+
jl_gen_llvm_gv_array(shadow_module, globalvars);
423428
PM.run(*shadow_module);
424429
#else
425-
jl_gen_llvm_gv_array(jl_Module);
430+
jl_gen_llvm_gv_array(jl_Module, globalvars);
426431
PM.run(*jl_Module);
427432
#endif
433+
for (SmallVectorImpl<GlobalVariable>::iterator *I = globalvars.begin(), *E = globalvars.end(); I != E; ++I) {
434+
(*I)->eraseFromParent();
435+
}
428436
}
429437

430438
// aggregate of array metadata

0 commit comments

Comments
 (0)