1 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=51 \
2 // RUN: -fsyntax-only -verify %s
3
4 // expected-no-diagnostics
5
6 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=51 \
7 // RUN: -ast-print %s | FileCheck %s --check-prefix=PRINT
8
9 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=51 \
10 // RUN: -ast-dump %s | FileCheck %s --check-prefix=DUMP
11
12 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=51 \
13 // RUN: -emit-pch -o %t %s
14
15 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=51 \
16 // RUN: -include-pch %t -ast-dump-all %s | FileCheck %s --check-prefix=DUMP
17
18 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=51 \
19 // RUN: -include-pch %t -ast-print %s | FileCheck %s --check-prefix=PRINT
20
21 #ifndef HEADER
22 #define HEADER
23
24 //PRINT: template <typename T, int C> void templ_foo(T t) {
25 //PRINT: T j, z;
26 //PRINT: #pragma omp loop collapse(C) reduction(+: z) lastprivate(j) bind(thread)
27 //PRINT: for (T i = 0; i < t; ++i)
28 //PRINT: for (j = 0; j < t; ++j)
29 //PRINT: z += i + j;
30 //PRINT: }
31 //DUMP: FunctionTemplateDecl{{.*}}templ_foo
32 //DUMP: TemplateTypeParmDecl{{.*}}T
33 //DUMP: NonTypeTemplateParmDecl{{.*}}C
34 //DUMP: OMPGenericLoopDirective
35 //DUMP: OMPCollapseClause
36 //DUMP: DeclRefExpr{{.*}}'C' 'int'
37 //DUMP: OMPReductionClause
38 //DUMP: DeclRefExpr{{.*}}'z' 'T'
39 //DUMP: OMPLastprivateClause
40 //DUMP: DeclRefExpr{{.*}}'j' 'T'
41 //DUMP: OMPBindClause
42 //DUMP: ForStmt
43 //DUMP: ForStmt
44
45 //PRINT: template<> void templ_foo<int, 2>(int t) {
46 //PRINT: int j, z;
47 //PRINT: #pragma omp loop collapse(2) reduction(+: z) lastprivate(j) bind(thread)
48 //PRINT: for (int i = 0; i < t; ++i)
49 //PRINT: for (j = 0; j < t; ++j)
50 //PRINT: z += i + j;
51 //PRINT: }
52 //DUMP: FunctionDecl{{.*}}templ_foo 'void (int)'
53 //DUMP: TemplateArgument type 'int'
54 //DUMP: TemplateArgument integral 2
55 //DUMP: ParmVarDecl{{.*}}'int':'int'
56 //DUMP: OMPGenericLoopDirective
57 //DUMP: OMPCollapseClause
58 //DUMP: ConstantExpr{{.*}}'int'
59 //DUMP: value: Int 2
60 //DUMP: OMPReductionClause
61 //DUMP: DeclRefExpr{{.*}}'z' 'int':'int'
62 //DUMP: OMPLastprivateClause
63 //DUMP: DeclRefExpr{{.*}}'j' 'int':'int'
64 //DUMP: OMPBindClause
65 //DUMP: ForStmt
66 template <typename T, int C>
templ_foo(T t)67 void templ_foo(T t) {
68
69 T j,z;
70 #pragma omp loop collapse(C) reduction(+:z) lastprivate(j) bind(thread)
71 for (T i = 0; i<t; ++i)
72 for (j = 0; j<t; ++j)
73 z += i+j;
74 }
75
76
77 //PRINT: void test() {
78 //DUMP: FunctionDecl {{.*}}test 'void ()'
test()79 void test() {
80 constexpr int N = 100;
81 float MTX[N][N];
82 int aaa[1000];
83
84 //PRINT: #pragma omp target teams distribute parallel for map(tofrom: MTX)
85 //PRINT: #pragma omp loop
86 //DUMP: OMPTargetTeamsDistributeParallelForDirective
87 //DUMP: CapturedStmt
88 //DUMP: ForStmt
89 //DUMP: CompoundStmt
90 //DUMP: OMPGenericLoopDirective
91 #pragma omp target teams distribute parallel for map(MTX)
92 for (auto i = 0; i < N; ++i) {
93 #pragma omp loop
94 for (auto j = 0; j < N; ++j) {
95 MTX[i][j] = 0;
96 }
97 }
98
99 //PRINT: #pragma omp target teams
100 //PRINT: #pragma omp loop
101 //DUMP: OMPTargetTeamsDirective
102 //DUMP: CapturedStmt
103 //DUMP: ForStmt
104 //DUMP: OMPGenericLoopDirective
105 #pragma omp target teams
106 for (int i=0; i<1000; ++i) {
107 #pragma omp loop
108 for (int j=0; j<100; j++) {
109 aaa[i] += i + j;
110 }
111 }
112
113 int j, z, z1;
114 //PRINT: #pragma omp loop collapse(2) private(z) lastprivate(j) order(concurrent) reduction(+: z1) bind(parallel)
115 //DUMP: OMPGenericLoopDirective
116 //DUMP: OMPCollapseClause
117 //DUMP: IntegerLiteral{{.*}}2
118 //DUMP: OMPPrivateClause
119 //DUMP-NEXT: DeclRefExpr{{.*}}'z'
120 //DUMP: OMPLastprivateClause
121 //DUMP-NEXT: DeclRefExpr{{.*}}'j'
122 //DUMP: OMPOrderClause
123 //DUMP: OMPReductionClause
124 //DUMP-NEXT: DeclRefExpr{{.*}}'z1'
125 //DUMP: OMPBindClause
126 //DUMP: ForStmt
127 //DUMP: ForStmt
128 #pragma omp loop collapse(2) private(z) lastprivate(j) order(concurrent) \
129 reduction(+:z1) bind(parallel)
130 for (auto i = 0; i < N; ++i) {
131 for (j = 0; j < N; ++j) {
132 z = i+j;
133 MTX[i][j] = z;
134 z1 += z;
135 }
136 }
137
138 //PRINT: #pragma omp target teams
139 //PRINT: #pragma omp loop bind(teams)
140 //DUMP: OMPTargetTeamsDirective
141 //DUMP: OMPGenericLoopDirective
142 //DUMP: OMPBindClause
143 //DUMP: ForStmt
144 #pragma omp target teams
145 #pragma omp loop bind(teams)
146 for (auto i = 0; i < N; ++i) { }
147
148 //PRINT: #pragma omp target
149 //PRINT: #pragma omp teams
150 //PRINT: #pragma omp loop bind(teams)
151 //DUMP: OMPTargetDirective
152 //DUMP: OMPTeamsDirective
153 //DUMP: OMPGenericLoopDirective
154 //DUMP: OMPBindClause
155 //DUMP: ForStmt
156 #pragma omp target
157 #pragma omp teams
158 #pragma omp loop bind(teams)
159 for (auto i = 0; i < N; ++i) { }
160 }
161
162 //PRINT: void nobindingfunc() {
163 //DUMP: FunctionDecl {{.*}}nobindingfunc 'void ()'
nobindingfunc()164 void nobindingfunc()
165 {
166 //PRINT: #pragma omp loop
167 //DUMP: OMPGenericLoopDirective
168 //DUMP: ForStmt
169 #pragma omp loop
170 for (int i=0; i<10; ++i) { }
171 }
172
bar()173 void bar()
174 {
175 templ_foo<int,2>(8);
176 }
177
178 #endif // HEADER
179