Skip to content

Commit

Permalink
delete jl_gen_llvm_gv_array GlobalVariables, so that jl_dump_objfile …
Browse files Browse the repository at this point in the history
…still works after calling jl_dump_bitcode
  • Loading branch information
vtjnash committed Dec 13, 2014
1 parent 7700bf1 commit 62685fc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
22 changes: 11 additions & 11 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,45 +226,45 @@ extern "C" {
extern void jl_cpuid(int32_t CPUInfo[4], int32_t InfoType);
}

static void jl_gen_llvm_gv_array(llvm::Module *mod)
static void jl_gen_llvm_gv_array(llvm::Module *mod, SmallVector<GlobalVariable*, 8> &globalvars)
{
// emit the variable table into the code image (can only call this once)
// used just before dumping bitcode
// emit the variable table into the code image. used just before dumping bitcode.
// afterwards, call eraseFromParent on everything in globalvars to reset code generator.
ArrayType *atype = ArrayType::get(T_psize,jl_sysimg_gvars.size());
new GlobalVariable(
globalvars.push_back(new GlobalVariable(
*mod,
atype,
true,
GlobalVariable::ExternalLinkage,
ConstantArray::get(atype, ArrayRef<Constant*>(jl_sysimg_gvars)),
"jl_sysimg_gvars");
new GlobalVariable(
"jl_sysimg_gvars"));
globalvars.push_back(new GlobalVariable(
*mod,
T_size,
true,
GlobalVariable::ExternalLinkage,
ConstantInt::get(T_size,globalUnique+1),
"jl_globalUnique");
"jl_globalUnique"));

Constant *feature_string = ConstantDataArray::getString(jl_LLVMContext, jl_cpu_string);
new GlobalVariable(*mod,
globalvars.push_back(new GlobalVariable(*mod,
feature_string->getType(),
true,
GlobalVariable::ExternalLinkage,
feature_string,
"jl_sysimg_cpu_target");
"jl_sysimg_cpu_target"));

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

jl_cpuid((int32_t*)info, 1);
new GlobalVariable(*mod,
globalvars.push_back(new GlobalVariable(*mod,
T_int64,
true,
GlobalVariable::ExternalLinkage,
ConstantInt::get(T_int64,((uint64_t)info[2])|(((uint64_t)info[3])<<32)),
"jl_sysimg_cpu_cpuid");
"jl_sysimg_cpu_cpuid"));
}
}

Expand Down
18 changes: 13 additions & 5 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ struct jl_varinfo_t {
};

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

extern "C"
void jl_dump_bitcode(char *fname)
Expand All @@ -354,13 +354,17 @@ void jl_dump_bitcode(char *fname)
std::string err;
raw_fd_ostream OS(fname, err);
#endif
SmallVector<GlobalVariable*, 8> globalvars;
#ifdef USE_MCJIT
jl_gen_llvm_gv_array(shadow_module);
jl_gen_llvm_gv_array(shadow_module, globalvars);
WriteBitcodeToFile(shadow_module, OS);
#else
jl_gen_llvm_gv_array(jl_Module);
jl_gen_llvm_gv_array(jl_Module, globalvars);
WriteBitcodeToFile(jl_Module, OS);
#endif
for (SmallVectorImpl<GlobalVariable>::iterator *I = globalvars.begin(), *E = globalvars.end(); I != E; ++I) {
(*I)->eraseFromParent();
}
}

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

SmallVector<GlobalVariable*, 8> globalvars;
#ifdef USE_MCJIT
jl_gen_llvm_gv_array(shadow_module);
jl_gen_llvm_gv_array(shadow_module, globalvars);
PM.run(*shadow_module);
#else
jl_gen_llvm_gv_array(jl_Module);
jl_gen_llvm_gv_array(jl_Module, globalvars);
PM.run(*jl_Module);
#endif
for (SmallVectorImpl<GlobalVariable>::iterator *I = globalvars.begin(), *E = globalvars.end(); I != E; ++I) {
(*I)->eraseFromParent();
}
}

// aggregate of array metadata
Expand Down

0 comments on commit 62685fc

Please sign in to comment.