From: Kwok Cheung Yeung <[email protected]>

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.
        * 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.
        (allocate_omp_iterator_elems): Likewise.
        (free_omp_iterator_elems): 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]>
---
 gcc/c/c-parser.cc           | 18 +++----
 gcc/c/c-typeck.cc           | 24 +++++-----
 gcc/cp/parser.cc            | 18 +++----
 gcc/cp/semantics.cc         | 26 +++++-----
 gcc/fortran/trans-openmp.cc | 40 ++++++++--------
 gcc/gimplify.cc             | 96 ++++++++++++++++++-------------------
 gcc/omp-low.cc              | 17 +++----
 gcc/tree-inline.cc          |  4 +-
 gcc/tree-pretty-print.cc    | 20 ++++----
 gcc/tree.h                  | 32 +++++++++++++
 10 files changed, 163 insertions(+), 132 deletions(-)

diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index 6e8688d33ea..af9d48b89bf 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -20335,11 +20335,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))
@@ -20404,7 +20404,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));
@@ -20535,7 +20535,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))
@@ -20979,7 +20979,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))
@@ -21408,7 +21408,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 3606fc66abf..33d8dca3bc9 100644
--- a/gcc/c/c-typeck.cc
+++ b/gcc/c/c-typeck.cc
@@ -16497,10 +16497,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);
@@ -16574,10 +16574,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 };
@@ -16612,10 +16612,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 86b5e89214d..2ab4d7d968f 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -44864,11 +44864,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))
@@ -44942,7 +44942,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));
@@ -45081,7 +45081,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))
@@ -45349,7 +45349,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)
@@ -45763,7 +45763,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/semantics.cc b/gcc/cp/semantics.cc
index 42278d336bf..6ba73090ca1 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 43697e99453..390bc67c4bf 100644
--- a/gcc/fortran/trans-openmp.cc
+++ b/gcc/fortran/trans-openmp.cc
@@ -3498,10 +3498,10 @@ gfc_trans_omp_array_section (stmtblock_t *block, 
gfc_exec_op op,
   ptr2 = fold_convert (ptrdiff_type_node, ptr2);
   for (tree it = iterator; it; it = TREE_CHAIN (it))
     {
-      ptr = simplify_replace_tree (ptr, TREE_VEC_ELT (it, 0),
-                                  TREE_VEC_ELT (it, 1));
-      ptr2 = simplify_replace_tree (ptr2, TREE_VEC_ELT (it, 0),
-                                   TREE_VEC_ELT (it, 1));
+      ptr = simplify_replace_tree (ptr, OMP_ITERATOR_VAR (it),
+                                  OMP_ITERATOR_BEGIN (it));
+      ptr2 = simplify_replace_tree (ptr2, OMP_ITERATOR_VAR (it),
+                                   OMP_ITERATOR_BEGIN (it));
     }
   OMP_CLAUSE_SIZE (node3) = fold_build2 (MINUS_EXPR, ptrdiff_type_node,
                                         ptr, ptr2);
@@ -3516,10 +3516,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;
 
@@ -3529,18 +3529,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;
@@ -3557,9 +3557,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;
     }
@@ -4146,7 +4146,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,
@@ -4307,7 +4307,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,
@@ -4357,7 +4357,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
@@ -5259,7 +5259,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
@@ -5283,7 +5283,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;
@@ -5403,7 +5403,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 5efe59bc3ca..aa421a326bc 100644
--- a/gcc/gimplify.cc
+++ b/gcc/gimplify.cc
@@ -9618,19 +9618,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);
@@ -9638,10 +9638,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);
@@ -9718,20 +9718,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);
@@ -9799,7 +9799,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);
@@ -9807,12 +9807,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:
@@ -9888,17 +9888,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;
 }
 
@@ -9943,7 +9943,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);
@@ -9989,7 +9989,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);
@@ -9997,13 +9997,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))
@@ -10011,7 +10011,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;
@@ -10022,7 +10022,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);
        }
@@ -10132,13 +10132,11 @@ 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 + 4);
-      TREE_VEC_ELT (new_iterator, elem_count) = loop.body_label;
-      TREE_VEC_ELT (new_iterator, elem_count + 1) = loop.index;
-      TREE_VEC_ELT (new_iterator, elem_count + 2) = elems;
-      TREE_VEC_ELT (new_iterator, elem_count + 3) = loop.count;
+      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;
+      OMP_ITERATOR_COUNT (new_iterator) = loop.count;
       TREE_CHAIN (new_iterator) = TREE_CHAIN (OMP_CLAUSE_ITERATORS (c));
       OMP_CLAUSE_ITERATORS (c) = new_iterator;
 
