| 1 |
/* { dg-do compile } */ |
| 2 |
/* { dg-additional-options "-foffload=disable -fdump-tree-optimized" } */ |
| 3 |
|
| 4 |
#include <stdlib.h> |
| 5 |
|
| 6 |
static void |
| 7 |
init (int n, double *a) |
| 8 |
{ |
| 9 |
for (int i = 0; i < n; i++) |
| 10 |
a[i] = (double) i; |
| 11 |
} |
| 12 |
|
| 13 |
static void |
| 14 |
check (int n, double *a, double s) |
| 15 |
{ |
| 16 |
for (int i = 0; i < n; i++) |
| 17 |
if (a[i] != (double) i * s) |
| 18 |
abort (); |
| 19 |
} |
| 20 |
|
| 21 |
typedef void (transform_fn) (int, double *, double); |
| 22 |
|
| 23 |
static void doit (transform_fn *f, int n, double *a, double s) |
| 24 |
{ |
| 25 |
init (n, a); |
| 26 |
(*f) (n, a, s); |
| 27 |
check (n, a, s); |
| 28 |
} |
| 29 |
|
| 30 |
/* Check various combinations for enforcing correct ordering of |
| 31 |
construct matches. */ |
| 32 |
static void |
| 33 |
f1 (int n, double* a, double s) |
| 34 |
{ |
| 35 |
#pragma omp target teams |
| 36 |
#pragma omp parallel |
| 37 |
#pragma omp metadirective \ |
| 38 |
when (construct={target} \ |
| 39 |
: for) \ |
| 40 |
default (error at(execution) message("f1 match failed")) |
| 41 |
for (int i = 0; i < n; i++) |
| 42 |
a[i] = a[i] * s; |
| 43 |
} |
| 44 |
|
| 45 |
static void |
| 46 |
f2 (int n, double* a, double s) |
| 47 |
{ |
| 48 |
#pragma omp target teams |
| 49 |
#pragma omp parallel |
| 50 |
#pragma omp metadirective \ |
| 51 |
when (construct={teams, parallel} \ |
| 52 |
: for) \ |
| 53 |
default (error at(execution) message("f2 match failed")) |
| 54 |
for (int i = 0; i < n; i++) |
| 55 |
a[i] = a[i] * s; |
| 56 |
} |
| 57 |
|
| 58 |
static void |
| 59 |
f3 (int n, double* a, double s) |
| 60 |
{ |
| 61 |
#pragma omp target teams |
| 62 |
#pragma omp parallel |
| 63 |
#pragma omp metadirective \ |
| 64 |
when (construct={target, teams, parallel} \ |
| 65 |
: for) \ |
| 66 |
default (error at(execution) message("f3 match failed")) |
| 67 |
for (int i = 0; i < n; i++) |
| 68 |
a[i] = a[i] * s; |
| 69 |
} |
| 70 |
|
| 71 |
static void |
| 72 |
f4 (int n, double* a, double s) |
| 73 |
{ |
| 74 |
#pragma omp target teams |
| 75 |
#pragma omp parallel |
| 76 |
#pragma omp metadirective \ |
| 77 |
when (construct={target, parallel} \ |
| 78 |
: for) \ |
| 79 |
default (error at(execution) message("f4 match failed")) |
| 80 |
for (int i = 0; i < n; i++) |
| 81 |
a[i] = a[i] * s; |
| 82 |
} |
| 83 |
|
| 84 |
static void |
| 85 |
f5 (int n, double* a, double s) |
| 86 |
{ |
| 87 |
#pragma omp target teams |
| 88 |
#pragma omp parallel |
| 89 |
#pragma omp metadirective \ |
| 90 |
when (construct={target, teams} \ |
| 91 |
: for) \ |
| 92 |
default (error at(execution) message("f5 match failed")) |
| 93 |
for (int i = 0; i < n; i++) |
| 94 |
a[i] = a[i] * s; |
| 95 |
} |
| 96 |
|
| 97 |
/* Next batch is for things where the construct doesn't match the context. */ |
| 98 |
static void |
| 99 |
f6 (int n, double* a, double s) |
| 100 |
{ |
| 101 |
#pragma omp target |
| 102 |
#pragma omp teams |
| 103 |
#pragma omp metadirective \ |
| 104 |
when (construct={parallel} \ |
| 105 |
: error at(execution) message("f6 match failed")) \ |
| 106 |
default (parallel for) |
| 107 |
for (int i = 0; i < n; i++) |
| 108 |
a[i] = a[i] * s; |
| 109 |
} |
| 110 |
|
| 111 |
static void |
| 112 |
f7 (int n, double* a, double s) |
| 113 |
{ |
| 114 |
#pragma omp target |
| 115 |
#pragma omp teams |
| 116 |
#pragma omp metadirective \ |
| 117 |
when (construct={target, parallel} \ |
| 118 |
: error at(execution) message("f7 match failed")) \ |
| 119 |
default (parallel for) |
| 120 |
for (int i = 0; i < n; i++) |
| 121 |
a[i] = a[i] * s; |
| 122 |
} |
| 123 |
|
| 124 |
static void |
| 125 |
f8 (int n, double* a, double s) |
| 126 |
{ |
| 127 |
#pragma omp target |
| 128 |
#pragma omp teams |
| 129 |
#pragma omp metadirective \ |
| 130 |
when (construct={parallel, target} \ |
| 131 |
: error at(execution) message("f8 match failed")) \ |
| 132 |
default (parallel for) |
| 133 |
for (int i = 0; i < n; i++) |
| 134 |
a[i] = a[i] * s; |
| 135 |
} |
| 136 |
|
| 137 |
/* Next test choosing the best alternative when there are multiple |
| 138 |
matches. */ |
| 139 |
static void |
| 140 |
f9 (int n, double* a, double s) |
| 141 |
{ |
| 142 |
#pragma omp target teams |
| 143 |
#pragma omp parallel |
| 144 |
#pragma omp metadirective \ |
| 145 |
when (construct={teams, parallel} \ |
| 146 |
: error at(execution) message("f9 match incorrect 1")) \ |
| 147 |
when (construct={target, teams, parallel} \ |
| 148 |
: for) \ |
| 149 |
when (construct={target, teams} \ |
| 150 |
: error at(execution) message("f9 match incorrect 2")) \ |
| 151 |
default (error at(execution) message("f9 match failed")) |
| 152 |
for (int i = 0; i < n; i++) |
| 153 |
a[i] = a[i] * s; |
| 154 |
} |
| 155 |
|
| 156 |
/* Note there are no tests for the matching the extended simd clause |
| 157 |
syntax, which is only useful for "declare variant". */ |
| 158 |
|
| 159 |
#define N 10 |
| 160 |
#define S 2.0 |
| 161 |
|
| 162 |
int |
| 163 |
main (void) |
| 164 |
{ |
| 165 |
double a[N]; |
| 166 |
doit (f1, N, a, S); |
| 167 |
doit (f2, N, a, S); |
| 168 |
doit (f3, N, a, S); |
| 169 |
doit (f4, N, a, S); |
| 170 |
doit (f5, N, a, S); |
| 171 |
doit (f6, N, a, S); |
| 172 |
doit (f7, N, a, S); |
| 173 |
doit (f8, N, a, S); |
| 174 |
doit (f9, N, a, S); |
| 175 |
} |
| 176 |
|
| 177 |
/* All the error calls should be optimized away. */ |
| 178 |
/* { dg-final { scan-tree-dump-not "__builtin_GOMP_error" "optimized" } } */ |