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: use type-safe vectors for basic block edges


On Tuesday 14 September 2004 09:48, Nathan Sidwell wrote:
> Ben Elliston wrote:
> > Richard Henderson <rth@redhat.com> writes:
> >>On Tue, Sep 14, 2004 at 12:01:59PM +1000, Ben Elliston wrote:
> >>>How does this revised patch to basic-block.h look?
> >>
> >>What's the proposed usage idiom?
> >
> > Here's an example from tree-cfg.c:
> >
> >   FOR_EACH_EDGE (ei, ENTRY_BLOCK_PTR->succs)
> >     {
> >       e = ei_edge (ei);
>
> hmm, you've elided the declarations of EI and E.  Once you've added
> those, what does 'struct edge_iterator' buy you?

It buys you that you have a *real* iterator and not a user declared
integer index variable for every FOR_EACH_EDGE and the misnamed and
and IMHO (I'm sorry to say) rather crappy VEC_iterator API.

Iterators exist to *hide* index variables.  VEC_iterator *exposes*
the index variable.  That is Very Ugly and bug prone if your VEC
can change during the iteration over it.


> 	edge_iterator ei;
> 	edge e;
> 	FOR_EACH_EDGE(ei, ENTRY_BLOCK_PTR->succs)
> 	  {
> 		e = ei_edge (ei);
> 		...
> 	  }
> vs
> 	int ix;
> 	edge e;
> 	FOR_EACH_EDGE (ix, ENTRY_BLOCK_PTR->succs, e)
> 	   {
> 	      ...
> 	   }

This means that you have to muck with ix when a vector element in
the vector is removed.  This is exactly what Ben had at the start,
and it is exactly the most bug prone style of iterator that I have
ever seen because you end up manipulating ix inside the iterator
"body" code.


> looks like needless source indirection to me.

Then you haven't looked at it very well at the problems we've had
with this kind of "iterator" ;-)  I explained that in the message
at http://gcc.gnu.org/ml/gcc-patches/2004-09/msg01405.html.  It
was a mess.


> I suppose the edge_iterator
> avoids multiple evaluations of ENTRY_BLOCK_PTR->succs and the like.

That too, probably, but that's not the main issue.

Gr.
Steven



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