1// RUN: %clang_cc1 -no-opaque-pointers -triple %itanium_abi_triple -emit-llvm -cl-ext=+cl_khr_subgroups -O0 -cl-std=clc++ -o - %s | FileCheck %s
2// FIXME: Add MS ABI manglings of OpenCL things and remove %itanium_abi_triple
3// above to support OpenCL in the MS C++ ABI.
4
5// CHECK-DAG: %opencl.pipe_ro_t = type opaque
6// CHECK-DAG: %opencl.pipe_wo_t = type opaque
7// CHECK-DAG: %opencl.reserve_id_t = type opaque
8
9#pragma OPENCL EXTENSION cl_khr_subgroups : enable
10
11void test1(read_only pipe int p, global int *ptr) {
12  // CHECK: call i32 @__read_pipe_2(%opencl.pipe_ro_t* %{{.*}}, i8* %{{.*}}, i32 4, i32 4)
13  read_pipe(p, ptr);
14  // CHECK: call %opencl.reserve_id_t* @__reserve_read_pipe(%opencl.pipe_ro_t* %{{.*}}, i32 {{.*}}, i32 4, i32 4)
15  reserve_id_t rid = reserve_read_pipe(p, 2);
16  // CHECK: call i32 @__read_pipe_4(%opencl.pipe_ro_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}}, i32 {{.*}}, i8* %{{.*}}, i32 4, i32 4)
17  read_pipe(p, rid, 2, ptr);
18  // CHECK: call void @__commit_read_pipe(%opencl.pipe_ro_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}}, i32 4, i32 4)
19  commit_read_pipe(p, rid);
20}
21
22void test2(write_only pipe int p, global int *ptr) {
23  // CHECK: call i32 @__write_pipe_2(%opencl.pipe_wo_t* %{{.*}}, i8* %{{.*}}, i32 4, i32 4)
24  write_pipe(p, ptr);
25  // CHECK: call %opencl.reserve_id_t* @__reserve_write_pipe(%opencl.pipe_wo_t* %{{.*}}, i32 {{.*}}, i32 4, i32 4)
26  reserve_id_t rid = reserve_write_pipe(p, 2);
27  // CHECK: call i32 @__write_pipe_4(%opencl.pipe_wo_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}}, i32 {{.*}}, i8* %{{.*}}, i32 4, i32 4)
28  write_pipe(p, rid, 2, ptr);
29  // CHECK: call void @__commit_write_pipe(%opencl.pipe_wo_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}}, i32 4, i32 4)
30  commit_write_pipe(p, rid);
31}
32
33void test3(read_only pipe int p, global int *ptr) {
34  // CHECK: call %opencl.reserve_id_t* @__work_group_reserve_read_pipe(%opencl.pipe_ro_t* %{{.*}}, i32 {{.*}}, i32 4, i32 4)
35  reserve_id_t rid = work_group_reserve_read_pipe(p, 2);
36  // CHECK: call void @__work_group_commit_read_pipe(%opencl.pipe_ro_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}}, i32 4, i32 4)
37  work_group_commit_read_pipe(p, rid);
38}
39
40void test4(write_only pipe int p, global int *ptr) {
41  // CHECK: call %opencl.reserve_id_t* @__work_group_reserve_write_pipe(%opencl.pipe_wo_t* %{{.*}}, i32 {{.*}}, i32 4, i32 4)
42  reserve_id_t rid = work_group_reserve_write_pipe(p, 2);
43  // CHECK: call void @__work_group_commit_write_pipe(%opencl.pipe_wo_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}}, i32 4, i32 4)
44  work_group_commit_write_pipe(p, rid);
45}
46
47void test5(read_only pipe int p, global int *ptr) {
48  // CHECK: call %opencl.reserve_id_t* @__sub_group_reserve_read_pipe(%opencl.pipe_ro_t* %{{.*}}, i32 {{.*}}, i32 4, i32 4)
49  reserve_id_t rid = sub_group_reserve_read_pipe(p, 2);
50  // CHECK: call void @__sub_group_commit_read_pipe(%opencl.pipe_ro_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}}, i32 4, i32 4)
51  sub_group_commit_read_pipe(p, rid);
52}
53
54void test6(write_only pipe int p, global int *ptr) {
55  // CHECK: call %opencl.reserve_id_t* @__sub_group_reserve_write_pipe(%opencl.pipe_wo_t* %{{.*}}, i32 {{.*}}, i32 4, i32 4)
56  reserve_id_t rid = sub_group_reserve_write_pipe(p, 2);
57  // CHECK: call void @__sub_group_commit_write_pipe(%opencl.pipe_wo_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}}, i32 4, i32 4)
58  sub_group_commit_write_pipe(p, rid);
59}
60
61void test7(read_only pipe int p, global int *ptr) {
62  // CHECK: call i32 @__get_pipe_num_packets_ro(%opencl.pipe_ro_t* %{{.*}}, i32 4, i32 4)
63  *ptr = get_pipe_num_packets(p);
64  // CHECK: call i32 @__get_pipe_max_packets_ro(%opencl.pipe_ro_t* %{{.*}}, i32 4, i32 4)
65  *ptr = get_pipe_max_packets(p);
66}
67
68void test8(write_only pipe int p, global int *ptr) {
69  // CHECK: call i32 @__get_pipe_num_packets_wo(%opencl.pipe_wo_t* %{{.*}}, i32 4, i32 4)
70  *ptr = get_pipe_num_packets(p);
71  // CHECK: call i32 @__get_pipe_max_packets_wo(%opencl.pipe_wo_t* %{{.*}}, i32 4, i32 4)
72  *ptr = get_pipe_max_packets(p);
73}
74