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