From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5683 invoked by alias); 20 Oct 2014 14:32:18 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 5670 invoked by uid 89); 20 Oct 2014 14:32:17 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,T_FROM_12LTRDOM autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 20 Oct 2014 14:32:13 +0000 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=SVR-IES-FEM-03.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1XgE0I-0004zt-1G from Bernd_Schmidt@mentor.com for gcc-patches@gcc.gnu.org; Mon, 20 Oct 2014 07:32:10 -0700 Received: from [127.0.0.1] (137.202.0.76) by SVR-IES-FEM-03.mgc.mentorg.com (137.202.0.108) with Microsoft SMTP Server id 14.3.181.6; Mon, 20 Oct 2014 15:32:08 +0100 Message-ID: <54451C9F.2080503@codesourcery.com> Date: Mon, 20 Oct 2014 14:32:00 -0000 From: Bernd Schmidt User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.8.0 MIME-Version: 1.0 To: GCC Patches Subject: The nvptx port [8/11+] Write undefined decls. References: <54451994.9070209@codesourcery.com> In-Reply-To: <54451994.9070209@codesourcery.com> Content-Type: multipart/mixed; boundary="------------020503070302030700050807" X-SW-Source: 2014-10/txt/msg01929.txt.bz2 --------------020503070302030700050807 Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit Content-length: 117 ptx assembly requires that declarations are written for undefined variables. This adds that functionality. Bernd --------------020503070302030700050807 Content-Type: text/x-patch; name="008-undefdecl.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="008-undefdecl.diff" Content-length: 7898 gcc/ * 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. ------------------------------------------------------------------------ Index: gcc/doc/tm.texi =================================================================== --- gcc/doc/tm.texi.orig +++ gcc/doc/tm.texi @@ -7899,6 +7902,13 @@ global; that is, available for reference 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: gcc/doc/tm.texi.in =================================================================== --- gcc/doc/tm.texi.in.orig +++ gcc/doc/tm.texi.in @@ -5693,6 +5693,8 @@ You may wish to use @code{ASM_OUTPUT_SIZ @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: gcc/hooks.c =================================================================== --- gcc/hooks.c.orig +++ gcc/hooks.c @@ -139,6 +139,13 @@ hook_void_FILEptr_constcharptr (FILE *a { } +/* 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: gcc/hooks.h =================================================================== --- gcc/hooks.h.orig +++ gcc/hooks.h @@ -69,6 +69,8 @@ extern void hook_void_void (void); extern void hook_void_constcharptr (const char *); extern void hook_void_rtx_int (rtx, 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 (rtx); extern void hook_void_tree (tree); Index: gcc/target.def =================================================================== --- gcc/target.def.orig +++ gcc/target.def @@ -158,6 +158,16 @@ global; that is, available for reference 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: gcc/final.c =================================================================== --- gcc/final.c.orig +++ gcc/final.c @@ -4434,17 +4434,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: gcc/varasm.c =================================================================== --- gcc/varasm.c.orig +++ gcc/varasm.c @@ -1611,6 +1611,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 @@ -1977,6 +1989,15 @@ assemble_variable_contents (tree decl, c } } +/* 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: gcc/output.h =================================================================== --- gcc/output.h.orig +++ gcc/output.h @@ -176,6 +176,9 @@ extern void default_assemble_visibility 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 @@ -201,6 +204,10 @@ extern void assemble_variable (tree, 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: gcc/varpool.c =================================================================== --- gcc/varpool.c.orig +++ gcc/varpool.c @@ -610,6 +642,9 @@ varpool_output_variables (void) FOR_EACH_DEFINED_VARIABLE (node) varpool_finalize_named_section_flags (node); + FOR_EACH_VARIABLE (node) + if (!node->definition) + assemble_undefined_decl (node->decl); FOR_EACH_DEFINED_VARIABLE (node) if (varpool_assemble_decl (node)) changed = true; --------------020503070302030700050807--