File: unroll_ast_print.cpp

package info (click to toggle)
llvm-toolchain-13 1%3A13.0.1-6~deb10u4
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,418,792 kB
  • sloc: cpp: 5,290,827; ansic: 996,570; asm: 544,593; python: 188,212; objc: 72,027; lisp: 30,291; f90: 25,395; sh: 24,900; javascript: 9,780; pascal: 9,398; perl: 7,484; ml: 5,432; awk: 3,523; makefile: 2,892; xml: 953; cs: 573; fortran: 539
file content (127 lines) | stat: -rw-r--r-- 4,139 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
// Check no warnings/errors
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=51 -fsyntax-only -verify %s
// expected-no-diagnostics

// Check AST and unparsing
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=51 -ast-dump  %s | FileCheck %s --check-prefix=DUMP
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=51 -ast-print %s | FileCheck %s --check-prefix=PRINT --match-full-lines

// Check same results after serialization round-trip
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=51 -emit-pch -o %t %s
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=51 -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 -include-pch %t -ast-print    %s | FileCheck %s --check-prefix=PRINT --match-full-lines

#ifndef HEADER
#define HEADER

// placeholder for loop body code.
void body(...);


// PRINT-LABEL: void func_unroll() {
// DUMP-LABEL:  FunctionDecl {{.*}} func_unroll
void func_unroll() {
  // PRINT:  #pragma omp unroll
  // DUMP:   OMPUnrollDirective
  #pragma omp unroll
  // PRINT-NEXT: for (int i = 7; i < 17; i += 3)
  // DUMP-NEXT: ForStmt
  for (int i = 7; i < 17; i += 3)
    // PRINT-NEXT: body(i);
    // DUMP: CallExpr
    body(i);
}


// PRINT-LABEL: void func_unroll_full() {
// DUMP-LABEL:  FunctionDecl {{.*}} func_unroll_full 
void func_unroll_full() {
  // PRINT:     #pragma omp unroll full
  // DUMP:      OMPUnrollDirective
  // DUMP-NEXT:   OMPFullClause
  #pragma omp unroll full
  // PRINT-NEXT: for (int i = 7; i < 17; i += 3)
  // DUMP-NEXT: ForStmt
  for (int i = 7; i < 17; i += 3)
    // PRINT-NEXT: body(i);
    // DUMP: CallExpr
    body(i);
}


// PRINT-LABEL: void func_unroll_partial() {
// DUMP-LABEL:  FunctionDecl {{.*}} func_unroll_partial 
void func_unroll_partial() {
  // PRINT:     #pragma omp unroll partial
  // DUMP:      OMPUnrollDirective
  // DUMP-NEXT:   OMPPartialClause
  // DUMP-NEXT:     <<<NULL>>>
  #pragma omp unroll partial
  // PRINT-NEXT: for (int i = 7; i < 17; i += 3)
  // DUMP-NEXT: ForStmt
  for (int i = 7; i < 17; i += 3)
    // PRINT: body(i);
    // DUMP: CallExpr
    body(i);
}


// PRINT-LABEL: void func_unroll_partial_factor() {
// DUMP-LABEL:  FunctionDecl {{.*}} func_unroll_partial_factor 
void func_unroll_partial_factor() {
  // PRINT:     #pragma omp unroll partial(4)
  // DUMP:      OMPUnrollDirective
  // DUMP-NEXT:   OMPPartialClause
  // DUMP-NEXT:     ConstantExpr
  // DUMP-NEXT:       value: Int 4
  // DUMP-NEXT:       IntegerLiteral {{.*}} 4
  #pragma omp unroll partial(4)
  // PRINT-NEXT: for (int i = 7; i < 17; i += 3)
  // DUMP-NEXT: ForStmt
  for (int i = 7; i < 17; i += 3)
    // PRINT-NEXT: body(i);
    // DUMP: CallExpr
    body(i);
}


// PRINT-LABEL: void func_unroll_partial_factor_for() {
// DUMP-LABEL:  FunctionDecl {{.*}} func_unroll_partial_factor_for 
void func_unroll_partial_factor_for() {
  // PRINT:     #pragma omp for
  // DUMP:      OMPForDirective
  #pragma omp for
  // PRINT:       #pragma omp unroll partial(2)
  // DUMP:        OMPUnrollDirective
  // DUMP-NEXT:     OMPPartialClause
  #pragma omp unroll partial(2)
  // PRINT-NEXT: for (int i = 7; i < 17; i += 3)
  // DUMP: ForStmt
  for (int i = 7; i < 17; i += 3)
    // PRINT-NEXT: body(i);
    // DUMP: CallExpr
    body(i);
}


// PRINT-LABEL: template <typename T, T Start, T End, T Step, int Factor> void unroll_templated() {
// DUMP-LABEL:  FunctionTemplateDecl {{.*}} unroll_templated
template<typename T, T Start, T End, T Step, int Factor>
void unroll_templated() {
  // PRINT: #pragma omp unroll partial(Factor)
  // DUMP:      OMPUnrollDirective
  // DUMP-NEXT: OMPPartialClause
  // DUMP-NEXT:   DeclRefExpr {{.*}} 'Factor' 'int'
  #pragma omp unroll partial(Factor)
    // PRINT-NEXT: for (T i = Start; i < End; i += Step)
    // DUMP-NEXT:  ForStmt
    for (T i = Start; i < End; i += Step)
      // PRINT-NEXT: body(i);
      // DUMP:  CallExpr
      body(i);
}
void unroll_template() {
  unroll_templated<int,0,1024,1,4>();
}

#endif