Alexey Bataev | f07946e | 2018-10-29 20:17:42 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -verify -fopenmp -ast-print %s -Wno-openmp-target | FileCheck %s |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2 | // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -emit-pch -o %t %s |
Alexey Bataev | f07946e | 2018-10-29 20:17:42 +0000 | [diff] [blame] | 3 | // RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print -Wno-openmp-target | FileCheck %s |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 4 | |
Alexey Bataev | f07946e | 2018-10-29 20:17:42 +0000 | [diff] [blame] | 5 | // RUN: %clang_cc1 -verify -fopenmp-simd -ast-print %s -Wno-openmp-target | FileCheck %s |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 6 | // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -emit-pch -o %t %s |
Alexey Bataev | f07946e | 2018-10-29 20:17:42 +0000 | [diff] [blame] | 7 | // RUN: %clang_cc1 -fopenmp-simd -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print -Wno-openmp-target | FileCheck %s |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 8 | // expected-no-diagnostics |
| 9 | |
| 10 | #ifndef HEADER |
| 11 | #define HEADER |
| 12 | |
| 13 | struct S { |
| 14 | S(): a(0) {} |
| 15 | S(int v) : a(v) {} |
| 16 | int a; |
| 17 | typedef int type; |
| 18 | }; |
| 19 | |
| 20 | template <typename T> |
| 21 | class S7 : public T { |
| 22 | protected: |
| 23 | T a; |
| 24 | S7() : a(0) {} |
| 25 | |
| 26 | public: |
| 27 | S7(typename T::type v) : a(v) { |
| 28 | #pragma omp target |
| 29 | #pragma omp teams |
Alexey Bataev | e04483e | 2019-03-27 14:14:31 +0000 | [diff] [blame] | 30 | #pragma omp distribute simd private(a) private(this->a) private(T::a) allocate(T::a) |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 31 | for (int k = 0; k < a.a; ++k) |
| 32 | ++this->a.a; |
| 33 | } |
| 34 | S7 &operator=(S7 &s) { |
| 35 | #pragma omp target |
| 36 | #pragma omp teams |
Alexey Bataev | e04483e | 2019-03-27 14:14:31 +0000 | [diff] [blame] | 37 | #pragma omp distribute simd allocate(a) private(a) private(this->a) |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 38 | for (int k = 0; k < s.a.a; ++k) |
| 39 | ++s.a.a; |
| 40 | return *this; |
| 41 | } |
| 42 | }; |
| 43 | |
Alexey Bataev | e04483e | 2019-03-27 14:14:31 +0000 | [diff] [blame] | 44 | // CHECK: #pragma omp distribute simd private(this->a) private(this->a) private(T::a) allocate(T::a){{$}} |
| 45 | // CHECK: #pragma omp distribute simd allocate(this->a) private(this->a) private(this->a) |
| 46 | // CHECK: #pragma omp distribute simd private(this->a) private(this->a) private(this->S::a) allocate(this->S::a) |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 47 | |
| 48 | class S8 : public S7<S> { |
| 49 | S8() {} |
| 50 | |
| 51 | public: |
| 52 | S8(int v) : S7<S>(v){ |
| 53 | #pragma omp target |
| 54 | #pragma omp teams |
| 55 | #pragma omp distribute simd private(a) private(this->a) private(S7<S>::a) |
| 56 | for (int k = 0; k < a.a; ++k) |
| 57 | ++this->a.a; |
| 58 | } |
| 59 | S8 &operator=(S8 &s) { |
| 60 | #pragma omp target |
| 61 | #pragma omp teams |
| 62 | #pragma omp distribute simd private(a) private(this->a) |
| 63 | for (int k = 0; k < s.a.a; ++k) |
| 64 | ++s.a.a; |
| 65 | return *this; |
| 66 | } |
| 67 | }; |
| 68 | |
| 69 | // CHECK: #pragma omp distribute simd private(this->a) private(this->a) private(this->S7<S>::a) |
| 70 | // CHECK: #pragma omp distribute simd private(this->a) private(this->a) |
| 71 | |
| 72 | template <class T, int N> |
| 73 | T tmain(T argc) { |
| 74 | T b = argc, c, d, e, f, h; |
| 75 | static T a; |
| 76 | // CHECK: static T a; |
| 77 | static T g; |
| 78 | #pragma omp threadprivate(g) |
| 79 | |
| 80 | #pragma omp target |
| 81 | #pragma omp teams |
| 82 | #pragma omp distribute simd dist_schedule(static, a) firstprivate(a) |
| 83 | for (int i = 0; i < 2; ++i) |
| 84 | a = 2; |
| 85 | // CHECK: #pragma omp distribute simd dist_schedule(static, a) firstprivate(a) |
| 86 | // CHECK-NEXT: for (int i = 0; i < 2; ++i) |
| 87 | // CHECK-NEXT: a = 2; |
| 88 | |
| 89 | #pragma omp target |
| 90 | #pragma omp teams |
Alexey Bataev | b358f99 | 2017-12-01 17:40:15 +0000 | [diff] [blame] | 91 | #pragma omp distribute simd private(argc, b), firstprivate(c, d), lastprivate(f) collapse(N) reduction(+ : h) dist_schedule(static,N) |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 92 | for (int i = 0; i < 2; ++i) |
| 93 | for (int j = 0; j < 2; ++j) |
| 94 | for (int k = 0; k < 10; ++k) |
| 95 | for (int m = 0; m < 10; ++m) |
| 96 | for (int n = 0; n < 10; ++n) |
| 97 | a++; |
Alexey Bataev | b358f99 | 2017-12-01 17:40:15 +0000 | [diff] [blame] | 98 | // CHECK: #pragma omp distribute simd private(argc,b) firstprivate(c,d) lastprivate(f) collapse(N) reduction(+: h) dist_schedule(static, N) |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 99 | // CHECK-NEXT: for (int i = 0; i < 2; ++i) |
| 100 | // CHECK-NEXT: for (int j = 0; j < 2; ++j) |
| 101 | // CHECK-NEXT: for (int k = 0; k < 10; ++k) |
| 102 | // CHECK-NEXT: for (int m = 0; m < 10; ++m) |
| 103 | // CHECK-NEXT: for (int n = 0; n < 10; ++n) |
| 104 | // CHECK-NEXT: a++; |
| 105 | return T(); |
| 106 | } |
| 107 | |
| 108 | int main(int argc, char **argv) { |
| 109 | int b = argc, c, d, e, f, h; |
| 110 | int x[200]; |
| 111 | static int a; |
| 112 | // CHECK: static int a; |
| 113 | static float g; |
| 114 | #pragma omp threadprivate(g) |
| 115 | |
| 116 | #pragma omp target |
| 117 | #pragma omp teams |
| 118 | #pragma omp distribute simd dist_schedule(static, a) private(a) |
| 119 | for (int i = 0; i < 2; ++i) |
| 120 | a = 2; |
| 121 | // CHECK: #pragma omp distribute simd dist_schedule(static, a) private(a) |
| 122 | // CHECK-NEXT: for (int i = 0; i < 2; ++i) |
| 123 | // CHECK-NEXT: a = 2; |
| 124 | |
| 125 | #pragma omp target |
| 126 | #pragma omp teams |
| 127 | #pragma omp distribute simd private(argc, b), firstprivate(argv, c), lastprivate(d, f) collapse(2) reduction(+ : h) dist_schedule(static, b) |
| 128 | for (int i = 0; i < 10; ++i) |
| 129 | for (int j = 0; j < 10; ++j) |
| 130 | a++; |
| 131 | // CHECK: #pragma omp distribute simd private(argc,b) firstprivate(argv,c) lastprivate(d,f) collapse(2) reduction(+: h) dist_schedule(static, b) |
| 132 | // CHECK-NEXT: for (int i = 0; i < 10; ++i) |
| 133 | // CHECK-NEXT: for (int j = 0; j < 10; ++j) |
| 134 | // CHECK-NEXT: a++; |
| 135 | |
Alexey Bataev | 2b86f21 | 2017-11-29 21:31:48 +0000 | [diff] [blame] | 136 | int i; |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 137 | #pragma omp target |
| 138 | #pragma omp teams |
Alexey Bataev | 2b86f21 | 2017-11-29 21:31:48 +0000 | [diff] [blame] | 139 | #pragma omp distribute simd aligned(x:8) linear(i:2) safelen(8) simdlen(8) |
| 140 | for (i = 0; i < 100; i++) |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 141 | for (int j = 0; j < 200; j++) |
| 142 | a += h + x[j]; |
Alexey Bataev | 2b86f21 | 2017-11-29 21:31:48 +0000 | [diff] [blame] | 143 | // CHECK: #pragma omp distribute simd aligned(x: 8) linear(i: 2) safelen(8) simdlen(8) |
| 144 | // CHECK-NEXT: for (i = 0; i < 100; i++) |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 145 | // CHECK-NEXT: for (int j = 0; j < 200; j++) |
| 146 | // CHECK-NEXT: a += h + x[j]; |
| 147 | |
| 148 | return (tmain<int, 5>(argc) + tmain<char, 1>(argv[0][0])); |
| 149 | } |
| 150 | |
| 151 | #endif |