summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYang Rong <rong.r.yang@intel.com>2015-02-12 16:29:40 +0800
committerZhigang Gong <zhigang.gong@intel.com>2015-02-12 18:59:47 +0800
commitdd6b8896deb8c799f1155b7c87343b5e6d1a9d86 (patch)
tree569a83c474cca03aafc49ca6bea1e98a0a674c71
parent7c21daf4d04c6ad3fbca040b1165c08f7b40d179 (diff)
Add llvm3.6 build support.
There are some changes from llvm3.5: 1. Some functions return std::unique_ptr instead of pointer. 2. MetaNode to Value and Value to MetaNode. V2: Fix llvm3.5 build error. V3: Print link and function materialize message. Signed-off-by: Yang Rong <rong.r.yang@intel.com> Reviewed-by: Zhigang Gong <zhigang.gong@linux.intel.com>
-rw-r--r--backend/src/backend/gen_program.cpp10
-rw-r--r--backend/src/backend/program.cpp4
-rw-r--r--backend/src/llvm/llvm_bitcode_link.cpp25
-rw-r--r--backend/src/llvm/llvm_gen_backend.cpp22
-rw-r--r--backend/src/llvm/llvm_passes.cpp4
-rw-r--r--backend/src/llvm/llvm_to_gen.cpp16
-rw-r--r--backend/src/llvm/llvm_unroll.cpp14
7 files changed, 90 insertions, 5 deletions
diff --git a/backend/src/backend/gen_program.cpp b/backend/src/backend/gen_program.cpp
index 621a42b1..6ad5eef0 100644
--- a/backend/src/backend/gen_program.cpp
+++ b/backend/src/backend/gen_program.cpp
@@ -248,9 +248,15 @@ namespace gbe {
llvm::StringRef llvm_bin_str(binary_content);
llvm::LLVMContext& c = llvm::getGlobalContext();
llvm::SMDiagnostic Err;
+#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6
+ std::unique_ptr<llvm::MemoryBuffer> memory_buffer = llvm::MemoryBuffer::getMemBuffer(llvm_bin_str, "llvm_bin_str");
+ acquireLLVMContextLock();
+ llvm::Module* module = llvm::parseIR(memory_buffer->getMemBufferRef(), Err, c).release();
+#else
llvm::MemoryBuffer* memory_buffer = llvm::MemoryBuffer::getMemBuffer(llvm_bin_str, "llvm_bin_str");
acquireLLVMContextLock();
llvm::Module* module = llvm::ParseIR(memory_buffer, Err, c);
+#endif
releaseLLVMContextLock();
if(module == NULL){
GBE_ASSERT(0);
@@ -374,7 +380,11 @@ namespace gbe {
llvm::Module* src = (llvm::Module*)((GenProgram*)src_program)->module;
llvm::Module* dst = (llvm::Module*)((GenProgram*)dst_program)->module;
+#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5
if (LLVMLinkModules(wrap(dst), wrap(src), LLVMLinkerPreserveSource, &errMsg)) {
+#else
+ if (LLVMLinkModules(wrap(dst), wrap(src), 0, &errMsg)) {
+#endif
if (err != NULL && errSize != NULL && stringSize > 0u) {
if(strlen(errMsg) < stringSize )
stringSize = strlen(errMsg);
diff --git a/backend/src/backend/program.cpp b/backend/src/backend/program.cpp
index 38ce9c83..06810bdb 100644
--- a/backend/src/backend/program.cpp
+++ b/backend/src/backend/program.cpp
@@ -621,7 +621,11 @@ namespace gbe {
if (!retVal)
return false;
+#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5
llvm::Module *module = Act->takeModule();
+#else
+ llvm::Module *module = Act->takeModule().release();
+#endif
*out_module = module;
return true;
diff --git a/backend/src/llvm/llvm_bitcode_link.cpp b/backend/src/llvm/llvm_bitcode_link.cpp
index 8eb6dd52..229e3bb5 100644
--- a/backend/src/llvm/llvm_bitcode_link.cpp
+++ b/backend/src/llvm/llvm_bitcode_link.cpp
@@ -63,7 +63,11 @@ namespace gbe
}
assert(findBC);
+#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5
oclLib = getLazyIRFileModule(FilePath, Err, ctx);
+#else
+ oclLib = getLazyIRFileModule(FilePath, Err, ctx).release();
+#endif
if (!oclLib) {
printf("Fatal Error: ocl lib can not be opened\n");
return NULL;
@@ -114,12 +118,18 @@ namespace gbe
std::string ErrInfo;// = "Not Materializable";
if (!fromSrc && newMF->isMaterializable()) {
+#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5
if (newMF->Materialize(&ErrInfo)) {
printf("Can not materialize the function: %s, because %s\n", fnName.c_str(), ErrInfo.c_str());
return false;
}
+#else
+ if (std::error_code EC = newMF->materialize()) {
+ printf("Can not materialize the function: %s, because %s\n", fnName.c_str(), EC.message().c_str());
+ return false;
+ }
+#endif
}
-
if (!materializedFuncCall(src, lib, *newMF, MFS))
return false;
@@ -205,12 +215,21 @@ namespace gbe
}
std::string ErrInfo;// = "Not Materializable";
if (newMF->isMaterializable()) {
+#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5
if (newMF->Materialize(&ErrInfo)) {
printf("Can not materialize the function: %s, because %s\n", fnName.c_str(), ErrInfo.c_str());
delete clonedLib;
return NULL;
}
}
+#else
+ if (std::error_code EC = newMF->materialize()) {
+ printf("Can not materialize the function: %s, because %s\n", fnName.c_str(), EC.message().c_str();
+ delete clonedLib;
+ return NULL;
+ }
+ }
+#endif
if (!materializedFuncCall(*mod, *clonedLib, *newMF, materializedFuncs)) {
delete clonedLib;
@@ -223,7 +242,11 @@ namespace gbe
/* We use beignet's bitcode as dst because it will have a lot of
lazy functions which will not be loaded. */
char* errorMsg;
+#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5
if(LLVMLinkModules(wrap(clonedLib), wrap(mod), LLVMLinkerDestroySource, &errorMsg)) {
+#else
+ if(LLVMLinkModules(wrap(clonedLib), wrap(mod), 0, &errorMsg)) {
+#endif
delete clonedLib;
printf("Fatal Error: link the bitcode error:\n%s\n", errorMsg);
return NULL;
diff --git a/backend/src/llvm/llvm_gen_backend.cpp b/backend/src/llvm/llvm_gen_backend.cpp
index 5eed85e5..296441f2 100644
--- a/backend/src/llvm/llvm_gen_backend.cpp
+++ b/backend/src/llvm/llvm_gen_backend.cpp
@@ -1467,7 +1467,12 @@ error:
/* First find the meta data belong to this function. */
for(uint i = 0; i < clKernelMetaDatas->getNumOperands(); i++) {
node = clKernelMetaDatas->getOperand(i);
+#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5
if (node->getOperand(0) == &F) break;
+#else
+ auto *V = cast<ValueAsMetadata>(node->getOperand(0));
+ if (V && V->getValue() == &F) break;
+#endif
node = NULL;
}
@@ -1484,9 +1489,15 @@ error:
if (attrName->getString() == "reqd_work_group_size") {
GBE_ASSERT(attrNode->getNumOperands() == 4);
+#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5
ConstantInt *x = dyn_cast<ConstantInt>(attrNode->getOperand(1));
ConstantInt *y = dyn_cast<ConstantInt>(attrNode->getOperand(2));
ConstantInt *z = dyn_cast<ConstantInt>(attrNode->getOperand(3));
+#else
+ ConstantInt *x = mdconst::extract<ConstantInt>(attrNode->getOperand(1));
+ ConstantInt *y = mdconst::extract<ConstantInt>(attrNode->getOperand(2));
+ ConstantInt *z = mdconst::extract<ConstantInt>(attrNode->getOperand(3));
+#endif
GBE_ASSERT(x && y && z);
reqd_wg_sz[0] = x->getZExtValue();
reqd_wg_sz[1] = y->getZExtValue();
@@ -1521,9 +1532,15 @@ error:
functionAttributes += " ";
} else if (attrName->getString() == "work_group_size_hint") {
GBE_ASSERT(attrNode->getNumOperands() == 4);
+#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5
ConstantInt *x = dyn_cast<ConstantInt>(attrNode->getOperand(1));
ConstantInt *y = dyn_cast<ConstantInt>(attrNode->getOperand(2));
ConstantInt *z = dyn_cast<ConstantInt>(attrNode->getOperand(3));
+#else
+ ConstantInt *x = mdconst::extract<ConstantInt>(attrNode->getOperand(1));
+ ConstantInt *y = mdconst::extract<ConstantInt>(attrNode->getOperand(2));
+ ConstantInt *z = mdconst::extract<ConstantInt>(attrNode->getOperand(3));
+#endif
GBE_ASSERT(x && y && z);
hint_wg_sz[0] = x->getZExtValue();
hint_wg_sz[1] = y->getZExtValue();
@@ -1561,8 +1578,11 @@ error:
for (; I != E; ++I, ++argID) {
const std::string &argName = I->getName().str();
Type *type = I->getType();
-
+#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5
llvmInfo.addrSpace = (cast<ConstantInt>(addrSpaceNode->getOperand(1 + argID)))->getZExtValue();
+#else
+ llvmInfo.addrSpace = (mdconst::extract<ConstantInt>(addrSpaceNode->getOperand(1 + argID)))->getZExtValue();
+#endif
llvmInfo.typeName = (cast<MDString>(typeNameNode->getOperand(1 + argID)))->getString();
llvmInfo.accessQual = (cast<MDString>(accessQualNode->getOperand(1 + argID)))->getString();
llvmInfo.typeQual = (cast<MDString>(typeQualNode->getOperand(1 + argID)))->getString();
diff --git a/backend/src/llvm/llvm_passes.cpp b/backend/src/llvm/llvm_passes.cpp
index d315d532..935cdcf1 100644
--- a/backend/src/llvm/llvm_passes.cpp
+++ b/backend/src/llvm/llvm_passes.cpp
@@ -119,7 +119,11 @@ namespace gbe
uint32_t ops = md.getNumOperands();
for(uint32_t x = 0; x < ops; x++) {
MDNode* node = md.getOperand(x);
+#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5
Value * op = node->getOperand(0);
+#else
+ Value * op = cast<ValueAsMetadata>(node->getOperand(0))->getValue();
+#endif
if(op == &F) bKernel = true;
}
}
diff --git a/backend/src/llvm/llvm_to_gen.cpp b/backend/src/llvm/llvm_to_gen.cpp
index 3dbdf559..89a22b69 100644
--- a/backend/src/llvm/llvm_to_gen.cpp
+++ b/backend/src/llvm/llvm_to_gen.cpp
@@ -80,7 +80,9 @@ namespace gbe
{
FunctionPassManager FPM(&mod);
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 5
+#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6
+ FPM.add(new DataLayoutPass());
+#elif LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR == 5
FPM.add(new DataLayoutPass(DL));
#else
FPM.add(new DataLayout(DL));
@@ -111,7 +113,9 @@ namespace gbe
{
llvm::PassManager MPM;
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 5
+#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6
+ MPM.add(new DataLayoutPass());
+#elif LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR == 5
MPM.add(new DataLayoutPass(DL));
#else
MPM.add(new DataLayout(DL));
@@ -230,7 +234,11 @@ namespace gbe
cl_mod = reinterpret_cast<Module*>(const_cast<void*>(module));
} else if (fileName){
llvm::LLVMContext& c = llvm::getGlobalContext();
+#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6
+ cl_mod = parseIRFile(fileName, Err, c).release();
+#else
cl_mod = ParseIRFile(fileName, Err, c);
+#endif
}
if (!cl_mod) return false;
@@ -258,7 +266,9 @@ namespace gbe
runFuntionPass(mod, libraryInfo, DL);
runModulePass(mod, libraryInfo, DL, optLevel, strictMath);
llvm::PassManager passes;
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 5
+#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6
+ passes.add(new DataLayoutPass());
+#elif LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR == 5
passes.add(new DataLayoutPass(DL));
#else
passes.add(new DataLayout(DL));
diff --git a/backend/src/llvm/llvm_unroll.cpp b/backend/src/llvm/llvm_unroll.cpp
index 172e724c..5d3fad88 100644
--- a/backend/src/llvm/llvm_unroll.cpp
+++ b/backend/src/llvm/llvm_unroll.cpp
@@ -95,7 +95,11 @@ namespace gbe {
if (Name.equals(S->getString())) {
assert(MD->getNumOperands() == 2 &&
"Unroll hint metadata should have two operands.");
+#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6
+ return mdconst::extract<ConstantInt>(MD->getOperand(1));
+#else
return cast<ConstantInt>(MD->getOperand(1));
+#endif
}
}
return nullptr;
@@ -105,6 +109,15 @@ namespace gbe {
if (!enable && disabledLoops.find(L) != disabledLoops.end())
return;
LLVMContext &Context = L->getHeader()->getContext();
+#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6
+ SmallVector<Metadata *, 2> forceUnroll;
+ forceUnroll.push_back(MDString::get(Context, "llvm.loop.unroll.enable"));
+ forceUnroll.push_back(ConstantAsMetadata::get(ConstantInt::get(Type::getInt1Ty(Context), enable)));
+ MDNode *forceUnrollNode = MDNode::get(Context, forceUnroll);
+ SmallVector<Metadata *, 4> Vals;
+ Vals.push_back(NULL);
+ Vals.push_back(forceUnrollNode);
+#else
SmallVector<Value *, 2> forceUnroll;
forceUnroll.push_back(MDString::get(Context, "llvm.loop.unroll.enable"));
forceUnroll.push_back(ConstantInt::get(Type::getInt1Ty(Context), enable));
@@ -112,6 +125,7 @@ namespace gbe {
SmallVector<Value *, 4> Vals;
Vals.push_back(NULL);
Vals.push_back(forceUnrollNode);
+#endif
MDNode *NewLoopID = MDNode::get(Context, Vals);
// Set operand 0 to refer to the loop id itself.
NewLoopID->replaceOperandWith(0, NewLoopID);