204 lines · cpp
1// Check no warnings/errors2// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fsyntax-only -verify %s3// expected-no-diagnostics4 5// Check AST and unparsing6// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -ast-dump %s | FileCheck %s --check-prefix=DUMP7// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -ast-print %s | FileCheck %s --check-prefix=PRINT8 9// Check same results after serialization round-trip10// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -emit-pch -o %t %s11// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -include-pch %t -ast-dump-all %s | FileCheck %s --check-prefix=DUMP12// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -include-pch %t -ast-print %s | FileCheck %s --check-prefix=PRINT13 14#ifndef HEADER15#define HEADER16 17// placeholder for loop body code.18extern "C" void body(...);19 20 21// PRINT-LABEL: void foo1(22// DUMP-LABEL: FunctionDecl {{.*}} foo123void foo1() {24 // PRINT: #pragma omp tile sizes(5, 5)25 // DUMP: OMPTileDirective26 // DUMP-NEXT: OMPSizesClause27 // DUMP-NEXT: IntegerLiteral {{.*}} 528 // DUMP-NEXT: IntegerLiteral {{.*}} 529 #pragma omp tile sizes(5,5)30 // PRINT: for (int i = 7; i < 17; i += 3)31 // DUMP-NEXT: ForStmt32 for (int i = 7; i < 17; i += 3)33 // PRINT: for (int j = 7; j < 17; j += 3)34 // DUMP: ForStmt35 for (int j = 7; j < 17; j += 3)36 // PRINT: body(i, j);37 // DUMP: CallExpr38 body(i, j);39}40 41 42// PRINT-LABEL: void foo2(43// DUMP-LABEL: FunctionDecl {{.*}} foo244void foo2(int start1, int start2, int end1, int end2) {45 // PRINT: #pragma omp tile sizes(5, 5)46 // DUMP: OMPTileDirective47 // DUMP-NEXT: OMPSizesClause48 // DUMP-NEXT: IntegerLiteral {{.*}} 549 // DUMP-NEXT: IntegerLiteral {{.*}} 550 #pragma omp tile sizes(5,5)51 // PRINT: for (int i = start1; i < end1; i += 1)52 // DUMP-NEXT: ForStmt53 for (int i = start1; i < end1; i += 1)54 // PRINT: for (int j = start2; j < end2; j += 1)55 // DUMP: ForStmt56 for (int j = start2; j < end2; j += 1)57 // PRINT: body(i, j);58 // DUMP: CallExpr59 body(i, j);60}61 62 63// PRINT-LABEL: void foo3(64// DUMP-LABEL: FunctionDecl {{.*}} foo365void foo3() {66 // PRINT: #pragma omp for67 // DUMP: OMPForDirective68 // DUMP-NEXT: CapturedStmt69 // DUMP-NEXT: CapturedDecl70 #pragma omp for71 // PRINT: #pragma omp tile sizes(5)72 // DUMP-NEXT: OMPTileDirective73 // DUMP-NEXT: OMPSizesClause74 // DUMP-NEXT: IntegerLiteral {{.*}} 575 #pragma omp tile sizes(5)76 for (int i = 7; i < 17; i += 3)77 // PRINT: body(i);78 // DUMP: CallExpr79 body(i);80}81 82 83// PRINT-LABEL: void foo4(84// DUMP-LABEL: FunctionDecl {{.*}} foo485void foo4() {86 // PRINT: #pragma omp for collapse(3)87 // DUMP: OMPForDirective88 // DUMP-NEXT: OMPCollapseClause89 // DUMP-NEXT: ConstantExpr90 // DUMP-NEXT: value: Int 391 // DUMP-NEXT: IntegerLiteral {{.*}} 392 // DUMP-NEXT: CapturedStmt93 // DUMP-NEXT: CapturedDecl94 #pragma omp for collapse(3)95 // PRINT: #pragma omp tile sizes(5, 5)96 // DUMP: OMPTileDirective97 // DUMP-NEXT: OMPSizesClause98 // DUMP-NEXT: IntegerLiteral {{.*}} 599 // DUMP-NEXT: IntegerLiteral {{.*}} 5100 #pragma omp tile sizes(5, 5)101 // PRINT: for (int i = 7; i < 17; i += 1)102 // DUMP-NEXT: ForStmt103 for (int i = 7; i < 17; i += 1)104 // PRINT: for (int j = 7; j < 17; j += 1)105 // DUMP: ForStmt106 for (int j = 7; j < 17; j += 1)107 // PRINT: body(i, j);108 // DUMP: CallExpr109 body(i, j);110}111 112 113// PRINT-LABEL: void foo5(114// DUMP-LABEL: FunctionDecl {{.*}} foo5115void foo5(int start, int end, int step) {116 // PRINT: #pragma omp for collapse(2)117 // DUMP: OMPForDirective118 // DUMP-NEXT: OMPCollapseClause119 // DUMP-NEXT: ConstantExpr120 // DUMP-NEXT: value: Int 2121 // DUMP-NEXT: IntegerLiteral {{.*}} 2122 // DUMP-NEXT: CapturedStmt123 // DUMP-NEXT: CapturedDecl124 #pragma omp for collapse(2)125 // PRINT: for (int i = 7; i < 17; i += 1)126 // DUMP-NEXT: ForStmt127 for (int i = 7; i < 17; i += 1)128 // PRINT: #pragma omp tile sizes(5)129 // DUMP: OMPTileDirective130 // DUMP-NEXT: OMPSizesClause131 // DUMP-NEXT: IntegerLiteral {{.*}} 5132 #pragma omp tile sizes(5)133 // PRINT: for (int j = 7; j < 17; j += 1)134 // DUMP-NEXT: ForStmt135 for (int j = 7; j < 17; j += 1)136 // PRINT: body(i, j);137 // DUMP: CallExpr138 body(i, j);139}140 141 142// PRINT-LABEL: void foo6(143// DUMP-LABEL: FunctionTemplateDecl {{.*}} foo6144template<typename T, T Step, T Tile>145void foo6(T start, T end) {146 // PRINT: #pragma omp tile sizes(Tile)147 // DUMP: OMPTileDirective148 // DUMP-NEXT: OMPSizesClause149 // DUMP-NEXT: DeclRefExpr {{.*}} 'Tile' 'T'150 #pragma omp tile sizes(Tile)151 // PRINT-NEXT: for (T i = start; i < end; i += Step)152 // DUMP-NEXT: ForStmt153 for (T i = start; i < end; i += Step)154 // PRINT-NEXT: body(i);155 // DUMP: CallExpr156 body(i);157}158 159// Also test instantiating the template.160void tfoo6() {161 foo6<int,3,5>(0, 42);162}163 164 165// PRINT-LABEL: template <int Tile> void foo7(int start, int stop, int step) {166// DUMP-LABEL: FunctionTemplateDecl {{.*}} foo7167template <int Tile>168void foo7(int start, int stop, int step) {169 // PRINT: #pragma omp tile sizes(Tile)170 // DUMP: OMPTileDirective171 // DUMP-NEXT: OMPSizesClause172 // DUMP-NEXT: DeclRefExpr {{.*}} 'Tile' 'int'173 #pragma omp tile sizes(Tile)174 // PRINT-NEXT: for (int i = start; i < stop; i += step)175 // DUMP-NEXT: ForStmt176 for (int i = start; i < stop; i += step)177 // PRINT-NEXT: body(i);178 // DUMP: CallExpr179 body(i);180}181void tfoo7() {182 foo7<5>(0, 42, 2);183}184 185 186// PRINT-LABEL: void foo8(187// DUMP-LABEL: FunctionDecl {{.*}} foo8188void foo8(int a) {189 // PRINT: #pragma omp tile sizes(a)190 // DUMP: OMPTileDirective191 // DUMP-NEXT: OMPSizesClause192 // DUMP-NEXT: ImplicitCastExpr193 // DUMP-NEXT: DeclRefExpr {{.*}} 'a'194 #pragma omp tile sizes(a)195 // PRINT-NEXT: for (int i = 7; i < 19; i += 3)196 // DUMP-NEXT: ForStmt197 for (int i = 7; i < 19; i += 3)198 // PRINT: body(i);199 // DUMP: CallExpr200 body(i);201}202 203#endif204