[Beignet] [Patch V2 2/2] Add llvm3.6 build support.
Zhigang Gong
zhigang.gong at linux.intel.com
Wed Feb 11 00:26:14 PST 2015
Some minor comments as below:
On Wed, Feb 11, 2015 at 03:44:58PM +0800, Yang Rong wrote:
> 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.
> Signed-off-by: Yang Rong <rong.r.yang at intel.com>
> ---
> backend/src/backend/gen_program.cpp | 10 ++++++++++
> backend/src/backend/program.cpp | 4 ++++
> backend/src/llvm/llvm_bitcode_link.cpp | 35 ++++++++++++++++++++++++++++++----
> backend/src/llvm/llvm_gen_backend.cpp | 23 ++++++++++++++++++++--
> backend/src/llvm/llvm_passes.cpp | 5 ++++-
> backend/src/llvm/llvm_to_gen.cpp | 16 +++++++++++++---
> backend/src/llvm/llvm_unroll.cpp | 14 ++++++++++++++
> 7 files changed, 97 insertions(+), 10 deletions(-)
>
> diff --git a/backend/src/backend/gen_program.cpp b/backend/src/backend/gen_program.cpp
> index 4cfb703..5d36975 100644
> --- a/backend/src/backend/gen_program.cpp
> +++ b/backend/src/backend/gen_program.cpp
> @@ -257,9 +257,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);
> @@ -386,10 +392,14 @@ namespace gbe {
> }else{
> 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 >= 6
> + llvm::Linker::LinkModules(dst, src);
Then how to get back the errMsg with LLVM 3.6?
> +#else
> llvm::Linker::LinkModules( dst,
> src,
> llvm::Linker::PreserveSource,
> &errMsg);
> +#endif
> if (errMsg.c_str() != NULL) {
> if (err != NULL && errSize != NULL && stringSize > 0u) {
> if(errMsg.length() < stringSize )
> diff --git a/backend/src/backend/program.cpp b/backend/src/backend/program.cpp
> index 38ce9c8..06810bd 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 d3058d6..f67ebe0 100644
> --- a/backend/src/llvm/llvm_bitcode_link.cpp
> +++ b/backend/src/llvm/llvm_bitcode_link.cpp
> @@ -67,7 +67,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;
> @@ -110,20 +114,26 @@ namespace gbe
> if (!newMF) {
> newMF = src.getFunction(fnName);
> if (!newMF) {
> - printf("Can not find the lib: %s\n", fnName.c_str());
> - return false;
> + printf("Can not find the lib: %s\n", fnName.c_str());
> + return false;
> }
> - fromSrc = true;
> + fromSrc = true;
> }
>
> 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 (newMF->materialize()) {
The same concern as the above one, then we will not know the reason why it fail? Or
is there any other mechanism to get it? Also the same concerns for the following
similar calls.
> + printf("Can not materialize the function: %s\n", fnName.c_str());
> + return false;
> + }
> +#endif
> }
> -
> if (!materializedFuncCall(src, lib, *newMF, MFS))
> return false;
>
> @@ -209,12 +219,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 (newMF->materialize()) {
> + printf("Can not materialize the function: %s\n", fnName.c_str());
> + delete clonedLib;
> + return NULL;
> + }
> + }
> +#endif
>
> if (!materializedFuncCall(*mod, *clonedLib, *newMF, materializedFuncs)) {
> delete clonedLib;
> @@ -227,11 +246,19 @@ namespace gbe
> /* We use beignet's bitcode as dst because it will have a lot of
> lazy functions which will not be loaded. */
> std::string errorMsg;
> +#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5
> if(Linker::LinkModules(clonedLib, mod, Linker::DestroySource, &errorMsg)) {
> delete clonedLib;
> printf("Fatal Error: link the bitcode error:\n%s\n", errorMsg.c_str());
> return NULL;
> }
> +#else
> + if(Linker::LinkModules(clonedLib, mod)) {
> + delete clonedLib;
> + printf("Fatal Error: link the bitcode error:\n");
> + return NULL;
> + }
> +#endif
>
> llvm::PassManager passes;
>
> diff --git a/backend/src/llvm/llvm_gen_backend.cpp b/backend/src/llvm/llvm_gen_backend.cpp
> index d47721a..de846cb 100644
> --- a/backend/src/llvm/llvm_gen_backend.cpp
> +++ b/backend/src/llvm/llvm_gen_backend.cpp
> @@ -100,7 +100,6 @@
> #include "llvm/ADT/SmallString.h"
> #include "llvm/ADT/STLExtras.h"
> #include "llvm/Analysis/ConstantsScanner.h"
> -#include "llvm/Analysis/FindUsedTypes.h"
> #include "llvm/Analysis/LoopInfo.h"
> #include "llvm/Analysis/ValueTracking.h"
> #include "llvm/CodeGen/Passes.h"
> @@ -1467,7 +1466,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 +1488,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 +1531,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 +1577,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 5c0a2e0..1b40389 100644
> --- a/backend/src/llvm/llvm_passes.cpp
> +++ b/backend/src/llvm/llvm_passes.cpp
> @@ -59,7 +59,6 @@
> #include "llvm/ADT/SmallString.h"
> #include "llvm/ADT/STLExtras.h"
> #include "llvm/Analysis/ConstantsScanner.h"
> -#include "llvm/Analysis/FindUsedTypes.h"
If this header file is not needed for both 3.3/3.4 and 3.5, it's better to use
a separate patch to remove it.
The other part LGTM.
Thanks,
Zhigang Gong.
More information about the Beignet
mailing list