[Beignet] [PATCH Release_v1.1] Backend: Fix the bug of printf in multi kernels within on file.

Yang, Rong R rong.r.yang at intel.com
Mon Jan 18 22:50:08 PST 2016


LGTM, pushed, thanks.

> -----Original Message-----
> From: Beignet [mailto:beignet-bounces at lists.freedesktop.org] On Behalf Of
> junyan.he at inbox.com
> Sent: Thursday, January 14, 2016 16:01
> To: beignet at lists.freedesktop.org
> Subject: [Beignet] [PATCH Release_v1.1] Backend: Fix the bug of printf in
> multi kernels within on file.
> 
> From: Junyan He <junyan.he at linux.intel.com>
> 
> Signed-off-by: Junyan He <junyan.he at linux.intel.com>
> ---
>  backend/src/llvm/llvm_printf_parser.cpp | 27 ++++++++++++++++++--------
> -
>  1 file changed, 18 insertions(+), 9 deletions(-)
> 
> diff --git a/backend/src/llvm/llvm_printf_parser.cpp
> b/backend/src/llvm/llvm_printf_parser.cpp
> index a0a2e21..9a054f1 100644
> --- a/backend/src/llvm/llvm_printf_parser.cpp
> +++ b/backend/src/llvm/llvm_printf_parser.cpp
> @@ -328,6 +328,8 @@ error:
>      Module* module;
>      IRBuilder<>* builder;
>      Type* intTy;
> +    llvm::Constant * pbuf_global;
> +    llvm::Constant * index_buf_global;
>      Value* pbuf_ptr;
>      Value* index_buf_ptr;
>      Value* g1Xg2Xg3;
> @@ -342,13 +344,11 @@ error:
>        PrintfSet::PrintfFmt* printf_fmt;
>      };
> 
> -    PrintfParser(void) : FunctionPass(ID)
> -    {
> +    void stateInit(void) {
>        module = NULL;
>        builder = NULL;
>        intTy = NULL;
>        out_buf_sizeof_offset = 0;
> -      printfs.clear();
>        pbuf_ptr = NULL;
>        index_buf_ptr = NULL;
>        g1Xg2Xg3 = NULL;
> @@ -357,6 +357,13 @@ error:
>        totalSizeofSize = 0;
>      }
> 
> +    PrintfParser(void) : FunctionPass(ID)
> +    {
> +      stateInit();
> +      pbuf_global = NULL;
> +      index_buf_global = NULL;
> +    }
> +
>      ~PrintfParser(void)
>      {
>        for (auto &s : printfs) {
> @@ -554,6 +561,7 @@ error:
> 
>    bool PrintfParser::runOnFunction(llvm::Function &F)
>    {
> +    stateInit();
>      bool changed = false;
>      bool hasPrintf = false;
>      switch (F.getCallingConv()) {
> @@ -630,29 +638,30 @@ error:
>      if (!hasPrintf)
>        return changed;
> 
> -    if (!pbuf_ptr) {
> +    if (!pbuf_global) {
>        /* alloc a new buffer ptr to collect the print output. */
>        Type *ptrTy = Type::getInt32PtrTy(module->getContext(), 1);
> -      llvm::Constant *pBuf = new GlobalVariable(*module, ptrTy, false,
> +      pbuf_global= new GlobalVariable(*module, ptrTy, false,
>                                  GlobalVariable::ExternalLinkage,
>                                  nullptr,
>                                  StringRef("__gen_ocl_printf_buf"),
>                                  nullptr,
>                                  GlobalVariable::NotThreadLocal,
>                                  1);
> -      pbuf_ptr = builder->CreatePtrToInt(pBuf, Type::getInt32Ty(module-
> >getContext()));
>      }
> -    if (!index_buf_ptr) {
> +    pbuf_ptr = builder->CreatePtrToInt(pbuf_global,
> Type::getInt32Ty(module->getContext()));
> +
> +    if (!index_buf_global) {
>        Type *ptrTy = Type::getInt32PtrTy(module->getContext(), 1);
> -      llvm::Constant *pBuf = new GlobalVariable(*module, ptrTy, false,
> +      index_buf_global = new GlobalVariable(*module, ptrTy, false,
>                                  GlobalVariable::ExternalLinkage,
>                                  nullptr,
>                                  StringRef("__gen_ocl_printf_index_buf"),
>                                  nullptr,
>                                  GlobalVariable::NotThreadLocal,
>                                  1);
> -      index_buf_ptr = builder->CreatePtrToInt(pBuf,
> Type::getInt32Ty(module->getContext()));
>      }
> +    index_buf_ptr = builder->CreatePtrToInt(index_buf_global,
> Type::getInt32Ty(module->getContext()));
> 
>      if (!wg_offset || !g1Xg2Xg3) {
>        Value* op0 = NULL;
> --
> 1.9.1
> 
> 
> 
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet


More information about the Beignet mailing list