xref: /llvm-project/clang/test/OpenMP/interchange_ast_print.cpp (revision 5b03efb85d63d1f4033ed649a56a177dd4ed62b4)
1 // Check no warnings/errors
2 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -std=c++20 -fopenmp -fopenmp-version=60 -fsyntax-only -verify %s
3 // expected-no-diagnostics
4 
5 // Check AST and unparsing
6 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -std=c++20 -fopenmp -fopenmp-version=60 -ast-dump  %s | FileCheck %s --check-prefix=DUMP
7 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -std=c++20 -fopenmp -fopenmp-version=60 -ast-print %s | FileCheck %s --check-prefix=PRINT
8 
9 // Check same results after serialization round-trip
10 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -std=c++20 -fopenmp -fopenmp-version=60 -emit-pch -o %t %s
11 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -std=c++20 -fopenmp -fopenmp-version=60 -include-pch %t -ast-dump-all %s | FileCheck %s --check-prefix=DUMP
12 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -std=c++20 -fopenmp -fopenmp-version=60 -include-pch %t -ast-print    %s | FileCheck %s --check-prefix=PRINT
13 
14 #ifndef HEADER
15 #define HEADER
16 
17 // placeholder for loop body code.
18 extern "C" void body(...);
19 
20 // PRINT-LABEL: void foo1(
21 // DUMP-LABEL:  FunctionDecl {{.*}} foo1
22 void foo1() {
23   // PRINT: #pragma omp interchange
24   // DUMP:  OMPInterchangeDirective
25   #pragma omp interchange
26   // PRINT: for (int i = 7; i < 17; i += 3)
27   // DUMP-NEXT: ForStmt
28   for (int i = 7; i < 17; i += 3)
29     // PRINT: for (int j = 7; j < 17; j += 3)
30     // DUMP:  ForStmt
31     for (int j = 7; j < 17; j += 3)
32       // PRINT: body(i, j);
33       // DUMP:  CallExpr
34       body(i, j);
35 }
36 
37 
38 // PRINT-LABEL: void foo2(
39 // DUMP-LABEL:  FunctionDecl {{.*}} foo2
40 void foo2(int start1, int start2, int start3, int end1, int end2, int end3) {
41   // PRINT:     #pragma omp interchange permutation(2, 3, 1)
42   // DUMP:      OMPInterchangeDirective
43   // DUMP-NEXT:   OMPPermutationClause
44   // DUMP-NEXT:     ConstantExpr
45   // DUMP-NEXT:       value: Int 2
46   // DUMP-NEXT:       IntegerLiteral {{.*}} 2
47   // DUMP-NEXT:     ConstantExpr
48   // DUMP-NEXT:       value: Int 3
49   // DUMP-NEXT:       IntegerLiteral {{.*}} 3
50   // DUMP-NEXT:     ConstantExpr
51   // DUMP-NEXT:       value: Int 1
52   // DUMP-NEXT:       IntegerLiteral {{.*}} 1
53  #pragma omp interchange permutation(2,3,1)
54   // PRINT: for (int i = start1; i < end1; i += 1)
55   // DUMP-NEXT: ForStmt
56   for (int i = start1; i < end1; i += 1)
57     // PRINT: for (int j = start2; j < end2; j += 1)
58     // DUMP:  ForStmt
59     for (int j = start2; j < end2; j += 1)
60     // PRINT: for (int k = start3; k < end3; k += 1)
61     // DUMP:  ForStmt
62       for (int k = start3; k < end3; k += 1)
63       // PRINT: body(i, j, k);
64       // DUMP:  CallExpr
65       body(i, j, k);
66 }
67 
68 
69 // PRINT-LABEL: void foo3(
70 // DUMP-LABEL:  FunctionDecl {{.*}} foo3
71 void foo3() {
72   // PRINT: #pragma omp for collapse(3)
73   // DUMP:      OMPForDirective
74   // DUMP-NEXT:   OMPCollapseClause
75   // DUMP-NEXT:     ConstantExpr
76   // DUMP-NEXT:       value: Int 3
77   // DUMP-NEXT:     IntegerLiteral {{.*}} 3
78   // DUMP-NEXT:     CapturedStmt
79   // DUMP-NEXT:       CapturedDecl
80   #pragma omp for collapse(3)
81   // PRINT: #pragma omp interchange
82   // DUMP:  OMPInterchangeDirective
83   #pragma omp interchange
84   // PRINT: for (int i = 7; i < 17; i += 1)
85   // DUMP-NEXT: ForStmt
86   for (int i = 7; i < 17; i += 1)
87     // PRINT: for (int j = 7; j < 17; j += 1)
88     // DUMP:  ForStmt
89     for (int j = 7; j < 17; j += 1)
90       // PRINT: for (int k = 7; k < 17; k += 1)
91       // DUMP:  ForStmt
92       for (int k = 7; k < 17; k += 1)
93         // PRINT: body(i, j, k);
94         // DUMP:  CallExpr
95         body(i, j, k);
96 }
97 
98 
99 // PRINT-LABEL: void foo4(
100 // DUMP-LABEL:  FunctionDecl {{.*}} foo4
101 void foo4(int start, int end, int step) {
102   // PRINT: #pragma omp for collapse(3)
103   // DUMP:      OMPForDirective
104   // DUMP-NEXT:   OMPCollapseClause
105   // DUMP-NEXT:    ConstantExpr
106   // DUMP-NEXT:      value: Int 3
107   // DUMP-NEXT:    IntegerLiteral {{.*}} 3
108   // DUMP-NEXT:  CapturedStmt
109   // DUMP-NEXT:    CapturedDecl
110   #pragma omp for collapse(3)
111   // PRINT:     for (int i = 7; i < 17; i += 1)
112   // DUMP-NEXT: ForStmt
113   for (int i = 7; i < 17; i += 1)
114     // PRINT:     #pragma omp interchange permutation(1)
115     // DUMP:      OMPInterchangeDirective
116     // DUMP-NEXT:   OMPPermutationClause
117     // DUMP-NEXT:     ConstantExpr
118     // DUMP-NEXT:       value: Int 1
119     // DUMP-NEXT:       IntegerLiteral {{.*}} 1
120     #pragma omp interchange permutation(1)
121     // PRINT:     for (int j = 7; j < 17; j += 1)
122     // DUMP-NEXT: ForStmt
123     for (int j = 7; j < 17; j += 1)
124       // PRINT: for (int k = 7; k < 17; k += 1)
125       // DUMP:  ForStmt
126       for (int k = 7; k < 17; k += 1)
127         // PRINT: body(i, j, k);
128         // DUMP:  CallExpr
129         body(i, j, k);
130 }
131 
132 
133 // PRINT-LABEL: void foo5(
134 // DUMP-LABEL: FunctionTemplateDecl {{.*}} foo5
135 template<typename T, T P>
136 void foo5(T start, T end) {
137   // PRINT: #pragma omp for
138   // DUMP:  OMPForDirective
139   #pragma omp for
140     // PRINT:     #pragma omp interchange permutation(P + 1, 2 - P)
141     // DUMP:      OMPInterchangeDirective
142     // DUMP-NEXT:   OMPPermutationClause
143     // DUMP-NEXT:     BinaryOperator {{.*}} '+'
144     // DUMP-NEXT:       DeclRefExpr {{.*}} 'P' 'T'
145     // DUMP-NEXT:       IntegerLiteral {{.*}} 'int' 1
146     // DUMP-NEXT:     BinaryOperator {{.*}} '-'
147     // DUMP-NEXT:       IntegerLiteral {{.*}} 'int' 2
148     // DUMP-NEXT:       DeclRefExpr {{.*}} 'P' 'T'
149     #pragma omp interchange permutation(P + 1, 2 - P)
150     // PRINT-NEXT: for (T i = start; i < end; i += 2)
151     // DUMP-NEXT:  ForStmt
152     for (T i = start; i < end; i += 2)
153       // PRINT-NEXT: for (T j = start; j < end; j += 2)
154       // DUMP:       ForStmt
155       for (T j = start; j < end; j += 2)
156         // PRINT-NEXT: body(i, j);
157         // DUMP:       CallExpr
158         body(i,j);
159 }
160 
161 // Also test instantiating the template.
162 void tfoo5() {
163   foo5<int,0>(0, 42);
164   foo5<int,1>(0, 42);
165 }
166 
167 
168 // PRINT-LABEL: void foo6(
169 // DUMP-LABEL: FunctionTemplateDecl {{.*}} foo6
170 template<int Tile>
171 void foo6() {
172     // PRINT:     #pragma omp interchange
173     // DUMP:      OMPInterchangeDirective
174     #pragma omp interchange
175       // PRINT-NEXT: for (int i = 0; i < 11; i += 2)
176       // DUMP-NEXT:  ForStmt
177       for (int i = 0; i < 11; i += 2)
178         // PRINT-NEXT: #pragma omp tile sizes(Tile)
179         // DUMP:       OMPTileDirective
180         #pragma omp tile sizes(Tile)
181         // PRINT-NEXT: for (int j = 0; j < 13; j += 2)
182         // DUMP:       ForStmt
183         for (int j = 0; j < 13; j += 2)
184           // PRINT-NEXT: body(i, j);
185           // DUMP:       CallExpr
186           body(i, j);
187 }
188 
189 // Also test instantiating the template.
190 void tfoo6() {
191   foo6<32>();
192 }
193 
194 
195 // PRINT-LABEL: void foo7(
196 // DUMP-LABEL: FunctionDecl {{.*}} foo7
197 void foo7() {
198   double arr[128];
199   // PRINT: #pragma omp interchange
200   // DUMP:  OMPInterchangeDirective
201   #pragma omp interchange
202   // PRINT-NEXT: for (double c = 42; auto &&v : arr)
203   // DUMP-NEXT:  CXXForRangeStmt
204   for (double c = 42; auto &&v : arr)
205     // PRINT-NEXT: for (int i = 0; i < 42; i += 2)
206     // DUMP:       ForStmt
207     for (int i = 0; i < 42; i += 2)
208       // PRINT-NEXT: body(c, v, i);
209       // DUMP:       CallExpr
210       body(c, v, i);
211 }
212 
213 
214 // PRINT-LABEL: void foo8(
215 // DUMP-LABEL: FunctionDecl {{.*}} foo8
216 void foo8() {
217   double arr[128];
218   // PRINT: #pragma omp interchange
219   // DUMP:  OMPInterchangeDirective
220   #pragma omp interchange
221   // PRINT-NEXT: for (int i = 0; i < 42; i += 2)
222   // DUMP-NEXT:  ForStmt
223   for (int i = 0; i < 42; i += 2)
224     // PRINT-NEXT: for (double c = 42; auto &&v : arr)
225     // DUMP:       CXXForRangeStmt
226     for (double c = 42; auto &&v : arr)
227       // PRINT-NEXT: body(i, c, v);
228       // DUMP:       CallExpr
229       body(i, c, v);
230 }
231 
232 #endif
233 
234