Mercurial > hg > CbC > CbC_gcc
annotate gcc/gimple.c @ 21:959d4c8c8abc
add conv.c conv1.c
author | kent <kent@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 29 Sep 2009 20:15:16 +0900 |
parents | a4c410aa4714 |
children | 326d9e06c2e3 |
rev | line source |
---|---|
0 | 1 /* Gimple IR support functions. |
2 | |
3 Copyright 2007, 2008 Free Software Foundation, Inc. | |
4 Contributed by Aldy Hernandez <aldyh@redhat.com> | |
5 | |
6 This file is part of GCC. | |
7 | |
8 GCC is free software; you can redistribute it and/or modify it under | |
9 the terms of the GNU General Public License as published by the Free | |
10 Software Foundation; either version 3, or (at your option) any later | |
11 version. | |
12 | |
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY | |
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
19 along with GCC; see the file COPYING3. If not see | |
20 <http://www.gnu.org/licenses/>. */ | |
21 | |
22 #include "config.h" | |
23 #include "system.h" | |
24 #include "coretypes.h" | |
25 #include "tm.h" | |
26 #include "tree.h" | |
27 #include "ggc.h" | |
28 #include "errors.h" | |
29 #include "hard-reg-set.h" | |
30 #include "basic-block.h" | |
31 #include "gimple.h" | |
32 #include "diagnostic.h" | |
33 #include "tree-flow.h" | |
34 #include "value-prof.h" | |
35 #include "flags.h" | |
5
a4c410aa4714
modifing gimple.[ch], cfgexpand.c
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
36 #ifndef noCbC |
a4c410aa4714
modifing gimple.[ch], cfgexpand.c
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
37 #include "cbc-tree.h" |
a4c410aa4714
modifing gimple.[ch], cfgexpand.c
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
38 #endif |
0 | 39 |
40 #define DEFGSCODE(SYM, NAME, STRUCT) NAME, | |
41 const char *const gimple_code_name[] = { | |
42 #include "gimple.def" | |
43 }; | |
44 #undef DEFGSCODE | |
45 | |
46 /* All the tuples have their operand vector at the very bottom | |
47 of the structure. Therefore, the offset required to find the | |
48 operands vector the size of the structure minus the size of the 1 | |
49 element tree array at the end (see gimple_ops). */ | |
50 #define DEFGSCODE(SYM, NAME, STRUCT) (sizeof (STRUCT) - sizeof (tree)), | |
51 const size_t gimple_ops_offset_[] = { | |
52 #include "gimple.def" | |
53 }; | |
54 #undef DEFGSCODE | |
55 | |
56 #ifdef GATHER_STATISTICS | |
57 /* Gimple stats. */ | |
58 | |
59 int gimple_alloc_counts[(int) gimple_alloc_kind_all]; | |
60 int gimple_alloc_sizes[(int) gimple_alloc_kind_all]; | |
61 | |
62 /* Keep in sync with gimple.h:enum gimple_alloc_kind. */ | |
63 static const char * const gimple_alloc_kind_names[] = { | |
64 "assignments", | |
65 "phi nodes", | |
66 "conditionals", | |
67 "sequences", | |
68 "everything else" | |
69 }; | |
70 | |
71 #endif /* GATHER_STATISTICS */ | |
72 | |
73 /* A cache of gimple_seq objects. Sequences are created and destroyed | |
74 fairly often during gimplification. */ | |
75 static GTY ((deletable)) struct gimple_seq_d *gimple_seq_cache; | |
76 | |
77 /* Private API manipulation functions shared only with some | |
78 other files. */ | |
79 extern void gimple_set_stored_syms (gimple, bitmap, bitmap_obstack *); | |
80 extern void gimple_set_loaded_syms (gimple, bitmap, bitmap_obstack *); | |
81 | |
82 /* Gimple tuple constructors. | |
83 Note: Any constructor taking a ``gimple_seq'' as a parameter, can | |
84 be passed a NULL to start with an empty sequence. */ | |
85 | |
86 /* Set the code for statement G to CODE. */ | |
87 | |
88 static inline void | |
89 gimple_set_code (gimple g, enum gimple_code code) | |
90 { | |
91 g->gsbase.code = code; | |
92 } | |
93 | |
94 | |
95 /* Return the GSS_* identifier for the given GIMPLE statement CODE. */ | |
96 | |
97 static enum gimple_statement_structure_enum | |
98 gss_for_code (enum gimple_code code) | |
99 { | |
100 switch (code) | |
101 { | |
102 case GIMPLE_ASSIGN: | |
103 case GIMPLE_CALL: | |
104 case GIMPLE_RETURN: return GSS_WITH_MEM_OPS; | |
105 case GIMPLE_COND: | |
106 case GIMPLE_GOTO: | |
107 case GIMPLE_LABEL: | |
108 case GIMPLE_CHANGE_DYNAMIC_TYPE: | |
109 case GIMPLE_SWITCH: return GSS_WITH_OPS; | |
110 case GIMPLE_ASM: return GSS_ASM; | |
111 case GIMPLE_BIND: return GSS_BIND; | |
112 case GIMPLE_CATCH: return GSS_CATCH; | |
113 case GIMPLE_EH_FILTER: return GSS_EH_FILTER; | |
114 case GIMPLE_NOP: return GSS_BASE; | |
115 case GIMPLE_PHI: return GSS_PHI; | |
116 case GIMPLE_RESX: return GSS_RESX; | |
117 case GIMPLE_TRY: return GSS_TRY; | |
118 case GIMPLE_WITH_CLEANUP_EXPR: return GSS_WCE; | |
119 case GIMPLE_OMP_CRITICAL: return GSS_OMP_CRITICAL; | |
120 case GIMPLE_OMP_FOR: return GSS_OMP_FOR; | |
121 case GIMPLE_OMP_MASTER: | |
122 case GIMPLE_OMP_ORDERED: | |
123 case GIMPLE_OMP_SECTION: return GSS_OMP; | |
124 case GIMPLE_OMP_RETURN: | |
125 case GIMPLE_OMP_SECTIONS_SWITCH: return GSS_BASE; | |
126 case GIMPLE_OMP_CONTINUE: return GSS_OMP_CONTINUE; | |
127 case GIMPLE_OMP_PARALLEL: return GSS_OMP_PARALLEL; | |
128 case GIMPLE_OMP_TASK: return GSS_OMP_TASK; | |
129 case GIMPLE_OMP_SECTIONS: return GSS_OMP_SECTIONS; | |
130 case GIMPLE_OMP_SINGLE: return GSS_OMP_SINGLE; | |
131 case GIMPLE_OMP_ATOMIC_LOAD: return GSS_OMP_ATOMIC_LOAD; | |
132 case GIMPLE_OMP_ATOMIC_STORE: return GSS_OMP_ATOMIC_STORE; | |
133 case GIMPLE_PREDICT: return GSS_BASE; | |
134 default: gcc_unreachable (); | |
135 } | |
136 } | |
137 | |
138 | |
139 /* Return the number of bytes needed to hold a GIMPLE statement with | |
140 code CODE. */ | |
141 | |
142 static size_t | |
143 gimple_size (enum gimple_code code) | |
144 { | |
145 enum gimple_statement_structure_enum gss = gss_for_code (code); | |
146 | |
147 if (gss == GSS_WITH_OPS) | |
148 return sizeof (struct gimple_statement_with_ops); | |
149 else if (gss == GSS_WITH_MEM_OPS) | |
150 return sizeof (struct gimple_statement_with_memory_ops); | |
151 | |
152 switch (code) | |
153 { | |
154 case GIMPLE_ASM: | |
155 return sizeof (struct gimple_statement_asm); | |
156 case GIMPLE_NOP: | |
157 return sizeof (struct gimple_statement_base); | |
158 case GIMPLE_BIND: | |
159 return sizeof (struct gimple_statement_bind); | |
160 case GIMPLE_CATCH: | |
161 return sizeof (struct gimple_statement_catch); | |
162 case GIMPLE_EH_FILTER: | |
163 return sizeof (struct gimple_statement_eh_filter); | |
164 case GIMPLE_TRY: | |
165 return sizeof (struct gimple_statement_try); | |
166 case GIMPLE_RESX: | |
167 return sizeof (struct gimple_statement_resx); | |
168 case GIMPLE_OMP_CRITICAL: | |
169 return sizeof (struct gimple_statement_omp_critical); | |
170 case GIMPLE_OMP_FOR: | |
171 return sizeof (struct gimple_statement_omp_for); | |
172 case GIMPLE_OMP_PARALLEL: | |
173 return sizeof (struct gimple_statement_omp_parallel); | |
174 case GIMPLE_OMP_TASK: | |
175 return sizeof (struct gimple_statement_omp_task); | |
176 case GIMPLE_OMP_SECTION: | |
177 case GIMPLE_OMP_MASTER: | |
178 case GIMPLE_OMP_ORDERED: | |
179 return sizeof (struct gimple_statement_omp); | |
180 case GIMPLE_OMP_RETURN: | |
181 return sizeof (struct gimple_statement_base); | |
182 case GIMPLE_OMP_CONTINUE: | |
183 return sizeof (struct gimple_statement_omp_continue); | |
184 case GIMPLE_OMP_SECTIONS: | |
185 return sizeof (struct gimple_statement_omp_sections); | |
186 case GIMPLE_OMP_SECTIONS_SWITCH: | |
187 return sizeof (struct gimple_statement_base); | |
188 case GIMPLE_OMP_SINGLE: | |
189 return sizeof (struct gimple_statement_omp_single); | |
190 case GIMPLE_OMP_ATOMIC_LOAD: | |
191 return sizeof (struct gimple_statement_omp_atomic_load); | |
192 case GIMPLE_OMP_ATOMIC_STORE: | |
193 return sizeof (struct gimple_statement_omp_atomic_store); | |
194 case GIMPLE_WITH_CLEANUP_EXPR: | |
195 return sizeof (struct gimple_statement_wce); | |
196 case GIMPLE_CHANGE_DYNAMIC_TYPE: | |
197 return sizeof (struct gimple_statement_with_ops); | |
198 case GIMPLE_PREDICT: | |
199 return sizeof (struct gimple_statement_base); | |
200 default: | |
201 break; | |
202 } | |
203 | |
204 gcc_unreachable (); | |
205 } | |
206 | |
207 | |
208 /* Allocate memory for a GIMPLE statement with code CODE and NUM_OPS | |
209 operands. */ | |
210 | |
211 #define gimple_alloc(c, n) gimple_alloc_stat (c, n MEM_STAT_INFO) | |
212 static gimple | |
213 gimple_alloc_stat (enum gimple_code code, unsigned num_ops MEM_STAT_DECL) | |
214 { | |
215 size_t size; | |
216 gimple stmt; | |
217 | |
218 size = gimple_size (code); | |
219 if (num_ops > 0) | |
220 size += sizeof (tree) * (num_ops - 1); | |
221 | |
222 #ifdef GATHER_STATISTICS | |
223 { | |
224 enum gimple_alloc_kind kind = gimple_alloc_kind (code); | |
225 gimple_alloc_counts[(int) kind]++; | |
226 gimple_alloc_sizes[(int) kind] += size; | |
227 } | |
228 #endif | |
229 | |
230 stmt = (gimple) ggc_alloc_cleared_stat (size PASS_MEM_STAT); | |
231 gimple_set_code (stmt, code); | |
232 gimple_set_num_ops (stmt, num_ops); | |
233 | |
234 /* Do not call gimple_set_modified here as it has other side | |
235 effects and this tuple is still not completely built. */ | |
236 stmt->gsbase.modified = 1; | |
237 | |
238 return stmt; | |
239 } | |
240 | |
241 /* Set SUBCODE to be the code of the expression computed by statement G. */ | |
242 | |
243 static inline void | |
244 gimple_set_subcode (gimple g, unsigned subcode) | |
245 { | |
246 /* We only have 16 bits for the RHS code. Assert that we are not | |
247 overflowing it. */ | |
248 gcc_assert (subcode < (1 << 16)); | |
249 g->gsbase.subcode = subcode; | |
250 } | |
251 | |
252 | |
253 | |
254 /* Build a tuple with operands. CODE is the statement to build (which | |
255 must be one of the GIMPLE_WITH_OPS tuples). SUBCODE is the sub-code | |
256 for the new tuple. NUM_OPS is the number of operands to allocate. */ | |
257 | |
258 #define gimple_build_with_ops(c, s, n) \ | |
259 gimple_build_with_ops_stat (c, s, n MEM_STAT_INFO) | |
260 | |
261 static gimple | |
262 gimple_build_with_ops_stat (enum gimple_code code, enum tree_code subcode, | |
263 unsigned num_ops MEM_STAT_DECL) | |
264 { | |
265 gimple s = gimple_alloc_stat (code, num_ops PASS_MEM_STAT); | |
266 gimple_set_subcode (s, subcode); | |
267 | |
268 return s; | |
269 } | |
270 | |
271 | |
272 /* Build a GIMPLE_RETURN statement returning RETVAL. */ | |
273 | |
274 gimple | |
275 gimple_build_return (tree retval) | |
276 { | |
277 gimple s = gimple_build_with_ops (GIMPLE_RETURN, 0, 1); | |
278 if (retval) | |
279 gimple_return_set_retval (s, retval); | |
280 return s; | |
281 } | |
282 | |
283 /* Helper for gimple_build_call, gimple_build_call_vec and | |
284 gimple_build_call_from_tree. Build the basic components of a | |
285 GIMPLE_CALL statement to function FN with NARGS arguments. */ | |
286 | |
287 static inline gimple | |
288 gimple_build_call_1 (tree fn, unsigned nargs) | |
289 { | |
290 gimple s = gimple_build_with_ops (GIMPLE_CALL, 0, nargs + 3); | |
291 if (TREE_CODE (fn) == FUNCTION_DECL) | |
292 fn = build_fold_addr_expr (fn); | |
293 gimple_set_op (s, 1, fn); | |
294 return s; | |
295 } | |
296 | |
297 | |
298 /* Build a GIMPLE_CALL statement to function FN with the arguments | |
299 specified in vector ARGS. */ | |
300 | |
301 gimple | |
302 gimple_build_call_vec (tree fn, VEC(tree, heap) *args) | |
303 { | |
304 unsigned i; | |
305 unsigned nargs = VEC_length (tree, args); | |
306 gimple call = gimple_build_call_1 (fn, nargs); | |
307 | |
308 for (i = 0; i < nargs; i++) | |
309 gimple_call_set_arg (call, i, VEC_index (tree, args, i)); | |
310 | |
311 return call; | |
312 } | |
313 | |
314 | |
315 /* Build a GIMPLE_CALL statement to function FN. NARGS is the number of | |
316 arguments. The ... are the arguments. */ | |
317 | |
318 gimple | |
319 gimple_build_call (tree fn, unsigned nargs, ...) | |
320 { | |
321 va_list ap; | |
322 gimple call; | |
323 unsigned i; | |
324 | |
325 gcc_assert (TREE_CODE (fn) == FUNCTION_DECL || is_gimple_call_addr (fn)); | |
326 | |
327 call = gimple_build_call_1 (fn, nargs); | |
328 | |
329 va_start (ap, nargs); | |
330 for (i = 0; i < nargs; i++) | |
331 gimple_call_set_arg (call, i, va_arg (ap, tree)); | |
332 va_end (ap); | |
333 | |
334 return call; | |
335 } | |
336 | |
337 | |
338 /* Build a GIMPLE_CALL statement from CALL_EXPR T. Note that T is | |
339 assumed to be in GIMPLE form already. Minimal checking is done of | |
340 this fact. */ | |
341 | |
342 gimple | |
343 gimple_build_call_from_tree (tree t) | |
344 { | |
345 unsigned i, nargs; | |
346 gimple call; | |
347 tree fndecl = get_callee_fndecl (t); | |
348 | |
349 gcc_assert (TREE_CODE (t) == CALL_EXPR); | |
350 | |
351 nargs = call_expr_nargs (t); | |
352 call = gimple_build_call_1 (fndecl ? fndecl : CALL_EXPR_FN (t), nargs); | |
353 | |
354 for (i = 0; i < nargs; i++) | |
355 gimple_call_set_arg (call, i, CALL_EXPR_ARG (t, i)); | |
356 | |
357 gimple_set_block (call, TREE_BLOCK (t)); | |
358 | |
359 /* Carry all the CALL_EXPR flags to the new GIMPLE_CALL. */ | |
360 gimple_call_set_chain (call, CALL_EXPR_STATIC_CHAIN (t)); | |
361 gimple_call_set_tail (call, CALL_EXPR_TAILCALL (t)); | |
362 gimple_call_set_cannot_inline (call, CALL_CANNOT_INLINE_P (t)); | |
363 gimple_call_set_return_slot_opt (call, CALL_EXPR_RETURN_SLOT_OPT (t)); | |
364 gimple_call_set_from_thunk (call, CALL_FROM_THUNK_P (t)); | |
365 gimple_call_set_va_arg_pack (call, CALL_EXPR_VA_ARG_PACK (t)); | |
5
a4c410aa4714
modifing gimple.[ch], cfgexpand.c
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
366 #ifndef noCbC |
21 | 367 gimple_call_set_cbc_goto (call, CALL_EXPR_CbC_GOTO (t)); |
5
a4c410aa4714
modifing gimple.[ch], cfgexpand.c
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
368 #endif |
0 | 369 |
370 return call; | |
371 } | |
372 | |
373 | |
374 /* Extract the operands and code for expression EXPR into *SUBCODE_P, | |
375 *OP1_P and *OP2_P respectively. */ | |
376 | |
377 void | |
378 extract_ops_from_tree (tree expr, enum tree_code *subcode_p, tree *op1_p, | |
379 tree *op2_p) | |
380 { | |
381 enum gimple_rhs_class grhs_class; | |
382 | |
383 *subcode_p = TREE_CODE (expr); | |
384 grhs_class = get_gimple_rhs_class (*subcode_p); | |
385 | |
386 if (grhs_class == GIMPLE_BINARY_RHS) | |
387 { | |
388 *op1_p = TREE_OPERAND (expr, 0); | |
389 *op2_p = TREE_OPERAND (expr, 1); | |
390 } | |
391 else if (grhs_class == GIMPLE_UNARY_RHS) | |
392 { | |
393 *op1_p = TREE_OPERAND (expr, 0); | |
394 *op2_p = NULL_TREE; | |
395 } | |
396 else if (grhs_class == GIMPLE_SINGLE_RHS) | |
397 { | |
398 *op1_p = expr; | |
399 *op2_p = NULL_TREE; | |
400 } | |
401 else | |
402 gcc_unreachable (); | |
403 } | |
404 | |
405 | |
406 /* Build a GIMPLE_ASSIGN statement. | |
407 | |
408 LHS of the assignment. | |
409 RHS of the assignment which can be unary or binary. */ | |
410 | |
411 gimple | |
412 gimple_build_assign_stat (tree lhs, tree rhs MEM_STAT_DECL) | |
413 { | |
414 enum tree_code subcode; | |
415 tree op1, op2; | |
416 | |
417 extract_ops_from_tree (rhs, &subcode, &op1, &op2); | |
418 return gimple_build_assign_with_ops_stat (subcode, lhs, op1, op2 | |
419 PASS_MEM_STAT); | |
420 } | |
421 | |
422 | |
423 /* Build a GIMPLE_ASSIGN statement with sub-code SUBCODE and operands | |
424 OP1 and OP2. If OP2 is NULL then SUBCODE must be of class | |
425 GIMPLE_UNARY_RHS or GIMPLE_SINGLE_RHS. */ | |
426 | |
427 gimple | |
428 gimple_build_assign_with_ops_stat (enum tree_code subcode, tree lhs, tree op1, | |
429 tree op2 MEM_STAT_DECL) | |
430 { | |
431 unsigned num_ops; | |
432 gimple p; | |
433 | |
434 /* Need 1 operand for LHS and 1 or 2 for the RHS (depending on the | |
435 code). */ | |
436 num_ops = get_gimple_rhs_num_ops (subcode) + 1; | |
437 | |
438 p = gimple_build_with_ops_stat (GIMPLE_ASSIGN, subcode, num_ops | |
439 PASS_MEM_STAT); | |
440 gimple_assign_set_lhs (p, lhs); | |
441 gimple_assign_set_rhs1 (p, op1); | |
442 if (op2) | |
443 { | |
444 gcc_assert (num_ops > 2); | |
445 gimple_assign_set_rhs2 (p, op2); | |
446 } | |
447 | |
448 return p; | |
449 } | |
450 | |
451 | |
452 /* Build a new GIMPLE_ASSIGN tuple and append it to the end of *SEQ_P. | |
453 | |
454 DST/SRC are the destination and source respectively. You can pass | |
455 ungimplified trees in DST or SRC, in which case they will be | |
456 converted to a gimple operand if necessary. | |
457 | |
458 This function returns the newly created GIMPLE_ASSIGN tuple. */ | |
459 | |
460 inline gimple | |
461 gimplify_assign (tree dst, tree src, gimple_seq *seq_p) | |
462 { | |
463 tree t = build2 (MODIFY_EXPR, TREE_TYPE (dst), dst, src); | |
464 gimplify_and_add (t, seq_p); | |
465 ggc_free (t); | |
466 return gimple_seq_last_stmt (*seq_p); | |
467 } | |
468 | |
469 | |
470 /* Build a GIMPLE_COND statement. | |
471 | |
472 PRED is the condition used to compare LHS and the RHS. | |
473 T_LABEL is the label to jump to if the condition is true. | |
474 F_LABEL is the label to jump to otherwise. */ | |
475 | |
476 gimple | |
477 gimple_build_cond (enum tree_code pred_code, tree lhs, tree rhs, | |
478 tree t_label, tree f_label) | |
479 { | |
480 gimple p; | |
481 | |
482 gcc_assert (TREE_CODE_CLASS (pred_code) == tcc_comparison); | |
483 p = gimple_build_with_ops (GIMPLE_COND, pred_code, 4); | |
484 gimple_cond_set_lhs (p, lhs); | |
485 gimple_cond_set_rhs (p, rhs); | |
486 gimple_cond_set_true_label (p, t_label); | |
487 gimple_cond_set_false_label (p, f_label); | |
488 return p; | |
489 } | |
490 | |
491 | |
492 /* Extract operands for a GIMPLE_COND statement out of COND_EXPR tree COND. */ | |
493 | |
494 void | |
495 gimple_cond_get_ops_from_tree (tree cond, enum tree_code *code_p, | |
496 tree *lhs_p, tree *rhs_p) | |
497 { | |
498 gcc_assert (TREE_CODE_CLASS (TREE_CODE (cond)) == tcc_comparison | |
499 || TREE_CODE (cond) == TRUTH_NOT_EXPR | |
500 || is_gimple_min_invariant (cond) | |
501 || SSA_VAR_P (cond)); | |
502 | |
503 extract_ops_from_tree (cond, code_p, lhs_p, rhs_p); | |
504 | |
505 /* Canonicalize conditionals of the form 'if (!VAL)'. */ | |
506 if (*code_p == TRUTH_NOT_EXPR) | |
507 { | |
508 *code_p = EQ_EXPR; | |
509 gcc_assert (*lhs_p && *rhs_p == NULL_TREE); | |
510 *rhs_p = fold_convert (TREE_TYPE (*lhs_p), integer_zero_node); | |
511 } | |
512 /* Canonicalize conditionals of the form 'if (VAL)' */ | |
513 else if (TREE_CODE_CLASS (*code_p) != tcc_comparison) | |
514 { | |
515 *code_p = NE_EXPR; | |
516 gcc_assert (*lhs_p && *rhs_p == NULL_TREE); | |
517 *rhs_p = fold_convert (TREE_TYPE (*lhs_p), integer_zero_node); | |
518 } | |
519 } | |
520 | |
521 | |
522 /* Build a GIMPLE_COND statement from the conditional expression tree | |
523 COND. T_LABEL and F_LABEL are as in gimple_build_cond. */ | |
524 | |
525 gimple | |
526 gimple_build_cond_from_tree (tree cond, tree t_label, tree f_label) | |
527 { | |
528 enum tree_code code; | |
529 tree lhs, rhs; | |
530 | |
531 gimple_cond_get_ops_from_tree (cond, &code, &lhs, &rhs); | |
532 return gimple_build_cond (code, lhs, rhs, t_label, f_label); | |
533 } | |
534 | |
535 /* Set code, lhs, and rhs of a GIMPLE_COND from a suitable | |
536 boolean expression tree COND. */ | |
537 | |
538 void | |
539 gimple_cond_set_condition_from_tree (gimple stmt, tree cond) | |
540 { | |
541 enum tree_code code; | |
542 tree lhs, rhs; | |
543 | |
544 gimple_cond_get_ops_from_tree (cond, &code, &lhs, &rhs); | |
545 gimple_cond_set_condition (stmt, code, lhs, rhs); | |
546 } | |
547 | |
548 /* Build a GIMPLE_LABEL statement for LABEL. */ | |
549 | |
550 gimple | |
551 gimple_build_label (tree label) | |
552 { | |
553 gimple p = gimple_build_with_ops (GIMPLE_LABEL, 0, 1); | |
554 gimple_label_set_label (p, label); | |
555 return p; | |
556 } | |
557 | |
558 /* Build a GIMPLE_GOTO statement to label DEST. */ | |
559 | |
560 gimple | |
561 gimple_build_goto (tree dest) | |
562 { | |
563 gimple p = gimple_build_with_ops (GIMPLE_GOTO, 0, 1); | |
564 gimple_goto_set_dest (p, dest); | |
565 return p; | |
566 } | |
567 | |
568 | |
569 /* Build a GIMPLE_NOP statement. */ | |
570 | |
571 gimple | |
572 gimple_build_nop (void) | |
573 { | |
574 return gimple_alloc (GIMPLE_NOP, 0); | |
575 } | |
576 | |
577 | |
578 /* Build a GIMPLE_BIND statement. | |
579 VARS are the variables in BODY. | |
580 BLOCK is the containing block. */ | |
581 | |
582 gimple | |
583 gimple_build_bind (tree vars, gimple_seq body, tree block) | |
584 { | |
585 gimple p = gimple_alloc (GIMPLE_BIND, 0); | |
586 gimple_bind_set_vars (p, vars); | |
587 if (body) | |
588 gimple_bind_set_body (p, body); | |
589 if (block) | |
590 gimple_bind_set_block (p, block); | |
591 return p; | |
592 } | |
593 | |
594 /* Helper function to set the simple fields of a asm stmt. | |
595 | |
596 STRING is a pointer to a string that is the asm blocks assembly code. | |
597 NINPUT is the number of register inputs. | |
598 NOUTPUT is the number of register outputs. | |
599 NCLOBBERS is the number of clobbered registers. | |
600 */ | |
601 | |
602 static inline gimple | |
603 gimple_build_asm_1 (const char *string, unsigned ninputs, unsigned noutputs, | |
604 unsigned nclobbers) | |
605 { | |
606 gimple p; | |
607 int size = strlen (string); | |
608 | |
609 p = gimple_build_with_ops (GIMPLE_ASM, 0, ninputs + noutputs + nclobbers); | |
610 | |
611 p->gimple_asm.ni = ninputs; | |
612 p->gimple_asm.no = noutputs; | |
613 p->gimple_asm.nc = nclobbers; | |
614 p->gimple_asm.string = ggc_alloc_string (string, size); | |
615 | |
616 #ifdef GATHER_STATISTICS | |
617 gimple_alloc_sizes[(int) gimple_alloc_kind (GIMPLE_ASM)] += size; | |
618 #endif | |
619 | |
620 return p; | |
621 } | |
622 | |
623 /* Build a GIMPLE_ASM statement. | |
624 | |
625 STRING is the assembly code. | |
626 NINPUT is the number of register inputs. | |
627 NOUTPUT is the number of register outputs. | |
628 NCLOBBERS is the number of clobbered registers. | |
629 INPUTS is a vector of the input register parameters. | |
630 OUTPUTS is a vector of the output register parameters. | |
631 CLOBBERS is a vector of the clobbered register parameters. */ | |
632 | |
633 gimple | |
634 gimple_build_asm_vec (const char *string, VEC(tree,gc)* inputs, | |
635 VEC(tree,gc)* outputs, VEC(tree,gc)* clobbers) | |
636 { | |
637 gimple p; | |
638 unsigned i; | |
639 | |
640 p = gimple_build_asm_1 (string, | |
641 VEC_length (tree, inputs), | |
642 VEC_length (tree, outputs), | |
643 VEC_length (tree, clobbers)); | |
644 | |
645 for (i = 0; i < VEC_length (tree, inputs); i++) | |
646 gimple_asm_set_input_op (p, i, VEC_index (tree, inputs, i)); | |
647 | |
648 for (i = 0; i < VEC_length (tree, outputs); i++) | |
649 gimple_asm_set_output_op (p, i, VEC_index (tree, outputs, i)); | |
650 | |
651 for (i = 0; i < VEC_length (tree, clobbers); i++) | |
652 gimple_asm_set_clobber_op (p, i, VEC_index (tree, clobbers, i)); | |
653 | |
654 return p; | |
655 } | |
656 | |
657 /* Build a GIMPLE_ASM statement. | |
658 | |
659 STRING is the assembly code. | |
660 NINPUT is the number of register inputs. | |
661 NOUTPUT is the number of register outputs. | |
662 NCLOBBERS is the number of clobbered registers. | |
663 ... are trees for each input, output and clobbered register. */ | |
664 | |
665 gimple | |
666 gimple_build_asm (const char *string, unsigned ninputs, unsigned noutputs, | |
667 unsigned nclobbers, ...) | |
668 { | |
669 gimple p; | |
670 unsigned i; | |
671 va_list ap; | |
672 | |
673 p = gimple_build_asm_1 (string, ninputs, noutputs, nclobbers); | |
674 | |
675 va_start (ap, nclobbers); | |
676 | |
677 for (i = 0; i < ninputs; i++) | |
678 gimple_asm_set_input_op (p, i, va_arg (ap, tree)); | |
679 | |
680 for (i = 0; i < noutputs; i++) | |
681 gimple_asm_set_output_op (p, i, va_arg (ap, tree)); | |
682 | |
683 for (i = 0; i < nclobbers; i++) | |
684 gimple_asm_set_clobber_op (p, i, va_arg (ap, tree)); | |
685 | |
686 va_end (ap); | |
687 | |
688 return p; | |
689 } | |
690 | |
691 /* Build a GIMPLE_CATCH statement. | |
692 | |
693 TYPES are the catch types. | |
694 HANDLER is the exception handler. */ | |
695 | |
696 gimple | |
697 gimple_build_catch (tree types, gimple_seq handler) | |
698 { | |
699 gimple p = gimple_alloc (GIMPLE_CATCH, 0); | |
700 gimple_catch_set_types (p, types); | |
701 if (handler) | |
702 gimple_catch_set_handler (p, handler); | |
703 | |
704 return p; | |
705 } | |
706 | |
707 /* Build a GIMPLE_EH_FILTER statement. | |
708 | |
709 TYPES are the filter's types. | |
710 FAILURE is the filter's failure action. */ | |
711 | |
712 gimple | |
713 gimple_build_eh_filter (tree types, gimple_seq failure) | |
714 { | |
715 gimple p = gimple_alloc (GIMPLE_EH_FILTER, 0); | |
716 gimple_eh_filter_set_types (p, types); | |
717 if (failure) | |
718 gimple_eh_filter_set_failure (p, failure); | |
719 | |
720 return p; | |
721 } | |
722 | |
723 /* Build a GIMPLE_TRY statement. | |
724 | |
725 EVAL is the expression to evaluate. | |
726 CLEANUP is the cleanup expression. | |
727 KIND is either GIMPLE_TRY_CATCH or GIMPLE_TRY_FINALLY depending on | |
728 whether this is a try/catch or a try/finally respectively. */ | |
729 | |
730 gimple | |
731 gimple_build_try (gimple_seq eval, gimple_seq cleanup, | |
732 enum gimple_try_flags kind) | |
733 { | |
734 gimple p; | |
735 | |
736 gcc_assert (kind == GIMPLE_TRY_CATCH || kind == GIMPLE_TRY_FINALLY); | |
737 p = gimple_alloc (GIMPLE_TRY, 0); | |
738 gimple_set_subcode (p, kind); | |
739 if (eval) | |
740 gimple_try_set_eval (p, eval); | |
741 if (cleanup) | |
742 gimple_try_set_cleanup (p, cleanup); | |
743 | |
744 return p; | |
745 } | |
746 | |
747 /* Construct a GIMPLE_WITH_CLEANUP_EXPR statement. | |
748 | |
749 CLEANUP is the cleanup expression. */ | |
750 | |
751 gimple | |
752 gimple_build_wce (gimple_seq cleanup) | |
753 { | |
754 gimple p = gimple_alloc (GIMPLE_WITH_CLEANUP_EXPR, 0); | |
755 if (cleanup) | |
756 gimple_wce_set_cleanup (p, cleanup); | |
757 | |
758 return p; | |
759 } | |
760 | |
761 | |
762 /* Build a GIMPLE_RESX statement. | |
763 | |
764 REGION is the region number from which this resx causes control flow to | |
765 leave. */ | |
766 | |
767 gimple | |
768 gimple_build_resx (int region) | |
769 { | |
770 gimple p = gimple_alloc (GIMPLE_RESX, 0); | |
771 gimple_resx_set_region (p, region); | |
772 return p; | |
773 } | |
774 | |
775 | |
776 /* The helper for constructing a gimple switch statement. | |
777 INDEX is the switch's index. | |
778 NLABELS is the number of labels in the switch excluding the default. | |
779 DEFAULT_LABEL is the default label for the switch statement. */ | |
780 | |
781 static inline gimple | |
782 gimple_build_switch_1 (unsigned nlabels, tree index, tree default_label) | |
783 { | |
784 /* nlabels + 1 default label + 1 index. */ | |
785 gimple p = gimple_build_with_ops (GIMPLE_SWITCH, 0, nlabels + 1 + 1); | |
786 gimple_switch_set_index (p, index); | |
787 gimple_switch_set_default_label (p, default_label); | |
788 return p; | |
789 } | |
790 | |
791 | |
792 /* Build a GIMPLE_SWITCH statement. | |
793 | |
794 INDEX is the switch's index. | |
795 NLABELS is the number of labels in the switch excluding the DEFAULT_LABEL. | |
796 ... are the labels excluding the default. */ | |
797 | |
798 gimple | |
799 gimple_build_switch (unsigned nlabels, tree index, tree default_label, ...) | |
800 { | |
801 va_list al; | |
802 unsigned i; | |
803 gimple p; | |
804 | |
805 p = gimple_build_switch_1 (nlabels, index, default_label); | |
806 | |
807 /* Store the rest of the labels. */ | |
808 va_start (al, default_label); | |
809 for (i = 1; i <= nlabels; i++) | |
810 gimple_switch_set_label (p, i, va_arg (al, tree)); | |
811 va_end (al); | |
812 | |
813 return p; | |
814 } | |
815 | |
816 | |
817 /* Build a GIMPLE_SWITCH statement. | |
818 | |
819 INDEX is the switch's index. | |
820 DEFAULT_LABEL is the default label | |
821 ARGS is a vector of labels excluding the default. */ | |
822 | |
823 gimple | |
824 gimple_build_switch_vec (tree index, tree default_label, VEC(tree, heap) *args) | |
825 { | |
826 unsigned i; | |
827 unsigned nlabels = VEC_length (tree, args); | |
828 gimple p = gimple_build_switch_1 (nlabels, index, default_label); | |
829 | |
830 /* Put labels in labels[1 - (nlabels + 1)]. | |
831 Default label is in labels[0]. */ | |
832 for (i = 1; i <= nlabels; i++) | |
833 gimple_switch_set_label (p, i, VEC_index (tree, args, i - 1)); | |
834 | |
835 return p; | |
836 } | |
837 | |
838 | |
839 /* Build a GIMPLE_OMP_CRITICAL statement. | |
840 | |
841 BODY is the sequence of statements for which only one thread can execute. | |
842 NAME is optional identifier for this critical block. */ | |
843 | |
844 gimple | |
845 gimple_build_omp_critical (gimple_seq body, tree name) | |
846 { | |
847 gimple p = gimple_alloc (GIMPLE_OMP_CRITICAL, 0); | |
848 gimple_omp_critical_set_name (p, name); | |
849 if (body) | |
850 gimple_omp_set_body (p, body); | |
851 | |
852 return p; | |
853 } | |
854 | |
855 /* Build a GIMPLE_OMP_FOR statement. | |
856 | |
857 BODY is sequence of statements inside the for loop. | |
858 CLAUSES, are any of the OMP loop construct's clauses: private, firstprivate, | |
859 lastprivate, reductions, ordered, schedule, and nowait. | |
860 COLLAPSE is the collapse count. | |
861 PRE_BODY is the sequence of statements that are loop invariant. */ | |
862 | |
863 gimple | |
864 gimple_build_omp_for (gimple_seq body, tree clauses, size_t collapse, | |
865 gimple_seq pre_body) | |
866 { | |
867 gimple p = gimple_alloc (GIMPLE_OMP_FOR, 0); | |
868 if (body) | |
869 gimple_omp_set_body (p, body); | |
870 gimple_omp_for_set_clauses (p, clauses); | |
871 p->gimple_omp_for.collapse = collapse; | |
872 p->gimple_omp_for.iter = GGC_CNEWVEC (struct gimple_omp_for_iter, collapse); | |
873 if (pre_body) | |
874 gimple_omp_for_set_pre_body (p, pre_body); | |
875 | |
876 return p; | |
877 } | |
878 | |
879 | |
880 /* Build a GIMPLE_OMP_PARALLEL statement. | |
881 | |
882 BODY is sequence of statements which are executed in parallel. | |
883 CLAUSES, are the OMP parallel construct's clauses. | |
884 CHILD_FN is the function created for the parallel threads to execute. | |
885 DATA_ARG are the shared data argument(s). */ | |
886 | |
887 gimple | |
888 gimple_build_omp_parallel (gimple_seq body, tree clauses, tree child_fn, | |
889 tree data_arg) | |
890 { | |
891 gimple p = gimple_alloc (GIMPLE_OMP_PARALLEL, 0); | |
892 if (body) | |
893 gimple_omp_set_body (p, body); | |
894 gimple_omp_parallel_set_clauses (p, clauses); | |
895 gimple_omp_parallel_set_child_fn (p, child_fn); | |
896 gimple_omp_parallel_set_data_arg (p, data_arg); | |
897 | |
898 return p; | |
899 } | |
900 | |
901 | |
902 /* Build a GIMPLE_OMP_TASK statement. | |
903 | |
904 BODY is sequence of statements which are executed by the explicit task. | |
905 CLAUSES, are the OMP parallel construct's clauses. | |
906 CHILD_FN is the function created for the parallel threads to execute. | |
907 DATA_ARG are the shared data argument(s). | |
908 COPY_FN is the optional function for firstprivate initialization. | |
909 ARG_SIZE and ARG_ALIGN are size and alignment of the data block. */ | |
910 | |
911 gimple | |
912 gimple_build_omp_task (gimple_seq body, tree clauses, tree child_fn, | |
913 tree data_arg, tree copy_fn, tree arg_size, | |
914 tree arg_align) | |
915 { | |
916 gimple p = gimple_alloc (GIMPLE_OMP_TASK, 0); | |
917 if (body) | |
918 gimple_omp_set_body (p, body); | |
919 gimple_omp_task_set_clauses (p, clauses); | |
920 gimple_omp_task_set_child_fn (p, child_fn); | |
921 gimple_omp_task_set_data_arg (p, data_arg); | |
922 gimple_omp_task_set_copy_fn (p, copy_fn); | |
923 gimple_omp_task_set_arg_size (p, arg_size); | |
924 gimple_omp_task_set_arg_align (p, arg_align); | |
925 | |
926 return p; | |
927 } | |
928 | |
929 | |
930 /* Build a GIMPLE_OMP_SECTION statement for a sections statement. | |
931 | |
932 BODY is the sequence of statements in the section. */ | |
933 | |
934 gimple | |
935 gimple_build_omp_section (gimple_seq body) | |
936 { | |
937 gimple p = gimple_alloc (GIMPLE_OMP_SECTION, 0); | |
938 if (body) | |
939 gimple_omp_set_body (p, body); | |
940 | |
941 return p; | |
942 } | |
943 | |
944 | |
945 /* Build a GIMPLE_OMP_MASTER statement. | |
946 | |
947 BODY is the sequence of statements to be executed by just the master. */ | |
948 | |
949 gimple | |
950 gimple_build_omp_master (gimple_seq body) | |
951 { | |
952 gimple p = gimple_alloc (GIMPLE_OMP_MASTER, 0); | |
953 if (body) | |
954 gimple_omp_set_body (p, body); | |
955 | |
956 return p; | |
957 } | |
958 | |
959 | |
960 /* Build a GIMPLE_OMP_CONTINUE statement. | |
961 | |
962 CONTROL_DEF is the definition of the control variable. | |
963 CONTROL_USE is the use of the control variable. */ | |
964 | |
965 gimple | |
966 gimple_build_omp_continue (tree control_def, tree control_use) | |
967 { | |
968 gimple p = gimple_alloc (GIMPLE_OMP_CONTINUE, 0); | |
969 gimple_omp_continue_set_control_def (p, control_def); | |
970 gimple_omp_continue_set_control_use (p, control_use); | |
971 return p; | |
972 } | |
973 | |
974 /* Build a GIMPLE_OMP_ORDERED statement. | |
975 | |
976 BODY is the sequence of statements inside a loop that will executed in | |
977 sequence. */ | |
978 | |
979 gimple | |
980 gimple_build_omp_ordered (gimple_seq body) | |
981 { | |
982 gimple p = gimple_alloc (GIMPLE_OMP_ORDERED, 0); | |
983 if (body) | |
984 gimple_omp_set_body (p, body); | |
985 | |
986 return p; | |
987 } | |
988 | |
989 | |
990 /* Build a GIMPLE_OMP_RETURN statement. | |
991 WAIT_P is true if this is a non-waiting return. */ | |
992 | |
993 gimple | |
994 gimple_build_omp_return (bool wait_p) | |
995 { | |
996 gimple p = gimple_alloc (GIMPLE_OMP_RETURN, 0); | |
997 if (wait_p) | |
998 gimple_omp_return_set_nowait (p); | |
999 | |
1000 return p; | |
1001 } | |
1002 | |
1003 | |
1004 /* Build a GIMPLE_OMP_SECTIONS statement. | |
1005 | |
1006 BODY is a sequence of section statements. | |
1007 CLAUSES are any of the OMP sections contsruct's clauses: private, | |
1008 firstprivate, lastprivate, reduction, and nowait. */ | |
1009 | |
1010 gimple | |
1011 gimple_build_omp_sections (gimple_seq body, tree clauses) | |
1012 { | |
1013 gimple p = gimple_alloc (GIMPLE_OMP_SECTIONS, 0); | |
1014 if (body) | |
1015 gimple_omp_set_body (p, body); | |
1016 gimple_omp_sections_set_clauses (p, clauses); | |
1017 | |
1018 return p; | |
1019 } | |
1020 | |
1021 | |
1022 /* Build a GIMPLE_OMP_SECTIONS_SWITCH. */ | |
1023 | |
1024 gimple | |
1025 gimple_build_omp_sections_switch (void) | |
1026 { | |
1027 return gimple_alloc (GIMPLE_OMP_SECTIONS_SWITCH, 0); | |
1028 } | |
1029 | |
1030 | |
1031 /* Build a GIMPLE_OMP_SINGLE statement. | |
1032 | |
1033 BODY is the sequence of statements that will be executed once. | |
1034 CLAUSES are any of the OMP single construct's clauses: private, firstprivate, | |
1035 copyprivate, nowait. */ | |
1036 | |
1037 gimple | |
1038 gimple_build_omp_single (gimple_seq body, tree clauses) | |
1039 { | |
1040 gimple p = gimple_alloc (GIMPLE_OMP_SINGLE, 0); | |
1041 if (body) | |
1042 gimple_omp_set_body (p, body); | |
1043 gimple_omp_single_set_clauses (p, clauses); | |
1044 | |
1045 return p; | |
1046 } | |
1047 | |
1048 | |
1049 /* Build a GIMPLE_CHANGE_DYNAMIC_TYPE statement. TYPE is the new type | |
1050 for the location PTR. */ | |
1051 | |
1052 gimple | |
1053 gimple_build_cdt (tree type, tree ptr) | |
1054 { | |
1055 gimple p = gimple_build_with_ops (GIMPLE_CHANGE_DYNAMIC_TYPE, 0, 2); | |
1056 gimple_cdt_set_new_type (p, type); | |
1057 gimple_cdt_set_location (p, ptr); | |
1058 | |
1059 return p; | |
1060 } | |
1061 | |
1062 | |
1063 /* Build a GIMPLE_OMP_ATOMIC_LOAD statement. */ | |
1064 | |
1065 gimple | |
1066 gimple_build_omp_atomic_load (tree lhs, tree rhs) | |
1067 { | |
1068 gimple p = gimple_alloc (GIMPLE_OMP_ATOMIC_LOAD, 0); | |
1069 gimple_omp_atomic_load_set_lhs (p, lhs); | |
1070 gimple_omp_atomic_load_set_rhs (p, rhs); | |
1071 return p; | |
1072 } | |
1073 | |
1074 /* Build a GIMPLE_OMP_ATOMIC_STORE statement. | |
1075 | |
1076 VAL is the value we are storing. */ | |
1077 | |
1078 gimple | |
1079 gimple_build_omp_atomic_store (tree val) | |
1080 { | |
1081 gimple p = gimple_alloc (GIMPLE_OMP_ATOMIC_STORE, 0); | |
1082 gimple_omp_atomic_store_set_val (p, val); | |
1083 return p; | |
1084 } | |
1085 | |
1086 /* Build a GIMPLE_PREDICT statement. PREDICT is one of the predictors from | |
1087 predict.def, OUTCOME is NOT_TAKEN or TAKEN. */ | |
1088 | |
1089 gimple | |
1090 gimple_build_predict (enum br_predictor predictor, enum prediction outcome) | |
1091 { | |
1092 gimple p = gimple_alloc (GIMPLE_PREDICT, 0); | |
1093 /* Ensure all the predictors fit into the lower bits of the subcode. */ | |
1094 gcc_assert ((int) END_PREDICTORS <= GF_PREDICT_TAKEN); | |
1095 gimple_predict_set_predictor (p, predictor); | |
1096 gimple_predict_set_outcome (p, outcome); | |
1097 return p; | |
1098 } | |
1099 | |
1100 /* Return which gimple structure is used by T. The enums here are defined | |
1101 in gsstruct.def. */ | |
1102 | |
1103 enum gimple_statement_structure_enum | |
1104 gimple_statement_structure (gimple gs) | |
1105 { | |
1106 return gss_for_code (gimple_code (gs)); | |
1107 } | |
1108 | |
1109 #if defined ENABLE_GIMPLE_CHECKING | |
1110 /* Complain of a gimple type mismatch and die. */ | |
1111 | |
1112 void | |
1113 gimple_check_failed (const_gimple gs, const char *file, int line, | |
1114 const char *function, enum gimple_code code, | |
1115 enum tree_code subcode) | |
1116 { | |
1117 internal_error ("gimple check: expected %s(%s), have %s(%s) in %s, at %s:%d", | |
1118 gimple_code_name[code], | |
1119 tree_code_name[subcode], | |
1120 gimple_code_name[gimple_code (gs)], | |
1121 gs->gsbase.subcode > 0 | |
1122 ? tree_code_name[gs->gsbase.subcode] | |
1123 : "", | |
1124 function, trim_filename (file), line); | |
1125 } | |
1126 #endif /* ENABLE_GIMPLE_CHECKING */ | |
1127 | |
1128 | |
1129 /* Allocate a new GIMPLE sequence in GC memory and return it. If | |
1130 there are free sequences in GIMPLE_SEQ_CACHE return one of those | |
1131 instead. */ | |
1132 | |
1133 gimple_seq | |
1134 gimple_seq_alloc (void) | |
1135 { | |
1136 gimple_seq seq = gimple_seq_cache; | |
1137 if (seq) | |
1138 { | |
1139 gimple_seq_cache = gimple_seq_cache->next_free; | |
1140 gcc_assert (gimple_seq_cache != seq); | |
1141 memset (seq, 0, sizeof (*seq)); | |
1142 } | |
1143 else | |
1144 { | |
1145 seq = (gimple_seq) ggc_alloc_cleared (sizeof (*seq)); | |
1146 #ifdef GATHER_STATISTICS | |
1147 gimple_alloc_counts[(int) gimple_alloc_kind_seq]++; | |
1148 gimple_alloc_sizes[(int) gimple_alloc_kind_seq] += sizeof (*seq); | |
1149 #endif | |
1150 } | |
1151 | |
1152 return seq; | |
1153 } | |
1154 | |
1155 /* Return SEQ to the free pool of GIMPLE sequences. */ | |
1156 | |
1157 void | |
1158 gimple_seq_free (gimple_seq seq) | |
1159 { | |
1160 if (seq == NULL) | |
1161 return; | |
1162 | |
1163 gcc_assert (gimple_seq_first (seq) == NULL); | |
1164 gcc_assert (gimple_seq_last (seq) == NULL); | |
1165 | |
1166 /* If this triggers, it's a sign that the same list is being freed | |
1167 twice. */ | |
1168 gcc_assert (seq != gimple_seq_cache || gimple_seq_cache == NULL); | |
1169 | |
1170 /* Add SEQ to the pool of free sequences. */ | |
1171 seq->next_free = gimple_seq_cache; | |
1172 gimple_seq_cache = seq; | |
1173 } | |
1174 | |
1175 | |
1176 /* Link gimple statement GS to the end of the sequence *SEQ_P. If | |
1177 *SEQ_P is NULL, a new sequence is allocated. */ | |
1178 | |
1179 void | |
1180 gimple_seq_add_stmt (gimple_seq *seq_p, gimple gs) | |
1181 { | |
1182 gimple_stmt_iterator si; | |
1183 | |
1184 if (gs == NULL) | |
1185 return; | |
1186 | |
1187 if (*seq_p == NULL) | |
1188 *seq_p = gimple_seq_alloc (); | |
1189 | |
1190 si = gsi_last (*seq_p); | |
1191 gsi_insert_after (&si, gs, GSI_NEW_STMT); | |
1192 } | |
1193 | |
1194 | |
1195 /* Append sequence SRC to the end of sequence *DST_P. If *DST_P is | |
1196 NULL, a new sequence is allocated. */ | |
1197 | |
1198 void | |
1199 gimple_seq_add_seq (gimple_seq *dst_p, gimple_seq src) | |
1200 { | |
1201 gimple_stmt_iterator si; | |
1202 | |
1203 if (src == NULL) | |
1204 return; | |
1205 | |
1206 if (*dst_p == NULL) | |
1207 *dst_p = gimple_seq_alloc (); | |
1208 | |
1209 si = gsi_last (*dst_p); | |
1210 gsi_insert_seq_after (&si, src, GSI_NEW_STMT); | |
1211 } | |
1212 | |
1213 | |
1214 /* Helper function of empty_body_p. Return true if STMT is an empty | |
1215 statement. */ | |
1216 | |
1217 static bool | |
1218 empty_stmt_p (gimple stmt) | |
1219 { | |
1220 if (gimple_code (stmt) == GIMPLE_NOP) | |
1221 return true; | |
1222 if (gimple_code (stmt) == GIMPLE_BIND) | |
1223 return empty_body_p (gimple_bind_body (stmt)); | |
1224 return false; | |
1225 } | |
1226 | |
1227 | |
1228 /* Return true if BODY contains nothing but empty statements. */ | |
1229 | |
1230 bool | |
1231 empty_body_p (gimple_seq body) | |
1232 { | |
1233 gimple_stmt_iterator i; | |
1234 | |
1235 | |
1236 if (gimple_seq_empty_p (body)) | |
1237 return true; | |
1238 for (i = gsi_start (body); !gsi_end_p (i); gsi_next (&i)) | |
1239 if (!empty_stmt_p (gsi_stmt (i))) | |
1240 return false; | |
1241 | |
1242 return true; | |
1243 } | |
1244 | |
1245 | |
1246 /* Perform a deep copy of sequence SRC and return the result. */ | |
1247 | |
1248 gimple_seq | |
1249 gimple_seq_copy (gimple_seq src) | |
1250 { | |
1251 gimple_stmt_iterator gsi; | |
1252 gimple_seq new_seq = gimple_seq_alloc (); | |
1253 gimple stmt; | |
1254 | |
1255 for (gsi = gsi_start (src); !gsi_end_p (gsi); gsi_next (&gsi)) | |
1256 { | |
1257 stmt = gimple_copy (gsi_stmt (gsi)); | |
1258 gimple_seq_add_stmt (&new_seq, stmt); | |
1259 } | |
1260 | |
1261 return new_seq; | |
1262 } | |
1263 | |
1264 | |
1265 /* Walk all the statements in the sequence SEQ calling walk_gimple_stmt | |
1266 on each one. WI is as in walk_gimple_stmt. | |
1267 | |
1268 If walk_gimple_stmt returns non-NULL, the walk is stopped, the | |
1269 value is stored in WI->CALLBACK_RESULT and the statement that | |
1270 produced the value is returned. | |
1271 | |
1272 Otherwise, all the statements are walked and NULL returned. */ | |
1273 | |
1274 gimple | |
1275 walk_gimple_seq (gimple_seq seq, walk_stmt_fn callback_stmt, | |
1276 walk_tree_fn callback_op, struct walk_stmt_info *wi) | |
1277 { | |
1278 gimple_stmt_iterator gsi; | |
1279 | |
1280 for (gsi = gsi_start (seq); !gsi_end_p (gsi); gsi_next (&gsi)) | |
1281 { | |
1282 tree ret = walk_gimple_stmt (&gsi, callback_stmt, callback_op, wi); | |
1283 if (ret) | |
1284 { | |
1285 /* If CALLBACK_STMT or CALLBACK_OP return a value, WI must exist | |
1286 to hold it. */ | |
1287 gcc_assert (wi); | |
1288 wi->callback_result = ret; | |
1289 return gsi_stmt (gsi); | |
1290 } | |
1291 } | |
1292 | |
1293 if (wi) | |
1294 wi->callback_result = NULL_TREE; | |
1295 | |
1296 return NULL; | |
1297 } | |
1298 | |
1299 | |
1300 /* Helper function for walk_gimple_stmt. Walk operands of a GIMPLE_ASM. */ | |
1301 | |
1302 static tree | |
1303 walk_gimple_asm (gimple stmt, walk_tree_fn callback_op, | |
1304 struct walk_stmt_info *wi) | |
1305 { | |
1306 tree ret; | |
1307 unsigned noutputs; | |
1308 const char **oconstraints; | |
1309 unsigned i; | |
1310 const char *constraint; | |
1311 bool allows_mem, allows_reg, is_inout; | |
1312 | |
1313 noutputs = gimple_asm_noutputs (stmt); | |
1314 oconstraints = (const char **) alloca ((noutputs) * sizeof (const char *)); | |
1315 | |
1316 if (wi) | |
1317 wi->is_lhs = true; | |
1318 | |
1319 for (i = 0; i < noutputs; i++) | |
1320 { | |
1321 tree op = gimple_asm_output_op (stmt, i); | |
1322 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op))); | |
1323 oconstraints[i] = constraint; | |
1324 parse_output_constraint (&constraint, i, 0, 0, &allows_mem, &allows_reg, | |
1325 &is_inout); | |
1326 if (wi) | |
1327 wi->val_only = (allows_reg || !allows_mem); | |
1328 ret = walk_tree (&TREE_VALUE (op), callback_op, wi, NULL); | |
1329 if (ret) | |
1330 return ret; | |
1331 } | |
1332 | |
1333 for (i = 0; i < gimple_asm_ninputs (stmt); i++) | |
1334 { | |
1335 tree op = gimple_asm_input_op (stmt, i); | |
1336 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op))); | |
1337 parse_input_constraint (&constraint, 0, 0, noutputs, 0, | |
1338 oconstraints, &allows_mem, &allows_reg); | |
1339 if (wi) | |
1340 wi->val_only = (allows_reg || !allows_mem); | |
1341 | |
1342 /* Although input "m" is not really a LHS, we need a lvalue. */ | |
1343 if (wi) | |
1344 wi->is_lhs = !wi->val_only; | |
1345 ret = walk_tree (&TREE_VALUE (op), callback_op, wi, NULL); | |
1346 if (ret) | |
1347 return ret; | |
1348 } | |
1349 | |
1350 if (wi) | |
1351 { | |
1352 wi->is_lhs = false; | |
1353 wi->val_only = true; | |
1354 } | |
1355 | |
1356 return NULL_TREE; | |
1357 } | |
1358 | |
1359 | |
1360 /* Helper function of WALK_GIMPLE_STMT. Walk every tree operand in | |
1361 STMT. CALLBACK_OP and WI are as in WALK_GIMPLE_STMT. | |
1362 | |
1363 CALLBACK_OP is called on each operand of STMT via walk_tree. | |
1364 Additional parameters to walk_tree must be stored in WI. For each operand | |
1365 OP, walk_tree is called as: | |
1366 | |
1367 walk_tree (&OP, CALLBACK_OP, WI, WI->PSET) | |
1368 | |
1369 If CALLBACK_OP returns non-NULL for an operand, the remaining | |
1370 operands are not scanned. | |
1371 | |
1372 The return value is that returned by the last call to walk_tree, or | |
1373 NULL_TREE if no CALLBACK_OP is specified. */ | |
1374 | |
1375 inline tree | |
1376 walk_gimple_op (gimple stmt, walk_tree_fn callback_op, | |
1377 struct walk_stmt_info *wi) | |
1378 { | |
1379 struct pointer_set_t *pset = (wi) ? wi->pset : NULL; | |
1380 unsigned i; | |
1381 tree ret = NULL_TREE; | |
1382 | |
1383 switch (gimple_code (stmt)) | |
1384 { | |
1385 case GIMPLE_ASSIGN: | |
1386 /* Walk the RHS operands. A formal temporary LHS may use a | |
1387 COMPONENT_REF RHS. */ | |
1388 if (wi) | |
1389 wi->val_only = !is_gimple_formal_tmp_var (gimple_assign_lhs (stmt)); | |
1390 | |
1391 for (i = 1; i < gimple_num_ops (stmt); i++) | |
1392 { | |
1393 ret = walk_tree (gimple_op_ptr (stmt, i), callback_op, wi, | |
1394 pset); | |
1395 if (ret) | |
1396 return ret; | |
1397 } | |
1398 | |
1399 /* Walk the LHS. If the RHS is appropriate for a memory, we | |
1400 may use a COMPONENT_REF on the LHS. */ | |
1401 if (wi) | |
1402 { | |
1403 /* If the RHS has more than 1 operand, it is not appropriate | |
1404 for the memory. */ | |
1405 wi->val_only = !is_gimple_mem_rhs (gimple_assign_rhs1 (stmt)) | |
1406 || !gimple_assign_single_p (stmt); | |
1407 wi->is_lhs = true; | |
1408 } | |
1409 | |
1410 ret = walk_tree (gimple_op_ptr (stmt, 0), callback_op, wi, pset); | |
1411 if (ret) | |
1412 return ret; | |
1413 | |
1414 if (wi) | |
1415 { | |
1416 wi->val_only = true; | |
1417 wi->is_lhs = false; | |
1418 } | |
1419 break; | |
1420 | |
1421 case GIMPLE_CALL: | |
1422 if (wi) | |
1423 wi->is_lhs = false; | |
1424 | |
1425 ret = walk_tree (gimple_call_chain_ptr (stmt), callback_op, wi, pset); | |
1426 if (ret) | |
1427 return ret; | |
1428 | |
1429 ret = walk_tree (gimple_call_fn_ptr (stmt), callback_op, wi, pset); | |
1430 if (ret) | |
1431 return ret; | |
1432 | |
1433 for (i = 0; i < gimple_call_num_args (stmt); i++) | |
1434 { | |
1435 ret = walk_tree (gimple_call_arg_ptr (stmt, i), callback_op, wi, | |
1436 pset); | |
1437 if (ret) | |
1438 return ret; | |
1439 } | |
1440 | |
1441 if (wi) | |
1442 wi->is_lhs = true; | |
1443 | |
1444 ret = walk_tree (gimple_call_lhs_ptr (stmt), callback_op, wi, pset); | |
1445 if (ret) | |
1446 return ret; | |
1447 | |
1448 if (wi) | |
1449 wi->is_lhs = false; | |
1450 break; | |
1451 | |
1452 case GIMPLE_CATCH: | |
1453 ret = walk_tree (gimple_catch_types_ptr (stmt), callback_op, wi, | |
1454 pset); | |
1455 if (ret) | |
1456 return ret; | |
1457 break; | |
1458 | |
1459 case GIMPLE_EH_FILTER: | |
1460 ret = walk_tree (gimple_eh_filter_types_ptr (stmt), callback_op, wi, | |
1461 pset); | |
1462 if (ret) | |
1463 return ret; | |
1464 break; | |
1465 | |
1466 case GIMPLE_CHANGE_DYNAMIC_TYPE: | |
1467 ret = walk_tree (gimple_cdt_location_ptr (stmt), callback_op, wi, pset); | |
1468 if (ret) | |
1469 return ret; | |
1470 | |
1471 ret = walk_tree (gimple_cdt_new_type_ptr (stmt), callback_op, wi, pset); | |
1472 if (ret) | |
1473 return ret; | |
1474 break; | |
1475 | |
1476 case GIMPLE_ASM: | |
1477 ret = walk_gimple_asm (stmt, callback_op, wi); | |
1478 if (ret) | |
1479 return ret; | |
1480 break; | |
1481 | |
1482 case GIMPLE_OMP_CONTINUE: | |
1483 ret = walk_tree (gimple_omp_continue_control_def_ptr (stmt), | |
1484 callback_op, wi, pset); | |
1485 if (ret) | |
1486 return ret; | |
1487 | |
1488 ret = walk_tree (gimple_omp_continue_control_use_ptr (stmt), | |
1489 callback_op, wi, pset); | |
1490 if (ret) | |
1491 return ret; | |
1492 break; | |
1493 | |
1494 case GIMPLE_OMP_CRITICAL: | |
1495 ret = walk_tree (gimple_omp_critical_name_ptr (stmt), callback_op, wi, | |
1496 pset); | |
1497 if (ret) | |
1498 return ret; | |
1499 break; | |
1500 | |
1501 case GIMPLE_OMP_FOR: | |
1502 ret = walk_tree (gimple_omp_for_clauses_ptr (stmt), callback_op, wi, | |
1503 pset); | |
1504 if (ret) | |
1505 return ret; | |
1506 for (i = 0; i < gimple_omp_for_collapse (stmt); i++) | |
1507 { | |
1508 ret = walk_tree (gimple_omp_for_index_ptr (stmt, i), callback_op, | |
1509 wi, pset); | |
1510 if (ret) | |
1511 return ret; | |
1512 ret = walk_tree (gimple_omp_for_initial_ptr (stmt, i), callback_op, | |
1513 wi, pset); | |
1514 if (ret) | |
1515 return ret; | |
1516 ret = walk_tree (gimple_omp_for_final_ptr (stmt, i), callback_op, | |
1517 wi, pset); | |
1518 if (ret) | |
1519 return ret; | |
1520 ret = walk_tree (gimple_omp_for_incr_ptr (stmt, i), callback_op, | |
1521 wi, pset); | |
1522 } | |
1523 if (ret) | |
1524 return ret; | |
1525 break; | |
1526 | |
1527 case GIMPLE_OMP_PARALLEL: | |
1528 ret = walk_tree (gimple_omp_parallel_clauses_ptr (stmt), callback_op, | |
1529 wi, pset); | |
1530 if (ret) | |
1531 return ret; | |
1532 ret = walk_tree (gimple_omp_parallel_child_fn_ptr (stmt), callback_op, | |
1533 wi, pset); | |
1534 if (ret) | |
1535 return ret; | |
1536 ret = walk_tree (gimple_omp_parallel_data_arg_ptr (stmt), callback_op, | |
1537 wi, pset); | |
1538 if (ret) | |
1539 return ret; | |
1540 break; | |
1541 | |
1542 case GIMPLE_OMP_TASK: | |
1543 ret = walk_tree (gimple_omp_task_clauses_ptr (stmt), callback_op, | |
1544 wi, pset); | |
1545 if (ret) | |
1546 return ret; | |
1547 ret = walk_tree (gimple_omp_task_child_fn_ptr (stmt), callback_op, | |
1548 wi, pset); | |
1549 if (ret) | |
1550 return ret; | |
1551 ret = walk_tree (gimple_omp_task_data_arg_ptr (stmt), callback_op, | |
1552 wi, pset); | |
1553 if (ret) | |
1554 return ret; | |
1555 ret = walk_tree (gimple_omp_task_copy_fn_ptr (stmt), callback_op, | |
1556 wi, pset); | |
1557 if (ret) | |
1558 return ret; | |
1559 ret = walk_tree (gimple_omp_task_arg_size_ptr (stmt), callback_op, | |
1560 wi, pset); | |
1561 if (ret) | |
1562 return ret; | |
1563 ret = walk_tree (gimple_omp_task_arg_align_ptr (stmt), callback_op, | |
1564 wi, pset); | |
1565 if (ret) | |
1566 return ret; | |
1567 break; | |
1568 | |
1569 case GIMPLE_OMP_SECTIONS: | |
1570 ret = walk_tree (gimple_omp_sections_clauses_ptr (stmt), callback_op, | |
1571 wi, pset); | |
1572 if (ret) | |
1573 return ret; | |
1574 | |
1575 ret = walk_tree (gimple_omp_sections_control_ptr (stmt), callback_op, | |
1576 wi, pset); | |
1577 if (ret) | |
1578 return ret; | |
1579 | |
1580 break; | |
1581 | |
1582 case GIMPLE_OMP_SINGLE: | |
1583 ret = walk_tree (gimple_omp_single_clauses_ptr (stmt), callback_op, wi, | |
1584 pset); | |
1585 if (ret) | |
1586 return ret; | |
1587 break; | |
1588 | |
1589 case GIMPLE_OMP_ATOMIC_LOAD: | |
1590 ret = walk_tree (gimple_omp_atomic_load_lhs_ptr (stmt), callback_op, wi, | |
1591 pset); | |
1592 if (ret) | |
1593 return ret; | |
1594 | |
1595 ret = walk_tree (gimple_omp_atomic_load_rhs_ptr (stmt), callback_op, wi, | |
1596 pset); | |
1597 if (ret) | |
1598 return ret; | |
1599 break; | |
1600 | |
1601 case GIMPLE_OMP_ATOMIC_STORE: | |
1602 ret = walk_tree (gimple_omp_atomic_store_val_ptr (stmt), callback_op, | |
1603 wi, pset); | |
1604 if (ret) | |
1605 return ret; | |
1606 break; | |
1607 | |
1608 /* Tuples that do not have operands. */ | |
1609 case GIMPLE_NOP: | |
1610 case GIMPLE_RESX: | |
1611 case GIMPLE_OMP_RETURN: | |
1612 case GIMPLE_PREDICT: | |
1613 break; | |
1614 | |
1615 default: | |
1616 { | |
1617 enum gimple_statement_structure_enum gss; | |
1618 gss = gimple_statement_structure (stmt); | |
1619 if (gss == GSS_WITH_OPS || gss == GSS_WITH_MEM_OPS) | |
1620 for (i = 0; i < gimple_num_ops (stmt); i++) | |
1621 { | |
1622 ret = walk_tree (gimple_op_ptr (stmt, i), callback_op, wi, pset); | |
1623 if (ret) | |
1624 return ret; | |
1625 } | |
1626 } | |
1627 break; | |
1628 } | |
1629 | |
1630 return NULL_TREE; | |
1631 } | |
1632 | |
1633 | |
1634 /* Walk the current statement in GSI (optionally using traversal state | |
1635 stored in WI). If WI is NULL, no state is kept during traversal. | |
1636 The callback CALLBACK_STMT is called. If CALLBACK_STMT indicates | |
1637 that it has handled all the operands of the statement, its return | |
1638 value is returned. Otherwise, the return value from CALLBACK_STMT | |
1639 is discarded and its operands are scanned. | |
1640 | |
1641 If CALLBACK_STMT is NULL or it didn't handle the operands, | |
1642 CALLBACK_OP is called on each operand of the statement via | |
1643 walk_gimple_op. If walk_gimple_op returns non-NULL for any | |
1644 operand, the remaining operands are not scanned. In this case, the | |
1645 return value from CALLBACK_OP is returned. | |
1646 | |
1647 In any other case, NULL_TREE is returned. */ | |
1648 | |
1649 tree | |
1650 walk_gimple_stmt (gimple_stmt_iterator *gsi, walk_stmt_fn callback_stmt, | |
1651 walk_tree_fn callback_op, struct walk_stmt_info *wi) | |
1652 { | |
1653 gimple ret; | |
1654 tree tree_ret; | |
1655 gimple stmt = gsi_stmt (*gsi); | |
1656 | |
1657 if (wi) | |
1658 wi->gsi = *gsi; | |
1659 | |
1660 if (wi && wi->want_locations && gimple_has_location (stmt)) | |
1661 input_location = gimple_location (stmt); | |
1662 | |
1663 ret = NULL; | |
1664 | |
1665 /* Invoke the statement callback. Return if the callback handled | |
1666 all of STMT operands by itself. */ | |
1667 if (callback_stmt) | |
1668 { | |
1669 bool handled_ops = false; | |
1670 tree_ret = callback_stmt (gsi, &handled_ops, wi); | |
1671 if (handled_ops) | |
1672 return tree_ret; | |
1673 | |
1674 /* If CALLBACK_STMT did not handle operands, it should not have | |
1675 a value to return. */ | |
1676 gcc_assert (tree_ret == NULL); | |
1677 | |
1678 /* Re-read stmt in case the callback changed it. */ | |
1679 stmt = gsi_stmt (*gsi); | |
1680 } | |
1681 | |
1682 /* If CALLBACK_OP is defined, invoke it on every operand of STMT. */ | |
1683 if (callback_op) | |
1684 { | |
1685 tree_ret = walk_gimple_op (stmt, callback_op, wi); | |
1686 if (tree_ret) | |
1687 return tree_ret; | |
1688 } | |
1689 | |
1690 /* If STMT can have statements inside (e.g. GIMPLE_BIND), walk them. */ | |
1691 switch (gimple_code (stmt)) | |
1692 { | |
1693 case GIMPLE_BIND: | |
1694 ret = walk_gimple_seq (gimple_bind_body (stmt), callback_stmt, | |
1695 callback_op, wi); | |
1696 if (ret) | |
1697 return wi->callback_result; | |
1698 break; | |
1699 | |
1700 case GIMPLE_CATCH: | |
1701 ret = walk_gimple_seq (gimple_catch_handler (stmt), callback_stmt, | |
1702 callback_op, wi); | |
1703 if (ret) | |
1704 return wi->callback_result; | |
1705 break; | |
1706 | |
1707 case GIMPLE_EH_FILTER: | |
1708 ret = walk_gimple_seq (gimple_eh_filter_failure (stmt), callback_stmt, | |
1709 callback_op, wi); | |
1710 if (ret) | |
1711 return wi->callback_result; | |
1712 break; | |
1713 | |
1714 case GIMPLE_TRY: | |
1715 ret = walk_gimple_seq (gimple_try_eval (stmt), callback_stmt, callback_op, | |
1716 wi); | |
1717 if (ret) | |
1718 return wi->callback_result; | |
1719 | |
1720 ret = walk_gimple_seq (gimple_try_cleanup (stmt), callback_stmt, | |
1721 callback_op, wi); | |
1722 if (ret) | |
1723 return wi->callback_result; | |
1724 break; | |
1725 | |
1726 case GIMPLE_OMP_FOR: | |
1727 ret = walk_gimple_seq (gimple_omp_for_pre_body (stmt), callback_stmt, | |
1728 callback_op, wi); | |
1729 if (ret) | |
1730 return wi->callback_result; | |
1731 | |
1732 /* FALL THROUGH. */ | |
1733 case GIMPLE_OMP_CRITICAL: | |
1734 case GIMPLE_OMP_MASTER: | |
1735 case GIMPLE_OMP_ORDERED: | |
1736 case GIMPLE_OMP_SECTION: | |
1737 case GIMPLE_OMP_PARALLEL: | |
1738 case GIMPLE_OMP_TASK: | |
1739 case GIMPLE_OMP_SECTIONS: | |
1740 case GIMPLE_OMP_SINGLE: | |
1741 ret = walk_gimple_seq (gimple_omp_body (stmt), callback_stmt, callback_op, | |
1742 wi); | |
1743 if (ret) | |
1744 return wi->callback_result; | |
1745 break; | |
1746 | |
1747 case GIMPLE_WITH_CLEANUP_EXPR: | |
1748 ret = walk_gimple_seq (gimple_wce_cleanup (stmt), callback_stmt, | |
1749 callback_op, wi); | |
1750 if (ret) | |
1751 return wi->callback_result; | |
1752 break; | |
1753 | |
1754 default: | |
1755 gcc_assert (!gimple_has_substatements (stmt)); | |
1756 break; | |
1757 } | |
1758 | |
1759 return NULL; | |
1760 } | |
1761 | |
1762 | |
1763 /* Set sequence SEQ to be the GIMPLE body for function FN. */ | |
1764 | |
1765 void | |
1766 gimple_set_body (tree fndecl, gimple_seq seq) | |
1767 { | |
1768 struct function *fn = DECL_STRUCT_FUNCTION (fndecl); | |
1769 if (fn == NULL) | |
1770 { | |
1771 /* If FNDECL still does not have a function structure associated | |
1772 with it, then it does not make sense for it to receive a | |
1773 GIMPLE body. */ | |
1774 gcc_assert (seq == NULL); | |
1775 } | |
1776 else | |
1777 fn->gimple_body = seq; | |
1778 } | |
1779 | |
1780 | |
1781 /* Return the body of GIMPLE statements for function FN. */ | |
1782 | |
1783 gimple_seq | |
1784 gimple_body (tree fndecl) | |
1785 { | |
1786 struct function *fn = DECL_STRUCT_FUNCTION (fndecl); | |
1787 return fn ? fn->gimple_body : NULL; | |
1788 } | |
1789 | |
1790 /* Return true when FNDECL has Gimple body either in unlowered | |
1791 or CFG form. */ | |
1792 bool | |
1793 gimple_has_body_p (tree fndecl) | |
1794 { | |
1795 struct function *fn = DECL_STRUCT_FUNCTION (fndecl); | |
1796 return (gimple_body (fndecl) || (fn && fn->cfg)); | |
1797 } | |
1798 | |
1799 /* Detect flags from a GIMPLE_CALL. This is just like | |
1800 call_expr_flags, but for gimple tuples. */ | |
1801 | |
1802 int | |
1803 gimple_call_flags (const_gimple stmt) | |
1804 { | |
1805 int flags; | |
1806 tree decl = gimple_call_fndecl (stmt); | |
1807 tree t; | |
1808 | |
1809 if (decl) | |
1810 flags = flags_from_decl_or_type (decl); | |
1811 else | |
1812 { | |
1813 t = TREE_TYPE (gimple_call_fn (stmt)); | |
1814 if (t && TREE_CODE (t) == POINTER_TYPE) | |
1815 flags = flags_from_decl_or_type (TREE_TYPE (t)); | |
1816 else | |
1817 flags = 0; | |
1818 } | |
1819 | |
1820 return flags; | |
1821 } | |
1822 | |
1823 | |
1824 /* Return true if GS is a copy assignment. */ | |
1825 | |
1826 bool | |
1827 gimple_assign_copy_p (gimple gs) | |
1828 { | |
1829 return gimple_code (gs) == GIMPLE_ASSIGN | |
1830 && get_gimple_rhs_class (gimple_assign_rhs_code (gs)) | |
1831 == GIMPLE_SINGLE_RHS | |
1832 && is_gimple_val (gimple_op (gs, 1)); | |
1833 } | |
1834 | |
1835 | |
1836 /* Return true if GS is a SSA_NAME copy assignment. */ | |
1837 | |
1838 bool | |
1839 gimple_assign_ssa_name_copy_p (gimple gs) | |
1840 { | |
1841 return (gimple_code (gs) == GIMPLE_ASSIGN | |
1842 && (get_gimple_rhs_class (gimple_assign_rhs_code (gs)) | |
1843 == GIMPLE_SINGLE_RHS) | |
1844 && TREE_CODE (gimple_assign_lhs (gs)) == SSA_NAME | |
1845 && TREE_CODE (gimple_assign_rhs1 (gs)) == SSA_NAME); | |
1846 } | |
1847 | |
1848 | |
1849 /* Return true if GS is an assignment with a singleton RHS, i.e., | |
1850 there is no operator associated with the assignment itself. | |
1851 Unlike gimple_assign_copy_p, this predicate returns true for | |
1852 any RHS operand, including those that perform an operation | |
1853 and do not have the semantics of a copy, such as COND_EXPR. */ | |
1854 | |
1855 bool | |
1856 gimple_assign_single_p (gimple gs) | |
1857 { | |
1858 return (gimple_code (gs) == GIMPLE_ASSIGN | |
1859 && get_gimple_rhs_class (gimple_assign_rhs_code (gs)) | |
1860 == GIMPLE_SINGLE_RHS); | |
1861 } | |
1862 | |
1863 /* Return true if GS is an assignment with a unary RHS, but the | |
1864 operator has no effect on the assigned value. The logic is adapted | |
1865 from STRIP_NOPS. This predicate is intended to be used in tuplifying | |
1866 instances in which STRIP_NOPS was previously applied to the RHS of | |
1867 an assignment. | |
1868 | |
1869 NOTE: In the use cases that led to the creation of this function | |
1870 and of gimple_assign_single_p, it is typical to test for either | |
1871 condition and to proceed in the same manner. In each case, the | |
1872 assigned value is represented by the single RHS operand of the | |
1873 assignment. I suspect there may be cases where gimple_assign_copy_p, | |
1874 gimple_assign_single_p, or equivalent logic is used where a similar | |
1875 treatment of unary NOPs is appropriate. */ | |
1876 | |
1877 bool | |
1878 gimple_assign_unary_nop_p (gimple gs) | |
1879 { | |
1880 return (gimple_code (gs) == GIMPLE_ASSIGN | |
1881 && (CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (gs)) | |
1882 || gimple_assign_rhs_code (gs) == NON_LVALUE_EXPR) | |
1883 && gimple_assign_rhs1 (gs) != error_mark_node | |
1884 && (TYPE_MODE (TREE_TYPE (gimple_assign_lhs (gs))) | |
1885 == TYPE_MODE (TREE_TYPE (gimple_assign_rhs1 (gs))))); | |
1886 } | |
1887 | |
1888 /* Set BB to be the basic block holding G. */ | |
1889 | |
1890 void | |
1891 gimple_set_bb (gimple stmt, basic_block bb) | |
1892 { | |
1893 stmt->gsbase.bb = bb; | |
1894 | |
1895 /* If the statement is a label, add the label to block-to-labels map | |
1896 so that we can speed up edge creation for GIMPLE_GOTOs. */ | |
1897 if (cfun->cfg && gimple_code (stmt) == GIMPLE_LABEL) | |
1898 { | |
1899 tree t; | |
1900 int uid; | |
1901 | |
1902 t = gimple_label_label (stmt); | |
1903 uid = LABEL_DECL_UID (t); | |
1904 if (uid == -1) | |
1905 { | |
1906 unsigned old_len = VEC_length (basic_block, label_to_block_map); | |
1907 LABEL_DECL_UID (t) = uid = cfun->cfg->last_label_uid++; | |
1908 if (old_len <= (unsigned) uid) | |
1909 { | |
1910 unsigned new_len = 3 * uid / 2; | |
1911 | |
1912 VEC_safe_grow_cleared (basic_block, gc, label_to_block_map, | |
1913 new_len); | |
1914 } | |
1915 } | |
1916 | |
1917 VEC_replace (basic_block, label_to_block_map, uid, bb); | |
1918 } | |
1919 } | |
1920 | |
1921 | |
1922 /* Fold the expression computed by STMT. If the expression can be | |
1923 folded, return the folded result, otherwise return NULL. STMT is | |
1924 not modified. */ | |
1925 | |
1926 tree | |
1927 gimple_fold (const_gimple stmt) | |
1928 { | |
1929 switch (gimple_code (stmt)) | |
1930 { | |
1931 case GIMPLE_COND: | |
1932 return fold_binary (gimple_cond_code (stmt), | |
1933 boolean_type_node, | |
1934 gimple_cond_lhs (stmt), | |
1935 gimple_cond_rhs (stmt)); | |
1936 | |
1937 case GIMPLE_ASSIGN: | |
1938 switch (get_gimple_rhs_class (gimple_assign_rhs_code (stmt))) | |
1939 { | |
1940 case GIMPLE_UNARY_RHS: | |
1941 return fold_unary (gimple_assign_rhs_code (stmt), | |
1942 TREE_TYPE (gimple_assign_lhs (stmt)), | |
1943 gimple_assign_rhs1 (stmt)); | |
1944 case GIMPLE_BINARY_RHS: | |
1945 return fold_binary (gimple_assign_rhs_code (stmt), | |
1946 TREE_TYPE (gimple_assign_lhs (stmt)), | |
1947 gimple_assign_rhs1 (stmt), | |
1948 gimple_assign_rhs2 (stmt)); | |
1949 case GIMPLE_SINGLE_RHS: | |
1950 return fold (gimple_assign_rhs1 (stmt)); | |
1951 default:; | |
1952 } | |
1953 break; | |
1954 | |
1955 case GIMPLE_SWITCH: | |
1956 return gimple_switch_index (stmt); | |
1957 | |
1958 case GIMPLE_CALL: | |
1959 return NULL_TREE; | |
1960 | |
1961 default: | |
1962 break; | |
1963 } | |
1964 | |
1965 gcc_unreachable (); | |
1966 } | |
1967 | |
1968 | |
1969 /* Modify the RHS of the assignment pointed-to by GSI using the | |
1970 operands in the expression tree EXPR. | |
1971 | |
1972 NOTE: The statement pointed-to by GSI may be reallocated if it | |
1973 did not have enough operand slots. | |
1974 | |
1975 This function is useful to convert an existing tree expression into | |
1976 the flat representation used for the RHS of a GIMPLE assignment. | |
1977 It will reallocate memory as needed to expand or shrink the number | |
1978 of operand slots needed to represent EXPR. | |
1979 | |
1980 NOTE: If you find yourself building a tree and then calling this | |
1981 function, you are most certainly doing it the slow way. It is much | |
1982 better to build a new assignment or to use the function | |
1983 gimple_assign_set_rhs_with_ops, which does not require an | |
1984 expression tree to be built. */ | |
1985 | |
1986 void | |
1987 gimple_assign_set_rhs_from_tree (gimple_stmt_iterator *gsi, tree expr) | |
1988 { | |
1989 enum tree_code subcode; | |
1990 tree op1, op2; | |
1991 | |
1992 extract_ops_from_tree (expr, &subcode, &op1, &op2); | |
1993 gimple_assign_set_rhs_with_ops (gsi, subcode, op1, op2); | |
1994 } | |
1995 | |
1996 | |
1997 /* Set the RHS of assignment statement pointed-to by GSI to CODE with | |
1998 operands OP1 and OP2. | |
1999 | |
2000 NOTE: The statement pointed-to by GSI may be reallocated if it | |
2001 did not have enough operand slots. */ | |
2002 | |
2003 void | |
2004 gimple_assign_set_rhs_with_ops (gimple_stmt_iterator *gsi, enum tree_code code, | |
2005 tree op1, tree op2) | |
2006 { | |
2007 unsigned new_rhs_ops = get_gimple_rhs_num_ops (code); | |
2008 gimple stmt = gsi_stmt (*gsi); | |
2009 | |
2010 /* If the new CODE needs more operands, allocate a new statement. */ | |
2011 if (gimple_num_ops (stmt) < new_rhs_ops + 1) | |
2012 { | |
2013 tree lhs = gimple_assign_lhs (stmt); | |
2014 gimple new_stmt = gimple_alloc (gimple_code (stmt), new_rhs_ops + 1); | |
2015 memcpy (new_stmt, stmt, gimple_size (gimple_code (stmt))); | |
2016 gsi_replace (gsi, new_stmt, true); | |
2017 stmt = new_stmt; | |
2018 | |
2019 /* The LHS needs to be reset as this also changes the SSA name | |
2020 on the LHS. */ | |
2021 gimple_assign_set_lhs (stmt, lhs); | |
2022 } | |
2023 | |
2024 gimple_set_num_ops (stmt, new_rhs_ops + 1); | |
2025 gimple_set_subcode (stmt, code); | |
2026 gimple_assign_set_rhs1 (stmt, op1); | |
2027 if (new_rhs_ops > 1) | |
2028 gimple_assign_set_rhs2 (stmt, op2); | |
2029 } | |
2030 | |
2031 | |
2032 /* Return the LHS of a statement that performs an assignment, | |
2033 either a GIMPLE_ASSIGN or a GIMPLE_CALL. Returns NULL_TREE | |
2034 for a call to a function that returns no value, or for a | |
2035 statement other than an assignment or a call. */ | |
2036 | |
2037 tree | |
2038 gimple_get_lhs (const_gimple stmt) | |
2039 { | |
2040 enum gimple_code code = gimple_code (stmt); | |
2041 | |
2042 if (code == GIMPLE_ASSIGN) | |
2043 return gimple_assign_lhs (stmt); | |
2044 else if (code == GIMPLE_CALL) | |
2045 return gimple_call_lhs (stmt); | |
2046 else | |
2047 return NULL_TREE; | |
2048 } | |
2049 | |
2050 | |
2051 /* Set the LHS of a statement that performs an assignment, | |
2052 either a GIMPLE_ASSIGN or a GIMPLE_CALL. */ | |
2053 | |
2054 void | |
2055 gimple_set_lhs (gimple stmt, tree lhs) | |
2056 { | |
2057 enum gimple_code code = gimple_code (stmt); | |
2058 | |
2059 if (code == GIMPLE_ASSIGN) | |
2060 gimple_assign_set_lhs (stmt, lhs); | |
2061 else if (code == GIMPLE_CALL) | |
2062 gimple_call_set_lhs (stmt, lhs); | |
2063 else | |
2064 gcc_unreachable(); | |
2065 } | |
2066 | |
2067 | |
2068 /* Return a deep copy of statement STMT. All the operands from STMT | |
2069 are reallocated and copied using unshare_expr. The DEF, USE, VDEF | |
2070 and VUSE operand arrays are set to empty in the new copy. */ | |
2071 | |
2072 gimple | |
2073 gimple_copy (gimple stmt) | |
2074 { | |
2075 enum gimple_code code = gimple_code (stmt); | |
2076 unsigned num_ops = gimple_num_ops (stmt); | |
2077 gimple copy = gimple_alloc (code, num_ops); | |
2078 unsigned i; | |
2079 | |
2080 /* Shallow copy all the fields from STMT. */ | |
2081 memcpy (copy, stmt, gimple_size (code)); | |
2082 | |
2083 /* If STMT has sub-statements, deep-copy them as well. */ | |
2084 if (gimple_has_substatements (stmt)) | |
2085 { | |
2086 gimple_seq new_seq; | |
2087 tree t; | |
2088 | |
2089 switch (gimple_code (stmt)) | |
2090 { | |
2091 case GIMPLE_BIND: | |
2092 new_seq = gimple_seq_copy (gimple_bind_body (stmt)); | |
2093 gimple_bind_set_body (copy, new_seq); | |
2094 gimple_bind_set_vars (copy, unshare_expr (gimple_bind_vars (stmt))); | |
2095 gimple_bind_set_block (copy, gimple_bind_block (stmt)); | |
2096 break; | |
2097 | |
2098 case GIMPLE_CATCH: | |
2099 new_seq = gimple_seq_copy (gimple_catch_handler (stmt)); | |
2100 gimple_catch_set_handler (copy, new_seq); | |
2101 t = unshare_expr (gimple_catch_types (stmt)); | |
2102 gimple_catch_set_types (copy, t); | |
2103 break; | |
2104 | |
2105 case GIMPLE_EH_FILTER: | |
2106 new_seq = gimple_seq_copy (gimple_eh_filter_failure (stmt)); | |
2107 gimple_eh_filter_set_failure (copy, new_seq); | |
2108 t = unshare_expr (gimple_eh_filter_types (stmt)); | |
2109 gimple_eh_filter_set_types (copy, t); | |
2110 break; | |
2111 | |
2112 case GIMPLE_TRY: | |
2113 new_seq = gimple_seq_copy (gimple_try_eval (stmt)); | |
2114 gimple_try_set_eval (copy, new_seq); | |
2115 new_seq = gimple_seq_copy (gimple_try_cleanup (stmt)); | |
2116 gimple_try_set_cleanup (copy, new_seq); | |
2117 break; | |
2118 | |
2119 case GIMPLE_OMP_FOR: | |
2120 new_seq = gimple_seq_copy (gimple_omp_for_pre_body (stmt)); | |
2121 gimple_omp_for_set_pre_body (copy, new_seq); | |
2122 t = unshare_expr (gimple_omp_for_clauses (stmt)); | |
2123 gimple_omp_for_set_clauses (copy, t); | |
2124 copy->gimple_omp_for.iter | |
2125 = GGC_NEWVEC (struct gimple_omp_for_iter, | |
2126 gimple_omp_for_collapse (stmt)); | |
2127 for (i = 0; i < gimple_omp_for_collapse (stmt); i++) | |
2128 { | |
2129 gimple_omp_for_set_cond (copy, i, | |
2130 gimple_omp_for_cond (stmt, i)); | |
2131 gimple_omp_for_set_index (copy, i, | |
2132 gimple_omp_for_index (stmt, i)); | |
2133 t = unshare_expr (gimple_omp_for_initial (stmt, i)); | |
2134 gimple_omp_for_set_initial (copy, i, t); | |
2135 t = unshare_expr (gimple_omp_for_final (stmt, i)); | |
2136 gimple_omp_for_set_final (copy, i, t); | |
2137 t = unshare_expr (gimple_omp_for_incr (stmt, i)); | |
2138 gimple_omp_for_set_incr (copy, i, t); | |
2139 } | |
2140 goto copy_omp_body; | |
2141 | |
2142 case GIMPLE_OMP_PARALLEL: | |
2143 t = unshare_expr (gimple_omp_parallel_clauses (stmt)); | |
2144 gimple_omp_parallel_set_clauses (copy, t); | |
2145 t = unshare_expr (gimple_omp_parallel_child_fn (stmt)); | |
2146 gimple_omp_parallel_set_child_fn (copy, t); | |
2147 t = unshare_expr (gimple_omp_parallel_data_arg (stmt)); | |
2148 gimple_omp_parallel_set_data_arg (copy, t); | |
2149 goto copy_omp_body; | |
2150 | |
2151 case GIMPLE_OMP_TASK: | |
2152 t = unshare_expr (gimple_omp_task_clauses (stmt)); | |
2153 gimple_omp_task_set_clauses (copy, t); | |
2154 t = unshare_expr (gimple_omp_task_child_fn (stmt)); | |
2155 gimple_omp_task_set_child_fn (copy, t); | |
2156 t = unshare_expr (gimple_omp_task_data_arg (stmt)); | |
2157 gimple_omp_task_set_data_arg (copy, t); | |
2158 t = unshare_expr (gimple_omp_task_copy_fn (stmt)); | |
2159 gimple_omp_task_set_copy_fn (copy, t); | |
2160 t = unshare_expr (gimple_omp_task_arg_size (stmt)); | |
2161 gimple_omp_task_set_arg_size (copy, t); | |
2162 t = unshare_expr (gimple_omp_task_arg_align (stmt)); | |
2163 gimple_omp_task_set_arg_align (copy, t); | |
2164 goto copy_omp_body; | |
2165 | |
2166 case GIMPLE_OMP_CRITICAL: | |
2167 t = unshare_expr (gimple_omp_critical_name (stmt)); | |
2168 gimple_omp_critical_set_name (copy, t); | |
2169 goto copy_omp_body; | |
2170 | |
2171 case GIMPLE_OMP_SECTIONS: | |
2172 t = unshare_expr (gimple_omp_sections_clauses (stmt)); | |
2173 gimple_omp_sections_set_clauses (copy, t); | |
2174 t = unshare_expr (gimple_omp_sections_control (stmt)); | |
2175 gimple_omp_sections_set_control (copy, t); | |
2176 /* FALLTHRU */ | |
2177 | |
2178 case GIMPLE_OMP_SINGLE: | |
2179 case GIMPLE_OMP_SECTION: | |
2180 case GIMPLE_OMP_MASTER: | |
2181 case GIMPLE_OMP_ORDERED: | |
2182 copy_omp_body: | |
2183 new_seq = gimple_seq_copy (gimple_omp_body (stmt)); | |
2184 gimple_omp_set_body (copy, new_seq); | |
2185 break; | |
2186 | |
2187 case GIMPLE_WITH_CLEANUP_EXPR: | |
2188 new_seq = gimple_seq_copy (gimple_wce_cleanup (stmt)); | |
2189 gimple_wce_set_cleanup (copy, new_seq); | |
2190 break; | |
2191 | |
2192 default: | |
2193 gcc_unreachable (); | |
2194 } | |
2195 } | |
2196 | |
2197 /* Make copy of operands. */ | |
2198 if (num_ops > 0) | |
2199 { | |
2200 for (i = 0; i < num_ops; i++) | |
2201 gimple_set_op (copy, i, unshare_expr (gimple_op (stmt, i))); | |
2202 | |
2203 /* Clear out SSA operand vectors on COPY. Note that we cannot | |
2204 call the API functions for setting addresses_taken, stores | |
2205 and loads. These functions free the previous values, and we | |
2206 cannot do that on COPY as it will affect the original | |
2207 statement. */ | |
2208 if (gimple_has_ops (stmt)) | |
2209 { | |
2210 gimple_set_def_ops (copy, NULL); | |
2211 gimple_set_use_ops (copy, NULL); | |
2212 copy->gsops.opbase.addresses_taken = NULL; | |
2213 } | |
2214 | |
2215 if (gimple_has_mem_ops (stmt)) | |
2216 { | |
2217 gimple_set_vdef_ops (copy, NULL); | |
2218 gimple_set_vuse_ops (copy, NULL); | |
2219 copy->gsmem.membase.stores = NULL; | |
2220 copy->gsmem.membase.loads = NULL; | |
2221 } | |
2222 | |
2223 update_stmt (copy); | |
2224 } | |
2225 | |
2226 return copy; | |
2227 } | |
2228 | |
2229 | |
2230 /* Set the MODIFIED flag to MODIFIEDP, iff the gimple statement G has | |
2231 a MODIFIED field. */ | |
2232 | |
2233 void | |
2234 gimple_set_modified (gimple s, bool modifiedp) | |
2235 { | |
2236 if (gimple_has_ops (s)) | |
2237 { | |
2238 s->gsbase.modified = (unsigned) modifiedp; | |
2239 | |
2240 if (modifiedp | |
2241 && cfun->gimple_df | |
2242 && is_gimple_call (s) | |
2243 && gimple_call_noreturn_p (s)) | |
2244 VEC_safe_push (gimple, gc, MODIFIED_NORETURN_CALLS (cfun), s); | |
2245 } | |
2246 } | |
2247 | |
2248 | |
2249 /* Return true if statement S has side-effects. We consider a | |
2250 statement to have side effects if: | |
2251 | |
2252 - It is a GIMPLE_CALL not marked with ECF_PURE or ECF_CONST. | |
2253 - Any of its operands are marked TREE_THIS_VOLATILE or TREE_SIDE_EFFECTS. */ | |
2254 | |
2255 bool | |
2256 gimple_has_side_effects (const_gimple s) | |
2257 { | |
2258 unsigned i; | |
2259 | |
2260 /* We don't have to scan the arguments to check for | |
2261 volatile arguments, though, at present, we still | |
2262 do a scan to check for TREE_SIDE_EFFECTS. */ | |
2263 if (gimple_has_volatile_ops (s)) | |
2264 return true; | |
2265 | |
2266 if (is_gimple_call (s)) | |
2267 { | |
2268 unsigned nargs = gimple_call_num_args (s); | |
2269 | |
2270 if (!(gimple_call_flags (s) & (ECF_CONST | ECF_PURE))) | |
2271 return true; | |
2272 else if (gimple_call_flags (s) & ECF_LOOPING_CONST_OR_PURE) | |
2273 /* An infinite loop is considered a side effect. */ | |
2274 return true; | |
2275 | |
2276 if (gimple_call_lhs (s) | |
2277 && TREE_SIDE_EFFECTS (gimple_call_lhs (s))) | |
2278 { | |
2279 gcc_assert (gimple_has_volatile_ops (s)); | |
2280 return true; | |
2281 } | |
2282 | |
2283 if (TREE_SIDE_EFFECTS (gimple_call_fn (s))) | |
2284 return true; | |
2285 | |
2286 for (i = 0; i < nargs; i++) | |
2287 if (TREE_SIDE_EFFECTS (gimple_call_arg (s, i))) | |
2288 { | |
2289 gcc_assert (gimple_has_volatile_ops (s)); | |
2290 return true; | |
2291 } | |
2292 | |
2293 return false; | |
2294 } | |
2295 else | |
2296 { | |
2297 for (i = 0; i < gimple_num_ops (s); i++) | |
2298 if (TREE_SIDE_EFFECTS (gimple_op (s, i))) | |
2299 { | |
2300 gcc_assert (gimple_has_volatile_ops (s)); | |
2301 return true; | |
2302 } | |
2303 } | |
2304 | |
2305 return false; | |
2306 } | |
2307 | |
2308 /* Return true if the RHS of statement S has side effects. | |
2309 We may use it to determine if it is admissable to replace | |
2310 an assignment or call with a copy of a previously-computed | |
2311 value. In such cases, side-effects due the the LHS are | |
2312 preserved. */ | |
2313 | |
2314 bool | |
2315 gimple_rhs_has_side_effects (const_gimple s) | |
2316 { | |
2317 unsigned i; | |
2318 | |
2319 if (is_gimple_call (s)) | |
2320 { | |
2321 unsigned nargs = gimple_call_num_args (s); | |
2322 | |
2323 if (!(gimple_call_flags (s) & (ECF_CONST | ECF_PURE))) | |
2324 return true; | |
2325 | |
2326 /* We cannot use gimple_has_volatile_ops here, | |
2327 because we must ignore a volatile LHS. */ | |
2328 if (TREE_SIDE_EFFECTS (gimple_call_fn (s)) | |
2329 || TREE_THIS_VOLATILE (gimple_call_fn (s))) | |
2330 { | |
2331 gcc_assert (gimple_has_volatile_ops (s)); | |
2332 return true; | |
2333 } | |
2334 | |
2335 for (i = 0; i < nargs; i++) | |
2336 if (TREE_SIDE_EFFECTS (gimple_call_arg (s, i)) | |
2337 || TREE_THIS_VOLATILE (gimple_call_arg (s, i))) | |
2338 return true; | |
2339 | |
2340 return false; | |
2341 } | |
2342 else if (is_gimple_assign (s)) | |
2343 { | |
2344 /* Skip the first operand, the LHS. */ | |
2345 for (i = 1; i < gimple_num_ops (s); i++) | |
2346 if (TREE_SIDE_EFFECTS (gimple_op (s, i)) | |
2347 || TREE_THIS_VOLATILE (gimple_op (s, i))) | |
2348 { | |
2349 gcc_assert (gimple_has_volatile_ops (s)); | |
2350 return true; | |
2351 } | |
2352 } | |
2353 else | |
2354 { | |
2355 /* For statements without an LHS, examine all arguments. */ | |
2356 for (i = 0; i < gimple_num_ops (s); i++) | |
2357 if (TREE_SIDE_EFFECTS (gimple_op (s, i)) | |
2358 || TREE_THIS_VOLATILE (gimple_op (s, i))) | |
2359 { | |
2360 gcc_assert (gimple_has_volatile_ops (s)); | |
2361 return true; | |
2362 } | |
2363 } | |
2364 | |
2365 return false; | |
2366 } | |
2367 | |
2368 | |
2369 /* Helper for gimple_could_trap_p and gimple_assign_rhs_could_trap_p. | |
2370 Return true if S can trap. If INCLUDE_LHS is true and S is a | |
2371 GIMPLE_ASSIGN, the LHS of the assignment is also checked. | |
2372 Otherwise, only the RHS of the assignment is checked. */ | |
2373 | |
2374 static bool | |
2375 gimple_could_trap_p_1 (gimple s, bool include_lhs) | |
2376 { | |
2377 unsigned i, start; | |
2378 tree t, div = NULL_TREE; | |
2379 enum tree_code op; | |
2380 | |
2381 start = (is_gimple_assign (s) && !include_lhs) ? 1 : 0; | |
2382 | |
2383 for (i = start; i < gimple_num_ops (s); i++) | |
2384 if (tree_could_trap_p (gimple_op (s, i))) | |
2385 return true; | |
2386 | |
2387 switch (gimple_code (s)) | |
2388 { | |
2389 case GIMPLE_ASM: | |
2390 return gimple_asm_volatile_p (s); | |
2391 | |
2392 case GIMPLE_CALL: | |
2393 t = gimple_call_fndecl (s); | |
2394 /* Assume that calls to weak functions may trap. */ | |
2395 if (!t || !DECL_P (t) || DECL_WEAK (t)) | |
2396 return true; | |
2397 return false; | |
2398 | |
2399 case GIMPLE_ASSIGN: | |
2400 t = gimple_expr_type (s); | |
2401 op = gimple_assign_rhs_code (s); | |
2402 if (get_gimple_rhs_class (op) == GIMPLE_BINARY_RHS) | |
2403 div = gimple_assign_rhs2 (s); | |
2404 return (operation_could_trap_p (op, FLOAT_TYPE_P (t), | |
2405 (INTEGRAL_TYPE_P (t) | |
2406 && TYPE_OVERFLOW_TRAPS (t)), | |
2407 div)); | |
2408 | |
2409 default: | |
2410 break; | |
2411 } | |
2412 | |
2413 return false; | |
2414 | |
2415 } | |
2416 | |
2417 | |
2418 /* Return true if statement S can trap. */ | |
2419 | |
2420 bool | |
2421 gimple_could_trap_p (gimple s) | |
2422 { | |
2423 return gimple_could_trap_p_1 (s, true); | |
2424 } | |
2425 | |
2426 | |
2427 /* Return true if RHS of a GIMPLE_ASSIGN S can trap. */ | |
2428 | |
2429 bool | |
2430 gimple_assign_rhs_could_trap_p (gimple s) | |
2431 { | |
2432 gcc_assert (is_gimple_assign (s)); | |
2433 return gimple_could_trap_p_1 (s, false); | |
2434 } | |
2435 | |
2436 | |
2437 /* Print debugging information for gimple stmts generated. */ | |
2438 | |
2439 void | |
2440 dump_gimple_statistics (void) | |
2441 { | |
2442 #ifdef GATHER_STATISTICS | |
2443 int i, total_tuples = 0, total_bytes = 0; | |
2444 | |
2445 fprintf (stderr, "\nGIMPLE statements\n"); | |
2446 fprintf (stderr, "Kind Stmts Bytes\n"); | |
2447 fprintf (stderr, "---------------------------------------\n"); | |
2448 for (i = 0; i < (int) gimple_alloc_kind_all; ++i) | |
2449 { | |
2450 fprintf (stderr, "%-20s %7d %10d\n", gimple_alloc_kind_names[i], | |
2451 gimple_alloc_counts[i], gimple_alloc_sizes[i]); | |
2452 total_tuples += gimple_alloc_counts[i]; | |
2453 total_bytes += gimple_alloc_sizes[i]; | |
2454 } | |
2455 fprintf (stderr, "---------------------------------------\n"); | |
2456 fprintf (stderr, "%-20s %7d %10d\n", "Total", total_tuples, total_bytes); | |
2457 fprintf (stderr, "---------------------------------------\n"); | |
2458 #else | |
2459 fprintf (stderr, "No gimple statistics\n"); | |
2460 #endif | |
2461 } | |
2462 | |
2463 | |
2464 /* Deep copy SYMS into the set of symbols stored by STMT. If SYMS is | |
2465 NULL or empty, the storage used is freed up. */ | |
2466 | |
2467 void | |
2468 gimple_set_stored_syms (gimple stmt, bitmap syms, bitmap_obstack *obs) | |
2469 { | |
2470 gcc_assert (gimple_has_mem_ops (stmt)); | |
2471 | |
2472 if (syms == NULL || bitmap_empty_p (syms)) | |
2473 BITMAP_FREE (stmt->gsmem.membase.stores); | |
2474 else | |
2475 { | |
2476 if (stmt->gsmem.membase.stores == NULL) | |
2477 stmt->gsmem.membase.stores = BITMAP_ALLOC (obs); | |
2478 | |
2479 bitmap_copy (stmt->gsmem.membase.stores, syms); | |
2480 } | |
2481 } | |
2482 | |
2483 | |
2484 /* Deep copy SYMS into the set of symbols loaded by STMT. If SYMS is | |
2485 NULL or empty, the storage used is freed up. */ | |
2486 | |
2487 void | |
2488 gimple_set_loaded_syms (gimple stmt, bitmap syms, bitmap_obstack *obs) | |
2489 { | |
2490 gcc_assert (gimple_has_mem_ops (stmt)); | |
2491 | |
2492 if (syms == NULL || bitmap_empty_p (syms)) | |
2493 BITMAP_FREE (stmt->gsmem.membase.loads); | |
2494 else | |
2495 { | |
2496 if (stmt->gsmem.membase.loads == NULL) | |
2497 stmt->gsmem.membase.loads = BITMAP_ALLOC (obs); | |
2498 | |
2499 bitmap_copy (stmt->gsmem.membase.loads, syms); | |
2500 } | |
2501 } | |
2502 | |
2503 | |
2504 /* Return the number of operands needed on the RHS of a GIMPLE | |
2505 assignment for an expression with tree code CODE. */ | |
2506 | |
2507 unsigned | |
2508 get_gimple_rhs_num_ops (enum tree_code code) | |
2509 { | |
2510 enum gimple_rhs_class rhs_class = get_gimple_rhs_class (code); | |
2511 | |
2512 if (rhs_class == GIMPLE_UNARY_RHS || rhs_class == GIMPLE_SINGLE_RHS) | |
2513 return 1; | |
2514 else if (rhs_class == GIMPLE_BINARY_RHS) | |
2515 return 2; | |
2516 else | |
2517 gcc_unreachable (); | |
2518 } | |
2519 | |
2520 #define DEFTREECODE(SYM, STRING, TYPE, NARGS) \ | |
2521 (unsigned char) \ | |
2522 ((TYPE) == tcc_unary ? GIMPLE_UNARY_RHS \ | |
2523 : ((TYPE) == tcc_binary \ | |
2524 || (TYPE) == tcc_comparison) ? GIMPLE_BINARY_RHS \ | |
2525 : ((TYPE) == tcc_constant \ | |
2526 || (TYPE) == tcc_declaration \ | |
2527 || (TYPE) == tcc_reference) ? GIMPLE_SINGLE_RHS \ | |
2528 : ((SYM) == TRUTH_AND_EXPR \ | |
2529 || (SYM) == TRUTH_OR_EXPR \ | |
2530 || (SYM) == TRUTH_XOR_EXPR) ? GIMPLE_BINARY_RHS \ | |
2531 : (SYM) == TRUTH_NOT_EXPR ? GIMPLE_UNARY_RHS \ | |
2532 : ((SYM) == COND_EXPR \ | |
2533 || (SYM) == CONSTRUCTOR \ | |
2534 || (SYM) == OBJ_TYPE_REF \ | |
2535 || (SYM) == ASSERT_EXPR \ | |
2536 || (SYM) == ADDR_EXPR \ | |
2537 || (SYM) == WITH_SIZE_EXPR \ | |
2538 || (SYM) == EXC_PTR_EXPR \ | |
2539 || (SYM) == SSA_NAME \ | |
2540 || (SYM) == FILTER_EXPR \ | |
2541 || (SYM) == POLYNOMIAL_CHREC \ | |
2542 || (SYM) == DOT_PROD_EXPR \ | |
2543 || (SYM) == VEC_COND_EXPR \ | |
2544 || (SYM) == REALIGN_LOAD_EXPR) ? GIMPLE_SINGLE_RHS \ | |
2545 : GIMPLE_INVALID_RHS), | |
2546 #define END_OF_BASE_TREE_CODES (unsigned char) GIMPLE_INVALID_RHS, | |
2547 | |
2548 const unsigned char gimple_rhs_class_table[] = { | |
2549 #include "all-tree.def" | |
2550 }; | |
2551 | |
2552 #undef DEFTREECODE | |
2553 #undef END_OF_BASE_TREE_CODES | |
2554 | |
2555 /* For the definitive definition of GIMPLE, see doc/tree-ssa.texi. */ | |
2556 | |
2557 /* Validation of GIMPLE expressions. */ | |
2558 | |
2559 /* Return true if OP is an acceptable tree node to be used as a GIMPLE | |
2560 operand. */ | |
2561 | |
2562 bool | |
2563 is_gimple_operand (const_tree op) | |
2564 { | |
2565 return op && get_gimple_rhs_class (TREE_CODE (op)) == GIMPLE_SINGLE_RHS; | |
2566 } | |
2567 | |
2568 | |
2569 /* Return true if T is a GIMPLE RHS for an assignment to a temporary. */ | |
2570 | |
2571 bool | |
2572 is_gimple_formal_tmp_rhs (tree t) | |
2573 { | |
2574 if (is_gimple_lvalue (t) || is_gimple_val (t)) | |
2575 return true; | |
2576 | |
2577 return get_gimple_rhs_class (TREE_CODE (t)) != GIMPLE_INVALID_RHS; | |
2578 } | |
2579 | |
2580 /* Returns true iff T is a valid RHS for an assignment to a renamed | |
2581 user -- or front-end generated artificial -- variable. */ | |
2582 | |
2583 bool | |
2584 is_gimple_reg_rhs (tree t) | |
2585 { | |
2586 /* If the RHS of the MODIFY_EXPR may throw or make a nonlocal goto | |
2587 and the LHS is a user variable, then we need to introduce a formal | |
2588 temporary. This way the optimizers can determine that the user | |
2589 variable is only modified if evaluation of the RHS does not throw. | |
2590 | |
2591 Don't force a temp of a non-renamable type; the copy could be | |
2592 arbitrarily expensive. Instead we will generate a VDEF for | |
2593 the assignment. */ | |
2594 | |
2595 if (is_gimple_reg_type (TREE_TYPE (t)) && tree_could_throw_p (t)) | |
2596 return false; | |
2597 | |
2598 return is_gimple_formal_tmp_rhs (t); | |
2599 } | |
2600 | |
2601 /* Returns true iff T is a valid RHS for an assignment to an un-renamed | |
2602 LHS, or for a call argument. */ | |
2603 | |
2604 bool | |
2605 is_gimple_mem_rhs (tree t) | |
2606 { | |
2607 /* If we're dealing with a renamable type, either source or dest must be | |
2608 a renamed variable. */ | |
2609 if (is_gimple_reg_type (TREE_TYPE (t))) | |
2610 return is_gimple_val (t); | |
2611 else | |
2612 return is_gimple_formal_tmp_rhs (t); | |
2613 } | |
2614 | |
2615 /* Return true if T is a valid LHS for a GIMPLE assignment expression. */ | |
2616 | |
2617 bool | |
2618 is_gimple_lvalue (tree t) | |
2619 { | |
2620 return (is_gimple_addressable (t) | |
2621 || TREE_CODE (t) == WITH_SIZE_EXPR | |
2622 /* These are complex lvalues, but don't have addresses, so they | |
2623 go here. */ | |
2624 || TREE_CODE (t) == BIT_FIELD_REF); | |
2625 } | |
2626 | |
2627 /* Return true if T is a GIMPLE condition. */ | |
2628 | |
2629 bool | |
2630 is_gimple_condexpr (tree t) | |
2631 { | |
2632 return (is_gimple_val (t) || (COMPARISON_CLASS_P (t) | |
2633 && !tree_could_trap_p (t) | |
2634 && is_gimple_val (TREE_OPERAND (t, 0)) | |
2635 && is_gimple_val (TREE_OPERAND (t, 1)))); | |
2636 } | |
2637 | |
2638 /* Return true if T is something whose address can be taken. */ | |
2639 | |
2640 bool | |
2641 is_gimple_addressable (tree t) | |
2642 { | |
2643 return (is_gimple_id (t) || handled_component_p (t) || INDIRECT_REF_P (t)); | |
2644 } | |
2645 | |
2646 /* Return true if T is a valid gimple constant. */ | |
2647 | |
2648 bool | |
2649 is_gimple_constant (const_tree t) | |
2650 { | |
2651 switch (TREE_CODE (t)) | |
2652 { | |
2653 case INTEGER_CST: | |
2654 case REAL_CST: | |
2655 case FIXED_CST: | |
2656 case STRING_CST: | |
2657 case COMPLEX_CST: | |
2658 case VECTOR_CST: | |
2659 return true; | |
2660 | |
2661 /* Vector constant constructors are gimple invariant. */ | |
2662 case CONSTRUCTOR: | |
2663 if (TREE_TYPE (t) && TREE_CODE (TREE_TYPE (t)) == VECTOR_TYPE) | |
2664 return TREE_CONSTANT (t); | |
2665 else | |
2666 return false; | |
2667 | |
2668 default: | |
2669 return false; | |
2670 } | |
2671 } | |
2672 | |
2673 /* Return true if T is a gimple address. */ | |
2674 | |
2675 bool | |
2676 is_gimple_address (const_tree t) | |
2677 { | |
2678 tree op; | |
2679 | |
2680 if (TREE_CODE (t) != ADDR_EXPR) | |
2681 return false; | |
2682 | |
2683 op = TREE_OPERAND (t, 0); | |
2684 while (handled_component_p (op)) | |
2685 { | |
2686 if ((TREE_CODE (op) == ARRAY_REF | |
2687 || TREE_CODE (op) == ARRAY_RANGE_REF) | |
2688 && !is_gimple_val (TREE_OPERAND (op, 1))) | |
2689 return false; | |
2690 | |
2691 op = TREE_OPERAND (op, 0); | |
2692 } | |
2693 | |
2694 if (CONSTANT_CLASS_P (op) || INDIRECT_REF_P (op)) | |
2695 return true; | |
2696 | |
2697 switch (TREE_CODE (op)) | |
2698 { | |
2699 case PARM_DECL: | |
2700 case RESULT_DECL: | |
2701 case LABEL_DECL: | |
2702 case FUNCTION_DECL: | |
2703 case VAR_DECL: | |
2704 case CONST_DECL: | |
2705 return true; | |
2706 | |
2707 default: | |
2708 return false; | |
2709 } | |
2710 } | |
2711 | |
2712 /* Strip out all handled components that produce invariant | |
2713 offsets. */ | |
2714 | |
2715 static const_tree | |
2716 strip_invariant_refs (const_tree op) | |
2717 { | |
2718 while (handled_component_p (op)) | |
2719 { | |
2720 switch (TREE_CODE (op)) | |
2721 { | |
2722 case ARRAY_REF: | |
2723 case ARRAY_RANGE_REF: | |
2724 if (!is_gimple_constant (TREE_OPERAND (op, 1)) | |
2725 || TREE_OPERAND (op, 2) != NULL_TREE | |
2726 || TREE_OPERAND (op, 3) != NULL_TREE) | |
2727 return NULL; | |
2728 break; | |
2729 | |
2730 case COMPONENT_REF: | |
2731 if (TREE_OPERAND (op, 2) != NULL_TREE) | |
2732 return NULL; | |
2733 break; | |
2734 | |
2735 default:; | |
2736 } | |
2737 op = TREE_OPERAND (op, 0); | |
2738 } | |
2739 | |
2740 return op; | |
2741 } | |
2742 | |
2743 /* Return true if T is a gimple invariant address. */ | |
2744 | |
2745 bool | |
2746 is_gimple_invariant_address (const_tree t) | |
2747 { | |
2748 const_tree op; | |
2749 | |
2750 if (TREE_CODE (t) != ADDR_EXPR) | |
2751 return false; | |
2752 | |
2753 op = strip_invariant_refs (TREE_OPERAND (t, 0)); | |
2754 | |
2755 return op && (CONSTANT_CLASS_P (op) || decl_address_invariant_p (op)); | |
2756 } | |
2757 | |
2758 /* Return true if T is a gimple invariant address at IPA level | |
2759 (so addresses of variables on stack are not allowed). */ | |
2760 | |
2761 bool | |
2762 is_gimple_ip_invariant_address (const_tree t) | |
2763 { | |
2764 const_tree op; | |
2765 | |
2766 if (TREE_CODE (t) != ADDR_EXPR) | |
2767 return false; | |
2768 | |
2769 op = strip_invariant_refs (TREE_OPERAND (t, 0)); | |
2770 | |
2771 return op && (CONSTANT_CLASS_P (op) || decl_address_ip_invariant_p (op)); | |
2772 } | |
2773 | |
2774 /* Return true if T is a GIMPLE minimal invariant. It's a restricted | |
2775 form of function invariant. */ | |
2776 | |
2777 bool | |
2778 is_gimple_min_invariant (const_tree t) | |
2779 { | |
2780 if (TREE_CODE (t) == ADDR_EXPR) | |
2781 return is_gimple_invariant_address (t); | |
2782 | |
2783 return is_gimple_constant (t); | |
2784 } | |
2785 | |
2786 /* Return true if T is a GIMPLE interprocedural invariant. It's a restricted | |
2787 form of gimple minimal invariant. */ | |
2788 | |
2789 bool | |
2790 is_gimple_ip_invariant (const_tree t) | |
2791 { | |
2792 if (TREE_CODE (t) == ADDR_EXPR) | |
2793 return is_gimple_ip_invariant_address (t); | |
2794 | |
2795 return is_gimple_constant (t); | |
2796 } | |
2797 | |
2798 /* Return true if T looks like a valid GIMPLE statement. */ | |
2799 | |
2800 bool | |
2801 is_gimple_stmt (tree t) | |
2802 { | |
2803 const enum tree_code code = TREE_CODE (t); | |
2804 | |
2805 switch (code) | |
2806 { | |
2807 case NOP_EXPR: | |
2808 /* The only valid NOP_EXPR is the empty statement. */ | |
2809 return IS_EMPTY_STMT (t); | |
2810 | |
2811 case BIND_EXPR: | |
2812 case COND_EXPR: | |
2813 /* These are only valid if they're void. */ | |
2814 return TREE_TYPE (t) == NULL || VOID_TYPE_P (TREE_TYPE (t)); | |
2815 | |
2816 case SWITCH_EXPR: | |
2817 case GOTO_EXPR: | |
2818 case RETURN_EXPR: | |
2819 case LABEL_EXPR: | |
2820 case CASE_LABEL_EXPR: | |
2821 case TRY_CATCH_EXPR: | |
2822 case TRY_FINALLY_EXPR: | |
2823 case EH_FILTER_EXPR: | |
2824 case CATCH_EXPR: | |
2825 case CHANGE_DYNAMIC_TYPE_EXPR: | |
2826 case ASM_EXPR: | |
2827 case RESX_EXPR: | |
2828 case STATEMENT_LIST: | |
2829 case OMP_PARALLEL: | |
2830 case OMP_FOR: | |
2831 case OMP_SECTIONS: | |
2832 case OMP_SECTION: | |
2833 case OMP_SINGLE: | |
2834 case OMP_MASTER: | |
2835 case OMP_ORDERED: | |
2836 case OMP_CRITICAL: | |
2837 case OMP_TASK: | |
2838 /* These are always void. */ | |
2839 return true; | |
2840 | |
2841 case CALL_EXPR: | |
2842 case MODIFY_EXPR: | |
2843 case PREDICT_EXPR: | |
2844 /* These are valid regardless of their type. */ | |
2845 return true; | |
2846 | |
2847 default: | |
2848 return false; | |
2849 } | |
2850 } | |
2851 | |
2852 /* Return true if T is a variable. */ | |
2853 | |
2854 bool | |
2855 is_gimple_variable (tree t) | |
2856 { | |
2857 return (TREE_CODE (t) == VAR_DECL | |
2858 || TREE_CODE (t) == PARM_DECL | |
2859 || TREE_CODE (t) == RESULT_DECL | |
2860 || TREE_CODE (t) == SSA_NAME); | |
2861 } | |
2862 | |
2863 /* Return true if T is a GIMPLE identifier (something with an address). */ | |
2864 | |
2865 bool | |
2866 is_gimple_id (tree t) | |
2867 { | |
2868 return (is_gimple_variable (t) | |
2869 || TREE_CODE (t) == FUNCTION_DECL | |
2870 || TREE_CODE (t) == LABEL_DECL | |
2871 || TREE_CODE (t) == CONST_DECL | |
2872 /* Allow string constants, since they are addressable. */ | |
2873 || TREE_CODE (t) == STRING_CST); | |
2874 } | |
2875 | |
2876 /* Return true if TYPE is a suitable type for a scalar register variable. */ | |
2877 | |
2878 bool | |
2879 is_gimple_reg_type (tree type) | |
2880 { | |
2881 /* In addition to aggregate types, we also exclude complex types if not | |
2882 optimizing because they can be subject to partial stores in GNU C by | |
2883 means of the __real__ and __imag__ operators and we cannot promote | |
2884 them to total stores (see gimplify_modify_expr_complex_part). */ | |
2885 return !(AGGREGATE_TYPE_P (type) | |
2886 || (TREE_CODE (type) == COMPLEX_TYPE && !optimize)); | |
2887 | |
2888 } | |
2889 | |
2890 /* Return true if T is a non-aggregate register variable. */ | |
2891 | |
2892 bool | |
2893 is_gimple_reg (tree t) | |
2894 { | |
2895 if (TREE_CODE (t) == SSA_NAME) | |
2896 t = SSA_NAME_VAR (t); | |
2897 | |
2898 if (MTAG_P (t)) | |
2899 return false; | |
2900 | |
2901 if (!is_gimple_variable (t)) | |
2902 return false; | |
2903 | |
2904 if (!is_gimple_reg_type (TREE_TYPE (t))) | |
2905 return false; | |
2906 | |
2907 /* A volatile decl is not acceptable because we can't reuse it as | |
2908 needed. We need to copy it into a temp first. */ | |
2909 if (TREE_THIS_VOLATILE (t)) | |
2910 return false; | |
2911 | |
2912 /* We define "registers" as things that can be renamed as needed, | |
2913 which with our infrastructure does not apply to memory. */ | |
2914 if (needs_to_live_in_memory (t)) | |
2915 return false; | |
2916 | |
2917 /* Hard register variables are an interesting case. For those that | |
2918 are call-clobbered, we don't know where all the calls are, since | |
2919 we don't (want to) take into account which operations will turn | |
2920 into libcalls at the rtl level. For those that are call-saved, | |
2921 we don't currently model the fact that calls may in fact change | |
2922 global hard registers, nor do we examine ASM_CLOBBERS at the tree | |
2923 level, and so miss variable changes that might imply. All around, | |
2924 it seems safest to not do too much optimization with these at the | |
2925 tree level at all. We'll have to rely on the rtl optimizers to | |
2926 clean this up, as there we've got all the appropriate bits exposed. */ | |
2927 if (TREE_CODE (t) == VAR_DECL && DECL_HARD_REGISTER (t)) | |
2928 return false; | |
2929 | |
2930 /* Complex and vector values must have been put into SSA-like form. | |
2931 That is, no assignments to the individual components. */ | |
2932 if (TREE_CODE (TREE_TYPE (t)) == COMPLEX_TYPE | |
2933 || TREE_CODE (TREE_TYPE (t)) == VECTOR_TYPE) | |
2934 return DECL_GIMPLE_REG_P (t); | |
2935 | |
2936 return true; | |
2937 } | |
2938 | |
2939 | |
2940 /* Returns true if T is a GIMPLE formal temporary variable. */ | |
2941 | |
2942 bool | |
2943 is_gimple_formal_tmp_var (tree t) | |
2944 { | |
2945 if (TREE_CODE (t) == SSA_NAME) | |
2946 return true; | |
2947 | |
2948 return TREE_CODE (t) == VAR_DECL && DECL_GIMPLE_FORMAL_TEMP_P (t); | |
2949 } | |
2950 | |
2951 /* Returns true if T is a GIMPLE formal temporary register variable. */ | |
2952 | |
2953 bool | |
2954 is_gimple_formal_tmp_reg (tree t) | |
2955 { | |
2956 /* The intent of this is to get hold of a value that won't change. | |
2957 An SSA_NAME qualifies no matter if its of a user variable or not. */ | |
2958 if (TREE_CODE (t) == SSA_NAME) | |
2959 return true; | |
2960 | |
2961 /* We don't know the lifetime characteristics of user variables. */ | |
2962 if (!is_gimple_formal_tmp_var (t)) | |
2963 return false; | |
2964 | |
2965 /* Finally, it must be capable of being placed in a register. */ | |
2966 return is_gimple_reg (t); | |
2967 } | |
2968 | |
2969 /* Return true if T is a GIMPLE variable whose address is not needed. */ | |
2970 | |
2971 bool | |
2972 is_gimple_non_addressable (tree t) | |
2973 { | |
2974 if (TREE_CODE (t) == SSA_NAME) | |
2975 t = SSA_NAME_VAR (t); | |
2976 | |
2977 return (is_gimple_variable (t) && ! needs_to_live_in_memory (t)); | |
2978 } | |
2979 | |
2980 /* Return true if T is a GIMPLE rvalue, i.e. an identifier or a constant. */ | |
2981 | |
2982 bool | |
2983 is_gimple_val (tree t) | |
2984 { | |
2985 /* Make loads from volatiles and memory vars explicit. */ | |
2986 if (is_gimple_variable (t) | |
2987 && is_gimple_reg_type (TREE_TYPE (t)) | |
2988 && !is_gimple_reg (t)) | |
2989 return false; | |
2990 | |
2991 /* FIXME make these decls. That can happen only when we expose the | |
2992 entire landing-pad construct at the tree level. */ | |
2993 if (TREE_CODE (t) == EXC_PTR_EXPR || TREE_CODE (t) == FILTER_EXPR) | |
2994 return true; | |
2995 | |
2996 return (is_gimple_variable (t) || is_gimple_min_invariant (t)); | |
2997 } | |
2998 | |
2999 /* Similarly, but accept hard registers as inputs to asm statements. */ | |
3000 | |
3001 bool | |
3002 is_gimple_asm_val (tree t) | |
3003 { | |
3004 if (TREE_CODE (t) == VAR_DECL && DECL_HARD_REGISTER (t)) | |
3005 return true; | |
3006 | |
3007 return is_gimple_val (t); | |
3008 } | |
3009 | |
3010 /* Return true if T is a GIMPLE minimal lvalue. */ | |
3011 | |
3012 bool | |
3013 is_gimple_min_lval (tree t) | |
3014 { | |
3015 return (is_gimple_id (t) || TREE_CODE (t) == INDIRECT_REF); | |
3016 } | |
3017 | |
3018 /* Return true if T is a typecast operation. */ | |
3019 | |
3020 bool | |
3021 is_gimple_cast (tree t) | |
3022 { | |
3023 return (CONVERT_EXPR_P (t) | |
3024 || TREE_CODE (t) == FIX_TRUNC_EXPR); | |
3025 } | |
3026 | |
3027 /* Return true if T is a valid function operand of a CALL_EXPR. */ | |
3028 | |
3029 bool | |
3030 is_gimple_call_addr (tree t) | |
3031 { | |
3032 return (TREE_CODE (t) == OBJ_TYPE_REF || is_gimple_val (t)); | |
3033 } | |
3034 | |
3035 /* If T makes a function call, return the corresponding CALL_EXPR operand. | |
3036 Otherwise, return NULL_TREE. */ | |
3037 | |
3038 tree | |
3039 get_call_expr_in (tree t) | |
3040 { | |
3041 if (TREE_CODE (t) == MODIFY_EXPR) | |
3042 t = TREE_OPERAND (t, 1); | |
3043 if (TREE_CODE (t) == WITH_SIZE_EXPR) | |
3044 t = TREE_OPERAND (t, 0); | |
3045 if (TREE_CODE (t) == CALL_EXPR) | |
3046 return t; | |
3047 return NULL_TREE; | |
3048 } | |
3049 | |
3050 | |
3051 /* Given a memory reference expression T, return its base address. | |
3052 The base address of a memory reference expression is the main | |
3053 object being referenced. For instance, the base address for | |
3054 'array[i].fld[j]' is 'array'. You can think of this as stripping | |
3055 away the offset part from a memory address. | |
3056 | |
3057 This function calls handled_component_p to strip away all the inner | |
3058 parts of the memory reference until it reaches the base object. */ | |
3059 | |
3060 tree | |
3061 get_base_address (tree t) | |
3062 { | |
3063 while (handled_component_p (t)) | |
3064 t = TREE_OPERAND (t, 0); | |
3065 | |
3066 if (SSA_VAR_P (t) | |
3067 || TREE_CODE (t) == STRING_CST | |
3068 || TREE_CODE (t) == CONSTRUCTOR | |
3069 || INDIRECT_REF_P (t)) | |
3070 return t; | |
3071 else | |
3072 return NULL_TREE; | |
3073 } | |
3074 | |
3075 void | |
3076 recalculate_side_effects (tree t) | |
3077 { | |
3078 enum tree_code code = TREE_CODE (t); | |
3079 int len = TREE_OPERAND_LENGTH (t); | |
3080 int i; | |
3081 | |
3082 switch (TREE_CODE_CLASS (code)) | |
3083 { | |
3084 case tcc_expression: | |
3085 switch (code) | |
3086 { | |
3087 case INIT_EXPR: | |
3088 case MODIFY_EXPR: | |
3089 case VA_ARG_EXPR: | |
3090 case PREDECREMENT_EXPR: | |
3091 case PREINCREMENT_EXPR: | |
3092 case POSTDECREMENT_EXPR: | |
3093 case POSTINCREMENT_EXPR: | |
3094 /* All of these have side-effects, no matter what their | |
3095 operands are. */ | |
3096 return; | |
3097 | |
3098 default: | |
3099 break; | |
3100 } | |
3101 /* Fall through. */ | |
3102 | |
3103 case tcc_comparison: /* a comparison expression */ | |
3104 case tcc_unary: /* a unary arithmetic expression */ | |
3105 case tcc_binary: /* a binary arithmetic expression */ | |
3106 case tcc_reference: /* a reference */ | |
3107 case tcc_vl_exp: /* a function call */ | |
3108 TREE_SIDE_EFFECTS (t) = TREE_THIS_VOLATILE (t); | |
3109 for (i = 0; i < len; ++i) | |
3110 { | |
3111 tree op = TREE_OPERAND (t, i); | |
3112 if (op && TREE_SIDE_EFFECTS (op)) | |
3113 TREE_SIDE_EFFECTS (t) = 1; | |
3114 } | |
3115 break; | |
3116 | |
3117 case tcc_constant: | |
3118 /* No side-effects. */ | |
3119 return; | |
3120 | |
3121 default: | |
3122 gcc_unreachable (); | |
3123 } | |
3124 } | |
3125 | |
3126 /* Canonicalize a tree T for use in a COND_EXPR as conditional. Returns | |
3127 a canonicalized tree that is valid for a COND_EXPR or NULL_TREE, if | |
3128 we failed to create one. */ | |
3129 | |
3130 tree | |
3131 canonicalize_cond_expr_cond (tree t) | |
3132 { | |
3133 /* For (bool)x use x != 0. */ | |
3134 if (TREE_CODE (t) == NOP_EXPR | |
3135 && TREE_TYPE (t) == boolean_type_node) | |
3136 { | |
3137 tree top0 = TREE_OPERAND (t, 0); | |
3138 t = build2 (NE_EXPR, TREE_TYPE (t), | |
3139 top0, build_int_cst (TREE_TYPE (top0), 0)); | |
3140 } | |
3141 /* For !x use x == 0. */ | |
3142 else if (TREE_CODE (t) == TRUTH_NOT_EXPR) | |
3143 { | |
3144 tree top0 = TREE_OPERAND (t, 0); | |
3145 t = build2 (EQ_EXPR, TREE_TYPE (t), | |
3146 top0, build_int_cst (TREE_TYPE (top0), 0)); | |
3147 } | |
3148 /* For cmp ? 1 : 0 use cmp. */ | |
3149 else if (TREE_CODE (t) == COND_EXPR | |
3150 && COMPARISON_CLASS_P (TREE_OPERAND (t, 0)) | |
3151 && integer_onep (TREE_OPERAND (t, 1)) | |
3152 && integer_zerop (TREE_OPERAND (t, 2))) | |
3153 { | |
3154 tree top0 = TREE_OPERAND (t, 0); | |
3155 t = build2 (TREE_CODE (top0), TREE_TYPE (t), | |
3156 TREE_OPERAND (top0, 0), TREE_OPERAND (top0, 1)); | |
3157 } | |
3158 | |
3159 if (is_gimple_condexpr (t)) | |
3160 return t; | |
3161 | |
3162 return NULL_TREE; | |
3163 } | |
3164 | |
3165 /* Build a GIMPLE_CALL identical to STMT but skipping the arguments in | |
3166 the positions marked by the set ARGS_TO_SKIP. */ | |
3167 | |
3168 gimple | |
3169 gimple_call_copy_skip_args (gimple stmt, bitmap args_to_skip) | |
3170 { | |
3171 int i; | |
3172 tree fn = gimple_call_fn (stmt); | |
3173 int nargs = gimple_call_num_args (stmt); | |
3174 VEC(tree, heap) *vargs = VEC_alloc (tree, heap, nargs); | |
3175 gimple new_stmt; | |
3176 | |
3177 for (i = 0; i < nargs; i++) | |
3178 if (!bitmap_bit_p (args_to_skip, i)) | |
3179 VEC_quick_push (tree, vargs, gimple_call_arg (stmt, i)); | |
3180 | |
3181 new_stmt = gimple_build_call_vec (fn, vargs); | |
3182 VEC_free (tree, heap, vargs); | |
3183 if (gimple_call_lhs (stmt)) | |
3184 gimple_call_set_lhs (new_stmt, gimple_call_lhs (stmt)); | |
3185 | |
3186 gimple_set_block (new_stmt, gimple_block (stmt)); | |
3187 if (gimple_has_location (stmt)) | |
3188 gimple_set_location (new_stmt, gimple_location (stmt)); | |
3189 | |
3190 /* Carry all the flags to the new GIMPLE_CALL. */ | |
3191 gimple_call_set_chain (new_stmt, gimple_call_chain (stmt)); | |
3192 gimple_call_set_tail (new_stmt, gimple_call_tail_p (stmt)); | |
3193 gimple_call_set_cannot_inline (new_stmt, gimple_call_cannot_inline_p (stmt)); | |
3194 gimple_call_set_return_slot_opt (new_stmt, gimple_call_return_slot_opt_p (stmt)); | |
3195 gimple_call_set_from_thunk (new_stmt, gimple_call_from_thunk_p (stmt)); | |
3196 gimple_call_set_va_arg_pack (new_stmt, gimple_call_va_arg_pack_p (stmt)); | |
5
a4c410aa4714
modifing gimple.[ch], cfgexpand.c
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
3197 #ifndef noCbC |
a4c410aa4714
modifing gimple.[ch], cfgexpand.c
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
3198 gimple_call_set_cbc_goto (new_stmt, gimple_call_cbc_goto_p (stmt)); |
a4c410aa4714
modifing gimple.[ch], cfgexpand.c
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
3199 #endif |
0 | 3200 return new_stmt; |
3201 } | |
3202 | |
3203 #include "gt-gimple.h" |