Mercurial > hg > CbC > CbC_gcc
annotate gcc/gimple-iterator.c @ 58:3aaf117db171
error at dwarf2out.c
author | ryoma <e075725@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 15 Feb 2010 14:58:24 +0900 |
parents | 77e2b8dfacca |
children | b7f97abdc517 |
rev | line source |
---|---|
0 | 1 /* Iterator routines for GIMPLE statements. |
2 Copyright (C) 2007, 2008 Free Software Foundation, Inc. | |
3 Contributed by Aldy Hernandez <aldy@quesejoda.com> | |
4 | |
5 This file is part of GCC. | |
6 | |
7 GCC is free software; you can redistribute it and/or modify it under | |
8 the terms of the GNU General Public License as published by the Free | |
9 Software Foundation; either version 3, or (at your option) any later | |
10 version. | |
11 | |
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY | |
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
18 along with GCC; see the file COPYING3. If not see | |
19 <http://www.gnu.org/licenses/>. */ | |
20 | |
21 #include "config.h" | |
22 #include "system.h" | |
23 #include "coretypes.h" | |
24 #include "tm.h" | |
25 #include "tree.h" | |
26 #include "gimple.h" | |
27 #include "tree-flow.h" | |
28 #include "value-prof.h" | |
29 | |
30 | |
31 /* Mark the statement STMT as modified, and update it. */ | |
32 | |
33 static inline void | |
34 update_modified_stmt (gimple stmt) | |
35 { | |
36 if (!ssa_operands_active ()) | |
37 return; | |
38 update_stmt_if_modified (stmt); | |
39 } | |
40 | |
41 | |
42 /* Mark the statements in SEQ as modified, and update them. */ | |
43 | |
44 static void | |
45 update_modified_stmts (gimple_seq seq) | |
46 { | |
47 gimple_stmt_iterator gsi; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
48 |
0 | 49 if (!ssa_operands_active ()) |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
50 return; |
0 | 51 for (gsi = gsi_start (seq); !gsi_end_p (gsi); gsi_next (&gsi)) |
52 update_stmt_if_modified (gsi_stmt (gsi)); | |
53 } | |
54 | |
55 | |
56 /* Set BB to be the basic block for all the statements in the list | |
57 starting at FIRST and LAST. */ | |
58 | |
59 static void | |
60 update_bb_for_stmts (gimple_seq_node first, basic_block bb) | |
61 { | |
62 gimple_seq_node n; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
63 |
0 | 64 for (n = first; n; n = n->next) |
65 gimple_set_bb (n->stmt, bb); | |
66 } | |
67 | |
68 | |
69 /* Insert the sequence delimited by nodes FIRST and LAST before | |
70 iterator I. M specifies how to update iterator I after insertion | |
71 (see enum gsi_iterator_update). | |
72 | |
73 This routine assumes that there is a forward and backward path | |
74 between FIRST and LAST (i.e., they are linked in a doubly-linked | |
75 list). Additionally, if FIRST == LAST, this routine will properly | |
76 insert a single node. */ | |
77 | |
78 static void | |
79 gsi_insert_seq_nodes_before (gimple_stmt_iterator *i, | |
80 gimple_seq_node first, | |
81 gimple_seq_node last, | |
82 enum gsi_iterator_update mode) | |
83 { | |
84 basic_block bb; | |
85 gimple_seq_node cur = i->ptr; | |
86 | |
87 if ((bb = gsi_bb (*i)) != NULL) | |
88 update_bb_for_stmts (first, bb); | |
89 | |
90 /* Link SEQ before CUR in the sequence. */ | |
91 if (cur) | |
92 { | |
93 first->prev = cur->prev; | |
94 if (first->prev) | |
95 first->prev->next = first; | |
96 else | |
97 gimple_seq_set_first (i->seq, first); | |
98 last->next = cur; | |
99 cur->prev = last; | |
100 } | |
101 else | |
102 { | |
103 gimple_seq_node itlast = gimple_seq_last (i->seq); | |
104 | |
105 /* If CUR is NULL, we link at the end of the sequence (this case happens | |
106 when gsi_after_labels is called for a basic block that contains only | |
107 labels, so it returns an iterator after the end of the block, and | |
108 we need to insert before it; it might be cleaner to add a flag to the | |
109 iterator saying whether we are at the start or end of the list). */ | |
110 first->prev = itlast; | |
111 if (itlast) | |
112 itlast->next = first; | |
113 else | |
114 gimple_seq_set_first (i->seq, first); | |
115 gimple_seq_set_last (i->seq, last); | |
116 } | |
117 | |
118 /* Update the iterator, if requested. */ | |
119 switch (mode) | |
120 { | |
121 case GSI_NEW_STMT: | |
122 case GSI_CONTINUE_LINKING: | |
123 i->ptr = first; | |
124 break; | |
125 case GSI_SAME_STMT: | |
126 break; | |
127 default: | |
128 gcc_unreachable (); | |
129 } | |
130 } | |
131 | |
132 | |
133 /* Inserts the sequence of statements SEQ before the statement pointed | |
134 by iterator I. MODE indicates what to do with the iterator after | |
135 insertion (see enum gsi_iterator_update). | |
136 | |
137 This function does not scan for new operands. It is provided for | |
138 the use of the gimplifier, which manipulates statements for which | |
139 def/use information has not yet been constructed. Most callers | |
140 should use gsi_insert_seq_before. */ | |
141 | |
142 void | |
143 gsi_insert_seq_before_without_update (gimple_stmt_iterator *i, gimple_seq seq, | |
144 enum gsi_iterator_update mode) | |
145 { | |
146 gimple_seq_node first, last; | |
147 | |
148 if (seq == NULL) | |
149 return; | |
150 | |
151 /* Don't allow inserting a sequence into itself. */ | |
152 gcc_assert (seq != i->seq); | |
153 | |
154 first = gimple_seq_first (seq); | |
155 last = gimple_seq_last (seq); | |
156 | |
157 gimple_seq_set_first (seq, NULL); | |
158 gimple_seq_set_last (seq, NULL); | |
159 gimple_seq_free (seq); | |
160 | |
161 /* Empty sequences need no work. */ | |
162 if (!first || !last) | |
163 { | |
164 gcc_assert (first == last); | |
165 return; | |
166 } | |
167 | |
168 gsi_insert_seq_nodes_before (i, first, last, mode); | |
169 } | |
170 | |
171 | |
172 /* Inserts the sequence of statements SEQ before the statement pointed | |
173 by iterator I. MODE indicates what to do with the iterator after | |
174 insertion (see enum gsi_iterator_update). Scan the statements in SEQ | |
175 for new operands. */ | |
176 | |
177 void | |
178 gsi_insert_seq_before (gimple_stmt_iterator *i, gimple_seq seq, | |
179 enum gsi_iterator_update mode) | |
180 { | |
181 update_modified_stmts (seq); | |
182 gsi_insert_seq_before_without_update (i, seq, mode); | |
183 } | |
184 | |
185 | |
186 /* Insert the sequence delimited by nodes FIRST and LAST after | |
187 iterator I. M specifies how to update iterator I after insertion | |
188 (see enum gsi_iterator_update). | |
189 | |
190 This routine assumes that there is a forward and backward path | |
191 between FIRST and LAST (i.e., they are linked in a doubly-linked | |
192 list). Additionally, if FIRST == LAST, this routine will properly | |
193 insert a single node. */ | |
194 | |
195 static void | |
196 gsi_insert_seq_nodes_after (gimple_stmt_iterator *i, | |
197 gimple_seq_node first, | |
198 gimple_seq_node last, | |
199 enum gsi_iterator_update m) | |
200 { | |
201 basic_block bb; | |
202 gimple_seq_node cur = i->ptr; | |
203 | |
204 /* If the iterator is inside a basic block, we need to update the | |
205 basic block information for all the nodes between FIRST and LAST. */ | |
206 if ((bb = gsi_bb (*i)) != NULL) | |
207 update_bb_for_stmts (first, bb); | |
208 | |
209 /* Link SEQ after CUR. */ | |
210 if (cur) | |
211 { | |
212 last->next = cur->next; | |
213 if (last->next) | |
214 last->next->prev = last; | |
215 else | |
216 gimple_seq_set_last (i->seq, last); | |
217 first->prev = cur; | |
218 cur->next = first; | |
219 } | |
220 else | |
221 { | |
222 gcc_assert (!gimple_seq_last (i->seq)); | |
223 gimple_seq_set_first (i->seq, first); | |
224 gimple_seq_set_last (i->seq, last); | |
225 } | |
226 | |
227 /* Update the iterator, if requested. */ | |
228 switch (m) | |
229 { | |
230 case GSI_NEW_STMT: | |
231 i->ptr = first; | |
232 break; | |
233 case GSI_CONTINUE_LINKING: | |
234 i->ptr = last; | |
235 break; | |
236 case GSI_SAME_STMT: | |
237 gcc_assert (cur); | |
238 break; | |
239 default: | |
240 gcc_unreachable (); | |
241 } | |
242 } | |
243 | |
244 | |
245 /* Links sequence SEQ after the statement pointed-to by iterator I. | |
246 MODE is as in gsi_insert_after. | |
247 | |
248 This function does not scan for new operands. It is provided for | |
249 the use of the gimplifier, which manipulates statements for which | |
250 def/use information has not yet been constructed. Most callers | |
251 should use gsi_insert_seq_after. */ | |
252 | |
253 void | |
254 gsi_insert_seq_after_without_update (gimple_stmt_iterator *i, gimple_seq seq, | |
255 enum gsi_iterator_update mode) | |
256 { | |
257 gimple_seq_node first, last; | |
258 | |
259 if (seq == NULL) | |
260 return; | |
261 | |
262 /* Don't allow inserting a sequence into itself. */ | |
263 gcc_assert (seq != i->seq); | |
264 | |
265 first = gimple_seq_first (seq); | |
266 last = gimple_seq_last (seq); | |
267 | |
268 gimple_seq_set_first (seq, NULL); | |
269 gimple_seq_set_last (seq, NULL); | |
270 gimple_seq_free (seq); | |
271 | |
272 /* Empty sequences need no work. */ | |
273 if (!first || !last) | |
274 { | |
275 gcc_assert (first == last); | |
276 return; | |
277 } | |
278 | |
279 gsi_insert_seq_nodes_after (i, first, last, mode); | |
280 } | |
281 | |
282 | |
283 /* Links sequence SEQ after the statement pointed-to by iterator I. | |
284 MODE is as in gsi_insert_after. Scan the statements in SEQ | |
285 for new operands. */ | |
286 | |
287 void | |
288 gsi_insert_seq_after (gimple_stmt_iterator *i, gimple_seq seq, | |
289 enum gsi_iterator_update mode) | |
290 { | |
291 update_modified_stmts (seq); | |
292 gsi_insert_seq_after_without_update (i, seq, mode); | |
293 } | |
294 | |
295 | |
296 /* Move all statements in the sequence after I to a new sequence. | |
297 Return this new sequence. */ | |
298 | |
299 gimple_seq | |
300 gsi_split_seq_after (gimple_stmt_iterator i) | |
301 { | |
302 gimple_seq_node cur, next; | |
303 gimple_seq old_seq, new_seq; | |
304 | |
305 cur = i.ptr; | |
306 | |
307 /* How can we possibly split after the end, or before the beginning? */ | |
308 gcc_assert (cur && cur->next); | |
309 next = cur->next; | |
310 | |
311 old_seq = i.seq; | |
312 new_seq = gimple_seq_alloc (); | |
313 | |
314 gimple_seq_set_first (new_seq, next); | |
315 gimple_seq_set_last (new_seq, gimple_seq_last (old_seq)); | |
316 gimple_seq_set_last (old_seq, cur); | |
317 cur->next = NULL; | |
318 next->prev = NULL; | |
319 | |
320 return new_seq; | |
321 } | |
322 | |
323 | |
324 /* Move all statements in the sequence before I to a new sequence. | |
325 Return this new sequence. I is set to the head of the new list. */ | |
326 | |
327 gimple_seq | |
328 gsi_split_seq_before (gimple_stmt_iterator *i) | |
329 { | |
330 gimple_seq_node cur, prev; | |
331 gimple_seq old_seq, new_seq; | |
332 | |
333 cur = i->ptr; | |
334 | |
335 /* How can we possibly split after the end? */ | |
336 gcc_assert (cur); | |
337 prev = cur->prev; | |
338 | |
339 old_seq = i->seq; | |
340 new_seq = gimple_seq_alloc (); | |
341 i->seq = new_seq; | |
342 | |
343 /* Set the limits on NEW_SEQ. */ | |
344 gimple_seq_set_first (new_seq, cur); | |
345 gimple_seq_set_last (new_seq, gimple_seq_last (old_seq)); | |
346 | |
347 /* Cut OLD_SEQ before I. */ | |
348 gimple_seq_set_last (old_seq, prev); | |
349 cur->prev = NULL; | |
350 if (prev) | |
351 prev->next = NULL; | |
352 else | |
353 gimple_seq_set_first (old_seq, NULL); | |
354 | |
355 return new_seq; | |
356 } | |
357 | |
358 | |
359 /* Replace the statement pointed-to by GSI to STMT. If UPDATE_EH_INFO | |
360 is true, the exception handling information of the original | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
361 statement is moved to the new statement. Assignments must only be |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
362 replaced with assignments to the same LHS. */ |
0 | 363 |
364 void | |
365 gsi_replace (gimple_stmt_iterator *gsi, gimple stmt, bool update_eh_info) | |
366 { | |
367 gimple orig_stmt = gsi_stmt (*gsi); | |
368 | |
369 if (stmt == orig_stmt) | |
370 return; | |
371 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
372 gcc_assert (!gimple_has_lhs (orig_stmt) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
373 || gimple_get_lhs (orig_stmt) == gimple_get_lhs (stmt)); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
374 |
0 | 375 gimple_set_location (stmt, gimple_location (orig_stmt)); |
376 gimple_set_bb (stmt, gsi_bb (*gsi)); | |
377 | |
378 /* Preserve EH region information from the original statement, if | |
379 requested by the caller. */ | |
380 if (update_eh_info) | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
381 maybe_clean_or_replace_eh_stmt (orig_stmt, stmt); |
0 | 382 |
383 gimple_duplicate_stmt_histograms (cfun, stmt, cfun, orig_stmt); | |
384 gimple_remove_stmt_histograms (cfun, orig_stmt); | |
385 delink_stmt_imm_use (orig_stmt); | |
386 *gsi_stmt_ptr (gsi) = stmt; | |
387 gimple_set_modified (stmt, true); | |
388 update_modified_stmt (stmt); | |
389 } | |
390 | |
391 | |
392 /* Insert statement STMT before the statement pointed-to by iterator I. | |
393 M specifies how to update iterator I after insertion (see enum | |
394 gsi_iterator_update). | |
395 | |
396 This function does not scan for new operands. It is provided for | |
397 the use of the gimplifier, which manipulates statements for which | |
398 def/use information has not yet been constructed. Most callers | |
399 should use gsi_insert_before. */ | |
400 | |
401 void | |
402 gsi_insert_before_without_update (gimple_stmt_iterator *i, gimple stmt, | |
403 enum gsi_iterator_update m) | |
404 { | |
405 gimple_seq_node n; | |
406 | |
407 n = GGC_NEW (struct gimple_seq_node_d); | |
408 n->prev = n->next = NULL; | |
409 n->stmt = stmt; | |
410 gsi_insert_seq_nodes_before (i, n, n, m); | |
411 } | |
412 | |
413 /* Insert statement STMT before the statement pointed-to by iterator I. | |
414 Update STMT's basic block and scan it for new operands. M | |
415 specifies how to update iterator I after insertion (see enum | |
416 gsi_iterator_update). */ | |
417 | |
418 void | |
419 gsi_insert_before (gimple_stmt_iterator *i, gimple stmt, | |
420 enum gsi_iterator_update m) | |
421 { | |
422 update_modified_stmt (stmt); | |
423 gsi_insert_before_without_update (i, stmt, m); | |
424 } | |
425 | |
426 | |
427 /* Insert statement STMT after the statement pointed-to by iterator I. | |
428 M specifies how to update iterator I after insertion (see enum | |
429 gsi_iterator_update). | |
430 | |
431 This function does not scan for new operands. It is provided for | |
432 the use of the gimplifier, which manipulates statements for which | |
433 def/use information has not yet been constructed. Most callers | |
434 should use gsi_insert_after. */ | |
435 | |
436 void | |
437 gsi_insert_after_without_update (gimple_stmt_iterator *i, gimple stmt, | |
438 enum gsi_iterator_update m) | |
439 { | |
440 gimple_seq_node n; | |
441 | |
442 n = GGC_NEW (struct gimple_seq_node_d); | |
443 n->prev = n->next = NULL; | |
444 n->stmt = stmt; | |
445 gsi_insert_seq_nodes_after (i, n, n, m); | |
446 } | |
447 | |
448 | |
449 /* Insert statement STMT after the statement pointed-to by iterator I. | |
450 Update STMT's basic block and scan it for new operands. M | |
451 specifies how to update iterator I after insertion (see enum | |
452 gsi_iterator_update). */ | |
453 | |
454 void | |
455 gsi_insert_after (gimple_stmt_iterator *i, gimple stmt, | |
456 enum gsi_iterator_update m) | |
457 { | |
458 update_modified_stmt (stmt); | |
459 gsi_insert_after_without_update (i, stmt, m); | |
460 } | |
461 | |
462 | |
463 /* Remove the current stmt from the sequence. The iterator is updated | |
464 to point to the next statement. | |
465 | |
466 REMOVE_PERMANENTLY is true when the statement is going to be removed | |
467 from the IL and not reinserted elsewhere. In that case we remove the | |
468 statement pointed to by iterator I from the EH tables, and free its | |
469 operand caches. Otherwise we do not modify this information. */ | |
470 | |
471 void | |
472 gsi_remove (gimple_stmt_iterator *i, bool remove_permanently) | |
473 { | |
474 gimple_seq_node cur, next, prev; | |
475 gimple stmt = gsi_stmt (*i); | |
476 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
477 insert_debug_temps_for_defs (i); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
478 |
0 | 479 /* Free all the data flow information for STMT. */ |
480 gimple_set_bb (stmt, NULL); | |
481 delink_stmt_imm_use (stmt); | |
482 gimple_set_modified (stmt, true); | |
483 | |
484 if (remove_permanently) | |
485 { | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
486 remove_stmt_from_eh_lp (stmt); |
0 | 487 gimple_remove_stmt_histograms (cfun, stmt); |
488 } | |
489 | |
490 /* Update the iterator and re-wire the links in I->SEQ. */ | |
491 cur = i->ptr; | |
492 next = cur->next; | |
493 prev = cur->prev; | |
494 | |
495 if (prev) | |
496 prev->next = next; | |
497 else | |
498 gimple_seq_set_first (i->seq, next); | |
499 | |
500 if (next) | |
501 next->prev = prev; | |
502 else | |
503 gimple_seq_set_last (i->seq, prev); | |
504 | |
505 i->ptr = next; | |
506 } | |
507 | |
508 | |
509 /* Finds iterator for STMT. */ | |
510 | |
511 gimple_stmt_iterator | |
512 gsi_for_stmt (gimple stmt) | |
513 { | |
514 gimple_stmt_iterator i; | |
515 basic_block bb = gimple_bb (stmt); | |
516 | |
517 if (gimple_code (stmt) == GIMPLE_PHI) | |
518 i = gsi_start_phis (bb); | |
519 else | |
520 i = gsi_start_bb (bb); | |
521 | |
522 for (; !gsi_end_p (i); gsi_next (&i)) | |
523 if (gsi_stmt (i) == stmt) | |
524 return i; | |
525 | |
526 gcc_unreachable (); | |
527 } | |
528 | |
529 | |
530 /* Move the statement at FROM so it comes right after the statement at TO. */ | |
531 | |
532 void | |
533 gsi_move_after (gimple_stmt_iterator *from, gimple_stmt_iterator *to) | |
534 { | |
535 gimple stmt = gsi_stmt (*from); | |
536 gsi_remove (from, false); | |
537 | |
538 /* We must have GSI_NEW_STMT here, as gsi_move_after is sometimes used to | |
539 move statements to an empty block. */ | |
540 gsi_insert_after (to, stmt, GSI_NEW_STMT); | |
541 } | |
542 | |
543 | |
544 /* Move the statement at FROM so it comes right before the statement | |
545 at TO. */ | |
546 | |
547 void | |
548 gsi_move_before (gimple_stmt_iterator *from, gimple_stmt_iterator *to) | |
549 { | |
550 gimple stmt = gsi_stmt (*from); | |
551 gsi_remove (from, false); | |
552 | |
553 /* For consistency with gsi_move_after, it might be better to have | |
554 GSI_NEW_STMT here; however, that breaks several places that expect | |
555 that TO does not change. */ | |
556 gsi_insert_before (to, stmt, GSI_SAME_STMT); | |
557 } | |
558 | |
559 | |
560 /* Move the statement at FROM to the end of basic block BB. */ | |
561 | |
562 void | |
563 gsi_move_to_bb_end (gimple_stmt_iterator *from, basic_block bb) | |
564 { | |
565 gimple_stmt_iterator last = gsi_last_bb (bb); | |
566 #ifdef ENABLE_CHECKING | |
567 gcc_assert (gsi_bb (last) == bb); | |
568 #endif | |
569 | |
570 /* Have to check gsi_end_p because it could be an empty block. */ | |
571 if (!gsi_end_p (last) && is_ctrl_stmt (gsi_stmt (last))) | |
572 gsi_move_before (from, &last); | |
573 else | |
574 gsi_move_after (from, &last); | |
575 } | |
576 | |
577 | |
578 /* Add STMT to the pending list of edge E. No actual insertion is | |
579 made until a call to gsi_commit_edge_inserts () is made. */ | |
580 | |
581 void | |
582 gsi_insert_on_edge (edge e, gimple stmt) | |
583 { | |
584 gimple_seq_add_stmt (&PENDING_STMT (e), stmt); | |
585 } | |
586 | |
587 /* Add the sequence of statements SEQ to the pending list of edge E. | |
588 No actual insertion is made until a call to gsi_commit_edge_inserts | |
589 is made. */ | |
590 | |
591 void | |
592 gsi_insert_seq_on_edge (edge e, gimple_seq seq) | |
593 { | |
594 gimple_seq_add_seq (&PENDING_STMT (e), seq); | |
595 } | |
596 | |
597 | |
598 /* Insert the statement pointed-to by GSI into edge E. Every attempt | |
599 is made to place the statement in an existing basic block, but | |
600 sometimes that isn't possible. When it isn't possible, the edge is | |
601 split and the statement is added to the new block. | |
602 | |
603 In all cases, the returned *GSI points to the correct location. The | |
604 return value is true if insertion should be done after the location, | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
605 or false if it should be done before the location. If a new basic block |
0 | 606 has to be created, it is stored in *NEW_BB. */ |
607 | |
608 static bool | |
609 gimple_find_edge_insert_loc (edge e, gimple_stmt_iterator *gsi, | |
610 basic_block *new_bb) | |
611 { | |
612 basic_block dest, src; | |
613 gimple tmp; | |
614 | |
615 dest = e->dest; | |
616 | |
617 /* If the destination has one predecessor which has no PHI nodes, | |
618 insert there. Except for the exit block. | |
619 | |
620 The requirement for no PHI nodes could be relaxed. Basically we | |
621 would have to examine the PHIs to prove that none of them used | |
622 the value set by the statement we want to insert on E. That | |
623 hardly seems worth the effort. */ | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
624 restart: |
0 | 625 if (single_pred_p (dest) |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
626 && gimple_seq_empty_p (phi_nodes (dest)) |
0 | 627 && dest != EXIT_BLOCK_PTR) |
628 { | |
629 *gsi = gsi_start_bb (dest); | |
630 if (gsi_end_p (*gsi)) | |
631 return true; | |
632 | |
633 /* Make sure we insert after any leading labels. */ | |
634 tmp = gsi_stmt (*gsi); | |
635 while (gimple_code (tmp) == GIMPLE_LABEL) | |
636 { | |
637 gsi_next (gsi); | |
638 if (gsi_end_p (*gsi)) | |
639 break; | |
640 tmp = gsi_stmt (*gsi); | |
641 } | |
642 | |
643 if (gsi_end_p (*gsi)) | |
644 { | |
645 *gsi = gsi_last_bb (dest); | |
646 return true; | |
647 } | |
648 else | |
649 return false; | |
650 } | |
651 | |
652 /* If the source has one successor, the edge is not abnormal and | |
653 the last statement does not end a basic block, insert there. | |
654 Except for the entry block. */ | |
655 src = e->src; | |
656 if ((e->flags & EDGE_ABNORMAL) == 0 | |
657 && single_succ_p (src) | |
658 && src != ENTRY_BLOCK_PTR) | |
659 { | |
660 *gsi = gsi_last_bb (src); | |
661 if (gsi_end_p (*gsi)) | |
662 return true; | |
663 | |
664 tmp = gsi_stmt (*gsi); | |
665 if (!stmt_ends_bb_p (tmp)) | |
666 return true; | |
667 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
668 switch (gimple_code (tmp)) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
669 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
670 case GIMPLE_RETURN: |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
671 case GIMPLE_RESX: |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
672 return false; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
673 default: |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
674 break; |
0 | 675 } |
676 } | |
677 | |
678 /* Otherwise, create a new basic block, and split this edge. */ | |
679 dest = split_edge (e); | |
680 if (new_bb) | |
681 *new_bb = dest; | |
682 e = single_pred_edge (dest); | |
683 goto restart; | |
684 } | |
685 | |
686 | |
687 /* Similar to gsi_insert_on_edge+gsi_commit_edge_inserts. If a new | |
688 block has to be created, it is returned. */ | |
689 | |
690 basic_block | |
691 gsi_insert_on_edge_immediate (edge e, gimple stmt) | |
692 { | |
693 gimple_stmt_iterator gsi; | |
694 basic_block new_bb = NULL; | |
695 | |
696 gcc_assert (!PENDING_STMT (e)); | |
697 | |
698 if (gimple_find_edge_insert_loc (e, &gsi, &new_bb)) | |
699 gsi_insert_after (&gsi, stmt, GSI_NEW_STMT); | |
700 else | |
701 gsi_insert_before (&gsi, stmt, GSI_NEW_STMT); | |
702 | |
703 return new_bb; | |
704 } | |
705 | |
706 /* Insert STMTS on edge E. If a new block has to be created, it | |
707 is returned. */ | |
708 | |
709 basic_block | |
710 gsi_insert_seq_on_edge_immediate (edge e, gimple_seq stmts) | |
711 { | |
712 gimple_stmt_iterator gsi; | |
713 basic_block new_bb = NULL; | |
714 | |
715 gcc_assert (!PENDING_STMT (e)); | |
716 | |
717 if (gimple_find_edge_insert_loc (e, &gsi, &new_bb)) | |
718 gsi_insert_seq_after (&gsi, stmts, GSI_NEW_STMT); | |
719 else | |
720 gsi_insert_seq_before (&gsi, stmts, GSI_NEW_STMT); | |
721 | |
722 return new_bb; | |
723 } | |
724 | |
725 /* This routine will commit all pending edge insertions, creating any new | |
726 basic blocks which are necessary. */ | |
727 | |
728 void | |
729 gsi_commit_edge_inserts (void) | |
730 { | |
731 basic_block bb; | |
732 edge e; | |
733 edge_iterator ei; | |
734 | |
735 gsi_commit_one_edge_insert (single_succ_edge (ENTRY_BLOCK_PTR), NULL); | |
736 | |
737 FOR_EACH_BB (bb) | |
738 FOR_EACH_EDGE (e, ei, bb->succs) | |
739 gsi_commit_one_edge_insert (e, NULL); | |
740 } | |
741 | |
742 | |
743 /* Commit insertions pending at edge E. If a new block is created, set NEW_BB | |
744 to this block, otherwise set it to NULL. */ | |
745 | |
746 void | |
747 gsi_commit_one_edge_insert (edge e, basic_block *new_bb) | |
748 { | |
749 if (new_bb) | |
750 *new_bb = NULL; | |
751 | |
752 if (PENDING_STMT (e)) | |
753 { | |
754 gimple_stmt_iterator gsi; | |
755 gimple_seq seq = PENDING_STMT (e); | |
756 | |
757 PENDING_STMT (e) = NULL; | |
758 | |
759 if (gimple_find_edge_insert_loc (e, &gsi, new_bb)) | |
760 gsi_insert_seq_after (&gsi, seq, GSI_NEW_STMT); | |
761 else | |
762 gsi_insert_seq_before (&gsi, seq, GSI_NEW_STMT); | |
763 } | |
764 } | |
765 | |
766 /* Returns iterator at the start of the list of phi nodes of BB. */ | |
767 | |
768 gimple_stmt_iterator | |
769 gsi_start_phis (basic_block bb) | |
770 { | |
771 return gsi_start (phi_nodes (bb)); | |
772 } |