Re: varpool alias reorg

2011-06-28 Thread Richard Guenther
On Mon, 27 Jun 2011, Jan Hubicka wrote:

> > On Fri, 24 Jun 2011, Jan Hubicka wrote:
> > 
> > > Hi,
> > > this is yet another variant of the fix.  This time we stream builtins 
> > > decls as
> > > usually, but at fixup time we copy the assembler names (if set) into the
> > > builtin decls used by folders.  Not sure if it is any better than breaking
> > > memops-asm, but I can imagine that things like glibc actually rename 
> > > string
> > > functions into their internal variants (and thus with this version of 
> > > patch we
> > > would be able to LTO such library, but still we won't be able to LTO such
> > > library into something else because something else would end up 
> > > referncing the
> > > internal versions of builtins).  I doubt we could do any better, however.
> > 
> > Not stream builtins with adjusted assembler names (I guess we'd need
> > a flag for this, DECL_USER_ASSEMBLER_NAME_SET_P?  Or just check for
> 
> Most of code just checks for '*' on begginign of assembler name. I suppose it 
> is safe.
> 
> > attributes?) as builtins but as new decls.  Let lto symbol merging
> > then register those as aliases.  But which way around?  probably
> > similar to how we should handle re-defined extern inlines, the
> > extern inline being the GCC builtin and the re-definition being
> > the aliased one.
> 
> I don't quite get your answer here.  What we do now is:
> 
>  1) stream in builtin as special kind of reference with decl assembler name 
> associated to it
>  2) at streaming in time always resolve builtlin to the "official" builtin 
> decls (no matter
>  what types and other stuff builtin had at stream out time) and overwritting 
> the official builtin
>  assembler name into one specified.
> 
> What i suggest is
> 
>  1) Stream out builtins as usual decls just with the extra function code
>  2) Stream in builtins as usually
>  3) optionally set the assembler name of the "official" decl
> 
> I see there are problems with i.e. one decl rule, but we do have same problems
> with normal frontends that also do use different decl for explicit builtin
> calls than for implicit, sadly.
> 
> I am not quite sure what the proper fix for this problem is - it is very handy
> to have builtin decl in middle end where I know it is sane (i.e. it has the
> right types etc.). Since C allows to declare the builtins arbitrarily, it gets
> bit tricky to preserve one decl rule here.

Hm.  I would suggest to do as now, stream in builtin specially if it
does not have an assembler name attribute.  If it does have it, stream
it as usually and let lto symtab do its job (I suppose we need to
register builtin functions with the symtab as well).

> > > __attribute__ ((used)) is still needed in memops-asm-lib.c because LTO 
> > > symtab
> > > of course doesn't see the future references to builtins that we will emit
> > > later via folding.  I think it is resonable requirement, as discussed at 
> > > the
> > > time enabling the plugin.
> > 
> > Yes, I think the testcase fix sounds reasonable.
> > 
> > I suppose you can come up with a simpler testcase for this "feature"
> > for gcc.dg/lto highlighting the different issues?  I'm not sure
> > if we are talking about my_memcpy () alias("memcpy") or
> > memcpy () alias("my_memcpy").
> > 
> > I still like to stream unmodified builtins as builtins, as that is
> > similar to pre-loading the streamer caches with things like
> > void_type_node or sizetype.
> 
> Doing so will need us to solve the other one decl rules probly.
> I didn't really got what the preloading is useful for after all?

Saving memory mostly, apart from the special singletons we have
(as Micha already hinted).

Richard.


Re: varpool alias reorg

2011-06-27 Thread Michael Matz
Hi,

On Mon, 27 Jun 2011, Jan Hubicka wrote:

> > I still like to stream unmodified builtins as builtins, as that is 
> > similar to pre-loading the streamer caches with things like 
> > void_type_node or sizetype.
> 
> Doing so will need us to solve the other one decl rules probly. I didn't 
> really got what the preloading is useful for after all?

One important thing that really affects correctness which preloading does 
is to guarantee pointer equality for things like void_type_node or 
error_mark_node, which are used sometimes.  If we weren't doing preloading 
we would have to forcibly merge all these trees over different units, and 
what's worse, also fill out the global tree arrays with that merged 
variant.  And for that we'd need to note somehow which array slot a 
certain tree is coming from (and deal with the fact that different 
language frontends fill this array differently, sometimes with 
pointer-eqal tree nodes, sometimes only with semantically equal tree 
nodes, sometimes not at all).

Or we could fix all places where we use pointer equality with some of the 
global trees, which I wouldn't like, even for abstract considerations.  
There's really no point in having different but equal void_type nodes, or 
error_mark nodes.

preloading really is the easiest way to solve all this.  It's just 
important that all .o files have the same idea about "tree at slot 
so-and-so" (e.g. meaning "error_mark_node"), which I fixed some weeks ago.

And with early-debug-info we don't even then have the issue of e.g. the 
base integer types not being named like the frontend emitted them.


Ciao,
Michael.


Re: varpool alias reorg

2011-06-27 Thread Jan Hubicka
> On Fri, 24 Jun 2011, Jan Hubicka wrote:
> 
> > Hi,
> > this is yet another variant of the fix.  This time we stream builtins decls 
> > as
> > usually, but at fixup time we copy the assembler names (if set) into the
> > builtin decls used by folders.  Not sure if it is any better than breaking
> > memops-asm, but I can imagine that things like glibc actually rename string
> > functions into their internal variants (and thus with this version of patch 
> > we
> > would be able to LTO such library, but still we won't be able to LTO such
> > library into something else because something else would end up referncing 
> > the
> > internal versions of builtins).  I doubt we could do any better, however.
> 
> Not stream builtins with adjusted assembler names (I guess we'd need
> a flag for this, DECL_USER_ASSEMBLER_NAME_SET_P?  Or just check for

Most of code just checks for '*' on begginign of assembler name. I suppose it 
is safe.

> attributes?) as builtins but as new decls.  Let lto symbol merging
> then register those as aliases.  But which way around?  probably
> similar to how we should handle re-defined extern inlines, the
> extern inline being the GCC builtin and the re-definition being
> the aliased one.

I don't quite get your answer here.  What we do now is:

 1) stream in builtin as special kind of reference with decl assembler name 
associated to it
 2) at streaming in time always resolve builtlin to the "official" builtin 
decls (no matter
 what types and other stuff builtin had at stream out time) and overwritting 
the official builtin
 assembler name into one specified.

What i suggest is

 1) Stream out builtins as usual decls just with the extra function code
 2) Stream in builtins as usually
 3) optionally set the assembler name of the "official" decl

I see there are problems with i.e. one decl rule, but we do have same problems
with normal frontends that also do use different decl for explicit builtin
calls than for implicit, sadly.

I am not quite sure what the proper fix for this problem is - it is very handy
to have builtin decl in middle end where I know it is sane (i.e. it has the
right types etc.). Since C allows to declare the builtins arbitrarily, it gets
bit tricky to preserve one decl rule here.
> 
> > __attribute__ ((used)) is still needed in memops-asm-lib.c because LTO 
> > symtab
> > of course doesn't see the future references to builtins that we will emit
> > later via folding.  I think it is resonable requirement, as discussed at the
> > time enabling the plugin.
> 
> Yes, I think the testcase fix sounds reasonable.
> 
> I suppose you can come up with a simpler testcase for this "feature"
> for gcc.dg/lto highlighting the different issues?  I'm not sure
> if we are talking about my_memcpy () alias("memcpy") or
> memcpy () alias("my_memcpy").
> 
> I still like to stream unmodified builtins as builtins, as that is
> similar to pre-loading the streamer caches with things like
> void_type_node or sizetype.

Doing so will need us to solve the other one decl rules probly.
I didn't really got what the preloading is useful for after all?

Honza

> 
> Richard.


Re: varpool alias reorg

2011-06-27 Thread Richard Guenther
On Fri, 24 Jun 2011, Jan Hubicka wrote:

> Hi,
> this is yet another variant of the fix.  This time we stream builtins decls as
> usually, but at fixup time we copy the assembler names (if set) into the
> builtin decls used by folders.  Not sure if it is any better than breaking
> memops-asm, but I can imagine that things like glibc actually rename string
> functions into their internal variants (and thus with this version of patch we
> would be able to LTO such library, but still we won't be able to LTO such
> library into something else because something else would end up referncing the
> internal versions of builtins).  I doubt we could do any better, however.

Not stream builtins with adjusted assembler names (I guess we'd need
a flag for this, DECL_USER_ASSEMBLER_NAME_SET_P?  Or just check for
attributes?) as builtins but as new decls.  Let lto symbol merging
then register those as aliases.  But which way around?  probably
similar to how we should handle re-defined extern inlines, the
extern inline being the GCC builtin and the re-definition being
the aliased one.

> __attribute__ ((used)) is still needed in memops-asm-lib.c because LTO symtab
> of course doesn't see the future references to builtins that we will emit
> later via folding.  I think it is resonable requirement, as discussed at the
> time enabling the plugin.

Yes, I think the testcase fix sounds reasonable.

I suppose you can come up with a simpler testcase for this "feature"
for gcc.dg/lto highlighting the different issues?  I'm not sure
if we are talking about my_memcpy () alias("memcpy") or
memcpy () alias("my_memcpy").

I still like to stream unmodified builtins as builtins, as that is
similar to pre-loading the streamer caches with things like
void_type_node or sizetype.

Richard.


Re: varpool alias reorg

2011-06-27 Thread Jan Hubicka
> > There are two problems here
> >   1) We do not stream builtin decls and merge them outside lto-symtab (by 
> > just
> >  streaming references to builtins with their asm names).  There is at 
> > least
> >  one extra PR related to this and on my TODO is to simply remove the 
> > code.
> >   2) Aliases within single unit works only when both the alias and the 
> > target use
> >  asm name.  This is because internally we store mangled 
> > DECL_ASSEMBLER_NAME and the
> >  alias_pair code.
> >  With LTO this breaks existing code simply because what used to be 
> > multiple units
> >  and thus safe is now single LTO unit.
> > 
> >  Dave Korn fixed part of the problem by introducing mangling code into 
> > lto-symtab
> >  His code solve similar problems with aliases from the asm code, but it
> >  did not solve the problem with aliases from LTO units, like here, 
> > simply
> >  because alias pair code bypass the lto-symtab.  One of goals of the 
> > incorrect patch
> >  above is to make lto-symtab to do the merging and thus fix this issue 
> > (for now at
> >  all decls except for builtins).
> > 
> >  Still it would be good to solve the problem on non-LTO compilation, 
> > too.
> >  We discussed introduction of proper symbol table into GCC at the GCC 
> > gathering last
> >  weekend.  It is where I am heading but it will take some time.
> > 
> > Until that happens, I suggest fixing the testcase same was as we already 
> > fixed
> > the memops-asm-lib.c in 4.6 timeframe.
> > 
> > Bootstrapped/regtested x86_64-linux, OK?
> 
> Ok.
Hi,
thanks!  Could you, please, also consider the second two variants I sent?  In
general attribute used is needed when implementing libfuncs since we never know
when folding will intoduce new libcall (like in memops-asm).  However this
particular case don't need use because the builtin is called directly.
They also solve the problem of BLOCK lists being messed up.

