From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 6A6663898526; Mon, 29 Nov 2021 08:50:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6A6663898526 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-9338] openmp: Fix up handling of kind(host) and kind(nohost) in ACCEL_COMPILERs [PR103384] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: f578f1828b1429728c5d104adf477859de0cf335 X-Git-Newrev: 333b0dc1792f48e822ebaaea6e104539918f47f2 Message-Id: <20211129085024.6A6663898526@sourceware.org> Date: Mon, 29 Nov 2021 08:50:24 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 29 Nov 2021 08:50:24 -0000 https://gcc.gnu.org/g:333b0dc1792f48e822ebaaea6e104539918f47f2 commit r11-9338-g333b0dc1792f48e822ebaaea6e104539918f47f2 Author: Jakub Jelinek Date: Wed Nov 24 10:30:32 2021 +0100 openmp: Fix up handling of kind(host) and kind(nohost) in ACCEL_COMPILERs [PR103384] As the testcase shows, we weren't handling kind(host) and kind(nohost) properly in the ACCEL_COMPILERs, the code written in there is valid for the host compiler only, where if we are maybe offloaded, we defer resolution after IPA, otherwise return 0 for kind(nohost) and accept it for kind(host). Note, omp_maybe_offloaded is false after IPA. If ACCEL_COMPILER is defined, it is the other way around, but also we know we are after IPA. 2021-11-24 Jakub Jelinek PR middle-end/103384 gcc/ * omp-general.c (omp_context_selector_matches): For ACCEL_COMPILER, return 0 for kind(host) and continue for kind(nohost). libgomp/ * testsuite/libgomp.c/declare-variant-2.c: New test. (cherry picked from commit 5bca26742cf3357bf4e20ec97eee4c7f7de17ce0) Diff: --- gcc/omp-general.c | 6 ++++ libgomp/testsuite/libgomp.c/declare-variant-2.c | 45 +++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/gcc/omp-general.c b/gcc/omp-general.c index fa6de01722b..65d151e496c 100644 --- a/gcc/omp-general.c +++ b/gcc/omp-general.c @@ -1328,16 +1328,22 @@ omp_context_selector_matches (tree ctx) continue; if (!strcmp (prop, "host")) { +#ifdef ACCEL_COMPILER + return 0; +#else if (omp_maybe_offloaded ()) ret = -1; continue; +#endif } if (!strcmp (prop, "nohost")) { +#ifndef ACCEL_COMPILER if (omp_maybe_offloaded ()) ret = -1; else return 0; +#endif continue; } int r = 0; diff --git a/libgomp/testsuite/libgomp.c/declare-variant-2.c b/libgomp/testsuite/libgomp.c/declare-variant-2.c new file mode 100644 index 00000000000..666ab20ea5f --- /dev/null +++ b/libgomp/testsuite/libgomp.c/declare-variant-2.c @@ -0,0 +1,45 @@ +/* { dg-do run } */ + +#include +#include + +void +foo_host (void) +{ + if (!omp_is_initial_device ()) + abort (); +} + +#pragma omp declare variant (foo_host) match (device={kind(host)}) +void +foo (void) +{ + if (omp_is_initial_device ()) + abort (); +} + +void +bar_nohost (void) +{ + if (omp_is_initial_device ()) + abort (); +} + +#pragma omp declare variant (bar_nohost) match (device={kind(nohost)}) +void +bar (void) +{ + if (!omp_is_initial_device ()) + abort (); +} + +int +main () +{ + #pragma omp target + { + foo (); + bar (); + } + return 0; +}