]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
openmp: Disable strided target updates when iterators are used
authorKwok Cheung Yeung <kcyeung@baylibre.com>
Thu, 12 Sep 2024 20:33:58 +0000 (21:33 +0100)
committerKwok Cheung Yeung <kcyeung@baylibre.com>
Thu, 17 Apr 2025 22:30:08 +0000 (23:30 +0100)
Non-contiguous target updates result in the new strided target updates code
being used, resulting in new clauses such as GOMP_MAP_GRID_DIM,
GOMP_MAP_GRID_STRIDE etc. These are not currently supported in conjunction
with iterators, so this code-path is disabled when used together with
iterators.

The older target updates supports non-contiguous updates as long as a stride
is not applied.

gcc/c/

* c-typeck.cc (handle_omp_array_sections): Add extra argument.  Set
argument to true if array section has a stride that is not one.
(c_finish_omp_clauses): Disable strided updates when iterators are
used in the clause.  Emit sorry if strided.

gcc/cp/

* semantics.cc (handle_omp_array_sections): Add extra argument.  Set
argument to true if array section has a stride that is not one.
(finish_omp_clauses): Disable strided updates when iterators are
used in the clause.  Emit sorry if strided.

gcc/fortran/

* trans-openmp.cc (gfc_trans_omp_clauses): Disable strided updates
when iterators are used in the clause.

gcc/c/ChangeLog.omp
gcc/c/c-typeck.cc
gcc/cp/ChangeLog.omp
gcc/cp/semantics.cc
gcc/fortran/ChangeLog.omp
gcc/fortran/trans-openmp.cc

index af995a398571aca3d62cc6f3f243bbac2b2c245c..80a771f502076a90be8ff8f44e681c0868ff31b3 100644 (file)
@@ -1,3 +1,10 @@
+2025-04-17  Kwok Cheung Yeung  <kcyeung@baylibre.com>
+
+       * c-typeck.cc (handle_omp_array_sections): Add extra argument.  Set
+       argument to true if array section has a stride that is not one.
+       (c_finish_omp_clauses): Disable strided updates when iterators are
+       used in the clause.  Emit sorry if strided.
+
 2025-04-17  Kwok Cheung Yeung  <kcyeung@baylibre.com>
 
        * c-parser.cc (c_parser_omp_clause_from_to): Parse 'iterator' modifier.
