8sa1-gcc/gcc/c-gimplify.c
Ian Lance Taylor fbc315db4a c-common.def: Move FOR_STMT...
./	* c-common.def: Move FOR_STMT, WHILE_STMT, DO_STMT, BREAK_STMT,
	CONTINUE_STMT, and SWITCH_STMT to cp/cp-tree.def.
	* c-common.h (WHILE_COND, WHILE_BODY): Move to cp/cp-tree.h.
	(DO_COND, DO_BODY): Likewise.
	(FOR_INIT_STMT, FOR_COND, FOR_EXPR, FOR_BODY): Likewise.
	(SWITCH_STMT_COND, SWITCH_STMT_BODY, SWITCH_STMT_TYPE): Likewise.
	(c_common_stmt_codes): Remove FOR_STMT, WHILE_STMT, DO_STMT,
	BREAK_STMT, CONTINUE_STMT, and SWITCH_STMT.
	(build_continue_stmt, build_break_stmt): Don't declare.
	(c_do_switch_warnings): Update declaration.
	* c-gimplify.c (enum bc_t): Remove.
	(struct c_gimplify_ctx, ctxp): Remove.
	(push_context, pop_context): Remove static functions.
	(c_genericize): Don't call push_context or pop_context.
	(begin_bc_block, finish_bc_block): Remove static functions.
	(build_bc_goto): Likewise.
	(gimplify_c_loop): Likewise.
	(gimplify_for_stmt, gimplify_while_stmt): Likewise.
	(gimplify_do_stmt, gimplify_switch_stmt): Likewise.
	(c_gimplify_expr): Remove handling of FOR_STMT, WHILE_STMT,
	DO_STMT, SWITCH_STMT, CONTINUE_STMT, BREAK_STMT.
	* c-common.c (c_do_switch_warnings): Rename from
	c_do_switch_warnings_1.
	(c_do_switch_warnings) [old version]: Remove.
	(c_do_switch_expr_warnings): Remove.
	* c-typeck.c (c_finish_case): Call new c_do_switch_warnings
	function instead of c_do_switch_expr_warnings.
	* c-dump.c (c_dump_tree): Remove handling of BREAK_STMT,
	CONTINUE_STMT, DO_STMT, FOR_STMT, SWITCH_STMT, and WHILE_STMT.
	* c-pretty-print.c (pp_c_statement): Likewise.
	* c-semantics.c (build_break_stmt, build_continue_stmt): Remove.
cp/
	* cp-tree.def: Define FOR_STMT, WHILE_STMT, DO_STMT, BREAK_STMT,
	CONTINUE_STMT, SWITCH_STMT.
	* cp-tree.h (cp_stmt_codes): Add FOR_STMT, WHILE_STMT, DO_STMT,
	BREAK_STMT, CONTINUE_STMT, SWITCH_STMT.
	(WHILE_COND, WHILE_BODY): Define.
	(DO_COND, DO_BODY): Define.
	(FOR_INIT_STMT, FOR_COND, FOR_EXPR, FOR_BODY): Define.
	(SWITCH_STMT_COND, SWITCH_STMT_BODY, SWITCH_STMT_TYPE): Define.
	* cp-gimplify.c (enum bc_t): Define.
	(struct cp_gimplify_ctx, ctxp): Define.
	(push_context, pop_context): New static functions.
	(begin_bc_block, finish_bc_block): New static functions.
	(build_bc_goto): New static function.
	(gimplify_cp_loop, gimplify_for_stmt): New static functions.
	(gimplify_while_stmt, gimplify_do_stmt): Likewise.
	(gimplify_switch_stmt): Likewise.
	(cp_gimplify_expr): Handle FOR_STMT, WHILE_STMT, DO_STMT,
	SWITCH_STMT, CONTINUE_STMT, BREAK_STMT.
	(cp_genericize): Call push_context and pop_context.
	* semantics.c (finish_break_stmt): Just call build_stmt
	(BREAK_STMT) rather than build_break_stmt.
	(finish_continue_stmt): Corresponding change.
	* decl.c (pop_switch): Update call to c_do_switch_warnings for new
	parameters.
	* cxx-pretty-print.c (pp_cxx_statement): Handle SWITCH_STMT,
	WHILE_STMT, DO_STMT, FOR_STMT, BREAK_STMT, CONTINUE_STMT.
	* dump.c (cp_dump_tree): Likewise.

