sanity of the use list by moving all the uses for a statement into
a controlled position, and then iterating over those uses. Then the
optimization can manipulate the stmt when all the uses have been
-processed. This is a little slower than the FAST version since it adds a
-placeholder element and must sort through the list a bit for each statement.
-This placeholder element must be also be removed if the loop is
-terminated early; a destructor takes care of that when leaving the
-@code{FOR_EACH_IMM_USE_STMT} scope.
+processed. Only the current active @code{imm_use_p} may be altered
+when using an inner @code{FOR_EACH_IMM_USE_ON_STMT} iteration.
+You have to be careful to not inadvertedly modify the immediate
+use list by working on another stmt than the the current @code{stmt} during
+the iteration. In particular calling @code{update_stmt} is destructive
+on all SSA uses immediate use lists related to the updated stmt.
+This slower than the FAST version since it sorts through the list for each
+statement.
+
+@code{FOR_EACH_IMM_USE_ON_STMT} iteration may not be nested inside
+another @code{FOR_EACH_IMM_USE_ON_STMT} or @code{FOR_EACH_IMM_USE_FAST}
+iteration of the same immediate use list.
+
+There is the @code{gather_imm_use_stmts} helper that trades memory for
+removing the need to care about the immediate use list consistency and
+which also avoids duplicate visiting of stmts that can occur with
+@code{FOR_EACH_IMM_USE_FAST} when there are multiple uses of an SSA name
+on a stmt. This can be used to iterate safely over all use stmts like
+this:
+
+@smallexample
+ tree ssa_var;
+
+ for (gimple *use_stmt : gather_imm_use_stmts (ssa_var))
+ @{
+ // do something with use_stmt
+ @}
+@end smallexample
There are checks in @code{verify_ssa} which verify that the immediate use list
is up to date.
Safe iteration via FOR_EACH_IMM_USE_STMT and FOR_EACH_IMM_USE_ON_STMT
allows insertion, deletion, and modification of SSA operands within
the current stmt iterated. The iterator manages this by re-sorting
- the immediate uses to batch uses on a single stmt after each other
- and inserts a marker node into the list immediately after the node
- ending the current batch. This marker node is uniquely identified by
- having null stmt *and* a null use pointer. */
+ the immediate uses to batch uses on a single stmt after each other.
+ If using an inner FOR_EACH_IMM_USE_ON_STMT iteration only the active
+ use may be manipulated. Safety relies on new immediate uses being
+ inserted at the front of immediate use lists. */
struct imm_use_iterator
{