From patchwork Tue Aug 9 12:39:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Stubbs X-Patchwork-Id: 447 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6a10:20da:b0:2d3:3019:e567 with SMTP id n26csp2489369pxc; Tue, 9 Aug 2022 05:40:23 -0700 (PDT) X-Google-Smtp-Source: AA6agR4eJzcJg5laizEX0q79ZUuXazl51lE4EWvx1C921rSs9km4EzlO7Hrq7MiDpDlb8pEyC5un X-Received: by 2002:a17:907:7dac:b0:732:fecf:2751 with SMTP id oz44-20020a1709077dac00b00732fecf2751mr413192ejc.186.1660048822750; Tue, 09 Aug 2022 05:40:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660048822; cv=none; d=google.com; s=arc-20160816; b=Ci/Lzdx1Y11go5ap7n+iv8dWSmMNQNI16z3W2v74yxCLa+F3MNWxV1EGNmHDy7yXhR FAdG6H4xNN1IdU+uee2hBkfyRKpHSGJ/qyvlelTEsZp0bnMjbiA1WOw2Qb4NS6U80Gw9 8BSiVIOgEkT7YOJEz9J6akGJPtUhJ0oBzlIOM5Y3lRzNV49EaJOc8rkowqxxKubscyxA x/IrOMBc9l7EvQUNF5gKASi321CTkb0fZaT6hEziUQv9V4tc75ID9/7Sx1sEeQwAqZt/ Of6mP5/827/Owzofd1nrwlsB0m3/alkWeRgioDgijYY0jnjqtEAxQzU++rxiCLnhUFJT X3+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:to:subject:from :content-language:user-agent:mime-version:date:message-id :ironport-sdr:dmarc-filter:delivered-to; bh=uTXAtdgH3i9uEbwi/dIqlZPpIEmLkfCxlYDg7TfYajY=; b=Doq8eohRxcjxJqeAGHwlndogVFIrDwb6OmIdKAkizdN8E84a+Ihz/YURYkx0A+ze0X Eww+9oXObUumNYcmo/peW3gw0Gz5nZBhvINsHlX7Bf0avEFXucCZ8IyBfHRjqab6vXEn 2q8lWWPBllI60KVDmTub7PAqMzKbAEERDbRVEHrlutQT+oGth03nm9BX+pbxfYaBq3Nz oNpz+XEHGqR9TnbWBHWrCfwOKhsrS7vYKNtNNl/+vifvuajsH+z4fWmvaOFAdgSvaTCO PRN72fEcMSso4Cga6CWrASZrg3XppXtbFgHItzc+e0fkjakb1Kuifqhj8urSF1x1p/yB 9gXw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id a3-20020a50e703000000b0043bbb19a3b4si7812575edn.174.2022.08.09.05.40.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Aug 2022 05:40:22 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EBC543856948 for ; Tue, 9 Aug 2022 12:40:09 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa3.mentor.iphmx.com (esa3.mentor.iphmx.com [68.232.137.180]) by sourceware.org (Postfix) with ESMTPS id E96A9385734F for ; Tue, 9 Aug 2022 12:39:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E96A9385734F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com X-IronPort-AV: E=Sophos;i="5.93,224,1654588800"; d="scan'208";a="80894657" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 09 Aug 2022 04:39:33 -0800 IronPort-SDR: lZ2s6jtc+jtG+AIAaiAx3JTOLp6gr1//qMjPOC8ZFsZiHq7iiVT32w9etq9K21C4PkTBNheo2p TX1hw2ydWPgg/T6P2O1QXN+oGD5q1o2wjAf/DqxRCsWI/jh0jNbTOWwKKlpb9tCQi3KQydQi47 5jRvTNz0rSRU59I1oJgC6pxkitIKnrEV/eIoK/1IKJHVaeN6hlyIX1AuIiCu59orYOe8dihsc1 EnV4dD1juBVqjsb6cE0QgNxdHgymEsqyjs4a6wYrmXIW55KcaJvkKoAEFvPle33X6lEt/+aKYp s18= Message-ID: Date: Tue, 9 Aug 2022 13:39:29 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.1.0 Content-Language: en-GB From: Andrew Stubbs Subject: [committed] amdgcn: Vector procedure call ABI To: "gcc-patches@gcc.gnu.org" X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-09.mgc.mentorg.com (139.181.222.9) To svr-ies-mbx-11.mgc.mentorg.com (139.181.222.11) X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1740687353988083415?= X-GMAIL-MSGID: =?utf-8?q?1740687353988083415?= I've committed this patch for amdgcn. This changes the procedure calling ABI such that vector arguments are passed in vector registers, rather than on the stack as before. The ABI for scalar functions is the same for arguments, but the return value has now moved to a vector register; keeping it the same for all types simplifies the compiler implementation. If a significant down-side is found then we can move to having multiple return locations, and worry about how to fix the "untyped" calls then. There's no "standard ABI" for this target, and there are no third party binaries with which to retain compatibility, so we're free to make whatever changes we wish. Andrew amdgcn: Vector procedure call ABI Adjust the (unofficial) procedure calling ABI such that vector arguments are passed in vector registers, not on the stack. Scalar arguments continue to be passed in scalar registers, making a total of 12 argument registers. The return value is also moved to a vector register (even for scalars; it would be possible to retain the scalar location, using untyped_call, but there's no obvious advantage in doing so). After this change the ABI is as follows: s0-s13 : Reserved for kernel launch parameters. s14-s15 : Frame pointer. s16-s17 : Stack pointer. s18-s19 : Link register. s20-s21 : Exec Save. s22-s23 : CC Save. s24-s25 : Scalar arguments. NO LONGER RETURN VALUE. s26-s29 : Additional scalar arguments (makes 6 total). s30-s31 : Static Chain. v0 : Prologue/epilogue scratch. v1 : Constant 0, 1, 2, 3, 4, ... 63. v2-v7 : Prologue/epilogue scratch. v8-v9 : Return value & vector arguments. NEW. v10-v13 : Additional vector arguments (makes 6 total). NEW. gcc/ChangeLog: * config/gcn/gcn.cc (gcn_function_value): Allow vector return values. (num_arg_regs): Allow vector arguments. (gcn_function_arg): Likewise. (gcn_function_arg_advance): Likewise. (gcn_arg_partial_bytes): Likewise. (gcn_return_in_memory): Likewise. (gcn_expand_epilogue): Get return value from v8. * config/gcn/gcn.h (RETURN_VALUE_REG): Set to v8. (FIRST_PARM_REG): USE FIRST_SGPR_REG for clarity. (FIRST_VPARM_REG): New. (FUNCTION_ARG_REGNO_P): Allow vector parameters. (struct gcn_args): Add vnum field. (LIBCALL_VALUE): All vector return values. * config/gcn/gcn.md (gcn_call_value): Add vector constraints. (gcn_call_value_indirect): Likewise. diff --git a/gcc/config/gcn/gcn.cc b/gcc/config/gcn/gcn.cc index 6fc20d3f659..96295e23aad 100644 --- a/gcc/config/gcn/gcn.cc +++ b/gcc/config/gcn/gcn.cc @@ -2284,7 +2284,7 @@ gcn_function_value (const_tree valtype, const_tree, bool) && GET_MODE_SIZE (mode) < 4) mode = SImode; - return gen_rtx_REG (mode, SGPR_REGNO (RETURN_VALUE_REG)); + return gen_rtx_REG (mode, RETURN_VALUE_REG); } /* Implement TARGET_FUNCTION_VALUE_REGNO_P. @@ -2308,7 +2308,9 @@ num_arg_regs (const function_arg_info &arg) return 0; int size = arg.promoted_size_in_bytes (); - return (size + UNITS_PER_WORD - 1) / UNITS_PER_WORD; + int regsize = UNITS_PER_WORD * (VECTOR_MODE_P (arg.mode) + ? GET_MODE_NUNITS (arg.mode) : 1); + return (size + regsize - 1) / regsize; } /* Implement TARGET_STRICT_ARGUMENT_NAMING. @@ -2358,16 +2360,16 @@ gcn_function_arg (cumulative_args_t cum_v, const function_arg_info &arg) if (targetm.calls.must_pass_in_stack (arg)) return 0; - /* Vector parameters are not supported yet. */ - if (VECTOR_MODE_P (arg.mode)) - return 0; - - int reg_num = FIRST_PARM_REG + cum->num; + int first_reg = (VECTOR_MODE_P (arg.mode) + ? FIRST_VPARM_REG : FIRST_PARM_REG); + int cum_num = (VECTOR_MODE_P (arg.mode) + ? cum->vnum : cum->num); + int reg_num = first_reg + cum_num; int num_regs = num_arg_regs (arg); if (num_regs > 0) while (reg_num % num_regs != 0) reg_num++; - if (reg_num + num_regs <= FIRST_PARM_REG + NUM_PARM_REGS) + if (reg_num + num_regs <= first_reg + NUM_PARM_REGS) return gen_rtx_REG (arg.mode, reg_num); } else @@ -2419,11 +2421,15 @@ gcn_function_arg_advance (cumulative_args_t cum_v, if (!arg.named) return; + int first_reg = (VECTOR_MODE_P (arg.mode) + ? FIRST_VPARM_REG : FIRST_PARM_REG); + int *cum_num = (VECTOR_MODE_P (arg.mode) + ? &cum->vnum : &cum->num); int num_regs = num_arg_regs (arg); if (num_regs > 0) - while ((FIRST_PARM_REG + cum->num) % num_regs != 0) - cum->num++; - cum->num += num_regs; + while ((first_reg + *cum_num) % num_regs != 0) + (*cum_num)++; + *cum_num += num_regs; } else { @@ -2454,14 +2460,18 @@ gcn_arg_partial_bytes (cumulative_args_t cum_v, const function_arg_info &arg) if (targetm.calls.must_pass_in_stack (arg)) return 0; - if (cum->num >= NUM_PARM_REGS) + int cum_num = (VECTOR_MODE_P (arg.mode) ? cum->vnum : cum->num); + int regsize = UNITS_PER_WORD * (VECTOR_MODE_P (arg.mode) + ? GET_MODE_NUNITS (arg.mode) : 1); + + if (cum_num >= NUM_PARM_REGS) return 0; /* If the argument fits entirely in registers, return 0. */ - if (cum->num + num_arg_regs (arg) <= NUM_PARM_REGS) + if (cum_num + num_arg_regs (arg) <= NUM_PARM_REGS) return 0; - return (NUM_PARM_REGS - cum->num) * UNITS_PER_WORD; + return (NUM_PARM_REGS - cum_num) * regsize; } /* A normal function which takes a pointer argument (to a scalar) may be @@ -2549,14 +2559,11 @@ gcn_return_in_memory (const_tree type, const_tree ARG_UNUSED (fntype)) if (AGGREGATE_TYPE_P (type)) return true; - /* Vector return values are not supported yet. */ - if (VECTOR_TYPE_P (type)) - return true; - if (mode == BLKmode) return true; - if (size > 2 * UNITS_PER_WORD) + if ((!VECTOR_TYPE_P (type) && size > 2 * UNITS_PER_WORD) + || size > 2 * UNITS_PER_WORD * 64) return true; return false; @@ -3199,9 +3206,10 @@ gcn_expand_epilogue (void) emit_move_insn (kernarg_reg, retptr_mem); rtx retval_mem = gen_rtx_MEM (SImode, kernarg_reg); + rtx scalar_retval = gen_rtx_REG (SImode, FIRST_PARM_REG); set_mem_addr_space (retval_mem, ADDR_SPACE_SCALAR_FLAT); - emit_move_insn (retval_mem, - gen_rtx_REG (SImode, SGPR_REGNO (RETURN_VALUE_REG))); + emit_move_insn (scalar_retval, gen_rtx_REG (SImode, RETURN_VALUE_REG)); + emit_move_insn (retval_mem, scalar_retval); } emit_jump_insn (gen_gcn_return ()); diff --git a/gcc/config/gcn/gcn.h b/gcc/config/gcn/gcn.h index a1297605047..318256c4a7a 100644 --- a/gcc/config/gcn/gcn.h +++ b/gcc/config/gcn/gcn.h @@ -138,7 +138,7 @@ #define LINK_REGNUM 18 #define EXEC_SAVE_REG 20 #define CC_SAVE_REG 22 -#define RETURN_VALUE_REG 24 /* Must be divisible by 4. */ +#define RETURN_VALUE_REG 168 /* Must be divisible by 4. */ #define STATIC_CHAIN_REGNUM 30 #define WORK_ITEM_ID_Z_REG 162 #define SOFT_ARG_REG 416 @@ -146,7 +146,8 @@ #define DWARF_LINK_REGISTER 420 #define FIRST_PSEUDO_REGISTER 421 -#define FIRST_PARM_REG 24 +#define FIRST_PARM_REG (FIRST_SGPR_REG + 24) +#define FIRST_VPARM_REG (FIRST_VGPR_REG + 8) #define NUM_PARM_REGS 6 /* There is no arg pointer. Just choose random fixed register that does @@ -164,7 +165,8 @@ #define CC_REG_P(X) (REG_P (X) && CC_REGNO_P (REGNO (X))) #define CC_REGNO_P(X) ((X) == SCC_REG || (X) == VCC_REG) #define FUNCTION_ARG_REGNO_P(N) \ - ((N) >= FIRST_PARM_REG && (N) < (FIRST_PARM_REG + NUM_PARM_REGS)) + (((N) >= FIRST_PARM_REG && (N) < (FIRST_PARM_REG + NUM_PARM_REGS)) \ + || ((N) >= FIRST_VPARM_REG && (N) < (FIRST_VPARM_REG + NUM_PARM_REGS))) #define FIXED_REGISTERS { \ @@ -550,6 +552,7 @@ typedef struct gcn_args tree fntype; struct gcn_kernel_args args; int num; + int vnum; int offset; int alignment; } CUMULATIVE_ARGS; @@ -653,7 +656,7 @@ enum gcn_builtin_codes } /* This needs to match gcn_function_value. */ -#define LIBCALL_VALUE(MODE) gen_rtx_REG (MODE, SGPR_REGNO (RETURN_VALUE_REG)) +#define LIBCALL_VALUE(MODE) gen_rtx_REG (MODE, RETURN_VALUE_REG) /* The s_ff0 and s_flbit instructions return -1 if no input bits are set. */ #define CLZ_DEFINED_VALUE_AT_ZERO(MODE, VALUE) ((VALUE) = -1, 2) diff --git a/gcc/config/gcn/gcn.md b/gcc/config/gcn/gcn.md index 70a769babc4..7805e867901 100644 --- a/gcc/config/gcn/gcn.md +++ b/gcc/config/gcn/gcn.md @@ -908,11 +908,11 @@ (define_expand "call_value" {}) (define_insn "gcn_call_value" - [(set (match_operand 0 "register_operand" "=Sg,Sg") - (call (mem (match_operand 1 "immediate_operand" "Y,B")) + [(set (match_operand 0 "register_operand" "=Sgv,Sgv") + (call (mem (match_operand 1 "immediate_operand" " Y, B")) (match_operand 2 "const_int_operand"))) (clobber (reg:DI LR_REGNUM)) - (clobber (match_scratch:DI 3 "=&Sg,X"))] + (clobber (match_scratch:DI 3 "=&Sg, X"))] "" "@ s_getpc_b64\t%3\;s_add_u32\t%L3, %L3, %1@rel32@lo+4\;s_addc_u32\t%H3, %H3, %1@rel32@hi+4\;s_swappc_b64\ts[18:19], %3 @@ -921,11 +921,11 @@ (define_insn "gcn_call_value" (set_attr "length" "24")]) (define_insn "gcn_call_value_indirect" - [(set (match_operand 0 "register_operand" "=Sg") - (call (mem (match_operand:DI 1 "register_operand" "Sg")) + [(set (match_operand 0 "register_operand" "=Sgv") + (call (mem (match_operand:DI 1 "register_operand" " Sg")) (match_operand 2 "" ""))) (clobber (reg:DI LR_REGNUM)) - (clobber (match_scratch:DI 3 "=X"))] + (clobber (match_scratch:DI 3 "= X"))] "" "s_swappc_b64\ts[18:19], %1" [(set_attr "type" "sop1")