blob: 19aacc3f0d92fdc1e01c2976b7ebdf8f170f5a4b [file] [log] [blame]
Scott Linder58df0e42018-08-08 15:56:12 +00001// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -o - -O0 -triple spir-unknown-unknown | FileCheck -check-prefixes=COMMON,SPIR %s
2// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -o - -O0 -triple amdgcn-amd-amdhsa | FileCheck -check-prefixes=COMMON,AMDGCN %s
3// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -o - -O0 -debug-info-kind=limited -triple spir-unknown-unknown | FileCheck -check-prefixes=CHECK-DEBUG %s
4// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -o - -O0 -debug-info-kind=limited -triple amdgcn-amd-amdhsa | FileCheck -check-prefixes=CHECK-DEBUG %s
Anastasia Stulovaaf0a7bb2017-01-27 15:11:34 +00005
Sven van Haastregtda3b6322018-10-02 13:02:24 +00006// SPIR: %struct.__opencl_block_literal_generic = type { i32, i32, i8 addrspace(4)* }
7// AMDGCN: %struct.__opencl_block_literal_generic = type { i32, i32, i8* }
8// SPIR: @__block_literal_global = internal addrspace(1) constant { i32, i32, i8 addrspace(4)* } { i32 12, i32 4, i8 addrspace(4)* addrspacecast (i8* bitcast (void (i8 addrspace(4)*, i8 addrspace(3)*)* @block_A_block_invoke to i8*) to i8 addrspace(4)*) }
9// AMDGCN: @__block_literal_global = internal addrspace(1) constant { i32, i32, i8* } { i32 16, i32 8, i8* bitcast (void (i8*, i8 addrspace(3)*)* @block_A_block_invoke to i8*) }
Yaxun Liu10712d92017-10-04 20:32:17 +000010// COMMON-NOT: .str
11
Yaxun Liuf5f45e52018-02-02 16:08:24 +000012// SPIR-LABEL: define internal {{.*}}void @block_A_block_invoke(i8 addrspace(4)* %.block_descriptor, i8 addrspace(3)* %a)
Yaxun Liuf8ad59d2018-02-15 19:12:41 +000013// AMDGCN-LABEL: define internal {{.*}}void @block_A_block_invoke(i8* %.block_descriptor, i8 addrspace(3)* %a)
Anastasia Stulovaaf0a7bb2017-01-27 15:11:34 +000014void (^block_A)(local void *) = ^(local void *a) {
15 return;
16};
17
Yaxun Liu10712d92017-10-04 20:32:17 +000018// COMMON-LABEL: define {{.*}}void @foo()
Anastasia Stulovaaf0a7bb2017-01-27 15:11:34 +000019void foo(){
20 int i;
Yaxun Liu10712d92017-10-04 20:32:17 +000021 // COMMON-NOT: %block.isa
22 // COMMON-NOT: %block.flags
23 // COMMON-NOT: %block.reserved
24 // COMMON-NOT: %block.descriptor
Sven van Haastregtda3b6322018-10-02 13:02:24 +000025 // SPIR: %[[block_size:.*]] = getelementptr inbounds <{ i32, i32, i8 addrspace(4)*, i32 }>, <{ i32, i32, i8 addrspace(4)*, i32 }>* %block, i32 0, i32 0
26 // AMDGCN: %[[block_size:.*]] = getelementptr inbounds <{ i32, i32, i8*, i32 }>, <{ i32, i32, i8*, i32 }> addrspace(5)* %block, i32 0, i32 0
27 // SPIR: store i32 16, i32* %[[block_size]]
28 // AMDGCN: store i32 20, i32 addrspace(5)* %[[block_size]]
29 // SPIR: %[[block_align:.*]] = getelementptr inbounds <{ i32, i32, i8 addrspace(4)*, i32 }>, <{ i32, i32, i8 addrspace(4)*, i32 }>* %block, i32 0, i32 1
30 // AMDGCN: %[[block_align:.*]] = getelementptr inbounds <{ i32, i32, i8*, i32 }>, <{ i32, i32, i8*, i32 }> addrspace(5)* %block, i32 0, i32 1
Yaxun Liu10712d92017-10-04 20:32:17 +000031 // SPIR: store i32 4, i32* %[[block_align]]
Sven van Haastregtda3b6322018-10-02 13:02:24 +000032 // AMDGCN: store i32 8, i32 addrspace(5)* %[[block_align]]
33 // SPIR: %[[block_invoke:.*]] = getelementptr inbounds <{ i32, i32, i8 addrspace(4)*, i32 }>, <{ i32, i32, i8 addrspace(4)*, i32 }>* %[[block:.*]], i32 0, i32 2
34 // SPIR: store i8 addrspace(4)* addrspacecast (i8* bitcast (i32 (i8 addrspace(4)*)* @__foo_block_invoke to i8*) to i8 addrspace(4)*), i8 addrspace(4)** %[[block_invoke]]
35 // SPIR: %[[block_captured:.*]] = getelementptr inbounds <{ i32, i32, i8 addrspace(4)*, i32 }>, <{ i32, i32, i8 addrspace(4)*, i32 }>* %[[block]], i32 0, i32 3
Yaxun Liuf5f45e52018-02-02 16:08:24 +000036 // SPIR: %[[i_value:.*]] = load i32, i32* %i
37 // SPIR: store i32 %[[i_value]], i32* %[[block_captured]],
Alexey Bader24fa0c12019-02-19 15:19:06 +000038 // SPIR: %[[blk_ptr:.*]] = bitcast <{ i32, i32, i8 addrspace(4)*, i32 }>* %[[block]] to %struct.__opencl_block_literal_generic*
39 // SPIR: %[[blk_gen_ptr:.*]] = addrspacecast %struct.__opencl_block_literal_generic* %[[blk_ptr]] to %struct.__opencl_block_literal_generic addrspace(4)*
40 // SPIR: store %struct.__opencl_block_literal_generic addrspace(4)* %[[blk_gen_ptr]], %struct.__opencl_block_literal_generic addrspace(4)** %[[block_B:.*]],
41 // SPIR: %[[block_literal:.*]] = load %struct.__opencl_block_literal_generic addrspace(4)*, %struct.__opencl_block_literal_generic addrspace(4)** %[[block_B]]
Sven van Haastregtda3b6322018-10-02 13:02:24 +000042 // SPIR: %[[invoke_addr:.*]] = getelementptr inbounds %struct.__opencl_block_literal_generic, %struct.__opencl_block_literal_generic addrspace(4)* %[[block_literal]], i32 0, i32 2
43 // SPIR: %[[blk_gen_ptr:.*]] = bitcast %struct.__opencl_block_literal_generic addrspace(4)* %[[block_literal]] to i8 addrspace(4)*
44 // SPIR: %[[invoke_func_ptr:.*]] = load i8 addrspace(4)*, i8 addrspace(4)* addrspace(4)* %[[invoke_addr]]
45 // SPIR: %[[invoke_func:.*]] = addrspacecast i8 addrspace(4)* %[[invoke_func_ptr]] to i32 (i8 addrspace(4)*)*
46 // SPIR: call {{.*}}i32 %[[invoke_func]](i8 addrspace(4)* %[[blk_gen_ptr]])
47 // AMDGCN: %[[block_invoke:.*]] = getelementptr inbounds <{ i32, i32, i8*, i32 }>, <{ i32, i32, i8*, i32 }> addrspace(5)* %[[block:.*]], i32 0, i32 2
48 // AMDGCN: store i8* bitcast (i32 (i8*)* @__foo_block_invoke to i8*), i8* addrspace(5)* %[[block_invoke]]
49 // AMDGCN: %[[block_captured:.*]] = getelementptr inbounds <{ i32, i32, i8*, i32 }>, <{ i32, i32, i8*, i32 }> addrspace(5)* %[[block]], i32 0, i32 3
Yaxun Liuf8ad59d2018-02-15 19:12:41 +000050 // AMDGCN: %[[i_value:.*]] = load i32, i32 addrspace(5)* %i
51 // AMDGCN: store i32 %[[i_value]], i32 addrspace(5)* %[[block_captured]],
Alexey Bader24fa0c12019-02-19 15:19:06 +000052 // AMDGCN: %[[blk_ptr:.*]] = bitcast <{ i32, i32, i8*, i32 }> addrspace(5)* %[[block]] to %struct.__opencl_block_literal_generic addrspace(5)*
53 // AMDGCN: %[[blk_gen_ptr:.*]] = addrspacecast %struct.__opencl_block_literal_generic addrspace(5)* %[[blk_ptr]] to %struct.__opencl_block_literal_generic*
54 // AMDGCN: store %struct.__opencl_block_literal_generic* %[[blk_gen_ptr]], %struct.__opencl_block_literal_generic* addrspace(5)* %[[block_B:.*]],
55 // AMDGCN: %[[block_literal:.*]] = load %struct.__opencl_block_literal_generic*, %struct.__opencl_block_literal_generic* addrspace(5)* %[[block_B]]
Sven van Haastregtda3b6322018-10-02 13:02:24 +000056 // AMDGCN: %[[invoke_addr:.*]] = getelementptr inbounds %struct.__opencl_block_literal_generic, %struct.__opencl_block_literal_generic* %[[block_literal]], i32 0, i32 2
57 // AMDGCN: %[[blk_gen_ptr:.*]] = bitcast %struct.__opencl_block_literal_generic* %[[block_literal]] to i8*
58 // AMDGCN: %[[invoke_func_ptr:.*]] = load i8*, i8** %[[invoke_addr]]
59 // AMDGCN: %[[invoke_func:.*]] = bitcast i8* %[[invoke_func_ptr]] to i32 (i8*)*
60 // AMDGCN: call {{.*}}i32 %[[invoke_func]](i8* %[[blk_gen_ptr]])
Yaxun Liu10712d92017-10-04 20:32:17 +000061
Anastasia Stulovaaf0a7bb2017-01-27 15:11:34 +000062 int (^ block_B)(void) = ^{
63 return i;
64 };
Yaxun Liu10712d92017-10-04 20:32:17 +000065 block_B();
Anastasia Stulovaaf0a7bb2017-01-27 15:11:34 +000066}
Yaxun Liu10712d92017-10-04 20:32:17 +000067
Yaxun Liuf5f45e52018-02-02 16:08:24 +000068// SPIR-LABEL: define internal {{.*}}i32 @__foo_block_invoke(i8 addrspace(4)* %.block_descriptor)
Sven van Haastregtda3b6322018-10-02 13:02:24 +000069// SPIR: %[[block:.*]] = bitcast i8 addrspace(4)* %.block_descriptor to <{ i32, i32, i8 addrspace(4)*, i32 }> addrspace(4)*
70// SPIR: %[[block_capture_addr:.*]] = getelementptr inbounds <{ i32, i32, i8 addrspace(4)*, i32 }>, <{ i32, i32, i8 addrspace(4)*, i32 }> addrspace(4)* %[[block]], i32 0, i32 3
Yaxun Liuf5f45e52018-02-02 16:08:24 +000071// SPIR: %[[block_capture:.*]] = load i32, i32 addrspace(4)* %[[block_capture_addr]]
Yaxun Liuf8ad59d2018-02-15 19:12:41 +000072// AMDGCN-LABEL: define internal {{.*}}i32 @__foo_block_invoke(i8* %.block_descriptor)
Sven van Haastregtda3b6322018-10-02 13:02:24 +000073// AMDGCN: %[[block:.*]] = bitcast i8* %.block_descriptor to <{ i32, i32, i8*, i32 }>*
74// AMDGCN: %[[block_capture_addr:.*]] = getelementptr inbounds <{ i32, i32, i8*, i32 }>, <{ i32, i32, i8*, i32 }>* %[[block]], i32 0, i32 3
Yaxun Liuf8ad59d2018-02-15 19:12:41 +000075// AMDGCN: %[[block_capture:.*]] = load i32, i32* %[[block_capture_addr]]
Yaxun Liuc2a87a02017-10-14 12:23:50 +000076
77// COMMON-NOT: define{{.*}}@__foo_block_invoke_kernel
Scott Linder2b5cf042018-07-30 20:31:11 +000078
Sven van Haastregta3c6b402018-10-02 13:02:27 +000079// Test that we support block arguments.
80// COMMON-LABEL: define {{.*}} @blockArgFunc
81int blockArgFunc(int (^ bl)(void)) {
82 return bl();
83}
84
85// COMMON-LABEL: define {{.*}} @get21
86// COMMON: define {{.*}} @__get21_block_invoke
87// COMMON: ret i32 21
88int get21() {
89 return blockArgFunc(^{return 21;});
90}
91
92// COMMON-LABEL: define {{.*}} @get42
93// COMMON: define {{.*}} @__get42_block_invoke
94// COMMON: ret i32 42
95int get42() {
96 return blockArgFunc(^{return 42;});
97}
98
Scott Linder58df0e42018-08-08 15:56:12 +000099// CHECK-DEBUG: !DIDerivedType(tag: DW_TAG_member, name: "__size"
100// CHECK-DEBUG: !DIDerivedType(tag: DW_TAG_member, name: "__align"
Scott Linder2b5cf042018-07-30 20:31:11 +0000101
Scott Linder58df0e42018-08-08 15:56:12 +0000102// CHECK-DEBUG-NOT: !DIDerivedType(tag: DW_TAG_member, name: "__isa"
103// CHECK-DEBUG-NOT: !DIDerivedType(tag: DW_TAG_member, name: "__flags"
104// CHECK-DEBUG-NOT: !DIDerivedType(tag: DW_TAG_member, name: "__reserved"
105// CHECK-DEBUG-NOT: !DIDerivedType(tag: DW_TAG_member, name: "__FuncPtr"