@@ -10189,7 +10187,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;
@@ -10711,8 +10709,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 ce2f4b1ed93..1bbac08114c 100644
--- a/gcc/omp-low.cc
+++ b/gcc/omp-low.cc
@@ -12703,8 +12703,8 @@ lower_omp_map_iterator_expr (tree expr, tree c, 
gomp_target *stmt)
     return expr;
 
   tree iterator = OMP_CLAUSE_ITERATORS (c);
-  tree index = TREE_VEC_ELT (iterator, 7);
-  tree elems = 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:  */
@@ -12741,8 +12741,8 @@ lower_omp_map_iterator_size (tree size, tree c, 
gomp_target *stmt)
     return size;
 
   tree iterator = OMP_CLAUSE_ITERATORS (c);
-  tree index = TREE_VEC_ELT (iterator, 7);
-  tree elems = 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:  */
@@ -12776,10 +12776,11 @@ allocate_omp_iterator_elems (tree clauses, gimple_seq 
loops_seq)
       if (!OMP_CLAUSE_HAS_ITERATORS (c))
        continue;
       tree iters = OMP_CLAUSE_ITERATORS (c);
-      tree elems = TREE_VEC_ELT (iters, 8);
+      tree elems = OMP_ITERATOR_ELEMS (iters);
       if (!POINTER_TYPE_P (TREE_TYPE (elems)))
        continue;
-      tree arr_length = omp_iterator_elems_length (TREE_VEC_ELT (iters, 9));
+      tree arr_length
+       = omp_iterator_elems_length (OMP_ITERATOR_COUNT (iters));
       tree call = builtin_decl_explicit (BUILT_IN_MALLOC);
       tree size = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MULT_EXPR,
                                   size_type_node, arr_length,
@@ -12788,7 +12789,7 @@ allocate_omp_iterator_elems (tree clauses, gimple_seq 
loops_seq)
                                      size);
 
       /* Find the first statement '<index> = -1' in the pre-loop statements.  
*/
-      tree index = TREE_VEC_ELT (iters, 7);
+      tree index = OMP_ITERATOR_INDEX (iters);
       gimple_stmt_iterator gsi;
       for (gsi = gsi_start (loops_seq); !gsi_end_p (gsi); gsi_next (&gsi))
        {
@@ -12813,7 +12814,7 @@ free_omp_iterator_elems (tree clauses, gimple_seq *seq)
     {
       if (!OMP_CLAUSE_HAS_ITERATORS (c))
        continue;
-      tree elems = TREE_VEC_ELT (OMP_CLAUSE_ITERATORS (c), 8);
+      tree elems = OMP_ITERATOR_ELEMS (OMP_CLAUSE_ITERATORS (c));
       if (!POINTER_TYPE_P (TREE_TYPE (elems)))
        continue;
       tree call = builtin_decl_explicit (BUILT_IN_FREE);
diff --git a/gcc/tree-inline.cc b/gcc/tree-inline.cc
index 302ab8d6b7c..0610af5f3f0 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 b8769d5a071..f0bcbb206a1 100644
--- a/gcc/tree-pretty-print.cc
+++ b/gcc/tree-pretty-print.cc
@@ -437,27 +437,27 @@ 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, ", index=");
-      dump_generic_node (pp, TREE_VEC_ELT (iter, 7), spc, flags, false);
+      dump_generic_node (pp, OMP_ITERATOR_INDEX (iter), spc, flags, false);
       pp_string (pp, ", elems=");
-      dump_generic_node (pp, TREE_VEC_ELT (iter, 8), spc, flags, false);
+      dump_generic_node (pp, OMP_ITERATOR_ELEMS (iter), spc, flags, false);
       pp_string (pp, ", elems_count=");
-      dump_generic_node (pp, TREE_VEC_ELT (iter, 9), spc, flags, false);
+      dump_generic_node (pp, OMP_ITERATOR_COUNT (iter), spc, flags, false);
     }
   pp_right_paren (pp);
 }
diff --git a/gcc/tree.h b/gcc/tree.h
index 415404cfbf4..20d28e93ba8 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -1699,6 +1699,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) \
@@ -7218,4 +7236,18 @@ extern tree unshare_expr_without_location (tree);
 
 extern void copy_if_shared (tree *, void * = NULL);
 
+/* 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  */
-- 
2.39.5


Reply via email to