gcc/gcc/tree-iterator.c
Diego Novillo 50674e968a tree-pretty-print.c (dump_generic_node): Handle OMP_PARALLEL_FN, OMP_PARALLEL_DATA_ARG and OMP_RETURN_EXPR.
* tree-pretty-print.c (dump_generic_node): Handle
	OMP_PARALLEL_FN, OMP_PARALLEL_DATA_ARG and OMP_RETURN_EXPR.
	* cgraph.c (cgraph_expand_queue): Rename from
	cgraph_analyze_queue.
	Update all users.
	* cgraphunit.c (cgraph_assemble_pending_functions): Process
	cgraph_expand_queue.
	(cgraph_expand_all_functions): Likewise.
	(cgraph_finalize_pending_functions): Remove.  Update callers.

	* tree.h (OMP_DIRECTIVE_P): Define.
	(OMP_PARALLEL_FN): Define.
	(OMP_PARALLEL_DATA_ARG): Define.
	(OMP_SECTIONS_SECTIONS): Define.
	* tree-pass.h (pass_expand_omp): Declare.
	* omp-low.c (struct omp_region): Declare.
	(struct omp_context): Remove fields 'parallel_type',
	'parallel_start_ix' and 'parallel_start_additional_args'.
	Update all users.
	(struct omp_for_data): Rename from struct expand_omp_for_data.
	(omp_regions): New static variable.
	(root_omp_region): New static variable.
	(find_omp_clause): Make static.
	(is_in_combined_parallel_ctx): Remove.
	(is_combined_parallel): New.
	(extract_omp_for_data): Move earlier in the file.
	(workshare_safe_to_combine_p): New.
	(get_ws_args_for): New.
	(determine_parallel_type): Move earlier in the file.
	(omp_copy_decl_2): Do not set DECL_CONTEXT of new local to the
	child function.
	(omp_copy_decl): Likewise.
	(create_omp_child_function): Likewise.
	(lookup_omp_region): New.
	(dump_omp_region): New.
	(debug_omp_region): New.
	(debug_all_omp_regions): New.
	(new_omp_region): New.
	(scan_omp_parallel): If parallel_nesting_level > 1, the
	directive is nested within another parallel directive.
	Set OMP_PARALLEL_FN.
	(scan_omp_for): Do not try to handle combined parallel+for
	cases.
	Remove FIXME comment.
	(scan_omp_nested): Remove.
	(scan_omp_1): Do not call scan_omp_nested when
	parallel_nesting_level is > 1.
	Do not change the DECL_CONTEXT of local variables found.
	(lookup_decl_in_outer_ctx): New.
	(lower_rec_input_clauses): Rename from expand_rec_input_clauses.
	(lower_lastprivate_clauses): Rename from expand_lastprivate_clauses.
	(lower_reduction_clauses): Rename from expand_reduction_clauses.
	(lower_copyprivate_clauses): Rename from expand_copyprivate_clauses.
	If CTX is nested, lookup VAR in the outer context when
	building copy assignment.
	(lower_send_clauses): Rename from expand_send_clauses.
	If CTX is nested, lookup VAR in the outer context when
	building copy assignments.
	(lower_send_shared_vars): Rename from expand_send_shared_vars.
	If CTX is nested, lookup VAR in the outer context when
	building copy assignments.
	(expand_parallel_call): Rename from build_parallel_call.
	Handle combined parallel+workshare cases.
	Re-implement to emit code into the CFG.
	(list2chain): New.
	(expand_omp_parallel): Re-implement to emit code into the CFG.
	Call move_sese_region_to_fn to outline the sub-graph
	containing the parallel region.
	(expand_omp_for_1): Remove.
	(expand_omp_for_generic): Re-implement to emit code into the
	CFG.
	(expand_omp_for_static_nochunk): Likewise.
	(expand_omp_for_static_chunk): Likewise.
	(expand_omp_for): Likewise.
	(expand_omp_sections): Likewise.
	(remove_exit_barriers): New.
	(expand_omp_synch): New.
	(expand_omp): New.
	(build_omp_regions_1): New.
	(build_omp_regions): New.
	(execute_expand_omp): New.
	(gate_expand_omp): New.
	(pass_expand_omp): Define.
	(lower_omp_sections): Rename from expand_omp_sections.
	Set OMP_SECTIONS_SECTIONS.
	(lower_omp_single_simple): Rename from expand_omp_single_simple.
	(lower_omp_single_copy): Rename from expand_omp_single_copy.
	(lower_omp_single): Rename from expand_omp_simple.
	(lower_omp_master): Rename from expand_omp_master.
	(lower_omp_ordered): Rename from expand_omp_ordered.
	(lower_omp_critical): Rename from expand_omp_critical.
	(lower_omp_for_lastprivate): Rename from expand_omp_for_lastprivate.
	(lower_omp_for): Re-implement.
	(lower_omp_parallel): Re-implement.
	(lower_regimplify): Rename from expand_regimplify.
	(lower_omp_1): Rename from expand_omp_1.
	If there are syntax errors in the program, replace every
	OpenMP directive with NOP.
	Call lower_omp_* instead of expand_omp_*.
	(lower_omp): Rename from expand_omp.

	* tree-gimple.c (is_gimple_stmt): Handle OMP_RETURN_EXPR.
	* tree-gimple.h (enum omp_parallel_type): Remove.
	(gimple_boolify): Declare extern.
	(find_omp_clause, determine_parallel_type): Remove.

	* gimple-low.c (lower_omp_directive): New.
	(lower_stmt): Call it.
	(record_vars_into): Move from ...
	(record_vars): ... here.
	Call record_vars_into with current_function_decl.

	* gimplify.c (struct gimplify_ctx): Remove fields
	combined_pre_p and combined_ctxp.  Update users.
	(get_formal_tmp_var): Add documentation.
	(gimple_boolify): Make extern.
	(gimplify_expr_in_ctx): Remove.  Update callers.
	(gimplify_omp_parallel): Do not assume that OMP_PARALLEL_BODY
	will always be a BIND_EXPR.
	(gimplify_expr): Handle OMP_RETURN_EXPR.
	* tree.def (BLOCK): Remove documentation about BLOCK_TYPE_TAGS.
	(OMP_PARALLEL): Add 3 operands.
	(OMP_SECTIONS): Add 1 operand.
	(OMP_RETURN_EXPR): Define.

	* tree-inline.c (estimate_num_insns_1): Handle OpenMP directives.
	(copy_tree_r): Restore TREE_CHAIN in OMP_CLAUSE_*.
	* tree-iterator.c (alloc_stmt_list): Assert that we are not
	creating a circular free list.
	(free_stmt_list): Assert that we are not freeing stmt_list_cache.

	* tree-flow.h (move_sese_region_to_fn): Declare.
	(record_vars_into): Declare.
	* tree-cfg.c (make_omp_sections_edges): New.
	(make_exit_edges): Handle OMP_PARALLEL, OMP_FOR, OMP_SINGLE,
	OMP_MASTER, OMP_ORDERED, OMP_CRITICAL, OMP_RETURN_EXPR,
	OMP_SECTIONS and OMP_SECTION.
	(is_ctrl_altering_stmt): Return true for OMP_DIRECTIVE_P.
	(set_bb_for_stmt): Undo change to check currently_expanding_to_rtl.
	(verify_stmt): Do not handle OMP_DIRECTIVE_P.
	(gather_blocks_in_sese_region): New.
	(struct move_stmt_d): Declare.
	(move_stmt_r): New.
	(move_block_to_fn): New.
	(move_sese_region_to_fn): New.

	* passes.c (init_optimization_passes): Schedule
	pass_expand_omp after pass_init_datastructures.

	* tree-ssa-operands.c (get_expr_operands): Handle
	OMP_PARALLEL, OMP_SECTIONS, OMP_FOR, OMP_RETURN_EXPR,
	OMP_SINGLE, OMP_MASTER, OMP_ORDERED, OMP_CRITICAL.


