Commit 0d4b5b86 by Bernd Schmidt Committed by Bernd Schmidt

Add a target hook for assembling undeclared decls.

	* 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
parent 42fd12b1
...@@ -272,6 +272,19 @@ ...@@ -272,6 +272,19 @@
2014-11-06 Bernd Schmidt <bernds@codesourcery.com> 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. * target.def (call_args, end_call_args): New hooks.
* hooks.c (hook_void_rtx_tree): New empty function. * hooks.c (hook_void_rtx_tree): New empty function.
* hooks.h (hook_void_rtx_tree): Declare. * hooks.h (hook_void_rtx_tree): Declare.
...@@ -7896,6 +7896,13 @@ global; that is, available for reference from other files. ...@@ -7896,6 +7896,13 @@ global; that is, available for reference from other files.
The default implementation uses the TARGET_ASM_GLOBALIZE_LABEL target hook. The default implementation uses the TARGET_ASM_GLOBALIZE_LABEL target hook.
@end deftypefn @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}) @defmac ASM_WEAKEN_LABEL (@var{stream}, @var{name})
A C statement (sans semicolon) to output to the stdio stream A C statement (sans semicolon) to output to the stdio stream
@var{stream} some commands that will make the label @var{name} weak; @var{stream} some commands that will make the label @var{name} weak;
......
...@@ -5606,6 +5606,8 @@ You may wish to use @code{ASM_OUTPUT_SIZE_DIRECTIVE} and/or ...@@ -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_GLOBALIZE_DECL_NAME
@hook TARGET_ASM_ASSEMBLE_UNDEFINED_DECL
@defmac ASM_WEAKEN_LABEL (@var{stream}, @var{name}) @defmac ASM_WEAKEN_LABEL (@var{stream}, @var{name})
A C statement (sans semicolon) to output to the stdio stream A C statement (sans semicolon) to output to the stdio stream
@var{stream} some commands that will make the label @var{name} weak; @var{stream} some commands that will make the label @var{name} weak;
......
...@@ -4468,17 +4468,7 @@ leaf_renumber_regs_insn (rtx in_rtx) ...@@ -4468,17 +4468,7 @@ leaf_renumber_regs_insn (rtx in_rtx)
static unsigned int static unsigned int
rest_of_handle_final (void) rest_of_handle_final (void)
{ {
rtx x; const char *fnname = get_fnname_from_decl (current_function_decl);
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);
assemble_start_function (current_function_decl, fnname); assemble_start_function (current_function_decl, fnname);
final_start_function (get_insns (), asm_out_file, optimize); final_start_function (get_insns (), asm_out_file, optimize);
......
...@@ -139,6 +139,13 @@ hook_void_FILEptr_constcharptr (FILE *a ATTRIBUTE_UNUSED, const char *b ATTRIBUT ...@@ -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. */ /* Generic hook that takes (FILE *, rtx) and returns false. */
bool bool
hook_bool_FILEptr_rtx_false (FILE *a ATTRIBUTE_UNUSED, hook_bool_FILEptr_rtx_false (FILE *a ATTRIBUTE_UNUSED,
......
...@@ -70,6 +70,8 @@ extern void hook_void_void (void); ...@@ -70,6 +70,8 @@ extern void hook_void_void (void);
extern void hook_void_constcharptr (const char *); extern void hook_void_constcharptr (const char *);
extern void hook_void_rtx_insn_int (rtx_insn *, int); 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 (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 bool hook_bool_FILEptr_rtx_false (FILE *, rtx);
extern void hook_void_rtx_tree (rtx, tree); extern void hook_void_rtx_tree (rtx, tree);
extern void hook_void_tree (tree); extern void hook_void_tree (tree);
......
...@@ -178,6 +178,9 @@ extern void default_assemble_visibility (tree, int); ...@@ -178,6 +178,9 @@ extern void default_assemble_visibility (tree, int);
for an `asm' keyword used between functions. */ for an `asm' keyword used between functions. */
extern void assemble_asm (tree); 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 /* Output assembler code for the constant pool of a function and associated
with defining the name of the function. DECL describes the function. 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 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); ...@@ -203,6 +206,10 @@ extern void assemble_variable (tree, int, int, int);
into the preinit array. */ into the preinit array. */
extern void assemble_vtv_preinit_initializer (tree); 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. /* Compute the alignment of variable specified by DECL.
DONT_OUTPUT_DATA is from assemble_variable. */ DONT_OUTPUT_DATA is from assemble_variable. */
extern void align_variable (tree decl, bool dont_output_data); extern void align_variable (tree decl, bool dont_output_data);
......
...@@ -158,6 +158,16 @@ global; that is, available for reference from other files.\n\ ...@@ -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.", The default implementation uses the TARGET_ASM_GLOBALIZE_LABEL target hook.",
void, (FILE *stream, tree decl), default_globalize_decl_name) 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 /* Output code that will emit a label for unwind info, if this
target requires such labels. Second argument is the decl the target requires such labels. Second argument is the decl the
unwind info is associated with, third is a boolean: true if unwind info is associated with, third is a boolean: true if
......
...@@ -1673,6 +1673,18 @@ decide_function_section (tree decl) ...@@ -1673,6 +1673,18 @@ decide_function_section (tree decl)
in_cold_section_p = first_function_block_is_cold; 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 /* Output assembler code for the constant pool of a function and associated
with defining the name of the function. DECL describes the function. 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 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, ...@@ -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. /* Assemble everything that is needed for a variable or function declaration.
Not used for automatic variables, and not used for function definitions. Not used for automatic variables, and not used for function definitions.
Should not be called for variables of incomplete structure type. Should not be called for variables of incomplete structure type.
......
...@@ -707,6 +707,9 @@ symbol_table::output_variables (void) ...@@ -707,6 +707,9 @@ symbol_table::output_variables (void)
timevar_push (TV_VAROUT); timevar_push (TV_VAROUT);
FOR_EACH_VARIABLE (node)
if (!node->definition)
assemble_undefined_decl (node->decl);
FOR_EACH_DEFINED_VARIABLE (node) FOR_EACH_DEFINED_VARIABLE (node)
{ {
/* Handled in output_in_order. */ /* Handled in output_in_order. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment