From patchwork Mon Oct 20 14:30:55 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Schmidt X-Patchwork-Id: 401163 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 6737B140081 for ; Tue, 21 Oct 2014 01:32:26 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:references :in-reply-to:content-type; q=dns; s=default; b=WuayN9yiorMspumuc YsjcxnA9R2Q/ipPLkukt3r3afCkh6nmV1Y3AdLKDo/GCRwyefpcuePE6qp3VJ67G 44mx1oeCfrTucEVvGNC/0HG+7wZXrMKzujtgNjHZTfy0wItct/N7ugExis53Wp77 NaUjc/Rt9K+voZg81Vb3v0hmlo= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:references :in-reply-to:content-type; s=default; bh=Kzit1UaNL0Xbe1TykNfeJKQ pCSQ=; b=g65YQalrlQv8B0EZQ6p1ngE/YIvv8kPsDvUqr/urfa7xWXq1J+FFHMm nKOS91Nq3kvv3pGcGo7jRGxYq9E+pjZ4xFt0ggj8QdT8ohTbrgCLUaDvylkPd2kN DmHWW5N6/O51KFw0DfqOL8LhdFNZkbo9b85Hu0IfzCALvZ55XayM= 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-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@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 16:30:55 +0200 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> ptx assembly requires that declarations are written for undefined variables. This adds that functionality. Bernd 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;