Clang Project

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