In meantime I tested both variants and they pass.  I will add a changelog, of 
course.

Honza


Re: varpool alias reorg

2011-06-27 Thread Richard Guenther
On Thu, 23 Jun 2011, Jan Hubicka wrote:

> > On Sat, Jun 18, 2011 at 7:19 AM, H.J. Lu  wrote:
> > > On Sat, Jun 18, 2011 at 1:32 AM, Jan Hubicka  wrote:
> > >> Hi,
> > >> this patch makes symetric changes to varpool as did the prevoius series 
> > >> to cgraph.
> > >> Basically the aliases are now represented as separate varpool nodes with 
> > >> alias reference
> > >> to the variable they refer to, with some infrastructure to walk the 
> > >> alias references
> > >> as needed.
> > >>
> > >> Bootstrapped/regtested x86_64-linux, comitted.
> > >>
> > >> Honza
> > >>
> > >>        * lto-symtab.c (lto_varpool_replace_node): Remove code handling
> > >>        extra name aliases.
> > >>        (lto_symtab_resolve_can_prevail_p): Likewise.
> > >>        (lto_symtab_merge_cgraph_nodes): Update alias_of pointers..
> > >>        * cgraphbuild.c (record_reference): Remove extra body alias code.
> > >>        (mark_load): Likewise.
> > >>        (mark_store): Likewise.
> > >>        * cgraph.h (varpool_node): Remove extra_name filed;
> > >>        add alias_of and extraname_alias.
> > >>        (varpool_create_variable_alias, varpool_for_node_and_aliases): 
> > >> Declare.
> > >>        (varpool_alias_aliased_node): New inline function.
> > >>        (varpool_variable_node): New function.
> > >>        * cgraphunit.c (handle_alias_pairs): Handle also variable aliases.
> > >>        * ipa-ref.c (ipa_record_reference): Allow aliases on variables.
> > >>        * lto-cgraph.c (lto_output_varpool_node): Update streaming.
> > >>        (input_varpool_node): Likewise.
> > >>        * lto-streamer-out.c (produce_symtab): Remove extra name aliases.
> > >>        (varpool_externally_visible_p): Remove extra body alias code.
> > >>        (function_and_variable_visibility): Likewise.
> > >>        * tree-ssa-structalias.c (associate_varinfo_to_alias_1): New 
> > >> function.
> > >>        (ipa_pta_execute): Use it.
> > >>        * varpool.c (varpool_remove_node): Remove extra name alias code.
> > >>        (varpool_mark_needed_node): Likewise.
> > >>        (varpool_analyze_pending_decls): Analyze aliases.
> > >>        (assemble_aliases): New functoin.
> > >>        (varpool_assemble_decl): Use it.
> > >>        (varpool_create_variable_alias): New function.
> > >>        (varpool_extra_name_alias): Rewrite.
> > >>        (varpool_for_node_and_aliases): New function.
> > >
> > > This caused:
> > >
> > > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49463
> > >
> > 
> > This patch is incorrect as shown in the PR above.
> 
> The builtins/strstr-asm.c is the same issue as I patched some time ago in 
> http://gcc.gnu.org/ml/gcc-patches/2010-12/msg00031.html
> just in this case the problem remained hidden until now.
> 
> Again the problem needs plugin to manifest.
> 
> There are two problems here
>   1) We do not stream builtin decls and merge them outside lto-symtab (by just
>  streaming references to builtins with their asm names).  There is at 
> least
>  one extra PR related to this and on my TODO is to simply remove the code.
>   2) Aliases within single unit works only when both the alias and the target 
> use
>  asm name.  This is because internally we store mangled 
> DECL_ASSEMBLER_NAME and the
>  alias_pair code.
>  With LTO this breaks existing code simply because what used to be 
> multiple units
>  and thus safe is now single LTO unit.
> 
>  Dave Korn fixed part of the problem by introducing mangling code into 
> lto-symtab
>  His code solve similar problems with aliases from the asm code, but it
>  did not solve the problem with aliases from LTO units, like here, simply
>  because alias pair code bypass the lto-symtab.  One of goals of the 
> incorrect patch
>  above is to make lto-symtab to do the merging and thus fix this issue 
> (for now at
>  all decls except for builtins).
> 
>  Still it would be good to solve the problem on non-LTO compilation, too.
>  We discussed introduction of proper symbol table into GCC at the GCC 
> gathering last
>  weekend.  It is where I am heading but it will take some time.
> 
> Until that happens, I suggest fixing the testcase same was as we already fixed
> the memops-asm-lib.c in 4.6 timeframe.
> 
> Bootstrapped/regtested x86_64-linux, OK?

Ok.

Thanks,
Richard.

