This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PATCH: use type-safe vectors for basic block edges
- From: Steven Bosscher <stevenb at suse dot de>
- To: Nathan Sidwell <nathan at codesourcery dot com>,Ben Elliston <bje at au1 dot ibm dot com>
- Cc: Richard Henderson <rth at redhat dot com>,Zdenek Dvorak <rakdver at atrey dot karlin dot mff dot cuni dot cz>,gcc-patches at gcc dot gnu dot org, mark at codesourcery dot com
- Date: Tue, 14 Sep 2004 10:04:07 +0200
- Subject: Re: PATCH: use type-safe vectors for basic block edges
- Organization: SUSE Labs
- References: <87k6uyfi83.fsf@au.ibm.com> <87vfeh5y4y.fsf@au.ibm.com> <4146A26B.5020509@codesourcery.com>
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