Next:Adding a new GIMPLE statement code, Previous:GIMPLE sequences, Up:GIMPLE [Contents][Index]
Sequence iterators are convenience constructs for iteratingthrough statements in a sequence. Given a sequenceSEQ, here isa 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 statementG. */ }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 withgsi_start_bb andgsi_last_bb.
In the documentation below we sometimes refer to enumgsi_iterator_update. The valid options for this enumeration are:
GSI_NEW_STMTOnly valid when a single statement is added. Move the iterator to it.GSI_SAME_STMTLeave the iterator at the same statement.GSI_CONTINUE_LINKINGMove iterator to whatever position is suitable for linking otherstatements in the same direction.Below is a list of the functions used to manipulate and usestatement iterators.
gimple_stmt_iteratorgsi_start(gimple_seq seq) ¶Return a new iterator pointing to the sequenceSEQ’s firststatement. IfSEQ is empty, the iterator’s basic block isNULL.Usegsi_start_bb instead when the iterator needs to always havethe correct basic block set.
gimple_stmt_iteratorgsi_start_bb(basic_block bb) ¶Return a new iterator pointing to the first statement in basicblockBB.
gimple_stmt_iteratorgsi_last(gimple_seq seq) ¶Return a new iterator initially pointing to the last statement ofsequenceSEQ. IfSEQ is empty, the iterator’s basic block isNULL. Usegsi_last_bb instead when the iterator needs to alwayshave the correct basic block set.
gimple_stmt_iteratorgsi_last_bb(basic_block bb) ¶Return a new iterator pointing to the last statement in basicblockBB.
boolgsi_end_p(gimple_stmt_iterator i) ¶ReturnTRUE if at the end ofI.
boolgsi_one_before_end_p(gimple_stmt_iterator i) ¶ReturnTRUE if we’re one statement before the end ofI.
voidgsi_next(gimple_stmt_iterator *i) ¶Advance the iterator to the next gimple statement.
voidgsi_prev(gimple_stmt_iterator *i) ¶Advance the iterator to the previous gimple statement.
gimplegsi_stmt(gimple_stmt_iterator i) ¶Return the current stmt.
gimple_stmt_iteratorgsi_after_labels(basic_block bb) ¶Return a block statement iterator that points to the firstnon-label statement in blockBB.
gimple *gsi_stmt_ptr(gimple_stmt_iterator *i) ¶Return a pointer to the current stmt.
basic_blockgsi_bb(gimple_stmt_iterator i) ¶Return the basic block associated with this iterator.
gimple_seqgsi_seq(gimple_stmt_iterator i) ¶Return the sequence associated with this iterator.
voidgsi_remove(gimple_stmt_iterator *i, bool remove_eh_info) ¶Remove the current stmt from the sequence. The iterator isupdated to point to the next statement. WhenREMOVE_EH_INFO istrue we remove the statement pointed to by iteratorI from theEHtables. Otherwise we do not modify theEH tables. Generally,REMOVE_EH_INFO should be true when the statement is going to beremoved from theIL and not reinserted elsewhere.
voidgsi_link_seq_before(gimple_stmt_iterator *i, gimple_seq seq, enum gsi_iterator_update mode) ¶Links the sequence of statementsSEQ before the statement pointedby iteratorI.MODE indicates what to do with the iteratorafter insertion (seeenum gsi_iterator_update above).
voidgsi_link_before(gimple_stmt_iterator *i, gimple g, enum gsi_iterator_update mode) ¶Links statementG before the statement pointed-to by iteratorI.Updates iteratorI according toMODE.
voidgsi_link_seq_after(gimple_stmt_iterator *i, gimple_seq seq, enum gsi_iterator_update mode) ¶Links sequenceSEQ after the statement pointed-to by iteratorI.MODE is as ingsi_insert_after.
voidgsi_link_after(gimple_stmt_iterator *i, gimple g, enum gsi_iterator_update mode) ¶Links statementG after the statement pointed-to by iteratorI.MODE is as ingsi_insert_after.
gimple_seqgsi_split_seq_after(gimple_stmt_iterator i) ¶Move all statements in the sequence afterI to a new sequence.Return this new sequence.
gimple_seqgsi_split_seq_before(gimple_stmt_iterator *i) ¶Move all statements in the sequence beforeI to a new sequence.Return this new sequence.
voidgsi_replace(gimple_stmt_iterator *i, gimple stmt, bool update_eh_info) ¶Replace the statement pointed-to byI toSTMT. IfUPDATE_EH_INFOis true, the exception handling information of the originalstatement is moved to the new statement.
voidgsi_insert_before(gimple_stmt_iterator *i, gimple stmt, enum gsi_iterator_update mode) ¶Insert statementSTMT before the statement pointed-to by iteratorI, updateSTMT’s basic block and scan it for new operands.MODEspecifies how to update iteratorI after insertion (see enumgsi_iterator_update).
voidgsi_insert_seq_before(gimple_stmt_iterator *i, gimple_seq seq, enum gsi_iterator_update mode) ¶Likegsi_insert_before, but for all the statements inSEQ.
voidgsi_insert_after(gimple_stmt_iterator *i, gimple stmt, enum gsi_iterator_update mode) ¶Insert statementSTMT after the statement pointed-to by iteratorI, updateSTMT’s basic block and scan it for new operands.MODEspecifies how to update iteratorI after insertion (see enumgsi_iterator_update).
voidgsi_insert_seq_after(gimple_stmt_iterator *i, gimple_seq seq, enum gsi_iterator_update mode) ¶Likegsi_insert_after, but for all the statements inSEQ.
gimple_stmt_iteratorgsi_for_stmt(gimple stmt) ¶Finds iterator forSTMT.
voidgsi_move_after(gimple_stmt_iterator *from, gimple_stmt_iterator *to) ¶Move the statement atFROM so it comes right after the statementatTO.
voidgsi_move_before(gimple_stmt_iterator *from, gimple_stmt_iterator *to) ¶Move the statement atFROM so it comes right before the statementatTO.
voidgsi_move_to_bb_end(gimple_stmt_iterator *from, basic_block bb) ¶Move the statement atFROM to the end of basic blockBB.
voidgsi_insert_on_edge(edge e, gimple stmt) ¶AddSTMT to the pending list of edgeE. No actual insertion ismade until a call togsi_commit_edge_inserts() is made.
voidgsi_insert_seq_on_edge(edge e, gimple_seq seq) ¶Add the sequence of statements inSEQ to the pending list of edgeE. No actual insertion is made until a call togsi_commit_edge_inserts() is made.
basic_blockgsi_insert_on_edge_immediate(edge e, gimple stmt) ¶Similar togsi_insert_on_edge+gsi_commit_edge_inserts. If a newblock has to be created, it is returned.
voidgsi_commit_one_edge_insert(edge e, basic_block *new_bb) ¶Commit insertions pending at edgeE. If a new block is created,setNEW_BB to this block, otherwise set it toNULL.
voidgsi_commit_edge_inserts(void) ¶This routine will commit all pending edge insertions, creatingany new basic blocks which are necessary.
Next:Adding a new GIMPLE statement code, Previous:GIMPLE sequences, Up:GIMPLE [Contents][Index]