https://gcc.gnu.org/g:fbd21dd552c7f0d178f9e1274c106c2d9a96aff4

commit fbd21dd552c7f0d178f9e1274c106c2d9a96aff4
Author: Kwok Cheung Yeung <[email protected]>
Date:   Sun Jun 7 01:37:18 2026 +0000

    openmp: Add macros for iterator element access
    
    gcc/c/
    
            * c-parser.cc (c_parser_omp_iterators): Use iterator constructors
            and macros for accessing iterator elements.
            (c_parser_omp_clause_affinity): Likewise.
            (c_parser_omp_clause_depend): Likewise.
            (c_parser_omp_clause_map): Likewise.
            (c_parser_omp_clause_from_to): Likewise.
            * c-typeck.cc (c_omp_finish_iterators): Likewise.
    
    gcc/cp/
    
            * parser.cc (cp_parser_omp_iterators): Use iterator constructors
            and macros for accessing iterator elements.
            (cp_parser_omp_clause_affinity): Likewise.
            (cp_parser_omp_clause_depend): Likewise.
            (cp_parser_omp_clause_from_to): Likewise.
            (cp_parser_omp_clause_map): Likewise.
            * pt.cc (tsubst_omp_clause_decl): Likewise.
            * semantics.cc (cp_omp_finish_iterators): Likewise.
    
    gcc/fortran/
    
            * trans-openmp.cc (gfc_trans_omp_array_section): Use macros for
            accessing iterator elements.
            (handle_iterator): Likewise, plus the iterator constructor.
            (gfc_trans_omp_clauses): Likewise.
    
    gcc/
    
            * gimplify.cc (gimplify_omp_affinity): Use macros for accessing
            iterator elements.
            (compute_omp_iterator_count): Likewise.
            (build_omp_iterator_loop): Likewise.
            (copy_omp_iterator): Use a boolean to force creation of an
            expanded iterator vector, instead of specifying the length 
explicitly.
            (remove_unused_omp_iterator_vars): Use accessor macros.
            (build_omp_iterators_loops): Likewise.
            (enter_omp_iterator_loop_context_1): Likewise.
            (extract_base_bit_offset): Likewise.
            * omp-low.cc (lower_omp_map_iterator_expr): Likewise.
            (lower_omp_map_iterator_size): Likewise.
            * tree-inline.cc (copy_tree_body_r): Likewise.
            * tree-pretty-print.cc (dump_omp_iterators): Likewise.
            * tree.h (OMP_ITERATOR_VAR, OMP_ITERATOR_BEGIN, OMP_ITERATOR_END,
            OMP_ITERATOR_STEP, OMP_ITERATOR_ORIG_STEP, OMP_ITERATOR_BLOCK,
            OMP_ITERATOR_LABEL, OMP_ITERATOR_INDEX, OMP_ITERATOR_ELEMS,
            OMP_ITERATOR_COUNT, OMP_ITERATOR_EXPANDED_P): New macros.
            (make_omp_iterator, make_expanded_omp_iterator): New constructor
            functions.
    
    Co-Authored-By: Sandra Loosemore <[email protected]>
    (cherry picked from commit 19bc99cb9c0f85da79bee41fabf40461b64d2cd1)

Diff:
---
 gcc/c/c-parser.cc           | 18 ++++-----
 gcc/c/c-typeck.cc           | 24 ++++++------
 gcc/cp/parser.cc            | 18 ++++-----
 gcc/cp/pt.cc                | 20 +++++-----
 gcc/cp/semantics.cc         | 26 ++++++-------
 gcc/fortran/trans-openmp.cc | 40 +++++++++----------
 gcc/gimplify.cc             | 94 ++++++++++++++++++++++-----------------------
 gcc/omp-low.cc              |  8 ++--
 gcc/tree-inline.cc          |  4 +-
 gcc/tree-pretty-print.cc    | 19 ++++-----
 gcc/tree.h                  | 32 +++++++++++++++
 11 files changed, 167 insertions(+), 136 deletions(-)

diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index 8fa989447a0f..4fcdf516163d 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -20311,11 +20311,11 @@ c_parser_omp_iterators (c_parser *parser)
       DECL_CONTEXT (iter_var) = current_function_decl;
       pushdecl (iter_var);
 
-      *last = make_tree_vec (6);
-      TREE_VEC_ELT (*last, 0) = iter_var;
-      TREE_VEC_ELT (*last, 1) = begin;
-      TREE_VEC_ELT (*last, 2) = end;
-      TREE_VEC_ELT (*last, 3) = step;
+      *last = make_omp_iterator ();
+      OMP_ITERATOR_VAR (*last) = iter_var;
+      OMP_ITERATOR_BEGIN (*last) = begin;
+      OMP_ITERATOR_END (*last) = end;
+      OMP_ITERATOR_STEP (*last) = step;
       last = &TREE_CHAIN (*last);
 
       if (c_parser_next_token_is (parser, CPP_COMMA))
@@ -20380,7 +20380,7 @@ c_parser_omp_clause_affinity (c_parser *parser, tree 
list)
       tree block = pop_scope ();
       if (iterators != error_mark_node)
        {
-         TREE_VEC_ELT (iterators, 5) = block;
+         OMP_ITERATOR_BLOCK (iterators) = block;
          for (tree c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
            OMP_CLAUSE_DECL (c) = build_tree_list (iterators,
                                                   OMP_CLAUSE_DECL (c));
@@ -20511,7 +20511,7 @@ c_parser_omp_clause_depend (c_parser *parser, tree 
list, location_t here)
          if (iterators == error_mark_node)
            iterators = NULL_TREE;
          else
-           TREE_VEC_ELT (iterators, 5) = block;
+           OMP_ITERATOR_BLOCK (iterators) = block;
        }
 
       for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
@@ -20955,7 +20955,7 @@ c_parser_omp_clause_map (c_parser *parser, tree list, 
bool declare_mapper_p)
       if (iterators == error_mark_node)
        iterators = NULL_TREE;
       else
-       TREE_VEC_ELT (iterators, 5) = block;
+       OMP_ITERATOR_BLOCK (iterators) = block;
     }
 
   for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
