FreeBSD Bugzilla – Attachment 181768 Details for
Bug 218644
fix build lang/beignet with llvm 4.0
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
fix build lang/beignet with llvm 4.0
patch-lang_beignet.diff (text/plain), 120.29 KB, created by
Eric Camachat
on 2017-04-13 19:59:56 UTC
(
hide
)
Description:
fix build lang/beignet with llvm 4.0
Filename:
MIME Type:
Creator:
Eric Camachat
Created:
2017-04-13 19:59:56 UTC
Size:
120.29 KB
patch
obsolete
>Index: lang/beignet/Makefile >=================================================================== >--- lang/beignet/Makefile (revision 438411) >+++ lang/beignet/Makefile (working copy) >@@ -47,7 +47,15 @@ > @${REINPLACE_CMD} -e 's|llvm-dis|llvm-dis${LLVMVER}|g; \ > s|clang |clang${LLVMVER} |g' \ > ${WRKSRC}/backend/kernels/compile.sh >+.if ${LLVMVER} >= 40 >+ ${CAT} \ >+ ${PATCHDIR}/extra-patch-remove_old_llvm_support \ >+ ${PATCHDIR}/extra-patch-refine_llvm_version_check \ >+ ${PATCHDIR}/extra-patch-add_llvm40_support | \ >+ ${PATCH} -E -p1 -d ${WRKSRC} >+.endif > >+ > # XXX bug 213732: compiler_fill_gl_image() [FAILED] > do-test-TEST-on: > -@(cd ${TEST_WRKSRC}/utests; . ./setenv.sh; \ >Index: lang/beignet/files/extra-patch-add_llvm40_support >=================================================================== >--- lang/beignet/files/extra-patch-add_llvm40_support (nonexistent) >+++ lang/beignet/files/extra-patch-add_llvm40_support (working copy) >@@ -0,0 +1,690 @@ >+From 919deced0cd796e30410d45fc71bcda37441e80c Mon Sep 17 00:00:00 2001 >+From: Pan Xiuli <xiuli.pan@intel.com> >+Date: Tue, 11 Apr 2017 15:59:50 +0800 >+Subject: Backend: Add LLVM40 support >+ >+1.Refine APFloat fltSemantics. >+2.Refine bitcode read/write header. >+3.Refine clang invocation. >+4.Refine return llvm::error handler. >+5.Refine ilist_iterator usage. >+6.Refine CFG Printer pass manager. >+7.Refine GEP with pointer type changing. >+8.Refine libocl 20 support >+V2: Add missing ocl_sampler.ll and ocl_sampler_20.ll file >+V3: Fix some build problem for llvm36 >+ >+Signed-off-by: Pan Xiuli <xiuli.pan@intel.com> >+Reviewed-by: Yang Rong <rong.r.yang@intel.com> >+ >+diff --git a/backend/src/backend/gen_program.cpp b/backend/src/backend/gen_program.cpp >+index 998e340..c1827b1 100644 >+--- a/backend/src/backend/gen_program.cpp >++++ b/backend/src/backend/gen_program.cpp >+@@ -29,7 +29,11 @@ >+ #include "llvm/IR/DataLayout.h" >+ #include "llvm-c/Linker.h" >+ #include "llvm/Transforms/Utils/Cloning.h" >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40 >++#include "llvm/Bitcode/BitcodeWriter.h" >++#else >+ #include "llvm/Bitcode/ReaderWriter.h" >++#endif /* LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40 */ >+ #include "llvm/Support/raw_ostream.h" >+ #include "llvm/ADT/StringRef.h" >+ #include "llvm/Support/MemoryBuffer.h" >+diff --git a/backend/src/backend/program.cpp b/backend/src/backend/program.cpp >+index 6e8227a..724058c 100644 >+--- a/backend/src/backend/program.cpp >++++ b/backend/src/backend/program.cpp >+@@ -62,7 +62,13 @@ >+ #include <clang/Basic/TargetOptions.h> >+ #include <llvm/ADT/IntrusiveRefCntPtr.h> >+ #include <llvm/IR/Module.h> >++ >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40 >++#include <llvm/Bitcode/BitcodeWriter.h> >++#include <clang/Lex/PreprocessorOptions.h> >++#else >+ #include <llvm/Bitcode/ReaderWriter.h> >++#endif >+ #include <llvm/Support/raw_ostream.h> >+ #endif >+ >+@@ -694,14 +700,15 @@ namespace gbe { >+ llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> DiagID(new clang::DiagnosticIDs()); >+ clang::DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagClient); >+ >++ llvm::StringRef srcString(source); >+ // Create the compiler invocation >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40 >++ auto CI = std::make_shared<clang::CompilerInvocation>(); >++ CI->getPreprocessorOpts().addRemappedFile("stringInput.cl", >++#else >+ std::unique_ptr<clang::CompilerInvocation> CI(new clang::CompilerInvocation); >+- clang::CompilerInvocation::CreateFromArgs(*CI, >+- &args[0], >+- &args[0] + args.size(), >+- Diags); >+- llvm::StringRef srcString(source); >+ (*CI).getPreprocessorOpts().addRemappedFile("stringInput.cl", >++#endif >+ #if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35 >+ llvm::MemoryBuffer::getMemBuffer(srcString) >+ #else >+@@ -709,9 +716,17 @@ namespace gbe { >+ #endif >+ ); >+ >++ clang::CompilerInvocation::CreateFromArgs(*CI, >++ &args[0], >++ &args[0] + args.size(), >++ Diags); >+ // Create the compiler instance >+ clang::CompilerInstance Clang; >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40 >++ Clang.setInvocation(std::move(CI)); >++#else >+ Clang.setInvocation(CI.release()); >++#endif >+ // Get ready to report problems >+ Clang.createDiagnostics(DiagClient, false); >+ >+diff --git a/backend/src/ir/half.cpp b/backend/src/ir/half.cpp >+index 1c0d7eb..0abc6cb 100644 >+--- a/backend/src/ir/half.cpp >++++ b/backend/src/ir/half.cpp >+@@ -29,7 +29,11 @@ namespace ir { >+ { >+ uint64_t v64 = static_cast<uint64_t>(v); >+ llvm::APInt apInt(16, v64, false); >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40 >++ return llvm::APFloat(llvm::APFloat::IEEEhalf(), apInt); >++#else >+ return llvm::APFloat(llvm::APFloat::IEEEhalf, apInt); >++#endif >+ } >+ >+ static uint16_t convAPFloatToU16(const llvm::APFloat& apf) >+@@ -42,14 +46,22 @@ namespace ir { >+ half::operator float(void) const { >+ bool loseInfo; >+ llvm::APFloat apf_self = convU16ToAPFloat(this->val); >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40 >++ apf_self.convert(llvm::APFloat::IEEEsingle(), llvm::APFloat::rmNearestTiesToEven, &loseInfo); >++#else >+ apf_self.convert(llvm::APFloat::IEEEsingle, llvm::APFloat::rmNearestTiesToEven, &loseInfo); >++#endif >+ return apf_self.convertToFloat(); >+ } >+ >+ half::operator double(void) const { >+ bool loseInfo; >+ llvm::APFloat apf_self = convU16ToAPFloat(this->val); >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40 >++ apf_self.convert(llvm::APFloat::IEEEdouble(), llvm::APFloat::rmNearestTiesToEven, &loseInfo); >++#else >+ apf_self.convert(llvm::APFloat::IEEEdouble, llvm::APFloat::rmNearestTiesToEven, &loseInfo); >++#endif >+ return apf_self.convertToDouble(); >+ } >+ >+@@ -70,7 +82,11 @@ namespace ir { >+ } >+ >+ half half::convToHalf(uint16_t u16) { >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40 >++ llvm::APFloat res(llvm::APFloat::IEEEhalf(), llvm::APInt(16, 0, false)); >++#else >+ llvm::APFloat res(llvm::APFloat::IEEEhalf, llvm::APInt(16, 0, false)); >++#endif >+ uint64_t u64 = static_cast<uint64_t>(u16); >+ llvm::APInt apInt(16, u64, false); >+ res.convertFromAPInt(apInt, false, llvm::APFloat::rmNearestTiesToEven); >+@@ -78,7 +94,11 @@ namespace ir { >+ } >+ >+ half half::convToHalf(int16_t v16) { >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40 >++ llvm::APFloat res(llvm::APFloat::IEEEhalf(), llvm::APInt(16, 0, true)); >++#else >+ llvm::APFloat res(llvm::APFloat::IEEEhalf, llvm::APInt(16, 0, true)); >++#endif >+ uint64_t u64 = static_cast<uint64_t>(v16); >+ llvm::APInt apInt(16, u64, true); >+ res.convertFromAPInt(apInt, true, llvm::APFloat::rmNearestTiesToEven); >+diff --git a/backend/src/libocl/CMakeLists.txt b/backend/src/libocl/CMakeLists.txt >+index c68ecb0..2917e6d 100644 >+--- a/backend/src/libocl/CMakeLists.txt >++++ b/backend/src/libocl/CMakeLists.txt >+@@ -211,7 +211,7 @@ MACRO(ADD_LL_TO_BC_TARGET M) >+ ) >+ ENDMACRO(ADD_LL_TO_BC_TARGET) >+ >+-SET (OCL_LL_MODULES_12 ocl_barrier ocl_clz ocl_ctz) >++SET (OCL_LL_MODULES_12 ocl_barrier ocl_clz ocl_ctz ocl_sampler) >+ FOREACH(f ${OCL_LL_MODULES_12}) >+ COPY_THE_LL(${f}) >+ ADD_LL_TO_BC_TARGET(${f}) >+@@ -255,7 +255,7 @@ if (ENABLE_OPENCL_20) >+ ADD_CL_TO_BC_TARGET(${f} ${bc_name} "${CLANG_OCL_FLAGS_20}") >+ ENDFOREACH(f) >+ >+- SET (OCL_LL_MODULES_20 ocl_barrier_20 ocl_clz_20 ocl_ctz_20 ocl_atomic_20) >++ SET (OCL_LL_MODULES_20 ocl_barrier_20 ocl_clz_20 ocl_ctz_20 ocl_atomic_20 ocl_sampler_20) >+ FOREACH(f ${OCL_LL_MODULES_20}) >+ COPY_THE_LL(${f}) >+ ADD_LL_TO_BC_TARGET(${f}) >+diff --git a/backend/src/libocl/include/ocl_enqueue.h b/backend/src/libocl/include/ocl_enqueue.h >+index 6479df7..7ccab59 100644 >+--- a/backend/src/libocl/include/ocl_enqueue.h >++++ b/backend/src/libocl/include/ocl_enqueue.h >+@@ -38,7 +38,7 @@ struct Block_literal { >+ void *isa; // initialized to &_NSConcreteStackBlock or &_NSConcreteGlobalBlock >+ int flags; >+ int reserved; >+- __global void (*invoke)(void *, ...); >++ __global void* invoke; >+ struct Block_descriptor_1 { >+ unsigned long int reserved; // NULL >+ unsigned long int size; // sizeof(struct Block_literal_1) >+@@ -65,10 +65,6 @@ OVERLOADABLE int enqueue_kernel(queue_t q, int flag, ndrange_t ndrange, void (^b >+ OVERLOADABLE int enqueue_kernel(queue_t q, int flag, ndrange_t ndrange, >+ uint num_events_in_wait_list, const clk_event_t *event_wait_list, >+ clk_event_t *event_ret, void (^block)(void)); >+-OVERLOADABLE int enqueue_kernel(queue_t q, int flag, ndrange_t ndrange, __private void *block, uint size0, ...); >+-OVERLOADABLE int enqueue_kernel(queue_t q, int flag, ndrange_t ndrange, >+- uint num_events_in_wait_list, const clk_event_t *event_wait_list, >+- clk_event_t *event_ret, __private void *block, uint size0, ...); >+ >+ queue_t get_default_queue(void); >+ int __gen_enqueue_kernel(queue_t q, int flag, ndrange_t ndrange, void (^block)(void), int size); >+diff --git a/backend/src/libocl/src/ocl_image.cl b/backend/src/libocl/src/ocl_image.cl >+index 2febfda..e66aa15 100644 >+--- a/backend/src/libocl/src/ocl_image.cl >++++ b/backend/src/libocl/src/ocl_image.cl >+@@ -295,17 +295,18 @@ GEN_VALIDATE_ARRAY_INDEX(int, read_write image1d_buffer_t) >+ // The work around is to use a LD message instead of normal sample message. >+ /////////////////////////////////////////////////////////////////////////////// >+ >+-bool __gen_ocl_sampler_need_fix(sampler_t); >+-bool __gen_ocl_sampler_need_rounding_fix(sampler_t); >++bool __gen_ocl_sampler_need_fix(int); >++bool __gen_ocl_sampler_need_rounding_fix(int); >++int __gen_ocl_sampler_to_int(sampler_t); >+ >+ bool __gen_sampler_need_fix(const sampler_t sampler) >+ { >+- return __gen_ocl_sampler_need_fix(sampler); >++ return __gen_ocl_sampler_need_fix(__gen_ocl_sampler_to_int(sampler)); >+ } >+ >+ bool __gen_sampler_need_rounding_fix(const sampler_t sampler) >+ { >+- return __gen_ocl_sampler_need_rounding_fix(sampler); >++ return __gen_ocl_sampler_need_rounding_fix(__gen_ocl_sampler_to_int(sampler)); >+ } >+ >+ INLINE_OVERLOADABLE float __gen_fixup_float_coord(float tmpCoord) >+diff --git a/backend/src/libocl/src/ocl_sampler.ll b/backend/src/libocl/src/ocl_sampler.ll >+new file mode 100644 >+index 0000000..6d39fdb >+--- /dev/null >++++ b/backend/src/libocl/src/ocl_sampler.ll >+@@ -0,0 +1,10 @@ >++target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" >++target triple = "spir" >++%opencl.sampler_t = type opaque >++ >++declare %opencl.sampler_t addrspace(2)*@__gen_ocl_int_to_sampler(i32) >++ >++define %opencl.sampler_t addrspace(2)*@__translate_sampler_initializer(i32 %s) { >++ %call = call %opencl.sampler_t addrspace(2)*@__gen_ocl_int_to_sampler(i32 %s) >++ ret %opencl.sampler_t addrspace(2)* %call >++} >+diff --git a/backend/src/libocl/src/ocl_sampler_20.ll b/backend/src/libocl/src/ocl_sampler_20.ll >+new file mode 100644 >+index 0000000..bea6d75 >+--- /dev/null >++++ b/backend/src/libocl/src/ocl_sampler_20.ll >+@@ -0,0 +1,10 @@ >++target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" >++target triple = "spir64" >++%opencl.sampler_t = type opaque >++ >++declare %opencl.sampler_t addrspace(2)*@__gen_ocl_int_to_sampler(i32) >++ >++define %opencl.sampler_t addrspace(2)*@__translate_sampler_initializer(i32 %s) { >++ %call = call %opencl.sampler_t addrspace(2)*@__gen_ocl_int_to_sampler(i32 %s) >++ ret %opencl.sampler_t addrspace(2)* %call >++} >+diff --git a/backend/src/llvm/ExpandUtils.cpp b/backend/src/llvm/ExpandUtils.cpp >+index a09d990..cb1736b 100644 >+--- a/backend/src/llvm/ExpandUtils.cpp >++++ b/backend/src/llvm/ExpandUtils.cpp >+@@ -101,7 +101,11 @@ namespace llvm { >+ Function *RecreateFunction(Function *Func, FunctionType *NewType) { >+ Function *NewFunc = Function::Create(NewType, Func->getLinkage()); >+ NewFunc->copyAttributesFrom(Func); >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40 >++ Func->getParent()->getFunctionList().insert(Func->getIterator(), NewFunc); >++#else >+ Func->getParent()->getFunctionList().insert(ilist_iterator<Function>(Func), NewFunc); >++#endif >+ NewFunc->takeName(Func); >+ NewFunc->getBasicBlockList().splice(NewFunc->begin(), >+ Func->getBasicBlockList()); >+diff --git a/backend/src/llvm/llvm_barrier_nodup.cpp b/backend/src/llvm/llvm_barrier_nodup.cpp >+index 727e6bd..a7d0d1a 100644 >+--- a/backend/src/llvm/llvm_barrier_nodup.cpp >++++ b/backend/src/llvm/llvm_barrier_nodup.cpp >+@@ -48,7 +48,12 @@ namespace gbe { >+ >+ } >+ >+- virtual const char *getPassName() const { >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40 >++ virtual StringRef getPassName() const >++#else >++ virtual const char *getPassName() const >++#endif >++ { >+ return "SPIR backend: set barrier no duplicate attr"; >+ } >+ >+diff --git a/backend/src/llvm/llvm_bitcode_link.cpp b/backend/src/llvm/llvm_bitcode_link.cpp >+index 869db89..5c6585d 100644 >+--- a/backend/src/llvm/llvm_bitcode_link.cpp >++++ b/backend/src/llvm/llvm_bitcode_link.cpp >+@@ -117,17 +117,28 @@ namespace gbe >+ >+ std::string ErrInfo;// = "Not Materializable"; >+ if (!fromSrc && newMF->isMaterializable()) { >+-#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35 >+- if (newMF->Materialize(&ErrInfo)) { >+- printf("Can not materialize the function: %s, because %s\n", fnName.c_str(), ErrInfo.c_str()); >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40 >++ if (llvm::Error EC = newMF->materialize()) { >++ std::string Msg; >++ handleAllErrors(std::move(EC), [&](ErrorInfoBase &EIB) { >++ Msg = EIB.message(); >++ }); >++ printf("Can not materialize the function: %s, because %s\n", fnName.c_str(), Msg.c_str()); >+ return false; >+ } >+-#else >++ Gvs.push_back((GlobalValue *)newMF); >++#elif LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 36 >+ 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; >+ } >+ Gvs.push_back((GlobalValue *)newMF); >++#else >++ if (newMF->Materialize(&ErrInfo)) { >++ printf("Can not materialize the function: %s, because %s\n", fnName.c_str(), ErrInfo.c_str()); >++ return false; >++ } >++ >+ #endif >+ } >+ if (!materializedFuncCall(src, lib, *newMF, MFS, Gvs)) >+@@ -250,21 +261,30 @@ namespace gbe >+ } >+ std::string ErrInfo;// = "Not Materializable"; >+ if (newMF->isMaterializable()) { >+-#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35 >+- if (newMF->Materialize(&ErrInfo)) { >+- printf("Can not materialize the function: %s, because %s\n", fnName.c_str(), ErrInfo.c_str()); >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40 >++ if (llvm::Error EC = newMF->materialize()) { >++ std::string Msg; >++ handleAllErrors(std::move(EC), [&](ErrorInfoBase &EIB) { >++ Msg = EIB.message(); >++ }); >++ printf("Can not materialize the function: %s, because %s\n", fnName.c_str(), Msg.c_str()); >+ delete clonedLib; >+ return NULL; >+ } >+- } >+-#else >++#elif LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 36 >+ 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; >+ } >+- } >++#else >++ if (newMF->Materialize(&ErrInfo)) { >++ printf("Can not materialize the function: %s, because %s\n", fnName.c_str(), ErrInfo.c_str()); >++ delete clonedLib; >++ return NULL; >++ } >+ #endif >++ } >+ >+ if (!materializedFuncCall(*mod, *clonedLib, *newMF, materializedFuncs, Gvs)) { >+ delete clonedLib; >+@@ -292,7 +312,12 @@ namespace gbe >+ Module::GlobalListType &GVlist = clonedLib->getGlobalList(); >+ for(Module::global_iterator GVitr = GVlist.begin();GVitr != GVlist.end();++GVitr) { >+ GlobalValue * GV = &*GVitr; >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40 >++ ExitOnError ExitOnErr("Can not materialize the clonedLib: "); >++ ExitOnErr(clonedLib->materialize(GV)); >++#else >+ clonedLib->materialize(GV); >++#endif >+ Gvs.push_back(GV); >+ } >+ llvm::legacy::PassManager Extract; >+@@ -300,8 +325,13 @@ namespace gbe >+ Extract.add(createGVExtractionPass(Gvs, false)); >+ Extract.run(*clonedLib); >+ /* Mark the library module as materialized for later use. */ >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40 >++ ExitOnError ExitOnErr("Can not materialize the clonedLib: "); >++ ExitOnErr(clonedLib->materializeAll()); >++#else >+ clonedLib->materializeAll(); >+ #endif >++#endif >+ >+ /* the SPIR binary datalayout maybe different with beignet's bitcode */ >+ if(clonedLib->getDataLayout() != mod->getDataLayout()) >+@@ -309,14 +339,14 @@ 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 * 10 + LLVM_VERSION_MINOR >= 39 >+ if(LLVMLinkModules2(wrap(clonedLib), wrap(mod))) { >+ #else >++ char* errorMsg; >+ if(LLVMLinkModules(wrap(clonedLib), wrap(mod), LLVMLinkerDestroySource, &errorMsg)) { >++ printf("Fatal Error: link the bitcode error:\n%s\n", errorMsg); >+ #endif >+ delete clonedLib; >+- printf("Fatal Error: link the bitcode error:\n%s\n", errorMsg); >+ return NULL; >+ } >+ #if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37 >+diff --git a/backend/src/llvm/llvm_gen_backend.cpp b/backend/src/llvm/llvm_gen_backend.cpp >+index fa45a42..a106259 100644 >+--- a/backend/src/llvm/llvm_gen_backend.cpp >++++ b/backend/src/llvm/llvm_gen_backend.cpp >+@@ -357,6 +357,15 @@ namespace gbe >+ GBE_ASSERT(! (isa<Constant>(value) && !isa<GlobalValue>(value))); >+ Type *type = value->getType(); >+ auto typeID = type->getTypeID(); >++ if (typeID == Type::PointerTyID) >++ { >++ Type *eltTy = dyn_cast<PointerType>(type)->getElementType(); >++ if (eltTy->isStructTy()) { >++ StructType *strTy = dyn_cast<StructType>(eltTy); >++ if (strTy->getName().data() && strstr(strTy->getName().data(), "sampler")) >++ type = Type::getInt32Ty(value->getContext()); >++ } >++ } >+ switch (typeID) { >+ case Type::IntegerTyID: >+ case Type::FloatTyID: >+@@ -573,7 +582,11 @@ namespace gbe >+ pass = PASS_EMIT_REGISTERS; >+ } >+ >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40 >++ virtual llvm::StringRef getPassName() const { return "Gen Back-End"; } >++#else >+ virtual const char *getPassName() const { return "Gen Back-End"; } >++#endif >+ >+ void getAnalysisUsage(AnalysisUsage &AU) const { >+ #if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37 >+@@ -2410,10 +2423,11 @@ namespace gbe >+ } >+ >+ if (llvmInfo.isSamplerType()) { >+- ctx.input(argName, ir::FunctionArgument::SAMPLER, reg, llvmInfo, getTypeByteSize(unit, type), getAlignmentByte(unit, type), 0); >++ ctx.input(argName, ir::FunctionArgument::SAMPLER, reg, llvmInfo, 4, 4, 0); >+ (void)ctx.getFunction().getSamplerSet()->append(reg, &ctx); >+ continue; >+ } >++ >+ if(llvmInfo.isPipeType()) { >+ llvmInfo.typeSize = getTypeSize(F.getParent(),unit,llvmInfo.typeName); >+ ctx.input(argName, ir::FunctionArgument::PIPE, reg, llvmInfo, getTypeByteSize(unit, type), getAlignmentByte(unit, type), BtiMap.find(&*I)->second); >+@@ -4070,6 +4084,15 @@ namespace gbe >+ regTranslator.newValueProxy(srcValue, dst); >+ break; >+ } >++ case GEN_OCL_INT_TO_SAMPLER: >++ case GEN_OCL_SAMPLER_TO_INT: >++ { >++ Value *srcValue = I.getOperand(0); >++ //srcValue->dump(); >++ //dst->dump(); >++ regTranslator.newValueProxy(srcValue, dst); >++ break; >++ } >+ case GEN_OCL_ENQUEUE_GET_ENQUEUE_INFO_ADDR: >+ regTranslator.newScalarProxy(ir::ocl::enqueuebufptr, dst); >+ break; >+@@ -4576,10 +4599,19 @@ namespace gbe >+ /* append a new sampler. should be called before any reference to >+ * a sampler_t value. */ >+ uint8_t GenWriter::appendSampler(CallSite::arg_iterator AI) { >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40 >++ CallInst *TC = dyn_cast<CallInst>(*AI); >++ Constant *CPV = TC ? dyn_cast<Constant>(TC->getOperand(0)) : NULL; >++#else >+ Constant *CPV = dyn_cast<Constant>(*AI); >++#endif >+ uint8_t index; >+ if (CPV != NULL) >+ { >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40 >++ // Check if the Callee is sampler convert function >++ GBE_ASSERT(TC->getCalledFunction()->getName().str() == "__gen_ocl_int_to_sampler"); >++#endif >+ // This is not a kernel argument sampler, we need to append it to sampler set, >+ // and allocate a sampler slot for it. >+ const ir::Immediate &x = processConstantImm(CPV); >+@@ -5583,6 +5615,8 @@ namespace gbe >+ case GEN_OCL_GET_PIPE: >+ case GEN_OCL_MAKE_RID: >+ case GEN_OCL_GET_RID: >++ case GEN_OCL_INT_TO_SAMPLER: >++ case GEN_OCL_SAMPLER_TO_INT: >+ { >+ break; >+ } >+diff --git a/backend/src/llvm/llvm_gen_ocl_function.hxx b/backend/src/llvm/llvm_gen_ocl_function.hxx >+index 5682c45..b056642 100644 >+--- a/backend/src/llvm/llvm_gen_ocl_function.hxx >++++ b/backend/src/llvm/llvm_gen_ocl_function.hxx >+@@ -279,3 +279,7 @@ DECL_LLVM_GEN_FUNCTION(MAKE_RID, __gen_ocl_make_rid) >+ DECL_LLVM_GEN_FUNCTION(ENQUEUE_SET_NDRANGE_INFO, __gen_ocl_set_ndrange_info) >+ DECL_LLVM_GEN_FUNCTION(ENQUEUE_GET_NDRANGE_INFO, __gen_ocl_get_ndrange_info) >+ DECL_LLVM_GEN_FUNCTION(ENQUEUE_GET_ENQUEUE_INFO_ADDR, __gen_ocl_get_enqueue_info_addr) >++ >++// sampler helper functions >++DECL_LLVM_GEN_FUNCTION(SAMPLER_TO_INT, __gen_ocl_sampler_to_int) >++DECL_LLVM_GEN_FUNCTION(INT_TO_SAMPLER, __gen_ocl_int_to_sampler) >+diff --git a/backend/src/llvm/llvm_includes.hpp b/backend/src/llvm/llvm_includes.hpp >+index a242fd3..184553a 100644 >+--- a/backend/src/llvm/llvm_includes.hpp >++++ b/backend/src/llvm/llvm_includes.hpp >+@@ -24,6 +24,7 @@ >+ #ifndef __GBE_IR_LLVM_INCLUDES_HPP__ >+ #define __GBE_IR_LLVM_INCLUDES_HPP__ >+ >++#ifdef GBE_COMPILER_AVAILABLE >+ #include "llvm/Config/llvm-config.h" >+ >+ #include "llvm/IR/BasicBlock.h" >+@@ -75,7 +76,12 @@ >+ >+ #include "llvm-c/Linker.h" >+ #include "llvm/IRReader/IRReader.h" >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40 >++#include <llvm/Bitcode/BitcodeWriter.h> >++//#include <llvm/Bitcode/BitcodeReader.h> >++#else >+ #include "llvm/Bitcode/ReaderWriter.h" >++#endif >+ #include "llvm/Transforms/IPO.h" >+ #include "llvm/Transforms/Utils/Cloning.h" >+ >+@@ -132,4 +138,10 @@ >+ #include "llvm/Transforms/Scalar/GVN.h" >+ #endif >+ >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39 >++#include "llvm/Support/Error.h" >++#endif >++ >++#endif /*GBE_COMPILER_AVAILABLE */ >++ >+ #endif /* __GBE_IR_LLVM_INCLUDES_HPP__ */ >+diff --git a/backend/src/llvm/llvm_intrinsic_lowering.cpp b/backend/src/llvm/llvm_intrinsic_lowering.cpp >+index f01bb51..57c933f 100644 >+--- a/backend/src/llvm/llvm_intrinsic_lowering.cpp >++++ b/backend/src/llvm/llvm_intrinsic_lowering.cpp >+@@ -40,7 +40,12 @@ namespace gbe { >+ >+ } >+ >+- virtual const char *getPassName() const { >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40 >++ virtual StringRef getPassName() const >++#else >++ virtual const char *getPassName() const >++#endif >++ { >+ return "SPIR backend: lowering instrinsics"; >+ } >+ static char convertSpaceToName(Value *val) { >+diff --git a/backend/src/llvm/llvm_loadstore_optimization.cpp b/backend/src/llvm/llvm_loadstore_optimization.cpp >+index 4f4639c..5aa38be 100644 >+--- a/backend/src/llvm/llvm_loadstore_optimization.cpp >++++ b/backend/src/llvm/llvm_loadstore_optimization.cpp >+@@ -75,8 +75,12 @@ namespace gbe { >+ const BasicBlock::iterator &start, >+ unsigned maxVecSize, >+ bool isLoad); >+- >+- virtual const char *getPassName() const { >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40 >++ virtual StringRef getPassName() const >++#else >++ virtual const char *getPassName() const >++#endif >++ { >+ return "Merge compatible Load/stores for Gen"; >+ } >+ }; >+diff --git a/backend/src/llvm/llvm_passes.cpp b/backend/src/llvm/llvm_passes.cpp >+index f414fbb..10752a3 100644 >+--- a/backend/src/llvm/llvm_passes.cpp >++++ b/backend/src/llvm/llvm_passes.cpp >+@@ -232,7 +232,11 @@ namespace gbe >+ AU.setPreservesCFG(); >+ } >+ >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40 >++ virtual StringRef getPassName() const { >++#else >+ virtual const char *getPassName() const { >++#endif >+ return "SPIR backend: insert special spir instructions"; >+ } >+ >+diff --git a/backend/src/llvm/llvm_printf_parser.cpp b/backend/src/llvm/llvm_printf_parser.cpp >+index a1b1c2c..6bb7c52 100644 >+--- a/backend/src/llvm/llvm_printf_parser.cpp >++++ b/backend/src/llvm/llvm_printf_parser.cpp >+@@ -309,7 +309,11 @@ error: >+ bool parseOnePrintfInstruction(CallInst * call); >+ bool generateOneParameterInst(PrintfSlot& slot, Value* arg, Value*& new_arg); >+ >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40 >++ virtual StringRef getPassName() const >++#else >+ virtual const char *getPassName() const >++#endif >+ { >+ return "Printf Parser"; >+ } >+@@ -515,7 +519,11 @@ error: >+ case Type::FloatTyID: { >+ /* llvm 3.6 will give a undef value for NAN. */ >+ if (dyn_cast<llvm::UndefValue>(arg)) { >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40 >++ APFloat nan = APFloat::getNaN(APFloat::IEEEsingle(), false); >++#else >+ APFloat nan = APFloat::getNaN(APFloat::IEEEsingle, false); >++#endif >+ new_arg = ConstantFP::get(module->getContext(), nan); >+ } >+ >+diff --git a/backend/src/llvm/llvm_profiling.cpp b/backend/src/llvm/llvm_profiling.cpp >+index bc16951..f7e4cc5 100644 >+--- a/backend/src/llvm/llvm_profiling.cpp >++++ b/backend/src/llvm/llvm_profiling.cpp >+@@ -83,7 +83,11 @@ namespace gbe >+ { >+ } >+ >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40 >++ virtual StringRef getPassName() const >++#else >+ virtual const char *getPassName() const >++#endif >+ { >+ return "Timestamp Parser"; >+ } >+diff --git a/backend/src/llvm/llvm_to_gen.cpp b/backend/src/llvm/llvm_to_gen.cpp >+index 9b3b1f4..37919ec 100644 >+--- a/backend/src/llvm/llvm_to_gen.cpp >++++ b/backend/src/llvm/llvm_to_gen.cpp >+@@ -402,9 +402,17 @@ namespace gbe >+ passes.add(createScalarizePass()); // Expand all vector ops >+ >+ if(OCL_OUTPUT_CFG) >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40 >++ passes.add(createCFGPrinterLegacyPassPass()); >++#else >+ passes.add(createCFGPrinterPass()); >++#endif >+ if(OCL_OUTPUT_CFG_ONLY) >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40 >++ passes.add(createCFGOnlyPrinterLegacyPassPass()); >++#else >+ passes.add(createCFGOnlyPrinterPass()); >++#endif >+ passes.add(createGenPass(unit)); >+ passes.run(mod); >+ errors = dc.str(); >+diff --git a/backend/src/llvm/llvm_unroll.cpp b/backend/src/llvm/llvm_unroll.cpp >+index bfd3bbe..107d793 100644 >+--- a/backend/src/llvm/llvm_unroll.cpp >++++ b/backend/src/llvm/llvm_unroll.cpp >+@@ -238,7 +238,12 @@ namespace gbe { >+ return true; >+ } >+ >+- virtual const char *getPassName() const { >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40 >++ virtual StringRef getPassName() const >++#else >++ virtual const char *getPassName() const >++#endif >++ { >+ return "SPIR backend: custom loop unrolling pass"; >+ } >+ >+-- >+cgit v0.10.2 >+ > >Property changes on: lang/beignet/files/extra-patch-add_llvm40_support >___________________________________________________________________ >Added: fbsd:nokeywords >## -0,0 +1 ## >+yes >\ No newline at end of property >Added: svn:eol-style >## -0,0 +1 ## >+native >\ No newline at end of property >Added: svn:mime-type >## -0,0 +1 ## >+text/plain >\ No newline at end of property >Index: lang/beignet/files/extra-patch-refine_llvm_version_check >=================================================================== >--- lang/beignet/files/extra-patch-refine_llvm_version_check (nonexistent) >+++ lang/beignet/files/extra-patch-refine_llvm_version_check (working copy) >@@ -0,0 +1,921 @@ >+From f40ed02f7de65296219a0a160118ae3234e765c5 Mon Sep 17 00:00:00 2001 >+From: Pan Xiuli <xiuli.pan@intel.com> >+Date: Fri, 17 Mar 2017 14:16:01 +0800 >+Subject: Backend: Refine LLVM version check macro >+ >+LLVM 4.0 is coming, we should refine our version check to fit the >+LLVM_MAJOR_VERSION bump to 4. >+ >+Signed-off-by: Pan Xiuli <xiuli.pan@intel.com> >+Reviewed-by: Yang Rong <rong.r.yang@intel.com> >+ >+diff --git a/backend/src/backend/gen_program.cpp b/backend/src/backend/gen_program.cpp >+index 376342b..998e340 100644 >+--- a/backend/src/backend/gen_program.cpp >++++ b/backend/src/backend/gen_program.cpp >+@@ -329,13 +329,13 @@ namespace gbe { >+ //the first byte stands for binary_type. >+ binary_content.assign(binary+1, size-1); >+ llvm::StringRef llvm_bin_str(binary_content); >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39 >+ llvm::LLVMContext& c = GBEGetLLVMContext(); >+ #else >+ llvm::LLVMContext& c = llvm::getGlobalContext(); >+ #endif >+ llvm::SMDiagnostic Err; >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 36 >+ 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(); >+@@ -482,14 +482,14 @@ namespace gbe { >+ using namespace gbe; >+ char* errMsg; >+ if(((GenProgram*)dst_program)->module == NULL){ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 8 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38 >+ ((GenProgram*)dst_program)->module = llvm::CloneModule((llvm::Module*)((GenProgram*)src_program)->module).release(); >+ #else >+ ((GenProgram*)dst_program)->module = llvm::CloneModule((llvm::Module*)((GenProgram*)src_program)->module); >+ #endif >+ errSize = 0; >+ }else{ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39 >+ // Src now will be removed automatically. So clone it. >+ llvm::Module* src = llvm::CloneModule((llvm::Module*)((GenProgram*)src_program)->module).release(); >+ #else >+@@ -497,9 +497,9 @@ namespace gbe { >+ #endif >+ llvm::Module* dst = (llvm::Module*)((GenProgram*)dst_program)->module; >+ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39 >+ if (LLVMLinkModules2(wrap(dst), wrap(src))) { >+-#elif LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7 >++#elif LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37 >+ if (LLVMLinkModules(wrap(dst), wrap(src), LLVMLinkerPreserveSource_Removed, &errMsg)) { >+ #else >+ if (LLVMLinkModules(wrap(dst), wrap(src), LLVMLinkerPreserveSource, &errMsg)) { >+diff --git a/backend/src/backend/program.cpp b/backend/src/backend/program.cpp >+index 6b5fce0..6e8227a 100644 >+--- a/backend/src/backend/program.cpp >++++ b/backend/src/backend/program.cpp >+@@ -115,7 +115,7 @@ namespace gbe { >+ llvm::Module * cloned_module = NULL; >+ bool ret = false; >+ if(module){ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 8 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38 >+ cloned_module = llvm::CloneModule((llvm::Module*)module).release(); >+ #else >+ cloned_module = llvm::CloneModule((llvm::Module*)module); >+@@ -124,7 +124,7 @@ namespace gbe { >+ bool strictMath = true; >+ if (fast_relaxed_math || !OCL_STRICT_CONFORMANCE) >+ strictMath = false; >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39 >+ llvm::Module * linked_module = module ? llvm::CloneModule((llvm::Module*)module).release() : NULL; >+ // Src now will be removed automatically. So clone it. >+ if (llvmToGen(*unit, fileName, linked_module, optLevel, strictMath, OCL_PROFILING_LOG, error) == false) { >+@@ -651,7 +651,7 @@ namespace gbe { >+ // The ParseCommandLineOptions used for mllvm args can not be used with multithread >+ // and GVN now have a 100 inst limit on block scan. Now only pass a bigger limit >+ // for each context only once, this can also fix multithread bug. >+-#if LLVM_VERSION_MINOR >= 8 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38 >+ static bool ifsetllvm = false; >+ if(!ifsetllvm) { >+ args.push_back("-mllvm"); >+@@ -702,7 +702,7 @@ namespace gbe { >+ Diags); >+ llvm::StringRef srcString(source); >+ (*CI).getPreprocessorOpts().addRemappedFile("stringInput.cl", >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35 >+ llvm::MemoryBuffer::getMemBuffer(srcString) >+ #else >+ llvm::MemoryBuffer::getMemBuffer(srcString).release() >+@@ -755,7 +755,7 @@ namespace gbe { >+ if (!retVal) >+ return false; >+ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35 >+ llvm::Module *module = Act->takeModule(); >+ #else >+ llvm::Module *module = Act->takeModule().release(); >+@@ -764,7 +764,7 @@ namespace gbe { >+ *out_module = module; >+ >+ // Dump the LLVM if requested. >+-#if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR < 6) >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR < 36 >+ if (!dumpLLVMFileName.empty()) { >+ std::string err; >+ llvm::raw_fd_ostream ostream (dumpLLVMFileName.c_str(), >+@@ -1123,7 +1123,7 @@ EXTEND_QUOTE: >+ //FIXME: if use new allocated context to link two modules there would be context mismatch >+ //for some functions, so we use global context now, need switch to new context later. >+ llvm::Module * out_module; >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39 >+ llvm::LLVMContext* llvm_ctx = &GBEGetLLVMContext(); >+ #else >+ llvm::LLVMContext* llvm_ctx = &llvm::getGlobalContext(); >+@@ -1599,7 +1599,7 @@ namespace gbe >+ } >+ >+ ~CallBackInitializer() { >+-#if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR > 3) >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 34 >+ llvm::llvm_shutdown(); >+ #endif >+ } >+diff --git a/backend/src/ir/function.hpp b/backend/src/ir/function.hpp >+index 5fcb14a..64d9727 100644 >+--- a/backend/src/ir/function.hpp >++++ b/backend/src/ir/function.hpp >+@@ -186,7 +186,7 @@ namespace ir { >+ >+ >+ // only llvm-3.6 or later has kernel_arg_base_type in metadata. >+-#if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR <= 5) >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35 >+ bool isImage1dT() const { >+ return typeName.compare("image1d_t") == 0; >+ } >+diff --git a/backend/src/llvm/ExpandLargeIntegers.cpp b/backend/src/llvm/ExpandLargeIntegers.cpp >+index 60740f5..8515dc1 100644 >+--- a/backend/src/llvm/ExpandLargeIntegers.cpp >++++ b/backend/src/llvm/ExpandLargeIntegers.cpp >+@@ -93,7 +93,7 @@ >+ >+ using namespace llvm; >+ >+-#if LLVM_VERSION_MINOR >= 5 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 35 >+ #define DEBUG_TYPE "nacl-expand-ints" >+ #endif >+ >+@@ -766,7 +766,7 @@ static void convertInstruction(Instruction *Inst, ConversionState &State, >+ bool ExpandLargeIntegers::runOnFunction(Function &F) { >+ // Don't support changing the function arguments. Illegal function arguments >+ // should not be generated by clang. >+-#if LLVM_VERSION_MINOR >= 5 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 35 >+ for (const Argument &Arg : F.args()) >+ #else >+ for (const Argument &Arg : F.getArgumentList()) >+@@ -789,7 +789,7 @@ bool ExpandLargeIntegers::runOnFunction(Function &F) { >+ // Only attempt to convert an instruction if its result or any of its >+ // operands are illegal. >+ bool ShouldConvert = shouldConvert(&I); >+-#if LLVM_VERSION_MINOR >= 5 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 35 >+ for (Value *Op : I.operands()) >+ ShouldConvert |= shouldConvert(Op); >+ #else >+diff --git a/backend/src/llvm/llvm_bitcode_link.cpp b/backend/src/llvm/llvm_bitcode_link.cpp >+index 89d5e7c..869db89 100644 >+--- a/backend/src/llvm/llvm_bitcode_link.cpp >++++ b/backend/src/llvm/llvm_bitcode_link.cpp >+@@ -60,7 +60,7 @@ namespace gbe >+ return NULL; >+ } >+ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35 >+ oclLib = getLazyIRFileModule(FilePath, Err, ctx); >+ #else >+ oclLib = getLazyIRFileModule(FilePath, Err, ctx).release(); >+@@ -117,7 +117,7 @@ namespace gbe >+ >+ std::string ErrInfo;// = "Not Materializable"; >+ if (!fromSrc && newMF->isMaterializable()) { >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35 >+ if (newMF->Materialize(&ErrInfo)) { >+ printf("Can not materialize the function: %s, because %s\n", fnName.c_str(), ErrInfo.c_str()); >+ return false; >+@@ -250,7 +250,7 @@ namespace gbe >+ } >+ std::string ErrInfo;// = "Not Materializable"; >+ if (newMF->isMaterializable()) { >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35 >+ if (newMF->Materialize(&ErrInfo)) { >+ printf("Can not materialize the function: %s, because %s\n", fnName.c_str(), ErrInfo.c_str()); >+ delete clonedLib; >+@@ -287,7 +287,7 @@ namespace gbe >+ * pass to extract the functions and values in Gvs from the library module. >+ * After extract what we need and remove what we do not need, we use >+ * materializeAll to mark the module as materialized. */ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >=8 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38 >+ /* Get all GlobalValue from module. */ >+ Module::GlobalListType &GVlist = clonedLib->getGlobalList(); >+ for(Module::global_iterator GVitr = GVlist.begin();GVitr != GVlist.end();++GVitr) { >+@@ -310,7 +310,7 @@ 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 >= 9 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39 >+ if(LLVMLinkModules2(wrap(clonedLib), wrap(mod))) { >+ #else >+ if(LLVMLinkModules(wrap(clonedLib), wrap(mod), LLVMLinkerDestroySource, &errorMsg)) { >+@@ -319,13 +319,13 @@ namespace gbe >+ printf("Fatal Error: link the bitcode error:\n%s\n", errorMsg); >+ return NULL; >+ } >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >=7 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37 >+ llvm::legacy::PassManager passes; >+ #else >+ llvm::PassManager passes; >+ #endif >+ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >=9 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39 >+ auto PreserveKernel = [=](const GlobalValue &GV) { >+ for(size_t i = 0;i < kernels.size(); ++i) >+ if(strcmp(GV.getName().data(), kernels[i])) >+diff --git a/backend/src/llvm/llvm_device_enqueue.cpp b/backend/src/llvm/llvm_device_enqueue.cpp >+index ee236de..9a0fb46 100644 >+--- a/backend/src/llvm/llvm_device_enqueue.cpp >++++ b/backend/src/llvm/llvm_device_enqueue.cpp >+@@ -62,7 +62,7 @@ namespace gbe { >+ for (Value::use_iterator iter = v->use_begin(); iter != v->use_end(); ++iter) { >+ // After LLVM 3.5, use_iterator points to 'Use' instead of 'User', >+ // which is more straightforward. >+-#if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR < 5) >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR < 35 >+ User *theUser = *iter; >+ #else >+ User *theUser = iter->getUser(); >+@@ -84,7 +84,7 @@ namespace gbe { >+ >+ Function* setFunctionAsKernel(Module *mod, Function *Fn) >+ { >+-#if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR >= 9) >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39 >+ LLVMContext &Context = mod->getContext(); >+ Type *intTy = IntegerType::get(mod->getContext(), 32); >+ SmallVector<llvm::Metadata *, 5> kernelMDArgs; >+@@ -210,7 +210,7 @@ namespace gbe { >+ } >+ >+ for (Value::use_iterator iter = bt->use_begin(); iter != bt->use_end(); ++iter) { >+-#if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR < 5) >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR < 35 >+ User *theUser = *iter; >+ #else >+ User *theUser = iter->getUser(); >+@@ -298,7 +298,7 @@ namespace gbe { >+ if(AllocaInst *ai = dyn_cast<AllocaInst>(ld->getPointerOperand())) { >+ Value *v = NULL; >+ for (Value::use_iterator iter = ai->use_begin(); iter != ai->use_end(); ++iter) { >+-#if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR < 5) >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR < 35 >+ User *theUser = *iter; >+ #else >+ User *theUser = iter->getUser(); >+@@ -347,7 +347,7 @@ namespace gbe { >+ if(ld) { >+ Value *block = ld->getPointerOperand(); >+ for (Value::use_iterator iter = block->use_begin(); iter != block->use_end(); ++iter) { >+-#if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR < 5) >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR < 35 >+ User *theUser = *iter; >+ #else >+ User *theUser = iter->getUser(); >+diff --git a/backend/src/llvm/llvm_gen_backend.cpp b/backend/src/llvm/llvm_gen_backend.cpp >+index 742c947..4621f6d 100644 >+--- a/backend/src/llvm/llvm_gen_backend.cpp >++++ b/backend/src/llvm/llvm_gen_backend.cpp >+@@ -95,9 +95,9 @@ >+ #define LLVM_VERSION_MINOR 0 >+ #endif /* !defined(LLVM_VERSION_MINOR) */ >+ >+-#if (LLVM_VERSION_MAJOR != 3) || (LLVM_VERSION_MINOR < 3) >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR < 33 >+ #error "Only LLVM 3.3 and newer are supported" >+-#endif /* (LLVM_VERSION_MAJOR != 3) || (LLVM_VERSION_MINOR > 4) */ >++#endif >+ >+ using namespace llvm; >+ >+@@ -565,7 +565,7 @@ namespace gbe >+ has_errors(false), >+ legacyMode(true) >+ { >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >=7 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37 >+ initializeLoopInfoWrapperPassPass(*PassRegistry::getPassRegistry()); >+ #else >+ initializeLoopInfoPass(*PassRegistry::getPassRegistry()); >+@@ -576,7 +576,7 @@ namespace gbe >+ virtual const char *getPassName() const { return "Gen Back-End"; } >+ >+ void getAnalysisUsage(AnalysisUsage &AU) const { >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >=7 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37 >+ AU.addRequired<LoopInfoWrapperPass>(); >+ #else >+ AU.addRequired<LoopInfo>(); >+@@ -611,7 +611,7 @@ namespace gbe >+ if (legacyMode) >+ analyzePointerOrigin(F); >+ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >=7 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37 >+ LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo(); >+ #else >+ LI = &getAnalysis<LoopInfo>(); >+@@ -835,7 +835,7 @@ namespace gbe >+ for (Value::use_iterator iter = work->use_begin(); iter != work->use_end(); ++iter) { >+ // After LLVM 3.5, use_iterator points to 'Use' instead of 'User', >+ // which is more straightforward. >+- #if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR < 5) >++ #if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR < 35 >+ User *theUser = *iter; >+ #else >+ User *theUser = iter->getUser(); >+@@ -1089,7 +1089,7 @@ namespace gbe >+ if (predBB->getTerminator()) >+ Builder2.SetInsertPoint(predBB->getTerminator()); >+ >+-#if (LLVM_VERSION_MAJOR== 3 && LLVM_VERSION_MINOR < 6) >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR < 36 >+ // llvm 3.5 and older version don't have CreateBitOrPointerCast() define >+ Type *srcTy = base->getType(); >+ Type *dstTy = ptr->getType(); >+@@ -1248,7 +1248,7 @@ namespace gbe >+ uint32_t ops = clKernels->getNumOperands(); >+ for(uint32_t x = 0; x < ops; x++) { >+ MDNode* node = clKernels->getOperand(x); >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35 >+ Value * op = node->getOperand(0); >+ #else >+ auto *V = cast<ValueAsMetadata>(node->getOperand(0)); >+@@ -1272,7 +1272,7 @@ namespace gbe >+ MDNode *typeNameNode = NULL; >+ MDNode *typeBaseNameNode = NULL; >+ MDNode *typeQualNode = NULL; >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39 >+ typeNameNode = F.getMetadata("kernel_arg_type"); >+ typeBaseNameNode = F.getMetadata("kernel_arg_base_type"); >+ typeQualNode = F.getMetadata("kernel_arg_type_qual"); >+@@ -1298,7 +1298,7 @@ namespace gbe >+ ir::FunctionArgument::InfoFromLLVM llvmInfo; >+ for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E; ++I, argID++) { >+ unsigned opID = argID; >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR < 9 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR < 39 >+ opID += 1; >+ #endif >+ >+@@ -1340,7 +1340,7 @@ namespace gbe >+ for (Value::use_iterator iter = work->use_begin(); iter != work->use_end(); ++iter) { >+ // After LLVM 3.5, use_iterator points to 'Use' instead of 'User', >+ // which is more straightforward. >+- #if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR < 5) >++ #if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR < 35 >+ User *theUser = *iter; >+ #else >+ User *theUser = iter->getUser(); >+@@ -2120,7 +2120,7 @@ namespace gbe >+ >+ std::string functionAttributes; >+ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39 >+ /* LLVM 3.9 change kernel arg info as function metadata */ >+ addrSpaceNode = F.getMetadata("kernel_arg_addr_space"); >+ accessQualNode = F.getMetadata("kernel_arg_access_qual"); >+@@ -2222,7 +2222,7 @@ namespace gbe >+ >+ if (attrName->getString() == "reqd_work_group_size") { >+ GBE_ASSERT(attrNode->getNumOperands() == 4); >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35 >+ ConstantInt *x = dyn_cast<ConstantInt>(attrNode->getOperand(1)); >+ ConstantInt *y = dyn_cast<ConstantInt>(attrNode->getOperand(2)); >+ ConstantInt *z = dyn_cast<ConstantInt>(attrNode->getOperand(3)); >+@@ -2264,13 +2264,13 @@ namespace gbe >+ } else if (attrName->getString() == "vec_type_hint") { >+ GBE_ASSERT(attrNode->getNumOperands() == 3); >+ functionAttributes += attrName->getString(); >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35 >+ Value* V = attrNode->getOperand(1); >+ #else >+ auto *Op1 = cast<ValueAsMetadata>(attrNode->getOperand(1)); >+ Value *V = Op1 ? Op1->getValue() : NULL; >+ #endif >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35 >+ ConstantInt *sign = dyn_cast<ConstantInt>(attrNode->getOperand(2)); >+ #else >+ ConstantInt *sign = mdconst::extract<ConstantInt>(attrNode->getOperand(2)); >+@@ -2299,7 +2299,7 @@ namespace gbe >+ functionAttributes += " "; >+ } else if (attrName->getString() == "work_group_size_hint") { >+ GBE_ASSERT(attrNode->getNumOperands() == 4); >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35 >+ ConstantInt *x = dyn_cast<ConstantInt>(attrNode->getOperand(1)); >+ ConstantInt *y = dyn_cast<ConstantInt>(attrNode->getOperand(2)); >+ ConstantInt *z = dyn_cast<ConstantInt>(attrNode->getOperand(3)); >+@@ -2341,13 +2341,13 @@ namespace gbe >+ // Insert a new register for each function argument >+ for (; I != E; ++I, ++argID) { >+ uint32_t opID = argID; >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR < 9 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR < 39 >+ opID += 1; >+ #endif >+ const std::string &argName = I->getName().str(); >+ Type *type = I->getType(); >+ if(addrSpaceNode) { >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35 >+ llvmInfo.addrSpace = (cast<ConstantInt>(addrSpaceNode->getOperand(opID)))->getZExtValue(); >+ #else >+ llvmInfo.addrSpace = (mdconst::extract<ConstantInt>(addrSpaceNode->getOperand(opID)))->getZExtValue(); >+@@ -2914,7 +2914,7 @@ namespace gbe >+ const Instruction *insn = NULL; >+ for(Value::const_use_iterator iter = v->use_begin(); iter != v->use_end(); ++iter) { >+ // After LLVM 3.5, use_iterator points to 'Use' instead of 'User', which is more straightforward. >+-#if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR < 5) >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR < 35 >+ const User *theUser = *iter; >+ #else >+ const User *theUser = iter->getUser(); >+diff --git a/backend/src/llvm/llvm_gen_backend.hpp b/backend/src/llvm/llvm_gen_backend.hpp >+index f1c791e..2a322ac 100644 >+--- a/backend/src/llvm/llvm_gen_backend.hpp >++++ b/backend/src/llvm/llvm_gen_backend.hpp >+@@ -149,7 +149,7 @@ namespace gbe >+ /*! Insert the time stamp for profiling. */ >+ llvm::FunctionPass* createProfilingInserterPass(int profilingType, ir::Unit &unit); >+ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 5 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 35 >+ /* customized loop unrolling pass. */ >+ llvm::LoopPass *createCustomLoopUnrollPass(); >+ #endif >+diff --git a/backend/src/llvm/llvm_includes.hpp b/backend/src/llvm/llvm_includes.hpp >+index 0b80979..a242fd3 100644 >+--- a/backend/src/llvm/llvm_includes.hpp >++++ b/backend/src/llvm/llvm_includes.hpp >+@@ -91,7 +91,7 @@ >+ #include "llvm/MC/MCSubtargetInfo.h" >+ #include "llvm/MC/MCSymbol.h" >+ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >=5 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 35 >+ #include "llvm/IR/Mangler.h" >+ #include "llvm/IR/CallSite.h" >+ #include "llvm/IR/CFG.h" >+@@ -111,7 +111,7 @@ >+ #include "llvm/Target/Mangler.h" >+ #endif >+ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >=7 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37 >+ #include "llvm/Analysis/TargetLibraryInfo.h" >+ #include "llvm/IR/LegacyPassManager.h" >+ #else >+@@ -122,12 +122,12 @@ >+ >+ #include <clang/CodeGen/CodeGenAction.h> >+ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >=8 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38 >+ #include "llvm/Analysis/BasicAliasAnalysis.h" >+ #include "llvm/Analysis/TypeBasedAliasAnalysis.h" >+ #endif >+ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39 >+ #include "llvm/Transforms/IPO/FunctionAttrs.h" >+ #include "llvm/Transforms/Scalar/GVN.h" >+ #endif >+diff --git a/backend/src/llvm/llvm_loadstore_optimization.cpp b/backend/src/llvm/llvm_loadstore_optimization.cpp >+index e797e98..4f4639c 100644 >+--- a/backend/src/llvm/llvm_loadstore_optimization.cpp >++++ b/backend/src/llvm/llvm_loadstore_optimization.cpp >+@@ -35,7 +35,7 @@ namespace gbe { >+ GenLoadStoreOptimization() : BasicBlockPass(ID) {} >+ >+ void getAnalysisUsage(AnalysisUsage &AU) const { >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 8 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38 >+ AU.addRequired<ScalarEvolutionWrapperPass>(); >+ AU.addPreserved<ScalarEvolutionWrapperPass>(); >+ #else >+@@ -46,12 +46,12 @@ namespace gbe { >+ } >+ >+ virtual bool runOnBasicBlock(BasicBlock &BB) { >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 8 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38 >+ SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE(); >+ #else >+ SE = &getAnalysis<ScalarEvolution>(); >+ #endif >+- #if LLVM_VERSION_MINOR >= 7 >++ #if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37 >+ TD = &BB.getModule()->getDataLayout(); >+ #elif LLVM_VERSION_MINOR >= 5 >+ DataLayoutPass *DLP = getAnalysisIfAvailable<DataLayoutPass>(); >+diff --git a/backend/src/llvm/llvm_passes.cpp b/backend/src/llvm/llvm_passes.cpp >+index 8f5bcc9..f414fbb 100644 >+--- a/backend/src/llvm/llvm_passes.cpp >++++ b/backend/src/llvm/llvm_passes.cpp >+@@ -42,7 +42,7 @@ namespace gbe >+ { >+ bool isKernelFunction(const llvm::Function &F) { >+ bool bKernel = false; >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39 >+ bKernel = F.getMetadata("kernel_arg_name") != NULL; >+ #else >+ const Module *module = F.getParent(); >+@@ -53,7 +53,7 @@ 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 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35 >+ Value * op = node->getOperand(0); >+ #else >+ Value * op = cast<ValueAsMetadata>(node->getOperand(0))->getValue(); >+@@ -74,7 +74,7 @@ namespace gbe >+ if(ops > 0) { >+ uint32_t major = 0, minor = 0; >+ MDNode* node = version->getOperand(0); >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 36 >+ major = mdconst::extract<ConstantInt>(node->getOperand(0))->getZExtValue(); >+ minor = mdconst::extract<ConstantInt>(node->getOperand(1))->getZExtValue(); >+ #else >+diff --git a/backend/src/llvm/llvm_profiling.cpp b/backend/src/llvm/llvm_profiling.cpp >+index 734c69d..bc16951 100644 >+--- a/backend/src/llvm/llvm_profiling.cpp >++++ b/backend/src/llvm/llvm_profiling.cpp >+@@ -34,7 +34,7 @@ >+ #include "llvm/Pass.h" >+ #include "llvm/IR/IRBuilder.h" >+ >+-#if LLVM_VERSION_MINOR >= 5 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 35 >+ #include "llvm/IR/CallSite.h" >+ #include "llvm/IR/CFG.h" >+ #else >+diff --git a/backend/src/llvm/llvm_sampler_fix.cpp b/backend/src/llvm/llvm_sampler_fix.cpp >+index de7ebdb..2e8bcf9 100644 >+--- a/backend/src/llvm/llvm_sampler_fix.cpp >++++ b/backend/src/llvm/llvm_sampler_fix.cpp >+@@ -33,7 +33,7 @@ namespace gbe { >+ class SamplerFix : public FunctionPass { >+ public: >+ SamplerFix() : FunctionPass(ID) { >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 5 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 35 >+ initializeDominatorTreeWrapperPassPass(*PassRegistry::getPassRegistry()); >+ #else >+ initializeDominatorTreePass(*PassRegistry::getPassRegistry()); >+diff --git a/backend/src/llvm/llvm_scalarize.cpp b/backend/src/llvm/llvm_scalarize.cpp >+index 329e3a9..be3d549 100644 >+--- a/backend/src/llvm/llvm_scalarize.cpp >++++ b/backend/src/llvm/llvm_scalarize.cpp >+@@ -96,7 +96,7 @@ namespace gbe { >+ >+ Scalarize() : FunctionPass(ID) >+ { >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 5 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 35 >+ initializeDominatorTreeWrapperPassPass(*PassRegistry::getPassRegistry()); >+ #else >+ initializeDominatorTreePass(*PassRegistry::getPassRegistry()); >+diff --git a/backend/src/llvm/llvm_to_gen.cpp b/backend/src/llvm/llvm_to_gen.cpp >+index bef4df1..9b3b1f4 100644 >+--- a/backend/src/llvm/llvm_to_gen.cpp >++++ b/backend/src/llvm/llvm_to_gen.cpp >+@@ -46,14 +46,14 @@ namespace gbe >+ BVAR(OCL_OUTPUT_CFG_GEN_IR, false); >+ using namespace llvm; >+ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39 >+ llvm::LLVMContext& GBEGetLLVMContext() { >+ static llvm::LLVMContext GBEContext; >+ return GBEContext; >+ } >+ #endif >+ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37 >+ #define TARGETLIBRARY TargetLibraryInfoImpl >+ #else >+ #define TARGETLIBRARY TargetLibraryInfo >+@@ -61,32 +61,32 @@ namespace gbe >+ >+ void runFuntionPass(Module &mod, TARGETLIBRARY *libraryInfo, const DataLayout &DL) >+ { >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37 >+ legacy::FunctionPassManager FPM(&mod); >+ #else >+ FunctionPassManager FPM(&mod); >+ #endif >+ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7 >+-#elif LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37 >++#elif LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 36 >+ FPM.add(new DataLayoutPass()); >+-#elif LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR == 5 >++#elif LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR == 35 >+ FPM.add(new DataLayoutPass(DL)); >+ #else >+ FPM.add(new DataLayout(DL)); >+ #endif >+ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >=5 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 35 >+ FPM.add(createVerifierPass(true)); >+ #else >+ FPM.add(createVerifierPass()); >+ #endif >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37 >+ FPM.add(new TargetLibraryInfoWrapperPass(*libraryInfo)); >+ #else >+ FPM.add(new TargetLibraryInfo(*libraryInfo)); >+ #endif >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 8 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38 >+ FPM.add(createTypeBasedAAWrapperPass()); >+ FPM.add(createBasicAAWrapperPass()); >+ #else >+@@ -108,27 +108,27 @@ namespace gbe >+ >+ void runModulePass(Module &mod, TARGETLIBRARY *libraryInfo, const DataLayout &DL, int optLevel, bool strictMath) >+ { >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37 >+ legacy::PassManager MPM; >+ #else >+ PassManager MPM; >+ #endif >+ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7 >+-#elif LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37 >++#elif LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 36 >+ MPM.add(new DataLayoutPass()); >+-#elif LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR == 5 >++#elif LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR == 35 >+ MPM.add(new DataLayoutPass(DL)); >+ #else >+ MPM.add(new DataLayout(DL)); >+ #endif >+ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37 >+ MPM.add(new TargetLibraryInfoWrapperPass(*libraryInfo)); >+ #else >+ MPM.add(new TargetLibraryInfo(*libraryInfo)); >+ #endif >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 8 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38 >+ MPM.add(createTypeBasedAAWrapperPass()); >+ MPM.add(createBasicAAWrapperPass()); >+ #else >+@@ -149,9 +149,9 @@ namespace gbe >+ MPM.add(createInstructionCombiningPass());// Clean up after IPCP & DAE >+ MPM.add(createCFGSimplificationPass()); // Clean up after IPCP & DAE >+ MPM.add(createPruneEHPass()); // Remove dead EH info >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39 >+ MPM.add(createPostOrderFunctionAttrsLegacyPass()); >+-#elif LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 8 >++#elif LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38 >+ MPM.add(createPostOrderFunctionAttrsPass()); // Set readonly/readnone attrs >+ #else >+ MPM.add(createFunctionAttrsPass()); // Set readonly/readnone attrs >+@@ -159,7 +159,7 @@ namespace gbe >+ >+ //MPM.add(createScalarReplAggregatesPass(64, true, -1, -1, 64)) >+ if(optLevel > 0) >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 8 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38 >+ MPM.add(createSROAPass()); >+ #else >+ MPM.add(createSROAPass(/*RequiresDomTree*/ false)); >+@@ -182,14 +182,14 @@ namespace gbe >+ MPM.add(createLoopDeletionPass()); // Delete dead loops >+ MPM.add(createLoopUnrollPass(640)); //1024, 32, 1024, 512)); //Unroll loops >+ if(optLevel > 0) { >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 8 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38 >+ MPM.add(createSROAPass()); >+ #else >+ MPM.add(createSROAPass(/*RequiresDomTree*/ false)); >+ #endif >+ MPM.add(createGVNPass()); // Remove redundancies >+ } >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 5 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 35 >+ // FIXME Workaround: we find that CustomLoopUnroll may increase register pressure greatly, >+ // and it may even make som cl kernel cannot compile because of limited scratch memory for spill. >+ // As we observe this under strict math. So we disable CustomLoopUnroll if strict math is enabled. >+@@ -199,7 +199,7 @@ namespace gbe >+ #endif >+ MPM.add(createLoopUnrollPass()); //1024, 32, 1024, 512)); //Unroll loops >+ if(optLevel > 0) { >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 8 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38 >+ MPM.add(createSROAPass()); >+ #else >+ MPM.add(createSROAPass(/*RequiresDomTree*/ false)); >+@@ -230,7 +230,7 @@ namespace gbe >+ } >+ >+ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37 >+ #define OUTPUT_BITCODE(STAGE, MOD) do { \ >+ legacy::PassManager passes__; \ >+ if (OCL_OUTPUT_LLVM_##STAGE) { \ >+@@ -238,7 +238,7 @@ namespace gbe >+ passes__.run(MOD); \ >+ } \ >+ }while(0) >+-#elif LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 5 >++#elif LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 35 >+ #define OUTPUT_BITCODE(STAGE, MOD) do { \ >+ PassManager passes__; \ >+ if (OCL_OUTPUT_LLVM_##STAGE) { \ >+@@ -303,12 +303,12 @@ namespace gbe >+ if (module) { >+ cl_mod = reinterpret_cast<Module*>(const_cast<void*>(module)); >+ } else if (fileName){ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39 >+ llvm::LLVMContext& c = GBEGetLLVMContext(); >+ #else >+ llvm::LLVMContext& c = llvm::getGlobalContext(); >+ #endif >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 36 >+ cl_mod = parseIRFile(fileName, Err, c).release(); >+ #else >+ cl_mod = ParseIRFile(fileName, Err, c); >+@@ -318,7 +318,7 @@ namespace gbe >+ if (!cl_mod) return false; >+ >+ OUTPUT_BITCODE(BEFORE_LINK, (*cl_mod)); >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37 >+ legacy::PassManager passes__; >+ #else >+ PassManager passes__; >+@@ -346,7 +346,7 @@ namespace gbe >+ gbeDiagnosticContext dc; >+ mod.getContext().setDiagnosticHandler(&gbeDiagnosticHandler,&dc); >+ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37 >+ mod.setDataLayout(DL); >+ #endif >+ Triple TargetTriple(mod.getTargetTriple()); >+@@ -357,15 +357,15 @@ namespace gbe >+ >+ runFuntionPass(mod, libraryInfo, DL); >+ runModulePass(mod, libraryInfo, DL, optLevel, strictMath); >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37 >+ legacy::PassManager passes; >+ #else >+ PassManager passes; >+ #endif >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7 >+-#elif LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37 >++#elif LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 36 >+ passes.add(new DataLayoutPass()); >+-#elif LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR == 5 >++#elif LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR == 35 >+ passes.add(new DataLayoutPass(DL)); >+ #else >+ passes.add(new DataLayout(DL)); >+@@ -374,7 +374,7 @@ namespace gbe >+ passes.add(createIntrinsicLoweringPass()); >+ passes.add(createStripAttributesPass()); // Strip unsupported attributes and calling conventions. >+ passes.add(createFunctionInliningPass(20000)); >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37 >+ passes.add(createSROAPass()); >+ #else >+ passes.add(createScalarReplAggregatesPass(64, true, -1, -1, 64)); >+diff --git a/backend/src/llvm/llvm_to_gen.hpp b/backend/src/llvm/llvm_to_gen.hpp >+index d3928c6..9025852 100644 >+--- a/backend/src/llvm/llvm_to_gen.hpp >++++ b/backend/src/llvm/llvm_to_gen.hpp >+@@ -23,7 +23,7 @@ >+ */ >+ #ifndef __GBE_IR_LLVM_TO_GEN_HPP__ >+ #define __GBE_IR_LLVM_TO_GEN_HPP__ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39 >+ #include "llvm/IR/LLVMContext.h" >+ #endif >+ >+@@ -37,7 +37,7 @@ namespace gbe { >+ optLevel 0 equal to clang -O1 and 1 equal to clang -O2*/ >+ bool llvmToGen(ir::Unit &unit, const char *fileName, const void* module, >+ int optLevel, bool strictMath, int profiling, std::string &errors); >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39 >+ extern llvm::LLVMContext& GBEGetLLVMContext(); >+ #endif >+ >+diff --git a/backend/src/llvm/llvm_unroll.cpp b/backend/src/llvm/llvm_unroll.cpp >+index e24dc4f..bfd3bbe 100644 >+--- a/backend/src/llvm/llvm_unroll.cpp >++++ b/backend/src/llvm/llvm_unroll.cpp >+@@ -16,7 +16,7 @@ >+ */ >+ >+ #include "llvm/Config/llvm-config.h" >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 5 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 35 >+ #include <set> >+ >+ #include "llvm_includes.hpp" >+@@ -36,7 +36,7 @@ namespace gbe { >+ LoopPass(ID) {} >+ >+ void getAnalysisUsage(AnalysisUsage &AU) const { >+-#if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR >= 7) >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37 >+ AU.addRequired<LoopInfoWrapperPass>(); >+ AU.addPreserved<LoopInfoWrapperPass>(); >+ #else >+@@ -47,7 +47,7 @@ namespace gbe { >+ AU.addPreservedID(LoopSimplifyID); >+ AU.addRequiredID(LCSSAID); >+ AU.addPreservedID(LCSSAID); >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 8 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38 >+ AU.addRequired<ScalarEvolutionWrapperPass>(); >+ AU.addPreserved<ScalarEvolutionWrapperPass>(); >+ #else >+@@ -91,7 +91,7 @@ namespace gbe { >+ assert(MD->getNumOperands() == 2 && >+ "Unroll count hint metadata should have two operands."); >+ unsigned Count; >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 36 >+ Count = mdconst::extract<ConstantInt>(MD->getOperand(1))->getZExtValue(); >+ #else >+ Count = cast<ConstantInt>(MD->getOperand(1))->getZExtValue(); >+@@ -105,7 +105,7 @@ namespace gbe { >+ void setUnrollID(Loop *L, bool enable) { >+ assert(enable); >+ LLVMContext &Context = L->getHeader()->getContext(); >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 36 >+ SmallVector<Metadata *, 2> forceUnroll; >+ forceUnroll.push_back(MDString::get(Context, "llvm.loop.unroll.enable")); >+ MDNode *forceUnrollNode = MDNode::get(Context, forceUnroll); >+@@ -169,7 +169,7 @@ namespace gbe { >+ // be unrolled. >+ bool handleParentLoops(Loop *L, LPPassManager &LPM) { >+ Loop *currL = L; >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 8 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38 >+ ScalarEvolution *SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE(); >+ LoopInfo &loopInfo = getAnalysis<LoopInfoWrapperPass>().getLoopInfo(); >+ #else >+@@ -205,7 +205,7 @@ namespace gbe { >+ if (parentTripCount != 0 && currTripCount * parentTripCount > 32) { >+ //Don't change the unrollID if doesn't force unroll. >+ //setUnrollID(parentL, false); >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 8 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38 >+ loopInfo.markAsRemoved(parentL); >+ #else >+ LPM.deleteLoopFromQueue(parentL); >+-- >+cgit v0.10.2 >+ > >Property changes on: lang/beignet/files/extra-patch-refine_llvm_version_check >___________________________________________________________________ >Added: fbsd:nokeywords >## -0,0 +1 ## >+yes >\ No newline at end of property >Added: svn:eol-style >## -0,0 +1 ## >+native >\ No newline at end of property >Added: svn:mime-type >## -0,0 +1 ## >+text/plain >\ No newline at end of property >Index: lang/beignet/files/extra-patch-refine_llvm_version_check.orig >=================================================================== >--- lang/beignet/files/extra-patch-refine_llvm_version_check.orig (nonexistent) >+++ lang/beignet/files/extra-patch-refine_llvm_version_check.orig (working copy) >@@ -0,0 +1,921 @@ >+From f40ed02f7de65296219a0a160118ae3234e765c5 Mon Sep 17 00:00:00 2001 >+From: Pan Xiuli <xiuli.pan@intel.com> >+Date: Fri, 17 Mar 2017 14:16:01 +0800 >+Subject: Backend: Refine LLVM version check macro >+ >+LLVM 4.0 is coming, we should refine our version check to fit the >+LLVM_MAJOR_VERSION bump to 4. >+ >+Signed-off-by: Pan Xiuli <xiuli.pan@intel.com> >+Reviewed-by: Yang Rong <rong.r.yang@intel.com> >+ >+diff --git a/backend/src/backend/gen_program.cpp b/backend/src/backend/gen_program.cpp >+index 376342b..998e340 100644 >+--- a/backend/src/backend/gen_program.cpp >++++ b/backend/src/backend/gen_program.cpp >+@@ -329,13 +329,13 @@ namespace gbe { >+ //the first byte stands for binary_type. >+ binary_content.assign(binary+1, size-1); >+ llvm::StringRef llvm_bin_str(binary_content); >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39 >+ llvm::LLVMContext& c = GBEGetLLVMContext(); >+ #else >+ llvm::LLVMContext& c = llvm::getGlobalContext(); >+ #endif >+ llvm::SMDiagnostic Err; >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 36 >+ 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(); >+@@ -482,14 +482,14 @@ namespace gbe { >+ using namespace gbe; >+ char* errMsg; >+ if(((GenProgram*)dst_program)->module == NULL){ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 8 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38 >+ ((GenProgram*)dst_program)->module = llvm::CloneModule((llvm::Module*)((GenProgram*)src_program)->module).release(); >+ #else >+ ((GenProgram*)dst_program)->module = llvm::CloneModule((llvm::Module*)((GenProgram*)src_program)->module); >+ #endif >+ errSize = 0; >+ }else{ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39 >+ // Src now will be removed automatically. So clone it. >+ llvm::Module* src = llvm::CloneModule((llvm::Module*)((GenProgram*)src_program)->module).release(); >+ #else >+@@ -497,9 +497,9 @@ namespace gbe { >+ #endif >+ llvm::Module* dst = (llvm::Module*)((GenProgram*)dst_program)->module; >+ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39 >+ if (LLVMLinkModules2(wrap(dst), wrap(src))) { >+-#elif LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7 >++#elif LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37 >+ if (LLVMLinkModules(wrap(dst), wrap(src), LLVMLinkerPreserveSource_Removed, &errMsg)) { >+ #else >+ if (LLVMLinkModules(wrap(dst), wrap(src), LLVMLinkerPreserveSource, &errMsg)) { >+diff --git a/backend/src/backend/program.cpp b/backend/src/backend/program.cpp >+index 6b5fce0..6e8227a 100644 >+--- a/backend/src/backend/program.cpp >++++ b/backend/src/backend/program.cpp >+@@ -115,7 +115,7 @@ namespace gbe { >+ llvm::Module * cloned_module = NULL; >+ bool ret = false; >+ if(module){ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 8 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38 >+ cloned_module = llvm::CloneModule((llvm::Module*)module).release(); >+ #else >+ cloned_module = llvm::CloneModule((llvm::Module*)module); >+@@ -124,7 +124,7 @@ namespace gbe { >+ bool strictMath = true; >+ if (fast_relaxed_math || !OCL_STRICT_CONFORMANCE) >+ strictMath = false; >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39 >+ llvm::Module * linked_module = module ? llvm::CloneModule((llvm::Module*)module).release() : NULL; >+ // Src now will be removed automatically. So clone it. >+ if (llvmToGen(*unit, fileName, linked_module, optLevel, strictMath, OCL_PROFILING_LOG, error) == false) { >+@@ -651,7 +651,7 @@ namespace gbe { >+ // The ParseCommandLineOptions used for mllvm args can not be used with multithread >+ // and GVN now have a 100 inst limit on block scan. Now only pass a bigger limit >+ // for each context only once, this can also fix multithread bug. >+-#if LLVM_VERSION_MINOR >= 8 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38 >+ static bool ifsetllvm = false; >+ if(!ifsetllvm) { >+ args.push_back("-mllvm"); >+@@ -702,7 +702,7 @@ namespace gbe { >+ Diags); >+ llvm::StringRef srcString(source); >+ (*CI).getPreprocessorOpts().addRemappedFile("stringInput.cl", >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35 >+ llvm::MemoryBuffer::getMemBuffer(srcString) >+ #else >+ llvm::MemoryBuffer::getMemBuffer(srcString).release() >+@@ -755,7 +755,7 @@ namespace gbe { >+ if (!retVal) >+ return false; >+ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35 >+ llvm::Module *module = Act->takeModule(); >+ #else >+ llvm::Module *module = Act->takeModule().release(); >+@@ -764,7 +764,7 @@ namespace gbe { >+ *out_module = module; >+ >+ // Dump the LLVM if requested. >+-#if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR < 6) >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR < 36 >+ if (!dumpLLVMFileName.empty()) { >+ std::string err; >+ llvm::raw_fd_ostream ostream (dumpLLVMFileName.c_str(), >+@@ -1123,7 +1123,7 @@ EXTEND_QUOTE: >+ //FIXME: if use new allocated context to link two modules there would be context mismatch >+ //for some functions, so we use global context now, need switch to new context later. >+ llvm::Module * out_module; >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39 >+ llvm::LLVMContext* llvm_ctx = &GBEGetLLVMContext(); >+ #else >+ llvm::LLVMContext* llvm_ctx = &llvm::getGlobalContext(); >+@@ -1599,7 +1599,7 @@ namespace gbe >+ } >+ >+ ~CallBackInitializer() { >+-#if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR > 3) >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 34 >+ llvm::llvm_shutdown(); >+ #endif >+ } >+diff --git a/backend/src/ir/function.hpp b/backend/src/ir/function.hpp >+index 5fcb14a..64d9727 100644 >+--- a/backend/src/ir/function.hpp >++++ b/backend/src/ir/function.hpp >+@@ -186,7 +186,7 @@ namespace ir { >+ >+ >+ // only llvm-3.6 or later has kernel_arg_base_type in metadata. >+-#if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR <= 5) >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35 >+ bool isImage1dT() const { >+ return typeName.compare("image1d_t") == 0; >+ } >+diff --git a/backend/src/llvm/ExpandLargeIntegers.cpp b/backend/src/llvm/ExpandLargeIntegers.cpp >+index 60740f5..8515dc1 100644 >+--- a/backend/src/llvm/ExpandLargeIntegers.cpp >++++ b/backend/src/llvm/ExpandLargeIntegers.cpp >+@@ -93,7 +93,7 @@ >+ >+ using namespace llvm; >+ >+-#if LLVM_VERSION_MINOR >= 5 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 35 >+ #define DEBUG_TYPE "nacl-expand-ints" >+ #endif >+ >+@@ -766,7 +766,7 @@ static void convertInstruction(Instruction *Inst, ConversionState &State, >+ bool ExpandLargeIntegers::runOnFunction(Function &F) { >+ // Don't support changing the function arguments. Illegal function arguments >+ // should not be generated by clang. >+-#if LLVM_VERSION_MINOR >= 5 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 35 >+ for (const Argument &Arg : F.args()) >+ #else >+ for (const Argument &Arg : F.getArgumentList()) >+@@ -789,7 +789,7 @@ bool ExpandLargeIntegers::runOnFunction(Function &F) { >+ // Only attempt to convert an instruction if its result or any of its >+ // operands are illegal. >+ bool ShouldConvert = shouldConvert(&I); >+-#if LLVM_VERSION_MINOR >= 5 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 35 >+ for (Value *Op : I.operands()) >+ ShouldConvert |= shouldConvert(Op); >+ #else >+diff --git a/backend/src/llvm/llvm_bitcode_link.cpp b/backend/src/llvm/llvm_bitcode_link.cpp >+index 89d5e7c..869db89 100644 >+--- a/backend/src/llvm/llvm_bitcode_link.cpp >++++ b/backend/src/llvm/llvm_bitcode_link.cpp >+@@ -60,7 +60,7 @@ namespace gbe >+ return NULL; >+ } >+ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35 >+ oclLib = getLazyIRFileModule(FilePath, Err, ctx); >+ #else >+ oclLib = getLazyIRFileModule(FilePath, Err, ctx).release(); >+@@ -117,7 +117,7 @@ namespace gbe >+ >+ std::string ErrInfo;// = "Not Materializable"; >+ if (!fromSrc && newMF->isMaterializable()) { >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35 >+ if (newMF->Materialize(&ErrInfo)) { >+ printf("Can not materialize the function: %s, because %s\n", fnName.c_str(), ErrInfo.c_str()); >+ return false; >+@@ -250,7 +250,7 @@ namespace gbe >+ } >+ std::string ErrInfo;// = "Not Materializable"; >+ if (newMF->isMaterializable()) { >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35 >+ if (newMF->Materialize(&ErrInfo)) { >+ printf("Can not materialize the function: %s, because %s\n", fnName.c_str(), ErrInfo.c_str()); >+ delete clonedLib; >+@@ -287,7 +287,7 @@ namespace gbe >+ * pass to extract the functions and values in Gvs from the library module. >+ * After extract what we need and remove what we do not need, we use >+ * materializeAll to mark the module as materialized. */ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >=8 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38 >+ /* Get all GlobalValue from module. */ >+ Module::GlobalListType &GVlist = clonedLib->getGlobalList(); >+ for(Module::global_iterator GVitr = GVlist.begin();GVitr != GVlist.end();++GVitr) { >+@@ -310,7 +310,7 @@ 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 >= 9 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39 >+ if(LLVMLinkModules2(wrap(clonedLib), wrap(mod))) { >+ #else >+ if(LLVMLinkModules(wrap(clonedLib), wrap(mod), LLVMLinkerDestroySource, &errorMsg)) { >+@@ -319,13 +319,13 @@ namespace gbe >+ printf("Fatal Error: link the bitcode error:\n%s\n", errorMsg); >+ return NULL; >+ } >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >=7 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37 >+ llvm::legacy::PassManager passes; >+ #else >+ llvm::PassManager passes; >+ #endif >+ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >=9 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39 >+ auto PreserveKernel = [=](const GlobalValue &GV) { >+ for(size_t i = 0;i < kernels.size(); ++i) >+ if(strcmp(GV.getName().data(), kernels[i])) >+diff --git a/backend/src/llvm/llvm_device_enqueue.cpp b/backend/src/llvm/llvm_device_enqueue.cpp >+index ee236de..9a0fb46 100644 >+--- a/backend/src/llvm/llvm_device_enqueue.cpp >++++ b/backend/src/llvm/llvm_device_enqueue.cpp >+@@ -62,7 +62,7 @@ namespace gbe { >+ for (Value::use_iterator iter = v->use_begin(); iter != v->use_end(); ++iter) { >+ // After LLVM 3.5, use_iterator points to 'Use' instead of 'User', >+ // which is more straightforward. >+-#if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR < 5) >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR < 35 >+ User *theUser = *iter; >+ #else >+ User *theUser = iter->getUser(); >+@@ -84,7 +84,7 @@ namespace gbe { >+ >+ Function* setFunctionAsKernel(Module *mod, Function *Fn) >+ { >+-#if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR >= 9) >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39 >+ LLVMContext &Context = mod->getContext(); >+ Type *intTy = IntegerType::get(mod->getContext(), 32); >+ SmallVector<llvm::Metadata *, 5> kernelMDArgs; >+@@ -210,7 +210,7 @@ namespace gbe { >+ } >+ >+ for (Value::use_iterator iter = bt->use_begin(); iter != bt->use_end(); ++iter) { >+-#if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR < 5) >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR < 35 >+ User *theUser = *iter; >+ #else >+ User *theUser = iter->getUser(); >+@@ -298,7 +298,7 @@ namespace gbe { >+ if(AllocaInst *ai = dyn_cast<AllocaInst>(ld->getPointerOperand())) { >+ Value *v = NULL; >+ for (Value::use_iterator iter = ai->use_begin(); iter != ai->use_end(); ++iter) { >+-#if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR < 5) >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR < 35 >+ User *theUser = *iter; >+ #else >+ User *theUser = iter->getUser(); >+@@ -347,7 +347,7 @@ namespace gbe { >+ if(ld) { >+ Value *block = ld->getPointerOperand(); >+ for (Value::use_iterator iter = block->use_begin(); iter != block->use_end(); ++iter) { >+-#if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR < 5) >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR < 35 >+ User *theUser = *iter; >+ #else >+ User *theUser = iter->getUser(); >+diff --git a/backend/src/llvm/llvm_gen_backend.cpp b/backend/src/llvm/llvm_gen_backend.cpp >+index 742c947..4621f6d 100644 >+--- a/backend/src/llvm/llvm_gen_backend.cpp >++++ b/backend/src/llvm/llvm_gen_backend.cpp >+@@ -95,9 +95,9 @@ >+ #define LLVM_VERSION_MINOR 0 >+ #endif /* !defined(LLVM_VERSION_MINOR) */ >+ >+-#if (LLVM_VERSION_MAJOR != 3) || (LLVM_VERSION_MINOR < 3) >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR < 33 >+ #error "Only LLVM 3.3 and newer are supported" >+-#endif /* (LLVM_VERSION_MAJOR != 3) || (LLVM_VERSION_MINOR > 4) */ >++#endif >+ >+ using namespace llvm; >+ >+@@ -565,7 +565,7 @@ namespace gbe >+ has_errors(false), >+ legacyMode(true) >+ { >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >=7 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37 >+ initializeLoopInfoWrapperPassPass(*PassRegistry::getPassRegistry()); >+ #else >+ initializeLoopInfoPass(*PassRegistry::getPassRegistry()); >+@@ -576,7 +576,7 @@ namespace gbe >+ virtual const char *getPassName() const { return "Gen Back-End"; } >+ >+ void getAnalysisUsage(AnalysisUsage &AU) const { >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >=7 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37 >+ AU.addRequired<LoopInfoWrapperPass>(); >+ #else >+ AU.addRequired<LoopInfo>(); >+@@ -611,7 +611,7 @@ namespace gbe >+ if (legacyMode) >+ analyzePointerOrigin(F); >+ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >=7 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37 >+ LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo(); >+ #else >+ LI = &getAnalysis<LoopInfo>(); >+@@ -835,7 +835,7 @@ namespace gbe >+ for (Value::use_iterator iter = work->use_begin(); iter != work->use_end(); ++iter) { >+ // After LLVM 3.5, use_iterator points to 'Use' instead of 'User', >+ // which is more straightforward. >+- #if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR < 5) >++ #if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR < 35 >+ User *theUser = *iter; >+ #else >+ User *theUser = iter->getUser(); >+@@ -1089,7 +1089,7 @@ namespace gbe >+ if (predBB->getTerminator()) >+ Builder2.SetInsertPoint(predBB->getTerminator()); >+ >+-#if (LLVM_VERSION_MAJOR== 3 && LLVM_VERSION_MINOR < 6) >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR < 36 >+ // llvm 3.5 and older version don't have CreateBitOrPointerCast() define >+ Type *srcTy = base->getType(); >+ Type *dstTy = ptr->getType(); >+@@ -1248,7 +1248,7 @@ namespace gbe >+ uint32_t ops = clKernels->getNumOperands(); >+ for(uint32_t x = 0; x < ops; x++) { >+ MDNode* node = clKernels->getOperand(x); >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35 >+ Value * op = node->getOperand(0); >+ #else >+ auto *V = cast<ValueAsMetadata>(node->getOperand(0)); >+@@ -1272,7 +1272,7 @@ namespace gbe >+ MDNode *typeNameNode = NULL; >+ MDNode *typeBaseNameNode = NULL; >+ MDNode *typeQualNode = NULL; >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39 >+ typeNameNode = F.getMetadata("kernel_arg_type"); >+ typeBaseNameNode = F.getMetadata("kernel_arg_base_type"); >+ typeQualNode = F.getMetadata("kernel_arg_type_qual"); >+@@ -1298,7 +1298,7 @@ namespace gbe >+ ir::FunctionArgument::InfoFromLLVM llvmInfo; >+ for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E; ++I, argID++) { >+ unsigned opID = argID; >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR < 9 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR < 39 >+ opID += 1; >+ #endif >+ >+@@ -1340,7 +1340,7 @@ namespace gbe >+ for (Value::use_iterator iter = work->use_begin(); iter != work->use_end(); ++iter) { >+ // After LLVM 3.5, use_iterator points to 'Use' instead of 'User', >+ // which is more straightforward. >+- #if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR < 5) >++ #if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR < 35 >+ User *theUser = *iter; >+ #else >+ User *theUser = iter->getUser(); >+@@ -2120,7 +2120,7 @@ namespace gbe >+ >+ std::string functionAttributes; >+ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39 >+ /* LLVM 3.9 change kernel arg info as function metadata */ >+ addrSpaceNode = F.getMetadata("kernel_arg_addr_space"); >+ accessQualNode = F.getMetadata("kernel_arg_access_qual"); >+@@ -2222,7 +2222,7 @@ namespace gbe >+ >+ if (attrName->getString() == "reqd_work_group_size") { >+ GBE_ASSERT(attrNode->getNumOperands() == 4); >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35 >+ ConstantInt *x = dyn_cast<ConstantInt>(attrNode->getOperand(1)); >+ ConstantInt *y = dyn_cast<ConstantInt>(attrNode->getOperand(2)); >+ ConstantInt *z = dyn_cast<ConstantInt>(attrNode->getOperand(3)); >+@@ -2264,13 +2264,13 @@ namespace gbe >+ } else if (attrName->getString() == "vec_type_hint") { >+ GBE_ASSERT(attrNode->getNumOperands() == 3); >+ functionAttributes += attrName->getString(); >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35 >+ Value* V = attrNode->getOperand(1); >+ #else >+ auto *Op1 = cast<ValueAsMetadata>(attrNode->getOperand(1)); >+ Value *V = Op1 ? Op1->getValue() : NULL; >+ #endif >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35 >+ ConstantInt *sign = dyn_cast<ConstantInt>(attrNode->getOperand(2)); >+ #else >+ ConstantInt *sign = mdconst::extract<ConstantInt>(attrNode->getOperand(2)); >+@@ -2299,7 +2299,7 @@ namespace gbe >+ functionAttributes += " "; >+ } else if (attrName->getString() == "work_group_size_hint") { >+ GBE_ASSERT(attrNode->getNumOperands() == 4); >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35 >+ ConstantInt *x = dyn_cast<ConstantInt>(attrNode->getOperand(1)); >+ ConstantInt *y = dyn_cast<ConstantInt>(attrNode->getOperand(2)); >+ ConstantInt *z = dyn_cast<ConstantInt>(attrNode->getOperand(3)); >+@@ -2341,13 +2341,13 @@ namespace gbe >+ // Insert a new register for each function argument >+ for (; I != E; ++I, ++argID) { >+ uint32_t opID = argID; >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR < 9 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR < 39 >+ opID += 1; >+ #endif >+ const std::string &argName = I->getName().str(); >+ Type *type = I->getType(); >+ if(addrSpaceNode) { >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35 >+ llvmInfo.addrSpace = (cast<ConstantInt>(addrSpaceNode->getOperand(opID)))->getZExtValue(); >+ #else >+ llvmInfo.addrSpace = (mdconst::extract<ConstantInt>(addrSpaceNode->getOperand(opID)))->getZExtValue(); >+@@ -2914,7 +2914,7 @@ namespace gbe >+ const Instruction *insn = NULL; >+ for(Value::const_use_iterator iter = v->use_begin(); iter != v->use_end(); ++iter) { >+ // After LLVM 3.5, use_iterator points to 'Use' instead of 'User', which is more straightforward. >+-#if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR < 5) >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR < 35 >+ const User *theUser = *iter; >+ #else >+ const User *theUser = iter->getUser(); >+diff --git a/backend/src/llvm/llvm_gen_backend.hpp b/backend/src/llvm/llvm_gen_backend.hpp >+index f1c791e..2a322ac 100644 >+--- a/backend/src/llvm/llvm_gen_backend.hpp >++++ b/backend/src/llvm/llvm_gen_backend.hpp >+@@ -149,7 +149,7 @@ namespace gbe >+ /*! Insert the time stamp for profiling. */ >+ llvm::FunctionPass* createProfilingInserterPass(int profilingType, ir::Unit &unit); >+ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 5 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 35 >+ /* customized loop unrolling pass. */ >+ llvm::LoopPass *createCustomLoopUnrollPass(); >+ #endif >+diff --git a/backend/src/llvm/llvm_includes.hpp b/backend/src/llvm/llvm_includes.hpp >+index 0b80979..a242fd3 100644 >+--- a/backend/src/llvm/llvm_includes.hpp >++++ b/backend/src/llvm/llvm_includes.hpp >+@@ -91,7 +91,7 @@ >+ #include "llvm/MC/MCSubtargetInfo.h" >+ #include "llvm/MC/MCSymbol.h" >+ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >=5 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 35 >+ #include "llvm/IR/Mangler.h" >+ #include "llvm/IR/CallSite.h" >+ #include "llvm/IR/CFG.h" >+@@ -111,7 +111,7 @@ >+ #include "llvm/Target/Mangler.h" >+ #endif >+ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >=7 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37 >+ #include "llvm/Analysis/TargetLibraryInfo.h" >+ #include "llvm/IR/LegacyPassManager.h" >+ #else >+@@ -122,12 +122,12 @@ >+ >+ #include <clang/CodeGen/CodeGenAction.h> >+ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >=8 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38 >+ #include "llvm/Analysis/BasicAliasAnalysis.h" >+ #include "llvm/Analysis/TypeBasedAliasAnalysis.h" >+ #endif >+ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39 >+ #include "llvm/Transforms/IPO/FunctionAttrs.h" >+ #include "llvm/Transforms/Scalar/GVN.h" >+ #endif >+diff --git a/backend/src/llvm/llvm_loadstore_optimization.cpp b/backend/src/llvm/llvm_loadstore_optimization.cpp >+index e797e98..4f4639c 100644 >+--- a/backend/src/llvm/llvm_loadstore_optimization.cpp >++++ b/backend/src/llvm/llvm_loadstore_optimization.cpp >+@@ -35,7 +35,7 @@ namespace gbe { >+ GenLoadStoreOptimization() : BasicBlockPass(ID) {} >+ >+ void getAnalysisUsage(AnalysisUsage &AU) const { >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 8 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38 >+ AU.addRequired<ScalarEvolutionWrapperPass>(); >+ AU.addPreserved<ScalarEvolutionWrapperPass>(); >+ #else >+@@ -46,12 +46,12 @@ namespace gbe { >+ } >+ >+ virtual bool runOnBasicBlock(BasicBlock &BB) { >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 8 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38 >+ SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE(); >+ #else >+ SE = &getAnalysis<ScalarEvolution>(); >+ #endif >+- #if LLVM_VERSION_MINOR >= 7 >++ #if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37 >+ TD = &BB.getModule()->getDataLayout(); >+ #elif LLVM_VERSION_MINOR >= 5 >+ DataLayoutPass *DLP = getAnalysisIfAvailable<DataLayoutPass>(); >+diff --git a/backend/src/llvm/llvm_passes.cpp b/backend/src/llvm/llvm_passes.cpp >+index 8f5bcc9..f414fbb 100644 >+--- a/backend/src/llvm/llvm_passes.cpp >++++ b/backend/src/llvm/llvm_passes.cpp >+@@ -42,7 +42,7 @@ namespace gbe >+ { >+ bool isKernelFunction(const llvm::Function &F) { >+ bool bKernel = false; >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39 >+ bKernel = F.getMetadata("kernel_arg_name") != NULL; >+ #else >+ const Module *module = F.getParent(); >+@@ -53,7 +53,7 @@ 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 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35 >+ Value * op = node->getOperand(0); >+ #else >+ Value * op = cast<ValueAsMetadata>(node->getOperand(0))->getValue(); >+@@ -74,7 +74,7 @@ namespace gbe >+ if(ops > 0) { >+ uint32_t major = 0, minor = 0; >+ MDNode* node = version->getOperand(0); >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 36 >+ major = mdconst::extract<ConstantInt>(node->getOperand(0))->getZExtValue(); >+ minor = mdconst::extract<ConstantInt>(node->getOperand(1))->getZExtValue(); >+ #else >+diff --git a/backend/src/llvm/llvm_profiling.cpp b/backend/src/llvm/llvm_profiling.cpp >+index 734c69d..bc16951 100644 >+--- a/backend/src/llvm/llvm_profiling.cpp >++++ b/backend/src/llvm/llvm_profiling.cpp >+@@ -34,7 +34,7 @@ >+ #include "llvm/Pass.h" >+ #include "llvm/IR/IRBuilder.h" >+ >+-#if LLVM_VERSION_MINOR >= 5 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 35 >+ #include "llvm/IR/CallSite.h" >+ #include "llvm/IR/CFG.h" >+ #else >+diff --git a/backend/src/llvm/llvm_sampler_fix.cpp b/backend/src/llvm/llvm_sampler_fix.cpp >+index de7ebdb..2e8bcf9 100644 >+--- a/backend/src/llvm/llvm_sampler_fix.cpp >++++ b/backend/src/llvm/llvm_sampler_fix.cpp >+@@ -33,7 +33,7 @@ namespace gbe { >+ class SamplerFix : public FunctionPass { >+ public: >+ SamplerFix() : FunctionPass(ID) { >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 5 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 35 >+ initializeDominatorTreeWrapperPassPass(*PassRegistry::getPassRegistry()); >+ #else >+ initializeDominatorTreePass(*PassRegistry::getPassRegistry()); >+diff --git a/backend/src/llvm/llvm_scalarize.cpp b/backend/src/llvm/llvm_scalarize.cpp >+index 329e3a9..be3d549 100644 >+--- a/backend/src/llvm/llvm_scalarize.cpp >++++ b/backend/src/llvm/llvm_scalarize.cpp >+@@ -96,7 +96,7 @@ namespace gbe { >+ >+ Scalarize() : FunctionPass(ID) >+ { >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 5 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 35 >+ initializeDominatorTreeWrapperPassPass(*PassRegistry::getPassRegistry()); >+ #else >+ initializeDominatorTreePass(*PassRegistry::getPassRegistry()); >+diff --git a/backend/src/llvm/llvm_to_gen.cpp b/backend/src/llvm/llvm_to_gen.cpp >+index bef4df1..9b3b1f4 100644 >+--- a/backend/src/llvm/llvm_to_gen.cpp >++++ b/backend/src/llvm/llvm_to_gen.cpp >+@@ -46,14 +46,14 @@ namespace gbe >+ BVAR(OCL_OUTPUT_CFG_GEN_IR, false); >+ using namespace llvm; >+ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39 >+ llvm::LLVMContext& GBEGetLLVMContext() { >+ static llvm::LLVMContext GBEContext; >+ return GBEContext; >+ } >+ #endif >+ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37 >+ #define TARGETLIBRARY TargetLibraryInfoImpl >+ #else >+ #define TARGETLIBRARY TargetLibraryInfo >+@@ -61,32 +61,32 @@ namespace gbe >+ >+ void runFuntionPass(Module &mod, TARGETLIBRARY *libraryInfo, const DataLayout &DL) >+ { >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37 >+ legacy::FunctionPassManager FPM(&mod); >+ #else >+ FunctionPassManager FPM(&mod); >+ #endif >+ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7 >+-#elif LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37 >++#elif LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 36 >+ FPM.add(new DataLayoutPass()); >+-#elif LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR == 5 >++#elif LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR == 35 >+ FPM.add(new DataLayoutPass(DL)); >+ #else >+ FPM.add(new DataLayout(DL)); >+ #endif >+ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >=5 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 35 >+ FPM.add(createVerifierPass(true)); >+ #else >+ FPM.add(createVerifierPass()); >+ #endif >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37 >+ FPM.add(new TargetLibraryInfoWrapperPass(*libraryInfo)); >+ #else >+ FPM.add(new TargetLibraryInfo(*libraryInfo)); >+ #endif >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 8 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38 >+ FPM.add(createTypeBasedAAWrapperPass()); >+ FPM.add(createBasicAAWrapperPass()); >+ #else >+@@ -108,27 +108,27 @@ namespace gbe >+ >+ void runModulePass(Module &mod, TARGETLIBRARY *libraryInfo, const DataLayout &DL, int optLevel, bool strictMath) >+ { >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37 >+ legacy::PassManager MPM; >+ #else >+ PassManager MPM; >+ #endif >+ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7 >+-#elif LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37 >++#elif LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 36 >+ MPM.add(new DataLayoutPass()); >+-#elif LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR == 5 >++#elif LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR == 35 >+ MPM.add(new DataLayoutPass(DL)); >+ #else >+ MPM.add(new DataLayout(DL)); >+ #endif >+ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37 >+ MPM.add(new TargetLibraryInfoWrapperPass(*libraryInfo)); >+ #else >+ MPM.add(new TargetLibraryInfo(*libraryInfo)); >+ #endif >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 8 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38 >+ MPM.add(createTypeBasedAAWrapperPass()); >+ MPM.add(createBasicAAWrapperPass()); >+ #else >+@@ -149,9 +149,9 @@ namespace gbe >+ MPM.add(createInstructionCombiningPass());// Clean up after IPCP & DAE >+ MPM.add(createCFGSimplificationPass()); // Clean up after IPCP & DAE >+ MPM.add(createPruneEHPass()); // Remove dead EH info >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39 >+ MPM.add(createPostOrderFunctionAttrsLegacyPass()); >+-#elif LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 8 >++#elif LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38 >+ MPM.add(createPostOrderFunctionAttrsPass()); // Set readonly/readnone attrs >+ #else >+ MPM.add(createFunctionAttrsPass()); // Set readonly/readnone attrs >+@@ -159,7 +159,7 @@ namespace gbe >+ >+ //MPM.add(createScalarReplAggregatesPass(64, true, -1, -1, 64)) >+ if(optLevel > 0) >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 8 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38 >+ MPM.add(createSROAPass()); >+ #else >+ MPM.add(createSROAPass(/*RequiresDomTree*/ false)); >+@@ -182,14 +182,14 @@ namespace gbe >+ MPM.add(createLoopDeletionPass()); // Delete dead loops >+ MPM.add(createLoopUnrollPass(640)); //1024, 32, 1024, 512)); //Unroll loops >+ if(optLevel > 0) { >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 8 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38 >+ MPM.add(createSROAPass()); >+ #else >+ MPM.add(createSROAPass(/*RequiresDomTree*/ false)); >+ #endif >+ MPM.add(createGVNPass()); // Remove redundancies >+ } >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 5 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 35 >+ // FIXME Workaround: we find that CustomLoopUnroll may increase register pressure greatly, >+ // and it may even make som cl kernel cannot compile because of limited scratch memory for spill. >+ // As we observe this under strict math. So we disable CustomLoopUnroll if strict math is enabled. >+@@ -199,7 +199,7 @@ namespace gbe >+ #endif >+ MPM.add(createLoopUnrollPass()); //1024, 32, 1024, 512)); //Unroll loops >+ if(optLevel > 0) { >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 8 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38 >+ MPM.add(createSROAPass()); >+ #else >+ MPM.add(createSROAPass(/*RequiresDomTree*/ false)); >+@@ -230,7 +230,7 @@ namespace gbe >+ } >+ >+ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37 >+ #define OUTPUT_BITCODE(STAGE, MOD) do { \ >+ legacy::PassManager passes__; \ >+ if (OCL_OUTPUT_LLVM_##STAGE) { \ >+@@ -238,7 +238,7 @@ namespace gbe >+ passes__.run(MOD); \ >+ } \ >+ }while(0) >+-#elif LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 5 >++#elif LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 35 >+ #define OUTPUT_BITCODE(STAGE, MOD) do { \ >+ PassManager passes__; \ >+ if (OCL_OUTPUT_LLVM_##STAGE) { \ >+@@ -303,12 +303,12 @@ namespace gbe >+ if (module) { >+ cl_mod = reinterpret_cast<Module*>(const_cast<void*>(module)); >+ } else if (fileName){ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39 >+ llvm::LLVMContext& c = GBEGetLLVMContext(); >+ #else >+ llvm::LLVMContext& c = llvm::getGlobalContext(); >+ #endif >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 36 >+ cl_mod = parseIRFile(fileName, Err, c).release(); >+ #else >+ cl_mod = ParseIRFile(fileName, Err, c); >+@@ -318,7 +318,7 @@ namespace gbe >+ if (!cl_mod) return false; >+ >+ OUTPUT_BITCODE(BEFORE_LINK, (*cl_mod)); >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37 >+ legacy::PassManager passes__; >+ #else >+ PassManager passes__; >+@@ -346,7 +346,7 @@ namespace gbe >+ gbeDiagnosticContext dc; >+ mod.getContext().setDiagnosticHandler(&gbeDiagnosticHandler,&dc); >+ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37 >+ mod.setDataLayout(DL); >+ #endif >+ Triple TargetTriple(mod.getTargetTriple()); >+@@ -357,15 +357,15 @@ namespace gbe >+ >+ runFuntionPass(mod, libraryInfo, DL); >+ runModulePass(mod, libraryInfo, DL, optLevel, strictMath); >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37 >+ legacy::PassManager passes; >+ #else >+ PassManager passes; >+ #endif >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7 >+-#elif LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37 >++#elif LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 36 >+ passes.add(new DataLayoutPass()); >+-#elif LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR == 5 >++#elif LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR == 35 >+ passes.add(new DataLayoutPass(DL)); >+ #else >+ passes.add(new DataLayout(DL)); >+@@ -374,7 +374,7 @@ namespace gbe >+ passes.add(createIntrinsicLoweringPass()); >+ passes.add(createStripAttributesPass()); // Strip unsupported attributes and calling conventions. >+ passes.add(createFunctionInliningPass(20000)); >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37 >+ passes.add(createSROAPass()); >+ #else >+ passes.add(createScalarReplAggregatesPass(64, true, -1, -1, 64)); >+diff --git a/backend/src/llvm/llvm_to_gen.hpp b/backend/src/llvm/llvm_to_gen.hpp >+index d3928c6..9025852 100644 >+--- a/backend/src/llvm/llvm_to_gen.hpp >++++ b/backend/src/llvm/llvm_to_gen.hpp >+@@ -23,7 +23,7 @@ >+ */ >+ #ifndef __GBE_IR_LLVM_TO_GEN_HPP__ >+ #define __GBE_IR_LLVM_TO_GEN_HPP__ >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39 >+ #include "llvm/IR/LLVMContext.h" >+ #endif >+ >+@@ -37,7 +37,7 @@ namespace gbe { >+ optLevel 0 equal to clang -O1 and 1 equal to clang -O2*/ >+ bool llvmToGen(ir::Unit &unit, const char *fileName, const void* module, >+ int optLevel, bool strictMath, int profiling, std::string &errors); >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39 >+ extern llvm::LLVMContext& GBEGetLLVMContext(); >+ #endif >+ >+diff --git a/backend/src/llvm/llvm_unroll.cpp b/backend/src/llvm/llvm_unroll.cpp >+index e24dc4f..bfd3bbe 100644 >+--- a/backend/src/llvm/llvm_unroll.cpp >++++ b/backend/src/llvm/llvm_unroll.cpp >+@@ -16,7 +16,7 @@ >+ */ >+ >+ #include "llvm/Config/llvm-config.h" >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 5 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 35 >+ #include <set> >+ >+ #include "llvm_includes.hpp" >+@@ -36,7 +36,7 @@ namespace gbe { >+ LoopPass(ID) {} >+ >+ void getAnalysisUsage(AnalysisUsage &AU) const { >+-#if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR >= 7) >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37 >+ AU.addRequired<LoopInfoWrapperPass>(); >+ AU.addPreserved<LoopInfoWrapperPass>(); >+ #else >+@@ -47,7 +47,7 @@ namespace gbe { >+ AU.addPreservedID(LoopSimplifyID); >+ AU.addRequiredID(LCSSAID); >+ AU.addPreservedID(LCSSAID); >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 8 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38 >+ AU.addRequired<ScalarEvolutionWrapperPass>(); >+ AU.addPreserved<ScalarEvolutionWrapperPass>(); >+ #else >+@@ -91,7 +91,7 @@ namespace gbe { >+ assert(MD->getNumOperands() == 2 && >+ "Unroll count hint metadata should have two operands."); >+ unsigned Count; >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 36 >+ Count = mdconst::extract<ConstantInt>(MD->getOperand(1))->getZExtValue(); >+ #else >+ Count = cast<ConstantInt>(MD->getOperand(1))->getZExtValue(); >+@@ -105,7 +105,7 @@ namespace gbe { >+ void setUnrollID(Loop *L, bool enable) { >+ assert(enable); >+ LLVMContext &Context = L->getHeader()->getContext(); >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 36 >+ SmallVector<Metadata *, 2> forceUnroll; >+ forceUnroll.push_back(MDString::get(Context, "llvm.loop.unroll.enable")); >+ MDNode *forceUnrollNode = MDNode::get(Context, forceUnroll); >+@@ -169,7 +169,7 @@ namespace gbe { >+ // be unrolled. >+ bool handleParentLoops(Loop *L, LPPassManager &LPM) { >+ Loop *currL = L; >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 8 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38 >+ ScalarEvolution *SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE(); >+ LoopInfo &loopInfo = getAnalysis<LoopInfoWrapperPass>().getLoopInfo(); >+ #else >+@@ -205,7 +205,7 @@ namespace gbe { >+ if (parentTripCount != 0 && currTripCount * parentTripCount > 32) { >+ //Don't change the unrollID if doesn't force unroll. >+ //setUnrollID(parentL, false); >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 8 >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38 >+ loopInfo.markAsRemoved(parentL); >+ #else >+ LPM.deleteLoopFromQueue(parentL); >+-- >+cgit v0.10.2 >+ > >Property changes on: lang/beignet/files/extra-patch-refine_llvm_version_check.orig >___________________________________________________________________ >Added: fbsd:nokeywords >## -0,0 +1 ## >+yes >\ No newline at end of property >Added: svn:eol-style >## -0,0 +1 ## >+native >\ No newline at end of property >Added: svn:mime-type >## -0,0 +1 ## >+text/plain >\ No newline at end of property >Index: lang/beignet/files/extra-patch-refine_llvm_version_check.rej >=================================================================== >--- lang/beignet/files/extra-patch-refine_llvm_version_check.rej (nonexistent) >+++ lang/beignet/files/extra-patch-refine_llvm_version_check.rej (working copy) >@@ -0,0 +1,12 @@ >+@@ -29,7 +29,11 @@ >+ #include "llvm/IR/DataLayout.h" >+ #include "llvm-c/Linker.h" >+ #include "llvm/Transforms/Utils/Cloning.h" >++#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40 >++#include "llvm/Bitcode/BitcodeWriter.h" >++#else >+ #include "llvm/Bitcode/ReaderWriter.h" >++#endif /* LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40 */ >+ #include "llvm/Support/raw_ostream.h" >+ #include "llvm/ADT/StringRef.h" >+ #include "llvm/Support/MemoryBuffer.h" > >Property changes on: lang/beignet/files/extra-patch-refine_llvm_version_check.rej >___________________________________________________________________ >Added: fbsd:nokeywords >## -0,0 +1 ## >+yes >\ No newline at end of property >Added: svn:eol-style >## -0,0 +1 ## >+native >\ No newline at end of property >Added: svn:mime-type >## -0,0 +1 ## >+text/plain >\ No newline at end of property >Index: lang/beignet/files/extra-patch-remove_old_llvm_support >=================================================================== >--- lang/beignet/files/extra-patch-remove_old_llvm_support (nonexistent) >+++ lang/beignet/files/extra-patch-remove_old_llvm_support (working copy) >@@ -0,0 +1,298 @@ >+From c6497b19e7b32bcb0d1f4aceb1988488dfec639d Mon Sep 17 00:00:00 2001 >+From: Pan Xiuli <xiuli.pan@intel.com> >+Date: Fri, 17 Mar 2017 14:15:58 +0800 >+Subject: Backend: Remove old llvm support code. >+ >+LLVM 3.3 or older is not supportted by Beignet now, and we need delete >+these codes. >+ >+Signed-off-by: Pan Xiuli <xiuli.pan@intel.com> >+Reviewed-by: Yang Rong <rong.r.yang@intel.com> >+ >+diff --git a/backend/src/backend/gen_program.cpp b/backend/src/backend/gen_program.cpp >+index 073ede6..376342b 100644 >+--- a/backend/src/backend/gen_program.cpp >++++ b/backend/src/backend/gen_program.cpp >+@@ -24,15 +24,9 @@ >+ >+ #ifdef GBE_COMPILER_AVAILABLE >+ #include "llvm/Config/llvm-config.h" >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 2 >+-#include "llvm/LLVMContext.h" >+-#include "llvm/Module.h" >+-#include "llvm/DataLayout.h" >+-#else >+ #include "llvm/IR/LLVMContext.h" >+ #include "llvm/IR/Module.h" >+ #include "llvm/IR/DataLayout.h" >+-#endif /* LLVM_VERSION_MINOR <= 2 */ >+ #include "llvm-c/Linker.h" >+ #include "llvm/Transforms/Utils/Cloning.h" >+ #include "llvm/Bitcode/ReaderWriter.h" >+diff --git a/backend/src/backend/program.cpp b/backend/src/backend/program.cpp >+index 8b8abc4..6b5fce0 100644 >+--- a/backend/src/backend/program.cpp >++++ b/backend/src/backend/program.cpp >+@@ -52,33 +52,16 @@ >+ #include <mutex> >+ >+ #ifdef GBE_COMPILER_AVAILABLE >+-/* Not defined for LLVM 3.0 */ >+-#if !defined(LLVM_VERSION_MAJOR) >+-#define LLVM_VERSION_MAJOR 3 >+-#endif /* !defined(LLVM_VERSION_MAJOR) */ >+- >+-/* Not defined for LLVM 3.0 */ >+-#if !defined(LLVM_VERSION_MINOR) >+-#define LLVM_VERSION_MINOR 0 >+-#endif /* !defined(LLVM_VERSION_MINOR) */ >+ >+ #include <clang/CodeGen/CodeGenAction.h> >+ #include <clang/Frontend/CompilerInstance.h> >+ #include <clang/Frontend/CompilerInvocation.h> >+-#if LLVM_VERSION_MINOR <= 1 >+-#include <clang/Frontend/DiagnosticOptions.h> >+-#else >+ #include <clang/Basic/DiagnosticOptions.h> >+-#endif /* LLVM_VERSION_MINOR <= 1 */ >+ #include <clang/Frontend/TextDiagnosticPrinter.h> >+ #include <clang/Basic/TargetInfo.h> >+ #include <clang/Basic/TargetOptions.h> >+ #include <llvm/ADT/IntrusiveRefCntPtr.h> >+-#if LLVM_VERSION_MINOR <= 2 >+-#include <llvm/Module.h> >+-#else >+ #include <llvm/IR/Module.h> >+-#endif /* LLVM_VERSION_MINOR <= 2 */ >+ #include <llvm/Bitcode/ReaderWriter.h> >+ #include <llvm/Support/raw_ostream.h> >+ #endif >+@@ -686,10 +669,6 @@ namespace gbe { >+ args.push_back("-disable-llvm-optzns"); >+ if(bFastMath) >+ args.push_back("-D __FAST_RELAXED_MATH__=1"); >+-#if LLVM_VERSION_MINOR <= 2 >+- args.push_back("-triple"); >+- args.push_back("nvptx"); >+-#else >+ args.push_back("-x"); >+ args.push_back("cl"); >+ args.push_back("-triple"); >+@@ -698,7 +677,6 @@ namespace gbe { >+ args.push_back("-fblocks"); >+ } else >+ args.push_back("spir"); >+-#endif /* LLVM_VERSION_MINOR <= 2 */ >+ args.push_back("stringInput.cl"); >+ args.push_back("-ffp-contract=on"); >+ if(OCL_DEBUGINFO) args.push_back("-g"); >+@@ -791,11 +769,7 @@ namespace gbe { >+ std::string err; >+ llvm::raw_fd_ostream ostream (dumpLLVMFileName.c_str(), >+ err, >+- #if LLVM_VERSION_MINOR == 3 >+- 0 >+- #else >+ llvm::sys::fs::F_None >+- #endif >+ ); >+ >+ if (err.empty()) { >+@@ -807,11 +781,7 @@ namespace gbe { >+ std::string err; >+ llvm::raw_fd_ostream ostream (dumpSPIRBinaryName.c_str(), >+ err, >+- #if LLVM_VERSION_MINOR == 3 >+- 0 >+- #else >+ llvm::sys::fs::F_None >+- #endif >+ ); >+ if (err.empty()) >+ llvm::WriteBitcodeToFile(*out_module, ostream); >+diff --git a/backend/src/llvm/llvm_gen_backend.cpp b/backend/src/llvm/llvm_gen_backend.cpp >+index d7dabe3..6fa1ae0 100644 >+--- a/backend/src/llvm/llvm_gen_backend.cpp >++++ b/backend/src/llvm/llvm_gen_backend.cpp >+@@ -746,9 +746,6 @@ namespace gbe >+ void visitVAArgInst(VAArgInst &I) {NOT_SUPPORTED;} >+ void visitSwitchInst(SwitchInst &I) {NOT_SUPPORTED;} >+ void visitInvokeInst(InvokeInst &I) {NOT_SUPPORTED;} >+-#if LLVM_VERSION_MINOR == 0 >+- void visitUnwindInst(UnwindInst &I) {NOT_SUPPORTED;} >+-#endif /* __LLVM_30__ */ >+ void visitResumeInst(ResumeInst &I) {NOT_SUPPORTED;} >+ void visitInlineAsm(CallInst &I) {NOT_SUPPORTED;} >+ void visitIndirectBrInst(IndirectBrInst &I) {NOT_SUPPORTED;} >+@@ -1750,7 +1747,6 @@ namespace gbe >+ { >+ GBE_ASSERT(dyn_cast<ConstantExpr>(CPV) == NULL); >+ >+-#if LLVM_VERSION_MINOR > 0 >+ ConstantDataSequential *seq = dyn_cast<ConstantDataSequential>(CPV); >+ >+ if (seq) { >+@@ -1773,7 +1769,6 @@ namespace gbe >+ GBE_ASSERTM(0, "Const data array never be half float\n"); >+ } >+ } else >+-#endif /* LLVM_VERSION_MINOR > 0 */ >+ >+ if (dyn_cast<ConstantAggregateZero>(CPV)) { >+ Type* Ty = CPV->getType(); >+@@ -2344,9 +2339,6 @@ namespace gbe >+ Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); >+ >+ // Insert a new register for each function argument >+-#if LLVM_VERSION_MINOR <= 1 >+- const AttrListPtr &PAL = F.getAttributes(); >+-#endif /* LLVM_VERSION_MINOR <= 1 */ >+ for (; I != E; ++I, ++argID) { >+ uint32_t opID = argID; >+ #if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR < 9 >+@@ -2436,11 +2428,7 @@ namespace gbe >+ continue; >+ Type *pointed = pointerType->getElementType(); >+ // By value structure >+-#if LLVM_VERSION_MINOR <= 1 >+- if (PAL.paramHasAttr(argID+1, Attribute::ByVal)) { >+-#else >+ if (I->hasByValAttr()) { >+-#endif /* LLVM_VERSION_MINOR <= 1 */ >+ const size_t structSize = getTypeByteSize(unit, pointed); >+ ctx.input(argName, ir::FunctionArgument::STRUCTURE, reg, llvmInfo, structSize, getAlignmentByte(unit, type), 0); >+ } >+@@ -3164,15 +3152,9 @@ namespace gbe >+ void GenWriter::emitFunction(Function &F) >+ { >+ switch (F.getCallingConv()) { >+-#if LLVM_VERSION_MINOR <= 2 >+- case CallingConv::PTX_Device: // we do not emit device function >+- return; >+- case CallingConv::PTX_Kernel: >+-#else >+ case CallingConv::C: >+ case CallingConv::Fast: >+ case CallingConv::SPIR_KERNEL: >+-#endif >+ break; >+ default: >+ GBE_ASSERTM(false, "Unsupported calling convention"); >+@@ -3789,14 +3771,12 @@ namespace gbe >+ break; >+ case Intrinsic::stackrestore: >+ break; >+-#if LLVM_VERSION_MINOR >= 2 >+ case Intrinsic::lifetime_start: >+ case Intrinsic::lifetime_end: >+ break; >+ case Intrinsic::fmuladd: >+ this->newRegister(&I); >+ break; >+-#endif /* LLVM_VERSION_MINOR >= 2 */ >+ case Intrinsic::debugtrap: >+ case Intrinsic::trap: >+ case Intrinsic::dbg_value: >+@@ -4644,11 +4624,9 @@ namespace gbe >+ ctx.MOV(ir::getType(family), dst, src); >+ } >+ break; >+-#if LLVM_VERSION_MINOR >= 2 >+ case Intrinsic::lifetime_start: >+ case Intrinsic::lifetime_end: >+ break; >+-#endif /* LLVM_VERSION_MINOR >= 2 */ >+ case Intrinsic::debugtrap: >+ case Intrinsic::trap: >+ case Intrinsic::dbg_value: >+diff --git a/backend/src/llvm/llvm_printf_parser.cpp b/backend/src/llvm/llvm_printf_parser.cpp >+index 800f343..d64fc60 100644 >+--- a/backend/src/llvm/llvm_printf_parser.cpp >++++ b/backend/src/llvm/llvm_printf_parser.cpp >+@@ -389,15 +389,9 @@ error: >+ { >+ bool hasPrintf = false; >+ switch (F.getCallingConv()) { >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 2 >+- case CallingConv::PTX_Device: >+- return false; >+- case CallingConv::PTX_Kernel: >+-#else >+ case CallingConv::C: >+ case CallingConv::Fast: >+ case CallingConv::SPIR_KERNEL: >+-#endif >+ break; >+ default: >+ GBE_ASSERTM(false, "Unsupported calling convention"); >+diff --git a/backend/src/llvm/llvm_profiling.cpp b/backend/src/llvm/llvm_profiling.cpp >+index 96c95ee..734c69d 100644 >+--- a/backend/src/llvm/llvm_profiling.cpp >++++ b/backend/src/llvm/llvm_profiling.cpp >+@@ -26,27 +26,13 @@ >+ #include <stdlib.h> >+ >+ #include "llvm/Config/llvm-config.h" >+-#if LLVM_VERSION_MINOR <= 2 >+-#include "llvm/Function.h" >+-#include "llvm/InstrTypes.h" >+-#include "llvm/Instructions.h" >+-#include "llvm/IntrinsicInst.h" >+-#include "llvm/Module.h" >+-#else >+ #include "llvm/IR/Function.h" >+ #include "llvm/IR/InstrTypes.h" >+ #include "llvm/IR/Instructions.h" >+ #include "llvm/IR/IntrinsicInst.h" >+ #include "llvm/IR/Module.h" >+-#endif /* LLVM_VERSION_MINOR <= 2 */ >+ #include "llvm/Pass.h" >+-#if LLVM_VERSION_MINOR <= 1 >+-#include "llvm/Support/IRBuilder.h" >+-#elif LLVM_VERSION_MINOR == 2 >+-#include "llvm/IRBuilder.h" >+-#else >+ #include "llvm/IR/IRBuilder.h" >+-#endif /* LLVM_VERSION_MINOR <= 1 */ >+ >+ #if LLVM_VERSION_MINOR >= 5 >+ #include "llvm/IR/CallSite.h" >+@@ -111,15 +97,9 @@ namespace gbe >+ int pointNum = 0; >+ >+ switch (F.getCallingConv()) { >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 2 >+- case CallingConv::PTX_Device: >+- return false; >+- case CallingConv::PTX_Kernel: >+-#else >+ case CallingConv::C: >+ case CallingConv::Fast: >+ case CallingConv::SPIR_KERNEL: >+-#endif >+ break; >+ default: >+ GBE_ASSERTM(false, "Unsupported calling convention"); >+diff --git a/backend/src/llvm/llvm_scalarize.cpp b/backend/src/llvm/llvm_scalarize.cpp >+index 6f46c9d..329e3a9 100644 >+--- a/backend/src/llvm/llvm_scalarize.cpp >++++ b/backend/src/llvm/llvm_scalarize.cpp >+@@ -884,15 +884,9 @@ namespace gbe { >+ bool Scalarize::runOnFunction(Function& F) >+ { >+ switch (F.getCallingConv()) { >+-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 2 >+- case CallingConv::PTX_Device: >+- return false; >+- case CallingConv::PTX_Kernel: >+-#else >+ case CallingConv::C: >+ case CallingConv::Fast: >+ case CallingConv::SPIR_KERNEL: >+-#endif >+ break; >+ default: >+ GBE_ASSERTM(false, "Unsupported calling convention"); >+-- >+cgit v0.10.2 >+ > >Property changes on: lang/beignet/files/extra-patch-remove_old_llvm_support >___________________________________________________________________ >Added: fbsd:nokeywords >## -0,0 +1 ## >+yes >\ No newline at end of property >Added: svn:eol-style >## -0,0 +1 ## >+native >\ No newline at end of property >Added: svn:mime-type >## -0,0 +1 ## >+text/plain >\ No newline at end of property
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 218644
: 181768