Next: Adding a new GIMPLE statement code, Previous: GIMPLE sequences, Up: GIMPLE
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. IfSEQis empty, the iterator's basic block isNULL. Usegsi_start_bbinstead 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. IfSEQis empty, the iterator's basic block isNULL. Usegsi_last_bbinstead 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
TRUEif 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_INFOis true we remove the statement pointed to by iteratorIfrom theEHtables. Otherwise we do not modify theEHtables. Generally,REMOVE_EH_INFOshould be true when the statement is going to be removed from theILand not reinserted elsewhere.
Links the sequence of statements
SEQbefore the statement pointed by iteratorI.MODEindicates what to do with the iterator after insertion (seeenum gsi_iterator_updateabove).
Links statement
Gbefore the statement pointed-to by iteratorI. Updates iteratorIaccording toMODE.
Links sequence
SEQafter the statement pointed-to by iteratorI.MODEis as ingsi_insert_after.
Links statement
Gafter the statement pointed-to by iteratorI.MODEis as ingsi_insert_after.
Move all statements in the sequence after
Ito a new sequence. Return this new sequence.
Move all statements in the sequence before
Ito a new sequence. Return this new sequence.
Replace the statement pointed-to by
ItoSTMT. IfUPDATE_EH_INFOis true, the exception handling information of the original statement is moved to the new statement.
Insert statement
STMTbefore the statement pointed-to by iteratorI, updateSTMT's basic block and scan it for new operands.MODEspecifies how to update iteratorIafter insertion (see enumgsi_iterator_update).
Like
gsi_insert_before, but for all the statements inSEQ.
Insert statement
STMTafter the statement pointed-to by iteratorI, updateSTMT's basic block and scan it for new operands.MODEspecifies how to update iteratorIafter insertion (see enumgsi_iterator_update).
Like
gsi_insert_after, but for all the statements inSEQ.
Move the statement at
FROMso it comes right after the statement atTO.
Move the statement at
FROMso it comes right before the statement atTO.
Move the statement at
FROMto the end of basic blockBB.
Add
STMTto 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
SEQto 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.