File: interchange_ast_print.cpp

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,998,520 kB
  • sloc: cpp: 6,951,680; ansic: 1,486,157; asm: 913,598; python: 232,024; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,009; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,167; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (135 lines) | stat: -rw-r--r-- 4,224 bytes parent folder | download | duplicates (3)
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
// Check no warnings/errors
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -std=c++20 -fopenmp -fopenmp-version=60 -fsyntax-only -verify %s
// expected-no-diagnostics

// Check AST and unparsing
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -std=c++20 -fopenmp -fopenmp-version=60 -ast-dump  %s | FileCheck %s --check-prefix=DUMP
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -std=c++20 -fopenmp -fopenmp-version=60 -ast-print %s | FileCheck %s --check-prefix=PRINT

// Check same results after serialization round-trip
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -std=c++20 -fopenmp -fopenmp-version=60 -emit-pch -o %t %s
// 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
// 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

#ifndef HEADER
#define HEADER

// placeholder for loop body code.
extern "C" void body(...);

// PRINT-LABEL: void foo1(
// DUMP-LABEL:  FunctionDecl {{.*}} foo1
void foo1() {
  // PRINT: #pragma omp interchange
  // DUMP:  OMPInterchangeDirective
  #pragma omp interchange
  // PRINT: for (int i = 7; i < 17; i += 3)
  // DUMP-NEXT: ForStmt
  for (int i = 7; i < 17; i += 3)
    // PRINT: for (int j = 7; j < 17; j += 3)
    // DUMP:  ForStmt
    for (int j = 7; j < 17; j += 3)
      // PRINT: body(i, j);
      // DUMP:  CallExpr
      body(i, j);
}




// PRINT-LABEL: void foo3(
// DUMP-LABEL:  FunctionDecl {{.*}} foo3
void foo3() {
  // PRINT: #pragma omp for collapse(3)
  // DUMP:      OMPForDirective
  // DUMP-NEXT:   OMPCollapseClause
  // DUMP-NEXT:     ConstantExpr
  // DUMP-NEXT:       value: Int 3
  // DUMP-NEXT:     IntegerLiteral {{.*}} 3
  // DUMP-NEXT:     CapturedStmt
  // DUMP-NEXT:       CapturedDecl
  #pragma omp for collapse(3)
  // PRINT: #pragma omp interchange
  // DUMP:  OMPInterchangeDirective
  #pragma omp interchange
  // PRINT: for (int i = 7; i < 17; i += 1)
  // DUMP-NEXT: ForStmt
  for (int i = 7; i < 17; i += 1)
    // PRINT: for (int j = 7; j < 17; j += 1)
    // DUMP:  ForStmt
    for (int j = 7; j < 17; j += 1)
      // PRINT: for (int k = 7; k < 17; k += 1)
      // DUMP:  ForStmt
      for (int k = 7; k < 17; k += 1)
        // PRINT: body(i, j, k);
        // DUMP:  CallExpr
        body(i, j, k);
}


// PRINT-LABEL: void foo6(
// DUMP-LABEL: FunctionTemplateDecl {{.*}} foo6
template<int Tile>
void foo6() {
    // PRINT:     #pragma omp interchange
    // DUMP:      OMPInterchangeDirective
    #pragma omp interchange
      // PRINT-NEXT: for (int i = 0; i < 11; i += 2)
      // DUMP-NEXT:  ForStmt
      for (int i = 0; i < 11; i += 2)
        // PRINT-NEXT: #pragma omp tile sizes(Tile)
        // DUMP:       OMPTileDirective
        #pragma omp tile sizes(Tile)
        // PRINT-NEXT: for (int j = 0; j < 13; j += 2)
        // DUMP:       ForStmt
        for (int j = 0; j < 13; j += 2)
          // PRINT-NEXT: body(i, j);
          // DUMP:       CallExpr
          body(i, j);
}

// Also test instantiating the template.
void tfoo6() {
  foo6<32>();
}


// PRINT-LABEL: void foo7(
// DUMP-LABEL: FunctionDecl {{.*}} foo7
void foo7() {
  double arr[128];
  // PRINT: #pragma omp interchange
  // DUMP:  OMPInterchangeDirective
  #pragma omp interchange
  // PRINT-NEXT: for (double c = 42; auto &&v : arr)
  // DUMP-NEXT:  CXXForRangeStmt
  for (double c = 42; auto &&v : arr)
    // PRINT-NEXT: for (int i = 0; i < 42; i += 2)
    // DUMP:       ForStmt
    for (int i = 0; i < 42; i += 2)
      // PRINT-NEXT: body(c, v, i);
      // DUMP:       CallExpr
      body(c, v, i);
}


// PRINT-LABEL: void foo8(
// DUMP-LABEL: FunctionDecl {{.*}} foo8
void foo8() {
  double arr[128];
  // PRINT: #pragma omp interchange
  // DUMP:  OMPInterchangeDirective
  #pragma omp interchange
  // PRINT-NEXT: for (int i = 0; i < 42; i += 2)
  // DUMP-NEXT:  ForStmt
  for (int i = 0; i < 42; i += 2)
    // PRINT-NEXT: for (double c = 42; auto &&v : arr)
    // DUMP:       CXXForRangeStmt
    for (double c = 42; auto &&v : arr)
      // PRINT-NEXT: body(i, c, v);
      // DUMP:       CallExpr
      body(i, c, v);
}

#endif