[OpenCL] Fix __enqueue_block for block with captures
authorYaxun Liu <Yaxun.Liu@amd.com>
Thu, 15 Feb 2018 16:39:19 +0000 (16:39 +0000)
committerYaxun Liu <Yaxun.Liu@amd.com>
Thu, 15 Feb 2018 16:39:19 +0000 (16:39 +0000)
commit8f335839945a303811ee3514202c94ecb78834da
tree255afc04ca2b426597aa53ff592c372641673800
parent7e12c117dfcbd54c5184d60fa78dd6321affd641
[OpenCL] Fix __enqueue_block for block with captures

The following test case causes issue with codegen of __enqueue_block

void (^block)(void) = ^{ callee(id, out); };

enqueue_kernel(queue, 0, ndrange, block);
Clang first does codegen for block expression in the first line and deletes its block info.
Clang then tries to do codegen for the same block expression again for the second line,
and fails because the block info is gone.

The fix is to do normal codegen for both lines. Introduce an API to OpenCL runtime to
record llvm block invoke function and llvm block literal emitted for each AST block
expression, and use the recorded information for generating the wrapper kernel.

The EmitBlockLiteral APIs are cleaned up to minimize changes to the normal codegen
of blocks.

Another minor issue is that some clean up AST expression is generated for block
with captures, which can be stripped by IgnoreImplicit.

Differential Revision: https://reviews.llvm.org/D43240

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@325264 91177308-0d34-0410-b5e6-96231b3b80d8
lib/CodeGen/CGBlocks.cpp
lib/CodeGen/CGOpenCLRuntime.cpp
lib/CodeGen/CGOpenCLRuntime.h
lib/CodeGen/CodeGenFunction.h
test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl
test/CodeGenOpenCL/cl20-device-side-enqueue.cl