index e6ec927c6bc2f07c8c44335ac0dbd428243a89a3..78272d582357cd1eea7806d271da115b1a3eab8c 100644 (file)
@@ -14597,7 +14597,7 @@ omp_array_section_low_bound (location_t loc, tree node)
 
 static bool
 handle_omp_array_sections (tree *pc, tree **pnext, enum c_omp_region_type ort,
-                          int *discontiguous)
+                          int *discontiguous, bool *strided = NULL)
 {
   tree c = *pc;
   bool maybe_zero_len = false;
@@ -14686,6 +14686,8 @@ handle_omp_array_sections (tree *pc, tree **pnext, enum c_omp_region_type ort,
 
          if (stride == NULL_TREE)
            stride = size_one_node;
+         if (strided && !integer_onep (stride))
+           *strided = true;
          if (discontiguous && *discontiguous)
            {
              /* This condition is similar to the error check below, but
@@ -16214,13 +16216,22 @@ c_finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
                grp_sentinel = OMP_CLAUSE_CHAIN (c);
 
                tree *pnext = NULL;
+               /* FIXME: Strided target updates not supported together with
+                  iterators yet.  */
                int discontiguous
                  = (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO
-                    || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FROM);
-               if (handle_omp_array_sections (pc, &pnext, ort, &discontiguous))
+                    || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FROM)
+                   && !OMP_CLAUSE_ITERATORS (c);
+               bool strided = false;
+               if (handle_omp_array_sections (pc, &pnext, ort, &discontiguous,
+                                              &strided))
                  remove = true;
                else
                  {
+                   if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO
+                        || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FROM)
+                       && OMP_CLAUSE_ITERATORS (c) && strided)
+                     sorry ("strided target updates with iterators");
                    c = *pc;
                    t = OMP_CLAUSE_DECL (c);
                    if (!omp_mappable_type (TREE_TYPE (t)))
index 80d2c3b5069ebf227be8c365a80cc04130e0510f..95e2b32e60e3f0e7f81697f044d3ca46773d978d 100644 (file)
@@ -1,3 +1,10 @@
+2025-04-17  Kwok Cheung Yeung  <kcyeung@baylibre.com>
+
+       * semantics.cc (handle_omp_array_sections): Add extra argument.  Set
+       argument to true if array section has a stride that is not one.
+       (finish_omp_clauses): Disable strided updates when iterators are
+       used in the clause.  Emit sorry if strided.
+
 2025-04-17  Kwok Cheung Yeung  <kcyeung@baylibre.com>
 
        * parser.cc (cp_parser_omp_clause_from_to): Parse 'iterator' modifier.
index dc102f15cf7cb6ec80d9ad63b668f473e51f7733..e7c2e69e0e26bc2a4e0bd4bcb64b477cedc7ed6f 100644 (file)
@@ -5993,7 +5993,7 @@ omp_array_section_low_bound (location_t loc, tree node)
 
 static bool
 handle_omp_array_sections (tree *pc, tree **pnext, enum c_omp_region_type ort,
-                          int *discontiguous)
+                          int *discontiguous, bool *strided = NULL)
 {
   tree c = *pc;
   bool maybe_zero_len = false;
@@ -6087,6 +6087,8 @@ handle_omp_array_sections (tree *pc, tree **pnext, enum c_omp_region_type ort,
 
          if (stride == NULL_TREE)
            stride = size_one_node;
+         if (strided && !integer_onep (stride))
+           *strided = true;
          if (discontiguous && *discontiguous)
            {
              /* This condition is similar to the error check below, but
@@ -8976,15 +8978,23 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
              {
                grp_start_p = pc;
                grp_sentinel = OMP_CLAUSE_CHAIN (c);
-
+               /* FIXME: Strided target updates not supported together with
+                  iterators yet.  */
                int discontiguous
                  = (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO
-                    || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FROM);
+                    || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FROM)
+                   && !OMP_CLAUSE_ITERATORS (c);
+               bool strided = false;
                tree *pnext = NULL;
-               if (handle_omp_array_sections (pc, &pnext, ort, &discontiguous))
+               if (handle_omp_array_sections (pc, &pnext, ort, &discontiguous,
+                                              &strided))
                  remove = true;
                else
                  {
+                   if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO
+                        || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FROM)
+                       && OMP_CLAUSE_ITERATORS (c) && strided)
+                     sorry ("strided target updates with iterators");
                    /* We might have replaced the clause, so refresh C.  */
                    c = *pc;
                    t = OMP_CLAUSE_DECL (c);
index ebbdf3d149e7195dce61e6578bdee9a22ed73db0..e1533c56b3475096cf39d55f4ec6e0fed934e81a 100644 (file)
@@ -1,3 +1,8 @@
+2025-04-17  Kwok Cheung Yeung  <kcyeung@baylibre.com>
+
+       * trans-openmp.cc (gfc_trans_omp_clauses): Disable strided updates
+       when iterators are used in the clause.
+
 2025-04-17  Kwok Cheung Yeung  <kcyeung@baylibre.com>
 
        * dump-parse-tree.cc (show_omp_namelist): Add iterator support for
index 5d62ea396df316d0396bf99cf833780e3182ce23..8154e7850509a0a43d0d3f68022064fd401e2321 100644 (file)
@@ -6465,7 +6465,10 @@ gfc_trans_omp_clauses (stmtblock_t *block, gfc_omp_clauses *clauses,
                  if (ref->type == REF_COMPONENT || ref->type == REF_ARRAY)
                    lastref = ref;
 
+             /* FIXME: Currently no support for strided target updates with
+                iterators.  */
              if ((list == OMP_LIST_TO || list == OMP_LIST_FROM)
+                 && !iterator
                  && (!n->expr || (lastref && lastref->type == REF_ARRAY))
                  && !gfc_omp_contiguous_update_p (n))
                {