[Beignet] [Patch V2 2/2] Add llvm3.6 build support.
Yang, Rong R
rong.r.yang at intel.com
Wed Feb 11 21:15:08 PST 2015
> -----Original Message-----
> From: Song, Ruiling
> Sent: Thursday, February 12, 2015 10:09
> To: Zhigang Gong; Yang, Rong R
> Cc: beignet at lists.freedesktop.org
> Subject: RE: [Beignet] [Patch V2 2/2] Add llvm3.6 build support.
>
>
>
> > -----Original Message-----
> > From: Beignet [mailto:beignet-bounces at lists.freedesktop.org] On Behalf
> > Of Zhigang Gong
> > Sent: Wednesday, February 11, 2015 4:26 PM
> > To: Yang, Rong R
> > Cc: beignet at lists.freedesktop.org
> > Subject: Re: [Beignet] [Patch V2 2/2] Add llvm3.6 build support.
> >
> > Some minor comments as below:
> >
> > On Wed, Feb 11, 2015 at 03:44:58PM +0800, Yang Rong wrote:
> > > There are some changes from llvm3.5:
> > > 1. Some functions return std::unique_ptr instead of pointer.
> > > 2. MetaNode to Value and Value to MetaNode.
> > >
> > > V2: Fix llvm3.5 build error.
> > > Signed-off-by: Yang Rong <rong.r.yang at intel.com>
> > > ---
> > > backend/src/backend/gen_program.cpp | 10 ++++++++++
> > > backend/src/backend/program.cpp | 4 ++++
> > > backend/src/llvm/llvm_bitcode_link.cpp | 35
> > > ++++++++++++++++++++++++++++++----
> > > backend/src/llvm/llvm_gen_backend.cpp | 23
> > ++++++++++++++++++++--
> > > backend/src/llvm/llvm_passes.cpp | 5 ++++-
> > > backend/src/llvm/llvm_to_gen.cpp | 16 +++++++++++++---
> > > backend/src/llvm/llvm_unroll.cpp | 14 ++++++++++++++
> > > 7 files changed, 97 insertions(+), 10 deletions(-)
> > >
> > > diff --git a/backend/src/backend/gen_program.cpp
> > > b/backend/src/backend/gen_program.cpp
> > > index 4cfb703..5d36975 100644
> > > --- a/backend/src/backend/gen_program.cpp
> > > +++ b/backend/src/backend/gen_program.cpp
> > > @@ -257,9 +257,15 @@ namespace gbe {
> > > llvm::StringRef llvm_bin_str(binary_content);
> > > llvm::LLVMContext& c = llvm::getGlobalContext();
> > > llvm::SMDiagnostic Err;
> > > +#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6
> > > + std::unique_ptr<llvm::MemoryBuffer> memory_buffer =
> > llvm::MemoryBuffer::getMemBuffer(llvm_bin_str, "llvm_bin_str");
> > > + acquireLLVMContextLock();
> > > + llvm::Module* module =
> > > +llvm::parseIR(memory_buffer->getMemBufferRef(), Err, c).release();
> > > +#else
> > > llvm::MemoryBuffer* memory_buffer =
> > llvm::MemoryBuffer::getMemBuffer(llvm_bin_str, "llvm_bin_str");
> > > acquireLLVMContextLock();
> > > llvm::Module* module = llvm::ParseIR(memory_buffer, Err, c);
> > > +#endif
> > > releaseLLVMContextLock();
> > > if(module == NULL){
> > > GBE_ASSERT(0);
> > > @@ -386,10 +392,14 @@ namespace gbe {
> > > }else{
> > > llvm::Module* src =
> > (llvm::Module*)((GenProgram*)src_program)->module;
> > > llvm::Module* dst =
> > > (llvm::Module*)((GenProgram*)dst_program)->module;
> > > +#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6
> > > + llvm::Linker::LinkModules(dst, src);
> > Then how to get back the errMsg with LLVM 3.6?
>
> I have a look at the tools/clang/lib/CodeGen/CodeGenAction.cpp
> It define an function BackendConsumer::linkerDiagnosticHandler() as the
> DiagnosticHandler, and pass it to LinkModules().
> We can use same kind of logic here.
Just find LLVM has function LLVMLinkMoudules in lib/Linker/LinkModules.cpp, has same interface, is what we need, I will use it.
>
>
> > > +#else
> >
> >
> > > llvm::Linker::LinkModules( dst,
> > > src,
> > > llvm::Linker::PreserveSource,
> > > &errMsg);
> > > +#endif
> > > if (errMsg.c_str() != NULL) {
> > > if (err != NULL && errSize != NULL && stringSize > 0u) {
> > > if(errMsg.length() < stringSize ) diff --git
> > > a/backend/src/backend/program.cpp
> b/backend/src/backend/program.cpp
> > > index 38ce9c8..06810bd 100644
> > > --- a/backend/src/backend/program.cpp
> > > +++ b/backend/src/backend/program.cpp
> > > @@ -621,7 +621,11 @@ namespace gbe {
> > > if (!retVal)
> > > return false;
> > >
> > > +#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5
> > > llvm::Module *module = Act->takeModule();
> > > +#else
> > > + llvm::Module *module = Act->takeModule().release(); #endif
> > >
> > > *out_module = module;
> > > return true;
> > > diff --git a/backend/src/llvm/llvm_bitcode_link.cpp
> > > b/backend/src/llvm/llvm_bitcode_link.cpp
> > > index d3058d6..f67ebe0 100644
> > > --- a/backend/src/llvm/llvm_bitcode_link.cpp
> > > +++ b/backend/src/llvm/llvm_bitcode_link.cpp
> > > @@ -67,7 +67,11 @@ namespace gbe
> > > }
> > > assert(findBC);
> > >
> > > +#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5
> > > oclLib = getLazyIRFileModule(FilePath, Err, ctx);
> > > +#else
> > > + oclLib = getLazyIRFileModule(FilePath, Err, ctx).release();
> > > +#endif
> > > if (!oclLib) {
> > > printf("Fatal Error: ocl lib can not be opened\n");
> > > return NULL;
> > > @@ -110,20 +114,26 @@ namespace gbe
> > > if (!newMF) {
> > > newMF = src.getFunction(fnName);
> > > if (!newMF) {
> > > - printf("Can not find the lib: %s\n", fnName.c_str());
> > > - return false;
> > > + printf("Can not find the lib: %s\n", fnName.c_str());
> > > + return false;
> > > }
> > > - fromSrc = true;
> > > + fromSrc = true;
> > > }
> > >
> > > std::string ErrInfo;// = "Not Materializable";
> > > if (!fromSrc && newMF->isMaterializable()) {
> > > +#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5
> > > if (newMF->Materialize(&ErrInfo)) {
> > > printf("Can not materialize the function: %s,
> > because %s\n", fnName.c_str(), ErrInfo.c_str());
> > > return false;
> > > }
> > > +#else
> > > + if (newMF->materialize()) {
> > The same concern as the above one, then we will not know the reason
> > why it fail? Or is there any other mechanism to get it? Also the same
> > concerns for the following similar calls.
>
> I find llvm 3.6 use std::error_code as the return value of materialize.
> We can write like:
> if(std::error_code EC = newMF->materialize()) {
> printf("Can not materialize the function: %s, because %s\n",
> fnName.c_str(), EC.message()); }
> >
> > > + printf("Can not materialize the function: %s\n",
> > fnName.c_str());
> > > + return false;
> > > + }
> > > +#endif
> > > }
> > > -
> > > if (!materializedFuncCall(src, lib, *newMF, MFS))
> > > return false;
> > >
> > > @@ -209,12 +219,21 @@ namespace gbe
> > > }
> > > std::string ErrInfo;// = "Not Materializable";
> > > if (newMF->isMaterializable()) {
> > > +#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5
> > > if (newMF->Materialize(&ErrInfo)) {
> > > printf("Can not materialize the function: %s, because
> > > %s\n",
> > fnName.c_str(), ErrInfo.c_str());
> > > delete clonedLib;
> > > return NULL;
> > > }
> > > }
> > > +#else
> > > + if (newMF->materialize()) {
> > > + printf("Can not materialize the function: %s\n",
> > fnName.c_str());
> > > + delete clonedLib;
> > > + return NULL;
> > > + }
> > > + }
> > > +#endif
> > >
> > > if (!materializedFuncCall(*mod, *clonedLib, *newMF,
> > materializedFuncs)) {
> > > delete clonedLib;
> > > @@ -227,11 +246,19 @@ namespace gbe
> > > /* We use beignet's bitcode as dst because it will have a lot of
> > > lazy functions which will not be loaded. */
> > > std::string errorMsg;
> > > +#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5
> > > if(Linker::LinkModules(clonedLib, mod, Linker::DestroySource,
> > &errorMsg)) {
> > > delete clonedLib;
> > > printf("Fatal Error: link the bitcode error:\n%s\n",
> > errorMsg.c_str());
> > > return NULL;
> > > }
> > > +#else
> > > + if(Linker::LinkModules(clonedLib, mod)) {
> > > + delete clonedLib;
>
> > > diff --git a/backend/src/llvm/llvm_passes.cpp
> > > b/backend/src/llvm/llvm_passes.cpp
> > > index 5c0a2e0..1b40389 100644
> > > --- a/backend/src/llvm/llvm_passes.cpp
> > > +++ b/backend/src/llvm/llvm_passes.cpp
> > > @@ -59,7 +59,6 @@
> > > #include "llvm/ADT/SmallString.h"
> > > #include "llvm/ADT/STLExtras.h"
> > > #include "llvm/Analysis/ConstantsScanner.h"
> > > -#include "llvm/Analysis/FindUsedTypes.h"
> > If this header file is not needed for both 3.3/3.4 and 3.5, it's
> > better to use a separate patch to remove it.
> >
> > The other part LGTM.
> >
> > Thanks,
> > Zhigang Gong.
> > _______________________________________________
> > Beignet mailing list
> > Beignet at lists.freedesktop.org
> > http://lists.freedesktop.org/mailman/listinfo/beignet
More information about the Beignet
mailing list