This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] Statement operand iterators


Hello,

> > > 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.
> > 
> 
> So something like this. (I havent even tried compiling it, so I dont
> know there isnt a bug, but you get the idea...)
> 
> 
> typedef struct use_iterator {
>   use_operand_type uses;
>   vuse_operand_type vuses;
>   v_may_def_operand_type v_may_defs;
>   int uses_end;
>   int vuses_end;
>   int v_may_defs_end;
>   int current_index;
>   int index_limit;
>   use_operand_p curr_use;
> } stmt_use_iterator;
> 
> 
> static void inline
> sui_next (stmt_use_iterator *sui)
> {
>   sui->current_index++;
>   if (sui->current_index < sui->uses_end)
>     {
>       sui->curr_use = USE_OP_PTR (sui->uses, sui->current_index);
>     }
>   else
>     if (sui->current_index < sui->vuses_end)
>       {
> 	sui->curr_use = VUSE_OP_PTR (sui->vuses, 
> 				     sui->current_index - sui->uses_end);
>       }
>     else
>       if (sui->current_index < sui->v_may_defs_end)
> 	sui->curr_use = V_MAY_DEF_OP_PTR (sui->v_may_defs, 
> 				          sui->current_index - sui->vuses_end);
>   }
> }
> 
> #define SUI_USE(SUI)		(SUI).curr_use
> 
> #define FOR_EVERY_STMT_USE(SUI, STMT, CODE)			\
>   do {								\
>     (SUI).uses = STMT_USE_OPS (STMT);				\
>     (SUI).vuses = STMT_VUSE_OPS (STMT);				\
>     (SUI).v_may_defs = STMT_V_MAY_DEF_OPS (STMT);		\
>     (SUI).uses_end = NUM_USES ((SUI).uses);			\
>     (SUI).vuses_end = (SUI).uses_end + NUM_VUSES ((SUI).vuses);	\
>     (SUI).v_may_defs_end = (SUI).vuses_end		      \
> 			   + NUM_V_MAY_DEFS ((SUI).v_may_defs);	\
>     (SUI).index_limit = (SUI).num_uses + (SUI).num_vuses + 	\
>     			(SUI).num_v_may_defs 			\
>     (SUI).current_index = -1; 					\
>     for (sui_next (&(SUI)); (SUI).current_index < limit;  	\
> 					  sui_next (&(SUI)))	\
>       {								\
>         CODE;							\
>       }								\ 
>   } while (0)							\
> 
> 	
> 
> There are a multitude of ways of implementing them, this is just an
> example of one which is pretty straightforward.

and about as slow as the iterator one; this version really has only
disadvantages compared with it.  The problem is really that the iterator
encompasing different types of operands must decide which one of them
to provide.  You can provide directly use_operand_ptr (then you can just
duplicate the code in the macro), but this does not work in case you are
interested in both uses and defs in the same time (which is not that
common, so we might live with that); but in any case those macros would
be huge and ugly.

Zdenek


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]