Alexey Bataev | b5be1c5 | 2020-04-21 13:21:00 -0400 | [diff] [blame] | 1 | // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=50 -ast-print %s | FileCheck %s |
| 2 | // RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -x c++ -std=c++11 -emit-pch -o %t %s |
| 3 | // RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print | FileCheck %s |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 4 | |
Alexey Bataev | b5be1c5 | 2020-04-21 13:21:00 -0400 | [diff] [blame] | 5 | // RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=50 -ast-print %s | FileCheck %s |
| 6 | // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=50 -x c++ -std=c++11 -emit-pch -o %t %s |
| 7 | // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=50 -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print | FileCheck %s |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 8 | // expected-no-diagnostics |
| 9 | |
| 10 | #ifndef HEADER |
| 11 | #define HEADER |
| 12 | |
Alexey Bataev | b5be1c5 | 2020-04-21 13:21:00 -0400 | [diff] [blame] | 13 | struct omp_alloctrait_t {}; |
| 14 | |
| 15 | typedef void **omp_allocator_handle_t; |
Alexey Bataev | 8026394 | 2020-04-30 13:32:22 -0400 | [diff] [blame] | 16 | extern const omp_allocator_handle_t omp_null_allocator; |
Alexey Bataev | b5be1c5 | 2020-04-21 13:21:00 -0400 | [diff] [blame] | 17 | extern const omp_allocator_handle_t omp_default_mem_alloc; |
| 18 | extern const omp_allocator_handle_t omp_large_cap_mem_alloc; |
| 19 | extern const omp_allocator_handle_t omp_const_mem_alloc; |
| 20 | extern const omp_allocator_handle_t omp_high_bw_mem_alloc; |
| 21 | extern const omp_allocator_handle_t omp_low_lat_mem_alloc; |
| 22 | extern const omp_allocator_handle_t omp_cgroup_mem_alloc; |
| 23 | extern const omp_allocator_handle_t omp_pteam_mem_alloc; |
| 24 | extern const omp_allocator_handle_t omp_thread_mem_alloc; |
| 25 | |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 26 | void foo() {} |
| 27 | |
| 28 | template <class T> |
| 29 | struct S { |
| 30 | operator T() {return T();} |
| 31 | static T TS; |
| 32 | #pragma omp threadprivate(TS) |
| 33 | }; |
| 34 | |
| 35 | // CHECK: template <class T> struct S { |
| 36 | // CHECK: static T TS; |
| 37 | // CHECK-NEXT: #pragma omp threadprivate(S::TS) |
| 38 | // CHECK: }; |
| 39 | // CHECK: template<> struct S<int> { |
| 40 | // CHECK: static int TS; |
| 41 | // CHECK-NEXT: #pragma omp threadprivate(S<int>::TS) |
| 42 | // CHECK-NEXT: } |
| 43 | // CHECK: template<> struct S<long> { |
| 44 | // CHECK: static long TS; |
| 45 | // CHECK-NEXT: #pragma omp threadprivate(S<long>::TS) |
| 46 | // CHECK-NEXT: } |
| 47 | |
| 48 | template <typename T, int C> |
| 49 | T tmain(T argc, T *argv) { |
| 50 | T b = argc, c, d, e, f, g; |
| 51 | static T a; |
| 52 | S<T> s; |
Alexey Bataev | b5be1c5 | 2020-04-21 13:21:00 -0400 | [diff] [blame] | 53 | omp_alloctrait_t traits[10]; |
| 54 | omp_allocator_handle_t my_allocator; |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 55 | #pragma omp target teams |
| 56 | a=2; |
Alexey Bataev | e04483e | 2019-03-27 14:14:31 +0000 | [diff] [blame] | 57 | #pragma omp target teams default(none), private(argc,b) firstprivate(argv) shared (d) reduction(+:c) reduction(max:e) num_teams(C) thread_limit(d*C) allocate(argv) |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 58 | foo(); |
Alexey Bataev | b5be1c5 | 2020-04-21 13:21:00 -0400 | [diff] [blame] | 59 | #pragma omp target teams allocate(my_allocator:f) reduction(^:e, f) reduction(&& : g) uses_allocators(my_allocator(traits)) |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 60 | foo(); |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | // CHECK: template <typename T, int C> T tmain(T argc, T *argv) { |
| 65 | // CHECK-NEXT: T b = argc, c, d, e, f, g; |
| 66 | // CHECK-NEXT: static T a; |
| 67 | // CHECK-NEXT: S<T> s; |
Alexey Bataev | b5be1c5 | 2020-04-21 13:21:00 -0400 | [diff] [blame] | 68 | // CHECK-NEXT: omp_alloctrait_t traits[10]; |
| 69 | // CHECK-NEXT: omp_allocator_handle_t my_allocator; |
Alexey Bataev | cbecfdf | 2018-02-14 17:38:47 +0000 | [diff] [blame] | 70 | // CHECK-NEXT: #pragma omp target teams{{$}} |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 71 | // CHECK-NEXT: a = 2; |
Alexey Bataev | e04483e | 2019-03-27 14:14:31 +0000 | [diff] [blame] | 72 | // CHECK-NEXT: #pragma omp target teams default(none) private(argc,b) firstprivate(argv) shared(d) reduction(+: c) reduction(max: e) num_teams(C) thread_limit(d * C) allocate(argv) |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 73 | // CHECK-NEXT: foo() |
Alexey Bataev | b5be1c5 | 2020-04-21 13:21:00 -0400 | [diff] [blame] | 74 | // CHECK-NEXT: #pragma omp target teams allocate(my_allocator: f) reduction(^: e,f) reduction(&&: g) uses_allocators(my_allocator(traits)) |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 75 | // CHECK-NEXT: foo() |
| 76 | // CHECK: template<> int tmain<int, 5>(int argc, int *argv) { |
| 77 | // CHECK-NEXT: int b = argc, c, d, e, f, g; |
| 78 | // CHECK-NEXT: static int a; |
| 79 | // CHECK-NEXT: S<int> s; |
Alexey Bataev | b5be1c5 | 2020-04-21 13:21:00 -0400 | [diff] [blame] | 80 | // CHECK-NEXT: omp_alloctrait_t traits[10]; |
| 81 | // CHECK-NEXT: omp_allocator_handle_t my_allocator; |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 82 | // CHECK-NEXT: #pragma omp target teams |
| 83 | // CHECK-NEXT: a = 2; |
Alexey Bataev | e04483e | 2019-03-27 14:14:31 +0000 | [diff] [blame] | 84 | // CHECK-NEXT: #pragma omp target teams default(none) private(argc,b) firstprivate(argv) shared(d) reduction(+: c) reduction(max: e) num_teams(5) thread_limit(d * 5) allocate(argv) |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 85 | // CHECK-NEXT: foo() |
Alexey Bataev | b5be1c5 | 2020-04-21 13:21:00 -0400 | [diff] [blame] | 86 | // CHECK-NEXT: #pragma omp target teams allocate(my_allocator: f) reduction(^: e,f) reduction(&&: g) uses_allocators(my_allocator(traits)) |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 87 | // CHECK-NEXT: foo() |
| 88 | // CHECK: template<> long tmain<long, 1>(long argc, long *argv) { |
| 89 | // CHECK-NEXT: long b = argc, c, d, e, f, g; |
| 90 | // CHECK-NEXT: static long a; |
| 91 | // CHECK-NEXT: S<long> s; |
Alexey Bataev | b5be1c5 | 2020-04-21 13:21:00 -0400 | [diff] [blame] | 92 | // CHECK-NEXT: omp_alloctrait_t traits[10]; |
| 93 | // CHECK-NEXT: omp_allocator_handle_t my_allocator; |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 94 | // CHECK-NEXT: #pragma omp target teams |
| 95 | // CHECK-NEXT: a = 2; |
Alexey Bataev | e04483e | 2019-03-27 14:14:31 +0000 | [diff] [blame] | 96 | // CHECK-NEXT: #pragma omp target teams default(none) private(argc,b) firstprivate(argv) shared(d) reduction(+: c) reduction(max: e) num_teams(1) thread_limit(d * 1) allocate(argv) |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 97 | // CHECK-NEXT: foo() |
Alexey Bataev | b5be1c5 | 2020-04-21 13:21:00 -0400 | [diff] [blame] | 98 | // CHECK-NEXT: #pragma omp target teams allocate(my_allocator: f) reduction(^: e,f) reduction(&&: g) uses_allocators(my_allocator(traits)) |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 99 | // CHECK-NEXT: foo() |
| 100 | |
| 101 | enum Enum { }; |
| 102 | |
| 103 | int main (int argc, char **argv) { |
| 104 | long x; |
| 105 | int b = argc, c, d, e, f, g; |
| 106 | static int a; |
| 107 | #pragma omp threadprivate(a) |
| 108 | Enum ee; |
| 109 | // CHECK: Enum ee; |
| 110 | #pragma omp target teams |
| 111 | // CHECK-NEXT: #pragma omp target teams |
| 112 | a=2; |
| 113 | // CHECK-NEXT: a = 2; |
| 114 | #pragma omp target teams default(none), private(argc,b) num_teams(f) firstprivate(argv) reduction(| : c, d) reduction(* : e) thread_limit(f+g) |
| 115 | // CHECK-NEXT: #pragma omp target teams default(none) private(argc,b) num_teams(f) firstprivate(argv) reduction(|: c,d) reduction(*: e) thread_limit(f + g) |
| 116 | foo(); |
| 117 | // CHECK-NEXT: foo(); |
| 118 | return tmain<int, 5>(b, &b) + tmain<long, 1>(x, &x); |
| 119 | } |
| 120 | |
| 121 | extern template int S<int>::TS; |
| 122 | extern template long S<long>::TS; |
| 123 | #endif |