From patchwork Wed Nov 25 14:09:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 548580 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 B3EE0140324 for ; Thu, 26 Nov 2015 01:09:27 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=CRkKXWRr; 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=NvK9XBr3fVKABvHBQfaHQx8GJsqh9BB2p94Dj37LkvOTci6Otj Z12x5yswmlTel50hMM0lcoouiraiOFOoSCYbEzpb8MKZzc32/oEZlBqAsIFi9wDy wWaTlZOC3pu8YC1eR0CB/DPVGjebOWWrCDkM/PdPLlWYOxONY2s2Jf2RY= 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=qwsokUWVGtH7hhw/FRgzHLNOA1A=; b=CRkKXWRrzfsZBHY+8jOE LYz1D6YJGv56xY2nXBsmQbmxB3HT3ipTYtwZ5LvnQB10nIBdpWhV5GYXODuEzLT1 6ET4frkrU13/4XgnfuxecTePJ3/92wAVatDIedPsiztpFwxuKebrLYjBRRGqg7x7 7d13dcCq4Qxm9GfXN6z0ARU= Received: (qmail 76173 invoked by alias); 25 Nov 2015 14:09:19 -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 76163 invoked by uid 89); 25 Nov 2015 14:09:19 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.6 required=5.0 tests=BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS, UNSUBSCRIBE_BODY autolearn=no version=3.3.2 X-HELO: mail-vk0-f42.google.com Received: from mail-vk0-f42.google.com (HELO mail-vk0-f42.google.com) (209.85.213.42) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Wed, 25 Nov 2015 14:09:16 +0000 Received: by vkay187 with SMTP id y187so34948395vka.3 for ; Wed, 25 Nov 2015 06:09:14 -0800 (PST) X-Received: by 10.31.12.77 with SMTP id 74mr32652593vkm.28.1448460554106; Wed, 25 Nov 2015 06:09:14 -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 g133sm18448481vke.25.2015.11.25.06.09.13 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 25 Nov 2015 06:09:13 -0800 (PST) To: GCC Patches From: Nathan Sidwell Subject: [PTX] Simplify function decl output Message-ID: <5655C108.2090801@acm.org> Date: Wed, 25 Nov 2015 09:09:12 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 I've applied this patch to reorganize nvptx_declare_function_name. It's responsible fo declaring a bunch of registers and assigning initial values to them. But those two pieces of code were separated, so all the declarations occurred before all the definitions. there's no need for that, decls and uses can be freely mixed, which is what this patch does. nathan 2015-11-25 Nathan Sidwell * config/nvptx/nvptx.c (walk_args_for_params): Delete. (nvptx_declare_function_name): Move assignments next to register declarations, and process params here. Index: config/nvptx/nvptx.c =================================================================== --- config/nvptx/nvptx.c (revision 230868) +++ config/nvptx/nvptx.c (working copy) @@ -436,59 +436,6 @@ nvptx_write_function_decl (std::stringst } } -/* Walk either ARGTYPES or ARGS if the former is null, and write out part of - the function header to FILE. If WRITE_COPY is false, write reg - declarations, otherwise write the copy from the incoming argument to that - reg. RETURN_IN_MEM indicates whether to start counting arg numbers at 1 - instead of 0. */ - -static void -walk_args_for_param (FILE *file, tree argtypes, tree args, bool write_copy, - bool return_in_mem) -{ - int i; - - bool args_from_decl = false; - if (argtypes == 0) - args_from_decl = true; - else - args = argtypes; - - for (i = return_in_mem ? 1 : 0; args != NULL_TREE; args = TREE_CHAIN (args)) - { - tree type = args_from_decl ? TREE_TYPE (args) : TREE_VALUE (args); - machine_mode mode = TYPE_MODE (type); - int count = 1; - - if (mode == VOIDmode) - break; - - if (!PASS_IN_REG_P (mode, type)) - mode = Pmode; - - machine_mode split = maybe_split_mode (mode); - if (split != VOIDmode) - { - count = 2; - mode = split; - } - else if (argtypes == NULL && !AGGREGATE_TYPE_P (type) && mode == SFmode) - mode = DFmode; - - mode = arg_promotion (mode); - while (count--) - { - i++; - if (write_copy) - fprintf (file, "\tld.param%s %%ar%d, [%%in_ar%d];\n", - nvptx_ptx_type_from_mode (mode, false), i, i); - else - fprintf (file, "\t.reg%s %%ar%d;\n", - nvptx_ptx_type_from_mode (mode, false), i); - } - } -} - /* Write a .func or .kernel declaration (not a definition) along with a helper comment for use by ld. S is the stream to write to, DECL the decl for the function with name NAME. */ @@ -589,6 +536,7 @@ nvptx_declare_function_name (FILE *file, { tree fntype = TREE_TYPE (decl); tree result_type = TREE_TYPE (fntype); + int argno = 0; name = nvptx_name_replacement (name); @@ -613,12 +561,54 @@ nvptx_declare_function_name (FILE *file, fprintf (file, "\n{\n"); - /* Ensure all arguments that should live in a register have one - declared. We'll emit the copies below. */ - walk_args_for_param (file, TYPE_ARG_TYPES (fntype), DECL_ARGUMENTS (decl), - false, return_in_mem); if (return_in_mem) - fprintf (file, "\t.reg.u%d %%ar1;\n", GET_MODE_BITSIZE (Pmode)); + { + ++argno; + fprintf (file, "\t.reg.u%d %%ar%d;\n", GET_MODE_BITSIZE (Pmode), argno); + fprintf (file, "\tld.param.u%d %%ar%d, [%%in_ar%d];\n", + GET_MODE_BITSIZE (Pmode), argno, argno); + } + + /* Declare and initialize incoming arguments. */ + tree args = DECL_ARGUMENTS (decl); + bool prototyped = false; + if (TYPE_ARG_TYPES (fntype)) + { + args = TYPE_ARG_TYPES (fntype); + prototyped = true; + } + + for (; args != NULL_TREE; args = TREE_CHAIN (args)) + { + tree type = prototyped ? TREE_VALUE (args) : TREE_TYPE (args); + machine_mode mode = TYPE_MODE (type); + int count = 1; + + if (mode == VOIDmode) + break; + + if (!PASS_IN_REG_P (mode, type)) + mode = Pmode; + + machine_mode split = maybe_split_mode (mode); + if (split != VOIDmode) + { + count = 2; + mode = split; + } + else if (!prototyped && !AGGREGATE_TYPE_P (type) && mode == SFmode) + mode = DFmode; + + mode = arg_promotion (mode); + while (count--) + { + ++argno; + fprintf (file, "\t.reg%s %%ar%d;\n", + nvptx_ptx_type_from_mode (mode, false), argno); + fprintf (file, "\tld.param%s %%ar%d, [%%in_ar%d];\n", + nvptx_ptx_type_from_mode (mode, false), argno, argno); + } + } /* C++11 ABI causes us to return a reference to the passed in pointer for return_in_mem. */ @@ -631,7 +621,11 @@ nvptx_declare_function_name (FILE *file, } if (stdarg_p (fntype)) - fprintf (file, "\t.reg.u%d %%argp;\n", GET_MODE_BITSIZE (Pmode)); + { + fprintf (file, "\t.reg.u%d %%argp;\n", GET_MODE_BITSIZE (Pmode)); + fprintf (file, "\tld.param.u%d %%argp, [%%in_argp];\n", + GET_MODE_BITSIZE (Pmode)); + } fprintf (file, "\t.reg.u%d %s;\n", GET_MODE_BITSIZE (Pmode), reg_names[OUTGOING_STATIC_CHAIN_REGNUM]); @@ -665,13 +659,23 @@ nvptx_declare_function_name (FILE *file, if (sz == 0) sz = 1; if (cfun->machine->has_call_with_varargs) - fprintf (file, "\t.reg.u%d %%outargs;\n" - "\t.local.align 8 .b8 %%outargs_ar[" HOST_WIDE_INT_PRINT_DEC"];\n", - BITS_PER_WORD, sz); + { + fprintf (file, "\t.reg.u%d %%outargs;\n" + "\t.local.align 8 .b8 %%outargs_ar[" + HOST_WIDE_INT_PRINT_DEC"];\n", + BITS_PER_WORD, sz); + fprintf (file, "\tcvta.local.u%d %%outargs, %%outargs_ar;\n", + BITS_PER_WORD); + } + if (cfun->machine->punning_buffer_size > 0) - fprintf (file, "\t.reg.u%d %%punbuffer;\n" - "\t.local.align 8 .b8 %%punbuffer_ar[%d];\n", - BITS_PER_WORD, cfun->machine->punning_buffer_size); + { + fprintf (file, "\t.reg.u%d %%punbuffer;\n" + "\t.local.align 8 .b8 %%punbuffer_ar[%d];\n", + BITS_PER_WORD, cfun->machine->punning_buffer_size); + fprintf (file, "\tcvta.local.u%d %%punbuffer, %%punbuffer_ar;\n", + BITS_PER_WORD); + } /* Declare a local variable for the frame. */ sz = get_frame_size (); @@ -686,23 +690,6 @@ nvptx_declare_function_name (FILE *file, BITS_PER_WORD); } - if (cfun->machine->has_call_with_varargs) - fprintf (file, "\tcvta.local.u%d %%outargs, %%outargs_ar;\n", - BITS_PER_WORD); - if (cfun->machine->punning_buffer_size > 0) - fprintf (file, "\tcvta.local.u%d %%punbuffer, %%punbuffer_ar;\n", - BITS_PER_WORD); - - /* Now emit any copies necessary for arguments. */ - walk_args_for_param (file, TYPE_ARG_TYPES (fntype), DECL_ARGUMENTS (decl), - true, return_in_mem); - if (return_in_mem) - fprintf (file, "\tld.param.u%d %%ar1, [%%in_ar1];\n", - GET_MODE_BITSIZE (Pmode)); - if (stdarg_p (fntype)) - fprintf (file, "\tld.param.u%d %%argp, [%%in_argp];\n", - GET_MODE_BITSIZE (Pmode)); - /* Emit axis predicates. */ if (cfun->machine->axis_predicate[0]) nvptx_init_axis_predicate (file,