public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: David Malcolm <dmalcolm@redhat.com>
To: Richard Sandiford <rdsandiford@googlemail.com>
Cc: Oleg Endo <oleg.endo@t-online.de>,
	       Steven Bosscher <stevenb.gcc@gmail.com>,
	       GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: Instructions vs Expressions in the backend (was Re: RFA: Rework FOR_BB_INSNS iterators)
Date: Fri, 27 Jun 2014 14:35:00 -0000	[thread overview]
Message-ID: <1403879554.21706.58.camel@surprise> (raw)
In-Reply-To: <87bnthgwku.fsf@talisman.default>

On Wed, 2014-06-25 at 10:36 +0100, Richard Sandiford wrote:
> Oleg Endo <oleg.endo@t-online.de> writes:
> > Personally, I'd like to see usage of standard STL-like iterator usage.
> > I've proposed something for edge_iterator a while ago, but people don't
> > seem very fond of it.  See also
> > https://gcc.gnu.org/ml/gcc-patches/2013-12/msg01129.html
> >
> > Have you also considered passing the new rtx_* types by value or
> > reference instead of pointer?  A long time ago I've quickly put together
> > a class 'rtxx' which was just a pointer wrapper for the rtx_def*
> > (basically the same as I proposed for edge_iterator).
> > I've converted the SH backend code to use it just to see what it would
> > look like.  The conversion itself was pretty straight forward -- just
> > replace 'rtx' with 'rtxx'.  Appropriate conversion
> > operators/constructors in 'class rtxx' made both interchangeable and
> > allowed co-existence of both and thus step-by-step conversion of the
> > code base.
> > Another advantage of passing around by value/ref is that it allows
> > operator overloading.  One use case could be instead of:
> >
> > if (MEM_P (XEXP (x, 0)))
> >   *total = address_cost (XEXP (XEXP (x, 0), 0),
> >                          GET_MODE (XEXP (x, 0)),
> >                          MEM_ADDR_SPACE (XEXP (x, 0)), true);
> >
> >
> > something like that (overloading operator[]):
> > if (x[0] == rtx_mem::type)
> >   *total = address_cost (x[0][0], x[0].mode (),
> >                          x[0].mem_addr_space (), true);
> >
> > ... where rtx_mem::type would be some type for which 'rtxx' (or whatever
> > the name of the base class is) would provide the according operator
> > ==, != overloads.
> 
> I think this is an example of another problem with gcc coding style:
> that we're far too afraid of temporary variables.  In David's scheme
> I think this would be:
> 
>   if (rtx_mem *mem = as_a <rtx_mem *> (XEXP (x, 0)))
>     *total = address_cost (XEXP (mem, 0), GET_MODE (mem),
>                            MEM_ADDR_SPACE (mem), true);

FWIW you want a dyn_cast<> rather than an as_a<> here, giving:

  if (rtx_mem *mem = dyn_cast <rtx_mem *> (XEXP (x, 0)))
    *total = address_cost (XEXP (mem, 0), GET_MODE (mem),
                           MEM_ADDR_SPACE (mem), true);

> which with members would become:
> 
>   if (rtx_mem *mem = as_a <rtx_mem *> (...))
>     *total = address_cost (mem->address (), mem->mode (), mem->address_space (),
>                            true);

(likewise)

> (although if we go down that route, I hope we can add an exception to the
> formatting rule so that no space should be used before "()".)
> 
> I suppose with the magic values it would be:
> 
>   if (rtx_mem mem = as_a <rtx_mem> (x[0]))
>     *total = address_cost (mem[0], mem.mode (), mem.address_space (), true);

(likewise).

> but I'm not sure that that would really be more readable.

[...snip...; see my other mail for notes on restricting the scope of the
current patch kit to an insn vs expr separation, for the sake of my
sanity :) ]

  parent reply	other threads:[~2014-06-27 14:35 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-07 17:54 RFA: Rework FOR_BB_INSNS iterators Richard Sandiford
2014-06-07 20:26 ` Steven Bosscher
2014-06-09 19:32   ` Richard Sandiford
2014-06-23 19:01     ` Instructions vs Expressions in the backend (was Re: RFA: Rework FOR_BB_INSNS iterators) David Malcolm
2014-06-23 20:38       ` Oleg Endo
2014-06-25  9:36         ` Richard Sandiford
2014-06-25 20:39           ` Jeff Law
2014-06-27 14:28             ` David Malcolm
2014-06-27 15:38               ` Jeff Law
2014-06-27  7:36           ` Oleg Endo
2014-06-27 14:35           ` David Malcolm [this message]
2014-06-25  8:54       ` Richard Sandiford
2014-06-25 20:46         ` Jeff Law
2014-06-25 21:24           ` Steven Bosscher

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1403879554.21706.58.camel@surprise \
    --to=dmalcolm@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=oleg.endo@t-online.de \
    --cc=rdsandiford@googlemail.com \
    --cc=stevenb.gcc@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).