Skip to content

Commit 377eff7

Browse files
committed
OpenMP: common C/C++ testcases for dispatch + adjust_args
gcc/testsuite/ChangeLog: * c-c++-common/gomp/declare-variant-2.c: Adjust dg-error directives. * c-c++-common/gomp/adjust-args-1.c: New test. * c-c++-common/gomp/adjust-args-2.c: New test. * c-c++-common/gomp/declare-variant-dup-match-clause.c: New test. * c-c++-common/gomp/dispatch-1.c: New test. * c-c++-common/gomp/dispatch-2.c: New test. * c-c++-common/gomp/dispatch-3.c: New test. * c-c++-common/gomp/dispatch-4.c: New test. * c-c++-common/gomp/dispatch-5.c: New test. * c-c++-common/gomp/dispatch-6.c: New test. * c-c++-common/gomp/dispatch-7.c: New test. * c-c++-common/gomp/dispatch-8.c: New test. * c-c++-common/gomp/dispatch-9.c: New test. * c-c++-common/gomp/dispatch-10.c: New test. libgomp/ChangeLog: * testsuite/libgomp.c-c++-common/dispatch-1.c: New test. * testsuite/libgomp.c-c++-common/dispatch-2.c: New test.
1 parent ed49709 commit 377eff7

File tree

16 files changed

+547
-2
lines changed

16 files changed

+547
-2
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* { dg-do compile } */
2+
/* { dg-additional-options "-fdump-tree-gimple" } */
3+
4+
int f (int a, void *b, float c[2]);
5+
6+
#pragma omp declare variant (f) match (construct={dispatch}) adjust_args (nothing: a) adjust_args (need_device_ptr: b, c)
7+
int f0 (int a, void *b, float c[2]);
8+
#pragma omp declare variant (f) match (construct={dispatch}) adjust_args (nothing: a) adjust_args (need_device_ptr: b) adjust_args (need_device_ptr: c)
9+
int f1 (int a, void *b, float c[2]);
10+
11+
int test () {
12+
int a;
13+
void *b;
14+
float c[2];
15+
struct {int a;} s;
16+
17+
s.a = f0 (a, b, c);
18+
#pragma omp dispatch
19+
s.a = f0 (a, b, c);
20+
21+
f1 (a, b, c);
22+
#pragma omp dispatch
23+
s.a = f1 (a, b, c);
24+
25+
return s.a;
26+
}
27+
28+
/* { dg-final { scan-tree-dump-times "__builtin_omp_get_default_device \\(\\);" 2 "gimple" } } */
29+
/* { dg-final { scan-tree-dump-times "D\.\[0-9]+ = __builtin_omp_get_mapped_ptr \\(&c, D\.\[0-9]+\\);" 2 "gimple" } } */
30+
/* { dg-final { scan-tree-dump-times "D\.\[0-9]+ = __builtin_omp_get_mapped_ptr \\(b, D\.\[0-9]+\\);" 2 "gimple" } } */
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* { dg-do compile } */
2+
/* { dg-additional-options "-fdump-tree-gimple" } */
3+
4+
int f (int a, void *b, float c[2]);
5+
6+
#pragma omp declare variant (f) match (construct={dispatch}) adjust_args (nothing: a) adjust_args (need_device_ptr: b, c)
7+
int f0 (int a, void *b, float c[2]);
8+
#pragma omp declare variant (f) adjust_args (need_device_ptr: b, c) match (construct={dispatch}) adjust_args (nothing: a)
9+
int f1 (int a, void *b, float c[2]);
10+
11+
void test () {
12+
int a;
13+
void *b;
14+
float c[2];
15+
16+
#pragma omp dispatch
17+
f0 (a, b, c);
18+
19+
#pragma omp dispatch device (-4852)
20+
f0 (a, b, c);
21+
22+
#pragma omp dispatch device (a + a)
23+
f0 (a, b, c);
24+
}
25+
26+
/* { dg-final { scan-tree-dump-times "__builtin_omp_get_default_device \\(\\);" 3 "gimple" } } */
27+
/* { dg-final { scan-tree-dump-times "D\.\[0-9]+ = __builtin_omp_get_mapped_ptr \\(&c, D\.\[0-9]+\\);" 2 "gimple" } } */
28+
/* { dg-final { scan-tree-dump-times "D\.\[0-9]+ = __builtin_omp_get_mapped_ptr \\(b, D\.\[0-9]+\\);" 2 "gimple" } } */
29+
/* { dg-final { scan-tree-dump-times "D\.\[0-9]+ = __builtin_omp_get_mapped_ptr \\(&c, -4852\\);" 1 "gimple" } } */
30+
/* { dg-final { scan-tree-dump-times "D\.\[0-9]+ = __builtin_omp_get_mapped_ptr \\(b, -4852\\);" 1 "gimple" } } */
31+
/* { dg-final { scan-tree-dump-not "#pragma omp dispatch device" "gimple" } } */

