PR 44292 Enable large record lengths in OPEN and INQUIRE statements
[official-gcc.git] / gcc / gimple-iterator.c
blobd9d02d305efa41df7a7d605d8d38bb45adc3bea6
1 /* Iterator routines for GIMPLE statements.
2 Copyright (C) 2007-2017 Free Software Foundation, Inc.
3 Contributed by Aldy Hernandez <aldy@quesejoda.com>
5 This file is part of GCC.
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.
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.
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/>. */
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "backend.h"
25 #include "tree.h"
26 #include "gimple.h"
27 #include "cfghooks.h"
28 #include "ssa.h"
29 #include "cgraph.h"
30 #include "tree-eh.h"
31 #include "gimple-iterator.h"
32 #include "tree-cfg.h"
33 #include "tree-ssa.h"
34 #include "value-prof.h"
37 /* Mark the statement STMT as modified, and update it. */
39 static inline void
40 update_modified_stmt (gimple *stmt)
42 if (!ssa_operands_active (cfun))
43 return;
44 update_stmt_if_modified (stmt);
48 /* Mark the statements in SEQ as modified, and update them. */
50 void
51 update_modified_stmts (gimple_seq seq)
53 gimple_stmt_iterator gsi;
55 if (!ssa_operands_active (cfun))
56 return;
57 for (gsi = gsi_start (seq); !gsi_end_p (gsi); gsi_next (&gsi))
58 update_stmt_if_modified (gsi_stmt (gsi));
62 /* Set BB to be the basic block for all the statements in the list
63 starting at FIRST and LAST. */
65 static void
66 update_bb_for_stmts (gimple_seq_node first, gimple_seq_node last,
67 basic_block bb)
69 gimple_seq_node n;
71 for (n = first; n; n = n->next)
73 gimple_set_bb (n, bb);
74 if (n == last)
75 break;
79 /* Set the frequencies for the cgraph_edges for each of the calls
80 starting at FIRST for their new position within BB. */
82 static void
83 update_call_edge_frequencies (gimple_seq_node first, basic_block bb)
85 struct cgraph_node *cfun_node = NULL;
86 gimple_seq_node n;
88 for (n = first; n ; n = n->next)
89 if (is_gimple_call (n))
91 struct cgraph_edge *e;
93 /* These function calls are expensive enough that we want
94 to avoid calling them if we never see any calls. */
95 if (cfun_node == NULL)
96 cfun_node = cgraph_node::get (current_function_decl);
98 e = cfun_node->get_edge (n);
99 if (e != NULL)
100 e->count = bb->count;
104 /* Insert the sequence delimited by nodes FIRST and LAST before
105 iterator I. M specifies how to update iterator I after insertion
106 (see enum gsi_iterator_update).
108 This routine assumes that there is a forward and backward path
109 between FIRST and LAST (i.e., they are linked in a doubly-linked
110 list). Additionally, if FIRST == LAST, this routine will properly
111 insert a single node. */
113 static void
114 gsi_insert_seq_nodes_before (gimple_stmt_iterator *i,
115 gimple_seq_node first,
116 gimple_seq_node last,
117 enum gsi_iterator_update mode)
119 basic_block bb;
120 gimple_seq_node cur = i->ptr;
122 gcc_assert (!cur || cur->prev);
124 if ((bb = gsi_bb (*i)) != NULL)
125 update_bb_for_stmts (first, last, bb);
127 /* Link SEQ before CUR in the sequence. */
128 if (cur)
130 first->prev = cur->prev;
131 if (first->prev->next)
132 first->prev->next = first;
133 else
134 gimple_seq_set_first (i->seq, first);
135 last->next = cur;
136 cur->prev = last;
138 else
140 gimple_seq_node itlast = gimple_seq_last (*i->seq);
142 /* If CUR is NULL, we link at the end of the sequence (this case happens
143 when gsi_after_labels is called for a basic block that contains only
144 labels, so it returns an iterator after the end of the block, and
145 we need to insert before it; it might be cleaner to add a flag to the
146 iterator saying whether we are at the start or end of the list). */
147 last->next = NULL;
148 if (itlast)
150 first->prev = itlast;
151 itlast->next = first;
153 else
154 gimple_seq_set_first (i->seq, first);
155 gimple_seq_set_last (i->seq, last);
158 /* Update the iterator, if requested. */
159 switch (mode)
161 case GSI_NEW_STMT:
162 case GSI_CONTINUE_LINKING:
163 i->ptr = first;
164 break;
165 case GSI_SAME_STMT:
166 break;
167 default:
168 gcc_unreachable ();
173 /* Inserts the sequence of statements SEQ before the statement pointed
174 by iterator I. MODE indicates what to do with the iterator after
175 insertion (see enum gsi_iterator_update).
177 This function does not scan for new operands. It is provided for
178 the use of the gimplifier, which manipulates statements for which
179 def/use information has not yet been constructed. Most callers
180 should use gsi_insert_seq_before. */
182 void
183 gsi_insert_seq_before_without_update (gimple_stmt_iterator *i, gimple_seq seq,
184 enum gsi_iterator_update mode)
186 gimple_seq_node first, last;
188 if (seq == NULL)
189 return;
191 /* Don't allow inserting a sequence into itself. */
192 gcc_assert (seq != *i->seq);
194 first = gimple_seq_first (seq);
195 last = gimple_seq_last (seq);
197 /* Empty sequences need no work. */
198 if (!first || !last)
200 gcc_assert (first == last);
201 return;
204 gsi_insert_seq_nodes_before (i, first, last, mode);
208 /* Inserts the sequence of statements SEQ before the statement pointed
209 by iterator I. MODE indicates what to do with the iterator after
210 insertion (see enum gsi_iterator_update). Scan the statements in SEQ
211 for new operands. */
213 void
214 gsi_insert_seq_before (gimple_stmt_iterator *i, gimple_seq seq,
215 enum gsi_iterator_update mode)
217 update_modified_stmts (seq);
218 gsi_insert_seq_before_without_update (i, seq, mode);
222 /* Insert the sequence delimited by nodes FIRST and LAST after
223 iterator I. M specifies how to update iterator I after insertion
224 (see enum gsi_iterator_update).
226 This routine assumes that there is a forward and backward path
227 between FIRST and LAST (i.e., they are linked in a doubly-linked
228 list). Additionally, if FIRST == LAST, this routine will properly
229 insert a single node. */
231 static void
232 gsi_insert_seq_nodes_after (gimple_stmt_iterator *i,
233 gimple_seq_node first,
234 gimple_seq_node last,
235 enum gsi_iterator_update m)
237 basic_block bb;
238 gimple_seq_node cur = i->ptr;
240 gcc_assert (!cur || cur->prev);
242 /* If the iterator is inside a basic block, we need to update the
243 basic block information for all the nodes between FIRST and LAST. */
244 if ((bb = gsi_bb (*i)) != NULL)
245 update_bb_for_stmts (first, last, bb);
247 /* Link SEQ after CUR. */
248 if (cur)
250 last->next = cur->next;
251 if (last->next)
253 last->next->prev = last;
255 else
256 gimple_seq_set_last (i->seq, last);
257 first->prev = cur;
258 cur->next = first;
260 else
262 gcc_assert (!gimple_seq_last (*i->seq));
263 last->next = NULL;
264 gimple_seq_set_first (i->seq, first);
265 gimple_seq_set_last (i->seq, last);
268 /* Update the iterator, if requested. */
269 switch (m)
271 case GSI_NEW_STMT:
272 i->ptr = first;
273 break;
274 case GSI_CONTINUE_LINKING:
275 i->ptr = last;
276 break;
277 case GSI_SAME_STMT:
278 gcc_assert (cur);
279 break;
280 default:
281 gcc_unreachable ();
286 /* Links sequence SEQ after the statement pointed-to by iterator I.
287 MODE is as in gsi_insert_after.
289 This function does not scan for new operands. It is provided for
290 the use of the gimplifier, which manipulates statements for which
291 def/use information has not yet been constructed. Most callers
292 should use gsi_insert_seq_after. */
294 void
295 gsi_insert_seq_after_without_update (gimple_stmt_iterator *i, gimple_seq seq,
296 enum gsi_iterator_update mode)
298 gimple_seq_node first, last;
300 if (seq == NULL)
301 return;
303 /* Don't allow inserting a sequence into itself. */
304 gcc_assert (seq != *i->seq);
306 first = gimple_seq_first (seq);
307 last = gimple_seq_last (seq);
309 /* Empty sequences need no work. */
310 if (!first || !last)
312 gcc_assert (first == last);
313 return;
316 gsi_insert_seq_nodes_after (i, first, last, mode);
320 /* Links sequence SEQ after the statement pointed-to by iterator I.
321 MODE is as in gsi_insert_after. Scan the statements in SEQ
322 for new operands. */
324 void
325 gsi_insert_seq_after (gimple_stmt_iterator *i, gimple_seq seq,
326 enum gsi_iterator_update mode)
328 update_modified_stmts (seq);
329 gsi_insert_seq_after_without_update (i, seq, mode);
333 /* Move all statements in the sequence after I to a new sequence.
334 Return this new sequence. */
336 gimple_seq
337 gsi_split_seq_after (gimple_stmt_iterator i)
339 gimple_seq_node cur, next;
340 gimple_seq *pold_seq, new_seq;
342 cur = i.ptr;
344 /* How can we possibly split after the end, or before the beginning? */
345 gcc_assert (cur && cur->next);
346 next = cur->next;
348 pold_seq = i.seq;
350 gimple_seq_set_first (&new_seq, next);
351 gimple_seq_set_last (&new_seq, gimple_seq_last (*pold_seq));
352 gimple_seq_set_last (pold_seq, cur);
353 cur->next = NULL;
355 return new_seq;
359 /* Set the statement to which GSI points to STMT. This only updates
360 the iterator and the gimple sequence, it doesn't do the bookkeeping
361 of gsi_replace. */
363 void
364 gsi_set_stmt (gimple_stmt_iterator *gsi, gimple *stmt)
366 gimple *orig_stmt = gsi_stmt (*gsi);
367 gimple *prev, *next;
369 stmt->next = next = orig_stmt->next;
370 stmt->prev = prev = orig_stmt->prev;
371 /* Note how we don't clear next/prev of orig_stmt. This is so that
372 copies of *GSI our callers might still hold (to orig_stmt)
373 can be advanced as if they too were replaced. */
374 if (prev->next)
375 prev->next = stmt;
376 else
377 gimple_seq_set_first (gsi->seq, stmt);
378 if (next)
379 next->prev = stmt;
380 else
381 gimple_seq_set_last (gsi->seq, stmt);
383 gsi->ptr = stmt;
387 /* Move all statements in the sequence before I to a new sequence.
388 Return this new sequence. I is set to the head of the new list. */
390 void
391 gsi_split_seq_before (gimple_stmt_iterator *i, gimple_seq *pnew_seq)
393 gimple_seq_node cur, prev;
394 gimple_seq old_seq;
396 cur = i->ptr;
398 /* How can we possibly split after the end? */
399 gcc_assert (cur);
400 prev = cur->prev;
402 old_seq = *i->seq;
403 if (!prev->next)
404 *i->seq = NULL;
405 i->seq = pnew_seq;
407 /* Set the limits on NEW_SEQ. */
408 gimple_seq_set_first (pnew_seq, cur);
409 gimple_seq_set_last (pnew_seq, gimple_seq_last (old_seq));
411 /* Cut OLD_SEQ before I. */
412 gimple_seq_set_last (&old_seq, prev);
413 if (prev->next)
414 prev->next = NULL;
418 /* Replace the statement pointed-to by GSI to STMT. If UPDATE_EH_INFO
419 is true, the exception handling information of the original
420 statement is moved to the new statement. Assignments must only be
421 replaced with assignments to the same LHS. Returns whether EH edge
422 cleanup is required. */
424 bool
425 gsi_replace (gimple_stmt_iterator *gsi, gimple *stmt, bool update_eh_info)
427 gimple *orig_stmt = gsi_stmt (*gsi);
428 bool require_eh_edge_purge = false;
430 if (stmt == orig_stmt)
431 return false;
433 gcc_assert (!gimple_has_lhs (orig_stmt) || !gimple_has_lhs (stmt)
434 || gimple_get_lhs (orig_stmt) == gimple_get_lhs (stmt));
436 gimple_set_location (stmt, gimple_location (orig_stmt));
437 gimple_set_bb (stmt, gsi_bb (*gsi));
439 /* Preserve EH region information from the original statement, if
440 requested by the caller. */
441 if (update_eh_info)
442 require_eh_edge_purge = maybe_clean_or_replace_eh_stmt (orig_stmt, stmt);
444 gimple_duplicate_stmt_histograms (cfun, stmt, cfun, orig_stmt);
446 /* Free all the data flow information for ORIG_STMT. */
447 gimple_set_bb (orig_stmt, NULL);
448 gimple_remove_stmt_histograms (cfun, orig_stmt);
449 delink_stmt_imm_use (orig_stmt);
451 gsi_set_stmt (gsi, stmt);
452 gimple_set_modified (stmt, true);
453 update_modified_stmt (stmt);
454 return require_eh_edge_purge;
458 /* Replace the statement pointed-to by GSI with the sequence SEQ.
459 If UPDATE_EH_INFO is true, the exception handling information of
460 the original statement is moved to the last statement of the new
461 sequence. If the old statement is an assignment, then so must
462 be the last statement of the new sequence, and they must have the
463 same LHS. */
465 void
466 gsi_replace_with_seq (gimple_stmt_iterator *gsi, gimple_seq seq,
467 bool update_eh_info)
469 gimple_stmt_iterator seqi;
470 gimple *last;
471 if (gimple_seq_empty_p (seq))
473 gsi_remove (gsi, true);
474 return;
476 seqi = gsi_last (seq);
477 last = gsi_stmt (seqi);
478 gsi_remove (&seqi, false);
479 gsi_insert_seq_before (gsi, seq, GSI_SAME_STMT);
480 gsi_replace (gsi, last, update_eh_info);
484 /* Insert statement STMT before the statement pointed-to by iterator I.
485 M specifies how to update iterator I after insertion (see enum
486 gsi_iterator_update).
488 This function does not scan for new operands. It is provided for
489 the use of the gimplifier, which manipulates statements for which
490 def/use information has not yet been constructed. Most callers
491 should use gsi_insert_before. */
493 void
494 gsi_insert_before_without_update (gimple_stmt_iterator *i, gimple *stmt,
495 enum gsi_iterator_update m)
497 gsi_insert_seq_nodes_before (i, stmt, stmt, m);
500 /* Insert statement STMT before the statement pointed-to by iterator I.
501 Update STMT's basic block and scan it for new operands. M
502 specifies how to update iterator I after insertion (see enum
503 gsi_iterator_update). */
505 void
506 gsi_insert_before (gimple_stmt_iterator *i, gimple *stmt,
507 enum gsi_iterator_update m)
509 update_modified_stmt (stmt);
510 gsi_insert_before_without_update (i, stmt, m);
514 /* Insert statement STMT after the statement pointed-to by iterator I.
515 M specifies how to update iterator I after insertion (see enum
516 gsi_iterator_update).
518 This function does not scan for new operands. It is provided for
519 the use of the gimplifier, which manipulates statements for which
520 def/use information has not yet been constructed. Most callers
521 should use gsi_insert_after. */
523 void
524 gsi_insert_after_without_update (gimple_stmt_iterator *i, gimple *stmt,
525 enum gsi_iterator_update m)
527 gsi_insert_seq_nodes_after (i, stmt, stmt, m);
531 /* Insert statement STMT after the statement pointed-to by iterator I.
532 Update STMT's basic block and scan it for new operands. M
533 specifies how to update iterator I after insertion (see enum
534 gsi_iterator_update). */
536 void
537 gsi_insert_after (gimple_stmt_iterator *i, gimple *stmt,
538 enum gsi_iterator_update m)
540 update_modified_stmt (stmt);
541 gsi_insert_after_without_update (i, stmt, m);
545 /* Remove the current stmt from the sequence. The iterator is updated
546 to point to the next statement.
548 REMOVE_PERMANENTLY is true when the statement is going to be removed
549 from the IL and not reinserted elsewhere. In that case we remove the
550 statement pointed to by iterator I from the EH tables, and free its
551 operand caches. Otherwise we do not modify this information. Returns
552 true whether EH edge cleanup is required. */
554 bool
555 gsi_remove (gimple_stmt_iterator *i, bool remove_permanently)
557 gimple_seq_node cur, next, prev;
558 gimple *stmt = gsi_stmt (*i);
559 bool require_eh_edge_purge = false;
561 if (gimple_code (stmt) != GIMPLE_PHI)
562 insert_debug_temps_for_defs (i);
564 /* Free all the data flow information for STMT. */
565 gimple_set_bb (stmt, NULL);
566 delink_stmt_imm_use (stmt);
567 gimple_set_modified (stmt, true);
569 if (remove_permanently)
571 require_eh_edge_purge = remove_stmt_from_eh_lp (stmt);
572 gimple_remove_stmt_histograms (cfun, stmt);
575 /* Update the iterator and re-wire the links in I->SEQ. */
576 cur = i->ptr;
577 next = cur->next;
578 prev = cur->prev;
579 /* See gsi_set_stmt for why we don't reset prev/next of STMT. */
581 if (next)
582 /* Cur is not last. */
583 next->prev = prev;
584 else if (prev->next)
585 /* Cur is last but not first. */
586 gimple_seq_set_last (i->seq, prev);
588 if (prev->next)
589 /* Cur is not first. */
590 prev->next = next;
591 else
592 /* Cur is first. */
593 *i->seq = next;
595 i->ptr = next;
597 return require_eh_edge_purge;
601 /* Finds iterator for STMT. */
603 gimple_stmt_iterator
604 gsi_for_stmt (gimple *stmt)
606 gimple_stmt_iterator i;
607 basic_block bb = gimple_bb (stmt);
609 if (gimple_code (stmt) == GIMPLE_PHI)
610 i = gsi_start_phis (bb);
611 else
612 i = gsi_start_bb (bb);
614 i.ptr = stmt;
615 return i;
618 /* Finds iterator for PHI. */
620 gphi_iterator
621 gsi_for_phi (gphi *phi)
623 gphi_iterator i;
624 basic_block bb = gimple_bb (phi);
626 i = gsi_start_phis (bb);
627 i.ptr = phi;
629 return i;
632 /* Move the statement at FROM so it comes right after the statement at TO. */
634 void
635 gsi_move_after (gimple_stmt_iterator *from, gimple_stmt_iterator *to)
637 gimple *stmt = gsi_stmt (*from);
638 gsi_remove (from, false);
640 /* We must have GSI_NEW_STMT here, as gsi_move_after is sometimes used to
641 move statements to an empty block. */
642 gsi_insert_after (to, stmt, GSI_NEW_STMT);
646 /* Move the statement at FROM so it comes right before the statement
647 at TO. */
649 void
650 gsi_move_before (gimple_stmt_iterator *from, gimple_stmt_iterator *to)
652 gimple *stmt = gsi_stmt (*from);
653 gsi_remove (from, false);
655 /* For consistency with gsi_move_after, it might be better to have
656 GSI_NEW_STMT here; however, that breaks several places that expect
657 that TO does not change. */
658 gsi_insert_before (to, stmt, GSI_SAME_STMT);
662 /* Move the statement at FROM to the end of basic block BB. */
664 void
665 gsi_move_to_bb_end (gimple_stmt_iterator *from, basic_block bb)
667 gimple_stmt_iterator last = gsi_last_bb (bb);
668 gcc_checking_assert (gsi_bb (last) == bb);
670 /* Have to check gsi_end_p because it could be an empty block. */
671 if (!gsi_end_p (last) && is_ctrl_stmt (gsi_stmt (last)))
672 gsi_move_before (from, &last);
673 else
674 gsi_move_after (from, &last);
678 /* Add STMT to the pending list of edge E. No actual insertion is
679 made until a call to gsi_commit_edge_inserts () is made. */
681 void
682 gsi_insert_on_edge (edge e, gimple *stmt)
684 gimple_seq_add_stmt (&PENDING_STMT (e), stmt);
687 /* Add the sequence of statements SEQ to the pending list of edge E.
688 No actual insertion is made until a call to gsi_commit_edge_inserts
689 is made. */
691 void
692 gsi_insert_seq_on_edge (edge e, gimple_seq seq)
694 gimple_seq_add_seq (&PENDING_STMT (e), seq);
697 /* Return a new iterator pointing to the first statement in sequence of
698 statements on edge E. Such statements need to be subsequently moved into a
699 basic block by calling gsi_commit_edge_inserts. */
701 gimple_stmt_iterator
702 gsi_start_edge (edge e)
704 return gsi_start (PENDING_STMT (e));
707 /* Insert the statement pointed-to by GSI into edge E. Every attempt
708 is made to place the statement in an existing basic block, but
709 sometimes that isn't possible. When it isn't possible, the edge is
710 split and the statement is added to the new block.
712 In all cases, the returned *GSI points to the correct location. The
713 return value is true if insertion should be done after the location,
714 or false if it should be done before the location. If a new basic block
715 has to be created, it is stored in *NEW_BB. */
717 static bool
718 gimple_find_edge_insert_loc (edge e, gimple_stmt_iterator *gsi,
719 basic_block *new_bb)
721 basic_block dest, src;
722 gimple *tmp;
724 dest = e->dest;
726 /* If the destination has one predecessor which has no PHI nodes,
727 insert there. Except for the exit block.
729 The requirement for no PHI nodes could be relaxed. Basically we
730 would have to examine the PHIs to prove that none of them used
731 the value set by the statement we want to insert on E. That
732 hardly seems worth the effort. */
733 restart:
734 if (single_pred_p (dest)
735 && gimple_seq_empty_p (phi_nodes (dest))
736 && dest != EXIT_BLOCK_PTR_FOR_FN (cfun))
738 *gsi = gsi_start_bb (dest);
739 if (gsi_end_p (*gsi))
740 return true;
742 /* Make sure we insert after any leading labels. */
743 tmp = gsi_stmt (*gsi);
744 while (gimple_code (tmp) == GIMPLE_LABEL)
746 gsi_next (gsi);
747 if (gsi_end_p (*gsi))
748 break;
749 tmp = gsi_stmt (*gsi);
752 if (gsi_end_p (*gsi))
754 *gsi = gsi_last_bb (dest);
755 return true;
757 else
758 return false;
761 /* If the source has one successor, the edge is not abnormal and
762 the last statement does not end a basic block, insert there.
763 Except for the entry block. */
764 src = e->src;
765 if ((e->flags & EDGE_ABNORMAL) == 0
766 && single_succ_p (src)
767 && src != ENTRY_BLOCK_PTR_FOR_FN (cfun))
769 *gsi = gsi_last_bb (src);
770 if (gsi_end_p (*gsi))
771 return true;
773 tmp = gsi_stmt (*gsi);
774 if (!stmt_ends_bb_p (tmp))
775 return true;
777 switch (gimple_code (tmp))
779 case GIMPLE_RETURN:
780 case GIMPLE_RESX:
781 return false;
782 default:
783 break;
787 /* Otherwise, create a new basic block, and split this edge. */
788 dest = split_edge (e);
789 if (new_bb)
790 *new_bb = dest;
791 e = single_pred_edge (dest);
792 goto restart;
796 /* Similar to gsi_insert_on_edge+gsi_commit_edge_inserts. If a new
797 block has to be created, it is returned. */
799 basic_block
800 gsi_insert_on_edge_immediate (edge e, gimple *stmt)
802 gimple_stmt_iterator gsi;
803 basic_block new_bb = NULL;
804 bool ins_after;
806 gcc_assert (!PENDING_STMT (e));
808 ins_after = gimple_find_edge_insert_loc (e, &gsi, &new_bb);
810 update_call_edge_frequencies (stmt, gsi.bb);
812 if (ins_after)
813 gsi_insert_after (&gsi, stmt, GSI_NEW_STMT);
814 else
815 gsi_insert_before (&gsi, stmt, GSI_NEW_STMT);
817 return new_bb;
820 /* Insert STMTS on edge E. If a new block has to be created, it
821 is returned. */
823 basic_block
824 gsi_insert_seq_on_edge_immediate (edge e, gimple_seq stmts)
826 gimple_stmt_iterator gsi;
827 basic_block new_bb = NULL;
828 bool ins_after;
830 gcc_assert (!PENDING_STMT (e));
832 ins_after = gimple_find_edge_insert_loc (e, &gsi, &new_bb);
833 update_call_edge_frequencies (gimple_seq_first (stmts), gsi.bb);
835 if (ins_after)
836 gsi_insert_seq_after (&gsi, stmts, GSI_NEW_STMT);
837 else
838 gsi_insert_seq_before (&gsi, stmts, GSI_NEW_STMT);
840 return new_bb;
843 /* This routine will commit all pending edge insertions, creating any new
844 basic blocks which are necessary. */
846 void
847 gsi_commit_edge_inserts (void)
849 basic_block bb;
850 edge e;
851 edge_iterator ei;
853 gsi_commit_one_edge_insert (single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun)),
854 NULL);
856 FOR_EACH_BB_FN (bb, cfun)
857 FOR_EACH_EDGE (e, ei, bb->succs)
858 gsi_commit_one_edge_insert (e, NULL);
862 /* Commit insertions pending at edge E. If a new block is created, set NEW_BB
863 to this block, otherwise set it to NULL. */
865 void
866 gsi_commit_one_edge_insert (edge e, basic_block *new_bb)
868 if (new_bb)
869 *new_bb = NULL;
871 if (PENDING_STMT (e))
873 gimple_stmt_iterator gsi;
874 gimple_seq seq = PENDING_STMT (e);
875 bool ins_after;
877 PENDING_STMT (e) = NULL;
879 ins_after = gimple_find_edge_insert_loc (e, &gsi, new_bb);
880 update_call_edge_frequencies (gimple_seq_first (seq), gsi.bb);
882 if (ins_after)
883 gsi_insert_seq_after (&gsi, seq, GSI_NEW_STMT);
884 else
885 gsi_insert_seq_before (&gsi, seq, GSI_NEW_STMT);
889 /* Returns iterator at the start of the list of phi nodes of BB. */
891 gphi_iterator
892 gsi_start_phis (basic_block bb)
894 gimple_seq *pseq = phi_nodes_ptr (bb);
896 /* Adapted from gsi_start_1. */
897 gphi_iterator i;
899 i.ptr = gimple_seq_first (*pseq);
900 i.seq = pseq;
901 i.bb = i.ptr ? gimple_bb (i.ptr) : NULL;
903 return i;