comparison gcc/c-gimplify.c @ 55:77e2b8dfacca gcc-4.4.5

update it from 4.4.3 to 4.5.0
author ryoma <e075725@ie.u-ryukyu.ac.jp>
date Fri, 12 Feb 2010 23:39:51 +0900
parents a06113de4d67
children b7f97abdc517
comparison
equal deleted inserted replaced
52:c156f1bd5cd9 55:77e2b8dfacca
101 fprintf (dump_orig, "\n"); 101 fprintf (dump_orig, "\n");
102 102
103 dump_end (TDI_original, dump_orig); 103 dump_end (TDI_original, dump_orig);
104 } 104 }
105 105
106 /* Go ahead and gimplify for now. */ 106 /* Dump all nested functions now. */
107 gimplify_function_tree (fndecl);
108
109 dump_function (TDI_generic, fndecl);
110
111 /* Genericize all nested functions now. We do things in this order so
112 that items like VLA sizes are expanded properly in the context of
113 the correct function. */
114 cgn = cgraph_node (fndecl); 107 cgn = cgraph_node (fndecl);
115 for (cgn = cgn->nested; cgn ; cgn = cgn->next_nested) 108 for (cgn = cgn->nested; cgn ; cgn = cgn->next_nested)
116 c_genericize (cgn->decl); 109 c_genericize (cgn->decl);
117 } 110 }
118 111
138 BLOCK_SUBBLOCKS of the enclosing block. 131 BLOCK_SUBBLOCKS of the enclosing block.
139 BODY is a chain of C _STMT nodes for the contents of the scope, to be 132 BODY is a chain of C _STMT nodes for the contents of the scope, to be
140 genericized. */ 133 genericized. */
141 134
142 tree 135 tree
143 c_build_bind_expr (tree block, tree body) 136 c_build_bind_expr (location_t loc, tree block, tree body)
144 { 137 {
145 tree decls, bind; 138 tree decls, bind;
146 139
147 if (block == NULL_TREE) 140 if (block == NULL_TREE)
148 decls = NULL_TREE; 141 decls = NULL_TREE;
160 add_block_to_enclosing (block); 153 add_block_to_enclosing (block);
161 } 154 }
162 } 155 }
163 156
164 if (!body) 157 if (!body)
165 body = build_empty_stmt (); 158 body = build_empty_stmt (loc);
166 if (decls || block) 159 if (decls || block)
167 { 160 {
168 bind = build3 (BIND_EXPR, void_type_node, decls, body, block); 161 bind = build3 (BIND_EXPR, void_type_node, decls, body, block);
169 TREE_SIDE_EFFECTS (bind) = 1; 162 TREE_SIDE_EFFECTS (bind) = 1;
163 SET_EXPR_LOCATION (bind, loc);
170 } 164 }
171 else 165 else
172 bind = body; 166 bind = body;
173 167
174 return bind; 168 return bind;
175 } 169 }
176 170
177 /* Gimplification of expression trees. */ 171 /* Gimplification of expression trees. */
178 172
179 /* Gimplify a C99 compound literal expression. This just means adding
180 the DECL_EXPR before the current statement and using its anonymous
181 decl instead. */
182
183 static enum gimplify_status
184 gimplify_compound_literal_expr (tree *expr_p, gimple_seq *pre_p)
185 {
186 tree decl_s = COMPOUND_LITERAL_EXPR_DECL_STMT (*expr_p);
187 tree decl = DECL_EXPR_DECL (decl_s);
188 /* Mark the decl as addressable if the compound literal
189 expression is addressable now, otherwise it is marked too late
190 after we gimplify the initialization expression. */
191 if (TREE_ADDRESSABLE (*expr_p))
192 TREE_ADDRESSABLE (decl) = 1;
193
194 /* Preliminarily mark non-addressed complex variables as eligible
195 for promotion to gimple registers. We'll transform their uses
196 as we find them. */
197 if ((TREE_CODE (TREE_TYPE (decl)) == COMPLEX_TYPE
198 || TREE_CODE (TREE_TYPE (decl)) == VECTOR_TYPE)
199 && !TREE_THIS_VOLATILE (decl)
200 && !needs_to_live_in_memory (decl))
201 DECL_GIMPLE_REG_P (decl) = 1;
202
203 /* This decl isn't mentioned in the enclosing block, so add it to the
204 list of temps. FIXME it seems a bit of a kludge to say that
205 anonymous artificial vars aren't pushed, but everything else is. */
206 if (DECL_NAME (decl) == NULL_TREE && !DECL_SEEN_IN_BIND_EXPR_P (decl))
207 gimple_add_tmp_var (decl);
208
209 gimplify_and_add (decl_s, pre_p);
210 *expr_p = decl;
211 return GS_OK;
212 }
213
214 /* Optimize embedded COMPOUND_LITERAL_EXPRs within a CONSTRUCTOR,
215 return a new CONSTRUCTOR if something changed. */
216
217 static tree
218 optimize_compound_literals_in_ctor (tree orig_ctor)
219 {
220 tree ctor = orig_ctor;
221 VEC(constructor_elt,gc) *elts = CONSTRUCTOR_ELTS (ctor);
222 unsigned int idx, num = VEC_length (constructor_elt, elts);
223
224 for (idx = 0; idx < num; idx++)
225 {
226 tree value = VEC_index (constructor_elt, elts, idx)->value;
227 tree newval = value;
228 if (TREE_CODE (value) == CONSTRUCTOR)
229 newval = optimize_compound_literals_in_ctor (value);
230 else if (TREE_CODE (value) == COMPOUND_LITERAL_EXPR)
231 {
232 tree decl_s = COMPOUND_LITERAL_EXPR_DECL_STMT (value);
233 tree decl = DECL_EXPR_DECL (decl_s);
234 tree init = DECL_INITIAL (decl);
235
236 if (!TREE_ADDRESSABLE (value)
237 && !TREE_ADDRESSABLE (decl)
238 && init)
239 newval = init;
240 }
241 if (newval == value)
242 continue;
243
244 if (ctor == orig_ctor)
245 {
246 ctor = copy_node (orig_ctor);
247 CONSTRUCTOR_ELTS (ctor) = VEC_copy (constructor_elt, gc, elts);
248 elts = CONSTRUCTOR_ELTS (ctor);
249 }
250 VEC_index (constructor_elt, elts, idx)->value = newval;
251 }
252 return ctor;
253 }
254
255 /* Do C-specific gimplification on *EXPR_P. PRE_P and POST_P are as in 173 /* Do C-specific gimplification on *EXPR_P. PRE_P and POST_P are as in
256 gimplify_expr. */ 174 gimplify_expr. */
257 175
258 int 176 int
259 c_gimplify_expr (tree *expr_p, gimple_seq *pre_p, 177 c_gimplify_expr (tree *expr_p, gimple_seq *pre_p ATTRIBUTE_UNUSED,
260 gimple_seq *post_p ATTRIBUTE_UNUSED) 178 gimple_seq *post_p ATTRIBUTE_UNUSED)
261 { 179 {
262 enum tree_code code = TREE_CODE (*expr_p); 180 enum tree_code code = TREE_CODE (*expr_p);
263 181
264 switch (code) 182 /* This is handled mostly by gimplify.c, but we have to deal with
265 { 183 not warning about int x = x; as it is a GCC extension to turn off
266 case DECL_EXPR: 184 this warning but only if warn_init_self is zero. */
267 /* This is handled mostly by gimplify.c, but we have to deal with 185 if (code == DECL_EXPR
268 not warning about int x = x; as it is a GCC extension to turn off 186 && TREE_CODE (DECL_EXPR_DECL (*expr_p)) == VAR_DECL
269 this warning but only if warn_init_self is zero. */ 187 && !DECL_EXTERNAL (DECL_EXPR_DECL (*expr_p))
270 if (TREE_CODE (DECL_EXPR_DECL (*expr_p)) == VAR_DECL 188 && !TREE_STATIC (DECL_EXPR_DECL (*expr_p))
271 && !DECL_EXTERNAL (DECL_EXPR_DECL (*expr_p)) 189 && (DECL_INITIAL (DECL_EXPR_DECL (*expr_p)) == DECL_EXPR_DECL (*expr_p))
272 && !TREE_STATIC (DECL_EXPR_DECL (*expr_p)) 190 && !warn_init_self)
273 && (DECL_INITIAL (DECL_EXPR_DECL (*expr_p)) 191 TREE_NO_WARNING (DECL_EXPR_DECL (*expr_p)) = 1;
274 == DECL_EXPR_DECL (*expr_p))
275 && !warn_init_self)
276 TREE_NO_WARNING (DECL_EXPR_DECL (*expr_p)) = 1;
277 return GS_UNHANDLED;
278 192
279 case COMPOUND_LITERAL_EXPR: 193 return GS_UNHANDLED;
280 return gimplify_compound_literal_expr (expr_p, pre_p);
281
282 case INIT_EXPR:
283 case MODIFY_EXPR:
284 if (TREE_CODE (TREE_OPERAND (*expr_p, 1)) == COMPOUND_LITERAL_EXPR)
285 {
286 tree complit = TREE_OPERAND (*expr_p, 1);
287 tree decl_s = COMPOUND_LITERAL_EXPR_DECL_STMT (complit);
288 tree decl = DECL_EXPR_DECL (decl_s);
289 tree init = DECL_INITIAL (decl);
290
291 /* struct T x = (struct T) { 0, 1, 2 } can be optimized
292 into struct T x = { 0, 1, 2 } if the address of the
293 compound literal has never been taken. */
294 if (!TREE_ADDRESSABLE (complit)
295 && !TREE_ADDRESSABLE (decl)
296 && init)
297 {
298 *expr_p = copy_node (*expr_p);
299 TREE_OPERAND (*expr_p, 1) = init;
300 return GS_OK;
301 }
302 }
303 else if (TREE_CODE (TREE_OPERAND (*expr_p, 1)) == CONSTRUCTOR)
304 {
305 tree ctor
306 = optimize_compound_literals_in_ctor (TREE_OPERAND (*expr_p, 1));
307
308 if (ctor != TREE_OPERAND (*expr_p, 1))
309 {
310 *expr_p = copy_node (*expr_p);
311 TREE_OPERAND (*expr_p, 1) = ctor;
312 return GS_OK;
313 }
314 }
315 return GS_UNHANDLED;
316
317 default:
318 return GS_UNHANDLED;
319 }
320 } 194 }