@@ -21335,7 +21335,7 @@ c_parser_omp_clause_from_to (c_parser *parser, enum 
omp_clause_code kind,
       if (iterators == error_mark_node)
        iterators = NULL_TREE;
       else
-       TREE_VEC_ELT (iterators, 5) = block;
+       OMP_ITERATOR_BLOCK (iterators) = block;
     }
 
   if (iterators)
diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
index 627ec86f26ab..90b56246255f 100644
--- a/gcc/c/c-typeck.cc
+++ b/gcc/c/c-typeck.cc
@@ -16504,10 +16504,10 @@ c_omp_finish_iterators (tree iter)
   bool ret = false;
   for (tree it = iter; it; it = TREE_CHAIN (it))
     {
-      tree var = TREE_VEC_ELT (it, 0);
-      tree begin = TREE_VEC_ELT (it, 1);
-      tree end = TREE_VEC_ELT (it, 2);
-      tree step = TREE_VEC_ELT (it, 3);
+      tree var = OMP_ITERATOR_VAR (it);
+      tree begin = OMP_ITERATOR_BEGIN (it);
+      tree end = OMP_ITERATOR_END (it);
+      tree step = OMP_ITERATOR_STEP (it);
       tree orig_step;
       tree type = TREE_TYPE (var);
       location_t loc = DECL_SOURCE_LOCATION (var);
@@ -16581,10 +16581,10 @@ c_omp_finish_iterators (tree iter)
       tree it2;
       for (it2 = TREE_CHAIN (it); it2; it2 = TREE_CHAIN (it2))
        {
-         tree var2 = TREE_VEC_ELT (it2, 0);
-         tree begin2 = TREE_VEC_ELT (it2, 1);
-         tree end2 = TREE_VEC_ELT (it2, 2);
-         tree step2 = TREE_VEC_ELT (it2, 3);
+         tree var2 = OMP_ITERATOR_VAR (it2);
+         tree begin2 = OMP_ITERATOR_BEGIN (it2);
+         tree end2 = OMP_ITERATOR_END (it2);
+         tree step2 = OMP_ITERATOR_STEP (it2);
          tree type2 = TREE_TYPE (var2);
          location_t loc2 = DECL_SOURCE_LOCATION (var2);
          struct c_find_omp_var_s data = { var, &pset };
@@ -16619,10 +16619,10 @@ c_omp_finish_iterators (tree iter)
          ret = true;
          continue;
        }
-      TREE_VEC_ELT (it, 1) = begin;
-      TREE_VEC_ELT (it, 2) = end;
-      TREE_VEC_ELT (it, 3) = step;
-      TREE_VEC_ELT (it, 4) = orig_step;
+      OMP_ITERATOR_BEGIN (it) = begin;
+      OMP_ITERATOR_END (it) = end;
+      OMP_ITERATOR_STEP (it) = step;
+      OMP_ITERATOR_ORIG_STEP (it) = orig_step;
     }
   return ret;
 }
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 9dcc2c475363..3a3972bbe643 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -44827,11 +44827,11 @@ cp_parser_omp_iterators (cp_parser *parser)
       DECL_CONTEXT (iter_var) = current_function_decl;
       pushdecl (iter_var);
 
-      *last = make_tree_vec (6);
-      TREE_VEC_ELT (*last, 0) = iter_var;
-      TREE_VEC_ELT (*last, 1) = begin;
-      TREE_VEC_ELT (*last, 2) = end;
-      TREE_VEC_ELT (*last, 3) = step;
+      *last = make_omp_iterator ();
+      OMP_ITERATOR_VAR (*last) = iter_var;
+      OMP_ITERATOR_BEGIN (*last) = begin;
+      OMP_ITERATOR_END (*last) = end;
+      OMP_ITERATOR_STEP (*last) = step;
       last = &TREE_CHAIN (*last);
 
       if (cp_lexer_next_token_is (parser->lexer, CPP_COMMA))
@@ -44905,7 +44905,7 @@ cp_parser_omp_clause_affinity (cp_parser *parser, tree 
list)
       tree block = poplevel (1, 1, 0);
       if (iterators != error_mark_node)
        {
-         TREE_VEC_ELT (iterators, 5) = block;
+         OMP_ITERATOR_BLOCK (iterators) = block;
          for (c = nlist; c != list; c = OMP_CLAUSE_CHAIN (c))
            OMP_CLAUSE_DECL (c) = build_tree_list (iterators,
                                                   OMP_CLAUSE_DECL (c));
@@ -45044,7 +45044,7 @@ cp_parser_omp_clause_depend (cp_parser *parser, tree 
list, location_t loc)
          if (iterators == error_mark_node)
            iterators = NULL_TREE;
          else
-           TREE_VEC_ELT (iterators, 5) = block;
+           OMP_ITERATOR_BLOCK (iterators) = block;
        }
 
       for (c = nlist; c != list; c = OMP_CLAUSE_CHAIN (c))
@@ -45253,7 +45253,7 @@ cp_parser_omp_clause_from_to (cp_parser *parser, enum 
omp_clause_code kind,
       if (iterators == error_mark_node)
        iterators = NULL_TREE;
       else
-       TREE_VEC_ELT (iterators, 5) = block;
+       OMP_ITERATOR_BLOCK (iterators) = block;
     }
 
   if (iterators)
