Clang Project

clang_source_code/test/OpenMP/parallel_num_threads_codegen.cpp
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
4
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
12
13typedef __INTPTR_TYPE__ intptr_t;
14
15// CHECK-DAG: [[IDENT_T_TY:%.+]] = type { i32, i32, i32, i32, i8* }
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 global [[IDENT_T_TY]] { i32 0, i32 2, i32 0, i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* [[STR]], i32 0, i32 0) }
19
20void foo();
21
22struct S {
23  intptr_t a, b, c;
24  S(intptr_t a) : a(a) {}
25  operator char() { return a; }
26  ~S() {}
27};
28
29template <typename T, int C>
30int tmain() {
31#pragma omp parallel num_threads(C)
32  foo();
33#pragma omp parallel num_threads(T(23))
34  foo();
35  return 0;
36}
37
38int 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>();
46}
47
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([[IDENT_T_TY]]* [[DEF_LOC_2]])
52// CHECK-DAG:   call {{.*}} [[S_TY_CONSTR:@.+]]([[S_TY]]* [[S_ADDR]], [[INTPTR_T_TY]] [[INTPTR_T_TY_ATTR:(signext )?]]0)
53// CHECK:       [[S_CHAR_OP:%.+]] = invoke{{.*}} i8 [[S_TY_CHAR_OP:@.+]]([[S_TY]]* [[S_ADDR]])
54// CHECK:       store i8 [[S_CHAR_OP]], i8* [[A_ADDR]]
55// CHECK:       call {{.*}}void @__kmpc_push_num_threads([[IDENT_T_TY]]* [[DEF_LOC_2]], i32 [[GTID]], i32 2)
56// CHECK:       call {{.*}}void {{.*}} @__kmpc_fork_call(
57// CHECK:       [[A_VAL:%.+]] = load i8, i8* [[A_ADDR]]
58// CHECK:       [[RES:%.+]] = sext i8 [[A_VAL]] to i32
59// CHECK:       call {{.*}}void @__kmpc_push_num_threads([[IDENT_T_TY]]* [[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:@.+]]([[S_TY]]* [[S_ADDR]])
64// CHECK:       ret [[INT_TY]]
65// CHECK:       }
66
67// CHECK:       define{{.*}} [[INT_TY]] [[TMAIN_CHAR_5]]()
68// CHECK:       [[GTID:%.+]] = call {{.*}}i32 @__kmpc_global_thread_num([[IDENT_T_TY]]* [[DEF_LOC_2]])
69// CHECK:       call {{.*}}void @__kmpc_push_num_threads([[IDENT_T_TY]]* [[DEF_LOC_2]], i32 [[GTID]], i32 5)
70// CHECK:       call {{.*}}void {{.*}} @__kmpc_fork_call(
71// CHECK:       call {{.*}}void @__kmpc_push_num_threads([[IDENT_T_TY]]* [[DEF_LOC_2]], i32 [[GTID]], i32 23)
72// CHECK:       call {{.*}}void {{.*}} @__kmpc_fork_call(
73// CHECK:       ret [[INT_TY]] 0
74// CHECK-NEXT:  }
75
76// CHECK:       define{{.*}} [[INT_TY]] [[TMAIN_S_1]]()
77// CHECK:       [[GTID:%.+]] = call {{.*}}i32 @__kmpc_global_thread_num([[IDENT_T_TY]]* [[DEF_LOC_2]])
78// CHECK:       call {{.*}}void @__kmpc_push_num_threads([[IDENT_T_TY]]* [[DEF_LOC_2]], i32 [[GTID]], i32 1)
79// CHECK:       call {{.*}}void {{.*}} @__kmpc_fork_call(
80// CHECK:       {{(invoke|call)}} {{.*}} [[S_TY_CONSTR]]([[S_TY]]* [[S_TEMP:%.+]], [[INTPTR_T_TY]] [[INTPTR_T_TY_ATTR]]23)
81// CHECK:       [[S_CHAR_OP:%.+]] = invoke{{.*}} i8 [[S_TY_CHAR_OP]]([[S_TY]]* [[S_TEMP]])
82// CHECK:       [[RES:%.+]] = sext {{.*}}i8 [[S_CHAR_OP]] to i32
83// CHECK:       call {{.*}}void @__kmpc_push_num_threads([[IDENT_T_TY]]* [[DEF_LOC_2]], i32 [[GTID]], i32 [[RES]])
84// CHECK:       {{(invoke|call)}} {{.*}} [[S_TY_DESTR]]([[S_TY]]* [[S_TEMP]])
85// CHECK:       call {{.*}}void {{.*}} @__kmpc_fork_call(
86// CHECK:       ret [[INT_TY]] 0
87// CHECK:       }
88
89#endif
90