Date: Thursday, April 13, 2017 @ 09:54:14 Author: foutrelis Revision: 222605
archrelease: copy trunk to community-staging-x86_64 Added: beignet/repos/community-staging-x86_64/ beignet/repos/community-staging-x86_64/0001-Backend-Remove-old-llvm-support-code.patch (from rev 222604, beignet/trunk/0001-Backend-Remove-old-llvm-support-code.patch) beignet/repos/community-staging-x86_64/0002-Backend-Fix-an-include-file-error-problem.patch (from rev 222604, beignet/trunk/0002-Backend-Fix-an-include-file-error-problem.patch) beignet/repos/community-staging-x86_64/0003-Backend-Refine-LLVM-version-check-macro.patch (from rev 222604, beignet/trunk/0003-Backend-Refine-LLVM-version-check-macro.patch) beignet/repos/community-staging-x86_64/0004-Backend-Add-LLVM40-support.patch (from rev 222604, beignet/trunk/0004-Backend-Add-LLVM40-support.patch) beignet/repos/community-staging-x86_64/PKGBUILD (from rev 222604, beignet/trunk/PKGBUILD) ------------------------------------------------------+ 0001-Backend-Remove-old-llvm-support-code.patch | 306 +++++ 0002-Backend-Fix-an-include-file-error-problem.patch | 80 + 0003-Backend-Refine-LLVM-version-check-macro.patch | 940 +++++++++++++++++ 0004-Backend-Add-LLVM40-support.patch | 715 ++++++++++++ PKGBUILD | 57 + 5 files changed, 2098 insertions(+) Copied: beignet/repos/community-staging-x86_64/0001-Backend-Remove-old-llvm-support-code.patch (from rev 222604, beignet/trunk/0001-Backend-Remove-old-llvm-support-code.patch) =================================================================== --- community-staging-x86_64/0001-Backend-Remove-old-llvm-support-code.patch (rev 0) +++ community-staging-x86_64/0001-Backend-Remove-old-llvm-support-code.patch 2017-04-13 09:54:14 UTC (rev 222605) @@ -0,0 +1,306 @@ +From d8a212e48ccded8b18c04e504e3e94ccd131d4ee Mon Sep 17 00:00:00 2001 +From: Pan Xiuli <xiuli....@intel.com> +Date: Fri, 17 Mar 2017 14:15:58 +0800 +Subject: [PATCH 1/4] 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....@intel.com> +Reviewed-by: Yang Rong <rong.r.y...@intel.com> +--- + backend/src/backend/gen_program.cpp | 6 ------ + backend/src/backend/program.cpp | 30 ------------------------------ + backend/src/llvm/llvm_gen_backend.cpp | 22 ---------------------- + backend/src/llvm/llvm_printf_parser.cpp | 6 ------ + backend/src/llvm/llvm_profiling.cpp | 20 -------------------- + backend/src/llvm/llvm_scalarize.cpp | 6 ------ + 6 files changed, 90 deletions(-) + +diff --git a/backend/src/backend/gen_program.cpp b/backend/src/backend/gen_program.cpp +index 073ede64..376342b8 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 09c79d81..2e676df4 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 3fefa926..9baf934d 100644 +--- a/backend/src/llvm/llvm_gen_backend.cpp ++++ b/backend/src/llvm/llvm_gen_backend.cpp +@@ -745,9 +745,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;} +@@ -1749,7 +1746,6 @@ namespace gbe + { + GBE_ASSERT(dyn_cast<ConstantExpr>(CPV) == NULL); + +-#if LLVM_VERSION_MINOR > 0 + ConstantDataSequential *seq = dyn_cast<ConstantDataSequential>(CPV); + + if (seq) { +@@ -1772,7 +1768,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(); +@@ -2343,9 +2338,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 +@@ -2435,11 +2427,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); + } +@@ -3163,15 +3151,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"); +@@ -3788,14 +3770,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: +@@ -4549,11 +4529,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 800f343f..d64fc60c 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 96c95eeb..734c69d9 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 8850abba..044a7e59 100644 +--- a/backend/src/llvm/llvm_scalarize.cpp ++++ b/backend/src/llvm/llvm_scalarize.cpp +@@ -873,15 +873,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"); +-- +2.12.2 + Copied: beignet/repos/community-staging-x86_64/0002-Backend-Fix-an-include-file-error-problem.patch (from rev 222604, beignet/trunk/0002-Backend-Fix-an-include-file-error-problem.patch) =================================================================== --- community-staging-x86_64/0002-Backend-Fix-an-include-file-error-problem.patch (rev 0) +++ community-staging-x86_64/0002-Backend-Fix-an-include-file-error-problem.patch 2017-04-13 09:54:14 UTC (rev 222605) @@ -0,0 +1,80 @@ +From d6c2927da11e774dcf1018e66433b6954b4e4d26 Mon Sep 17 00:00:00 2001 +From: Pan Xiuli <xiuli....@intel.com> +Date: Fri, 17 Mar 2017 14:15:59 +0800 +Subject: [PATCH 2/4] Backend: Fix an include file error problem + +We should not include any llvm header in ir unit, and we need add +missing headers for proliling after deleting llvm headers. + +Signed-off-by: Pan Xiuli <xiuli....@intel.com> +Reviewed-by: Yang Rong <rong.r.y...@intel.com> +--- + backend/src/ir/profiling.cpp | 1 + + backend/src/ir/unit.hpp | 4 +--- + backend/src/llvm/llvm_gen_backend.cpp | 2 +- + backend/src/llvm/llvm_printf_parser.cpp | 2 +- + 4 files changed, 4 insertions(+), 5 deletions(-) + +diff --git a/backend/src/ir/profiling.cpp b/backend/src/ir/profiling.cpp +index ac61e9b2..3289e769 100644 +--- a/backend/src/ir/profiling.cpp ++++ b/backend/src/ir/profiling.cpp +@@ -24,6 +24,7 @@ + #include <stdlib.h> + #include "ir/profiling.hpp" + #include "src/cl_device_data.h" ++#include <inttypes.h> + + namespace gbe + { +diff --git a/backend/src/ir/unit.hpp b/backend/src/ir/unit.hpp +index 46d7be79..d7a2a672 100644 +--- a/backend/src/ir/unit.hpp ++++ b/backend/src/ir/unit.hpp +@@ -32,8 +32,6 @@ + #include "sys/map.hpp" + #include <string.h> + +-#include "llvm/IR/Instructions.h" +- + namespace gbe { + namespace ir { + +@@ -46,7 +44,7 @@ namespace ir { + public: + typedef map<std::string, Function*> FunctionSet; + /*! Moved from printf pass */ +- map<llvm::CallInst*, PrintfSet::PrintfFmt*> printfs; ++ map<void *, PrintfSet::PrintfFmt*> printfs; + vector<std::string> blockFuncs; + /*! Create an empty unit */ + Unit(PointerSize pointerSize = POINTER_32_BITS); +diff --git a/backend/src/llvm/llvm_gen_backend.cpp b/backend/src/llvm/llvm_gen_backend.cpp +index 9baf934d..71a3174e 100644 +--- a/backend/src/llvm/llvm_gen_backend.cpp ++++ b/backend/src/llvm/llvm_gen_backend.cpp +@@ -763,7 +763,7 @@ namespace gbe + void emitUnalignedDQLoadStore(ir::Register ptr, Value *llvmValues, ir::AddressSpace addrSpace, ir::Register bti, bool isLoad, bool dwAligned, bool fixedBTI); + void visitInstruction(Instruction &I) {NOT_SUPPORTED;} + ir::PrintfSet::PrintfFmt* getPrintfInfo(CallInst* inst) { +- if (unit.printfs.find(inst) == unit.printfs.end()) ++ if (unit.printfs.find((void *)inst) == unit.printfs.end()) + return NULL; + return unit.printfs[inst]; + } +diff --git a/backend/src/llvm/llvm_printf_parser.cpp b/backend/src/llvm/llvm_printf_parser.cpp +index d64fc60c..a1b1c2c9 100644 +--- a/backend/src/llvm/llvm_printf_parser.cpp ++++ b/backend/src/llvm/llvm_printf_parser.cpp +@@ -381,7 +381,7 @@ error: + } + + GBE_ASSERT(unit.printfs.find(call) == unit.printfs.end()); +- unit.printfs.insert(std::pair<llvm::CallInst*, PrintfSet::PrintfFmt*>(call, printf_fmt)); ++ unit.printfs.insert(std::pair<void *, PrintfSet::PrintfFmt*>((void *)call, printf_fmt)); + return true; + } + +-- +2.12.2 + Copied: beignet/repos/community-staging-x86_64/0003-Backend-Refine-LLVM-version-check-macro.patch (from rev 222604, beignet/trunk/0003-Backend-Refine-LLVM-version-check-macro.patch) =================================================================== --- community-staging-x86_64/0003-Backend-Refine-LLVM-version-check-macro.patch (rev 0) +++ community-staging-x86_64/0003-Backend-Refine-LLVM-version-check-macro.patch 2017-04-13 09:54:14 UTC (rev 222605) @@ -0,0 +1,940 @@ +From 3b3ddb42410d2b65d8c616a2f3ed9f285d6cd828 Mon Sep 17 00:00:00 2001 +From: Pan Xiuli <xiuli....@intel.com> +Date: Fri, 17 Mar 2017 14:16:01 +0800 +Subject: [PATCH 3/4] 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....@intel.com> +Reviewed-by: Yang Rong <rong.r.y...@intel.com> +--- + backend/src/backend/gen_program.cpp | 12 ++--- + backend/src/backend/program.cpp | 16 +++--- + backend/src/ir/function.hpp | 2 +- + backend/src/llvm/ExpandLargeIntegers.cpp | 6 +-- + backend/src/llvm/llvm_bitcode_link.cpp | 14 +++--- + backend/src/llvm/llvm_device_enqueue.cpp | 10 ++-- + backend/src/llvm/llvm_gen_backend.cpp | 38 +++++++------- + backend/src/llvm/llvm_gen_backend.hpp | 2 +- + backend/src/llvm/llvm_includes.hpp | 8 +-- + backend/src/llvm/llvm_loadstore_optimization.cpp | 6 +-- + backend/src/llvm/llvm_passes.cpp | 6 +-- + backend/src/llvm/llvm_profiling.cpp | 2 +- + backend/src/llvm/llvm_sampler_fix.cpp | 2 +- + backend/src/llvm/llvm_scalarize.cpp | 2 +- + backend/src/llvm/llvm_to_gen.cpp | 64 ++++++++++++------------ + backend/src/llvm/llvm_to_gen.hpp | 4 +- + backend/src/llvm/llvm_unroll.cpp | 14 +++--- + 17 files changed, 104 insertions(+), 104 deletions(-) + +diff --git a/backend/src/backend/gen_program.cpp b/backend/src/backend/gen_program.cpp +index 376342b8..998e340f 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 2e676df4..f9f75215 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(), +@@ -1121,7 +1121,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(); +@@ -1595,7 +1595,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 5fcb14ac..64d9727b 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 60740f5d..8515dc13 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 89d5e7ce..869db89c 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 ee236def..9a0fb46f 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 71a3174e..74539cde 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>(); +@@ -834,7 +834,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(); +@@ -1088,7 +1088,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(); +@@ -1247,7 +1247,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)); +@@ -1271,7 +1271,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"); +@@ -1297,7 +1297,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 + +@@ -1339,7 +1339,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(); +@@ -2119,7 +2119,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"); +@@ -2221,7 +2221,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)); +@@ -2263,13 +2263,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)); +@@ -2298,7 +2298,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)); +@@ -2340,13 +2340,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(); +@@ -2913,7 +2913,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 1ab77c9d..0ceba58d 100644 +--- a/backend/src/llvm/llvm_gen_backend.hpp ++++ b/backend/src/llvm/llvm_gen_backend.hpp +@@ -146,7 +146,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 0b809797..a242fd34 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 e797e989..4f4639c0 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 c5f3ffe4..02a24a2a 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 734c69d9..bc169516 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 de7ebdbc..2e8bcf93 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 044a7e59..e9a2a66f 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 bef4df1b..9b3b1f4e 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 d3928c6b..90258521 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 e24dc4fa..bfd3bbe3 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); +-- +2.12.2 + Copied: beignet/repos/community-staging-x86_64/0004-Backend-Add-LLVM40-support.patch (from rev 222604, beignet/trunk/0004-Backend-Add-LLVM40-support.patch) =================================================================== --- community-staging-x86_64/0004-Backend-Add-LLVM40-support.patch (rev 0) +++ community-staging-x86_64/0004-Backend-Add-LLVM40-support.patch 2017-04-13 09:54:14 UTC (rev 222605) @@ -0,0 +1,715 @@ +From 87a3b0903eabb2a31f01ac9b1c8846a955507886 Mon Sep 17 00:00:00 2001 +From: Pan Xiuli <xiuli....@intel.com> +Date: Tue, 11 Apr 2017 15:59:50 +0800 +Subject: [PATCH 4/4] 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....@intel.com> +Reviewed-by: Yang Rong <rong.r.y...@intel.com> +--- + backend/src/backend/gen_program.cpp | 4 ++ + backend/src/backend/program.cpp | 25 ++++++++--- + backend/src/ir/half.cpp | 20 +++++++++ + backend/src/libocl/CMakeLists.txt | 4 +- + backend/src/libocl/include/ocl_enqueue.h | 6 +-- + backend/src/libocl/src/ocl_image.cl | 9 ++-- + backend/src/libocl/src/ocl_sampler.ll | 10 +++++ + backend/src/libocl/src/ocl_sampler_20.ll | 10 +++++ + backend/src/llvm/ExpandUtils.cpp | 4 ++ + backend/src/llvm/llvm_barrier_nodup.cpp | 7 ++- + backend/src/llvm/llvm_bitcode_link.cpp | 54 ++++++++++++++++++------ + backend/src/llvm/llvm_gen_backend.cpp | 36 +++++++++++++++- + backend/src/llvm/llvm_gen_ocl_function.hxx | 4 ++ + backend/src/llvm/llvm_includes.hpp | 12 ++++++ + backend/src/llvm/llvm_intrinsic_lowering.cpp | 7 ++- + backend/src/llvm/llvm_loadstore_optimization.cpp | 8 +++- + backend/src/llvm/llvm_passes.cpp | 4 ++ + backend/src/llvm/llvm_printf_parser.cpp | 8 ++++ + backend/src/llvm/llvm_profiling.cpp | 4 ++ + backend/src/llvm/llvm_to_gen.cpp | 8 ++++ + backend/src/llvm/llvm_unroll.cpp | 7 ++- + 21 files changed, 217 insertions(+), 34 deletions(-) + create mode 100644 backend/src/libocl/src/ocl_sampler.ll + create mode 100644 backend/src/libocl/src/ocl_sampler_20.ll + +diff --git a/backend/src/backend/gen_program.cpp b/backend/src/backend/gen_program.cpp +index 998e340f..c1827b11 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 f9f75215..d570c06a 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 1c0d7eb9..0abc6cb3 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 c68ecb01..2917e6d2 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 6479df71..7ccab59f 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 2febfdac..e66aa155 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 00000000..6d39fdb2 +--- /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 00000000..bea6d755 +--- /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 a09d9908..cb1736b7 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 727e6bd2..a7d0d1ad 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 869db89c..5c6585d0 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 74539cde..20f1de74 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 +@@ -2409,10 +2422,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); +@@ -4061,6 +4075,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; +@@ -4479,10 +4502,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); +@@ -5462,6 +5494,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 86485da3..08087cb9 100644 +--- a/backend/src/llvm/llvm_gen_ocl_function.hxx ++++ b/backend/src/llvm/llvm_gen_ocl_function.hxx +@@ -266,3 +266,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 a242fd34..184553af 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 f01bb516..57c933f5 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 4f4639c0..5aa38bef 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 02a24a2a..f2732770 100644 +--- a/backend/src/llvm/llvm_passes.cpp ++++ b/backend/src/llvm/llvm_passes.cpp +@@ -222,7 +222,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 a1b1c2c9..6bb7c52a 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 bc169516..f7e4cc53 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 9b3b1f4e..37919ec6 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 bfd3bbe3..107d7937 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"; + } + +-- +2.12.2 + Copied: beignet/repos/community-staging-x86_64/PKGBUILD (from rev 222604, beignet/trunk/PKGBUILD) =================================================================== --- community-staging-x86_64/PKGBUILD (rev 0) +++ community-staging-x86_64/PKGBUILD 2017-04-13 09:54:14 UTC (rev 222605) @@ -0,0 +1,57 @@ +# Maintainer: Bruno Pagani (a.k.a. ArchangeGabriel) <archa...@archlinux.org> +# Contributor: Antoine Lubineau <anto...@lubignon.info> +# Contributor: Leopold Bloom <blinxw...@gmail.com> +# Contributor: Michal Krenek (a.k.a. Mikos) <m.kre...@gmail.com> + +pkgname=beignet +pkgver=1.3.1 +pkgrel=2 +pkgdesc="An open source OpenCL implementation for Intel IvyBridge+ iGPUs" +arch=('x86_64') +url="https://01.org/${pkgname}" +license=('LGPL') +depends=('glu' 'llvm' 'mesa' 'ocl-icd' 'opencl-headers') +makedepends=('clang' 'cmake' 'python') +provides=('opencl-intel') +conflicts=('opencl-intel') +source=("https://01.org/sites/default/files/${pkgname}-${pkgver}-source.tar.gz" + '0001-Backend-Remove-old-llvm-support-code.patch' + '0002-Backend-Fix-an-include-file-error-problem.patch' + '0003-Backend-Refine-LLVM-version-check-macro.patch' + '0004-Backend-Add-LLVM40-support.patch') +sha256sums=('399b7bc64d674b3092683263f7c085c5592686b9d837817e77857248e5cb561f' + 'f6b785f887aae72da09af71cf0e5ffc4609cb560347aee80f201699f8bbe86d7' + 'ac16a8ecc0ae0ebc1073ffc101315e74deda8f8025918427e9e86a3fc6a71851' + 'f3d681efdb6b2c390823ff91a6fed02742e556da6dbb43fef41240d1d6d5ee07' + 'a0d3aebf0d24a8dd4939833b8629947c813338e45dc7dfcd277fafdb10f093e5') + +prepare() { + cd ${pkgname^}-${pkgver}-Source + mkdir -p build + + # LLVM 4.0.0 support + patch -Np1 -i ../0001-Backend-Remove-old-llvm-support-code.patch + patch -Np1 -i ../0002-Backend-Fix-an-include-file-error-problem.patch + patch -Np1 -i ../0003-Backend-Refine-LLVM-version-check-macro.patch + patch -Np1 -i ../0004-Backend-Add-LLVM40-support.patch +} + +build() { + cd ${pkgname^}-${pkgver}-Source/build + + cmake .. \ + -DCMAKE_INSTALL_PREFIX=/usr \ + -DCMAKE_INSTALL_LIBDIR=/usr/lib \ + -DCMAKE_BUILD_TYPE=RELEASE + make +} + +package() { + cd ${pkgname^}-${pkgver}-Source/build + + make DESTDIR="${pkgdir}" install + + # Remove headers already provided by 'opencl-headers' + cd "${pkgdir}/usr/include/CL" + rm cl.h cl_egl.h cl_ext.h cl_gl.h cl_gl_ext.h cl_platform.h opencl.h +}