The patchset LGTM, thanks.
> -----Original Message----- > From: Beignet [mailto:beignet-boun...@lists.freedesktop.org] On Behalf Of > Zhigang Gong > Sent: Wednesday, April 1, 2015 10:06 > To: beignet@lists.freedesktop.org > Cc: Gong, Zhigang > Subject: [Beignet] [PATCH 1/8] strip unsupported attributes and calling > conventions. > > Signed-off-by: Zhigang Gong <zhigang.g...@intel.com> > --- > backend/src/CMakeLists.txt | 1 + > backend/src/llvm/StripAttributes.cpp | 119 > ++++++++++++++++++++++++++++++++++ > backend/src/llvm/llvm_gen_backend.cpp | 7 +- > backend/src/llvm/llvm_gen_backend.hpp | 4 +- > backend/src/llvm/llvm_scalarize.cpp | 1 + > backend/src/llvm/llvm_to_gen.cpp | 6 +- > 6 files changed, 134 insertions(+), 4 deletions(-) create mode 100644 > backend/src/llvm/StripAttributes.cpp > > diff --git a/backend/src/CMakeLists.txt b/backend/src/CMakeLists.txt index > a21918c..a6736ec 100644 > --- a/backend/src/CMakeLists.txt > +++ b/backend/src/CMakeLists.txt > @@ -88,6 +88,7 @@ set (GBE_SRC > llvm/ExpandUtils.cpp > llvm/PromoteIntegers.cpp > llvm/ExpandLargeIntegers.cpp > + llvm/StripAttributes.cpp > llvm/llvm_to_gen.cpp > llvm/llvm_loadstore_optimization.cpp > llvm/llvm_gen_backend.hpp > diff --git a/backend/src/llvm/StripAttributes.cpp > b/backend/src/llvm/StripAttributes.cpp > new file mode 100644 > index 0000000..05cac17 > --- /dev/null > +++ b/backend/src/llvm/StripAttributes.cpp > @@ -0,0 +1,119 @@ > +/* > + * Copyright © 2012 Intel Corporation > + * > + * This library is free software; you can redistribute it and/or > + * modify it under the terms of the GNU Lesser General Public > + * License as published by the Free Software Foundation; either > + * version 2.1 of the License, or (at your option) any later version. > + * > + * This library is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > GNU > + * Lesser General Public License for more details. > + * > + * You should have received a copy of the GNU Lesser General Public > + * License along with this library. If not, see > <http://www.gnu.org/licenses/>. > + * > + */ > + > +// Imported from pNaCl project > +// Copyright (c) 2003-2014 University of Illinois at Urbana-Champaign. > +// All rights reserved. > +// > +// Developed by: > +// > +// LLVM Team > +// > +// University of Illinois at Urbana-Champaign > +// > +// http://llvm.org > +// > +// Permission is hereby granted, free of charge, to any person > +obtaining a copy of // this software and associated documentation files > +(the "Software"), to deal with // the Software without restriction, > +including without limitation the rights to // use, copy, modify, merge, > +publish, distribute, sublicense, and/or sell copies // of the Software, > +and to permit persons to whom the Software is furnished to do // so, > subject to the following conditions: > +// > +// * Redistributions of source code must retain the above copyright > notice, > +// this list of conditions and the following disclaimers. > +// > +// * Redistributions in binary form must reproduce the above copyright > notice, > +// this list of conditions and the following disclaimers in the > +// documentation and/or other materials provided with the distribution. > +// > +// * Neither the names of the LLVM Team, University of Illinois at > +// Urbana-Champaign, nor the names of its contributors may be used to > +// endorse or promote products derived from this Software without > specific > +// prior written permission. > +// > +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, > +EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES > OF > +MERCHANTABILITY, FITNESS // FOR A PARTICULAR PURPOSE AND > +NONINFRINGEMENT. IN NO EVENT SHALL THE // CONTRIBUTORS OR > COPYRIGHT > +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, > WHETHER > +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT > OF OR > +IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS > WITH THE // SOFTWARE. > + > +// > +// The LLVM Compiler Infrastructure > +// > +// This file is distributed under the University of Illinois Open > +Source // License. See LICENSE.TXT for details. > +// > +//===------------------------------------------------------------------ > +----===// > +// > +// This pass strips out attributes that are not supported by Beignet. > +// Currently, this strips out: > +// > +// * Calling conventions from functions and function calls. > +// > + > +#include "llvm/IR/Function.h" > +#include "llvm/Pass.h" > + > +#if LLVM_VERSION_MINOR >= 5 > +#include "llvm/IR/CallSite.h" > +#else > +#include "llvm/Support/CallSite.h" > +#endif > + > +#include "llvm_gen_backend.hpp" > + > +using namespace llvm; > + > +namespace { > + class StripAttributes : public FunctionPass { > + public: > + static char ID; // Pass identification, replacement for typeid > + StripAttributes() : FunctionPass(ID) { > + } > + > + virtual bool runOnFunction(Function &Func); > + }; > +} > + > +char StripAttributes::ID = 0; > + > +bool StripAttributes::runOnFunction(Function &Func) { > + if (!gbe::isKernelFunction(Func)) > + Func.addFnAttr(Attribute::AlwaysInline); > + Func.setCallingConv(CallingConv::C); > + Func.setLinkage(GlobalValue::ExternalLinkage); > + > + for (Function::iterator BB = Func.begin(), E = Func.end(); > + BB != E; ++BB) { > + for (BasicBlock::iterator Inst = BB->begin(), E = BB->end(); > + Inst != E; ++Inst) { > + CallSite Call(Inst); > + if (Call) > + Call.setCallingConv(CallingConv::C); > + } > + } > + > + return true; > +} > + > +FunctionPass *llvm::createStripAttributesPass() { > + return new StripAttributes(); > +} > diff --git a/backend/src/llvm/llvm_gen_backend.cpp > b/backend/src/llvm/llvm_gen_backend.cpp > index 813d0d3..ec79628 100644 > --- a/backend/src/llvm/llvm_gen_backend.cpp > +++ b/backend/src/llvm/llvm_gen_backend.cpp > @@ -2791,8 +2791,13 @@ namespace gbe > break; > case GEN_OCL_PRINTF: > break; > + case GEN_OCL_NOT_FOUND: > default: > - GBE_ASSERTM(false, "Function call are not supported yet"); > + std::cerr << "Caller instruction: " << std::endl; > + I.dump(); > + std::cerr << "Callee function: " << std::endl; > + Callee->dump(); > + GBE_ASSERT(0); > }; > } > > diff --git a/backend/src/llvm/llvm_gen_backend.hpp > b/backend/src/llvm/llvm_gen_backend.hpp > index 91a1166..5724917 100644 > --- a/backend/src/llvm/llvm_gen_backend.hpp > +++ b/backend/src/llvm/llvm_gen_backend.hpp > @@ -50,6 +50,7 @@ namespace llvm { > FunctionPass *createExpandConstantExprPass(); > FunctionPass *createExpandLargeIntegersPass(); > FunctionPass *createPromoteIntegersPass(); > + FunctionPass *createStripAttributesPass(); > // Copy debug information from Original to New, and return New. > template <typename T> T *CopyDebug(T *New, llvm::Instruction *Original) > { > New->setDebugLoc(Original->getDebugLoc()); > @@ -66,6 +67,7 @@ namespace gbe > enum OCLInstrinsic { > #define DECL_LLVM_GEN_FUNCTION(ID, NAME) GEN_OCL_##ID, #include > "llvm_gen_ocl_function.hxx" > + GEN_OCL_NOT_FOUND, > #undef DECL_LLVM_GEN_FUNCTION > }; > > @@ -97,7 +99,7 @@ namespace gbe > if (it == map.end()) { > std::cerr << "Unresolved symbol: " << symbol << std::endl; > std::cerr << "Aborting..." << std::endl; > - exit(-1); > + return GEN_OCL_NOT_FOUND; > } > return it->second; > } > diff --git a/backend/src/llvm/llvm_scalarize.cpp > b/backend/src/llvm/llvm_scalarize.cpp > index 860053f..b657246 100644 > --- a/backend/src/llvm/llvm_scalarize.cpp > +++ b/backend/src/llvm/llvm_scalarize.cpp > @@ -643,6 +643,7 @@ namespace gbe { > CallSite::arg_iterator CI = CS.arg_begin() + 1; > > switch (genIntrinsicID) { > + case GEN_OCL_NOT_FOUND: > default: break; > case GEN_OCL_READ_IMAGE_I: > case GEN_OCL_READ_IMAGE_UI: > diff --git a/backend/src/llvm/llvm_to_gen.cpp > b/backend/src/llvm/llvm_to_gen.cpp > index 89a22b6..a4ce4a2 100644 > --- a/backend/src/llvm/llvm_to_gen.cpp > +++ b/backend/src/llvm/llvm_to_gen.cpp > @@ -133,8 +133,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 > + MPM.add(createStripAttributesPass()); // Strip unsupported attributes > and calling conventions. > MPM.add(createBarrierNodupPass(false)); // remove noduplicate fnAttr > before inlining. > - MPM.add(createFunctionInliningPass(200000)); > + MPM.add(createFunctionInliningPass(20000)); > MPM.add(createBarrierNodupPass(true)); // restore noduplicate fnAttr > after inlining. > MPM.add(createFunctionAttrsPass()); // Set readonly/readnone attrs > > @@ -275,7 +276,8 @@ namespace gbe > #endif > // Print the code before further optimizations > passes.add(createIntrinsicLoweringPass()); > - passes.add(createFunctionInliningPass(200000)); > + passes.add(createStripAttributesPass()); // Strip unsupported > attributes and calling conventions. > + passes.add(createFunctionInliningPass(20000)); > passes.add(createScalarReplAggregatesPass(64, true, -1, -1, 64)); > passes.add(createLoadStoreOptimizationPass()); > passes.add(createConstantPropagationPass()); > -- > 1.9.1 > > _______________________________________________ > Beignet mailing list > Beignet@lists.freedesktop.org > http://lists.freedesktop.org/mailman/listinfo/beignet _______________________________________________ Beignet mailing list Beignet@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/beignet