From-SVN: r97885
2005-04-09 03:18:18 +00:00

276 lines
8.1 KiB
C

/* Tree lowering pass. This pass gimplifies the tree representation built
by the C-based front ends. The structure of gimplified, or
language-independent, trees is dictated by the grammar described in this
file.
Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
Lowering of expressions contributed by Sebastian Pop <s.pop@laposte.net>
Re-written to support lowering of whole function trees, documentation
and miscellaneous cleanups by Diego Novillo <dnovillo@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, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA. */
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "tree.h"
#include "errors.h"
#include "varray.h"
#include "c-tree.h"
#include "c-common.h"
#include "tree-gimple.h"
#include "hard-reg-set.h"
#include "basic-block.h"
#include "tree-flow.h"
#include "tree-inline.h"
#include "diagnostic.h"
#include "langhooks.h"
#include "langhooks-def.h"
#include "flags.h"
#include "rtl.h"
#include "toplev.h"
#include "tree-dump.h"
#include "c-pretty-print.h"
#include "cgraph.h"
/* The gimplification pass converts the language-dependent trees
(ld-trees) emitted by the parser into language-independent trees
(li-trees) that are the target of SSA analysis and transformations.
Language-independent trees are based on the SIMPLE intermediate
representation used in the McCAT compiler framework:
"Designing the McCAT Compiler Based on a Family of Structured
Intermediate Representations,"
L. Hendren, C. Donawa, M. Emami, G. Gao, Justiani, and B. Sridharan,
Proceedings of the 5th International Workshop on Languages and
Compilers for Parallel Computing, no. 757 in Lecture Notes in
Computer Science, New Haven, Connecticut, pp. 406-420,
Springer-Verlag, August 3-5, 1992.
http://www-acaps.cs.mcgill.ca/info/McCAT/McCAT.html
Basically, we walk down gimplifying the nodes that we encounter. As we
walk back up, we check that they fit our constraints, and copy them
into temporaries if not. */
/* Gimplification of statement trees. */
/* Convert the tree representation of FNDECL from C frontend trees to
GENERIC. */
void
c_genericize (tree fndecl)
{
FILE *dump_file;
int local_dump_flags;
struct cgraph_node *cgn;
/* Dump the C-specific tree IR. */
dump_file = dump_begin (TDI_original, &local_dump_flags);
if (dump_file)
{
fprintf (dump_file, "\n;; Function %s",
lang_hooks.decl_printable_name (fndecl, 2));
fprintf (dump_file, " (%s)\n",
IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl)));
fprintf (dump_file, ";; enabled by -%s\n", dump_flag_name (TDI_original));
fprintf (dump_file, "\n");
if (local_dump_flags & TDF_RAW)
dump_node (DECL_SAVED_TREE (fndecl),
TDF_SLIM | local_dump_flags, dump_file);
else
print_c_tree (dump_file, DECL_SAVED_TREE (fndecl));
fprintf (dump_file, "\n");
dump_end (TDI_original, dump_file);
}
/* Go ahead and gimplify for now. */
gimplify_function_tree (fndecl);
/* Dump the genericized tree IR. */
dump_function (TDI_generic, fndecl);
/* Genericize all nested functions now. We do things in this order so
that items like VLA sizes are expanded properly in the context of
the correct function. */
cgn = cgraph_node (fndecl);
for (cgn = cgn->nested; cgn ; cgn = cgn->next_nested)
c_genericize (cgn->decl);
}
static void
add_block_to_enclosing (tree block)
{
tree enclosing;
for (enclosing = gimple_current_bind_expr ();
enclosing; enclosing = TREE_CHAIN (enclosing))
if (BIND_EXPR_BLOCK (enclosing))
break;
enclosing = BIND_EXPR_BLOCK (enclosing);
BLOCK_SUBBLOCKS (enclosing) = chainon (BLOCK_SUBBLOCKS (enclosing), block);
}
/* Genericize a scope by creating a new BIND_EXPR.
BLOCK is either a BLOCK representing the scope or a chain of _DECLs.
In the latter case, we need to create a new BLOCK and add it to the
BLOCK_SUBBLOCKS of the enclosing block.
BODY is a chain of C _STMT nodes for the contents of the scope, to be
genericized. */
tree
c_build_bind_expr (tree block, tree body)
{
tree decls, bind;
if (block == NULL_TREE)
decls = NULL_TREE;
else if (TREE_CODE (block) == BLOCK)
decls = BLOCK_VARS (block);
else
{
decls = block;
if (DECL_ARTIFICIAL (decls))
block = NULL_TREE;
else
{
block = make_node (BLOCK);
BLOCK_VARS (block) = decls;
add_block_to_enclosing (block);
}
}
if (!body)
body = build_empty_stmt ();
if (decls || block)
{
bind = build3 (BIND_EXPR, void_type_node, decls, body, block);
TREE_SIDE_EFFECTS (bind) = 1;
}
else
bind = body;
return bind;
}
/* Gimplify an EXPR_STMT node.
STMT is the statement node.
PRE_P points to the list where side effects that must happen before
STMT should be stored.
POST_P points to the list where side effects that must happen after
STMT should be stored. */
static enum gimplify_status
gimplify_expr_stmt (tree *stmt_p)
{
tree stmt = EXPR_STMT_EXPR (*stmt_p);
if (stmt == error_mark_node)
stmt = NULL;
/* Gimplification of a statement expression will nullify the
statement if all its side effects are moved to *PRE_P and *POST_P.
In this case we will not want to emit the gimplified statement.
However, we may still want to emit a warning, so we do that before
gimplification. */
if (stmt && (extra_warnings || warn_unused_value))
{
if (!TREE_SIDE_EFFECTS (stmt))
{
if (!IS_EMPTY_STMT (stmt)
&& !VOID_TYPE_P (TREE_TYPE (stmt))
&& !TREE_NO_WARNING (stmt))
warning ("statement with no effect");
}
else if (warn_unused_value)
warn_if_unused_value (stmt, input_location);
}
if (stmt == NULL_TREE)
stmt = alloc_stmt_list ();
*stmt_p = stmt;
return GS_OK;
}
/* Gimplification of expression trees. */
/* Gimplify a C99 compound literal expression. This just means adding the
DECL_EXPR before the current EXPR_STMT and using its anonymous decl
instead. */
static enum gimplify_status
gimplify_compound_literal_expr (tree *expr_p, tree *pre_p)
{
tree decl_s = COMPOUND_LITERAL_EXPR_DECL_STMT (*expr_p);
tree decl = DECL_EXPR_DECL (decl_s);
/* This decl isn't mentioned in the enclosing block, so add it to the
list of temps. FIXME it seems a bit of a kludge to say that
anonymous artificial vars aren't pushed, but everything else is. */
if (DECL_NAME (decl) == NULL_TREE)
gimple_add_tmp_var (decl);
gimplify_and_add (decl_s, pre_p);
*expr_p = decl;
return GS_OK;
}
/* Do C-specific gimplification. Args are as for gimplify_expr. */
int
c_gimplify_expr (tree *expr_p, tree *pre_p, tree *post_p ATTRIBUTE_UNUSED)
{
enum tree_code code = TREE_CODE (*expr_p);
switch (code)
{
case DECL_EXPR:
/* This is handled mostly by gimplify.c, but we have to deal with
not warning about int x = x; as it is a GCC extension to turn off
this warning but only if warn_init_self is zero. */
if (TREE_CODE (DECL_EXPR_DECL (*expr_p)) == VAR_DECL
&& !DECL_EXTERNAL (DECL_EXPR_DECL (*expr_p))
&& !TREE_STATIC (DECL_EXPR_DECL (*expr_p))
&& (DECL_INITIAL (DECL_EXPR_DECL (*expr_p))
== DECL_EXPR_DECL (*expr_p))
&& !warn_init_self)
TREE_NO_WARNING (DECL_EXPR_DECL (*expr_p)) = 1;
return GS_UNHANDLED;
case COMPOUND_LITERAL_EXPR:
return gimplify_compound_literal_expr (expr_p, pre_p);
case EXPR_STMT:
return gimplify_expr_stmt (expr_p);
default:
return GS_UNHANDLED;
}
}