diff options
author | Pan Xiuli <xiuli.pan@intel.com> | 2017-04-11 15:59:50 +0800 |
---|---|---|
committer | Yang Rong <rong.r.yang@intel.com> | 2017-04-13 19:39:29 +0800 |
commit | 919deced0cd796e30410d45fc71bcda37441e80c (patch) | |
tree | 01043bccdbc8e997e9104b205bac5a186eb893b4 /backend | |
parent | 8e119eb32e01066c23c3d96bd2b42032e03f7628 (diff) |
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>
Diffstat (limited to 'backend')
21 files changed, 217 insertions, 34 deletions
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 6e8227a6..724058c6 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 fa45a420..a106259f 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 5682c45d..b0566423 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 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 f414fbbd..10752a35 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 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"; } |