Add a target hook for assembling undeclared decls.
authorBernd Schmidt <bernds@codesourcery.com>
Mon, 10 Nov 2014 16:12:21 +0000 (16:12 +0000)
committerBernd Schmidt <bernds@gcc.gnu.org>
Mon, 10 Nov 2014 16:12:21 +0000 (16:12 +0000)
* target.def (assemble_undefined_decl): New hooks.
* hooks.c (hook_void_FILEptr_constcharptr_const_tree): New function.
* hooks.h (hook_void_FILEptr_constcharptr_const_tree): Declare.
* doc/tm.texi.in (TARGET_ASM_ASSEMBLE_UNDEFINED_DECL): Add.
* doc/tm.texi: Regenerate.
* output.h (assemble_undefined_decl): Declare.
(get_fnname_from_decl): Declare.
* varasm.c (assemble_undefined_decl): New function.
(get_fnname_from_decl): New function.
* final.c (rest_of_handle_final): Use it.
* varpool.c (varpool_output_variables): Call assemble_undefined_decl
for nodes without a definition.

From-SVN: r217293

gcc/ChangeLog
gcc/doc/tm.texi
gcc/doc/tm.texi.in
gcc/final.c
gcc/hooks.c
gcc/hooks.h
gcc/output.h
gcc/target.def
gcc/varasm.c
gcc/varpool.c

index c49af15ca6bae0750fff4b976f56819badd3bba2..4dc83d3f5ad9c8e232ff945939725cbae2c65254 100644 (file)
 
 2014-11-06  Bernd Schmidt  <bernds@codesourcery.com>
 
+       * target.def (assemble_undefined_decl): New hooks.
+       * hooks.c (hook_void_FILEptr_constcharptr_const_tree): New function.
+       * hooks.h (hook_void_FILEptr_constcharptr_const_tree): Declare.
+       * doc/tm.texi.in (TARGET_ASM_ASSEMBLE_UNDEFINED_DECL): Add.
+       * doc/tm.texi: Regenerate.
+       * output.h (assemble_undefined_decl): Declare.
+       (get_fnname_from_decl): Declare.
+       * varasm.c (assemble_undefined_decl): New function.
+       (get_fnname_from_decl): New function.
+       * final.c (rest_of_handle_final): Use it.
+       * varpool.c (varpool_output_variables): Call assemble_undefined_decl
+       for nodes without a definition.
+
        * target.def (call_args, end_call_args): New hooks.
        * hooks.c (hook_void_rtx_tree): New empty function.
        * hooks.h (hook_void_rtx_tree): Declare.
index a55206d6c051d6781615ed8e980e599426423d93..33a5a9744e551b121d757957e158ac5c7aa7992d 100644 (file)
@@ -7896,6 +7896,13 @@ global; that is, available for reference from other files.
 The default implementation uses the TARGET_ASM_GLOBALIZE_LABEL target hook.
 @end deftypefn
 
+@deftypefn {Target Hook} void TARGET_ASM_ASSEMBLE_UNDEFINED_DECL (FILE *@var{stream}, const char *@var{name}, const_tree @var{decl})
+This target hook is a function to output to the stdio stream
+@var{stream} some commands that will declare the name associated with
+@var{decl} which is not defined in the current translation unit.  Most
+assemblers do not require anything to be output in this case.
+@end deftypefn
+
 @defmac ASM_WEAKEN_LABEL (@var{stream}, @var{name})
 A C statement (sans semicolon) to output to the stdio stream
 @var{stream} some commands that will make the label @var{name} weak;
index e0c52c8a37a084c05afae532e7f54d2ce0839bd8..068aa31ba3269ad64a0e575e6071b4a89b8bea31 100644 (file)
@@ -5606,6 +5606,8 @@ You may wish to use @code{ASM_OUTPUT_SIZE_DIRECTIVE} and/or
 
 @hook TARGET_ASM_GLOBALIZE_DECL_NAME
 
+@hook TARGET_ASM_ASSEMBLE_UNDEFINED_DECL
+
 @defmac ASM_WEAKEN_LABEL (@var{stream}, @var{name})
 A C statement (sans semicolon) to output to the stdio stream
 @var{stream} some commands that will make the label @var{name} weak;
