[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / OpenMP / ordered_doacross_codegen.c
blob2976b8ec4816e0ec8ed7034e24f61e913eb43adb
1 // RUN: %clang_cc1 -verify -fopenmp -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-NORMAL
2 // RUN: %clang_cc1 -fopenmp -triple x86_64-unknown-unknown -emit-pch -o %t %s
3 // RUN: %clang_cc1 -fopenmp -triple x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-NORMAL
5 // RUN: %clang_cc1 -verify -fopenmp -triple x86_64-unknown-unknown -emit-llvm %s -o - -fopenmp-version=52 -DOMP52 | FileCheck %s --check-prefixes=CHECK,CHECK-NORMAL
6 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-IRBUILDER
7 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -fopenmp-version=52 -DOMP52 -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-IRBUILDER
8 // RUN: %clang_cc1 -fopenmp -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -emit-pch -o %t %s
9 // RUN: %clang_cc1 -fopenmp -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-IRBUILDER
11 // RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -DOMP52 -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -emit-pch -o %t %s
12 // RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -DOMP52 -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-IRBUILDER
14 // RUN: %clang_cc1 -verify -fopenmp-simd -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
15 // RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=52 -DOMP52 -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
16 // RUN: %clang_cc1 -fopenmp-simd -triple x86_64-unknown-unknown -emit-pch -o %t %s
17 // RUN: %clang_cc1 -fopenmp-simd -triple x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
18 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=52 -DOMP52 -triple x86_64-unknown-unknown -emit-pch -o %t %s
19 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=52 -DOMP52 -triple x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
20 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
21 // expected-no-diagnostics
23 #ifndef HEADER
24 #define HEADER
26 // CHECK: [[KMP_DIM:%.+]] = type { i64, i64, i64 }
27 extern int n;
28 int a[10], b[10], c[10], d[10];
29 void foo(void);
31 // CHECK-LABEL: @main()
32 int main(void) {
33 int i;
34 // CHECK: [[DIMS:%.+]] = alloca [1 x [[KMP_DIM]]],
35 // CHECK-NORMAL: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num(ptr [[IDENT:@.+]])
36 // CHECK: icmp
37 // CHECK-NEXT: br i1 %
38 // CHECK: call void @llvm.memset.p0.i64(ptr align 8 [[DIMS]], i8 0, i64 24, i1 false)
39 // CHECK: [[DIM:%.+]] = getelementptr inbounds [1 x [[KMP_DIM]]], ptr [[DIMS]], i64 0, i64 0
40 // CHECK: getelementptr inbounds nuw [[KMP_DIM]], ptr [[DIM]], i32 0, i32 1
41 // CHECK: store i64 %{{.+}}, ptr %
42 // CHECK: getelementptr inbounds nuw [[KMP_DIM]], ptr [[DIM]], i32 0, i32 2
43 // CHECK: store i64 1, ptr %
44 // CHECK: [[DIM:%.+]] = getelementptr inbounds [1 x [[KMP_DIM]]], ptr [[DIMS]], i64 0, i64 0
45 // CHECK-NORMAL: call void @__kmpc_doacross_init(ptr [[IDENT]], i32 [[GTID]], i32 1, ptr [[DIM]])
46 // CHECK-NORMAL: call void @__kmpc_for_static_init_4(ptr @{{.+}}, i32 [[GTID]], i32 33, ptr %{{.+}}, ptr %{{.+}}, ptr %{{.+}}, ptr %{{.+}}, i32 1, i32 1)
47 #pragma omp for ordered(1)
48 for (i = 0; i < n; ++i) {
49 a[i] = b[i] + 1;
50 foo();
51 // CHECK: call void @foo()
52 // CHECK: load i32, ptr [[I:%.+]],
53 // CHECK-NEXT: sub nsw i32 %{{.+}}, 0
54 // CHECK-NEXT: sdiv i32 %{{.+}}, 1
55 // CHECK-NEXT: sext i32 %{{.+}} to i64
56 // CHECK-NEXT: [[TMP:%.+]] = getelementptr inbounds [1 x i64], ptr [[CNT:%.+]], i64 0, i64 0
57 // CHECK-NEXT: store i64 %{{.+}}, ptr [[TMP]],
58 // CHECK-NEXT: [[TMP:%.+]] = getelementptr inbounds [1 x i64], ptr [[CNT]], i64 0, i64 0
59 // CHECK-NORMAL-NEXT: call void @__kmpc_doacross_post(ptr [[IDENT]], i32 [[GTID]], ptr [[TMP]])
60 // CHECK-IRBUILDER-NEXT: [[GTID1:%.+]] = call i32 @__kmpc_global_thread_num(ptr [[IDENT:@.+]])
61 // CHECK-IRBUILDER-NEXT: call void @__kmpc_doacross_post(ptr [[IDENT]], i32 [[GTID1]], ptr [[TMP]])
62 #ifdef OMP52
63 #pragma omp ordered doacross(source:)
64 #else
65 #pragma omp ordered depend(source)
66 #endif
67 c[i] = c[i] + 1;
68 foo();
69 // CHECK: call void @foo()
70 // CHECK: load i32, ptr [[I]],
71 // CHECK-NEXT: sub nsw i32 %{{.+}}, 2
72 // CHECK-NEXT: sub nsw i32 %{{.+}}, 0
73 // CHECK-NEXT: sdiv i32 %{{.+}}, 1
74 // CHECK-NEXT: sext i32 %{{.+}} to i64
75 // CHECK-NEXT: [[TMP:%.+]] = getelementptr inbounds [1 x i64], ptr [[CNT:%.+]], i64 0, i64 0
76 // CHECK-NEXT: store i64 %{{.+}}, ptr [[TMP]],
77 // CHECK-NEXT: [[TMP:%.+]] = getelementptr inbounds [1 x i64], ptr [[CNT]], i64 0, i64 0
78 // CHECK-NORMAL-NEXT: call void @__kmpc_doacross_wait(ptr [[IDENT]], i32 [[GTID]], ptr [[TMP]])
79 // CHECK-IRBUILDER-NEXT: [[GTID2:%.+]] = call i32 @__kmpc_global_thread_num(ptr [[IDENT:@.+]])
80 // CHECK-IRBUILDER-NEXT: call void @__kmpc_doacross_wait(ptr [[IDENT]], i32 [[GTID2]], ptr [[TMP]])
81 #ifdef OMP52
82 #pragma omp ordered doacross(sink : i - 2)
83 #else
84 #pragma omp ordered depend(sink : i - 2)
85 #endif
86 d[i] = a[i - 2];
87 foo();
88 // CHECK: call void @foo()
89 // CHECK: load i32, ptr [[I]],
90 // CHECK-NEXT: sub nsw i32 %{{.+}}, 1
91 // CHECK-NEXT: sub nsw i32 %{{.+}}, 0
92 // CHECK-NEXT: sdiv i32 %{{.+}}, 1
93 // CHECK-NEXT: sext i32 %{{.+}} to i64
94 // CHECK-NEXT: [[TMP:%.+]] = getelementptr inbounds [1 x i64], ptr [[CNT:%.+]], i64 0, i64 0
95 // CHECK-NEXT: store i64 %{{.+}}, ptr [[TMP]],
96 // CHECK-NEXT: [[TMP:%.+]] = getelementptr inbounds [1 x i64], ptr [[CNT]], i64 0, i64 0
97 // CHECK-NORMAL-NEXT: call void @__kmpc_doacross_wait(ptr [[IDENT]], i32 [[GTID]], ptr [[TMP]])
98 // CHECK-IRBUILDER-NEXT: [[GTID2:%.+]] = call i32 @__kmpc_global_thread_num(ptr [[IDENT:@.+]])
99 // CHECK-IRBUILDER-NEXT: call void @__kmpc_doacross_wait(ptr [[IDENT]], i32 [[GTID2]], ptr [[TMP]])
100 #ifdef OMP52
101 #pragma omp ordered doacross(sink :omp_cur_iteration - 1)
102 #else
103 #pragma omp ordered depend(sink : i - 1)
104 #endif
105 d[i] = a[i - 1];
106 foo();
107 // CHECK: call void @foo()
108 // CHECK: load i32, ptr [[I:%.+]],
109 // CHECK-NEXT: sub nsw i32 %{{.+}}, 0
110 // CHECK-NEXT: sdiv i32 %{{.+}}, 1
111 // CHECK-NEXT: sext i32 %{{.+}} to i64
112 // CHECK-NEXT: [[TMP:%.+]] = getelementptr inbounds [1 x i64], ptr [[CNT:%.+]], i64 0, i64 0
113 // CHECK-NEXT: store i64 %{{.+}}, ptr [[TMP]],
114 // CHECK-NEXT: [[TMP:%.+]] = getelementptr inbounds [1 x i64], ptr [[CNT]], i64 0, i64 0
115 // CHECK-NORMAL-NEXT: call void @__kmpc_doacross_post(ptr [[IDENT]], i32 [[GTID]], ptr [[TMP]])
116 // CHECK-IRBUILDER-NEXT: [[GTID1:%.+]] = call i32 @__kmpc_global_thread_num(ptr [[IDENT:@.+]])
117 // CHECK-IRBUILDER-NEXT: call void @__kmpc_doacross_post(ptr [[IDENT]], i32 [[GTID1]], ptr [[TMP]])
118 #ifdef OMP52
119 #pragma omp ordered doacross(source:omp_cur_iteration)
120 #else
121 #pragma omp ordered depend(source)
122 #endif
123 c[i] = c[i] + 1;
125 // CHECK: call void @__kmpc_for_static_fini(
126 // CHECK-NORMAL: call void @__kmpc_doacross_fini(ptr [[IDENT]], i32 [[GTID]])
127 // CHECK: ret i32 0
128 return 0;
130 #endif // HEADER