blob: 675240c6f05dc40c1fe9f8ac3e15ba217005a143 [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]],
Sven van Haastregtda3b6322018-10-02 13:02:24 +000038 // SPIR: %[[blk_ptr:.*]] = bitcast <{ i32, i32, i8 addrspace(4)*, i32 }>* %[[block]] to i32 ()*
Yaxun Liuf5f45e52018-02-02 16:08:24 +000039 // SPIR: %[[blk_gen_ptr:.*]] = addrspacecast i32 ()* %[[blk_ptr]] to i32 () addrspace(4)*
40 // SPIR: store i32 () addrspace(4)* %[[blk_gen_ptr]], i32 () addrspace(4)** %[[block_B:.*]],
Sven van Haastregtda3b6322018-10-02 13:02:24 +000041 // SPIR: %[[blk_gen_ptr:.*]] = load i32 () addrspace(4)*, i32 () addrspace(4)** %[[block_B]]
42 // SPIR: %[[block_literal:.*]] = bitcast i32 () addrspace(4)* %[[blk_gen_ptr]] to %struct.__opencl_block_literal_generic addrspace(4)*
43 // SPIR: %[[invoke_addr:.*]] = getelementptr inbounds %struct.__opencl_block_literal_generic, %struct.__opencl_block_literal_generic addrspace(4)* %[[block_literal]], i32 0, i32 2
44 // SPIR: %[[blk_gen_ptr:.*]] = bitcast %struct.__opencl_block_literal_generic addrspace(4)* %[[block_literal]] to i8 addrspace(4)*
45 // SPIR: %[[invoke_func_ptr:.*]] = load i8 addrspace(4)*, i8 addrspace(4)* addrspace(4)* %[[invoke_addr]]
46 // SPIR: %[[invoke_func:.*]] = addrspacecast i8 addrspace(4)* %[[invoke_func_ptr]] to i32 (i8 addrspace(4)*)*
47 // SPIR: call {{.*}}i32 %[[invoke_func]](i8 addrspace(4)* %[[blk_gen_ptr]])
48 // AMDGCN: %[[block_invoke:.*]] = getelementptr inbounds <{ i32, i32, i8*, i32 }>, <{ i32, i32, i8*, i32 }> addrspace(5)* %[[block:.*]], i32 0, i32 2
49 // AMDGCN: store i8* bitcast (i32 (i8*)* @__foo_block_invoke to i8*), i8* addrspace(5)* %[[block_invoke]]
50 // 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 +000051 // AMDGCN: %[[i_value:.*]] = load i32, i32 addrspace(5)* %i
52 // AMDGCN: store i32 %[[i_value]], i32 addrspace(5)* %[[block_captured]],
Sven van Haastregtda3b6322018-10-02 13:02:24 +000053 // AMDGCN: %[[blk_ptr:.*]] = bitcast <{ i32, i32, i8*, i32 }> addrspace(5)* %[[block]] to i32 () addrspace(5)*
Yaxun Liuf8ad59d2018-02-15 19:12:41 +000054 // AMDGCN: %[[blk_gen_ptr:.*]] = addrspacecast i32 () addrspace(5)* %[[blk_ptr]] to i32 ()*
55 // AMDGCN: store i32 ()* %[[blk_gen_ptr]], i32 ()* addrspace(5)* %[[block_B:.*]],
Sven van Haastregtda3b6322018-10-02 13:02:24 +000056 // AMDGCN: %[[blk_gen_ptr:.*]] = load i32 ()*, i32 ()* addrspace(5)* %[[block_B]]
57 // AMDGCN: %[[block_literal:.*]] = bitcast i32 ()* %[[blk_gen_ptr]] to %struct.__opencl_block_literal_generic*
58 // AMDGCN: %[[invoke_addr:.*]] = getelementptr inbounds %struct.__opencl_block_literal_generic, %struct.__opencl_block_literal_generic* %[[block_literal]], i32 0, i32 2
59 // AMDGCN: %[[blk_gen_ptr:.*]] = bitcast %struct.__opencl_block_literal_generic* %[[block_literal]] to i8*
60 // AMDGCN: %[[invoke_func_ptr:.*]] = load i8*, i8** %[[invoke_addr]]
61 // AMDGCN: %[[invoke_func:.*]] = bitcast i8* %[[invoke_func_ptr]] to i32 (i8*)*
62 // AMDGCN: call {{.*}}i32 %[[invoke_func]](i8* %[[blk_gen_ptr]])
Yaxun Liu10712d92017-10-04 20:32:17 +000063
Anastasia Stulovaaf0a7bb2017-01-27 15:11:34 +000064 int (^ block_B)(void) = ^{
65 return i;
66 };
Yaxun Liu10712d92017-10-04 20:32:17 +000067 block_B();
Anastasia Stulovaaf0a7bb2017-01-27 15:11:34 +000068}
Yaxun Liu10712d92017-10-04 20:32:17 +000069
Yaxun Liuf5f45e52018-02-02 16:08:24 +000070// SPIR-LABEL: define internal {{.*}}i32 @__foo_block_invoke(i8 addrspace(4)* %.block_descriptor)
Sven van Haastregtda3b6322018-10-02 13:02:24 +000071// SPIR: %[[block:.*]] = bitcast i8 addrspace(4)* %.block_descriptor to <{ i32, i32, i8 addrspace(4)*, i32 }> addrspace(4)*
72// 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 +000073// SPIR: %[[block_capture:.*]] = load i32, i32 addrspace(4)* %[[block_capture_addr]]
Yaxun Liuf8ad59d2018-02-15 19:12:41 +000074// AMDGCN-LABEL: define internal {{.*}}i32 @__foo_block_invoke(i8* %.block_descriptor)
Sven van Haastregtda3b6322018-10-02 13:02:24 +000075// AMDGCN: %[[block:.*]] = bitcast i8* %.block_descriptor to <{ i32, i32, i8*, i32 }>*
76// 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 +000077// AMDGCN: %[[block_capture:.*]] = load i32, i32* %[[block_capture_addr]]
Yaxun Liuc2a87a02017-10-14 12:23:50 +000078
79// COMMON-NOT: define{{.*}}@__foo_block_invoke_kernel
Scott Linder2b5cf042018-07-30 20:31:11 +000080
Sven van Haastregta3c6b402018-10-02 13:02:27 +000081// Test that we support block arguments.
82// COMMON-LABEL: define {{.*}} @blockArgFunc
83int blockArgFunc(int (^ bl)(void)) {
84 return bl();
85}
86
87// COMMON-LABEL: define {{.*}} @get21
88// COMMON: define {{.*}} @__get21_block_invoke
89// COMMON: ret i32 21
90int get21() {
91 return blockArgFunc(^{return 21;});
92}
93
94// COMMON-LABEL: define {{.*}} @get42
95// COMMON: define {{.*}} @__get42_block_invoke
96// COMMON: ret i32 42
97int get42() {
98 return blockArgFunc(^{return 42;});
99}
100
Scott Linder58df0e42018-08-08 15:56:12 +0000101// CHECK-DEBUG: !DIDerivedType(tag: DW_TAG_member, name: "__size"
102// CHECK-DEBUG: !DIDerivedType(tag: DW_TAG_member, name: "__align"
Scott Linder2b5cf042018-07-30 20:31:11 +0000103
Scott Linder58df0e42018-08-08 15:56:12 +0000104// CHECK-DEBUG-NOT: !DIDerivedType(tag: DW_TAG_member, name: "__isa"
105// CHECK-DEBUG-NOT: !DIDerivedType(tag: DW_TAG_member, name: "__flags"
106// CHECK-DEBUG-NOT: !DIDerivedType(tag: DW_TAG_member, name: "__reserved"
107// CHECK-DEBUG-NOT: !DIDerivedType(tag: DW_TAG_member, name: "__FuncPtr"