testsuite/

	* testsuite/gcc.dg/gomp/for-13.c: Use -fdump-tree-ompexp.
	* testsuite/gcc.dg/gomp/critical-1.c: Likewise.
	* testsuite/gcc.dg/gomp/critical-3.c: Likewise.
	* testsuite/gcc.dg/gomp/empty.c: Likewise.
	* testsuite/gcc.dg/gomp/ordered-1.c: Likewise.
	* testsuite/gcc.dg/gomp/for-4.c: Likewise.
	* testsuite/gcc.dg/gomp/for-6.c: Likewise.
	* testsuite/gcc.dg/gomp/master-3.c: Likewise.
	* testsuite/gcc.dg/gomp/for-8.c: Likewise.
	* testsuite/gcc.dg/gomp/for-10.c: Likewise.
	* testsuite/gcc.dg/gomp/for-18.c: Likewise.
	* testsuite/gcc.dg/gomp/for-5.c: Likewise.
	* testsuite/gcc.dg/gomp/for-7.c: Likewise.
	* testsuite/gcc.dg/gomp/for-9.c: Likewise.

From-SVN: r109969
2006-01-19 11:55:52 -05:00

362 lines
8.2 KiB
C

/* Iterator routines for manipulating GENERIC and GIMPLE tree statements.
Copyright (C) 2003, 2004 Free Software Foundation, Inc.
Contributed by Andrew MacLeod <amacleod@redhat.com>
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GCC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING. If not, write to
the Free Software Foundation, 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tree.h"
#include "tree-gimple.h"
#include "tree-iterator.h"
#include "ggc.h"
/* This is a cache of STATEMENT_LIST nodes. We create and destroy them
fairly often during gimplification. */
static GTY ((deletable (""))) tree stmt_list_cache;
tree
alloc_stmt_list (void)
{
tree list = stmt_list_cache;
if (list)
{
stmt_list_cache = TREE_CHAIN (list);
gcc_assert (stmt_list_cache != list);
memset (list, 0, sizeof(struct tree_common));
TREE_SET_CODE (list, STATEMENT_LIST);
}
else
list = make_node (STATEMENT_LIST);
TREE_TYPE (list) = void_type_node;
return list;
}
void
free_stmt_list (tree t)
{
gcc_assert (!STATEMENT_LIST_HEAD (t));
gcc_assert (!STATEMENT_LIST_TAIL (t));
/* If this triggers, it's a sign that the same list is being freed
twice. */
gcc_assert (t != stmt_list_cache || stmt_list_cache == NULL);
TREE_CHAIN (t) = stmt_list_cache;
stmt_list_cache = t;
}
/* Links a statement, or a chain of statements, before the current stmt. */
void
tsi_link_before (tree_stmt_iterator *i, tree t, enum tsi_iterator_update mode)
{
struct tree_statement_list_node *head, *tail, *cur;
/* Die on looping. */
gcc_assert (t != i->container);
if (TREE_CODE (t) == STATEMENT_LIST)
{
head = STATEMENT_LIST_HEAD (t);
tail = STATEMENT_LIST_TAIL (t);
STATEMENT_LIST_HEAD (t) = NULL;
STATEMENT_LIST_TAIL (t) = NULL;
free_stmt_list (t);
/* Empty statement lists need no work. */
if (!head || !tail)
{
gcc_assert (head == tail);
return;
}
}
else
{
head = ggc_alloc (sizeof (*head));
head->prev = NULL;
head->next = NULL;
head->stmt = t;
tail = head;
}
TREE_SIDE_EFFECTS (i->container) = 1;
cur = i->ptr;
/* Link it into the list. */
if (cur)
{
head->prev = cur->prev;
if (head->prev)
head->prev->next = head;
else
STATEMENT_LIST_HEAD (i->container) = head;
tail->next = cur;
cur->prev = tail;
}
else
{
head->prev = STATEMENT_LIST_TAIL (i->container);
if (head->prev)
head->prev->next = head;
else
STATEMENT_LIST_HEAD (i->container) = head;
STATEMENT_LIST_TAIL (i->container) = tail;
}
/* Update the iterator, if requested. */
switch (mode)
{
case TSI_NEW_STMT:
case TSI_CONTINUE_LINKING:
case TSI_CHAIN_START:
i->ptr = head;
break;
case TSI_CHAIN_END:
i->ptr = tail;
break;
case TSI_SAME_STMT:
break;
}
}
/* Links a statement, or a chain of statements, after the current stmt. */
void
tsi_link_after (tree_stmt_iterator *i, tree t, enum tsi_iterator_update mode)
{
struct tree_statement_list_node *head, *tail, *cur;
/* Die on looping. */
gcc_assert (t != i->container);
if (TREE_CODE (t) == STATEMENT_LIST)
{
head = STATEMENT_LIST_HEAD (t);
tail = STATEMENT_LIST_TAIL (t);
STATEMENT_LIST_HEAD (t) = NULL;
STATEMENT_LIST_TAIL (t) = NULL;
free_stmt_list (t);
/* Empty statement lists need no work. */
if (!head || !tail)
{
gcc_assert (head == tail);
return;
}
}
else
{
head = ggc_alloc (sizeof (*head));
head->prev = NULL;
head->next = NULL;
head->stmt = t;
tail = head;
}
TREE_SIDE_EFFECTS (i->container) = 1;
cur = i->ptr;
/* Link it into the list. */
if (cur)
{
tail->next = cur->next;
if (tail->next)
tail->next->prev = tail;
else
STATEMENT_LIST_TAIL (i->container) = tail;
head->prev = cur;
cur->next = head;
}
else
{
gcc_assert (!STATEMENT_LIST_TAIL (i->container));
STATEMENT_LIST_HEAD (i->container) = head;
STATEMENT_LIST_TAIL (i->container) = tail;
}
/* Update the iterator, if requested. */
switch (mode)
{
case TSI_NEW_STMT:
case TSI_CHAIN_START:
i->ptr = head;
break;
case TSI_CONTINUE_LINKING:
case TSI_CHAIN_END:
i->ptr = tail;
break;
case TSI_SAME_STMT:
gcc_assert (cur);
break;
}
}
/* Remove a stmt from the tree list. The iterator is updated to point to
the next stmt. */
void
tsi_delink (tree_stmt_iterator *i)
{
struct tree_statement_list_node *cur, *next, *prev;
cur = i->ptr;
next = cur->next;
prev = cur->prev;
if (prev)
prev->next = next;
else
STATEMENT_LIST_HEAD (i->container) = next;
if (next)
next->prev = prev;
else
STATEMENT_LIST_TAIL (i->container) = prev;
if (!next && !prev)
TREE_SIDE_EFFECTS (i->container) = 0;
i->ptr = next;
}
/* Move all statements in the statement list after I to a new
statement list. I itself is unchanged. */
tree
tsi_split_statement_list_after (const tree_stmt_iterator *i)
{
struct tree_statement_list_node *cur, *next;
tree old_sl, new_sl;
cur = i->ptr;
/* How can we possibly split after the end, or before the beginning? */
gcc_assert (cur);
next = cur->next;
old_sl = i->container;
new_sl = alloc_stmt_list ();
TREE_SIDE_EFFECTS (new_sl) = 1;
STATEMENT_LIST_HEAD (new_sl) = next;
STATEMENT_LIST_TAIL (new_sl) = STATEMENT_LIST_TAIL (old_sl);
STATEMENT_LIST_TAIL (old_sl) = cur;
cur->next = NULL;
next->prev = NULL;
return new_sl;
}
/* Move all statements in the statement list before I to a new
statement list. I is set to the head of the new list. */
tree
tsi_split_statement_list_before (tree_stmt_iterator *i)
{
struct tree_statement_list_node *cur, *prev;
tree old_sl, new_sl;
cur = i->ptr;
/* How can we possibly split after the end, or before the beginning? */
gcc_assert (cur);
prev = cur->prev;
old_sl = i->container;
new_sl = alloc_stmt_list ();
TREE_SIDE_EFFECTS (new_sl) = 1;
i->container = new_sl;
STATEMENT_LIST_HEAD (new_sl) = cur;
STATEMENT_LIST_TAIL (new_sl) = STATEMENT_LIST_TAIL (old_sl);
STATEMENT_LIST_TAIL (old_sl) = prev;
cur->prev = NULL;
prev->next = NULL;
return new_sl;
}
/* Return the first expression in a sequence of COMPOUND_EXPRs,
or in a STATEMENT_LIST. */
tree
expr_first (tree expr)
{
if (expr == NULL_TREE)
return expr;
if (TREE_CODE (expr) == STATEMENT_LIST)
{
struct tree_statement_list_node *n = STATEMENT_LIST_HEAD (expr);
return n ? n->stmt : NULL_TREE;
}
while (TREE_CODE (expr) == COMPOUND_EXPR)
expr = TREE_OPERAND (expr, 0);
return expr;
}
/* Return the last expression in a sequence of COMPOUND_EXPRs,
or in a STATEMENT_LIST. */
tree
expr_last (tree expr)
{
if (expr == NULL_TREE)
return expr;
if (TREE_CODE (expr) == STATEMENT_LIST)
{
struct tree_statement_list_node *n = STATEMENT_LIST_TAIL (expr);
return n ? n->stmt : NULL_TREE;
}
while (TREE_CODE (expr) == COMPOUND_EXPR)
expr = TREE_OPERAND (expr, 1);
return expr;
}
/* If EXPR is a single statement return it. If EXPR is a
STATEMENT_LIST containing exactly one statement S, return S.
Otherwise, return NULL. */
tree
expr_only (tree expr)
{
if (expr == NULL_TREE)
return NULL_TREE;
if (TREE_CODE (expr) == STATEMENT_LIST)
{
struct tree_statement_list_node *n = STATEMENT_LIST_TAIL (expr);
if (n && STATEMENT_LIST_HEAD (expr) == n)
return n->stmt;
else
return NULL_TREE;
}
if (TREE_CODE (expr) == COMPOUND_EXPR)
return NULL_TREE;
return expr;
}
#include "gt-tree-iterator.h"