gcc/testsuite/c-c++-common/gomp/declare-variant-2.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ void f3 (void);
88
void f4 (void);
99
#pragma omp declare variant match(user={condition(0)}) /* { dg-error "expected '\\(' before 'match'" } */
1010
void f5 (void);
11-
#pragma omp declare variant (f1) /* { dg-error "expected 'match' before end of line" } */
11+
#pragma omp declare variant (f1) /* { dg-error "expected 'match' clause before end of line" } */
1212
void f6 (void);
13-
#pragma omp declare variant (f1) simd /* { dg-error "expected 'match' before 'simd'" } */
13+
#pragma omp declare variant (f1) simd /* { dg-error "expected 'match' clause before 'simd'" } */
1414
void f7 (void);
1515
#pragma omp declare variant (f1) match /* { dg-error "expected '\\(' before end of line" } */
1616
void f8 (void);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/* Check that errors are detected if a match clause appears more than once,
2+
even if compatible. */
3+
4+
void f();
5+
#pragma omp declare variant(f) match(construct={target}) match(construct={target}) /* { dg-error "too many 'match' clauses" } */
6+
void g();
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#include <stdint.h>
2+
3+
int f0 (int, long, double);
4+
void f2 (void);
5+
int f3 (void);
6+
void (*f4) (void);
7+
void f5 (int*, int);
8+
9+
int *pp (void);
10+
int dd (void);
11+
12+
void f1 (void)
13+
{
14+
int a, c;
15+
long b;
16+
double x;
17+
struct {int a; float b; short c;} s, *sp;
18+
int arr[3];
19+
20+
#pragma omp dispatch
21+
c = f0 (a, b, x);
22+
#pragma omp dispatch
23+
x = f0 (a * 4, 2 - b, x * x);
24+
#pragma omp dispatch
25+
s.a = f0 (a, sp->c, x);
26+
#pragma omp dispatch
27+
sp->c = f0 (s.a - 2, b / 3, x * 5);
28+
#pragma omp dispatch
29+
arr[0] = f0 (arr[1], !b, arr[2]);
30+
#pragma omp dispatch
31+
(*sp).c = f0 (s.a, b, x);
32+
#pragma omp dispatch
33+
sp->b = f0 (s.a++, b % 4, --x);
34+
#pragma omp dispatch
35+
f0 (f3(), b, s.b);
36+
#pragma omp dispatch
37+
f2 ();
38+
#pragma omp dispatch
39+
f4 ();
40+
#pragma omp dispatch
41+
f5 (pp(), pp()[dd()]);
42+
43+
#pragma omp dispatch nocontext(sp->a * x + arr[2])
44+
f2 ();
45+
#pragma omp dispatch nocontext(arr - (intptr_t)(x / s.b))
46+
f2 ();
47+
#pragma omp dispatch nocontext(x == s.c || b != c)
48+
f2 ();
49+
#pragma omp dispatch novariants(b << sp->c)
50+
f2 ();
51+
#pragma omp dispatch novariants(!arr | s.a)
52+
f2 ();
53+
#pragma omp dispatch novariants(s.c ? f3() : a & c)
54+
f2 ();
55+
#pragma omp dispatch nowait
56+
f2 ();
57+
#pragma omp dispatch device(-25373654)
58+
f2 ();
59+
#pragma omp dispatch device(b * (int)(x - sp->b))
60+
f2 ();
61+
#pragma omp dispatch is_device_ptr(arr)
62+
f2 ();
63+
#pragma omp dispatch is_device_ptr(sp)
64+
f2 ();
65+
#pragma omp dispatch depend(inout: sp)
66+
f2 ();
67+
#pragma omp dispatch depend(inoutset: arr[:2])
68+
f2 ();
69+
#pragma omp dispatch depend(out: arr)
70+
f2 ();
71+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/* { dg-do compile } */
2+
/* { dg-additional-options "-fdump-tree-gimple" } */
3+
4+
int *f();
5+
6+
struct t {
7+
int *a, *b;
8+
};
9+
10+
void construct(int *x, int *y);
11+
void noconstruct(int *x, int *y);
12+
13+
#pragma omp declare variant(construct) match(construct={dispatch}) adjust_args(need_device_ptr: x,y)
14+
#pragma omp declare variant(noconstruct) match(implementation={vendor(gnu)})
15+
void bar(int *x, int *y);
16+
17+
int nocontext, novariant;
18+
19+
void sub(struct t *s, void *y)
20+
{
21+
bar( f(), s->b);
22+
#pragma omp dispatch device(0) is_device_ptr(s)
23+
bar( f(), s->b);
24+
25+
bar( (int *) y, s->b);
26+
#pragma omp dispatch device(0) is_device_ptr(y)
27+
bar( (int *) y, s->b);
28+
}
29+
30+
/* { dg-final { scan-tree-dump-times "__builtin_omp_get_default_device" 2 "gimple" } } */
31+
/* { dg-final { scan-tree-dump-times "__builtin_omp_set_default_device" 4 "gimple" } } */
32+
/* { dg-final { scan-tree-dump-times "__builtin_omp_set_default_device \\(0\\);" 2 "gimple" } } */
33+
/* { dg-final { scan-tree-dump-times "__builtin_omp_set_default_device \\(D\\.\[0-9\]+\\);" 2 "gimple" } } */
34+
/* { dg-final { scan-tree-dump-times "__builtin_omp_get_mapped_ptr" 3 "gimple" } } */
35+
/* { dg-final { scan-tree-dump-times "D\\.\[0-9\]+ = s->b;\[\r\n\]* *D\\.\[0-9\]+ = __builtin_omp_get_mapped_ptr \\(D\\.\[0-9\]+, 0\\);" 2 "gimple" } } */
36+
/* { dg-final { scan-tree-dump-times "D\\.\[0-9\]+ = f \\(\\);\[\r\n\]* *D\\.\[0-9\]+ = __builtin_omp_get_mapped_ptr \\(D\\.\[0-9\]+, 0\\);" 1 "gimple" } } */
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* { dg-do compile } */
2+
/* { dg-additional-options "-fdump-tree-gimple" } */
3+
4+
int f0 (void);
5+
int f1 (void);
6+
#pragma omp declare variant (f0) match (construct={dispatch})
7+
#pragma omp declare variant (f1) match (implementation={vendor(gnu)})
8+
int f2 (void);
9+
10+
int test (void)
11+
{
12+
int a;
13+
#pragma omp dispatch
14+
a = f2 ();
15+
#pragma omp dispatch novariants(1)
16+
a = f2 ();
17+
#pragma omp dispatch novariants(0)
18+
a = f2 ();
19+
#pragma omp dispatch nocontext(1)
20+
a = f2 ();
21+
#pragma omp dispatch nocontext(0)
22+
a = f2 ();
23+
return a;
24+
}
25+
26+
/* { dg-final { scan-tree-dump-times "a = f0 \\\(\\\);" 3 "gimple" } } */
27+
/* { dg-final { scan-tree-dump-times "a = f1 \\\(\\\);" 1 "gimple" } } */
28+
/* { dg-final { scan-tree-dump-times "a = f2 \\\(\\\);" 1 "gimple" } } */
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/* { dg-do compile } */
2+
/* { dg-additional-options "-fdump-tree-gimple" } */
3+
4+
void f2 (void);
5+
6+
void test (void)
7+
{
8+
#pragma omp dispatch /* { dg-final { scan-tree-dump-not "#pragma omp task" "gimple" } } */
9+
f2 ();
10+
#pragma omp dispatch nowait /* { dg-final { scan-tree-dump-not "nowait" "gimple" } } */
11+
f2 ();
12+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* { dg-do compile } */
2+
/* { dg-additional-options "-fdump-tree-gimple" } */
3+
4+
void f2 (int a);
5+
6+
void test (void)
7+
{
8+
int a;
9+
10+
#pragma omp dispatch device(-25373654)
11+
/* { dg-final { scan-tree-dump-times "__builtin_omp_set_default_device \\(-25373654\\);" 1 "gimple" } } */
12+
f2 (a);
13+
#pragma omp dispatch device(a + a)
14+
/* { dg-final { scan-tree-dump-times "(D\.\[0-9]+) = a \\* 2;.*#pragma omp dispatch.*__builtin_omp_set_default_device \\(\\1\\);.*f2 \\(a\\)" 2 "gimple" } } */
15+
f2 (a);
16+
}
17+
18+
/* { dg-final { scan-tree-dump-times "(D\.\[0-9]+) = __builtin_omp_get_default_device \\(\\);.*__builtin_omp_set_default_device \\(\\1\\);" 4 "gimple" } } */
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* { dg-do compile } */
2+
/* { dg-additional-options "-fdump-tree-gimple" } */
3+
4+
void f1 (void* p, int arr[]);
5+
#pragma omp declare variant (f1) match (construct={dispatch}) adjust_args (need_device_ptr: p, arr)
6+
void f2 (void* p, int arr[]);
7+
8+
void test (void)
9+
{
10+
void *p;
11+
int arr[2];
12+
13+
/* Note there are multiple matches because every variable capturing matches in addition,
14+
i.e. scan-tree-dump-times = 1 plus number of captures used for backward references.
15+
16+
For the first scan-tree-dump, on some targets the __builtin_omp_get_mapped_ptr get
17+
swapped. As the counting does not work well with variable-name capturing, it only
18+
uses 'scan-tree-dump' and not 'scan-tree-dump-times'. */
19+
20+
#pragma omp dispatch
21+
/* { dg-final { scan-tree-dump "#pragma omp dispatch\[ \t\n\r\{]*int (D\.\[0-9]+);\[ \t\n\r]*void \\* (D\.\[0-9]+);\[ \t\n\r]*void \\* (D\.\[0-9]+);\[ \t\n\r]*\\1 = __builtin_omp_get_default_device \\(\\);\[ \t\n\r]*\\2 = __builtin_omp_get_mapped_ptr \\(&arr, \\1\\);\[ \t\n\r]*\\3 = __builtin_omp_get_mapped_ptr \\(p, \\1\\);\[ \t\n\r]*f1 \\(\\3, \\2\\);|#pragma omp dispatch\[ \t\n\r\{]*int (D\.\[0-9]+);\[ \t\n\r]*void \\* (D\.\[0-9]+);\[ \t\n\r]*void \\* (D\.\[0-9]+);\[ \t\n\r]*\\4 = __builtin_omp_get_default_device \\(\\);\[ \t\n\r]*\\5 = __builtin_omp_get_mapped_ptr \\(p, \\4\\);\[ \t\n\r]*\\6 = __builtin_omp_get_mapped_ptr \\(&arr, \\4\\);\[ \t\n\r]*f1 \\(\\5, \\6\\);" "gimple" } } */
22+
f2 (p, arr);
23+
#pragma omp dispatch is_device_ptr(p)
24+
/* { dg-final { scan-tree-dump-times "#pragma omp dispatch is_device_ptr\\(p\\)\[ \t\n\r\{]*int (D\.\[0-9]+);\[ \t\n\r]*void \\* (D\.\[0-9]+);\[ \t\n\r]*\\1 = __builtin_omp_get_default_device \\(\\);\[ \t\n\r]*\\2 = __builtin_omp_get_mapped_ptr \\(&arr, \\1\\);\[ \t\n\r]*f1 \\(p, \\2\\);" 3 "gimple" } } */
25+
f2 (p, arr);
26+
#pragma omp dispatch is_device_ptr(arr)
27+
/* { dg-final { scan-tree-dump-times "#pragma omp dispatch is_device_ptr\\(arr\\)\[ \t\n\r\{]*int (D\.\[0-9]+);\[ \t\n\r]*void \\* (D\.\[0-9]+);\[ \t\n\r]*\\1 = __builtin_omp_get_default_device \\(\\);\[ \t\n\r]*\\2 = __builtin_omp_get_mapped_ptr \\(p, \\1\\);\[ \t\n\r]*f1 \\(\\2, &arr\\);" 3 "gimple" } } */
28+
f2 (p, arr);
29+
#pragma omp dispatch is_device_ptr(p, arr)
30+
/* { dg-final { scan-tree-dump-times "#pragma omp dispatch is_device_ptr\\(arr\\) is_device_ptr\\(p\\)\[ \t\n\r\{]*f1 \\(p, &arr\\);" 1 "gimple" } } */
31+
f2 (p, arr);
32+
}
33+
34+

0 commit comments

Comments
 (0)