From patchwork Wed Dec 16 20:04:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 557742 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 7405D1402BC for ; Thu, 17 Dec 2015 07:04:31 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=WcqngsBd; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=rViE8QKU+BTHjbt+TfJMGZvj4/K64QsrG/YUTYvw3MVLxXgCgd 2c4wB/XgjicV+jZUEFTjUz2+BxwG0LCOsWjlWHTaRn1Ew+PeIWA1VUZZ5gcatTZe Qdm5/wCbinV9CaIwO/gHsB+3+HEsB7ZH/sI7z1qoQRci+N4o1SG8AMi24= 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:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=NS+mdFBro6jppx7+0st/x2Dajwk=; b=WcqngsBdmCBc16lmtx+i N4ukx1YCALWF3lATI0FyK7wuox/Rym9UcQEMBZjCXf3SgmQ/LPW+1ICucq0dNcpf 2wVaLg7vvP7zMRMZBTF4kU8AqfRIQppH6QBt1F4mWLZb4jRRCEB5XHStzgk6XQcH 3qNbpDO8se/jOw14IO5eVEQ= Received: (qmail 2750 invoked by alias); 16 Dec 2015 20:04:24 -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 2739 invoked by uid 89); 16 Dec 2015 20:04:23 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.1 required=5.0 tests=BAYES_20, FREEMAIL_FROM, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=no version=3.3.2 spammy=Complex, gen_rtx_REG, gen_rtx_reg, sk:nvptx_f X-HELO: mail-qg0-f41.google.com Received: from mail-qg0-f41.google.com (HELO mail-qg0-f41.google.com) (209.85.192.41) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Wed, 16 Dec 2015 20:04:22 +0000 Received: by mail-qg0-f41.google.com with SMTP id i91so36585783qgf.2 for ; Wed, 16 Dec 2015 12:04:22 -0800 (PST) X-Received: by 10.140.163.198 with SMTP id j189mr58399889qhj.36.1450296260058; Wed, 16 Dec 2015 12:04:20 -0800 (PST) Received: from ?IPv6:2601:181:c000:c497:a2a8:cdff:fe3e:b48? ([2601:181:c000:c497:a2a8:cdff:fe3e:b48]) by smtp.googlemail.com with ESMTPSA id h19sm3202650qgd.37.2015.12.16.12.04.19 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 16 Dec 2015 12:04:19 -0800 (PST) To: GCC Patches From: Nathan Sidwell Subject: [PTX] function frame emission Message-ID: <5671C3C2.4030405@acm.org> Date: Wed, 16 Dec 2015 15:04:18 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 This patch removes OUTGOING_STATIC_CHAIN_REGNUM -- there's no need for it to be distinct from STATIC_CHAIN_REGNUM. Also, when we have to emit a frame or outgoing args, but it's zero sized, there's no need to actually emit the frame or arg array. We can just initialize the appropriate register to zero -- it's ill formed for the area to be dereferenced. Some other minor tidying up included. nathan 2015-12-16 Nathan Sidwell * config/nvptx/nvptx.h (OUTGOING_STATIC_CHAIN_REGNUM): Remove. (REGISTER_NAMES): Adjust. * config/nvptx/nvptx.c (nvptx_pass_by_reference): Avoid long line. (nvptx_static_hain): Delete. (write_arg_mode): Don't emit initializer if argno < 0. (write_arg_type): Fix whitespace. (init_frame): Initialize reg to zero if frame is zero-sized. (nvptx_declare_function_name): Use write_arg_type to emit chain decl. (nvptx_output_call_insn): Adjust static chain emission. (nvptx_goacc_reduction): Make static. (TARGET_STATIC_CHAIN): Don't override. Index: config/nvptx/nvptx.c =================================================================== --- config/nvptx/nvptx.c (revision 231717) +++ config/nvptx/nvptx.c (working copy) @@ -525,8 +525,9 @@ nvptx_function_value_regno_p (const unsi reference in memory. */ static bool -nvptx_pass_by_reference (cumulative_args_t ARG_UNUSED (cum), machine_mode mode, - const_tree type, bool ARG_UNUSED (named)) +nvptx_pass_by_reference (cumulative_args_t ARG_UNUSED (cum), + machine_mode mode, const_tree type, + bool ARG_UNUSED (named)) { return pass_in_memory (mode, type, false); } @@ -549,18 +550,6 @@ nvptx_promote_function_mode (const_tree return promote_arg (mode, for_return || !type || TYPE_ARG_TYPES (funtype)); } -/* Implement TARGET_STATIC_CHAIN. */ - -static rtx -nvptx_static_chain (const_tree fndecl, bool incoming_p) -{ - if (!DECL_STATIC_CHAIN (fndecl)) - return NULL; - - return gen_rtx_REG (Pmode, (incoming_p ? STATIC_CHAIN_REGNUM - : OUTGOING_STATIC_CHAIN_REGNUM)); -} - /* Helper for write_arg. Emit a single PTX argument of MODE, either in a prototype, or as copy in a function prologue. ARGNO is the index of this argument in the PTX function. FOR_REG is negative, @@ -588,12 +577,15 @@ write_arg_mode (std::stringstream &s, in else s << "%ar" << argno; s << ";\n"; - s << "\tld.param" << ptx_type << " "; - if (for_reg) - s << reg_names[for_reg]; - else - s << "%ar" << argno; - s << ", [%in_ar" << argno << "];\n"; + if (argno >= 0) + { + s << "\tld.param" << ptx_type << " "; + if (for_reg) + s << reg_names[for_reg]; + else + s << "%ar" << argno; + s << ", [%in_ar" << argno << "];\n"; + } } return argno + 1; } @@ -625,7 +617,7 @@ write_arg_type (std::stringstream &s, in { /* Complex types are sent as two separate args. */ type = TREE_TYPE (type); - mode = TYPE_MODE (type); + mode = TYPE_MODE (type); prototyped = true; } @@ -917,16 +909,20 @@ nvptx_maybe_record_fnsym (rtx sym) } /* Emit a local array to hold some part of a conventional stack frame - and initialize REGNO to point to it. */ + and initialize REGNO to point to it. If the size is zero, it'll + never be valid to dereference, so we can simply initialize to + zero. */ static void init_frame (FILE *file, int regno, unsigned align, unsigned size) { - fprintf (file, "\t.reg.u%d %s;\n" - "\t.local.align %d .b8 %s_ar[%u];\n" - "\tcvta.local.u%d %s, %s_ar;\n", - POINTER_SIZE, reg_names[regno], - align, reg_names[regno], size ? size : 1, + if (size) + fprintf (file, "\t.local .align %d .b8 %s_ar[%u];\n", + align, reg_names[regno], size); + fprintf (file, "\t.reg.u%d %s;\n", + POINTER_SIZE, reg_names[regno]); + fprintf (file, (size ? "\tcvta.local.u%d %s, %s_ar;\n" + : "\tmov.u%d %s, 0;\n"), POINTER_SIZE, reg_names[regno], reg_names[regno]); } @@ -981,12 +977,14 @@ nvptx_declare_function_name (FILE *file, } if (stdarg_p (fntype)) - argno = write_arg_type (s, ARG_POINTER_REGNUM, argno, ptr_type_node, true); - - if (DECL_STATIC_CHAIN (decl)) - argno = write_arg_type (s, STATIC_CHAIN_REGNUM, argno, ptr_type_node, + argno = write_arg_type (s, ARG_POINTER_REGNUM, argno, ptr_type_node, true); + if (DECL_STATIC_CHAIN (decl) || cfun->machine->has_chain) + write_arg_type (s, STATIC_CHAIN_REGNUM, + DECL_STATIC_CHAIN (decl) ? argno : -1, ptr_type_node, + true); + fprintf (file, "%s", s.str().c_str()); /* Declare a local var for outgoing varargs. */ @@ -1000,10 +998,6 @@ nvptx_declare_function_name (FILE *file, init_frame (file, FRAME_POINTER_REGNUM, crtl->stack_alignment_needed / BITS_PER_UNIT, sz); - if (cfun->machine->has_chain) - fprintf (file, "\t.reg.u%d %s;\n", GET_MODE_BITSIZE (Pmode), - reg_names[OUTGOING_STATIC_CHAIN_REGNUM]); - /* Declare the pseudos we have as ptx registers. */ int maxregs = max_reg_num (); for (int i = LAST_VIRTUAL_REGISTER + 1; i < maxregs; i++) @@ -1864,8 +1858,7 @@ nvptx_output_call_insn (rtx_insn *insn, } if (decl && DECL_STATIC_CHAIN (decl)) { - fprintf (asm_out_file, ", %s%s", open, - reg_names [OUTGOING_STATIC_CHAIN_REGNUM]); + fprintf (asm_out_file, ", %s%s", open, reg_names [STATIC_CHAIN_REGNUM]); open = ""; } if (!open[0]) @@ -4779,7 +4772,7 @@ nvptx_goacc_reduction_teardown (gcall *c /* NVPTX reduction expander. */ -void +static void nvptx_goacc_reduction (gcall *call) { unsigned code = (unsigned)TREE_INT_CST_LOW (gimple_call_arg (call, 0)); @@ -4845,9 +4838,6 @@ nvptx_goacc_reduction (gcall *call) #define TARGET_OMIT_STRUCT_RETURN_REG true #undef TARGET_STRICT_ARGUMENT_NAMING #define TARGET_STRICT_ARGUMENT_NAMING nvptx_strict_argument_naming -#undef TARGET_STATIC_CHAIN -#define TARGET_STATIC_CHAIN nvptx_static_chain - #undef TARGET_CALL_ARGS #define TARGET_CALL_ARGS nvptx_call_args #undef TARGET_END_CALL_ARGS Index: config/nvptx/nvptx.h =================================================================== --- config/nvptx/nvptx.h (revision 231717) +++ config/nvptx/nvptx.h (working copy) @@ -157,12 +157,11 @@ enum reg_class #define ARG_POINTER_REGNUM 14 #define STATIC_CHAIN_REGNUM 12 -#define OUTGOING_STATIC_CHAIN_REGNUM 10 #define REGISTER_NAMES \ { \ "%hr0", "%outargs", "%hfp", "%hr3", "%retval", "%hr5", "%hr6", "%hr7", \ - "%hr8", "%hr9", "%chain_out", "%hr11", "%chain_in", "%hr13", "%argp", "%frame" \ + "%hr8", "%hr9", "%hr10", "%hr11", "%chain_in", "%hr13", "%argp", "%frame" \ } #define FIRST_PARM_OFFSET(FNDECL) ((void)(FNDECL), 0)