From 62685fc70e139f439cce9b306faba4fd4d813a5c Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Sat, 13 Dec 2014 03:25:13 -0500 Subject: [PATCH] delete jl_gen_llvm_gv_array GlobalVariables, so that jl_dump_objfile still works after calling jl_dump_bitcode --- src/cgutils.cpp | 22 +++++++++++----------- src/codegen.cpp | 18 +++++++++++++----- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/cgutils.cpp b/src/cgutils.cpp index 840c2a7fededf..09de8dea0096a 100644 --- a/src/cgutils.cpp +++ b/src/cgutils.cpp @@ -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 &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(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")); } } diff --git a/src/codegen.cpp b/src/codegen.cpp index ec39aea4bc198..54814ac37e4ba 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -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 &globalvars); extern "C" void jl_dump_bitcode(char *fname) @@ -354,13 +354,17 @@ void jl_dump_bitcode(char *fname) std::string err; raw_fd_ostream OS(fname, err); #endif + SmallVector 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::iterator *I = globalvars.begin(), *E = globalvars.end(); I != E; ++I) { + (*I)->eraseFromParent(); + } } extern "C" @@ -418,13 +422,17 @@ void jl_dump_objfile(char *fname, int jit_model) jl_error("Could not generate obj file for this target"); } + SmallVector 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::iterator *I = globalvars.begin(), *E = globalvars.end(); I != E; ++I) { + (*I)->eraseFromParent(); + } } // aggregate of array metadata