On 6/5/26 09:38, Tobias Burnus wrote:
[snip]
LGTM. — I hope we haven't missed any iterator accesses in this cleanup!
I checked and found some in cp/pt.cc that had escaped previous versions
of the patch. I also refactored this patch with respect to the part 6
patch in the series that had preceded it, so that I could get it in to
improve the readability of the code and help debugging the problems you
noted in your part 6 review. I've pushed the attached version.
-Sandra
From 19bc99cb9c0f85da79bee41fabf40461b64d2cd1 Mon Sep 17 00:00:00 2001
From: Kwok Cheung Yeung <[email protected]>
Date: Sun, 7 Jun 2026 01:37:18 +0000
Subject: [PUSHED] 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]>
---
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 cf13bc2d796..b532dcb8a1a 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -20397,11 +20397,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))
@@ -20466,7 +20466,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));
@@ -20597,7 +20597,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))
@@ -21041,7 +21041,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))
@@ -21470,7 +21470,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 0f96de20074..c8127cc1f05 100644
--- a/gcc/c/c-typeck.cc
+++ b/gcc/c/c-typeck.cc
@@ -16499,10 +16499,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);
@@ -16576,10 +16576,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 };
@@ -16614,10 +16614,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 1ce591666fe..8194106c6e9 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -44889,11 +44889,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))
@@ -44967,7 +44967,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));
@@ -45106,7 +45106,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))
@@ -45374,7 +45374,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)
@@ -45788,7 +45788,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 c260f965da1..f7aa1022680 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -18698,16 +18698,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 5610fd6b678..684c6550345 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 fd4b19f6626..0f368d3d805 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,
@@ -4418,7 +4418,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
@@ -5320,7 +5320,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
@@ -5344,7 +5344,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;
@@ -5464,7 +5464,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 b1f263a0826..8f64979571b 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);
}
@@ -10127,12 +10127,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;
@@ -10183,7 +10181,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;
@@ -10705,8 +10703,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 eef0b418b9b..6e4cff502d2 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 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 0674a27501b..9d3cb4d81bd 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 6aacb4df7c8..73a26dbe75c 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) \
@@ -7240,4 +7258,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