gccint: Sequence iterators

1 
1 12.10 Sequence iterators
1 ========================
1 
1 Sequence iterators are convenience constructs for iterating through
1 statements in a sequence.  Given a sequence 'SEQ', here is a typical use
1 of gimple sequence iterators:
1 
1      gimple_stmt_iterator gsi;
1 
1      for (gsi = gsi_start (seq); !gsi_end_p (gsi); gsi_next (&gsi))
1        {
1          gimple g = gsi_stmt (gsi);
1          /* Do something with gimple statement G.  */
1        }
1 
1  Backward iterations are possible:
1 
1              for (gsi = gsi_last (seq); !gsi_end_p (gsi); gsi_prev (&gsi))
1 
1  Forward and backward iterations on basic blocks are possible with
1 'gsi_start_bb' and 'gsi_last_bb'.
1 
1  In the documentation below we sometimes refer to enum
1 'gsi_iterator_update'.  The valid options for this enumeration are:
1 
1    * 'GSI_NEW_STMT' Only valid when a single statement is added.  Move
1      the iterator to it.
1 
1    * 'GSI_SAME_STMT' Leave the iterator at the same statement.
1 
1    * 'GSI_CONTINUE_LINKING' Move iterator to whatever position is
1      suitable for linking other statements in the same direction.
1 
1  Below is a list of the functions used to manipulate and use statement
1 iterators.
1 
1  -- GIMPLE function: gimple_stmt_iterator gsi_start (gimple_seq seq)
1      Return a new iterator pointing to the sequence 'SEQ''s first
1      statement.  If 'SEQ' is empty, the iterator's basic block is
1      'NULL'.  Use 'gsi_start_bb' instead when the iterator needs to
1      always have the correct basic block set.
1 
1  -- GIMPLE function: gimple_stmt_iterator gsi_start_bb (basic_block bb)
1      Return a new iterator pointing to the first statement in basic
1      block 'BB'.
1 
1  -- GIMPLE function: gimple_stmt_iterator gsi_last (gimple_seq seq)
1      Return a new iterator initially pointing to the last statement of
1      sequence 'SEQ'.  If 'SEQ' is empty, the iterator's basic block is
1      'NULL'.  Use 'gsi_last_bb' instead when the iterator needs to
1      always have the correct basic block set.
1 
1  -- GIMPLE function: gimple_stmt_iterator gsi_last_bb (basic_block bb)
1      Return a new iterator pointing to the last statement in basic block
1      'BB'.
1 
1  -- GIMPLE function: bool gsi_end_p (gimple_stmt_iterator i)
1      Return 'TRUE' if at the end of 'I'.
1 
1  -- GIMPLE function: bool gsi_one_before_end_p (gimple_stmt_iterator i)
1      Return 'TRUE' if we're one statement before the end of 'I'.
1 
1  -- GIMPLE function: void gsi_next (gimple_stmt_iterator *i)
1      Advance the iterator to the next gimple statement.
1 
1  -- GIMPLE function: void gsi_prev (gimple_stmt_iterator *i)
1      Advance the iterator to the previous gimple statement.
1 
1  -- GIMPLE function: gimple gsi_stmt (gimple_stmt_iterator i)
1      Return the current stmt.
1 
1  -- GIMPLE function: gimple_stmt_iterator gsi_after_labels (basic_block
1           bb)
1      Return a block statement iterator that points to the first
1      non-label statement in block 'BB'.
1 
1  -- GIMPLE function: gimple * gsi_stmt_ptr (gimple_stmt_iterator *i)
1      Return a pointer to the current stmt.
1 
1  -- GIMPLE function: basic_block gsi_bb (gimple_stmt_iterator i)
1      Return the basic block associated with this iterator.
1 
1  -- GIMPLE function: gimple_seq gsi_seq (gimple_stmt_iterator i)
1      Return the sequence associated with this iterator.
1 
1  -- GIMPLE function: void gsi_remove (gimple_stmt_iterator *i, bool
1           remove_eh_info)
1      Remove the current stmt from the sequence.  The iterator is updated
1      to point to the next statement.  When 'REMOVE_EH_INFO' is true we
1      remove the statement pointed to by iterator 'I' from the 'EH'
1      tables.  Otherwise we do not modify the 'EH' tables.  Generally,
1      'REMOVE_EH_INFO' should be true when the statement is going to be
1      removed from the 'IL' and not reinserted elsewhere.
1 
1  -- GIMPLE function: void gsi_link_seq_before (gimple_stmt_iterator *i,
1           gimple_seq seq, enum gsi_iterator_update mode)
1      Links the sequence of statements 'SEQ' before the statement pointed
1      by iterator 'I'.  'MODE' indicates what to do with the iterator
1      after insertion (see 'enum gsi_iterator_update' above).
1 
1  -- GIMPLE function: void gsi_link_before (gimple_stmt_iterator *i,
1           gimple g, enum gsi_iterator_update mode)
1      Links statement 'G' before the statement pointed-to by iterator
1      'I'.  Updates iterator 'I' according to 'MODE'.
1 
1  -- GIMPLE function: void gsi_link_seq_after (gimple_stmt_iterator *i,
1           gimple_seq seq, enum gsi_iterator_update mode)
1      Links sequence 'SEQ' after the statement pointed-to by iterator
1      'I'.  'MODE' is as in 'gsi_insert_after'.
1 
1  -- GIMPLE function: void gsi_link_after (gimple_stmt_iterator *i,
1           gimple g, enum gsi_iterator_update mode)
1      Links statement 'G' after the statement pointed-to by iterator 'I'.
1      'MODE' is as in 'gsi_insert_after'.
1 
1  -- GIMPLE function: gimple_seq gsi_split_seq_after
1           (gimple_stmt_iterator i)
1      Move all statements in the sequence after 'I' to a new sequence.
1      Return this new sequence.
1 
1  -- GIMPLE function: gimple_seq gsi_split_seq_before
1           (gimple_stmt_iterator *i)
1      Move all statements in the sequence before 'I' to a new sequence.
1      Return this new sequence.
1 
1  -- GIMPLE function: void gsi_replace (gimple_stmt_iterator *i, gimple
1           stmt, bool update_eh_info)
1      Replace the statement pointed-to by 'I' to 'STMT'.  If
1      'UPDATE_EH_INFO' is true, the exception handling information of the
1      original statement is moved to the new statement.
1 
1  -- GIMPLE function: void gsi_insert_before (gimple_stmt_iterator *i,
1           gimple stmt, enum gsi_iterator_update mode)
1      Insert statement 'STMT' before the statement pointed-to by iterator
1      'I', update 'STMT''s basic block and scan it for new operands.
1      'MODE' specifies how to update iterator 'I' after insertion (see
1      enum 'gsi_iterator_update').
1 
1  -- GIMPLE function: void gsi_insert_seq_before (gimple_stmt_iterator
1           *i, gimple_seq seq, enum gsi_iterator_update mode)
1      Like 'gsi_insert_before', but for all the statements in 'SEQ'.
1 
1  -- GIMPLE function: void gsi_insert_after (gimple_stmt_iterator *i,
1           gimple stmt, enum gsi_iterator_update mode)
1      Insert statement 'STMT' after the statement pointed-to by iterator
1      'I', update 'STMT''s basic block and scan it for new operands.
1      'MODE' specifies how to update iterator 'I' after insertion (see
1      enum 'gsi_iterator_update').
1 
1  -- GIMPLE function: void gsi_insert_seq_after (gimple_stmt_iterator *i,
1           gimple_seq seq, enum gsi_iterator_update mode)
1      Like 'gsi_insert_after', but for all the statements in 'SEQ'.
1 
1  -- GIMPLE function: gimple_stmt_iterator gsi_for_stmt (gimple stmt)
1      Finds iterator for 'STMT'.
1 
1  -- GIMPLE function: void gsi_move_after (gimple_stmt_iterator *from,
1           gimple_stmt_iterator *to)
1      Move the statement at 'FROM' so it comes right after the statement
1      at 'TO'.
1 
1  -- GIMPLE function: void gsi_move_before (gimple_stmt_iterator *from,
1           gimple_stmt_iterator *to)
1      Move the statement at 'FROM' so it comes right before the statement
1      at 'TO'.
1 
1  -- GIMPLE function: void gsi_move_to_bb_end (gimple_stmt_iterator
1           *from, basic_block bb)
1      Move the statement at 'FROM' to the end of basic block 'BB'.
1 
1  -- GIMPLE function: void gsi_insert_on_edge (edge e, gimple stmt)
1      Add 'STMT' to the pending list of edge 'E'.  No actual insertion is
1      made until a call to 'gsi_commit_edge_inserts'() is made.
1 
1  -- GIMPLE function: void gsi_insert_seq_on_edge (edge e, gimple_seq
1           seq)
1      Add the sequence of statements in 'SEQ' to the pending list of edge
1      'E'.  No actual insertion is made until a call to
1      'gsi_commit_edge_inserts'() is made.
1 
1  -- GIMPLE function: basic_block gsi_insert_on_edge_immediate (edge e,
1           gimple stmt)
1      Similar to 'gsi_insert_on_edge'+'gsi_commit_edge_inserts'.  If a
1      new block has to be created, it is returned.
1 
1  -- GIMPLE function: void gsi_commit_one_edge_insert (edge e,
1           basic_block *new_bb)
1      Commit insertions pending at edge 'E'.  If a new block is created,
1      set 'NEW_BB' to this block, otherwise set it to 'NULL'.
1 
1  -- GIMPLE function: void gsi_commit_edge_inserts (void)
1      This routine will commit all pending edge insertions, creating any
1      new basic blocks which are necessary.
1