@@ -45646,7 +45646,7 @@ cp_parser_omp_clause_map (cp_parser *parser, tree list, 
bool declare_mapper_p)
       if (iterators == error_mark_node)
        iterators = NULL_TREE;
       else
-       TREE_VEC_ELT (iterators, 5) = block;
+       OMP_ITERATOR_BLOCK (iterators) = block;
     }
 
   for (c = nlist; c != list; c = OMP_CLAUSE_CHAIN (c))
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index c75871719b14..d500f0869bff 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -18572,16 +18572,16 @@ tsubst_omp_clause_decl (tree decl, tree args, 
tsubst_flags_t complain,
          for (tree it = TREE_PURPOSE (decl); it; it = TREE_CHAIN (it))
            {
              *tp = copy_node (it);
-             TREE_VEC_ELT (*tp, 0)
-               = tsubst_decl (TREE_VEC_ELT (it, 0), args, complain);
-             DECL_CONTEXT (TREE_VEC_ELT (*tp, 0)) = current_function_decl;
-             pushdecl (TREE_VEC_ELT (*tp, 0));
-             TREE_VEC_ELT (*tp, 1)
-               = tsubst_stmt (TREE_VEC_ELT (it, 1), args, complain, in_decl);
-             TREE_VEC_ELT (*tp, 2)
-               = tsubst_stmt (TREE_VEC_ELT (it, 2), args, complain, in_decl);
-             TREE_VEC_ELT (*tp, 3)
-               = tsubst_stmt (TREE_VEC_ELT (it, 3), args, complain, in_decl);
+             OMP_ITERATOR_VAR (*tp)
+               = tsubst_decl (OMP_ITERATOR_VAR (it), args, complain);
+             DECL_CONTEXT (OMP_ITERATOR_VAR (*tp)) = current_function_decl;
+             pushdecl (OMP_ITERATOR_VAR (*tp));
+             OMP_ITERATOR_BEGIN (*tp)
+               = tsubst_stmt (OMP_ITERATOR_BEGIN (it), args, complain, 
in_decl);
+             OMP_ITERATOR_END (*tp)
+               = tsubst_stmt (OMP_ITERATOR_END (it), args, complain, in_decl);
+             OMP_ITERATOR_STEP (*tp)
+               = tsubst_stmt (OMP_ITERATOR_STEP (it), args, complain, in_decl);
              TREE_CHAIN (*tp) = NULL_TREE;
              tp = &TREE_CHAIN (*tp);
            }
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index d0a48ff85260..225d8793eab8 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -7595,10 +7595,10 @@ cp_omp_finish_iterators (tree iter)
   bool ret = false;
   for (tree it = iter; it; it = TREE_CHAIN (it))
     {
-      tree var = TREE_VEC_ELT (it, 0);
-      tree begin = TREE_VEC_ELT (it, 1);
-      tree end = TREE_VEC_ELT (it, 2);
-      tree step = TREE_VEC_ELT (it, 3);
+      tree var = OMP_ITERATOR_VAR (it);
+      tree begin = OMP_ITERATOR_BEGIN (it);
+      tree end = OMP_ITERATOR_END (it);
+      tree step = OMP_ITERATOR_STEP (it);
       tree orig_step;
       tree type = TREE_TYPE (var);
       location_t loc = DECL_SOURCE_LOCATION (var);
@@ -7696,10 +7696,10 @@ cp_omp_finish_iterators (tree iter)
       tree it2;
       for (it2 = TREE_CHAIN (it); it2; it2 = TREE_CHAIN (it2))
        {
-         tree var2 = TREE_VEC_ELT (it2, 0);
-         tree begin2 = TREE_VEC_ELT (it2, 1);
-         tree end2 = TREE_VEC_ELT (it2, 2);
-         tree step2 = TREE_VEC_ELT (it2, 3);
+         tree var2 = OMP_ITERATOR_VAR (it2);
+         tree begin2 = OMP_ITERATOR_BEGIN (it2);
+         tree end2 = OMP_ITERATOR_END (it2);
+         tree step2 = OMP_ITERATOR_STEP (it2);
          location_t loc2 = DECL_SOURCE_LOCATION (var2);
          if (cp_walk_tree (&begin2, find_omp_placeholder_r, var, &pset))
            {
@@ -7725,14 +7725,14 @@ cp_omp_finish_iterators (tree iter)
          ret = true;
          continue;
        }
-      TREE_VEC_ELT (it, 1) = begin;
-      TREE_VEC_ELT (it, 2) = end;
+      OMP_ITERATOR_BEGIN (it) = begin;
+      OMP_ITERATOR_END (it) = end;
       if (processing_template_decl)
-       TREE_VEC_ELT (it, 3) = orig_step;
+       OMP_ITERATOR_STEP (it) = orig_step;
       else
        {
-         TREE_VEC_ELT (it, 3) = step;
-         TREE_VEC_ELT (it, 4) = orig_step;
+         OMP_ITERATOR_STEP (it) = step;
+         OMP_ITERATOR_ORIG_STEP (it) = orig_step;
        }
     }
   return ret;
diff --git a/gcc/fortran/trans-openmp.cc b/gcc/fortran/trans-openmp.cc
index fce5d221fe98..e23f10d34a82 100644
--- a/gcc/fortran/trans-openmp.cc
+++ b/gcc/fortran/trans-openmp.cc
@@ -3549,10 +3549,10 @@ gfc_trans_omp_array_section (stmtblock_t *block, 
gfc_exec_op op,
   base = fold_convert (ptrdiff_type_node, base);
   for (tree it = iterator; it; it = TREE_CHAIN (it))
     {
-      ptr = simplify_replace_tree (ptr, TREE_VEC_ELT (it, 0),
-                                  TREE_VEC_ELT (it, 1));
-      base = simplify_replace_tree (base, TREE_VEC_ELT (it, 0),
-                                   TREE_VEC_ELT (it, 1));
+      ptr = simplify_replace_tree (ptr, OMP_ITERATOR_VAR (it),
+                                  OMP_ITERATOR_BEGIN (it));
+      base = simplify_replace_tree (base, OMP_ITERATOR_VAR (it),
+                                   OMP_ITERATOR_BEGIN (it));
     }
 
   /* The OMP_CLAUSE_SIZE field for the array data map clause node3
@@ -3570,10 +3570,10 @@ handle_iterator (gfc_namespace *ns, stmtblock_t 
*iter_block, tree block)
       gfc_constructor *c;
       gfc_se se;
 
-      tree last = make_tree_vec (6);
+      tree last = make_omp_iterator ();
       tree iter_var = gfc_get_symbol_decl (sym);
       tree type = TREE_TYPE (iter_var);
-      TREE_VEC_ELT (last, 0) = iter_var;
+      OMP_ITERATOR_VAR (last) = iter_var;
       DECL_CHAIN (iter_var) = BLOCK_VARS (block);
       BLOCK_VARS (block) = iter_var;
 
@@ -3583,18 +3583,18 @@ handle_iterator (gfc_namespace *ns, stmtblock_t 
*iter_block, tree block)
       gfc_conv_expr (&se, c->expr);
       gfc_add_block_to_block (iter_block, &se.pre);
       gfc_add_block_to_block (iter_block, &se.post);
-      TREE_VEC_ELT (last, 1) = fold_convert (type,
-                                            gfc_evaluate_now (se.expr,
-                                                              iter_block));
+      OMP_ITERATOR_BEGIN (last) = fold_convert (type,
+                                               gfc_evaluate_now (se.expr,
+                                                                 iter_block));
       /* end */
       c = gfc_constructor_next (c);
       gfc_init_se (&se, NULL);
       gfc_conv_expr (&se, c->expr);
       gfc_add_block_to_block (iter_block, &se.pre);
       gfc_add_block_to_block (iter_block, &se.post);
-      TREE_VEC_ELT (last, 2) = fold_convert (type,
-                                            gfc_evaluate_now (se.expr,
-                                                              iter_block));
+      OMP_ITERATOR_END (last) = fold_convert (type,
+                                             gfc_evaluate_now (se.expr,
+                                                               iter_block));
       /* step */
       c = gfc_constructor_next (c);
       tree step;
@@ -3611,9 +3611,9 @@ handle_iterator (gfc_namespace *ns, stmtblock_t 
*iter_block, tree block)
        }
       else
        step = build_int_cst (type, 1);
-      TREE_VEC_ELT (last, 3) = step;
+      OMP_ITERATOR_STEP (last) = step;
       /* orig_step */
-      TREE_VEC_ELT (last, 4) = save_expr (step);
+      OMP_ITERATOR_ORIG_STEP (last) = save_expr (step);
       TREE_CHAIN (last) = list;
       list = last;
     }
@@ -4200,7 +4200,7 @@ gfc_trans_omp_clauses (stmtblock_t *block, 
gfc_omp_clauses *clauses,
              if (iterator && prev->u2.ns != n->u2.ns)
                {
                  BLOCK_SUBBLOCKS (tree_block) = gfc_finish_block (&iter_block);
-                 TREE_VEC_ELT (iterator, 5) = tree_block;
+                 OMP_ITERATOR_BLOCK (iterator) = tree_block;
                  for (tree c = omp_clauses; c != prev_clauses;
                       c = OMP_CLAUSE_CHAIN (c))
                    OMP_CLAUSE_DECL (c) = build_tree_list (iterator,
@@ -4361,7 +4361,7 @@ gfc_trans_omp_clauses (stmtblock_t *block, 
gfc_omp_clauses *clauses,
          if (iterator)
            {
              BLOCK_SUBBLOCKS (tree_block) = gfc_finish_block (&iter_block);
-             TREE_VEC_ELT (iterator, 5) = tree_block;
+             OMP_ITERATOR_BLOCK (iterator) = tree_block;
              for (tree c = omp_clauses; c != prev_clauses;
                   c = OMP_CLAUSE_CHAIN (c))
                OMP_CLAUSE_DECL (c) = build_tree_list (iterator,
@@ -4411,7 +4411,7 @@ gfc_trans_omp_clauses (stmtblock_t *block, 
gfc_omp_clauses *clauses,
                {
                  /* Finish previous iterator group.  */
                  BLOCK_SUBBLOCKS (tree_block) = gfc_finish_block (&iter_block);
-                 TREE_VEC_ELT (iterator, 5) = tree_block;
+                 OMP_ITERATOR_BLOCK (iterator) = tree_block;
                  for (tree c = omp_clauses; c != prev_clauses;
                       c = OMP_CLAUSE_CHAIN (c))
                    if (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FIRSTPRIVATE_POINTER
@@ -5313,7 +5313,7 @@ gfc_trans_omp_clauses (stmtblock_t *block, 
gfc_omp_clauses *clauses,
            {
              /* Finish last iterator group.  */
              BLOCK_SUBBLOCKS (tree_block) = gfc_finish_block (&iter_block);
-             TREE_VEC_ELT (iterator, 5) = tree_block;
+             OMP_ITERATOR_BLOCK (iterator) = tree_block;
              for (tree c = omp_clauses; c != prev_clauses;
                   c = OMP_CLAUSE_CHAIN (c))
                if (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FIRSTPRIVATE_POINTER
@@ -5337,7 +5337,7 @@ gfc_trans_omp_clauses (stmtblock_t *block, 
gfc_omp_clauses *clauses,
                {
                  /* Finish previous iterator group.  */
                  BLOCK_SUBBLOCKS (tree_block) = gfc_finish_block (&iter_block);
-                 TREE_VEC_ELT (iterator, 5) = tree_block;
+                 OMP_ITERATOR_BLOCK (iterator) = tree_block;
                  for (tree c = omp_clauses; c != prev_clauses;
                       c = OMP_CLAUSE_CHAIN (c))
                    OMP_CLAUSE_ITERATORS (c) = iterator;
@@ -5457,7 +5457,7 @@ gfc_trans_omp_clauses (stmtblock_t *block, 
gfc_omp_clauses *clauses,
            {
              /* Finish last iterator group.  */
              BLOCK_SUBBLOCKS (tree_block) = gfc_finish_block (&iter_block);
-             TREE_VEC_ELT (iterator, 5) = tree_block;
+             OMP_ITERATOR_BLOCK (iterator) = tree_block;
              for (tree c = omp_clauses; c != prev_clauses;
                   c = OMP_CLAUSE_CHAIN (c))
                OMP_CLAUSE_ITERATORS (c) = iterator;
diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc
index 6b21116ce56e..f80a100085bc 100644
--- a/gcc/gimplify.cc
+++ b/gcc/gimplify.cc
@@ -9759,19 +9759,19 @@ gimplify_omp_affinity (tree *list_p, gimple_seq *pre_p)
                  }
                for (tree it = TREE_PURPOSE (t); it; it = TREE_CHAIN (it))
                  {
-                   if (gimplify_expr (&TREE_VEC_ELT (it, 1), pre_p, NULL,
+                   if (gimplify_expr (&OMP_ITERATOR_BEGIN (it), pre_p, NULL,
                                       is_gimple_val, fb_rvalue) == GS_ERROR
-                       || gimplify_expr (&TREE_VEC_ELT (it, 2), pre_p, NULL,
+                       || gimplify_expr (&OMP_ITERATOR_END (it), pre_p, NULL,
                                          is_gimple_val, fb_rvalue) == GS_ERROR
-                       || gimplify_expr (&TREE_VEC_ELT (it, 3), pre_p, NULL,
+                       || gimplify_expr (&OMP_ITERATOR_STEP (it), pre_p, NULL,
                                          is_gimple_val, fb_rvalue) == GS_ERROR
-                       || (gimplify_expr (&TREE_VEC_ELT (it, 4), pre_p, NULL,
-                                          is_gimple_val, fb_rvalue)
+                       || (gimplify_expr (&OMP_ITERATOR_ORIG_STEP (it), pre_p,
+                                          NULL, is_gimple_val, fb_rvalue)
                            == GS_ERROR))
                      return;
                  }
            last_iter = TREE_PURPOSE (t);
-           tree block = TREE_VEC_ELT (TREE_PURPOSE (t), 5);
+           tree block = OMP_ITERATOR_BLOCK (TREE_PURPOSE (t));
            last_bind = build3 (BIND_EXPR, void_type_node, BLOCK_VARS (block),
                                NULL, block);
            last_body = &BIND_EXPR_BODY (last_bind);
@@ -9779,10 +9779,10 @@ gimplify_omp_affinity (tree *list_p, gimple_seq *pre_p)
            location_t loc = OMP_CLAUSE_LOCATION (c);
            for (tree it = TREE_PURPOSE (t); it; it = TREE_CHAIN (it))
              {
-               tree var = TREE_VEC_ELT (it, 0);
-               tree begin = TREE_VEC_ELT (it, 1);
-               tree end = TREE_VEC_ELT (it, 2);
-               tree step = TREE_VEC_ELT (it, 3);
+               tree var = OMP_ITERATOR_VAR (it);
+               tree begin = OMP_ITERATOR_BEGIN (it);
+               tree end = OMP_ITERATOR_END (it);
+               tree step = OMP_ITERATOR_STEP (it);
                loc = DECL_SOURCE_LOCATION (var);
                tree tem = build2_loc (loc, MODIFY_EXPR, void_type_node,
                                       var, begin);
@@ -9859,20 +9859,20 @@ compute_omp_iterator_count (tree it, gimple_seq *pre_p)
   tree tcnt = size_one_node;
   for (; it; it = TREE_CHAIN (it))
     {
-      if (gimplify_expr (&TREE_VEC_ELT (it, 1), pre_p, NULL,
+      if (gimplify_expr (&OMP_ITERATOR_BEGIN (it), pre_p, NULL,
                         is_gimple_val, fb_rvalue) == GS_ERROR
-         || gimplify_expr (&TREE_VEC_ELT (it, 2), pre_p, NULL,
+         || gimplify_expr (&OMP_ITERATOR_END (it), pre_p, NULL,
                            is_gimple_val, fb_rvalue) == GS_ERROR
-         || gimplify_expr (&TREE_VEC_ELT (it, 3), pre_p, NULL,
+         || gimplify_expr (&OMP_ITERATOR_STEP (it), pre_p, NULL,
                            is_gimple_val, fb_rvalue) == GS_ERROR
-         || (gimplify_expr (&TREE_VEC_ELT (it, 4), pre_p, NULL,
+         || (gimplify_expr (&OMP_ITERATOR_ORIG_STEP (it), pre_p, NULL,
                             is_gimple_val, fb_rvalue) == GS_ERROR))
        return NULL_TREE;
-      tree var = TREE_VEC_ELT (it, 0);
-      tree begin = TREE_VEC_ELT (it, 1);
-      tree end = TREE_VEC_ELT (it, 2);
-      tree step = TREE_VEC_ELT (it, 3);
-      tree orig_step = TREE_VEC_ELT (it, 4);
+      tree var = OMP_ITERATOR_VAR (it);
+      tree begin = OMP_ITERATOR_BEGIN (it);
+      tree end = OMP_ITERATOR_END (it);
+      tree step = OMP_ITERATOR_STEP (it);
+      tree orig_step = OMP_ITERATOR_ORIG_STEP (it);
       tree type = TREE_TYPE (var);
       tree stype = TREE_TYPE (step);
       location_t loc = DECL_SOURCE_LOCATION (var);
@@ -9940,7 +9940,7 @@ build_omp_iterator_loop (tree it, gimple_seq *pre_p, tree 
*last_bind)
 {
   if (*last_bind)
     gimplify_and_add (*last_bind, pre_p);
-  tree block = TREE_VEC_ELT (it, 5);
+  tree block = OMP_ITERATOR_BLOCK (it);
   tree block_stmts = lang_GNU_Fortran () ? BLOCK_SUBBLOCKS (block) : NULL_TREE;
   *last_bind = build3 (BIND_EXPR, void_type_node,
                       BLOCK_VARS (block), NULL, block);
@@ -9948,12 +9948,12 @@ build_omp_iterator_loop (tree it, gimple_seq *pre_p, 
tree *last_bind)
   tree *p = &BIND_EXPR_BODY (*last_bind);
   for (; it; it = TREE_CHAIN (it))
     {
-      tree var = TREE_VEC_ELT (it, 0);
-      tree begin = TREE_VEC_ELT (it, 1);
-      tree end = TREE_VEC_ELT (it, 2);
-      tree step = TREE_VEC_ELT (it, 3);
-      tree orig_step = TREE_VEC_ELT (it, 4);
-      block = TREE_VEC_ELT (it, 5);
+      tree var = OMP_ITERATOR_VAR (it);
+      tree begin = OMP_ITERATOR_BEGIN (it);
+      tree end = OMP_ITERATOR_END (it);
+      tree step = OMP_ITERATOR_STEP (it);
+      tree orig_step = OMP_ITERATOR_ORIG_STEP (it);
+      block = OMP_ITERATOR_BLOCK (it);
       tree type = TREE_TYPE (var);
       location_t loc = DECL_SOURCE_LOCATION (var);
       /* Emit:
@@ -10029,17 +10029,17 @@ find_var_decl (tree *tp, int *, void *data)
   return NULL_TREE;
 }
 
-/* Returns an element-by-element copy of OMP iterator tree IT.  */
-
+/* Returns an element-by-element copy of OMP iterator tree IT.  If
+   EXPAND is true, force the result to be an expanded iterator; otherwise
+   it makes the copy the same size as IT.  */
 static tree
-copy_omp_iterator (tree it, int elem_count = -1)
+copy_omp_iterator (tree it, bool expand = false)
 {
-  if (elem_count < 0)
-    elem_count = TREE_VEC_LENGTH (it);
-  tree new_it = make_tree_vec (elem_count);
+  int elem_count = TREE_VEC_LENGTH (it);
+  tree new_it =
+    (expand ? make_expanded_omp_iterator () : make_tree_vec (elem_count));
   for (int i = 0; i < TREE_VEC_LENGTH (it); i++)
     TREE_VEC_ELT (new_it, i) = TREE_VEC_ELT (it, i);
-
   return new_it;
 }
 
@@ -10084,7 +10084,7 @@ remove_unused_omp_iterator_vars (tree *list_p)
       bool need_new_iterators = false;
       for (tree it = OMP_CLAUSE_ITERATORS (c); it; it = TREE_CHAIN (it))
        {
-         tree var = TREE_VEC_ELT (it, 0);
+         tree var = OMP_ITERATOR_VAR (it);
          tree t = walk_tree (&OMP_CLAUSE_DECL (c), find_var_decl, var, NULL);
          if (t == NULL_TREE)
            t = walk_tree (&OMP_CLAUSE_SIZE (c), find_var_decl, var, NULL);
@@ -10130,7 +10130,7 @@ remove_unused_omp_iterator_vars (tree *list_p)
          for (tree it = OMP_CLAUSE_ITERATORS (c); it && i < vars.length();
               it = TREE_CHAIN (it))
            {
-             tree var = TREE_VEC_ELT (it, 0);
+             tree var = OMP_ITERATOR_VAR (it);
              if (var == vars[i])
                {
                  *new_iters_p = copy_omp_iterator (it);
@@ -10138,13 +10138,13 @@ remove_unused_omp_iterator_vars (tree *list_p)
                                            DECL_NAME (var), TREE_TYPE (var));
                  DECL_ARTIFICIAL (*new_vars_p) = 1;
                  DECL_CONTEXT (*new_vars_p) = DECL_CONTEXT (var);
-                 TREE_VEC_ELT (*new_iters_p, 0) = *new_vars_p;
+                 OMP_ITERATOR_VAR (*new_iters_p) = *new_vars_p;
                  new_iters_p = &TREE_CHAIN (*new_iters_p);
                  new_vars_p = &DECL_CHAIN (*new_vars_p);
                  i++;
                }
            }
-         tree old_block = TREE_VEC_ELT (OMP_CLAUSE_ITERATORS (c), 5);
+         tree old_block = OMP_ITERATOR_BLOCK (OMP_CLAUSE_ITERATORS (c));
          tree new_block = make_node (BLOCK);
          BLOCK_VARS (new_block) = new_vars;
          if (BLOCK_SUBBLOCKS (old_block))
@@ -10152,7 +10152,7 @@ remove_unused_omp_iterator_vars (tree *list_p)
              BLOCK_SUBBLOCKS (new_block) = BLOCK_SUBBLOCKS (old_block);
              BLOCK_SUBBLOCKS (old_block) = NULL_TREE;
            }
-         TREE_VEC_ELT (new_iters, 5) = new_block;
+         OMP_ITERATOR_BLOCK (new_iters) = new_block;
          new_iterators.safe_push (new_iters);
          iter_vars.safe_push (vars.copy ());
          OMP_CLAUSE_ITERATORS (c) = new_iters;
@@ -10163,7 +10163,7 @@ remove_unused_omp_iterator_vars (tree *list_p)
       for (tree it = OMP_CLAUSE_ITERATORS (c); it; it = TREE_CHAIN (it))
        {
          tree old_var = vars[i++];
-         tree new_var = TREE_VEC_ELT (it, 0);
+         tree new_var = OMP_ITERATOR_VAR (it);
          remap_omp_iterator_var (&OMP_CLAUSE_DECL (c), old_var, new_var);
          remap_omp_iterator_var (&OMP_CLAUSE_SIZE (c), old_var, new_var);
        }
@@ -10268,12 +10268,10 @@ build_omp_iterators_loops (tree *list_p, gimple_seq 
*loops_seq_p)
       gimplify_and_add (tem, loops_seq_p);
 
       /* Make a copy of the iterator with extra info at the end.  */
-      int elem_count = TREE_VEC_LENGTH (OMP_CLAUSE_ITERATORS (c));
-      tree new_iterator = copy_omp_iterator (OMP_CLAUSE_ITERATORS (c),
-                                            elem_count + 3);
-      TREE_VEC_ELT (new_iterator, elem_count) = loop.body_label;
-      TREE_VEC_ELT (new_iterator, elem_count + 1) = elems;
-      TREE_VEC_ELT (new_iterator, elem_count + 2) = loop.index;
+      tree new_iterator = copy_omp_iterator (OMP_CLAUSE_ITERATORS (c), true);
+      OMP_ITERATOR_LABEL (new_iterator) = loop.body_label;
+      OMP_ITERATOR_INDEX (new_iterator) = loop.index;
+      OMP_ITERATOR_ELEMS (new_iterator) = elems;
       TREE_CHAIN (new_iterator) = TREE_CHAIN (OMP_CLAUSE_ITERATORS (c));
       OMP_CLAUSE_ITERATORS (c) = new_iterator;
 
@@ -10324,7 +10322,7 @@ enter_omp_iterator_loop_context_1 (tree iterator, 
gimple_seq *loops_seq_p)
          {
            glabel *label_stmt = as_a<glabel *> (stmt);
            tree label = gimple_label_label (label_stmt);
-           if (label == TREE_VEC_ELT (iterator, 6))
+           if (label == OMP_ITERATOR_LABEL (iterator))
              return loops_seq_p;
          }
          break;
@@ -10846,8 +10844,8 @@ extract_base_bit_offset (tree base, poly_int64 *bitposp,
         actual locations of the iterated mappings are elsewhere.  */
       tree it;
       for (it = iterator; it; it = TREE_CHAIN (it))
-       base = simplify_replace_tree (base, TREE_VEC_ELT (it, 0),
-                                     TREE_VEC_ELT (it, 1));
+       base = simplify_replace_tree (base, OMP_ITERATOR_VAR (it),
+                                     OMP_ITERATOR_BEGIN (it));
     }
 
   base = get_inner_reference (base, &bitsize, &bitpos, &offset, &mode,
diff --git a/gcc/omp-low.cc b/gcc/omp-low.cc
index 52d73d204142..d0be7989cf53 100644
--- a/gcc/omp-low.cc
+++ b/gcc/omp-low.cc
@@ -12712,8 +12712,8 @@ lower_omp_map_iterator_expr (tree expr, tree c, 
gomp_target *stmt)
     return expr;
 
   tree iterator = OMP_CLAUSE_ITERATORS (c);
-  tree elems = TREE_VEC_ELT (iterator, 7);
-  tree index = TREE_VEC_ELT (iterator, 8);
+  tree index = OMP_ITERATOR_INDEX (iterator);
+  tree elems = OMP_ITERATOR_ELEMS (iterator);
   gimple_seq *loop_body_p = enter_omp_iterator_loop_context (c, stmt);
 
    /* IN LOOP BODY:  */
@@ -12740,8 +12740,8 @@ lower_omp_map_iterator_size (tree size, tree c, 
gomp_target *stmt)
     return size;
 
   tree iterator = OMP_CLAUSE_ITERATORS (c);
-  tree elems = TREE_VEC_ELT (iterator, 7);
-  tree index = TREE_VEC_ELT (iterator, 8);
+  tree index = OMP_ITERATOR_INDEX (iterator);
+  tree elems = OMP_ITERATOR_ELEMS (iterator);
   gimple_seq *loop_body_p = enter_omp_iterator_loop_context (c, stmt);
 
   /* IN LOOP BODY:  */
diff --git a/gcc/tree-inline.cc b/gcc/tree-inline.cc
index df5597ef30dd..c0dff62a38b2 100644
--- a/gcc/tree-inline.cc
+++ b/gcc/tree-inline.cc
@@ -1475,8 +1475,8 @@ copy_tree_body_r (tree *tp, int *walk_subtrees, void 
*data)
              for (int i = 0; i <= 4; i++)
                walk_tree (&TREE_VEC_ELT (TREE_PURPOSE (t), i),
                           copy_tree_body_r, id, NULL);
-             if (TREE_VEC_ELT (TREE_PURPOSE (t), 5))
-               remap_block (&TREE_VEC_ELT (TREE_PURPOSE (t), 5), id);
+             if (OMP_ITERATOR_BLOCK (TREE_PURPOSE (t)))
+               remap_block (&OMP_ITERATOR_BLOCK (TREE_PURPOSE (t)), id);
              walk_tree (&TREE_VALUE (t), copy_tree_body_r, id, NULL);
            }
        }
diff --git a/gcc/tree-pretty-print.cc b/gcc/tree-pretty-print.cc
index 0674a27501bf..9d3cb4d81bd3 100644
--- a/gcc/tree-pretty-print.cc
+++ b/gcc/tree-pretty-print.cc
@@ -437,25 +437,26 @@ dump_omp_iterators (pretty_printer *pp, tree iter, int 
spc, dump_flags_t flags)
     {
       if (it != iter)
        pp_string (pp, ", ");
-      dump_generic_node (pp, TREE_TYPE (TREE_VEC_ELT (it, 0)), spc, flags,
+      dump_generic_node (pp, TREE_TYPE (OMP_ITERATOR_VAR (it)), spc, flags,
                         false);
       pp_space (pp);
-      dump_generic_node (pp, TREE_VEC_ELT (it, 0), spc, flags, false);
+      dump_generic_node (pp, OMP_ITERATOR_VAR (it), spc, flags, false);
       pp_equal (pp);
-      dump_generic_node (pp, TREE_VEC_ELT (it, 1), spc, flags, false);
+      dump_generic_node (pp, OMP_ITERATOR_BEGIN (it), spc, flags, false);
       pp_colon (pp);
-      dump_generic_node (pp, TREE_VEC_ELT (it, 2), spc, flags, false);
+      dump_generic_node (pp, OMP_ITERATOR_END (it), spc, flags, false);
       pp_colon (pp);
-      dump_generic_node (pp, TREE_VEC_ELT (it, 3), spc, flags, false);
+      dump_generic_node (pp, OMP_ITERATOR_STEP (it), spc, flags, false);
     }
-  if (TREE_VEC_LENGTH (iter) > 6)
+  if (OMP_ITERATOR_EXPANDED_P (iter))
     {
       pp_string (pp, ", loop_label=");
-      dump_generic_node (pp, TREE_VEC_ELT (iter, 6), spc, flags, false);
+      dump_generic_node (pp, OMP_ITERATOR_LABEL (iter), spc, flags, false);
       pp_string (pp, ", elems=");
-      dump_generic_node (pp, TREE_VEC_ELT (iter, 7), spc, flags, false);
+      dump_generic_node (pp, OMP_ITERATOR_ELEMS (iter), spc, flags, false);
       pp_string (pp, ", index=");
-      dump_generic_node (pp, TREE_VEC_ELT (iter, 8), spc, flags, false);
+      dump_generic_node (pp, OMP_ITERATOR_INDEX (iter), spc, flags, false);
+      /* The count field is not used yet.  */
     }
   pp_right_paren (pp);
 }
diff --git a/gcc/tree.h b/gcc/tree.h
index f8b2d718b7ee..9976df44d0f8 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -1687,6 +1687,24 @@ class auto_suppress_location_wrappers
                                              OMP_CLAUSE_FROM,          \
                                              OMP_CLAUSE_MAP), 2)
 
+/* An iterator modifier on a clause is represented as a vector.
+   Unexpanded iterators produced by the front-end parsers have 6
+   elements; after expansion, they have 10.  See also the
+   make_omp_iterator and make_expanded_omp_iterator constructors
+   below.  */
+#define OMP_ITERATOR_VAR(NODE)         TREE_VEC_ELT (NODE, 0)
+#define OMP_ITERATOR_BEGIN(NODE)       TREE_VEC_ELT (NODE, 1)
+#define OMP_ITERATOR_END(NODE)         TREE_VEC_ELT (NODE, 2)
+#define OMP_ITERATOR_STEP(NODE)        TREE_VEC_ELT (NODE, 3)
+#define OMP_ITERATOR_ORIG_STEP(NODE)   TREE_VEC_ELT (NODE, 4)
+#define OMP_ITERATOR_BLOCK(NODE)       TREE_VEC_ELT (NODE, 5)
+#define OMP_ITERATOR_LABEL(NODE)       TREE_VEC_ELT (NODE, 6)
+#define OMP_ITERATOR_INDEX(NODE)       TREE_VEC_ELT (NODE, 7)
+#define OMP_ITERATOR_ELEMS(NODE)       TREE_VEC_ELT (NODE, 8)
+#define OMP_ITERATOR_COUNT(NODE)       TREE_VEC_ELT (NODE, 9)
+
+#define OMP_ITERATOR_EXPANDED_P(NODE)  (TREE_VEC_LENGTH (NODE) > 6)
+
 /* True on OMP_FOR and other OpenMP/OpenACC looping constructs if the loop nest
    is non-rectangular.  */
 #define OMP_FOR_NON_RECTANGULAR(NODE) \
@@ -7197,4 +7215,18 @@ extern bool disjoint_version_decls (tree, tree);
 /* Checks if two overlapping decls are not mergeable.  */
 extern bool diagnose_versioned_decls (tree, tree);
 
+/* Make a vector to hold an unexpanded omp iterator vector.  */
+inline tree
+make_omp_iterator (void)
+{
+  return make_tree_vec (6);
+}
+
+/* Make a vector to hold an expanded omp iterator vector.  */
+inline tree
+make_expanded_omp_iterator (void)
+{
+  return make_tree_vec (10);
+}
+
 #endif  /* GCC_TREE_H  */

Reply via email to