[PATCH] D50104: [OpenCL] Always emit alloca in entry block for enqueue_kernel builtin
Scott Linder via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 31 14:25:29 PDT 2018
scott.linder created this revision.
scott.linder added reviewers: yaxunl, Anastasia, arsenm.
Herald added subscribers: cfe-commits, wdng.
Ensures the statically sized alloca is not converted to DYNAMIC_STACKALLOC later because it is not in the entry block.
I believe it is valid to insert the alloca in the entry block, but I'm not confident the way I accomplish it is correct.
Repository:
rC Clang
https://reviews.llvm.org/D50104
Files:
lib/CodeGen/CGBuiltin.cpp
test/CodeGenOpenCL/enqueue-kernel-non-entry-block.cl
Index: test/CodeGenOpenCL/enqueue-kernel-non-entry-block.cl
===================================================================
--- /dev/null
+++ test/CodeGenOpenCL/enqueue-kernel-non-entry-block.cl
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -O0 -emit-llvm -o - -triple amdgcn | FileCheck %s --check-prefixes=COMMON,AMDGPU
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -O0 -emit-llvm -o - -triple "spir-unknown-unknown" | FileCheck %s --check-prefixes=COMMON,SPIR32
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -O0 -emit-llvm -o - -triple "spir64-unknown-unknown" | FileCheck %s --check-prefixes=COMMON,SPIR64
+
+typedef struct {int a;} ndrange_t;
+
+kernel void test(int i) {
+// COMMON-LABEL: define {{.*}} void @test
+// COMMON-LABEL: entry:
+// AMDGPU: alloca [1 x i64]
+// SPIR32: alloca [1 x i32]
+// SPIR64: alloca [1 x i64]
+// COMMON-LABEL: if.then:
+// COMMON-NOT: alloca
+// COMMON-LABEL: if.end
+ queue_t default_queue;
+ unsigned flags = 0;
+ ndrange_t ndrange;
+ if (i)
+ enqueue_kernel(default_queue, flags, ndrange, ^(local void *a) { }, 32);
+}
Index: lib/CodeGen/CGBuiltin.cpp
===================================================================
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -3339,7 +3339,16 @@
// for the block. \p First is the position of the first size argument.
auto CreateArrayForSizeVar = [=](unsigned First) {
auto *AT = llvm::ArrayType::get(SizeTy, NumArgs - First);
+ // Always insert the alloca in the entry block so it remains static in
+ // the SelectionDAG.
+ BasicBlock *Begin = nullptr;
+ if (Instruction *Entry = CurFn->getEntryBlock().getTerminator()) {
+ Begin = Builder.GetInsertBlock();
+ Builder.SetInsertPoint(Entry);
+ }
auto *Arr = Builder.CreateAlloca(AT);
+ if (Begin)
+ Builder.SetInsertPoint(Begin);
llvm::Value *Ptr;
// Each of the following arguments specifies the size of the corresponding
// argument passed to the enqueued block.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50104.158385.patch
Type: text/x-patch
Size: 2011 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180731/00709c2c/attachment.bin>
More information about the cfe-commits
mailing list