diff options
author | Yang, Rong R <rong.r.yang@intel.com> | 2016-11-28 19:32:36 +0800 |
---|---|---|
committer | Yang Rong <rong.r.yang@intel.com> | 2016-12-28 17:37:17 +0800 |
commit | 7bbb487ec00e1d2db6186bf77bc0d06d2b0ff3db (patch) | |
tree | 5a8fab0ae398d8c7ff862f4954fb7317f890a7d7 /backend/src/llvm | |
parent | 8cd6fcc8535ec7a2bdae1c55e5c8326e26466b8e (diff) | |
download | beignet-7bbb487ec00e1d2db6186bf77bc0d06d2b0ff3db.tar.gz |
OCL20: enable -cl-std=CL2.0.
When build from source, get the OpenCL version from the option. Use
spir64 triple if it is OpenCL 2.0.
Get the OpenCL version for llvm module's meta. If OpenCL version is
2.0, set the unit's point size to 64 bits before using
unit.getPointerSize().
Signed-off-by: Yang Rong <rong.r.yang@intel.com>
Reviewed-by: Ruiling Song <ruiling.song@intel.com>
Diffstat (limited to 'backend/src/llvm')
-rw-r--r-- | backend/src/llvm/llvm_bitcode_link.cpp | 19 | ||||
-rw-r--r-- | backend/src/llvm/llvm_gen_backend.cpp | 3 | ||||
-rw-r--r-- | backend/src/llvm/llvm_gen_backend.hpp | 4 | ||||
-rw-r--r-- | backend/src/llvm/llvm_passes.cpp | 25 | ||||
-rw-r--r-- | backend/src/llvm/llvm_to_gen.cpp | 5 |
5 files changed, 46 insertions, 10 deletions
diff --git a/backend/src/llvm/llvm_bitcode_link.cpp b/backend/src/llvm/llvm_bitcode_link.cpp index 0b01929f..87cefb51 100644 --- a/backend/src/llvm/llvm_bitcode_link.cpp +++ b/backend/src/llvm/llvm_bitcode_link.cpp @@ -26,18 +26,23 @@ #include "src/GBEConfig.h" #include "llvm_includes.hpp" #include "llvm/llvm_gen_backend.hpp" +#include "ir/unit.hpp" using namespace llvm; SVAR(OCL_BITCODE_LIB_PATH, OCL_BITCODE_BIN); +SVAR(OCL_BITCODE_LIB_20_PATH, OCL_BITCODE_BIN_20); namespace gbe { - static Module* createOclBitCodeModule(LLVMContext& ctx, bool strictMath) + static Module* createOclBitCodeModule(LLVMContext& ctx, + bool strictMath, + uint32_t oclVersion) { - std::string bitCodeFiles = OCL_BITCODE_LIB_PATH; + std::string bitCodeFiles = oclVersion >= 200 ? + OCL_BITCODE_LIB_20_PATH : OCL_BITCODE_LIB_PATH; if(bitCodeFiles == "") - bitCodeFiles = OCL_BITCODE_BIN; + bitCodeFiles = oclVersion >= 200 ? OCL_BITCODE_BIN_20 : OCL_BITCODE_BIN; std::istringstream bitCodeFilePath(bitCodeFiles); std::string FilePath; bool findBC = false; @@ -135,12 +140,16 @@ namespace gbe } - Module* runBitCodeLinker(Module *mod, bool strictMath) + Module* runBitCodeLinker(Module *mod, bool strictMath, ir::Unit &unit) { LLVMContext& ctx = mod->getContext(); std::set<std::string> materializedFuncs; std::vector<GlobalValue *> Gvs; - Module* clonedLib = createOclBitCodeModule(ctx, strictMath); + + uint32_t oclVersion = getModuleOclVersion(mod); + ir::PointerSize size = oclVersion >= 200 ? ir::POINTER_64_BITS : ir::POINTER_32_BITS; + unit.setPointerSize(size); + Module* clonedLib = createOclBitCodeModule(ctx, strictMath, oclVersion); if (clonedLib == NULL) return NULL; diff --git a/backend/src/llvm/llvm_gen_backend.cpp b/backend/src/llvm/llvm_gen_backend.cpp index d7bdcf04..8c7a230c 100644 --- a/backend/src/llvm/llvm_gen_backend.cpp +++ b/backend/src/llvm/llvm_gen_backend.cpp @@ -1697,6 +1697,9 @@ namespace gbe // Initialize TheModule = &M; + uint32_t oclVersion = getModuleOclVersion(TheModule); + legacyMode = oclVersion >= 200 ? false : true; + unit.setOclVersion(oclVersion); collectGlobalConstant(); return false; } diff --git a/backend/src/llvm/llvm_gen_backend.hpp b/backend/src/llvm/llvm_gen_backend.hpp index f2a278e6..1fecc739 100644 --- a/backend/src/llvm/llvm_gen_backend.hpp +++ b/backend/src/llvm/llvm_gen_backend.hpp @@ -153,7 +153,9 @@ namespace gbe llvm::FunctionPass* createSamplerFixPass(); /*! Add all the function call of ocl to our bitcode. */ - llvm::Module* runBitCodeLinker(llvm::Module *mod, bool strictMath); + llvm::Module* runBitCodeLinker(llvm::Module *mod, bool strictMath, ir::Unit &unit); + + uint32_t getModuleOclVersion(const llvm::Module *M); void* getPrintfInfo(llvm::CallInst* inst); } /* namespace gbe */ diff --git a/backend/src/llvm/llvm_passes.cpp b/backend/src/llvm/llvm_passes.cpp index 02dd4bfb..f5d90521 100644 --- a/backend/src/llvm/llvm_passes.cpp +++ b/backend/src/llvm/llvm_passes.cpp @@ -65,6 +65,27 @@ namespace gbe return bKernel; } + uint32_t getModuleOclVersion(const llvm::Module *M) { + uint32_t oclVersion = 120; + NamedMDNode *version = M->getNamedMetadata("opencl.ocl.version"); + if (version == NULL) + return oclVersion; + uint32_t ops = version->getNumOperands(); + if(ops > 0) { + uint32_t major = 0, minor = 0; + MDNode* node = version->getOperand(0); +#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6 + major = mdconst::extract<ConstantInt>(node->getOperand(0))->getZExtValue(); + minor = mdconst::extract<ConstantInt>(node->getOperand(1))->getZExtValue(); +#else + major = cast<ConstantInt>(MD->getOperand(0))->getZExtValue(); + minor = cast<ConstantInt>(MD->getOperand(1))->getZExtValue(); +#endif + oclVersion = major * 100 + minor * 10; + } + return oclVersion; + } + int32_t getPadding(int32_t offset, int32_t align) { return (align - (offset % align)) % align; } @@ -262,7 +283,7 @@ namespace gbe if(!operand) continue; - +#if 0 //HACK TODO: Inserted by type replacement.. this code could break something???? if(getTypeByteSize(unit, operand->getType())>4) { @@ -286,7 +307,7 @@ namespace gbe "", GEPInst); } } - +#endif Value* tmpMul = operand; if (size != 1) { tmpMul = BinaryOperator::Create(Instruction::Mul, newConstSize, operand, diff --git a/backend/src/llvm/llvm_to_gen.cpp b/backend/src/llvm/llvm_to_gen.cpp index a889c56a..b58dfb72 100644 --- a/backend/src/llvm/llvm_to_gen.cpp +++ b/backend/src/llvm/llvm_to_gen.cpp @@ -321,8 +321,9 @@ namespace gbe std::unique_ptr<Module> M; - /* Before do any thing, we first filter in all CL functions in bitcode. */ - M.reset(runBitCodeLinker(cl_mod, strictMath)); + /* Before do any thing, we first filter in all CL functions in bitcode. */ + /* Also set unit's pointer size in runBitCodeLinker */ + M.reset(runBitCodeLinker(cl_mod, strictMath, unit)); if (!module) delete cl_mod; if (M.get() == 0) |