This patch adds a test scaffold for OpenMP compile tests in under the gcc.target testsuite. It also adds a target tests directory libgomp.target along with an SVE execution test
gcc/testsuite/ChangeLog: * gcc.target/aarch64/sve/omp/gomp.exp: New scaffold. libgomp/ChangeLog: * testsuite/libgomp.target/aarch64/aarch64.exp: New scaffold. * testsuite/libgomp.target/aarch64/shared.c: New test. --- .../gcc.target/aarch64/sve/omp/gomp.exp | 46 +++++ .../libgomp.target/aarch64/aarch64.exp | 57 ++++++ .../testsuite/libgomp.target/aarch64/shared.c | 186 ++++++++++++++++++ 3 files changed, 289 insertions(+) create mode 100644 gcc/testsuite/gcc.target/aarch64/sve/omp/gomp.exp create mode 100644 libgomp/testsuite/libgomp.target/aarch64/aarch64.exp create mode 100644 libgomp/testsuite/libgomp.target/aarch64/shared.c diff --git a/gcc/testsuite/gcc.target/aarch64/sve/omp/gomp.exp b/gcc/testsuite/gcc.target/aarch64/sve/omp/gomp.exp new file mode 100644 index 00000000000..279df81cf89 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/omp/gomp.exp @@ -0,0 +1,46 @@ +# Copyright (C) 2006-2024 Free Software Foundation, Inc. +# +# This file is part of GCC. +# +# GCC is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GCC is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GCC; see the file COPYING3. If not see +# <http://www.gnu.org/licenses/>. + +# GCC testsuite that uses the `dg.exp' driver. + +# Exit immediately if this isn't an AArch64 target. +if {![istarget aarch64*-*-*] } then { + return +} + +# Load support procs. +load_lib gcc-dg.exp + +# Initialize `dg'. +dg-init + +if ![check_effective_target_fopenmp] { + return +} + +if { [check_effective_target_aarch64_sve] } { + set sve_flags "" +} else { + set sve_flags "-march=armv8.2-a+sve" +} + +# Main loop. +dg-runtest [lsort [find $srcdir/$subdir *.c]] "$sve_flags -fopenmp" "" + +# All done. +dg-finish diff --git a/libgomp/testsuite/libgomp.target/aarch64/aarch64.exp b/libgomp/testsuite/libgomp.target/aarch64/aarch64.exp new file mode 100644 index 00000000000..828cc06c65b --- /dev/null +++ b/libgomp/testsuite/libgomp.target/aarch64/aarch64.exp @@ -0,0 +1,57 @@ +# Copyright (C) 2006-2024 Free Software Foundation, Inc. +# +# This file is part of GCC. +# +# GCC is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GCC is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GCC; see the file COPYING3. If not see +# <http://www.gnu.org/licenses/>. + +# Load support procs. +load_lib libgomp-dg.exp +load_gcc_lib gcc-dg.exp + +# Exit immediately if this isn't an AArch64 target. +if {![istarget aarch64*-*-*] } then { + return +} + +lappend ALWAYS_CFLAGS "compiler=$GCC_UNDER_TEST" + +if { [check_effective_target_aarch64_sve] } { + set sve_flags "" +} else { + set sve_flags "-march=armv8.2-a+sve" +} + +# Initialize `dg'. +dg-init + +#if ![check_effective_target_fopenmp] { +# return +#} + +# Turn on OpenMP. +lappend ALWAYS_CFLAGS "additional_flags=-fopenmp" + +# Gather a list of all tests. +set tests [lsort [find $srcdir/$subdir *.c]] + +set ld_library_path $always_ld_library_path +append ld_library_path [gcc-set-multilib-library-path $GCC_UNDER_TEST] +set_ld_library_path_env_vars + +# Main loop. +dg-runtest $tests "" $sve_flags + +# All done. +dg-finish diff --git a/libgomp/testsuite/libgomp.target/aarch64/shared.c b/libgomp/testsuite/libgomp.target/aarch64/shared.c new file mode 100644 index 00000000000..3f380d95da4 --- /dev/null +++ b/libgomp/testsuite/libgomp.target/aarch64/shared.c @@ -0,0 +1,186 @@ +/* { dg-do run { target aarch64_sve256_hw } } */ +/* { dg-options "-msve-vector-bits=256 -std=gnu99 -fopenmp -O2 -fdump-tree-ompexp" } */ + +#include <arm_sve.h> +#include <stdint.h> +#include <stdlib.h> +#include <stdbool.h> + +svint32_t +__attribute__ ((noinline)) +explicit_shared (svint32_t a, svint32_t b, svbool_t p) +{ + +#pragma omp parallel shared (a, b, p) num_threads (1) + { + /* 'a', 'b' and 'p' are explicitly shared. */ + a = svadd_s32_z (p, a, b); + } + +#pragma omp parallel shared (a, b, p) num_threads (1) + { + a = svadd_s32_z (p, a, b); + } + + return a; +} + +svint32_t +__attribute__ ((noinline)) +implicit_shared_default (svint32_t a, svint32_t b, svbool_t p) +{ + +#pragma omp parallel default (shared) num_threads (1) + { + /* 'a', 'b' and 'p' are implicitly shared. */ + a = svadd_s32_z (p, a, b); + } + +#pragma omp parallel default (shared) num_threads (1) + { + a = svadd_s32_z (p, a, b); + } + + return a; +} + +svint32_t +__attribute__ ((noinline)) +implicit_shared_no_default (svint32_t a, svint32_t b, svbool_t p) +{ + +#pragma omp parallel num_threads (1) + { + /* 'a', 'b' and 'p' are implicitly shared without default clause. */ + a = svadd_s32_z (p, a, b); + } + +#pragma omp parallel num_threads (1) + { + a = svadd_s32_z (p, a, b); + } + + return a; +} + +svint32_t +__attribute__ ((noinline)) +mix_shared (svint32_t b, svbool_t p) +{ + + svint32_t a; + int32_t *m = (int32_t *)malloc (8 * sizeof (int32_t)); + int i; + +#pragma omp parallel for + for (i = 0; i < 8; i++) + m[i] = i; + +#pragma omp parallel + { + /* 'm' is predetermined shared here. 'a' is implicitly shared here. */ + a = svld1_s32 (svptrue_b32 (), m); + } + +#pragma omp parallel num_threads (1) + { + /* 'a', 'b' and 'p' are implicitly shared here. */ + a = svadd_s32_z (p, a, b); + } + +#pragma omp parallel shared (a, b, p) num_threads (1) + { + /* 'a', 'b' and 'p' are explicitly shared here. */ + a = svadd_s32_z (p, a, b); + } + + return a; +} + +void +__attribute__ ((noinline)) +predetermined_shared_static (bool x) +{ + + int32_t *m = (int32_t *)malloc (8 * sizeof (int32_t)); + int i; + +#pragma omp parallel for + /* 'm' is predetermined shared here. */ + for (i = 0; i < 8; i++) + { + m[i] = i; + } + +#pragma omp parallel + { + /* 'a' is predetermined shared here. */ + static int64_t n; + svint32_t a; + #pragma omp parallel + { + /* 'n' is predetermined shared here. */ + if (x) + { + a = svld1_s32 (svptrue_b32 (), m); + n = svaddv_s32 (svptrue_b32 (), a); + } + if (!x && n != 28) + __builtin_abort (); + } + } +} + +svint32_t +__attribute__ ((noinline)) +foo (svint32_t a, svint32_t b, svbool_t p) +{ + a = svadd_s32_z (p, a, b); + a = svadd_s32_z (p, a, b); + return a; +} + +void compare_vec (svint32_t x, svint32_t y) +{ + svbool_t p = svnot_b_z (svptrue_b32 (), svcmpeq_s32 (svptrue_b32 (), x, y)); + + if (svptest_any (svptrue_b32 (), p)) + __builtin_abort (); +} + +int +main () +{ + svint32_t x = svindex_s32 (0 ,1); + svint32_t y = svindex_s32 (8, 1); + svint32_t a, b; + svbool_t p; + + /* Implicit shared. */ + a = foo (x, y, p); + b = implicit_shared_default (x, y, p); + compare_vec (a, b); + + /* Explicit shared. */ + a = foo (x ,y, p); + b = explicit_shared (x, y, p); + compare_vec (a, b); + + /* Implicit shared with no default clause. */ + a = foo (x ,y, p); + b = implicit_shared_no_default (x, y, p); + compare_vec (a, b); + + /* Mix shared. */ + a = foo (x ,y, p); + b = mix_shared (y, p); + compare_vec (a, b); + + /* Predetermined shared. */ + predetermined_shared_static (true); + predetermined_shared_static (false); + + return 0; +} + +/* { dg-final { scan-tree-dump-times "value-expr: \*.omp_data_i->a" 10 "ompexp" } } */ -- 2.25.1