Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / OpenMP / generic_loop_ast_print.cpp
blobdf806405571cf767ef24c8e3d3e8b9fe0573e157
1 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp \
2 // RUN: -fsyntax-only -verify %s
4 // expected-no-diagnostics
6 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp \
7 // RUN: -ast-print %s | FileCheck %s --check-prefix=PRINT
9 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp \
10 // RUN: -ast-dump %s | FileCheck %s --check-prefix=DUMP
12 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp \
13 // RUN: -emit-pch -o %t %s
15 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp \
16 // RUN: -include-pch %t -ast-dump-all %s | FileCheck %s --check-prefix=DUMP
18 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp \
19 // RUN: -include-pch %t -ast-print %s | FileCheck %s --check-prefix=PRINT
21 #ifndef HEADER
22 #define HEADER
24 //PRINT: template <typename T, int C> void templ_foo(T t) {
25 //PRINT: T j, z;
26 //PRINT: #pragma omp simd collapse(C) reduction(+: z) lastprivate(j)
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: OMPSimdDirective
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: ForStmt
42 //DUMP: ForStmt
44 //PRINT: template<> void templ_foo<int, 2>(int t) {
45 //PRINT: int j, z;
46 //PRINT: #pragma omp simd collapse(2) reduction(+: z) lastprivate(j)
47 //PRINT: for (int i = 0; i < t; ++i)
48 //PRINT: for (j = 0; j < t; ++j)
49 //PRINT: z += i + j;
50 //PRINT: }
51 //DUMP: FunctionDecl{{.*}}templ_foo 'void (int)'
52 //DUMP: TemplateArgument type 'int'
53 //DUMP: TemplateArgument integral 2
54 //DUMP: ParmVarDecl{{.*}}'int'
55 //DUMP: OMPSimdDirective
56 //DUMP: OMPCollapseClause
57 //DUMP: ConstantExpr{{.*}}'int'
58 //DUMP: value: Int 2
59 //DUMP: OMPReductionClause
60 //DUMP: DeclRefExpr{{.*}}'z' 'int'
61 //DUMP: OMPLastprivateClause
62 //DUMP: DeclRefExpr{{.*}}'j' 'int'
63 //DUMP: ForStmt
64 template <typename T, int C>
65 void templ_foo(T t) {
67 T j,z;
68 #pragma omp loop collapse(C) reduction(+:z) lastprivate(j) bind(thread)
69 for (T i = 0; i<t; ++i)
70 for (j = 0; j<t; ++j)
71 z += i+j;
75 //PRINT: void test() {
76 //DUMP: FunctionDecl {{.*}}test 'void ()'
77 void test() {
78 constexpr int N = 100;
79 float MTX[N][N];
80 int aaa[1000];
82 //PRINT: #pragma omp target teams distribute parallel for map(tofrom: MTX)
83 //PRINT: #pragma omp simd
84 //DUMP: OMPTargetTeamsDistributeParallelForDirective
85 //DUMP: CapturedStmt
86 //DUMP: ForStmt
87 //DUMP: CompoundStmt
88 //DUMP: OMPSimdDirective
89 #pragma omp target teams distribute parallel for map(MTX)
90 for (auto i = 0; i < N; ++i) {
91 #pragma omp loop
92 for (auto j = 0; j < N; ++j) {
93 MTX[i][j] = 0;
97 //PRINT: #pragma omp target teams
98 //PRINT: #pragma omp distribute
99 //DUMP: OMPTargetTeamsDirective
100 //DUMP: CapturedStmt
101 //DUMP: ForStmt
102 //DUMP: OMPDistributeDirective
103 #pragma omp target teams
104 for (int i=0; i<1000; ++i) {
105 #pragma omp loop
106 for (int j=0; j<100; j++) {
107 aaa[i] += i + j;
111 int j, z, z1;
112 //PRINT: #pragma omp for collapse(2) private(z) lastprivate(j) order(concurrent) reduction(+: z1)
113 //DUMP: OMPForDirective
114 //DUMP: OMPCollapseClause
115 //DUMP: IntegerLiteral{{.*}}2
116 //DUMP: OMPPrivateClause
117 //DUMP-NEXT: DeclRefExpr{{.*}}'z'
118 //DUMP: OMPLastprivateClause
119 //DUMP-NEXT: DeclRefExpr{{.*}}'j'
120 //DUMP: OMPOrderClause
121 //DUMP: OMPReductionClause
122 //DUMP-NEXT: DeclRefExpr{{.*}}'z1'
123 //DUMP: ForStmt
124 //DUMP: ForStmt
125 #pragma omp loop collapse(2) private(z) lastprivate(j) order(concurrent) \
126 reduction(+:z1) bind(parallel)
127 for (auto i = 0; i < N; ++i) {
128 for (j = 0; j < N; ++j) {
129 z = i+j;
130 MTX[i][j] = z;
131 z1 += z;
135 //PRINT: #pragma omp target teams
136 //PRINT: #pragma omp distribute
137 //DUMP: OMPTargetTeamsDirective
138 //DUMP: OMPDistributeDirective
139 //DUMP: ForStmt
140 #pragma omp target teams
141 #pragma omp loop bind(teams)
142 for (auto i = 0; i < N; ++i) { }
144 //PRINT: #pragma omp target
145 //PRINT: #pragma omp teams
146 //PRINT: #pragma omp distribute
147 //DUMP: OMPTargetDirective
148 //DUMP: OMPTeamsDirective
149 //DUMP: OMPDistributeDirective
150 //DUMP: ForStmt
151 #pragma omp target
152 #pragma omp teams
153 #pragma omp loop bind(teams)
154 for (auto i = 0; i < N; ++i) { }
157 void bar()
159 templ_foo<int,2>(8);
162 #endif // HEADER