1// RUN: %clang_cc1 %s -cl-std=CL2.0 -ffake-address-space-map -O0 -emit-llvm -o - -triple "spir-unknown-unknown" | FileCheck %s --check-prefix=COMMON --check-prefix=B32 2// RUN: %clang_cc1 %s -cl-std=CL2.0 -ffake-address-space-map -O0 -emit-llvm -o - -triple "spir64-unknown-unknown" | FileCheck %s --check-prefix=COMMON --check-prefix=B64 3// RUN: %clang_cc1 %s -cl-std=CL2.0 -ffake-address-space-map -O1 -emit-llvm -o - -triple "spir64-unknown-unknown" | FileCheck %s --check-prefix=CHECK-LIFETIMES 4 5#pragma OPENCL EXTENSION cl_khr_subgroups : enable 6 7typedef void (^bl_t)(local void *); 8typedef struct {int a;} ndrange_t; 9 10// For a block global variable, first emit the block literal as a global variable, then emit the block variable itself. 11// COMMON: [[BL_GLOBAL:@__block_literal_global[^ ]*]] = internal addrspace(1) constant { i32, i32 } { i32 {{[0-9]+}}, i32 {{[0-9]+}} } 12// 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)*) 13 14// For anonymous blocks without captures, emit block literals as global variable. 15// COMMON: [[BLG1:@__block_literal_global[^ ]*]] = internal addrspace(1) constant { i32, i32 } { i32 {{[0-9]+}}, i32 {{[0-9]+}} } 16// COMMON: [[BLG2:@__block_literal_global[^ ]*]] = internal addrspace(1) constant { i32, i32 } { i32 {{[0-9]+}}, i32 {{[0-9]+}} } 17// COMMON: [[BLG3:@__block_literal_global[^ ]*]] = internal addrspace(1) constant { i32, i32 } { i32 {{[0-9]+}}, i32 {{[0-9]+}} } 18// COMMON: [[BLG4:@__block_literal_global[^ ]*]] = internal addrspace(1) constant { i32, i32 } { i32 {{[0-9]+}}, i32 {{[0-9]+}} } 19// COMMON: [[BLG5:@__block_literal_global[^ ]*]] = internal addrspace(1) constant { i32, i32 } { i32 {{[0-9]+}}, i32 {{[0-9]+}} } 20// COMMON: [[BLG6:@__block_literal_global[^ ]*]] = internal addrspace(1) constant { i32, i32 } { i32 {{[0-9]+}}, i32 {{[0-9]+}} } 21// COMMON: [[BLG7:@__block_literal_global[^ ]*]] = internal addrspace(1) constant { i32, i32 } { i32 {{[0-9]+}}, i32 {{[0-9]+}} } 22// COMMON: [[BLG8:@__block_literal_global[^ ]*]] = internal addrspace(1) constant { i32, i32 } { i32 {{[0-9]+}}, i32 {{[0-9]+}} } 23// COMMON: [[BLG9:@__block_literal_global[^ ]*]] = internal addrspace(1) constant { i32, i32 } { i32 {{[0-9]+}}, i32 {{[0-9]+}} } 24// COMMON: [[BLG10:@__block_literal_global[^ ]*]] = internal addrspace(1) constant { i32, i32 } { i32 {{[0-9]+}}, i32 {{[0-9]+}} } 25// COMMON: [[BLG11:@__block_literal_global[^ ]*]] = internal addrspace(1) constant { i32, i32 } { i32 {{[0-9]+}}, i32 {{[0-9]+}} } 26 27// Emits block literal [[BL_GLOBAL]], invoke function [[INV_G]] and global block variable @block_G 28// COMMON: define internal spir_func void [[INV_G:.*]](i8 addrspace(4)* %{{.*}}, i8 addrspace(3)* %{{.*}}) 29const bl_t block_G = (bl_t) ^ (local void *a) {}; 30 31void callee(int id, __global int *out) { 32 out[id] = id; 33} 34 35// COMMON-LABEL: define spir_kernel void @device_side_enqueue(i32 addrspace(1)* %{{.*}}, i32 addrspace(1)* %b, i32 %i) 36kernel void device_side_enqueue(global int *a, global int *b, int i) { 37 // COMMON: %default_queue = alloca %opencl.queue_t* 38 queue_t default_queue; 39 // COMMON: %flags = alloca i32 40 unsigned flags = 0; 41 // COMMON: %ndrange = alloca %struct.ndrange_t 42 ndrange_t ndrange; 43 // COMMON: %clk_event = alloca %opencl.clk_event_t* 44 clk_event_t clk_event; 45 // COMMON: %event_wait_list = alloca %opencl.clk_event_t* 46 clk_event_t event_wait_list; 47 // COMMON: %event_wait_list2 = alloca [1 x %opencl.clk_event_t*] 48 clk_event_t event_wait_list2[] = {clk_event}; 49 50 // COMMON: [[NDR:%[a-z0-9]+]] = alloca %struct.ndrange_t, align 4 51 52 // B32: %[[BLOCK_SIZES1:.*]] = alloca [1 x i32] 53 // B64: %[[BLOCK_SIZES1:.*]] = alloca [1 x i64] 54 // CHECK-LIFETIMES: %[[BLOCK_SIZES1:.*]] = alloca [1 x i64] 55 // B32: %[[BLOCK_SIZES2:.*]] = alloca [1 x i32] 56 // B64: %[[BLOCK_SIZES2:.*]] = alloca [1 x i64] 57 // CHECK-LIFETIMES: %[[BLOCK_SIZES2:.*]] = alloca [1 x i64] 58 // B32: %[[BLOCK_SIZES3:.*]] = alloca [1 x i32] 59 // B64: %[[BLOCK_SIZES3:.*]] = alloca [1 x i64] 60 // CHECK-LIFETIMES: %[[BLOCK_SIZES3:.*]] = alloca [1 x i64] 61 // B32: %[[BLOCK_SIZES4:.*]] = alloca [1 x i32] 62 // B64: %[[BLOCK_SIZES4:.*]] = alloca [1 x i64] 63 // CHECK-LIFETIMES: %[[BLOCK_SIZES4:.*]] = alloca [1 x i64] 64 // B32: %[[BLOCK_SIZES5:.*]] = alloca [1 x i32] 65 // B64: %[[BLOCK_SIZES5:.*]] = alloca [1 x i64] 66 // CHECK-LIFETIMES: %[[BLOCK_SIZES5:.*]] = alloca [1 x i64] 67 // B32: %[[BLOCK_SIZES6:.*]] = alloca [3 x i32] 68 // B64: %[[BLOCK_SIZES6:.*]] = alloca [3 x i64] 69 // CHECK-LIFETIMES: %[[BLOCK_SIZES6:.*]] = alloca [3 x i64] 70 // B32: %[[BLOCK_SIZES7:.*]] = alloca [1 x i32] 71 // B64: %[[BLOCK_SIZES7:.*]] = alloca [1 x i64] 72 // CHECK-LIFETIMES: %[[BLOCK_SIZES7:.*]] = alloca [1 x i64] 73 74 // Emits block literal on stack and block kernel [[INVLK1]]. 75 // COMMON: [[DEF_Q:%[0-9]+]] = load %opencl.queue_t{{.*}}*, %opencl.queue_t{{.*}}** %default_queue 76 // COMMON: [[FLAGS:%[0-9]+]] = load i32, i32* %flags 77 // B32: [[BL:%[0-9]+]] = bitcast <{ i32, i32, i32 addrspace(1)*, i32, i32 addrspace(1)* }>* %block to void ()* 78 // B64: [[BL:%[0-9]+]] = bitcast <{ i32, i32, i32 addrspace(1)*, i32 addrspace(1)*, i32 }>* %block to void ()* 79 // COMMON: [[BL_I8:%[0-9]+]] = addrspacecast void ()* [[BL]] to i8 addrspace(4)* 80 // COMMON-LABEL: call i32 @__enqueue_kernel_basic( 81 // COMMON-SAME: %opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]], %struct.ndrange_t* byval [[NDR]]{{([0-9]+)?}}, 82 // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8* bitcast ({{.*}} [[INVLK1:[^ ]+_kernel]] to i8*) to i8 addrspace(4)*), 83 // COMMON-SAME: i8 addrspace(4)* [[BL_I8]]) 84 enqueue_kernel(default_queue, flags, ndrange, 85 ^(void) { 86 a[i] = b[i]; 87 }); 88 89 // Emits block literal on stack and block kernel [[INVLK2]]. 90 // COMMON: [[DEF_Q:%[0-9]+]] = load %opencl.queue_t{{.*}}*, %opencl.queue_t{{.*}}** %default_queue 91 // COMMON: [[FLAGS:%[0-9]+]] = load i32, i32* %flags 92 // COMMON: [[WAIT_EVNT:%[0-9]+]] = addrspacecast %opencl.clk_event_t{{.*}}** %event_wait_list to %opencl.clk_event_t{{.*}}* addrspace(4)* 93 // COMMON: [[EVNT:%[0-9]+]] = addrspacecast %opencl.clk_event_t{{.*}}** %clk_event to %opencl.clk_event_t{{.*}}* addrspace(4)* 94 // COMMON: [[BL:%[0-9]+]] = bitcast <{ i32, i32, i32{{.*}}, i32{{.*}}, i32{{.*}} }>* %block3 to void ()* 95 // COMMON: [[BL_I8:%[0-9]+]] = addrspacecast void ()* [[BL]] to i8 addrspace(4)* 96 // COMMON-LABEL: call i32 @__enqueue_kernel_basic_events 97 // COMMON-SAME: (%opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]], %struct.ndrange_t* {{.*}}, i32 2, %opencl.clk_event_t{{.*}}* addrspace(4)* [[WAIT_EVNT]], %opencl.clk_event_t{{.*}}* addrspace(4)* [[EVNT]], 98 // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8* bitcast ({{.*}} [[INVLK2:[^ ]+_kernel]] to i8*) to i8 addrspace(4)*), 99 // COMMON-SAME: i8 addrspace(4)* [[BL_I8]]) 100 enqueue_kernel(default_queue, flags, ndrange, 2, &event_wait_list, &clk_event, 101 ^(void) { 102 a[i] = b[i]; 103 }); 104 105 // Emits global block literal [[BLG1]] and block kernel [[INVGK1]]. 106 // COMMON: [[DEF_Q:%[0-9]+]] = load %opencl.queue_t{{.*}}*, %opencl.queue_t{{.*}}** %default_queue 107 // COMMON: [[FLAGS:%[0-9]+]] = load i32, i32* %flags 108 // CHECK-LIFETIMES: [[LIFETIME_PTR:%[0-9]+]] = bitcast [1 x i64]* %[[BLOCK_SIZES1]] to i8* 109 // CHECK-LIFETIMES-NEXT: call void @llvm.lifetime.start.p0i8(i64 8, i8* nonnull [[LIFETIME_PTR]]) 110 // CHECK-LIFETIMES-NEXT: getelementptr inbounds [1 x i64], [1 x i64]* %[[BLOCK_SIZES1]], i64 0, i64 0 111 // CHECK-LIFETIMES-LABEL: call i32 @__enqueue_kernel_varargs( 112 // CHECK-LIFETIMES-NEXT: call void @llvm.lifetime.end.p0i8(i64 8, i8* nonnull [[LIFETIME_PTR]]) 113 // B32: %[[TMP:.*]] = getelementptr [1 x i32], [1 x i32]* %[[BLOCK_SIZES1]], i32 0, i32 0 114 // B32: store i32 256, i32* %[[TMP]], align 4 115 // B64: %[[TMP:.*]] = getelementptr [1 x i64], [1 x i64]* %[[BLOCK_SIZES1]], i32 0, i32 0 116 // B64: store i64 256, i64* %[[TMP]], align 8 117 // COMMON-LABEL: call i32 @__enqueue_kernel_varargs( 118 // COMMON-SAME: %opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]], %struct.ndrange_t* [[NDR]]{{([0-9]+)?}}, 119 // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8* bitcast ({{.*}} [[INVGK1:[^ ]+_kernel]] to i8*) to i8 addrspace(4)*), 120 // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32 } addrspace(1)* [[BLG1]] to i8 addrspace(1)*) to i8 addrspace(4)*), i32 1, 121 // B32-SAME: i32* %[[TMP]]) 122 // B64-SAME: i64* %[[TMP]]) 123 enqueue_kernel(default_queue, flags, ndrange, 124 ^(local void *p) { 125 return; 126 }, 127 256); 128 129 char c; 130 // Emits global block literal [[BLG2]] and block kernel [[INVGK2]]. 131 // COMMON: [[DEF_Q:%[0-9]+]] = load %opencl.queue_t{{.*}}*, %opencl.queue_t{{.*}}** %default_queue 132 // COMMON: [[FLAGS:%[0-9]+]] = load i32, i32* %flags 133 // CHECK-LIFETIMES: [[LIFETIME_PTR:%[0-9]+]] = bitcast [1 x i64]* %[[BLOCK_SIZES2]] to i8* 134 // CHECK-LIFETIMES-NEXT: call void @llvm.lifetime.start.p0i8(i64 8, i8* nonnull [[LIFETIME_PTR]]) 135 // CHECK-LIFETIMES-NEXT: getelementptr inbounds [1 x i64], [1 x i64]* %[[BLOCK_SIZES2]], i64 0, i64 0 136 // CHECK-LIFETIMES-LABEL: call i32 @__enqueue_kernel_varargs( 137 // CHECK-LIFETIMES-NEXT: call void @llvm.lifetime.end.p0i8(i64 8, i8* nonnull [[LIFETIME_PTR]]) 138 // B32: %[[TMP:.*]] = getelementptr [1 x i32], [1 x i32]* %[[BLOCK_SIZES2]], i32 0, i32 0 139 // B32: store i32 %{{.*}}, i32* %[[TMP]], align 4 140 // B64: %[[TMP:.*]] = getelementptr [1 x i64], [1 x i64]* %[[BLOCK_SIZES2]], i32 0, i32 0 141 // B64: store i64 %{{.*}}, i64* %[[TMP]], align 8 142 // COMMON-LABEL: call i32 @__enqueue_kernel_varargs( 143 // COMMON-SAME: %opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]], %struct.ndrange_t* [[NDR]]{{([0-9]+)?}}, 144 // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8* bitcast ({{.*}} [[INVGK2:[^ ]+_kernel]] to i8*) to i8 addrspace(4)*), 145 // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32 } addrspace(1)* [[BLG2]] to i8 addrspace(1)*) to i8 addrspace(4)*), i32 1, 146 // B32-SAME: i32* %[[TMP]]) 147 // B64-SAME: i64* %[[TMP]]) 148 enqueue_kernel(default_queue, flags, ndrange, 149 ^(local void *p) { 150 return; 151 }, 152 c); 153 154 // Emits global block literal [[BLG3]] and block kernel [[INVGK3]]. 155 // COMMON: [[DEF_Q:%[0-9]+]] = load %opencl.queue_t{{.*}}*, %opencl.queue_t{{.*}}** %default_queue 156 // COMMON: [[FLAGS:%[0-9]+]] = load i32, i32* %flags 157 // COMMON: [[AD:%arraydecay[0-9]*]] = getelementptr inbounds [1 x %opencl.clk_event_t*], [1 x %opencl.clk_event_t*]* %event_wait_list2, i32 0, i32 0 158 // COMMON: [[WAIT_EVNT:%[0-9]+]] = addrspacecast %opencl.clk_event_t{{.*}}** [[AD]] to %opencl.clk_event_t{{.*}}* addrspace(4)* 159 // COMMON: [[EVNT:%[0-9]+]] = addrspacecast %opencl.clk_event_t{{.*}}** %clk_event to %opencl.clk_event_t{{.*}}* addrspace(4)* 160 // CHECK-LIFETIMES: [[LIFETIME_PTR:%[0-9]+]] = bitcast [1 x i64]* %[[BLOCK_SIZES3]] to i8* 161 // CHECK-LIFETIMES-NEXT: call void @llvm.lifetime.start.p0i8(i64 8, i8* nonnull [[LIFETIME_PTR]]) 162 // CHECK-LIFETIMES-NEXT: getelementptr inbounds [1 x i64], [1 x i64]* %[[BLOCK_SIZES3]], i64 0, i64 0 163 // CHECK-LIFETIMES-LABEL: call i32 @__enqueue_kernel_events_varargs( 164 // CHECK-LIFETIMES-NEXT: call void @llvm.lifetime.end.p0i8(i64 8, i8* nonnull [[LIFETIME_PTR]]) 165 // B32: %[[TMP:.*]] = getelementptr [1 x i32], [1 x i32]* %[[BLOCK_SIZES3]], i32 0, i32 0 166 // B32: store i32 256, i32* %[[TMP]], align 4 167 // B64: %[[TMP:.*]] = getelementptr [1 x i64], [1 x i64]* %[[BLOCK_SIZES3]], i32 0, i32 0 168 // B64: store i64 256, i64* %[[TMP]], align 8 169 // COMMON-LABEL: call i32 @__enqueue_kernel_events_varargs 170 // COMMON-SAME: (%opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]], %struct.ndrange_t* {{.*}}, i32 2, %opencl.clk_event_t{{.*}} [[WAIT_EVNT]], %opencl.clk_event_t{{.*}} [[EVNT]], 171 // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8* bitcast ({{.*}} [[INVGK3:[^ ]+_kernel]] to i8*) to i8 addrspace(4)*), 172 // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32 } addrspace(1)* [[BLG3]] to i8 addrspace(1)*) to i8 addrspace(4)*), i32 1, 173 // B32-SAME: i32* %[[TMP]]) 174 // B64-SAME: i64* %[[TMP]]) 175 enqueue_kernel(default_queue, flags, ndrange, 2, event_wait_list2, &clk_event, 176 ^(local void *p) { 177 return; 178 }, 179 256); 180 181 // Emits global block literal [[BLG4]] and block kernel [[INVGK4]]. 182 // COMMON: [[DEF_Q:%[0-9]+]] = load %opencl.queue_t{{.*}}*, %opencl.queue_t{{.*}}** %default_queue 183 // COMMON: [[FLAGS:%[0-9]+]] = load i32, i32* %flags 184 // COMMON: [[AD:%arraydecay[0-9]*]] = getelementptr inbounds [1 x %opencl.clk_event_t*], [1 x %opencl.clk_event_t*]* %event_wait_list2, i32 0, i32 0 185 // COMMON: [[WAIT_EVNT:%[0-9]+]] = addrspacecast %opencl.clk_event_t{{.*}}** [[AD]] to %opencl.clk_event_t{{.*}}* addrspace(4)* 186 // COMMON: [[EVNT:%[0-9]+]] = addrspacecast %opencl.clk_event_t{{.*}}** %clk_event to %opencl.clk_event_t{{.*}}* addrspace(4)* 187 // CHECK-LIFETIMES: [[LIFETIME_PTR:%[0-9]+]] = bitcast [1 x i64]* %[[BLOCK_SIZES4]] to i8* 188 // CHECK-LIFETIMES-NEXT: call void @llvm.lifetime.start.p0i8(i64 8, i8* nonnull [[LIFETIME_PTR]]) 189 // CHECK-LIFETIMES-NEXT: getelementptr inbounds [1 x i64], [1 x i64]* %[[BLOCK_SIZES4]], i64 0, i64 0 190 // CHECK-LIFETIMES-LABEL: call i32 @__enqueue_kernel_events_varargs( 191 // CHECK-LIFETIMES-NEXT: call void @llvm.lifetime.end.p0i8(i64 8, i8* nonnull [[LIFETIME_PTR]]) 192 // B32: %[[TMP:.*]] = getelementptr [1 x i32], [1 x i32]* %[[BLOCK_SIZES4]], i32 0, i32 0 193 // B32: store i32 %{{.*}}, i32* %[[TMP]], align 4 194 // B64: %[[TMP:.*]] = getelementptr [1 x i64], [1 x i64]* %[[BLOCK_SIZES4]], i32 0, i32 0 195 // B64: store i64 %{{.*}}, i64* %[[TMP]], align 8 196 // COMMON-LABEL: call i32 @__enqueue_kernel_events_varargs 197 // COMMON-SAME: (%opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]], %struct.ndrange_t* {{.*}}, i32 2, %opencl.clk_event_t{{.*}}* addrspace(4)* [[WAIT_EVNT]], %opencl.clk_event_t{{.*}}* addrspace(4)* [[EVNT]], 198 // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8* bitcast ({{.*}} [[INVGK4:[^ ]+_kernel]] to i8*) to i8 addrspace(4)*), 199 // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32 } addrspace(1)* [[BLG4]] to i8 addrspace(1)*) to i8 addrspace(4)*), i32 1, 200 // B32-SAME: i32* %[[TMP]]) 201 // B64-SAME: i64* %[[TMP]]) 202 enqueue_kernel(default_queue, flags, ndrange, 2, event_wait_list2, &clk_event, 203 ^(local void *p) { 204 return; 205 }, 206 c); 207 208 long l; 209 // Emits global block literal [[BLG5]] and block kernel [[INVGK5]]. 210 // COMMON: [[DEF_Q:%[0-9]+]] = load %opencl.queue_t{{.*}}*, %opencl.queue_t{{.*}}** %default_queue 211 // COMMON: [[FLAGS:%[0-9]+]] = load i32, i32* %flags 212 // CHECK-LIFETIMES: [[LIFETIME_PTR:%[0-9]+]] = bitcast [1 x i64]* %[[BLOCK_SIZES5]] to i8* 213 // CHECK-LIFETIMES-NEXT: call void @llvm.lifetime.start.p0i8(i64 8, i8* nonnull [[LIFETIME_PTR]]) 214 // CHECK-LIFETIMES-NEXT: getelementptr inbounds [1 x i64], [1 x i64]* %[[BLOCK_SIZES5]], i64 0, i64 0 215 // CHECK-LIFETIMES-LABEL: call i32 @__enqueue_kernel_varargs( 216 // CHECK-LIFETIMES-NEXT: call void @llvm.lifetime.end.p0i8(i64 8, i8* nonnull [[LIFETIME_PTR]]) 217 // B32: %[[TMP:.*]] = getelementptr [1 x i32], [1 x i32]* %[[BLOCK_SIZES5]], i32 0, i32 0 218 // B32: store i32 %{{.*}}, i32* %[[TMP]], align 4 219 // B64: %[[TMP:.*]] = getelementptr [1 x i64], [1 x i64]* %[[BLOCK_SIZES5]], i32 0, i32 0 220 // B64: store i64 %{{.*}}, i64* %[[TMP]], align 8 221 // COMMON-LABEL: call i32 @__enqueue_kernel_varargs 222 // COMMON-SAME: (%opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]], %struct.ndrange_t* [[NDR]]{{([0-9]+)?}}, 223 // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8* bitcast ({{.*}} [[INVGK5:[^ ]+_kernel]] to i8*) to i8 addrspace(4)*), 224 // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32 } addrspace(1)* [[BLG5]] to i8 addrspace(1)*) to i8 addrspace(4)*), i32 1, 225 // B32-SAME: i32* %[[TMP]]) 226 // B64-SAME: i64* %[[TMP]]) 227 enqueue_kernel(default_queue, flags, ndrange, 228 ^(local void *p) { 229 return; 230 }, 231 l); 232 233 // Emits global block literal [[BLG6]] and block kernel [[INVGK6]]. 234 // COMMON: [[DEF_Q:%[0-9]+]] = load %opencl.queue_t{{.*}}*, %opencl.queue_t{{.*}}** %default_queue 235 // COMMON: [[FLAGS:%[0-9]+]] = load i32, i32* %flags 236 // CHECK-LIFETIMES: [[LIFETIME_PTR:%[0-9]+]] = bitcast [3 x i64]* %[[BLOCK_SIZES6]] to i8* 237 // CHECK-LIFETIMES-NEXT: call void @llvm.lifetime.start.p0i8(i64 24, i8* nonnull [[LIFETIME_PTR]]) 238 // CHECK-LIFETIMES-NEXT: getelementptr inbounds [3 x i64], [3 x i64]* %[[BLOCK_SIZES6]], i64 0, i64 0 239 // CHECK-LIFETIMES-LABEL: call i32 @__enqueue_kernel_varargs( 240 // CHECK-LIFETIMES-NEXT: call void @llvm.lifetime.end.p0i8(i64 24, i8* nonnull [[LIFETIME_PTR]]) 241 // B32: %[[TMP:.*]] = getelementptr [3 x i32], [3 x i32]* %[[BLOCK_SIZES6]], i32 0, i32 0 242 // B32: store i32 1, i32* %[[TMP]], align 4 243 // B32: %[[BLOCK_SIZES62:.*]] = getelementptr [3 x i32], [3 x i32]* %[[BLOCK_SIZES6]], i32 0, i32 1 244 // B32: store i32 2, i32* %[[BLOCK_SIZES62]], align 4 245 // B32: %[[BLOCK_SIZES63:.*]] = getelementptr [3 x i32], [3 x i32]* %[[BLOCK_SIZES6]], i32 0, i32 2 246 // B32: store i32 4, i32* %[[BLOCK_SIZES63]], align 4 247 // B64: %[[TMP:.*]] = getelementptr [3 x i64], [3 x i64]* %[[BLOCK_SIZES6]], i32 0, i32 0 248 // B64: store i64 1, i64* %[[TMP]], align 8 249 // B64: %[[BLOCK_SIZES62:.*]] = getelementptr [3 x i64], [3 x i64]* %[[BLOCK_SIZES6]], i32 0, i32 1 250 // B64: store i64 2, i64* %[[BLOCK_SIZES62]], align 8 251 // B64: %[[BLOCK_SIZES63:.*]] = getelementptr [3 x i64], [3 x i64]* %[[BLOCK_SIZES6]], i32 0, i32 2 252 // B64: store i64 4, i64* %[[BLOCK_SIZES63]], align 8 253 // COMMON-LABEL: call i32 @__enqueue_kernel_varargs 254 // COMMON-SAME: (%opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]], %struct.ndrange_t* [[NDR]]{{([0-9]+)?}}, 255 // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8* bitcast ({{.*}} [[INVGK6:[^ ]+_kernel]] to i8*) to i8 addrspace(4)*), 256 // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32 } addrspace(1)* [[BLG6]] to i8 addrspace(1)*) to i8 addrspace(4)*), i32 3, 257 // B32-SAME: i32* %[[TMP]]) 258 // B64-SAME: i64* %[[TMP]]) 259 enqueue_kernel(default_queue, flags, ndrange, 260 ^(local void *p1, local void *p2, local void *p3) { 261 return; 262 }, 263 1, 2, 4); 264 265 // Emits global block literal [[BLG7]] and block kernel [[INVGK7]]. 266 // COMMON: [[DEF_Q:%[0-9]+]] = load %opencl.queue_t*, %opencl.queue_t** %default_queue 267 // COMMON: [[FLAGS:%[0-9]+]] = load i32, i32* %flags 268 // CHECK-LIFETIMES: [[LIFETIME_PTR:%[0-9]+]] = bitcast [1 x i64]* %[[BLOCK_SIZES7]] to i8* 269 // CHECK-LIFETIMES-NEXT: call void @llvm.lifetime.start.p0i8(i64 8, i8* nonnull [[LIFETIME_PTR]]) 270 // CHECK-LIFETIMES-NEXT: getelementptr inbounds [1 x i64], [1 x i64]* %[[BLOCK_SIZES7]], i64 0, i64 0 271 // CHECK-LIFETIMES-LABEL: call i32 @__enqueue_kernel_varargs( 272 // CHECK-LIFETIMES-NEXT: call void @llvm.lifetime.end.p0i8(i64 8, i8* nonnull [[LIFETIME_PTR]]) 273 // B32: %[[TMP:.*]] = getelementptr [1 x i32], [1 x i32]* %[[BLOCK_SIZES7]], i32 0, i32 0 274 // B32: store i32 0, i32* %[[TMP]], align 4 275 // B64: %[[TMP:.*]] = getelementptr [1 x i64], [1 x i64]* %[[BLOCK_SIZES7]], i32 0, i32 0 276 // B64: store i64 4294967296, i64* %[[TMP]], align 8 277 // COMMON-LABEL: call i32 @__enqueue_kernel_varargs 278 // COMMON-SAME: (%opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]], %struct.ndrange_t* [[NDR]]{{([0-9]+)?}}, 279 // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8* bitcast ({{.*}} [[INVGK7:[^ ]+_kernel]] to i8*) to i8 addrspace(4)*), 280 // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32 } addrspace(1)* [[BLG7]] to i8 addrspace(1)*) to i8 addrspace(4)*), i32 1, 281 // B32-SAME: i32* %[[TMP]]) 282 // B64-SAME: i64* %[[TMP]]) 283 enqueue_kernel(default_queue, flags, ndrange, 284 ^(local void *p) { 285 return; 286 }, 287 4294967296L); 288 289 // Emits global block literal [[BLG8]] and invoke function [[INVG8]]. 290 // The full type of these expressions are long (and repeated elsewhere), so we 291 // capture it as part of the regex for convenience and clarity. 292 // COMMON: store void () addrspace(4)* addrspacecast (void () addrspace(1)* bitcast ({ i32, i32 } addrspace(1)* [[BLG8]] to void () addrspace(1)*) to void () addrspace(4)*), void () addrspace(4)** %block_A 293 void (^const block_A)(void) = ^{ 294 return; 295 }; 296 297 // Emits global block literal [[BLG9]] and invoke function [[INVG9]]. 298 // COMMON: store void (i8 addrspace(3)*) addrspace(4)* addrspacecast (void (i8 addrspace(3)*) addrspace(1)* bitcast ({ i32, i32 } addrspace(1)* [[BLG9]] to void (i8 addrspace(3)*) addrspace(1)*) to void (i8 addrspace(3)*) addrspace(4)*), void (i8 addrspace(3)*) addrspace(4)** %block_B 299 void (^const block_B)(local void *) = ^(local void *a) { 300 return; 301 }; 302 303 // Uses global block literal [[BLG8]] and invoke function [[INVG8]]. 304 // COMMON: call spir_func void [[INVG8:.*]](i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32 } addrspace(1)* [[BLG8]] to i8 addrspace(1)*) to i8 addrspace(4)*)) 305 block_A(); 306 307 // Emits global block literal [[BLG8]] and block kernel [[INVGK8]]. [[INVGK8]] calls [[INVG8]]. 308 // COMMON: [[DEF_Q:%[0-9]+]] = load %opencl.queue_t{{.*}}*, %opencl.queue_t{{.*}}** %default_queue 309 // COMMON: [[FLAGS:%[0-9]+]] = load i32, i32* %flags 310 // COMMON-LABEL: call i32 @__enqueue_kernel_basic( 311 // COMMON-SAME: %opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]], %struct.ndrange_t* byval [[NDR]]{{([0-9]+)?}}, 312 // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8* bitcast ({{.*}} [[INVGK8:[^ ]+_kernel]] to i8*) to i8 addrspace(4)*), 313 // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32 } addrspace(1)* [[BLG8]] to i8 addrspace(1)*) to i8 addrspace(4)*)) 314 enqueue_kernel(default_queue, flags, ndrange, block_A); 315 316 // Uses block kernel [[INVGK8]] and global block literal [[BLG8]]. 317 // COMMON: call i32 @__get_kernel_work_group_size_impl( 318 // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8* bitcast ({{.*}} [[INVGK8]] to i8*) to i8 addrspace(4)*), 319 // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32 } addrspace(1)* [[BLG8]] to i8 addrspace(1)*) to i8 addrspace(4)*)) 320 unsigned size = get_kernel_work_group_size(block_A); 321 322 // Uses global block literal [[BLG8]] and invoke function [[INVG8]]. Make sure no redundant block literal and invoke functions are emitted. 323 // COMMON: call spir_func void [[INVG8]](i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32 } addrspace(1)* [[BLG8]] to i8 addrspace(1)*) to i8 addrspace(4)*)) 324 block_A(); 325 326 void (^block_C)(void) = ^{ 327 callee(i, a); 328 }; 329 330 // Emits block literal on stack and block kernel [[INVLK3]]. 331 // COMMON: [[DEF_Q:%[0-9]+]] = load %opencl.queue_t{{.*}}*, %opencl.queue_t{{.*}}** %default_queue 332 // COMMON: [[FLAGS:%[0-9]+]] = load i32, i32* %flags 333 // COMMON: [[BL_I8:%[0-9]+]] = addrspacecast void ()* {{.*}} to i8 addrspace(4)* 334 // COMMON-LABEL: call i32 @__enqueue_kernel_basic( 335 // COMMON-SAME: %opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]], %struct.ndrange_t* byval [[NDR]]{{([0-9]+)?}}, 336 // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8* bitcast ({{.*}} [[INVLK3:[^ ]+_kernel]] to i8*) to i8 addrspace(4)*), 337 // COMMON-SAME: i8 addrspace(4)* [[BL_I8]]) 338 enqueue_kernel(default_queue, flags, ndrange, block_C); 339 340 // Emits global block literal [[BLG9]] and block kernel [[INVGK9]]. [[INVGK9]] calls [[INVG9]]. 341 // COMMON: call i32 @__get_kernel_work_group_size_impl( 342 // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8* bitcast ({{.*}} [[INVGK9:[^ ]+_kernel]] to i8*) to i8 addrspace(4)*), 343 // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32 } addrspace(1)* [[BLG9]] to i8 addrspace(1)*) to i8 addrspace(4)*)) 344 size = get_kernel_work_group_size(block_B); 345 346 // Uses global block literal [[BLG8]] and block kernel [[INVGK8]]. Make sure no redundant block literal ind invoke functions are emitted. 347 // COMMON: call i32 @__get_kernel_preferred_work_group_size_multiple_impl( 348 // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8* bitcast ({{.*}} [[INVGK8]] to i8*) to i8 addrspace(4)*), 349 // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32 } addrspace(1)* [[BLG8]] to i8 addrspace(1)*) to i8 addrspace(4)*)) 350 size = get_kernel_preferred_work_group_size_multiple(block_A); 351 352 // Uses global block literal [[BL_GLOBAL]] and block kernel [[INV_G_K]]. [[INV_G_K]] calls [[INV_G]]. 353 // COMMON: call i32 @__get_kernel_preferred_work_group_size_multiple_impl( 354 // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8* bitcast ({{.*}} [[INV_G_K:[^ ]+_kernel]] to i8*) to i8 addrspace(4)*), 355 // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32 } addrspace(1)* [[BL_GLOBAL]] to i8 addrspace(1)*) to i8 addrspace(4)*)) 356 size = get_kernel_preferred_work_group_size_multiple(block_G); 357 358 // Emits global block literal [[BLG10]] and block kernel [[INVGK10]]. 359 // COMMON: call i32 @__get_kernel_max_sub_group_size_for_ndrange_impl(%struct.ndrange_t* {{[^,]+}}, 360 // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8* bitcast ({{.*}} [[INVGK10:[^ ]+_kernel]] to i8*) to i8 addrspace(4)*), 361 // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32 } addrspace(1)* [[BLG10]] to i8 addrspace(1)*) to i8 addrspace(4)*)) 362 size = get_kernel_max_sub_group_size_for_ndrange(ndrange, ^(){}); 363 364 // Emits global block literal [[BLG11]] and block kernel [[INVGK11]]. 365 // COMMON: call i32 @__get_kernel_sub_group_count_for_ndrange_impl(%struct.ndrange_t* {{[^,]+}}, 366 // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8* bitcast ({{.*}} [[INVGK11:[^ ]+_kernel]] to i8*) to i8 addrspace(4)*), 367 // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32 } addrspace(1)* [[BLG11]] to i8 addrspace(1)*) to i8 addrspace(4)*)) 368 size = get_kernel_sub_group_count_for_ndrange(ndrange, ^(){}); 369} 370 371// COMMON: define internal spir_kernel void [[INVLK1]](i8 addrspace(4)*) #{{[0-9]+}} { 372// COMMON: entry: 373// COMMON: call void @__device_side_enqueue_block_invoke(i8 addrspace(4)* %0) 374// COMMON: ret void 375// COMMON: } 376// COMMON: define internal spir_kernel void [[INVLK2]](i8 addrspace(4)*{{.*}}) 377// COMMON: define internal spir_kernel void [[INVGK1]](i8 addrspace(4)*{{.*}}, i8 addrspace(3)*{{.*}}) 378// COMMON: define internal spir_kernel void [[INVGK2]](i8 addrspace(4)*{{.*}}, i8 addrspace(3)*{{.*}}) 379// COMMON: define internal spir_kernel void [[INVGK3]](i8 addrspace(4)*{{.*}}, i8 addrspace(3)*{{.*}}) 380// COMMON: define internal spir_kernel void [[INVGK4]](i8 addrspace(4)*{{.*}}, i8 addrspace(3)*{{.*}}) 381// COMMON: define internal spir_kernel void [[INVGK5]](i8 addrspace(4)*{{.*}}, i8 addrspace(3)*{{.*}}) 382// COMMON: define internal spir_kernel void [[INVGK6]](i8 addrspace(4)*, i8 addrspace(3)*, i8 addrspace(3)*, i8 addrspace(3)*) #{{[0-9]+}} { 383// COMMON: entry: 384// COMMON: call void @__device_side_enqueue_block_invoke_8(i8 addrspace(4)* %0, i8 addrspace(3)* %1, i8 addrspace(3)* %2, i8 addrspace(3)* %3) 385// COMMON: ret void 386// COMMON: } 387// COMMON: define internal spir_kernel void [[INVGK7]](i8 addrspace(4)*{{.*}}, i8 addrspace(3)*{{.*}}) 388// COMMON: define internal spir_func void [[INVG8]](i8 addrspace(4)*{{.*}}) 389// COMMON: define internal spir_func void [[INVG9:.*]](i8 addrspace(4)*{{.*}}, i8 addrspace(3)* %{{.*}}) 390// COMMON: define internal spir_kernel void [[INVGK8]](i8 addrspace(4)*{{.*}}) 391// COMMON: define internal spir_kernel void [[INVLK3]](i8 addrspace(4)*{{.*}}) 392// COMMON: define internal spir_kernel void [[INVGK9]](i8 addrspace(4)*{{.*}}, i8 addrspace(3)*{{.*}}) 393// COMMON: define internal spir_kernel void [[INV_G_K]](i8 addrspace(4)*{{.*}}, i8 addrspace(3)*{{.*}}) 394// COMMON: define internal spir_kernel void [[INVGK10]](i8 addrspace(4)*{{.*}}) 395// COMMON: define internal spir_kernel void [[INVGK11]](i8 addrspace(4)*{{.*}}) 396