[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / OpenMP / parallel_num_threads_codegen.cpp
blobde10bead4ff8158afd2c43f09e6b96c7666b301e
1 // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple %itanium_abi_triple -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s
2 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple %itanium_abi_triple -fexceptions -fcxx-exceptions -emit-pch -o %t %s
3 // RUN: %clang_cc1 -fopenmp -x c++ -triple %itanium_abi_triple -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
5 // RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -triple %itanium_abi_triple -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck --check-prefix SIMD-ONLY0 %s
6 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -triple %itanium_abi_triple -fexceptions -fcxx-exceptions -emit-pch -o %t %s
7 // RUN: %clang_cc1 -fopenmp-simd -x c++ -triple %itanium_abi_triple -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
8 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
9 // expected-no-diagnostics
10 #ifndef HEADER
11 #define HEADER
13 typedef __INTPTR_TYPE__ intptr_t;
15 // CHECK-DAG: [[IDENT_T_TY:%.+]] = type { i32, i32, i32, i32, ptr }
16 // CHECK-DAG: [[S_TY:%.+]] = type { [[INTPTR_T_TY:i[0-9]+]], [[INTPTR_T_TY]], [[INTPTR_T_TY]] }
17 // CHECK-DAG: [[STR:@.+]] = private unnamed_addr constant [23 x i8] c";unknown;unknown;0;0;;\00"
18 // CHECK-DAG: [[DEF_LOC_2:@.+]] = private unnamed_addr constant [[IDENT_T_TY]] { i32 0, i32 2, i32 0, i32 22, ptr [[STR]] }
20 void foo();
22 struct S {
23 intptr_t a, b, c;
24 S(intptr_t a) : a(a) {}
25 operator char() { extern void mayThrow(); mayThrow(); return a; }
26 ~S() {}
29 template <typename T, int C>
30 int tmain() {
31 #pragma omp parallel num_threads(C)
32 foo();
33 #pragma omp parallel num_threads(T(23))
34 foo();
35 return 0;
38 int main() {
39 S s(0);
40 char a = s;
41 #pragma omp parallel num_threads(2)
42 foo();
43 #pragma omp parallel num_threads(a)
44 foo();
45 return a + tmain<char, 5>() + tmain<S, 1>();
48 // CHECK-LABEL: define {{.*}}i{{[0-9]+}} @main()
49 // CHECK-DAG: [[S_ADDR:%.+]] = alloca [[S_TY]]
50 // CHECK-DAG: [[A_ADDR:%.+]] = alloca i8
51 // CHECK-DAG: [[GTID:%.+]] = call {{.*}}i32 @__kmpc_global_thread_num(ptr [[DEF_LOC_2]])
52 // CHECK-DAG: call {{.*}} [[S_TY_CONSTR:@.+]](ptr {{[^,]*}} [[S_ADDR]], [[INTPTR_T_TY]] noundef [[INTPTR_T_TY_ATTR:(signext )?]]0)
53 // CHECK: [[S_CHAR_OP:%.+]] = invoke{{.*}} i8 [[S_TY_CHAR_OP:@.+]](ptr {{[^,]*}} [[S_ADDR]])
54 // CHECK: store i8 [[S_CHAR_OP]], ptr [[A_ADDR]]
55 // CHECK: call {{.*}}void @__kmpc_push_num_threads(ptr [[DEF_LOC_2]], i32 [[GTID]], i32 2)
56 // CHECK: call {{.*}}void {{.*}} @__kmpc_fork_call(
57 // CHECK: [[A_VAL:%.+]] = load i8, ptr [[A_ADDR]]
58 // CHECK: [[RES:%.+]] = sext i8 [[A_VAL]] to i32
59 // CHECK: call {{.*}}void @__kmpc_push_num_threads(ptr [[DEF_LOC_2]], i32 [[GTID]], i32 [[RES]])
60 // CHECK: call {{.*}}void {{.*}} @__kmpc_fork_call(
61 // CHECK: invoke{{.*}} [[INT_TY:i[0-9]+]] [[TMAIN_CHAR_5:@.+]]()
62 // CHECK: invoke{{.*}} [[INT_TY]] [[TMAIN_S_1:@.+]]()
63 // CHECK: call {{.*}} [[S_TY_DESTR:@.+]](ptr {{[^,]*}} [[S_ADDR]])
64 // CHECK: ret [[INT_TY]]
65 // CHECK: }
67 // CHECK: define{{.*}} [[INT_TY]] [[TMAIN_CHAR_5]]()
68 // CHECK: [[GTID:%.+]] = call {{.*}}i32 @__kmpc_global_thread_num(ptr [[DEF_LOC_2]])
69 // CHECK: call {{.*}}void @__kmpc_push_num_threads(ptr [[DEF_LOC_2]], i32 [[GTID]], i32 5)
70 // CHECK: call {{.*}}void {{.*}} @__kmpc_fork_call(
71 // CHECK: call {{.*}}void @__kmpc_push_num_threads(ptr [[DEF_LOC_2]], i32 [[GTID]], i32 23)
72 // CHECK: call {{.*}}void {{.*}} @__kmpc_fork_call(
73 // CHECK: ret [[INT_TY]] 0
74 // CHECK-NEXT: }
76 // CHECK: define{{.*}} [[INT_TY]] [[TMAIN_S_1]]()
77 // CHECK: [[GTID:%.+]] = call {{.*}}i32 @__kmpc_global_thread_num(ptr [[DEF_LOC_2]])
78 // CHECK: call {{.*}}void @__kmpc_push_num_threads(ptr [[DEF_LOC_2]], i32 [[GTID]], i32 1)
79 // CHECK: call {{.*}}void {{.*}} @__kmpc_fork_call(
80 // CHECK: {{(invoke|call)}} {{.*}} [[S_TY_CONSTR]](ptr {{[^,]*}} [[S_TEMP:%.+]], [[INTPTR_T_TY]] noundef [[INTPTR_T_TY_ATTR]]23)
81 // CHECK: [[S_CHAR_OP:%.+]] = invoke{{.*}} i8 [[S_TY_CHAR_OP]](ptr {{[^,]*}} [[S_TEMP]])
82 // CHECK: [[RES:%.+]] = sext {{.*}}i8 [[S_CHAR_OP]] to i32
83 // CHECK: call {{.*}}void @__kmpc_push_num_threads(ptr [[DEF_LOC_2]], i32 [[GTID]], i32 [[RES]])
84 // CHECK: {{(invoke|call)}} {{.*}} [[S_TY_DESTR]](ptr {{[^,]*}} [[S_TEMP]])
85 // CHECK: call {{.*}}void {{.*}} @__kmpc_fork_call(
86 // CHECK: ret [[INT_TY]] 0
87 // CHECK: }
89 #endif