LLVM IR pass will produce memcpy and memset, if set LinkOnceAnyLinkage, memcpy and memset will be delete before and cause fail.
Signed-off-by: Yang Rong <rong.r.y...@intel.com> --- backend/src/llvm/StripAttributes.cpp | 15 +++++++++++---- backend/src/llvm/llvm_gen_backend.hpp | 2 +- backend/src/llvm/llvm_to_gen.cpp | 4 ++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/backend/src/llvm/StripAttributes.cpp b/backend/src/llvm/StripAttributes.cpp index 9d07c29..afa8783 100644 --- a/backend/src/llvm/StripAttributes.cpp +++ b/backend/src/llvm/StripAttributes.cpp @@ -79,10 +79,13 @@ namespace { class StripAttributes : public FunctionPass { public: static char ID; // Pass identification, replacement for typeid - StripAttributes() : FunctionPass(ID) { + StripAttributes(bool lastTime) : FunctionPass(ID), + lastTime(lastTime) { } virtual bool runOnFunction(Function &Func); + private: + bool lastTime; //last time all StripAttributes }; } @@ -93,7 +96,11 @@ bool StripAttributes::runOnFunction(Function &Func) { Func.setLinkage(GlobalValue::ExternalLinkage); if (!gbe::isKernelFunction(Func)) { Func.addFnAttr(Attribute::AlwaysInline); - Func.setLinkage(GlobalValue::LinkOnceAnyLinkage); + if (lastTime || + (Func.getName().find("__gen_mem") == std::string::npos)) + // Memcpy and memset functions could be deleted at last inline. + // Delete memcpy and memset functions for output llvm ir friendly. + Func.setLinkage(GlobalValue::LinkOnceAnyLinkage); } for (Function::iterator BB = Func.begin(), E = Func.end(); @@ -109,6 +116,6 @@ bool StripAttributes::runOnFunction(Function &Func) { return true; } -FunctionPass *llvm::createStripAttributesPass() { - return new StripAttributes(); +FunctionPass *llvm::createStripAttributesPass(bool lastTime) { + return new StripAttributes(lastTime); } diff --git a/backend/src/llvm/llvm_gen_backend.hpp b/backend/src/llvm/llvm_gen_backend.hpp index 1ab77c9..79b698c 100644 --- a/backend/src/llvm/llvm_gen_backend.hpp +++ b/backend/src/llvm/llvm_gen_backend.hpp @@ -46,7 +46,7 @@ namespace llvm { FunctionPass *createExpandConstantExprPass(); FunctionPass *createExpandLargeIntegersPass(); FunctionPass *createPromoteIntegersPass(); - FunctionPass *createStripAttributesPass(); + FunctionPass *createStripAttributesPass(bool lastTime); // Copy debug information from Original to New, and return New. template <typename T> T *CopyDebug(T *New, llvm::Instruction *Original) { New->setDebugLoc(Original->getDebugLoc()); diff --git a/backend/src/llvm/llvm_to_gen.cpp b/backend/src/llvm/llvm_to_gen.cpp index bef4df1..5fd7219 100644 --- a/backend/src/llvm/llvm_to_gen.cpp +++ b/backend/src/llvm/llvm_to_gen.cpp @@ -139,7 +139,7 @@ namespace gbe MPM.add(createBarrierNodupPass(false)); // remove noduplicate fnAttr before inlining. MPM.add(createFunctionInliningPass(20000)); MPM.add(createBarrierNodupPass(true)); // restore noduplicate fnAttr after inlining. - MPM.add(createStripAttributesPass()); // Strip unsupported attributes and calling conventions. + MPM.add(createStripAttributesPass(false)); // Strip unsupported attributes and calling conventions. MPM.add(createSamplerFixPass()); MPM.add(createGlobalOptimizerPass()); // Optimize out global vars @@ -372,7 +372,7 @@ namespace gbe #endif // Print the code before further optimizations passes.add(createIntrinsicLoweringPass()); - passes.add(createStripAttributesPass()); // Strip unsupported attributes and calling conventions. + passes.add(createStripAttributesPass(true)); // Strip unsupported attributes and calling conventions. passes.add(createFunctionInliningPass(20000)); #if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7 passes.add(createSROAPass()); -- 2.1.4 _______________________________________________ Beignet mailing list Beignet@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/beignet