public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Steven Bosscher <stevenb.gcc@gmail.com>
To: Richard Guenther <richard.guenther@gmail.com>, Jan Hubicha <jh@suse.cz>
Cc: GCC Mailing List <gcc@gcc.gnu.org>,
	GCC Patches list <gcc-patches@gcc.gnu.org>
Subject: Re: [patch][RFC] bail out after front-end errors
Date: Fri, 28 Dec 2012 17:36:00 -0000	[thread overview]
Message-ID: <CABu31nNawk1bKmVVp6f8TGAJaQMCUhh25HOEB7Suu8kamAeHrQ@mail.gmail.com> (raw)
In-Reply-To: <CAFiYyc0S4358PFGyzJjqe_Uw=H-DmGH4n+C=AvO1Xx-nQOLD9A@mail.gmail.com>

On Tue, Mar 27, 2012 at 10:59 AM, Richard Guenther wrote:
> On Tue, Mar 27, 2012 at 10:32 AM, Steven Bosscher  wrote:
>> On Tue, Mar 27, 2012 at 9:17 AM, Richard Guenther wrote:
>>> It would be nice to finally move
>>> the call to cgraph_finalize_compilation_unit to the middle-end ...
>>> (warning, if you try that you run into an issue with the Java frontend ... :/)
>>
>> Do you remember what issues that causes? I'm running into a great
>> number of issues there already with some varasm fixes (basically just
>> cleanups for the tree-ssa and unit-at-a-time era we're supposed to
>> live in - except Java).
>
> I think it was the
>
>   /* Generate hidden aliases for Java.  */
>   if (candidates)
>     {
>       build_java_method_aliases (candidates);
>       pointer_set_destroy (candidates);
>     }
>
> hunk in cp_write_global_declarations that does not work when run
> before cgraph_finalize_compilation_unit
> (I simply tried to move that call out of, and after calling the
> langhook).  So the problem materialized when
> building libjava I think.

Hello,

Coming back to this issue...  Attached patch is an attempt to resolve
this part of the finalize_compilation_unit problem. Instead of
emitting aliases with assemble_alias after finalize_compilation_unit,
this patch uses cgraph_same_body_alias before it.

Bootstrapped&tested on powerpc64-unknown-linux-gnu.
Richi, Honza, does this make sense?

Ciao!
Steven

cp/
	* decl2.c (collect_candidates_for_java_method_aliases): Remove.
	(build_java_method_aliases): Rewrite to emit the aliases via the
	cgraphunit machinery.
	(cp_write_global_declarations): Adjust for abovementioned changes.

Index: cp/decl2.c
===================================================================
--- cp/decl2.c	(revision 194725)
+++ cp/decl2.c	(working copy)
stevenb@stevenb-laptop:~$ cat devel/java_method_aliases.diff
cp/
	* decl2.c (collect_candidates_for_java_method_aliases): Remove.
	(build_java_method_aliases): Rewrite to emit the aliases via the
	cgraphunit machinery.
	(cp_write_global_declarations): Adjust for abovementioned changes.

