]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
OpenMP: Update OMP_REQUIRES_TARGET_USED for declare_target + interop
authorTobias Burnus <tburnus@baylibre.com>
Wed, 25 Sep 2024 11:57:02 +0000 (13:57 +0200)
committerTobias Burnus <tburnus@baylibre.com>
Wed, 25 Sep 2024 11:57:02 +0000 (13:57 +0200)
Older versions of the OpenMP specification were not clear about what counted
as device usage. Newer (like TR13) are rather clear. Hence, this commit adds
GCC's target-used flag also when a 'declare target' or an 'interop' are
encountered.  (The latter only to Fortran as C/C++ parsing support is still
missing.) TR13 also lists 'dispatch' as target-used construct (as it has the
device clause) and 'device_safesync' as clause with global requirement
property, but both are not yet supported in GCC.

gcc/c/ChangeLog:

* c-parser.cc (c_parser_omp_declare_target): Set target-used bit
in omp_requires_mask.

gcc/cp/ChangeLog:

* parser.cc (cp_parser_omp_declare_target): Set target-used bit
in omp_requires_mask.

gcc/fortran/ChangeLog:

* parse.cc (decode_omp_directive): Set target-used bit of
omp_requires_mask when encountering the declare_target or interop
directive.

gcc/testsuite/ChangeLog:

* gfortran.dg/gomp/interop-1.f90: Add dg-error for missing
omp requires requirement and declare_variant usage.
* gfortran.dg/gomp/requires-8.f90: Likewise.

gcc/c/c-parser.cc
gcc/cp/parser.cc
gcc/fortran/parse.cc
gcc/testsuite/gfortran.dg/gomp/interop-1.f90
gcc/testsuite/gfortran.dg/gomp/requires-8.f90

index 6a46577f5119638603429fc887c15001bef14a5a..a681438cbbefc04c7c3e3d248c87763fd791b39a 100644 (file)
@@ -25492,6 +25492,9 @@ c_parser_omp_declare_target (c_parser *parser)
   int device_type = 0;
   bool indirect = false;
   bool only_device_type_or_indirect = true;
+  if (flag_openmp)
+    omp_requires_mask
+      = (enum omp_requires) (omp_requires_mask | OMP_REQUIRES_TARGET_USED);
   if (c_parser_next_token_is (parser, CPP_NAME)
       || (c_parser_next_token_is (parser, CPP_COMMA)
          && c_parser_peek_2nd_token (parser)->type == CPP_NAME))
index 83ae38a33ab256603dd6c3ce3649ab5bfd43883a..6d3be94bf4487489fd68bdd9351febddeccfc455 100644 (file)
@@ -49571,6 +49571,9 @@ cp_parser_omp_declare_target (cp_parser *parser, cp_token *pragma_tok)
   int device_type = 0;
   bool indirect = false;
   bool only_device_type_or_indirect = true;
+  if (flag_openmp)
+    omp_requires_mask
+      = (enum omp_requires) (omp_requires_mask | OMP_REQUIRES_TARGET_USED);
   if (cp_lexer_next_token_is (parser->lexer, CPP_NAME)
       || (cp_lexer_next_token_is (parser->lexer, CPP_COMMA)
          && cp_lexer_nth_token_is (parser->lexer, 2, CPP_NAME)))
index e749bbdc6b5900b85387d6c20cf39b7d5449f2fa..9e06dbf0911da7831d5e5bd3a3a70b99b6490593 100644 (file)
@@ -1345,8 +1345,12 @@ decode_omp_directive (void)
 
   switch (ret)
     {
-    /* Set omp_target_seen; exclude ST_OMP_DECLARE_TARGET.
-       FIXME: Get clarification, cf. OpenMP Spec Issue #3240.  */
+    /* For the constraints on clauses with the global requirement property,
+       we set omp_target_seen. This included all clauses that take the
+       DEVICE clause, (BEGIN) DECLARE_TARGET and procedures run the device
+       (which effectively is implied by the former).  */
+    case ST_OMP_DECLARE_TARGET:
+    case ST_OMP_INTEROP:
     case ST_OMP_TARGET:
     case ST_OMP_TARGET_DATA:
     case ST_OMP_TARGET_ENTER_DATA:
index 8c99fc97f8883f47cb9a77464d15553c33de2a8c..b7d2164812cc050fc0b0f83cefaca5e3123f1d12 100644 (file)
@@ -17,7 +17,7 @@ module m
  integer (omp_interop_fr_kind), parameter :: omp_ifr_hsa = 7
 end module m
 
-subroutine sub1
+subroutine sub1  ! { dg-error "Program unit at .1. has OpenMP device constructs/routines but does not set !.OMP REQUIRES REVERSE_OFFLOAD but other program units do" }
   !$omp interop
   integer :: y ! { dg-error "Unexpected data declaration statement" }
 end subroutine sub1
index 583c5a56b32e07f7c1f50aea589ce4012a73cd2b..3b0a7d81768c65cddfe869d6c88f4fc704c09f7f 100644 (file)
@@ -17,9 +17,9 @@ contains
  end subroutine foo
 end module m
 
-subroutine bar
+subroutine bar  ! { dg-error "has OpenMP device constructs/routines but does not set !.OMP REQUIRES REVERSE_OFFLOAD but other program units do" }
   !use m
-  !$omp requires unified_shared_memory  ! Possibly OK - needs OpenMP Lang Spec clarification (-> #3240)
+  !$omp requires unified_shared_memory
   !$omp declare target
 end subroutine bar