summaryrefslogtreecommitdiff
path: root/clang/test/OpenMP/generic_loop_ast_print.cpp
blob: 7f5f53003e40cae28b0807787ecbe714e0818099 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=51 \
// RUN:   -fsyntax-only -verify %s

// expected-no-diagnostics

// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=51 \
// RUN:   -ast-print %s | FileCheck %s --check-prefix=PRINT

// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=51 \
// RUN:   -ast-dump  %s | FileCheck %s --check-prefix=DUMP

// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=51 \
// RUN:   -emit-pch -o %t %s

// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=51 \
// RUN:   -include-pch %t -ast-dump-all %s | FileCheck %s --check-prefix=DUMP

// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=51 \
// RUN:   -include-pch %t -ast-print %s | FileCheck %s --check-prefix=PRINT

#ifndef HEADER
#define HEADER

//PRINT: template <typename T, int C> void templ_foo(T t) {
//PRINT:   T j, z;
//PRINT:   #pragma omp loop collapse(C) reduction(+: z) lastprivate(j)
//PRINT:   for (T i = 0; i < t; ++i)
//PRINT:       for (j = 0; j < t; ++j)
//PRINT:           z += i + j;
//PRINT: }
//DUMP: FunctionTemplateDecl{{.*}}templ_foo
//DUMP: TemplateTypeParmDecl{{.*}}T
//DUMP: NonTypeTemplateParmDecl{{.*}}C
//DUMP: OMPGenericLoopDirective
//DUMP: OMPCollapseClause
//DUMP: DeclRefExpr{{.*}}'C' 'int'
//DUMP: OMPReductionClause
//DUMP: DeclRefExpr{{.*}}'z' 'T'
//DUMP: OMPLastprivateClause
//DUMP: DeclRefExpr{{.*}}'j' 'T'
//DUMP: ForStmt
//DUMP: ForStmt

//PRINT: template<> void templ_foo<int, 2>(int t) {
//PRINT:     int j, z;
//PRINT:     #pragma omp loop collapse(2) reduction(+: z) lastprivate(j)
//PRINT:         for (int i = 0; i < t; ++i)
//PRINT:             for (j = 0; j < t; ++j)
//PRINT:                 z += i + j;
//PRINT: }
//DUMP: FunctionDecl{{.*}}templ_foo 'void (int)'
//DUMP: TemplateArgument type 'int'
//DUMP: TemplateArgument integral 2
//DUMP: ParmVarDecl{{.*}}'int':'int'
//DUMP: OMPGenericLoopDirective
//DUMP: OMPCollapseClause
//DUMP: ConstantExpr{{.*}}'int'
//DUMP: value: Int 2
//DUMP: OMPReductionClause
//DUMP: DeclRefExpr{{.*}}'z' 'int':'int'
//DUMP: OMPLastprivateClause
//DUMP: DeclRefExpr{{.*}}'j' 'int':'int'
//DUMP: ForStmt
template <typename T, int C>
void templ_foo(T t) {

  T j,z;
  #pragma omp loop collapse(C) reduction(+:z) lastprivate(j)
  for (T i = 0; i<t; ++i)
    for (j = 0; j<t; ++j)
      z += i+j;
}


//PRINT: void test() {
//DUMP: FunctionDecl {{.*}}test 'void ()'
void test() {
  constexpr int N = 100;
  float MTX[N][N];
  int aaa[1000];

  //PRINT: #pragma omp target teams distribute parallel for map(tofrom: MTX)
  //PRINT: #pragma omp loop
  //DUMP: OMPTargetTeamsDistributeParallelForDirective
  //DUMP: CapturedStmt
  //DUMP: ForStmt
  //DUMP: CompoundStmt
  //DUMP: OMPGenericLoopDirective
  #pragma omp target teams distribute parallel for map(MTX)
  for (auto i = 0; i < N; ++i) {
    #pragma omp loop
    for (auto j = 0; j < N; ++j) {
      MTX[i][j] = 0;
    }
  }

  //PRINT: #pragma omp target teams
  //PRINT: #pragma omp loop
  //DUMP: OMPTargetTeamsDirective
  //DUMP: CapturedStmt
  //DUMP: ForStmt
  //DUMP: OMPGenericLoopDirective
  #pragma omp target teams
  for (int i=0; i<1000; ++i) {
    #pragma omp loop
    for (int j=0; j<100; j++) {
      aaa[i] += i + j;
    }
  }

  int j, z, z1;
  //PRINT: #pragma omp loop collapse(2) private(z) lastprivate(j) order(concurrent) reduction(+: z1)
  //DUMP: OMPGenericLoopDirective
  //DUMP: OMPCollapseClause
  //DUMP: IntegerLiteral{{.*}}2
  //DUMP: OMPPrivateClause
  //DUMP-NEXT: DeclRefExpr{{.*}}'z'
  //DUMP: OMPLastprivateClause
  //DUMP-NEXT: DeclRefExpr{{.*}}'j'
  //DUMP: OMPOrderClause
  //DUMP: OMPReductionClause
  //DUMP-NEXT: DeclRefExpr{{.*}}'z1'
  //DUMP: ForStmt
  //DUMP: ForStmt
  #pragma omp loop collapse(2) private(z) lastprivate(j) order(concurrent) \
                   reduction(+:z1)
  for (auto i = 0; i < N; ++i) {
    for (j = 0; j < N; ++j) {
      z = i+j;
      MTX[i][j] = z;
      z1 += z;
    }
  }
}

void bar()
{
  templ_foo<int,2>(8);
}

#endif // HEADER