This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [LTO merge] gimplification of types and symbols [2/2]


On Wed, Sep 2, 2009 at 13:49, Jason Merrill<jason@redhat.com> wrote:
> On 09/02/2009 01:26 PM, Diego Novillo wrote:
>>
>> @@ -282,6 +282,8 @@ decl_is_template_id (const tree decl, tr
>> Â Â Â Â/* Check if this is a primary template. Â*/
>> Â Â Â Âif (DECL_LANG_SPECIFIC (decl) != NULL
>> Â Â Â Â&& ÂDECL_USE_TEMPLATE (decl)
>> + Â Â Â && ÂTREE_CODE (DECL_TI_TEMPLATE (decl)) != OVERLOAD
>> + Â Â Â && ÂTREE_CODE (DECL_TI_TEMPLATE (decl)) != IDENTIFIER_NODE
>> Â Â Â Â&& ÂPRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (decl))
>> Â Â Â Â&& ÂTREE_CODE (decl) != TEMPLATE_DECL)
>> Â Â Â Â{
>
> This hunk should be able to go away, too. ÂIf not, as Mark says, we have a
> bug.

Yes.  This is no longer needed.  I just re-tested with no new
regressions.  The C++ hunks that I'm planning to commit are below.

OK for mainline?


Thanks.  Diego.

cp/ChangeLog

2009-09-01  Doug Kwan  <dougkwan@google.com>

       * tree.c (cp_fix_function_decl_p): New.
       (cp_free_lang_data): New.

2009-09-01  Diego Novillo  <dnovillo@google.com>

       * Make-lang.in (decl2.o): Add dependency on $(POINTER_SET_H).
       * decl2.c: Include pointer-set.h.
       (collect_candidates_for_java_method_aliases): New.
       (cp_write_global_declarations): Call it.
       Add local variable CANDIDATES.  If set, call
       build_java_method_aliases.
       (build_java_method_aliases): Add argument CANDIDATES.
       Use it to determine if FNDECL should get a hidden alias.
       * cp-objcp-common.h (LANG_HOOKS_FREE_LANG_DATA): Define.
       * cp-tree.h (cp_free_lang_data): Declare.

Index: cp/Make-lang.in
===================================================================
--- cp/Make-lang.in	(revision 151295)
+++ cp/Make-lang.in	(working copy)
@@ -257,7 +257,7 @@ cp/decl.o: cp/decl.c $(CXX_TREE_H) $(TM_
   debug.h gt-cp-decl.h $(TIMEVAR_H) $(TREE_FLOW_H) $(TARGET_H) $(PLUGIN_H)
 cp/decl2.o: cp/decl2.c $(CXX_TREE_H) $(TM_H) $(FLAGS_H) cp/decl.h $(EXPR_H) \
   output.h except.h toplev.h $(RTL_H) $(C_COMMON_H) gt-cp-decl2.h $(CGRAPH_H) \
-  $(C_PRAGMA_H) $(TREE_DUMP_H) intl.h $(TARGET_H) $(GIMPLE_H)
+  $(C_PRAGMA_H) $(TREE_DUMP_H) intl.h $(TARGET_H) $(GIMPLE_H) $(POINTER_SET_H)
 cp/cp-objcp-common.o : cp/cp-objcp-common.c $(CONFIG_H) $(SYSTEM_H) \
   coretypes.h $(TM_H) $(TREE_H) $(CXX_TREE_H) $(C_COMMON_H) toplev.h \
   langhooks.h $(LANGHOOKS_DEF_H) $(DIAGNOSTIC_H) debug.h \
Index: cp/tree.c
===================================================================
--- cp/tree.c	(revision 151295)
+++ cp/tree.c	(working copy)
@@ -3030,6 +3030,53 @@ cast_valid_in_integral_constant_expressi
 	  || type == error_mark_node);
 }

+/* Return true if we need to fix linkage information of DECL.  */
+
+static bool
+cp_fix_function_decl_p (tree decl)
+{
+  /* Skip if DECL is not externally visible.  */
+  if (!TREE_PUBLIC (decl))
+    return false;
+
+  /* We need to fix DECL if it a appears to be exported but with no
+     function body.  Thunks do not have CFGs and we may need to
+     handle them specially later.   */
+  if (!gimple_has_body_p (decl)
+      && !DECL_THUNK_P (decl)
+      && !DECL_EXTERNAL (decl))
+    return true;
+
+  return false;
+}
+
+/* Clean the C++ specific parts of the tree T. */
+
+void
+cp_free_lang_data (tree t)
+{
+  if (TREE_CODE (t) == METHOD_TYPE
+      || TREE_CODE (t) == FUNCTION_TYPE)
+    {
+      /* Default args are not interesting anymore.  */
+      tree argtypes = TYPE_ARG_TYPES (t);
+      while (argtypes)
+        {
+	  TREE_PURPOSE (argtypes) = 0;
+	  argtypes = TREE_CHAIN (argtypes);
+	}
+    }
+  else if (TREE_CODE (t) == FUNCTION_DECL
+	   && cp_fix_function_decl_p (t))
+    {
+      /* If T is used in this translation unit at all,  the definition
+	 must exist somewhere else since we have decided to not emit it
+	 in this TU.  So make it an external reference.  */
+      DECL_EXTERNAL (t) = 1;
+      TREE_STATIC (t) = 0;
+    }
+}
+
 
 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
 /* Complain that some language-specific thing hanging off a tree
Index: cp/cp-lang.c
===================================================================
--- cp/cp-lang.c	(revision 151295)
+++ cp/cp-lang.c	(working copy)
@@ -73,7 +73,7 @@ static enum classify_record cp_classify_
 #define LANG_HOOKS_INIT_TS cp_init_ts

 /* Each front end provides its own lang hook initializer.  */
