Sequence iterators are convenience constructs for iterating
through statements in a sequence. Given a sequence SEQ
, here is
a typical use of gimple sequence iterators:
gimple_stmt_iterator gsi;
for (gsi = gsi_start (seq); !gsi_end_p (gsi); gsi_next (&gsi))
{
gimple g = gsi_stmt (gsi);
/* Do something with gimple statement G
. */
}
Backward iterations are possible:
for (gsi = gsi_last (seq); !gsi_end_p (gsi); gsi_prev (&gsi))
Forward and backward iterations on basic blocks are possible with
gsi_start_bb
and gsi_last_bb
.
In the documentation below we sometimes refer to enum
gsi_iterator_update
. The valid options for this enumeration are:
GSI_NEW_STMT
Only valid when a single statement is added. Move the iterator to it.
GSI_SAME_STMT
Leave the iterator at the same statement.
GSI_CONTINUE_LINKING
Move iterator to whatever position is suitable for linking other
statements in the same direction.
Below is a list of the functions used to manipulate and use statement iterators.
Return a new iterator pointing to the sequence
SEQ
's first statement. IfSEQ
is empty, the iterator's basic block isNULL
. Usegsi_start_bb
instead when the iterator needs to always have the correct basic block set.
Return a new iterator pointing to the first statement in basic block
BB
.
Return a new iterator initially pointing to the last statement of sequence
SEQ
. IfSEQ
is empty, the iterator's basic block isNULL
. Usegsi_last_bb
instead when the iterator needs to always have the correct basic block set.
Return a new iterator pointing to the last statement in basic block
BB
.
Return
TRUE
if we're one statement before the end ofI
.
Advance the iterator to the next gimple statement.
Advance the iterator to the previous gimple statement.
Return a block statement iterator that points to the first non-label statement in block
BB
.
Return a pointer to the current stmt.
Return the basic block associated with this iterator.
Return the sequence associated with this iterator.
Remove the current stmt from the sequence. The iterator is updated to point to the next statement. When
REMOVE_EH_INFO
is true we remove the statement pointed to by iteratorI
from theEH
tables. Otherwise we do not modify theEH
tables. Generally,REMOVE_EH_INFO
should be true when the statement is going to be removed from theIL
and not reinserted elsewhere.
Links the sequence of statements
SEQ
before the statement pointed by iteratorI
.MODE
indicates what to do with the iterator after insertion (seeenum gsi_iterator_update
above).
Links statement
G
before the statement pointed-to by iteratorI
. Updates iteratorI
according toMODE
.
Links sequence
SEQ
after the statement pointed-to by iteratorI
.MODE
is as ingsi_insert_after
.
Links statement
G
after the statement pointed-to by iteratorI
.MODE
is as ingsi_insert_after
.
Move all statements in the sequence after
I
to a new sequence. Return this new sequence.
Move all statements in the sequence before
I
to a new sequence. Return this new sequence.
Replace the statement pointed-to by
I
toSTMT
. IfUPDATE_EH_INFO
is true, the exception handling information of the original statement is moved to the new statement.
Insert statement
STMT
before the statement pointed-to by iteratorI
, updateSTMT
's basic block and scan it for new operands.MODE
specifies how to update iteratorI
after insertion (see enumgsi_iterator_update
).
Like
gsi_insert_before
, but for all the statements inSEQ
.
Insert statement
STMT
after the statement pointed-to by iteratorI
, updateSTMT
's basic block and scan it for new operands.MODE
specifies how to update iteratorI
after insertion (see enumgsi_iterator_update
).
Like
gsi_insert_after
, but for all the statements inSEQ
.
Move the statement at
FROM
so it comes right after the statement atTO
.
Move the statement at
FROM
so it comes right before the statement atTO
.
Move the statement at
FROM
to the end of basic blockBB
.
Add
STMT
to the pending list of edgeE
. No actual insertion is made until a call togsi_commit_edge_inserts
() is made.
Add the sequence of statements in
SEQ
to the pending list of edgeE
. No actual insertion is made until a call togsi_commit_edge_inserts
() is made.
Similar to
gsi_insert_on_edge
+gsi_commit_edge_inserts
. If a new block has to be created, it is returned.