2018-08-08 23:56:12 +08:00
|
|
|
// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -o - -O0 -triple spir-unknown-unknown | FileCheck -check-prefixes=COMMON,SPIR %s
|
|
|
|
// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -o - -O0 -triple amdgcn-amd-amdhsa | FileCheck -check-prefixes=COMMON,AMDGCN %s
|
|
|
|
// 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
|
|
|
|
// 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
|
2017-01-27 23:11:34 +08:00
|
|
|
|
2018-10-02 21:02:24 +08:00
|
|
|
// SPIR: %struct.__opencl_block_literal_generic = type { i32, i32, i8 addrspace(4)* }
|
|
|
|
// AMDGCN: %struct.__opencl_block_literal_generic = type { i32, i32, i8* }
|
|
|
|
// 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)*) }
|
|
|
|
// 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*) }
|
2017-10-05 04:32:17 +08:00
|
|
|
// COMMON-NOT: .str
|
|
|
|
|
2018-02-03 00:08:24 +08:00
|
|
|
// SPIR-LABEL: define internal {{.*}}void @block_A_block_invoke(i8 addrspace(4)* %.block_descriptor, i8 addrspace(3)* %a)
|
2018-02-16 03:12:41 +08:00
|
|
|
// AMDGCN-LABEL: define internal {{.*}}void @block_A_block_invoke(i8* %.block_descriptor, i8 addrspace(3)* %a)
|
2017-01-27 23:11:34 +08:00
|
|
|
void (^block_A)(local void *) = ^(local void *a) {
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
|
2017-10-05 04:32:17 +08:00
|
|
|
// COMMON-LABEL: define {{.*}}void @foo()
|
2017-01-27 23:11:34 +08:00
|
|
|
void foo(){
|
|
|
|
int i;
|
2017-10-05 04:32:17 +08:00
|
|
|
// COMMON-NOT: %block.isa
|
|
|
|
// COMMON-NOT: %block.flags
|
|
|
|
// COMMON-NOT: %block.reserved
|
|
|
|
// COMMON-NOT: %block.descriptor
|
2018-10-02 21:02:24 +08:00
|
|
|
// SPIR: %[[block_size:.*]] = getelementptr inbounds <{ i32, i32, i8 addrspace(4)*, i32 }>, <{ i32, i32, i8 addrspace(4)*, i32 }>* %block, i32 0, i32 0
|
|
|
|
// AMDGCN: %[[block_size:.*]] = getelementptr inbounds <{ i32, i32, i8*, i32 }>, <{ i32, i32, i8*, i32 }> addrspace(5)* %block, i32 0, i32 0
|
|
|
|
// SPIR: store i32 16, i32* %[[block_size]]
|
|
|
|
// AMDGCN: store i32 20, i32 addrspace(5)* %[[block_size]]
|
|
|
|
// SPIR: %[[block_align:.*]] = getelementptr inbounds <{ i32, i32, i8 addrspace(4)*, i32 }>, <{ i32, i32, i8 addrspace(4)*, i32 }>* %block, i32 0, i32 1
|
|
|
|
// AMDGCN: %[[block_align:.*]] = getelementptr inbounds <{ i32, i32, i8*, i32 }>, <{ i32, i32, i8*, i32 }> addrspace(5)* %block, i32 0, i32 1
|
2017-10-05 04:32:17 +08:00
|
|
|
// SPIR: store i32 4, i32* %[[block_align]]
|
2018-10-02 21:02:24 +08:00
|
|
|
// AMDGCN: store i32 8, i32 addrspace(5)* %[[block_align]]
|
|
|
|
// SPIR: %[[block_invoke:.*]] = getelementptr inbounds <{ i32, i32, i8 addrspace(4)*, i32 }>, <{ i32, i32, i8 addrspace(4)*, i32 }>* %[[block:.*]], i32 0, i32 2
|
|
|
|
// 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]]
|
|
|
|
// SPIR: %[[block_captured:.*]] = getelementptr inbounds <{ i32, i32, i8 addrspace(4)*, i32 }>, <{ i32, i32, i8 addrspace(4)*, i32 }>* %[[block]], i32 0, i32 3
|
2018-02-03 00:08:24 +08:00
|
|
|
// SPIR: %[[i_value:.*]] = load i32, i32* %i
|
|
|
|
// SPIR: store i32 %[[i_value]], i32* %[[block_captured]],
|
2019-02-19 23:19:06 +08:00
|
|
|
// SPIR: %[[blk_ptr:.*]] = bitcast <{ i32, i32, i8 addrspace(4)*, i32 }>* %[[block]] to %struct.__opencl_block_literal_generic*
|
|
|
|
// SPIR: %[[blk_gen_ptr:.*]] = addrspacecast %struct.__opencl_block_literal_generic* %[[blk_ptr]] to %struct.__opencl_block_literal_generic addrspace(4)*
|
|
|
|
// SPIR: store %struct.__opencl_block_literal_generic addrspace(4)* %[[blk_gen_ptr]], %struct.__opencl_block_literal_generic addrspace(4)** %[[block_B:.*]],
|
|
|
|
// SPIR: %[[block_literal:.*]] = load %struct.__opencl_block_literal_generic addrspace(4)*, %struct.__opencl_block_literal_generic addrspace(4)** %[[block_B]]
|
2018-10-02 21:02:24 +08:00
|
|
|
// SPIR: %[[blk_gen_ptr:.*]] = bitcast %struct.__opencl_block_literal_generic addrspace(4)* %[[block_literal]] to i8 addrspace(4)*
|
2019-02-21 19:02:10 +08:00
|
|
|
// SPIR: call {{.*}}i32 @__foo_block_invoke(i8 addrspace(4)* %[[blk_gen_ptr]])
|
2018-10-02 21:02:24 +08:00
|
|
|
// AMDGCN: %[[block_invoke:.*]] = getelementptr inbounds <{ i32, i32, i8*, i32 }>, <{ i32, i32, i8*, i32 }> addrspace(5)* %[[block:.*]], i32 0, i32 2
|
|
|
|
// AMDGCN: store i8* bitcast (i32 (i8*)* @__foo_block_invoke to i8*), i8* addrspace(5)* %[[block_invoke]]
|
|
|
|
// AMDGCN: %[[block_captured:.*]] = getelementptr inbounds <{ i32, i32, i8*, i32 }>, <{ i32, i32, i8*, i32 }> addrspace(5)* %[[block]], i32 0, i32 3
|
2018-02-16 03:12:41 +08:00
|
|
|
// AMDGCN: %[[i_value:.*]] = load i32, i32 addrspace(5)* %i
|
|
|
|
// AMDGCN: store i32 %[[i_value]], i32 addrspace(5)* %[[block_captured]],
|
2019-02-19 23:19:06 +08:00
|
|
|
// AMDGCN: %[[blk_ptr:.*]] = bitcast <{ i32, i32, i8*, i32 }> addrspace(5)* %[[block]] to %struct.__opencl_block_literal_generic addrspace(5)*
|
|
|
|
// AMDGCN: %[[blk_gen_ptr:.*]] = addrspacecast %struct.__opencl_block_literal_generic addrspace(5)* %[[blk_ptr]] to %struct.__opencl_block_literal_generic*
|
|
|
|
// AMDGCN: store %struct.__opencl_block_literal_generic* %[[blk_gen_ptr]], %struct.__opencl_block_literal_generic* addrspace(5)* %[[block_B:.*]],
|
|
|
|
// AMDGCN: %[[block_literal:.*]] = load %struct.__opencl_block_literal_generic*, %struct.__opencl_block_literal_generic* addrspace(5)* %[[block_B]]
|
2018-10-02 21:02:24 +08:00
|
|
|
// AMDGCN: %[[blk_gen_ptr:.*]] = bitcast %struct.__opencl_block_literal_generic* %[[block_literal]] to i8*
|
2019-02-21 19:02:10 +08:00
|
|
|
// AMDGCN: call {{.*}}i32 @__foo_block_invoke(i8* %[[blk_gen_ptr]])
|
2017-10-05 04:32:17 +08:00
|
|
|
|
2017-01-27 23:11:34 +08:00
|
|
|
int (^ block_B)(void) = ^{
|
|
|
|
return i;
|
|
|
|
};
|
2017-10-05 04:32:17 +08:00
|
|
|
block_B();
|
2017-01-27 23:11:34 +08:00
|
|
|
}
|
2017-10-05 04:32:17 +08:00
|
|
|
|
2018-02-03 00:08:24 +08:00
|
|
|
// SPIR-LABEL: define internal {{.*}}i32 @__foo_block_invoke(i8 addrspace(4)* %.block_descriptor)
|
2018-10-02 21:02:24 +08:00
|
|
|
// SPIR: %[[block:.*]] = bitcast i8 addrspace(4)* %.block_descriptor to <{ i32, i32, i8 addrspace(4)*, i32 }> addrspace(4)*
|
|
|
|
// 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
|
2018-02-03 00:08:24 +08:00
|
|
|
// SPIR: %[[block_capture:.*]] = load i32, i32 addrspace(4)* %[[block_capture_addr]]
|
2018-02-16 03:12:41 +08:00
|
|
|
// AMDGCN-LABEL: define internal {{.*}}i32 @__foo_block_invoke(i8* %.block_descriptor)
|
2018-10-02 21:02:24 +08:00
|
|
|
// AMDGCN: %[[block:.*]] = bitcast i8* %.block_descriptor to <{ i32, i32, i8*, i32 }>*
|
|
|
|
// AMDGCN: %[[block_capture_addr:.*]] = getelementptr inbounds <{ i32, i32, i8*, i32 }>, <{ i32, i32, i8*, i32 }>* %[[block]], i32 0, i32 3
|
2018-02-16 03:12:41 +08:00
|
|
|
// AMDGCN: %[[block_capture:.*]] = load i32, i32* %[[block_capture_addr]]
|
2017-10-14 20:23:50 +08:00
|
|
|
|
|
|
|
// COMMON-NOT: define{{.*}}@__foo_block_invoke_kernel
|
2018-07-31 04:31:11 +08:00
|
|
|
|
2018-10-02 21:02:27 +08:00
|
|
|
// Test that we support block arguments.
|
|
|
|
// COMMON-LABEL: define {{.*}} @blockArgFunc
|
|
|
|
int blockArgFunc(int (^ bl)(void)) {
|
|
|
|
return bl();
|
|
|
|
}
|
|
|
|
|
|
|
|
// COMMON-LABEL: define {{.*}} @get21
|
|
|
|
// COMMON: define {{.*}} @__get21_block_invoke
|
|
|
|
// COMMON: ret i32 21
|
|
|
|
int get21() {
|
|
|
|
return blockArgFunc(^{return 21;});
|
|
|
|
}
|
|
|
|
|
|
|
|
// COMMON-LABEL: define {{.*}} @get42
|
|
|
|
// COMMON: define {{.*}} @__get42_block_invoke
|
|
|
|
// COMMON: ret i32 42
|
|
|
|
int get42() {
|
|
|
|
return blockArgFunc(^{return 42;});
|
|
|
|
}
|
|
|
|
|
2019-02-27 00:20:41 +08:00
|
|
|
// COMMON-LABEL: define {{.*}}@call_block
|
|
|
|
// call {{.*}}@__call_block_block_invoke
|
|
|
|
int call_block() {
|
|
|
|
return ^int(int num) { return num; } (11);
|
|
|
|
}
|
|
|
|
|
2018-08-08 23:56:12 +08:00
|
|
|
// CHECK-DEBUG: !DIDerivedType(tag: DW_TAG_member, name: "__size"
|
|
|
|
// CHECK-DEBUG: !DIDerivedType(tag: DW_TAG_member, name: "__align"
|
2018-07-31 04:31:11 +08:00
|
|
|
|
2018-08-08 23:56:12 +08:00
|
|
|
// CHECK-DEBUG-NOT: !DIDerivedType(tag: DW_TAG_member, name: "__isa"
|
|
|
|
// CHECK-DEBUG-NOT: !DIDerivedType(tag: DW_TAG_member, name: "__flags"
|
|
|
|
// CHECK-DEBUG-NOT: !DIDerivedType(tag: DW_TAG_member, name: "__reserved"
|
|
|
|
// CHECK-DEBUG-NOT: !DIDerivedType(tag: DW_TAG_member, name: "__FuncPtr"
|