Index: cp/decl2.c
===================================================================
--- cp/decl2.c	(revision 194725)
+++ cp/decl2.c	(working copy)
@@ -3615,79 +3615,53 @@ generate_ctor_and_dtor_functions_for_priority (spl

 /* Java requires that we be able to reference a local address for a
    method, and not be confused by PLT entries.  If hidden aliases are
-   supported, collect and return all the functions for which we should
+   supported, emit one for each java function that we've emitted.
    emit a hidden alias.  */

-static struct pointer_set_t *
-collect_candidates_for_java_method_aliases (void)
+static void
+build_java_method_aliases (void)
 {
+#ifdef HAVE_GAS_HIDDEN
   struct cgraph_node *node;
-  struct pointer_set_t *candidates = NULL;
+  tree fndecl;
+  vec<tree> candidates = vNULL;
+  unsigned int ix;

-#ifndef HAVE_GAS_HIDDEN
-  return candidates;
-#endif
-
+  /* First collect all candidates.  We cannot create the aliases
+     in place, it confuses the FOR_EACH_FUNCTION iterator.  */
   FOR_EACH_FUNCTION (node)
     {
-      tree fndecl = node->symbol.decl;
-
+      fndecl = node->symbol.decl;
       if (DECL_CONTEXT (fndecl)
 	  && TYPE_P (DECL_CONTEXT (fndecl))
 	  && TYPE_FOR_JAVA (DECL_CONTEXT (fndecl))
 	  && TARGET_USE_LOCAL_THUNK_ALIAS_P (fndecl))
-	{
-	  if (candidates == NULL)
-	    candidates = pointer_set_create ();
-	  pointer_set_insert (candidates, fndecl);
-	}
+	candidates.safe_push (fndecl);
     }

-  return candidates;
-}
-
-
-/* Java requires that we be able to reference a local address for a
-   method, and not be confused by PLT entries.  If hidden aliases are
-   supported, emit one for each java function that we've emitted.
-   CANDIDATES is the set of FUNCTION_DECLs that were gathered
-   by collect_candidates_for_java_method_aliases.  */
-
-static void
-build_java_method_aliases (struct pointer_set_t *candidates)
-{
-  struct cgraph_node *node;
-
-#ifndef HAVE_GAS_HIDDEN
-  return;
-#endif
-
-  FOR_EACH_FUNCTION (node)
+  /* Now add the aliases for the candidates collected above.
+     Mangle the name in a predictable way; we need to reference
+     this from a java compiled object file.  */
+  FOR_EACH_VEC_ELT (candidates, ix, fndecl)
     {
-      tree fndecl = node->symbol.decl;
+      tree oid, nid, alias;
+      const char *oname;
+      char *nname;

-      if (TREE_ASM_WRITTEN (fndecl)
-	  && pointer_set_contains (candidates, fndecl))
-	{
-	  /* Mangle the name in a predictable way; we need to reference
-	     this from a java compiled object file.  */
-	  tree oid, nid, alias;
-	  const char *oname;
-	  char *nname;
+      oid = DECL_ASSEMBLER_NAME (fndecl);
+      oname = IDENTIFIER_POINTER (oid);
+      gcc_assert (oname[0] == '_' && oname[1] == 'Z');
+      nname = ACONCAT (("_ZGA", oname+2, NULL));
+      nid = get_identifier (nname);

-	  oid = DECL_ASSEMBLER_NAME (fndecl);
-	  oname = IDENTIFIER_POINTER (oid);
-	  gcc_assert (oname[0] == '_' && oname[1] == 'Z');
-	  nname = ACONCAT (("_ZGA", oname+2, NULL));
-	  nid = get_identifier (nname);
-
-	  alias = make_alias_for (fndecl, nid);
-	  TREE_PUBLIC (alias) = 1;
-	  DECL_VISIBILITY (alias) = VISIBILITY_HIDDEN;
-
-	  assemble_alias (alias, oid);
-	}
+      alias = make_alias_for (fndecl, nid);
+      TREE_PUBLIC (alias) = 1;
+      DECL_VISIBILITY (alias) = VISIBILITY_HIDDEN;
+      node = cgraph_same_body_alias (NULL, alias, fndecl);
+      gcc_assert (node);
     }
+#endif
+  return;
 }

 /* Return C++ property of T, based on given operation OP.  */
@@ -3933,7 +3907,6 @@ cp_write_global_declarations (void)
   unsigned ssdf_count = 0;
   int retries = 0;
   tree decl;
-  struct pointer_set_t *candidates;

   locus = input_location;
   at_eof = 1;
@@ -4282,8 +4255,8 @@ cp_write_global_declarations (void)
      linkage now.  */
   pop_lang_context ();

-  /* Collect candidates for Java hidden aliases.  */
-  candidates = collect_candidates_for_java_method_aliases ();
+  /* Generate hidden aliases for Java.  */
+  build_java_method_aliases ();

   timevar_stop (TV_PHASE_DEFERRED);
   timevar_start (TV_PHASE_OPT_GEN);
@@ -4306,13 +4279,6 @@ cp_write_global_declarations (void)

   perform_deferred_noexcept_checks ();

-  /* Generate hidden aliases for Java.  */
-  if (candidates)
-    {
-      build_java_method_aliases (candidates);
-      pointer_set_destroy (candidates);
-    }
-
   finish_repo ();

   /* The entire file is now complete.  If requested, dump everything

  parent reply	other threads:[~2012-12-28 17:36 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-26 20:56 Steven Bosscher
2012-03-27  7:17 ` Richard Guenther
2012-03-27  9:50   ` Paolo Carlini
     [not found]   ` <CABu31nOcM81G89w4G2LKn0KoSNamLpgTO07YjZm=-9a94CQttA@mail.gmail.com>
     [not found]     ` <CAFiYyc0S4358PFGyzJjqe_Uw=H-DmGH4n+C=AvO1Xx-nQOLD9A@mail.gmail.com>
2012-12-28 17:36       ` Steven Bosscher [this message]
2013-01-02 15:07         ` Richard Biener
2012-03-27 19:00 ` Mike Stump
2012-03-27 19:13   ` 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=CABu31nNawk1bKmVVp6f8TGAJaQMCUhh25HOEB7Suu8kamAeHrQ@mail.gmail.com \
    --to=stevenb.gcc@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=gcc@gcc.gnu.org \
    --cc=jh@suse.cz \
    --cc=richard.guenther@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).