From 36f6a8b6b956ffed15d100abe677125d4a5aeaed Mon Sep 17 00:00:00 2001 From: "Yang, Rong R" Date: Thu, 22 Jun 2017 17:38:55 +0800 Subject: GBE: clean llvm module's clone and release. There are some changes: 1. Clone the module before call LLVMLinkModules2, remove other clones for it. 2. Don't delete module in function llvmToGen. 3. Add a function programNewFromLLVMFile so genProgramNewFromLLVM and buildFromLLVMModule only handle llvm module. Actually, programNewFromLLVMFile is only used by clCreateProgramWithLLVMIntel, and I think it is useless, maybe we could delete it at all. V2: define errDiag beside #if/#endif. Signed-off-by: Yang Rong Reviewed-by: Pan Xiuli --- backend/src/llvm/llvm_bitcode_link.cpp | 3 ++- backend/src/llvm/llvm_to_gen.cpp | 19 ++----------------- backend/src/llvm/llvm_to_gen.hpp | 2 +- 3 files changed, 5 insertions(+), 19 deletions(-) (limited to 'backend/src/llvm') diff --git a/backend/src/llvm/llvm_bitcode_link.cpp b/backend/src/llvm/llvm_bitcode_link.cpp index 5c6585d0..ef56e4c2 100644 --- a/backend/src/llvm/llvm_bitcode_link.cpp +++ b/backend/src/llvm/llvm_bitcode_link.cpp @@ -340,7 +340,8 @@ namespace gbe /* We use beignet's bitcode as dst because it will have a lot of lazy functions which will not be loaded. */ #if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39 - if(LLVMLinkModules2(wrap(clonedLib), wrap(mod))) { + llvm::Module * linked_module = llvm::CloneModule((llvm::Module*)mod).release(); + if(LLVMLinkModules2(wrap(clonedLib), wrap(linked_module))) { #else char* errorMsg; if(LLVMLinkModules(wrap(clonedLib), wrap(mod), LLVMLinkerDestroySource, &errorMsg)) { diff --git a/backend/src/llvm/llvm_to_gen.cpp b/backend/src/llvm/llvm_to_gen.cpp index ceefbbb0..8546f730 100644 --- a/backend/src/llvm/llvm_to_gen.cpp +++ b/backend/src/llvm/llvm_to_gen.cpp @@ -288,7 +288,7 @@ namespace gbe dc->process(diagnostic); } - bool llvmToGen(ir::Unit &unit, const char *fileName,const void* module, + bool llvmToGen(ir::Unit &unit, const void* module, int optLevel, bool strictMath, int profiling, std::string &errors) { std::string errInfo; @@ -296,23 +296,9 @@ namespace gbe if (OCL_OUTPUT_LLVM_BEFORE_LINK || OCL_OUTPUT_LLVM_AFTER_LINK || OCL_OUTPUT_LLVM_AFTER_GEN) o = std::unique_ptr(new llvm::raw_fd_ostream(fileno(stdout), false)); - // Get the module from its file - llvm::SMDiagnostic Err; - Module* cl_mod = NULL; if (module) { cl_mod = reinterpret_cast(const_cast(module)); - } else if (fileName){ -#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39 - llvm::LLVMContext& c = GBEGetLLVMContext(); -#else - llvm::LLVMContext& c = llvm::getGlobalContext(); -#endif -#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 36 - cl_mod = parseIRFile(fileName, Err, c).release(); -#else - cl_mod = ParseIRFile(fileName, Err, c); -#endif } if (!cl_mod) return false; @@ -335,8 +321,7 @@ namespace gbe /* Before do any thing, we first filter in all CL functions in bitcode. */ /* Also set unit's pointer size in runBitCodeLinker */ M.reset(runBitCodeLinker(cl_mod, strictMath, unit)); - if (!module) - delete cl_mod; + if (M.get() == 0) return true; diff --git a/backend/src/llvm/llvm_to_gen.hpp b/backend/src/llvm/llvm_to_gen.hpp index 90258521..73e88194 100644 --- a/backend/src/llvm/llvm_to_gen.hpp +++ b/backend/src/llvm/llvm_to_gen.hpp @@ -35,7 +35,7 @@ namespace gbe { /*! Convert the LLVM IR code to a GEN IR code, optLevel 0 equal to clang -O1 and 1 equal to clang -O2*/ - bool llvmToGen(ir::Unit &unit, const char *fileName, const void* module, + bool llvmToGen(ir::Unit &unit, const void* module, int optLevel, bool strictMath, int profiling, std::string &errors); #if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39 extern llvm::LLVMContext& GBEGetLLVMContext(); -- cgit v1.2.1