[tuples] new gsi_split_seq* functions

Aldy Hernandez aldyh@redhat.com
Tue Aug 14 23:33:00 GMT 2007


New functions to split a sequence.  These are analogous to the
tsi_split* functions.

Committed.

	* gimple-iterator.c (gsi_split_seq_after): New.
	(gsi_split_seq_before): New.
	* gimple-iterator.h: Prototype above two functions.

Index: gimple-iterator.c
===================================================================
--- gimple-iterator.c	(revision 127493)
+++ gimple-iterator.c	(working copy)
@@ -202,3 +202,61 @@ gsi_delink (gimple_stmt_iterator *i)
 
   i->stmt = next;
 }
+
+
+/* Move all statements in the sequence after I to a new sequence.  I
+   itself is unchanged.  */
+
+gimple_seq
+gsi_split_seq_after (const gimple_stmt_iterator *i)
+{
+  gimple cur, next;
+  gimple_seq old_seq, new_seq;
+
+  cur = i->stmt;
+  /* How can we possibly split after the end, or before the beginning?  */
+  gcc_assert (cur);
+  next = gimple_next (cur);
+
+  old_seq = i->seq;
+  new_seq = (gimple_seq) ggc_alloc_cleared (sizeof (*new_seq));
+
+  gimple_seq_set_first (new_seq, next);
+  gimple_seq_set_last (new_seq, gimple_seq_last (old_seq));
+  gimple_seq_set_last (old_seq, cur);
+  set_gimple_next (cur, NULL);
+  set_gimple_prev (next, NULL);
+
+  return new_seq;
+}
+
+
+/* Move all statements in the sequence before I to a new sequence.  I
+   is set to the head of the new list.  */
+
+gimple_seq
+gsi_split_seq_before (gimple_stmt_iterator *i)
+{
+  gimple cur, prev;
+  gimple_seq old_seq, new_seq;
+
+  cur = i->stmt;
+  /* How can we possibly split after the end, or before the beginning?  */
+  gcc_assert (cur);
+  prev = gimple_prev (cur);
+
+  old_seq = i->seq;
+  new_seq = (gimple_seq) ggc_alloc_cleared (sizeof (*new_seq));
+  i->seq = new_seq;
+
+  gimple_seq_set_first (new_seq, cur);
+  gimple_seq_set_last (new_seq, gimple_seq_last (old_seq));
+  gimple_seq_set_last (old_seq, prev);
+  set_gimple_prev (cur, NULL);
+  if (prev)
+    set_gimple_next (prev, NULL);
+  else
+    gimple_seq_set_first (old_seq, NULL);
+
+  return new_seq;
+}
Index: gimple-iterator.h
===================================================================
--- gimple-iterator.h	(revision 127493)
+++ gimple-iterator.h	(working copy)
@@ -130,5 +130,7 @@ void gsi_link_seq_after (gimple_stmt_ite
 			 enum gsi_iterator_update);
 void gsi_link_after (gimple_stmt_iterator *, gimple, enum gsi_iterator_update);
 void gsi_delink (gimple_stmt_iterator *);
+gimple_seq gsi_split_seq_after (const gimple_stmt_iterator *);
+gimple_seq gsi_split_seq_before (gimple_stmt_iterator *);
 
 #endif /* GCC_SEQ_ITERATOR_H */



More information about the Gcc-patches mailing list