From patchwork Thu Nov 26 14:17:58 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 549115 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 77B831402DD for ; Fri, 27 Nov 2015 01:18:12 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=l0ibJkXe; 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=USTVvW1Mcm92FhwGTMgeXY04VtfQKooGfBHmZFUyPaR/JJRcM5 xyK9eNKd3JYD0JuwFQvCjyyfDvWJJWWwvIm2BBzXa6+4XN29bQtpsdKbl3box9sG ha6ZfwHN5e9rNnd3kkUm96KdNdhPhWuyVR0+nvv0FsW8sgzbBlq7sI8fk= 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=eLaPvZCU1XcBJ+wzzJk3aDSpUN4=; b=l0ibJkXeBJzDQImQ3MUd pfRbYRzCThmzq80dc8TdUGtm6MGkpMVSgRr0ho0C6mQucOkkIEb2u0KQ3QIdi/pD 20vdfi/gw7hCJnQ1z1GbGdkcBdM6DSp6vFqz5g1SVALTepl4FEsAoAMeJKCXHXru wHf7Dh68FIktWQRm9gIPZ8U= Received: (qmail 62429 invoked by alias); 26 Nov 2015 14:18:04 -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 62397 invoked by uid 89); 26 Nov 2015 14:18:03 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=BAYES_00, FREEMAIL_FROM, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-qg0-f53.google.com Received: from mail-qg0-f53.google.com (HELO mail-qg0-f53.google.com) (209.85.192.53) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 26 Nov 2015 14:18:02 +0000 Received: by qgea14 with SMTP id a14so54757223qge.0 for ; Thu, 26 Nov 2015 06:18:00 -0800 (PST) X-Received: by 10.140.30.180 with SMTP id d49mr45731352qgd.48.1448547479989; Thu, 26 Nov 2015 06:17:59 -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 b107sm7298799qga.10.2015.11.26.06.17.59 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 26 Nov 2015 06:17:59 -0800 (PST) To: GCC Patches From: Nathan Sidwell Subject: [PTX] simplify call emission Message-ID: <56571496.3000904@acm.org> Date: Thu, 26 Nov 2015 09:17:58 -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 committed this patch to simplify some more call emission machinery. write_func_decl_from_insn was doing more work than necessary. 1) it doesn't need to examine the callee to figure out whether this is an indirect call or not. It's callers have already done this, and can pass in the relevant info (name or NULL). 2) it doesn't need to deal with split regs. That was already done when the call was expanded. nvptx_output_call_insn had the same issue with split regs. I changed the formatting slightly, so the proto-1.c testcase needed a tweak. While there I canged the fn name from nearly-but-not-quite acc_on_device, to 'foo', so it didn;t look superficially like a builtin test. nathan 2015-11-26 Nathan Sidwell * config/nvptx/nvptx.c (write_func_decl_from_insn): Replace callee arg with name. Don't deal with split regs. Tweak formatting. (nvptx_expand_call): Adjust write_func_decl_from_insn call. (nvptx_output_call_insn): Don't deal with split regs here. testsuite/ * gcc.target/nvptx/proto-1.c: Adjust expected asm. Index: config/nvptx/nvptx.c =================================================================== --- config/nvptx/nvptx.c (revision 230963) +++ config/nvptx/nvptx.c (working copy) @@ -719,69 +719,46 @@ nvptx_output_return (void) generated by emit_library_call for which no decl exists. */ static void -write_func_decl_from_insn (std::stringstream &s, rtx result, rtx pat, - rtx callee) +write_func_decl_from_insn (std::stringstream &s, const char *name, + rtx result, rtx pat) { - bool callprototype = register_operand (callee, Pmode); - const char *name = "_"; - if (!callprototype) + if (!name) + { + s << "\t.callprototype "; + name = "_"; + } + else { - name = XSTR (callee, 0); - name = nvptx_name_replacement (name); s << "\n// BEGIN GLOBAL FUNCTION DECL: " << name << "\n"; + s << "\t.extern .func "; } - s << (callprototype ? "\t.callprototype\t" : "\t.extern .func "); if (result != NULL_RTX) - { - s << "(.param"; - s << nvptx_ptx_type_from_mode (arg_promotion (GET_MODE (result)), - false); - s << " "; - if (callprototype) - s << "_"; - else - s << "%out_retval"; - s << ")"; - } + s << "(.param" + << nvptx_ptx_type_from_mode (arg_promotion (GET_MODE (result)), false) + << " %rval) "; s << name; + const char *sep = " ("; int arg_end = XVECLEN (pat, 0); - - if (1 < arg_end) + for (int i = 1; i < arg_end; i++) { - const char *comma = ""; - s << " ("; - for (int i = 1; i < arg_end; i++) - { - rtx t = XEXP (XVECEXP (pat, 0, i), 0); - machine_mode mode = GET_MODE (t); - machine_mode split = maybe_split_mode (mode); - int count = 1; - - if (split != VOIDmode) - { - mode = split; - count = 2; - } - - while (count--) - { - s << comma << ".param"; - s << nvptx_ptx_type_from_mode (mode, false); - s << " "; - if (callprototype) - s << "_"; - else - s << "%arg" << i - 1; - if (mode == QImode || mode == HImode) - s << "[1]"; - comma = ", "; - } - } - s << ")"; + /* We don't have to deal with mode splitting here, as that was + already done when generating the call sequence. */ + machine_mode mode = GET_MODE (XEXP (XVECEXP (pat, 0, i), 0)); + + s << sep + << ".param" + << nvptx_ptx_type_from_mode (mode, false) + << " %arg" + << i; + if (mode == QImode || mode == HImode) + s << "[1]"; + sep = ", "; } + if (arg_end != 1) + s << ")"; s << ";\n"; } @@ -905,10 +882,7 @@ nvptx_expand_call (rtx retval, rtx addre && stdarg_p (cfun->machine->funtype)) { varargs = gen_reg_rtx (Pmode); - if (Pmode == DImode) - emit_move_insn (varargs, stack_pointer_rtx); - else - emit_move_insn (varargs, stack_pointer_rtx); + emit_move_insn (varargs, stack_pointer_rtx); cfun->machine->has_call_with_varargs = true; } vec = rtvec_alloc (nargs + 1 + (varargs ? 1 : 0)); @@ -951,7 +925,11 @@ nvptx_expand_call (rtx retval, rtx addre if (*slot == NULL) { *slot = callee; - write_func_decl_from_insn (func_decls, retval, pat, callee); + + const char *name = XSTR (callee, 0); + if (decl_type) + name = nvptx_name_replacement (name); + write_func_decl_from_insn (func_decls, name, retval, pat); } } @@ -1798,7 +1776,7 @@ nvptx_assemble_undefined_decl (FILE *fil const char * nvptx_output_call_insn (rtx_insn *insn, rtx result, rtx callee) { - char buf[256]; + char buf[16]; static int labelno; bool needs_tgt = register_operand (callee, Pmode); rtx pat = PATTERN (insn); @@ -1825,36 +1803,22 @@ nvptx_output_call_insn (rtx_insn *insn, labelno++; ASM_OUTPUT_LABEL (asm_out_file, buf); std::stringstream s; - write_func_decl_from_insn (s, result, pat, callee); + write_func_decl_from_insn (s, NULL, result, pat); fputs (s.str().c_str(), asm_out_file); } - for (int i = 1, argno = 0; i < arg_end; i++) + for (int argno = 1; argno < arg_end; argno++) { - rtx t = XEXP (XVECEXP (pat, 0, i), 0); + rtx t = XEXP (XVECEXP (pat, 0, argno), 0); machine_mode mode = GET_MODE (t); - machine_mode split = maybe_split_mode (mode); - int count = 1; - - if (split != VOIDmode) - { - mode = split; - count = 2; - } - for (int n = 0; n != count; n++) - { - fprintf (asm_out_file, "\t\t.param%s %%out_arg%d%s;\n", - nvptx_ptx_type_from_mode (mode, false), argno, - mode == QImode || mode == HImode ? "[1]" : ""); - fprintf (asm_out_file, "\t\tst.param%s [%%out_arg%d], %%r%d", - nvptx_ptx_type_from_mode (mode, false), argno, - REGNO (t)); - if (split != VOIDmode) - fprintf (asm_out_file, "$%d", n); - fprintf (asm_out_file, ";\n"); - argno++; - } + /* Mode splitting has already been done. */ + fprintf (asm_out_file, "\t\t.param%s %%out_arg%d%s;\n", + nvptx_ptx_type_from_mode (mode, false), argno, + mode == QImode || mode == HImode ? "[1]" : ""); + fprintf (asm_out_file, "\t\tst.param%s [%%out_arg%d], %%r%d;\n", + nvptx_ptx_type_from_mode (mode, false), argno, + REGNO (t)); } fprintf (asm_out_file, "\t\tcall "); @@ -1870,31 +1834,20 @@ nvptx_output_call_insn (rtx_insn *insn, else output_address (VOIDmode, callee); - if (arg_end > 1 || (decl && DECL_STATIC_CHAIN (decl))) + const char *open = "("; + for (int argno = 1; argno < arg_end; argno++) { - const char *comma = ""; - - fprintf (asm_out_file, ", ("); - for (int i = 1, argno = 0; i < arg_end; i++) - { - rtx t = XEXP (XVECEXP (pat, 0, i), 0); - machine_mode mode = GET_MODE (t); - machine_mode split = maybe_split_mode (mode); - - if (split != VOIDmode) - { - fprintf (asm_out_file, "%s%%out_arg%d", comma, argno++); - comma = ", "; - } - fprintf (asm_out_file, "%s%%out_arg%d", comma, argno++); - comma = ", "; - } - if (decl && DECL_STATIC_CHAIN (decl)) - fprintf (asm_out_file, "%s%s", comma, - reg_names [OUTGOING_STATIC_CHAIN_REGNUM]); - - fprintf (asm_out_file, ")"); + fprintf (asm_out_file, ", %s%%out_arg%d", open, argno); + open = ""; + } + if (decl && DECL_STATIC_CHAIN (decl)) + { + fprintf (asm_out_file, ", %s%s", open, + reg_names [OUTGOING_STATIC_CHAIN_REGNUM]); + open = ""; } + if (!open[0]) + fprintf (asm_out_file, ")"); if (needs_tgt) { @@ -1902,10 +1855,8 @@ nvptx_output_call_insn (rtx_insn *insn, assemble_name (asm_out_file, buf); } fprintf (asm_out_file, ";\n"); - if (result != NULL_RTX) - return "\tld.param%t0\t%0, [%%retval_in];\n\t}"; - return "}"; + return result != NULL_RTX ? "\tld.param%t0\t%0, [%%retval_in];\n\t}" : "}"; } /* Implement TARGET_PRINT_OPERAND_PUNCT_VALID_P. */ Index: testsuite/gcc.target/nvptx/proto-1.c =================================================================== --- testsuite/gcc.target/nvptx/proto-1.c (revision 230963) +++ testsuite/gcc.target/nvptx/proto-1.c (working copy) @@ -6,8 +6,8 @@ int f(void) /* Check that without an explicit prototype, we deduce from call site the signature for the (mandatory in PTX) prototype. */ - /* extern int acc_on_device_(int *); */ + /* extern int foo (int *); */ /* { dg-final { scan-assembler-not "\\\.callprototype" } } */ - /* { dg-final { scan-assembler "\\\.extern \\\.func \\\(\[^,\n\r\]+\\\)acc_on_device_ \\\(\[^,\n\r\]+\\\);" } } */ - return !acc_on_device_(&dev); + /* { dg-final { scan-assembler "\\\.extern \\\.func \\\(\[^,\n\r\]+\\\) foo \\\(\[^,\n\r\]+\\\);" } } */ + return !foo(&dev); }