> Index: strstr-asm-lib.c
> ===
> --- strstr-asm-lib.c  (revision 175183)
> +++ strstr-asm-lib.c  (working copy)
> @@ -7,6 +7,7 @@
>  extern int inside_main;
>  extern const char *p;
>  
> +__attribute__ ((used))
>  char *
>  my_strstr (const char *s1, const char *s2)
>  {

Re: varpool alias reorg

2011-06-24 Thread Jan Hubicka
Hi,
this is yet another variant of the fix.  This time we stream builtins decls as
usually, but at fixup time we copy the assembler names (if set) into the
builtin decls used by folders.  Not sure if it is any better than breaking
memops-asm, but I can imagine that things like glibc actually rename string
functions into their internal variants (and thus with this version of patch we
would be able to LTO such library, but still we won't be able to LTO such
library into something else because something else would end up referncing the
internal versions of builtins).  I doubt we could do any better, however.

__attribute__ ((used)) is still needed in memops-asm-lib.c because LTO symtab
of course doesn't see the future references to builtins that we will emit
later via folding.  I think it is resonable requirement, as discussed at the
time enabling the plugin.

Honza

Index: lto-streamer-out.c
===
--- lto-streamer-out.c  (revision 175350)
+++ lto-streamer-out.c  (working copy)
@@ -484,8 +484,6 @@ pack_ts_function_decl_value_fields (stru
 {
   /* For normal/md builtins we only write the class and code, so they
  should never be handled here.  */
-  gcc_assert (!lto_stream_as_builtin_p (expr));
-
   bp_pack_enum (bp, built_in_class, BUILT_IN_LAST,
DECL_BUILT_IN_CLASS (expr));
   bp_pack_value (bp, DECL_STATIC_CONSTRUCTOR (expr), 1);
@@ -1121,7 +1119,7 @@ lto_output_ts_binfo_tree_pointers (struc
  together large portions of programs making it harder to partition.  
Becuase
  devirtualization is interesting before inlining, only, there is no real
  need to ship it into ltrans partition.  */
-  lto_output_tree_or_ref (ob, flag_wpa ? NULL : BINFO_VIRTUALS (expr), ref_p);
+  lto_output_tree_or_ref (ob, flag_wpa || 1 ? NULL : BINFO_VIRTUALS (expr), 
ref_p);
   lto_output_tree_or_ref (ob, BINFO_VPTR_FIELD (expr), ref_p);
 
   output_uleb128 (ob, VEC_length (tree, BINFO_BASE_ACCESSES (expr)));
@@ -1306,41 +1304,6 @@ lto_output_tree_header (struct output_bl
 }
 
 
-/* Write the code and class of builtin EXPR to output block OB.  IX is
-   the index into the streamer cache where EXPR is stored.*/
-
-static void
-lto_output_builtin_tree (struct output_block *ob, tree expr)
-{
-  gcc_assert (lto_stream_as_builtin_p (expr));
-
-  if (DECL_BUILT_IN_CLASS (expr) == BUILT_IN_MD
-  && !targetm.builtin_decl)
-sorry ("gimple bytecode streams do not support machine specific builtin "
-  "functions on this target");
-
-  output_record_start (ob, LTO_builtin_decl);
-  lto_output_enum (ob->main_stream, built_in_class, BUILT_IN_LAST,
-  DECL_BUILT_IN_CLASS (expr));
-  output_uleb128 (ob, DECL_FUNCTION_CODE (expr));
-
-  if (DECL_ASSEMBLER_NAME_SET_P (expr))
-{
-  /* When the assembler name of a builtin gets a user name,
-the new name is always prefixed with '*' by
-set_builtin_user_assembler_name.  So, to prevent the
-reader side from adding a second '*', we omit it here.  */
-  const char *str = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (expr));
-  if (strlen (str) > 1 && str[0] == '*')
-   lto_output_string (ob, ob->main_stream, &str[1], true);
-  else
-   lto_output_string (ob, ob->main_stream, NULL, true);
-}
-  else
-lto_output_string (ob, ob->main_stream, NULL, true);
-}
-
-
 /* Write a physical representation of tree node EXPR to output block
OB.  If REF_P is true, the leaves of EXPR are emitted as references
via lto_output_tree_ref.  IX is the index into the streamer cache
@@ -1456,15 +1419,6 @@ lto_output_tree (struct output_block *ob
   lto_output_enum (ob->main_stream, LTO_tags, LTO_NUM_TAGS,
   lto_tree_code_to_tag (TREE_CODE (expr)));
 }
-  else if (lto_stream_as_builtin_p (expr))
-{
-  /* MD and NORMAL builtins do not need to be written out
-completely as they are always instantiated by the
-compiler on startup.  The only builtins that need to
-be written out are BUILT_IN_FRONTEND.  For all other
-builtins, we simply write the class and code.  */
-  lto_output_builtin_tree (ob, expr);
-}
   else
 {
   /* This is the first time we see EXPR, write its fields
Index: lto-streamer-in.c
===
--- lto-streamer-in.c   (revision 175350)
+++ lto-streamer-in.c   (working copy)
@@ -1736,18 +1736,7 @@ unpack_ts_function_decl_value_fields (st
   DECL_PURE_P (expr) = (unsigned) bp_unpack_value (bp, 1);
   DECL_LOOPING_CONST_OR_PURE_P (expr) = (unsigned) bp_unpack_value (bp, 1);
   if (DECL_BUILT_IN_CLASS (expr) != NOT_BUILT_IN)
-{
-  DECL_FUNCTION_CODE (expr) = (enum built_in_function) bp_unpack_value 
(bp, 11);
-  if (DECL_BUILT_IN_CLASS (expr) == BUILT_IN_NORMAL
- && DECL_FUNCTION_CODE (expr) >= END_BUILTINS)
-   fatal_error ("machine independent builtin code out of range");
- 

Re: varpool alias reorg

2011-06-24 Thread Jan Hubicka
Hi,
I also tested the attached variant that simply disable the builtins streaming.
It fixes the testcase, too, bootstraps/regtestes x86_64 with and without plugin
and builds mozilla. It also solves the decl sharing problems that leads to
debug info confussion.
However it breaks memops-asm.c testcase.  What testcase does is giving builtlins
asm name (i.e. my_memcpy instead of memcpy) and then it tests that the new calls
to the builtilns introduced via folding actually use these asm names.

The code this patch remove was probably invented specifically for this testcase:
instead of streaming builtin decl like we do all other streaming, we just stream
reference to the builtin + an asm name and the single builtin decl in the
LTO unit gets the name.

The problem is that this won't work when LTOing multiple such units each giving 
a
different asm name (i.e. one of units will win). We can't quite fix this because
we don't want to keep track from where the code we are folding is comming.

So I wonder, do we really need to preserve this behaviour?  
I do not think it is documented anywhere and it seems to me that both variants:
ignoring the asm names or honoring them are sane.

Honza

Index: testsuite/gcc.c-torture/execute/builtins/memops-asm-lib.c
===
*** testsuite/gcc.c-torture/execute/builtins/memops-asm-lib.c   (revision 
175350)
--- testsuite/gcc.c-torture/execute/builtins/memops-asm-lib.c   (working copy)
*** typedef __SIZE_TYPE__ size_t;
*** 6,12 
  
  /* LTO code is at the present to able to track that asm alias my_bcopy on 
builtin
 actually refers to this function.  See PR47181. */
- __attribute__ ((used))
  void *
  my_memcpy (void *d, const void *s, size_t n)
  {
--- 6,11 
*** my_memcpy (void *d, const void *s, size_
*** 19,25 
  
  /* LTO code is at the present to able to track that asm alias my_bcopy on 
builtin
 actually refers to this function.  See PR47181. */
- __attribute__ ((used))
  void
  my_bcopy (const void *s, void *d, size_t n)
  {
--- 18,23 
*** my_bcopy (const void *s, void *d, size_t
*** 39,45 
  
  /* LTO code is at the present to able to track that asm alias my_bcopy on 
builtin
 actually refers to this function.  See PR47181. */
- __attribute__ ((used))
  void *
  my_memset (void *d, int c, size_t n)
  {
--- 37,42 
*** my_memset (void *d, int c, size_t n)
*** 51,57 
  
  /* LTO code is at the present to able to track that asm alias my_bcopy on 
builtin
 actually refers to this function.  See PR47181. */
- __attribute__ ((used))
  void
  my_bzero (void *d, size_t n)
  {
--- 48,53 
Index: lto-streamer-out.c
===
*** lto-streamer-out.c  (revision 175350)
--- lto-streamer-out.c  (working copy)
*** pack_ts_function_decl_value_fields (stru
*** 484,491 
  {
/* For normal/md builtins we only write the class and code, so they
   should never be handled here.  */
-   gcc_assert (!lto_stream_as_builtin_p (expr));
- 
bp_pack_enum (bp, built_in_class, BUILT_IN_LAST,
DECL_BUILT_IN_CLASS (expr));
bp_pack_value (bp, DECL_STATIC_CONSTRUCTOR (expr), 1);
--- 484,489 
*** lto_output_tree_header (struct output_bl
*** 1306,1346 
  }
  
  
- /* Write the code and class of builtin EXPR to output block OB.  IX is
-the index into the streamer cache where EXPR is stored.*/
- 
- static void
- lto_output_builtin_tree (struct output_block *ob, tree expr)
- {
-   gcc_assert (lto_stream_as_builtin_p (expr));
- 
-   if (DECL_BUILT_IN_CLASS (expr) == BUILT_IN_MD
-   && !targetm.builtin_decl)
- sorry ("gimple bytecode streams do not support machine specific builtin "
-  "functions on this target");
- 
-   output_record_start (ob, LTO_builtin_decl);
-   lto_output_enum (ob->main_stream, built_in_class, BUILT_IN_LAST,
-  DECL_BUILT_IN_CLASS (expr));
-   output_uleb128 (ob, DECL_FUNCTION_CODE (expr));
- 
-   if (DECL_ASSEMBLER_NAME_SET_P (expr))
- {
-   /* When the assembler name of a builtin gets a user name,
-the new name is always prefixed with '*' by
-set_builtin_user_assembler_name.  So, to prevent the
-reader side from adding a second '*', we omit it here.  */
-   const char *str = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (expr));
-   if (strlen (str) > 1 && str[0] == '*')
-   lto_output_string (ob, ob->main_stream, &str[1], true);
-   else
-   lto_output_string (ob, ob->main_stream, NULL, true);
- }
-   else
- lto_output_string (ob, ob->main_stream, NULL, true);
- }
- 
- 
  /* Write a physical representation of tree node EXPR to output block
 OB.  If REF_P is true, the leaves of EXPR are emitted as references
 via lto_output_tree_ref.  IX is the index into the streamer cache
--- 1304,1309 
*** lto_output_tree (st

Re: varpool alias reorg

2011-06-23 Thread Jan Hubicka
> On Sat, Jun 18, 2011 at 7:19 AM, H.J. Lu  wrote:
> > On Sat, Jun 18, 2011 at 1:32 AM, Jan Hubicka  wrote:
> >> Hi,
> >> this patch makes symetric changes to varpool as did the prevoius series to 
> >> cgraph.
> >> Basically the aliases are now represented as separate varpool nodes with 
> >> alias reference
> >> to the variable they refer to, with some infrastructure to walk the alias 
> >> references
> >> as needed.
> >>
> >> Bootstrapped/regtested x86_64-linux, comitted.
> >>
> >> Honza
> >>
> >>        * lto-symtab.c (lto_varpool_replace_node): Remove code handling
> >>        extra name aliases.
> >>        (lto_symtab_resolve_can_prevail_p): Likewise.
> >>        (lto_symtab_merge_cgraph_nodes): Update alias_of pointers..
> >>        * cgraphbuild.c (record_reference): Remove extra body alias code.
> >>        (mark_load): Likewise.
> >>        (mark_store): Likewise.
> >>        * cgraph.h (varpool_node): Remove extra_name filed;
> >>        add alias_of and extraname_alias.
> >>        (varpool_create_variable_alias, varpool_for_node_and_aliases): 
> >> Declare.
> >>        (varpool_alias_aliased_node): New inline function.
> >>        (varpool_variable_node): New function.
> >>        * cgraphunit.c (handle_alias_pairs): Handle also variable aliases.
> >>        * ipa-ref.c (ipa_record_reference): Allow aliases on variables.
> >>        * lto-cgraph.c (lto_output_varpool_node): Update streaming.
> >>        (input_varpool_node): Likewise.
> >>        * lto-streamer-out.c (produce_symtab): Remove extra name aliases.
> >>        (varpool_externally_visible_p): Remove extra body alias code.
> >>        (function_and_variable_visibility): Likewise.
> >>        * tree-ssa-structalias.c (associate_varinfo_to_alias_1): New 
> >> function.
> >>        (ipa_pta_execute): Use it.
> >>        * varpool.c (varpool_remove_node): Remove extra name alias code.
> >>        (varpool_mark_needed_node): Likewise.
> >>        (varpool_analyze_pending_decls): Analyze aliases.
> >>        (assemble_aliases): New functoin.
> >>        (varpool_assemble_decl): Use it.
> >>        (varpool_create_variable_alias): New function.
> >>        (varpool_extra_name_alias): Rewrite.
> >>        (varpool_for_node_and_aliases): New function.
> >
> > This caused:
> >
> > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49463
> >
> 
> This patch is incorrect as shown in the PR above.

The builtins/strstr-asm.c is the same issue as I patched some time ago in 
http://gcc.gnu.org/ml/gcc-patches/2010-12/msg00031.html
just in this case the problem remained hidden until now.

Again the problem needs plugin to manifest.

There are two problems here
  1) We do not stream builtin decls and merge them outside lto-symtab (by just
 streaming references to builtins with their asm names).  There is at least
 one extra PR related to this and on my TODO is to simply remove the code.
  2) Aliases within single unit works only when both the alias and the target 
use
 asm name.  This is because internally we store mangled DECL_ASSEMBLER_NAME 
and the
 alias_pair code.
 With LTO this breaks existing code simply because what used to be multiple 
units
 and thus safe is now single LTO unit.

 Dave Korn fixed part of the problem by introducing mangling code into 
lto-symtab
 His code solve similar problems with aliases from the asm code, but it
 did not solve the problem with aliases from LTO units, like here, simply
 because alias pair code bypass the lto-symtab.  One of goals of the 
incorrect patch
 above is to make lto-symtab to do the merging and thus fix this issue (for 
now at
 all decls except for builtins).

 Still it would be good to solve the problem on non-LTO compilation, too.
 We discussed introduction of proper symbol table into GCC at the GCC 
gathering last
 weekend.  It is where I am heading but it will take some time.

Until that happens, I suggest fixing the testcase same was as we already fixed
the memops-asm-lib.c in 4.6 timeframe.

Bootstrapped/regtested x86_64-linux, OK?

Index: strstr-asm-lib.c
===
--- strstr-asm-lib.c(revision 175183)
+++ strstr-asm-lib.c(working copy)
@@ -7,6 +7,7 @@
 extern int inside_main;
 extern const char *p;
 
+__attribute__ ((used))
 char *
 my_strstr (const char *s1, const char *s2)
 {


Re: varpool alias reorg

2011-06-23 Thread H.J. Lu
On Sat, Jun 18, 2011 at 7:19 AM, H.J. Lu  wrote:
> On Sat, Jun 18, 2011 at 1:32 AM, Jan Hubicka  wrote:
>> Hi,
>> this patch makes symetric changes to varpool as did the prevoius series to 
>> cgraph.
>> Basically the aliases are now represented as separate varpool nodes with 
>> alias reference
>> to the variable they refer to, with some infrastructure to walk the alias 
>> references
>> as needed.
>>
>> Bootstrapped/regtested x86_64-linux, comitted.
>>
>> Honza
>>
>>        * lto-symtab.c (lto_varpool_replace_node): Remove code handling
>>        extra name aliases.
>>        (lto_symtab_resolve_can_prevail_p): Likewise.
>>        (lto_symtab_merge_cgraph_nodes): Update alias_of pointers.
>>        * cgraphbuild.c (record_reference): Remove extra body alias code.
>>        (mark_load): Likewise.
>>        (mark_store): Likewise.
>>        * cgraph.h (varpool_node): Remove extra_name filed;
>>        add alias_of and extraname_alias.
>>        (varpool_create_variable_alias, varpool_for_node_and_aliases): 
>> Declare.
>>        (varpool_alias_aliased_node): New inline function.
>>        (varpool_variable_node): New function.
>>        * cgraphunit.c (handle_alias_pairs): Handle also variable aliases.
>>        * ipa-ref.c (ipa_record_reference): Allow aliases on variables.
>>        * lto-cgraph.c (lto_output_varpool_node): Update streaming.
>>        (input_varpool_node): Likewise.
>>        * lto-streamer-out.c (produce_symtab): Remove extra name aliases.
>>        (varpool_externally_visible_p): Remove extra body alias code.
>>        (function_and_variable_visibility): Likewise.
>>        * tree-ssa-structalias.c (associate_varinfo_to_alias_1): New function.
>>        (ipa_pta_execute): Use it.
>>        * varpool.c (varpool_remove_node): Remove extra name alias code.
>>        (varpool_mark_needed_node): Likewise.
>>        (varpool_analyze_pending_decls): Analyze aliases.
>>        (assemble_aliases): New functoin.
>>        (varpool_assemble_decl): Use it.
>>        (varpool_create_variable_alias): New function.
>>        (varpool_extra_name_alias): Rewrite.
>>        (varpool_for_node_and_aliases): New function.
>
> This caused:
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49463
>

This patch is incorrect as shown in the PR above.

-- 
H.J.


Regression with "varpool alias reorg"

2011-06-21 Thread Hans-Peter Nilsson
On Sat, 18 Jun 2011, Jan Hubicka wrote:

>   * lto-symtab.c (lto_varpool_replace_node): Remove code handling
>   extra name aliases.
>   (lto_symtab_resolve_can_prevail_p): Likewise.
>   (lto_symtab_merge_cgraph_nodes): Update alias_of pointers.
>   * cgraphbuild.c (record_reference): Remove extra body alias code.
>   (mark_load): Likewise.
>   (mark_store): Likewise.
>   * cgraph.h (varpool_node): Remove extra_name filed;
>   add alias_of and extraname_alias.
>   (varpool_create_variable_alias, varpool_for_node_and_aliases): Declare.
>   (varpool_alias_aliased_node): New inline function.
>   (varpool_variable_node): New function.
>   * cgraphunit.c (handle_alias_pairs): Handle also variable aliases.
>   * ipa-ref.c (ipa_record_reference): Allow aliases on variables.
>   * lto-cgraph.c (lto_output_varpool_node): Update streaming.
>   (input_varpool_node): Likewise.
>   * lto-streamer-out.c (produce_symtab): Remove extra name aliases.
>   (varpool_externally_visible_p): Remove extra body alias code.
>   (function_and_variable_visibility): Likewise.
>   * tree-ssa-structalias.c (associate_varinfo_to_alias_1): New function.
>   (ipa_pta_execute): Use it.
>   * varpool.c (varpool_remove_node): Remove extra name alias code.
>   (varpool_mark_needed_node): Likewise.
>   (varpool_analyze_pending_decls): Analyze aliases.
>   (assemble_aliases): New functoin.
>   (varpool_assemble_decl): Use it.
>   (varpool_create_variable_alias): New function.
>   (varpool_extra_name_alias): Rewrite.
>   (varpool_for_node_and_aliases): New function.

This caused a regression for emutls targets, see PR49500.

brgds, H-P


Re: varpool alias reorg

2011-06-18 Thread H.J. Lu
On Sat, Jun 18, 2011 at 1:32 AM, Jan Hubicka  wrote:
> Hi,
> this patch makes symetric changes to varpool as did the prevoius series to 
> cgraph.
> Basically the aliases are now represented as separate varpool nodes with 
> alias reference
> to the variable they refer to, with some infrastructure to walk the alias 
> references
> as needed.
>
> Bootstrapped/regtested x86_64-linux, comitted.
>
> Honza
>
>        * lto-symtab.c (lto_varpool_replace_node): Remove code handling
>        extra name aliases.
>        (lto_symtab_resolve_can_prevail_p): Likewise.
>        (lto_symtab_merge_cgraph_nodes): Update alias_of pointers.
>        * cgraphbuild.c (record_reference): Remove extra body alias code.
>        (mark_load): Likewise.
>        (mark_store): Likewise.
>        * cgraph.h (varpool_node): Remove extra_name filed;
>        add alias_of and extraname_alias.
>        (varpool_create_variable_alias, varpool_for_node_and_aliases): Declare.
>        (varpool_alias_aliased_node): New inline function.
>        (varpool_variable_node): New function.
>        * cgraphunit.c (handle_alias_pairs): Handle also variable aliases.
>        * ipa-ref.c (ipa_record_reference): Allow aliases on variables.
>        * lto-cgraph.c (lto_output_varpool_node): Update streaming.
>        (input_varpool_node): Likewise.
>        * lto-streamer-out.c (produce_symtab): Remove extra name aliases.
>        (varpool_externally_visible_p): Remove extra body alias code.
>        (function_and_variable_visibility): Likewise.
>        * tree-ssa-structalias.c (associate_varinfo_to_alias_1): New function.
>        (ipa_pta_execute): Use it.
>        * varpool.c (varpool_remove_node): Remove extra name alias code.
>        (varpool_mark_needed_node): Likewise.
>        (varpool_analyze_pending_decls): Analyze aliases.
>        (assemble_aliases): New functoin.
>        (varpool_assemble_decl): Use it.
>        (varpool_create_variable_alias): New function.
>        (varpool_extra_name_alias): Rewrite.
>        (varpool_for_node_and_aliases): New function.

This caused:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49463

-- 
H.J.


varpool alias reorg

2011-06-18 Thread Jan Hubicka
Hi,
this patch makes symetric changes to varpool as did the prevoius series to 
cgraph.
Basically the aliases are now represented as separate varpool nodes with alias 
reference
to the variable they refer to, with some infrastructure to walk the alias 
references
as needed.

Bootstrapped/regtested x86_64-linux, comitted.

Honza

* lto-symtab.c (lto_varpool_replace_node): Remove code handling
extra name aliases.
(lto_symtab_resolve_can_prevail_p): Likewise.
(lto_symtab_merge_cgraph_nodes): Update alias_of pointers.
* cgraphbuild.c (record_reference): Remove extra body alias code.
(mark_load): Likewise.
(mark_store): Likewise.
* cgraph.h (varpool_node): Remove extra_name filed;
add alias_of and extraname_alias.
(varpool_create_variable_alias, varpool_for_node_and_aliases): Declare.
(varpool_alias_aliased_node): New inline function.
(varpool_variable_node): New function.
* cgraphunit.c (handle_alias_pairs): Handle also variable aliases.
* ipa-ref.c (ipa_record_reference): Allow aliases on variables.
* lto-cgraph.c (lto_output_varpool_node): Update streaming.
(input_varpool_node): Likewise.
* lto-streamer-out.c (produce_symtab): Remove extra name aliases.
(varpool_externally_visible_p): Remove extra body alias code.
(function_and_variable_visibility): Likewise.
* tree-ssa-structalias.c (associate_varinfo_to_alias_1): New function.
(ipa_pta_execute): Use it.
* varpool.c (varpool_remove_node): Remove extra name alias code.
(varpool_mark_needed_node): Likewise.
(varpool_analyze_pending_decls): Analyze aliases.
(assemble_aliases): New functoin.
(varpool_assemble_decl): Use it.
(varpool_create_variable_alias): New function.
(varpool_extra_name_alias): Rewrite.
(varpool_for_node_and_aliases): New function.
Index: lto-symtab.c
===
*** lto-symtab.c(revision 175079)
--- lto-symtab.c(working copy)
*** lto_varpool_replace_node (struct varpool
*** 268,299 
gcc_assert (!vnode->analyzed || prevailing_node->analyzed);
varpool_mark_needed_node (prevailing_node);
  }
-   /* Relink aliases.  */
-   if (vnode->extra_name && !vnode->alias)
- {
-   struct varpool_node *alias, *last;
-   for (alias = vnode->extra_name;
-  alias; alias = alias->next)
-   {
- last = alias;
- alias->extra_name = prevailing_node;
-   }
- 
-   if (prevailing_node->extra_name)
-   {
- last->next = prevailing_node->extra_name;
- prevailing_node->extra_name->prev = last;
-   }
-   prevailing_node->extra_name = vnode->extra_name;
-   vnode->extra_name = NULL;
- }
gcc_assert (!vnode->finalized || prevailing_node->finalized);
gcc_assert (!vnode->analyzed || prevailing_node->analyzed);
  
-   /* When replacing by an alias, the references goes to the original
-  variable.  */
-   if (prevailing_node->alias && prevailing_node->extra_name)
- prevailing_node = prevailing_node->extra_name;
ipa_clone_refering (NULL, prevailing_node, &vnode->ref_list);
  
/* Be sure we can garbage collect the initializer.  */
--- 268,276 
*** lto_symtab_resolve_can_prevail_p (lto_sy
*** 445,451 
return false;
if (e->vnode->finalized)
return true;
-   return e->vnode->alias && e->vnode->extra_name->finalized;
  }
  
gcc_unreachable ();
*** void
*** 779,784 
--- 755,761 
  lto_symtab_merge_cgraph_nodes (void)
  {
struct cgraph_node *node;
+   struct varpool_node *vnode;
lto_symtab_maybe_init_hash_table ();
htab_traverse (lto_symtab_identifiers, lto_symtab_merge_cgraph_nodes_1, 
NULL);
  
*** lto_symtab_merge_cgraph_nodes (void)
*** 786,791 
--- 763,771 
  if ((node->thunk.thunk_p || node->alias)
&& node->thunk.alias)
node->thunk.alias = lto_symtab_prevailing_decl (node->thunk.alias);
+   for (vnode = varpool_nodes; vnode; vnode = vnode->next)
+ if (vnode->alias_of)
+   vnode->alias_of = lto_symtab_prevailing_decl (vnode->alias_of);
  }
  
  /* Given the decl DECL, return the prevailing decl with the same name. */
Index: cgraphbuild.c
===
*** cgraphbuild.c   (revision 175079)
--- cgraphbuild.c   (working copy)
*** record_reference (tree *tp, int *walk_su
*** 87,94 
  if (lang_hooks.callgraph.analyze_expr)
lang_hooks.callgraph.analyze_expr (&decl, walk_subtrees);
  varpool_mark_needed_node (vnode);
- if (vnode->alias && vnode->extra_name)
-   vnode = vnode->extra_name;
  ipa_record_reference (NULL, ctx->varpool_node,
NULL, vnode,