[patch] Statement operand iterators

Andrew MacLeod amacleod@redhat.com
Thu Jun 24 18:19:00 GMT 2004

On Thu, 2004-06-24 at 11:44, Zdenek Dvorak wrote:
> Hello,
> currently, we have operands of statements split into 6 different
> cathegories, with a separate accessor macros for each of them.
> In addition we have a completely separate way of accessing arguments
> of phi nodes.
> This means that if I for example want to run some code over all uses
> of the statement (both real and virtual), it means that I first have
> to check whether I work with a phi node, or with a normal statement,
> and in the later case prepare three optype variables and for each of them
> run a separate loop.  In total I need either to duplicate the code
> four times, or create a function for it

Its pretty easy to hide that now behind a new macro. All uses now return
a use_operand_p with that last set of changes I made.  So writing a
macro to do 
FOR_EVERY_STMT_USE (stmt, iterator, {code})
would be pretty straightforward without going to a lot of extra hassle,
and have very little impact on compile time.

> Given that this is a fairly common operation, this is way too much work.
> This patch introduces operand iterators.  With them, I may solve the
> above with simply writing
> oii oi;
> for (oi_init (&oi, stmt, OI_ALL_USES); !oi_end_p (&oi); oi_next (&oi))
>   code (oi_op (&oi));

So this would look like:

  stmt_use_iterator sui;
  FOR_EVERY_STMT_USE (sui, stmt,
      code (SUI_USE (sui))

where SUI_USE simply returns the use_operand_p for the use.

If you want a macro for all defs, or some other such thing, use the same
process.  These macros would just do under the covers the code you dont
want to write yourself.

I'd much rather do that than all this code...


More information about the Gcc-patches mailing list