Skip to content

Commit cbff4d4

Browse files
committed
[PATCH] Re-fix invalid address space generation for clk_event_t arguments
https://reviews.llvm.org/D59985
1 parent e42dbc0 commit cbff4d4

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
From 6a67b954040196807b2c75813cd1ac74f01a8a5d Mon Sep 17 00:00:00 2001
2+
From: Alexey Sotkin <[email protected]>
3+
Date: Thu, 11 Apr 2019 06:18:17 +0000
4+
Subject: [PATCH] [OpenCL] Re-fix invalid address space generation for
5+
clk_event_t arguments of enqueue_kernel builtin function
6+
7+
Summary:
8+
https://reviews.llvm.org/D53809 fixed wrong address space(assert in debug build)
9+
generated for event_ret argument. But exactly the same problem exists for
10+
event_wait_list argument. This patch should fix both.
11+
12+
Reviewers: Anastasia, yaxunl
13+
14+
Reviewed By: Anastasia
15+
16+
Subscribers: kristina, ebevhan, cfe-commits
17+
18+
Differential Revision: https://reviews.llvm.org/D59985
19+
20+
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@358151 91177308-0d34-0410-b5e6-96231b3b80d8
21+
---
22+
lib/CodeGen/CGBuiltin.cpp | 41 ++++++++++++++++++--------
23+
test/CodeGenOpenCL/cl20-device-side-enqueue.cl | 6 ++--
24+
2 files changed, 31 insertions(+), 16 deletions(-)
25+
26+
diff --git a/lib/CodeGen/CGBuiltin.cpp b/lib/CodeGen/CGBuiltin.cpp
27+
index cd074af..a9e4bed 100644
28+
--- a/lib/CodeGen/CGBuiltin.cpp
29+
+++ b/lib/CodeGen/CGBuiltin.cpp
30+
@@ -3388,21 +3388,35 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,
31+
// Any calls now have event arguments passed.
32+
if (NumArgs >= 7) {
33+
llvm::Type *EventTy = ConvertType(getContext().OCLClkEventTy);
34+
- llvm::Type *EventPtrTy = EventTy->getPointerTo(
35+
+ llvm::PointerType *EventPtrTy = EventTy->getPointerTo(
36+
CGM.getContext().getTargetAddressSpace(LangAS::opencl_generic));
37+
38+
llvm::Value *NumEvents =
39+
Builder.CreateZExtOrTrunc(EmitScalarExpr(E->getArg(3)), Int32Ty);
40+
- llvm::Value *EventList =
41+
- E->getArg(4)->getType()->isArrayType()
42+
- ? EmitArrayToPointerDecay(E->getArg(4)).getPointer()
43+
- : EmitScalarExpr(E->getArg(4));
44+
- llvm::Value *ClkEvent = EmitScalarExpr(E->getArg(5));
45+
- // Convert to generic address space.
46+
- EventList = Builder.CreatePointerCast(EventList, EventPtrTy);
47+
- ClkEvent = ClkEvent->getType()->isIntegerTy()
48+
- ? Builder.CreateBitOrPointerCast(ClkEvent, EventPtrTy)
49+
- : Builder.CreatePointerCast(ClkEvent, EventPtrTy);
50+
+
51+
+ // Since SemaOpenCLBuiltinEnqueueKernel allows fifth and sixth arguments
52+
+ // to be a null pointer constant (including `0` literal), we can take it
53+
+ // into account and emit null pointer directly.
54+
+ llvm::Value *EventWaitList = nullptr;
55+
+ if (E->getArg(4)->isNullPointerConstant(
56+
+ getContext(), Expr::NPC_ValueDependentIsNotNull)) {
57+
+ EventWaitList = llvm::ConstantPointerNull::get(EventPtrTy);
58+
+ } else {
59+
+ EventWaitList = E->getArg(4)->getType()->isArrayType()
60+
+ ? EmitArrayToPointerDecay(E->getArg(4)).getPointer()
61+
+ : EmitScalarExpr(E->getArg(4));
62+
+ // Convert to generic address space.
63+
+ EventWaitList = Builder.CreatePointerCast(EventWaitList, EventPtrTy);
64+
+ }
65+
+ llvm::Value *EventRet = nullptr;
66+
+ if (E->getArg(5)->isNullPointerConstant(
67+
+ getContext(), Expr::NPC_ValueDependentIsNotNull)) {
68+
+ EventRet = llvm::ConstantPointerNull::get(EventPtrTy);
69+
+ } else {
70+
+ EventRet =
71+
+ Builder.CreatePointerCast(EmitScalarExpr(E->getArg(5)), EventPtrTy);
72+
+ }
73+
+
74+
auto Info =
75+
CGM.getOpenCLRuntime().emitOpenCLEnqueuedBlock(*this, E->getArg(6));
76+
llvm::Value *Kernel =
77+
@@ -3414,8 +3428,9 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,
78+
QueueTy, Int32Ty, RangeTy, Int32Ty,
79+
EventPtrTy, EventPtrTy, GenericVoidPtrTy, GenericVoidPtrTy};
80+
81+
- std::vector<llvm::Value *> Args = {Queue, Flags, Range, NumEvents,
82+
- EventList, ClkEvent, Kernel, Block};
83+
+ std::vector<llvm::Value *> Args = {Queue, Flags, Range,
84+
+ NumEvents, EventWaitList, EventRet,
85+
+ Kernel, Block};
86+
87+
if (NumArgs == 7) {
88+
// Has events but no variadics.
89+
diff --git a/test/CodeGenOpenCL/cl20-device-side-enqueue.cl b/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
90+
index 120a426..09ac474 100644
91+
--- a/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
92+
+++ b/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
93+
@@ -11,7 +11,7 @@ typedef struct {int a;} ndrange_t;
94+
// COMMON: @block_G = addrspace(1) constant void (i8 addrspace(3)*) addrspace(4)* addrspacecast (void (i8 addrspace(3)*) addrspace(1)* bitcast ({ i32, i32 } addrspace(1)* [[BL_GLOBAL]] to void (i8 addrspace(3)*) addrspace(1)*) to void (i8 addrspace(3)*) addrspace(4)*)
95+
96+
// For anonymous blocks without captures, emit block literals as global variable.
97+
-// COMMON: [[BLG1:@__block_literal_global[^ ]*]] = internal addrspace(1) constant { i32, i32 } { i32 {{[0-9]+}}, i32 {{[0-9]+}} }
98+
+// COMMON: [[BLG1:@__block_literal_global.2]] = internal addrspace(1) constant { i32, i32 } { i32 {{[0-9]+}}, i32 {{[0-9]+}} }
99+
// COMMON: [[BLG2:@__block_literal_global[^ ]*]] = internal addrspace(1) constant { i32, i32 } { i32 {{[0-9]+}}, i32 {{[0-9]+}} }
100+
// COMMON: [[BLG3:@__block_literal_global[^ ]*]] = internal addrspace(1) constant { i32, i32 } { i32 {{[0-9]+}}, i32 {{[0-9]+}} }
101+
// COMMON: [[BLG4:@__block_literal_global[^ ]*]] = internal addrspace(1) constant { i32, i32 } { i32 {{[0-9]+}}, i32 {{[0-9]+}} }
102+
@@ -80,8 +80,8 @@ kernel void device_side_enqueue(global int *a, global int *b, int i) {
103+
});
104+
105+
// COMMON-LABEL: call i32 @__enqueue_kernel_basic_events
106+
- // COMMON-SAME: (%opencl.queue_t{{.*}}* {{%[0-9]+}}, i32 {{%[0-9]+}}, %struct.ndrange_t* {{.*}}, i32 1, %opencl.clk_event_t{{.*}}* addrspace(4)* {{%[0-9]+}}, %opencl.clk_event_t{{.*}}* addrspace(4)* null,
107+
- enqueue_kernel(default_queue, flags, ndrange, 1, &event_wait_list, 0,
108+
+ // COMMON-SAME: (%opencl.queue_t{{.*}}* {{%[0-9]+}}, i32 {{%[0-9]+}}, %struct.ndrange_t* {{.*}}, i32 1, %opencl.clk_event_t{{.*}}* addrspace(4)* null, %opencl.clk_event_t{{.*}}* addrspace(4)* null,
109+
+ enqueue_kernel(default_queue, flags, ndrange, 1, 0, 0,
110+
^(void) {
111+
return;
112+
});
113+
--
114+
1.8.3.1
115+

0 commit comments

Comments
 (0)