Next: Adding a new GIMPLE statement code, Previous: GIMPLE sequences, Up: GIMPLE [Contents][Index]
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. If SEQ
is empty, the iterator’s basic block is NULL
.
Use gsi_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
. If SEQ
is empty, the iterator’s basic block is
NULL
. Use gsi_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 at the end of I
.
Return TRUE
if we’re one statement before the end of I
.
Advance the iterator to the next gimple statement.
Advance the iterator to the previous gimple statement.
Return the current stmt.
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 iterator I
from the EH
tables. Otherwise we do not modify the EH
tables. Generally,
REMOVE_EH_INFO
should be true when the statement is going to be
removed from the IL
and not reinserted elsewhere.
Links the sequence of statements SEQ
before the statement pointed
by iterator I
. MODE
indicates what to do with the iterator
after insertion (see enum gsi_iterator_update
above).
Links statement G
before the statement pointed-to by iterator I
.
Updates iterator I
according to MODE
.
Links sequence SEQ
after the statement pointed-to by iterator I
.
MODE
is as in gsi_insert_after
.
Links statement G
after the statement pointed-to by iterator I
.
MODE
is as in gsi_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
to STMT
. If UPDATE_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 iterator
I
, update STMT
’s basic block and scan it for new operands. MODE
specifies how to update iterator I
after insertion (see enum
gsi_iterator_update
).
Like gsi_insert_before
, but for all the statements in SEQ
.
Insert statement STMT
after the statement pointed-to by iterator
I
, update STMT
’s basic block and scan it for new operands. MODE
specifies how to update iterator I
after insertion (see enum
gsi_iterator_update
).
Like gsi_insert_after
, but for all the statements in SEQ
.
Finds iterator for STMT
.
Move the statement at FROM
so it comes right after the statement
at TO
.
Move the statement at FROM
so it comes right before the statement
at TO
.
Move the statement at FROM
to the end of basic block BB
.
Add STMT
to the pending list of edge E
. No actual insertion is
made until a call to gsi_commit_edge_inserts
() is made.
Add the sequence of statements in SEQ
to the pending list of edge
E
. No actual insertion is made until a call to
gsi_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.
Commit insertions pending at edge E
. If a new block is created,
set NEW_BB
to this block, otherwise set it to NULL
.
This routine will commit all pending edge insertions, creating any new basic blocks which are necessary.
Next: Adding a new GIMPLE statement code, Previous: GIMPLE sequences, Up: GIMPLE [Contents][Index]