PR 43726 * config/lm32/lm32.h: Remove definition of GO_IF_MODE_DEPENDENT_ADDRESS.
[official-gcc.git] / gcc / c-gimplify.c
blob58729f16ecf3f2bd51e9e9ea686c6e47a429de74
1 /* Tree lowering pass. This pass gimplifies the tree representation built
2 by the C-based front ends. The structure of gimplified, or
3 language-independent, trees is dictated by the grammar described in this
4 file.
5 Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008
6 Free Software Foundation, Inc.
7 Lowering of expressions contributed by Sebastian Pop <s.pop@laposte.net>
8 Re-written to support lowering of whole function trees, documentation
9 and miscellaneous cleanups by Diego Novillo <dnovillo@redhat.com>
11 This file is part of GCC.
13 GCC is free software; you can redistribute it and/or modify it under
14 the terms of the GNU General Public License as published by the Free
15 Software Foundation; either version 3, or (at your option) any later
16 version.
18 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
19 WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
23 You should have received a copy of the GNU General Public License
24 along with GCC; see the file COPYING3. If not see
25 <http://www.gnu.org/licenses/>. */
27 #include "config.h"
28 #include "system.h"
29 #include "coretypes.h"
30 #include "tm.h"
31 #include "tree.h"
32 #include "c-tree.h"
33 #include "c-common.h"
34 #include "gimple.h"
35 #include "basic-block.h"
36 #include "tree-flow.h"
37 #include "tree-inline.h"
38 #include "diagnostic.h"
39 #include "langhooks.h"
40 #include "langhooks-def.h"
41 #include "flags.h"
42 #include "toplev.h"
43 #include "tree-dump.h"
44 #include "c-pretty-print.h"
45 #include "cgraph.h"
48 /* The gimplification pass converts the language-dependent trees
49 (ld-trees) emitted by the parser into language-independent trees
50 (li-trees) that are the target of SSA analysis and transformations.
52 Language-independent trees are based on the SIMPLE intermediate
53 representation used in the McCAT compiler framework:
55 "Designing the McCAT Compiler Based on a Family of Structured
56 Intermediate Representations,"
57 L. Hendren, C. Donawa, M. Emami, G. Gao, Justiani, and B. Sridharan,
58 Proceedings of the 5th International Workshop on Languages and
59 Compilers for Parallel Computing, no. 757 in Lecture Notes in
60 Computer Science, New Haven, Connecticut, pp. 406-420,
61 Springer-Verlag, August 3-5, 1992.
63 http://www-acaps.cs.mcgill.ca/info/McCAT/McCAT.html
65 Basically, we walk down gimplifying the nodes that we encounter. As we
66 walk back up, we check that they fit our constraints, and copy them
67 into temporaries if not. */
69 /* Gimplification of statement trees. */
71 /* Convert the tree representation of FNDECL from C frontend trees to
72 GENERIC. */
74 void
75 c_genericize (tree fndecl)
77 FILE *dump_orig;
78 int local_dump_flags;
79 struct cgraph_node *cgn;
81 /* Dump the C-specific tree IR. */
82 dump_orig = dump_begin (TDI_original, &local_dump_flags);
83 if (dump_orig)
85 fprintf (dump_orig, "\n;; Function %s",
86 lang_hooks.decl_printable_name (fndecl, 2));
87 fprintf (dump_orig, " (%s)\n",
88 (!DECL_ASSEMBLER_NAME_SET_P (fndecl) ? "null"
89 : IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl))));
90 fprintf (dump_orig, ";; enabled by -%s\n", dump_flag_name (TDI_original));
91 fprintf (dump_orig, "\n");
93 if (local_dump_flags & TDF_RAW)
94 dump_node (DECL_SAVED_TREE (fndecl),
95 TDF_SLIM | local_dump_flags, dump_orig);
96 else
97 print_c_tree (dump_orig, DECL_SAVED_TREE (fndecl));
98 fprintf (dump_orig, "\n");
100 dump_end (TDI_original, dump_orig);
103 /* Dump all nested functions now. */
104 cgn = cgraph_node (fndecl);
105 for (cgn = cgn->nested; cgn ; cgn = cgn->next_nested)
106 c_genericize (cgn->decl);
109 static void
110 add_block_to_enclosing (tree block)
112 unsigned i;
113 tree enclosing;
114 gimple bind;
115 VEC(gimple, heap) *stack = gimple_bind_expr_stack ();
117 for (i = 0; VEC_iterate (gimple, stack, i, bind); i++)
118 if (gimple_bind_block (bind))
119 break;
121 enclosing = gimple_bind_block (bind);
122 BLOCK_SUBBLOCKS (enclosing) = chainon (BLOCK_SUBBLOCKS (enclosing), block);
125 /* Genericize a scope by creating a new BIND_EXPR.
126 BLOCK is either a BLOCK representing the scope or a chain of _DECLs.
127 In the latter case, we need to create a new BLOCK and add it to the
128 BLOCK_SUBBLOCKS of the enclosing block.
129 BODY is a chain of C _STMT nodes for the contents of the scope, to be
130 genericized. */
132 tree
133 c_build_bind_expr (location_t loc, tree block, tree body)
135 tree decls, bind;
137 if (block == NULL_TREE)
138 decls = NULL_TREE;
139 else if (TREE_CODE (block) == BLOCK)
140 decls = BLOCK_VARS (block);
141 else
143 decls = block;
144 if (DECL_ARTIFICIAL (decls))
145 block = NULL_TREE;
146 else
148 block = make_node (BLOCK);
149 BLOCK_VARS (block) = decls;
150 add_block_to_enclosing (block);
154 if (!body)
155 body = build_empty_stmt (loc);
156 if (decls || block)
158 bind = build3 (BIND_EXPR, void_type_node, decls, body, block);
159 TREE_SIDE_EFFECTS (bind) = 1;
160 SET_EXPR_LOCATION (bind, loc);
162 else
163 bind = body;
165 return bind;
168 /* Gimplification of expression trees. */
170 /* Do C-specific gimplification on *EXPR_P. PRE_P and POST_P are as in
171 gimplify_expr. */
174 c_gimplify_expr (tree *expr_p, gimple_seq *pre_p ATTRIBUTE_UNUSED,
175 gimple_seq *post_p ATTRIBUTE_UNUSED)
177 enum tree_code code = TREE_CODE (*expr_p);
179 /* This is handled mostly by gimplify.c, but we have to deal with
180 not warning about int x = x; as it is a GCC extension to turn off
181 this warning but only if warn_init_self is zero. */
182 if (code == DECL_EXPR
183 && TREE_CODE (DECL_EXPR_DECL (*expr_p)) == VAR_DECL
184 && !DECL_EXTERNAL (DECL_EXPR_DECL (*expr_p))
185 && !TREE_STATIC (DECL_EXPR_DECL (*expr_p))
186 && (DECL_INITIAL (DECL_EXPR_DECL (*expr_p)) == DECL_EXPR_DECL (*expr_p))
187 && !warn_init_self)
188 TREE_NO_WARNING (DECL_EXPR_DECL (*expr_p)) = 1;
190 return GS_UNHANDLED;