index e958a5202462dfcfc96d06a43a59daac27edae88..c3805c9e283c68775ce0e7adfbf8cf8d6c8609b1 100644 (file)
@@ -4468,17 +4468,7 @@ leaf_renumber_regs_insn (rtx in_rtx)
 static unsigned int
 rest_of_handle_final (void)
 {
-  rtx x;
-  const char *fnname;
-
-  /* Get the function's name, as described by its RTL.  This may be
-     different from the DECL_NAME name used in the source file.  */
-
-  x = DECL_RTL (current_function_decl);
-  gcc_assert (MEM_P (x));
-  x = XEXP (x, 0);
-  gcc_assert (GET_CODE (x) == SYMBOL_REF);
-  fnname = XSTR (x, 0);
+  const char *fnname = get_fnname_from_decl (current_function_decl);
 
   assemble_start_function (current_function_decl, fnname);
   final_start_function (get_insns (), asm_out_file, optimize);
index 91e17cd70c2be987f238070638cd67bed17388ae..356c64c9d928bc8942d8e46704615138d8ac14f4 100644 (file)
@@ -139,6 +139,13 @@ hook_void_FILEptr_constcharptr (FILE *a ATTRIBUTE_UNUSED, const char *b ATTRIBUT
 {
 }
 
+/* Generic hook that takes (FILE *, const char *, constr_tree *) and does
+   nothing.  */
+void
+hook_void_FILEptr_constcharptr_const_tree (FILE *, const char *, const_tree)
+{
+}
+
 /* Generic hook that takes (FILE *, rtx) and returns false.  */
 bool
 hook_bool_FILEptr_rtx_false (FILE *a ATTRIBUTE_UNUSED,
index 4006cad3412cb9a0aeedb279210c6bd4788649dd..5e4f95b0f0aa3844c39fe6c33cc4a8888d6dc291 100644 (file)
@@ -70,6 +70,8 @@ extern void hook_void_void (void);
 extern void hook_void_constcharptr (const char *);
 extern void hook_void_rtx_insn_int (rtx_insn *, int);
 extern void hook_void_FILEptr_constcharptr (FILE *, const char *);
+extern void hook_void_FILEptr_constcharptr_const_tree (FILE *, const char *,
+                                                      const_tree);
 extern bool hook_bool_FILEptr_rtx_false (FILE *, rtx);
 extern void hook_void_rtx_tree (rtx, tree);
 extern void hook_void_tree (tree);
index f213b9964297eebe5e47b1077018a81e03b73233..e19fdd3f42b2a8ea02e22db4568b68b814c51c5e 100644 (file)
@@ -178,6 +178,9 @@ extern void default_assemble_visibility (tree, int);
    for an `asm' keyword used between functions.  */
 extern void assemble_asm (tree);
 
+/* Get the function's name from a decl, as described by its RTL.  */
+extern const char *get_fnname_from_decl (tree);
+
 /* Output assembler code for the constant pool of a function and associated
    with defining the name of the function.  DECL describes the function.
    NAME is the function's name.  For the constant pool, we use the current
@@ -203,6 +206,10 @@ extern void assemble_variable (tree, int, int, int);
    into the preinit array.  */
 extern void assemble_vtv_preinit_initializer (tree);
 
+/* Assemble everything that is needed for a variable declaration that has
+   no definition in the current translation unit.  */
+extern void assemble_undefined_decl (tree);
+
 /* Compute the alignment of variable specified by DECL.
    DONT_OUTPUT_DATA is from assemble_variable.  */
 extern void align_variable (tree decl, bool dont_output_data);
index d6198ad3569ca94605b611f2fec170d74509677d..b2fe47b806653685f03793e73fbdc62f8cbb4db7 100644 (file)
@@ -158,6 +158,16 @@ global; that is, available for reference from other files.\n\
 The default implementation uses the TARGET_ASM_GLOBALIZE_LABEL target hook.",
  void, (FILE *stream, tree decl), default_globalize_decl_name)
 
+/* Output code that will declare an external variable.  */
+DEFHOOK
+(assemble_undefined_decl,
+ "This target hook is a function to output to the stdio stream\n\
+@var{stream} some commands that will declare the name associated with\n\
+@var{decl} which is not defined in the current translation unit.  Most\n\
+assemblers do not require anything to be output in this case.",
+ void, (FILE *stream, const char *name, const_tree decl),
+ hook_void_FILEptr_constcharptr_const_tree)
+
 /* Output code that will emit a label for unwind info, if this
    target requires such labels.  Second argument is the decl the
    unwind info is associated with, third is a boolean: true if
index 8d857a4bc9a41dd01b5371975d9e3b20a856a0b8..54611f8fd3f17a035eb3befbc606a6ce311fc7de 100644 (file)
@@ -1673,6 +1673,18 @@ decide_function_section (tree decl)
   in_cold_section_p = first_function_block_is_cold;
 }
 
+/* Get the function's name, as described by its RTL.  This may be
+   different from the DECL_NAME name used in the source file.  */
+const char *
+get_fnname_from_decl (tree decl)
+{
+  rtx x = DECL_RTL (decl);
+  gcc_assert (MEM_P (x));
+  x = XEXP (x, 0);
+  gcc_assert (GET_CODE (x) == SYMBOL_REF);
+  return XSTR (x, 0);
+}
+
 /* Output assembler code for the constant pool of a function and associated
    with defining the name of the function.  DECL describes the function.
    NAME is the function's name.  For the constant pool, we use the current
@@ -2045,6 +2057,15 @@ assemble_variable_contents (tree decl, const char *name,
     }
 }
 
+/* Write out assembly for the variable DECL, which is not defined in
+   the current translation unit.  */
+void
+assemble_undefined_decl (tree decl)
+{
+  const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
+  targetm.asm_out.assemble_undefined_decl (asm_out_file, name, decl);
+}
+
 /* Assemble everything that is needed for a variable or function declaration.
    Not used for automatic variables, and not used for function definitions.
    Should not be called for variables of incomplete structure type.
index 5bfb0a7c8676d6ed03eb9c5b3f9ac11aa0729cdf..ac7abc1be86b10491844a6b4cfa4cb23ed8738eb 100644 (file)
@@ -707,6 +707,9 @@ symbol_table::output_variables (void)
 
   timevar_push (TV_VAROUT);
 
+  FOR_EACH_VARIABLE (node)
+    if (!node->definition)
+      assemble_undefined_decl (node->decl);
   FOR_EACH_DEFINED_VARIABLE (node)
     {
       /* Handled in output_in_order.  */