-const struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
+struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;

 /* Lang hook routines common to C++ and ObjC++ appear in cp/cp-objcp-common.c;
    there should be very few routines below.  */
Index: cp/semantics.c
===================================================================
--- cp/semantics.c	(revision 151295)
+++ cp/semantics.c	(working copy)
@@ -3186,7 +3186,9 @@ emit_associated_thunks (tree fn)
      is so that you can know statically the entire set of thunks that
      will ever be needed for a given virtual function, thereby
      enabling you to output all the thunks with the function itself.  */
-  if (DECL_VIRTUAL_P (fn))
+  if (DECL_VIRTUAL_P (fn)
+      /* Do not emit thunks for extern template instantiations.  */
+      && ! DECL_REALLY_EXTERN (fn))
     {
       tree thunk;

Index: cp/decl2.c
===================================================================
--- cp/decl2.c	(revision 151295)
+++ cp/decl2.c	(working copy)
@@ -52,6 +52,7 @@ along with GCC; see the file COPYING3.
 #include "tree-dump.h"
 #include "intl.h"
 #include "gimple.h"
+#include "pointer-set.h"

 extern cpp_reader *parse_in;

@@ -3288,27 +3289,60 @@ cxx_callgraph_analyze_expr (tree *tp, in

 /* 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.  */
+   supported, collect and return all the functions for which we should
+   emit a hidden alias.  */

-static void
-build_java_method_aliases (void)
+static struct pointer_set_t *
+collect_candidates_for_java_method_aliases (void)
 {
   struct cgraph_node *node;
+  struct pointer_set_t *candidates = NULL;

 #ifndef HAVE_GAS_HIDDEN
-  return;
+  return candidates;
 #endif

   for (node = cgraph_nodes; node ; node = node->next)
     {
       tree fndecl = node->decl;

-      if (TREE_ASM_WRITTEN (fndecl)
-	  && DECL_CONTEXT (fndecl)
+      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);
+	}
+    }
+
+  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 (node = cgraph_nodes; node ; node = node->next)
+    {
+      tree fndecl = node->decl;
+
+      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;
@@ -3379,6 +3413,7 @@ 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;
@@ -3676,6 +3711,9 @@ cp_write_global_declarations (void)
      linkage now.  */
   pop_lang_context ();

+  /* Collect candidates for Java hidden aliases.  */
+  candidates = collect_candidates_for_java_method_aliases ();
+
   cgraph_finalize_compilation_unit ();

   /* Now, issue warnings about static, but not defined, functions,
@@ -3690,7 +3728,11 @@ cp_write_global_declarations (void)
     }

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

   finish_repo ();

Index: cp/cp-objcp-common.h
===================================================================
--- cp/cp-objcp-common.h	(revision 151295)
+++ cp/cp-objcp-common.h	(working copy)
@@ -32,6 +32,8 @@ extern bool cp_function_decl_explicit_p
    specific to C++ or ObjC++ go in cp/cp-lang.c and objcp/objcp-lang.c,
    respectively.  */

+#undef LANG_HOOKS_FREE_LANG_DATA
+#define LANG_HOOKS_FREE_LANG_DATA cp_free_lang_data
 #undef LANG_HOOKS_TREE_SIZE
 #define LANG_HOOKS_TREE_SIZE cp_tree_size
 #undef LANG_HOOKS_FINISH
Index: cp/cp-tree.h
===================================================================
--- cp/cp-tree.h	(revision 151295)
+++ cp/cp-tree.h	(working copy)
@@ -4888,6 +4888,7 @@ extern tree finish_decltype_type
 extern tree finish_trait_expr			(enum cp_trait_kind, tree, tree);

 /* in tree.c */
+void cp_free_lang_data 				(tree t);
 extern tree force_target_expr			(tree, tree);
 extern tree build_target_expr_with_type		(tree, tree);
 extern void lang_check_failed			(const char *, int,


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]