PATCH: remove expand_constant lang_hook (was [RFC] Migrate pointers to members to the middle end)

Ollie Wild aaw@google.com
Mon Sep 24 20:25:00 GMT 2007


On 8/10/07, Mark Mitchell <mark@codesourcery.com> wrote:
> Ollie Wild wrote:
>
> > Offhand, I don't remember what happened with the various other cases,
> > but my testing at the time wasn't particularly thorough.  The feedback
> > I've gotten so far seems overwhelmingly negative, so I think the next
> > step is to revisit the lowering approach, exercise the hell out of it,
> > and see what, if any, limitations pop up.
>
> Yes, I agree.  Again, thank you for being patient with the process.
>
> Let me know when you're at the point where you'd like me to review the
> front-end lowering patch again; send me a URL, and I'll be happy to do so.

OK.  I think I'm ready for another go.

This is a resubmission of my patch from
http://gcc.gnu.org/ml/gcc-patches/2007-03/msg01819.html.  It removes
the expand_constant language hook which was previously used to expand
C++ pointers to members.  This expansion is now done during
initializer storage.

Previously, this patch was put on hold to investigate ways to improve
optimization of pointers to members.  A middle end migration was
investigated but rejected by the GCC community.  Instead, I've opted
to improve GCC's ability to handle pointers to members in their
lowered form.

In conjunction with my patch for folding BIT_AND_EXPR's with ADDR_EXPR
operands (http://gcc.gnu.org/ml/gcc-patches/2007-09/msg00940.html) and
the -O2 optimization level, this code is able to convert:

   struct S { void f(); };  // optionally virtual
   typedef void (S::*P)(void);
   const P ps[2] = { &S::f, 0 };
   void g(S s) {
       P p = ps[0];
       (s.*p)();  // replace with s.f ()
   }

to the same code with (s.*p)() replaced by s.f ().  Furthermore, it
does so irrespective of whether f() is virtual or the value of
TARGET_PTRMEMFUNC_VBIT_LOCATION.

There is still room for additional pointer to member optimization.  In
particular, the following are on my queue: (a) fix comparison of
pointers to member functions, (b) enable simplification of
std::mem_fun_ref calls, and (c) investigate devirtualization.

Ollie


2007-09-24  Ollie Wild  <aaw@google.com>

    * varasm.c (compare_constant): Removed call to
    lang_hooks.expand_constant.
    (copy_constants): Removed call to lang_hooks.expand_constant.
    (compute_reloc_for_constant): Removed call to
    lang_hooks.expand_constant.
    (output_addressed_constants): Removed call to
    lang_hooks.expand_constant.
    (constructor_static_from_elts_p): Removed call to
    lang_hooks.expand_constant.
    (output_constant): Removed calls to lang_hooks.expand_constant.
    * langhooks.h (struct lang_hooks): Removed field expand_constant.
    * langhooks-def.h (lhd_return_tree): Removed.
    (LANG_HOOKS_EXPAND_CONSTANT): Removed.
    (LANG_HOOKS_INITIALIZER): Removed LANG_HOOKS_EXPAND_CONSTANT.
    * langhooks.c (lhd_return_tree): Removed.

2007-09-24  Ollie Wild  <aaw@google.com>

    * typeck2.c (digest_init): Call cplus_expand_constant after
    convert_for_initialization.
    * cp-objcp-common.h (LANG_HOOKS_EXPAND_CONSTANT): Removed.
    * expr.c (cplus_expand_constant): Updated function description.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: no_expand_constant.patch
Type: text/x-patch
Size: 7081 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20070924/bebb26ba/attachment.bin>


More information about the Gcc-patches mailing list