From: Ruiling Song Date: Wed, 16 Oct 2013 07:38:07 +0000 (+0800) Subject: GBE: Skip non-kernel functions in backend passes. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=10d2b050a4cbac0b4e5fa660357d81464b00e744;p=contrib%2Fbeignet.git GBE: Skip non-kernel functions in backend passes. As non-kernel functions hit many assert in the backend, simply skip them as we already inline all function calls. Signed-off-by: Ruiling Song Reviewed-by: "Yang, Rong R" --- diff --git a/backend/src/llvm/llvm_gen_backend.cpp b/backend/src/llvm/llvm_gen_backend.cpp index 5fb4f49..7519ff1 100644 --- a/backend/src/llvm/llvm_gen_backend.cpp +++ b/backend/src/llvm/llvm_gen_backend.cpp @@ -472,6 +472,10 @@ namespace gbe if (F.hasAvailableExternallyLinkage()) return false; + // As we inline all function calls, so skip non-kernel functions + bool bKernel = isKernelFunction(F); + if(!bKernel) return false; + LI = &getAnalysis(); emitFunction(F); diff --git a/backend/src/llvm/llvm_gen_backend.hpp b/backend/src/llvm/llvm_gen_backend.hpp index 2ad879e..d6c98dd 100644 --- a/backend/src/llvm/llvm_gen_backend.hpp +++ b/backend/src/llvm/llvm_gen_backend.hpp @@ -75,6 +75,9 @@ namespace gbe /*! Get the type size in bytes */ uint32_t getTypeByteSize(const ir::Unit &unit, llvm::Type* Ty); + /*! whether this is a kernel function */ + bool isKernelFunction(const llvm::Function &f); + /*! Create a Gen-IR unit */ llvm::FunctionPass *createGenPass(ir::Unit &unit); diff --git a/backend/src/llvm/llvm_passes.cpp b/backend/src/llvm/llvm_passes.cpp index 4bafc0d..60c9df1 100644 --- a/backend/src/llvm/llvm_passes.cpp +++ b/backend/src/llvm/llvm_passes.cpp @@ -105,6 +105,23 @@ using namespace llvm; namespace gbe { + bool isKernelFunction(const llvm::Function &F) { + const Module *module = F.getParent(); + const Module::NamedMDListType& globalMD = module->getNamedMDList(); + bool bKernel = false; + for(auto i = globalMD.begin(); i != globalMD.end(); i++) { + const NamedMDNode &md = *i; + if(strcmp(md.getName().data(), "opencl.kernels") != 0) continue; + uint32_t ops = md.getNumOperands(); + for(uint32_t x = 0; x < ops; x++) { + MDNode* node = md.getOperand(x); + Value * op = node->getOperand(0); + if(op == &F) bKernel = true; + } + } + return bKernel; + } + uint32_t getPadding(uint32_t offset, uint32_t align) { return (align - (offset % align)) % align; } diff --git a/backend/src/llvm/llvm_scalarize.cpp b/backend/src/llvm/llvm_scalarize.cpp index 7a40616..edfc369 100644 --- a/backend/src/llvm/llvm_scalarize.cpp +++ b/backend/src/llvm/llvm_scalarize.cpp @@ -767,6 +767,10 @@ namespace gbe { default: GBE_ASSERTM(false, "Unsupported calling convention"); } + // As we inline all function calls, so skip non-kernel functions + bool bKernel = isKernelFunction(F); + if(!bKernel) return false; + bool changed = false; module = F.getParent(); intTy = IntegerType::get(module->getContext(), 32);