summaryrefslogtreecommitdiff
path: root/backend/src/llvm
diff options
context:
space:
mode:
authorYang, Rong R <rong.r.yang@intel.com>2017-06-22 17:38:55 +0800
committerYang Rong <rong.r.yang@intel.com>2017-06-23 16:04:54 +0800
commit36f6a8b6b956ffed15d100abe677125d4a5aeaed (patch)
tree17353b2825c6fbb8124746bafca9aa9ee196a8f0 /backend/src/llvm
parentf32e067b2ef32568253cf32fd1bd0eaafe20439c (diff)
downloadbeignet-36f6a8b6b956ffed15d100abe677125d4a5aeaed.tar.gz
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 <rong.r.yang@intel.com> Reviewed-by: Pan Xiuli <xiuli.pan@intel.com>
Diffstat (limited to 'backend/src/llvm')
-rw-r--r--backend/src/llvm/llvm_bitcode_link.cpp3
-rw-r--r--backend/src/llvm/llvm_to_gen.cpp19
-rw-r--r--backend/src/llvm/llvm_to_gen.hpp2
3 files changed, 5 insertions, 19 deletions
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<llvm::raw_fd_ostream>(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<Module*>(const_cast<void*>(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();