[Beignet] [PATCH] Fix the global string bug for printf.

Zhigang Gong zhigang.gong at linux.intel.com
Mon Sep 1 19:09:49 PDT 2014


LGTM, pushed, thanks.

On Mon, Sep 01, 2014 at 04:18:45PM +0800, junyan.he at inbox.com wrote:
> From: Junyan He <junyan.he at linux.intel.com>
> 
> When there are multi printf statements in multi kernel
> fucntions within the same translate unit, if they have
> the same sting parameter, the Clang will just generate
> one global string named .strXXX to represent that string.
> So when translating the kernel to gen, we can not unref
> that global var. Just ignore it to avoid assert.
> 
> Signed-off-by: Junyan He <junyan.he at linux.intel.com>
> ---
>  backend/src/llvm/llvm_gen_backend.cpp | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/backend/src/llvm/llvm_gen_backend.cpp b/backend/src/llvm/llvm_gen_backend.cpp
> index 8f0d5c2..1604ede 100644
> --- a/backend/src/llvm/llvm_gen_backend.cpp
> +++ b/backend/src/llvm/llvm_gen_backend.cpp
> @@ -1727,6 +1727,18 @@ namespace gbe
>            ctx.getFunction().getPrintfSet()->setIndexBufBTI(btiBase);
>            globalPointer.insert(std::make_pair(&v, btiBase++));
>            regTranslator.newScalarProxy(ir::ocl::printfiptr, const_cast<GlobalVariable*>(&v));
> +	} else if(v.getName().str().substr(0, 4) == ".str") {
> +          /* When there are multi printf statements in multi kernel fucntions within the same
> +             translate unit, if they have the same sting parameter, such as
> +             kernel_func1 () {
> +               printf("Line is %d\n", line_num1);
> +             }
> +             kernel_func2 () {
> +               printf("Line is %d\n", line_num2);
> +             }
> +             The Clang will just generate one global string named .strXXX to represent "Line is %d\n"
> +             So when translating the kernel_func1, we can not unref that global var, so we will
> +             get here. Just ignore it to avoid assert. */
>          } else {
>            GBE_ASSERT(0);
>          }
> -- 
> 1.8.3.2
> 
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet


More information about the Beignet mailing list