From patchwork Mon Jan 13 20:08:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Packard X-Patchwork-Id: 104711 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E05A83857BB3 for ; Mon, 13 Jan 2025 20:35:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E05A83857BB3 Authentication-Results: sourceware.org; dkim=fail reason="signature verification failed" (2048-bit key, unprotected) header.d=keithp.com header.i=@keithp.com header.a=rsa-sha256 header.s=mail header.b=QYNBbSfB; dkim=fail reason="signature verification failed" (2048-bit key) header.d=keithp.com header.i=@keithp.com header.a=rsa-sha256 header.s=mail header.b=iiO9xYIo X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from elaine.keithp.com (home.keithp.com [63.227.221.253]) by sourceware.org (Postfix) with ESMTPS id ECB343858405 for ; Mon, 13 Jan 2025 20:26:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ECB343858405 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=keithp.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=keithp.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org ECB343858405 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=63.227.221.253 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736799974; cv=none; b=K2sFv8y0I6eA62UT0jPJ+7GQslIp0mFw//4k4mlW9Mv973VNfzUGdxCgOM3n4/aLB20mEMX2Esy8Q9eC9QSCp9mOXwGeTqYnO+++F5aQPjkWTIPE7RaDvHfHKt02auHDyRWwxEw/MgcA3B3DSzYNzJKA7ofHHVl02c/P8LLTJPM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736799974; c=relaxed/simple; bh=1FLPk0emVFKojOJ/+cHVY5L/tDfHIkNRbW7SPSOeZ5U=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=uCn4kIdou32uRspgm22Gp+s9mtF7+og8iiAvV0Issk30oZT1c1Ru9duh3UpYT9+FhaGfvT03UB+yc4d7y9x+WTT4zD5Jvtli5sGQcXUALxOfVjIwoaB4FyneAD1PQCubRNgZh0L5trA4Rrq8fQtUe+zdcfwrZBlGO9cpjOdckUk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ECB343858405 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=keithp.com; s=mail; t=1736799973; bh=1FLPk0emVFKojOJ/+cHVY5L/tDfHIkNRbW7SPSOeZ5U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QYNBbSfBQysql1xQD0mJjs/SJKWsZjXct6eE96gQNdVWdrEVgTZNqAHkpoYhBioKM lnqZG6yUE9s3UTnEnyfxpC9NGihMEgjl5sZqQ5l71fDj8vBP5+wQzifRMnH6MerplI tm/CPTg/UHmZKbh1ibE1HYyt6oXdsLESWv/eSNk/1inNmoLwc6/eSMJ1k40GFpBvIe 2tfHdcR8oJK3a+TKEdVwNjt+4Ng2gbibgjUmvwN1t6h2fiNiMycnmWW24DUemJ8raa GWHl6LRVNM9x+w4vXwtlZo7cMAV98WYIzvv9Zkz6lCa2MTI0I7OD18vszfXzpxntgJ E4DskTvepJHIg== Received: from localhost (localhost [127.0.0.1]) by elaine.keithp.com (Postfix) with ESMTP id 2D81B3F22951 for ; Mon, 13 Jan 2025 12:26:13 -0800 (PST) X-Virus-Scanned: Debian amavis at keithp.com Received: from elaine.keithp.com ([127.0.0.1]) by localhost (elaine.keithp.com [127.0.0.1]) (amavis, port 10024) with LMTP id dJxhyUpU-5Zn; Mon, 13 Jan 2025 12:26:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=keithp.com; s=mail; t=1736799969; bh=1FLPk0emVFKojOJ/+cHVY5L/tDfHIkNRbW7SPSOeZ5U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iiO9xYIoJz3vX0SQf0EtjAPFUxsh9xe7ZZGDW7nx7YQ0pZJBBUcCX2440eXdP1sO7 fmtFFVUxm4nmF/71egHkvsW5Ca6b2kDGjDrdmqPLZL3GahVKtH211oKOP80wRWR513 ie5SewbaWgwbwpcY8yfxAPdAoOtATs4S9AfUebCV0JGRrhqHiXptg2sn/s6dXOVErD xe/zoq5vg7TOw+CZZgmwjw3T63YYRRKP04xUrWUO/QEjq47Hz25s4Vvk+n1JpWTx9q wXChvWqh4NHHt2TsndsGTzA+sVCEqK013ljNnHV7qTFUJyY1BGM8fyEnm9qI1rvST+ fMtukFvtWVmgA== Received: from keithp.com (koto.keithp.com [192.168.11.2]) by elaine.keithp.com (Postfix) with ESMTPSA id F15B03F20874; Mon, 13 Jan 2025 12:26:09 -0800 (PST) Received: by keithp.com (Postfix, from userid 1000) id 9EDC81E6007A; Mon, 13 Jan 2025 12:26:09 -0800 (PST) From: Keith Packard To: gcc-patches@gcc.gnu.org Cc: Keith Packard Subject: [PATCH 1/4] lm32: Args with arg.named false still get passed in regs Date: Mon, 13 Jan 2025 12:08:31 -0800 Message-ID: <20250113202607.3288177-2-keithp@keithp.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250113202607.3288177-1-keithp@keithp.com> References: <20250113202607.3288177-1-keithp@keithp.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org Signed-off-by: Keith Packard --- gcc/config/lm32/lm32.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gcc/config/lm32/lm32.cc b/gcc/config/lm32/lm32.cc index 4445295fe2b..d78efc59da5 100644 --- a/gcc/config/lm32/lm32.cc +++ b/gcc/config/lm32/lm32.cc @@ -632,8 +632,7 @@ lm32_function_arg (cumulative_args_t cum_v, const function_arg_info &arg) if (targetm.calls.must_pass_in_stack (arg)) return NULL_RTX; - if (!arg.named - || *cum + LM32_NUM_REGS2 (arg.mode, arg.type) > LM32_NUM_ARG_REGS) + if (*cum + LM32_NUM_REGS2 (arg.mode, arg.type) > LM32_NUM_ARG_REGS) return NULL_RTX; return gen_rtx_REG (arg.mode, *cum + LM32_FIRST_ARG_REG); From patchwork Mon Jan 13 20:08:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Packard X-Patchwork-Id: 104707 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4A1B13858405 for ; Mon, 13 Jan 2025 20:28:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4A1B13858405 Authentication-Results: sourceware.org; dkim=fail reason="signature verification failed" (2048-bit key, unprotected) header.d=keithp.com header.i=@keithp.com header.a=rsa-sha256 header.s=mail header.b=TABw6UM4; dkim=fail reason="signature verification failed" (2048-bit key) header.d=keithp.com header.i=@keithp.com header.a=rsa-sha256 header.s=mail header.b=It/ZtsKS X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from elaine.keithp.com (home.keithp.com [63.227.221.253]) by sourceware.org (Postfix) with ESMTPS id 83C023858432 for ; Mon, 13 Jan 2025 20:26:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 83C023858432 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=keithp.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=keithp.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 83C023858432 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=63.227.221.253 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736799974; cv=none; b=XPJ7iutagt8yJg2Hm2ny6wm/Vjx6I3MZE3wDT8XXoHMskyRXlb45MXoeQdhbbTVN6xxVHJoI9CUJS6kDXRRa6SpDpsv26qSM/qHEIsoX/faPhGU98EP7rLg/ZPmZZGKw8jsHViiRJELQqKsBsPbPni98lvRFTDXyl26pdaiR6Yg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736799974; c=relaxed/simple; bh=oE2lswkMvXNmHq5jr90k+dMW88Cp881tNhaviQNyrsM=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=w5rAjsKYDDoSmfi+BfVjm1xqIwxgPZKd3l192C8vlTAliWTwemFPN6rcfpAemMd1ujzSoaU8lHp4WqbX0kwbstNlIZ1evBeDyc3pXMf3qfvzBPrrW4l7wcZaM52B/F2qT29XlDsQqFvEino3qvao1A5W3nyoSER5OZHjRFsUrSY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 83C023858432 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=keithp.com; s=mail; t=1736799973; bh=oE2lswkMvXNmHq5jr90k+dMW88Cp881tNhaviQNyrsM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TABw6UM4hh9ZsvkNF9scf7ntaYcwbnGxi9Cz9fjYLsA8eV66pMJ3P80Afu/5irKQp Lyr9Ne/XwylzY2C99a1nJLgZBLJhPPA8d+lkJy1q8CZ3cfECcaIsIq1WGJTK3K5NqG lx912akrGMF/I11bxKXdlWLiQVKofv03jSDC7Ph3KNIUBDdV+WrdGjLbljluuA61+C kPMue1/GWuKfwMyC39As11yuu8zW9iJQuOLEBpDgCzIRsHyjNgU7gXUjrVe/nGl1fu HlEIdYwzX9yTo71glUY8coV8e8b5uQV/EomTin5BCC9tkEA818RcaBdzC0FJSChLak XtgtYgSdhBnpg== Received: from localhost (localhost [127.0.0.1]) by elaine.keithp.com (Postfix) with ESMTP id AA31E3F20874 for ; Mon, 13 Jan 2025 12:26:13 -0800 (PST) X-Virus-Scanned: Debian amavis at keithp.com Received: from elaine.keithp.com ([127.0.0.1]) by localhost (elaine.keithp.com [127.0.0.1]) (amavis, port 10024) with LMTP id gjWvHx5iEBca; Mon, 13 Jan 2025 12:26:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=keithp.com; s=mail; t=1736799970; bh=oE2lswkMvXNmHq5jr90k+dMW88Cp881tNhaviQNyrsM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=It/ZtsKSt7S3ZpR2bbSG0WujT/5y9OmwqJ9bFKIFR3avd87GGkEv4+3sjS76rl8Wc tmjedgFT1o/LQ2HKhuMhkkM2YfVfpgRZeoSPYHLSkDca8t0EGc0JjUBoD7aJsgIuI6 57eJhd8ukcoQ2dX7u9qdPsMFv+NEm4HwUoBOp6HWeCrvAykCNFGFp0Qy0hcpAJHJRK dBXqiAzr5pc7wzn2cR1YIIuUOYVHFliS7cnbPiY4x2r7WVNMKenTUFe93g6ky78XCy 390PrFrKMUHNyfODJ30mgQl581HfcgzABx9kLYr+TTsVFOT4xB1TTvGmeAR7Z83aDe mRivH4/Ffnh+A== Received: from keithp.com (koto.keithp.com [192.168.11.2]) by elaine.keithp.com (Postfix) with ESMTPSA id 03E743F221A8; Mon, 13 Jan 2025 12:26:10 -0800 (PST) Received: by keithp.com (Postfix, from userid 1000) id A0C851E60090; Mon, 13 Jan 2025 12:26:09 -0800 (PST) From: Keith Packard To: gcc-patches@gcc.gnu.org Cc: Keith Packard Subject: [PATCH 2/4] lm32: Skip last named param when computing save varargs regs Date: Mon, 13 Jan 2025 12:08:32 -0800 Message-ID: <20250113202607.3288177-3-keithp@keithp.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250113202607.3288177-1-keithp@keithp.com> References: <20250113202607.3288177-1-keithp@keithp.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org The cumulative args value in setup_incoming_varargs points at the last named parameter. We need to skip over that (if present) to get to the first anonymous argument as we only want to include those anonymous args in the saved register block. Signed-off-by: Keith Packard --- gcc/config/lm32/lm32.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/gcc/config/lm32/lm32.cc b/gcc/config/lm32/lm32.cc index d78efc59da5..dfec28608a0 100644 --- a/gcc/config/lm32/lm32.cc +++ b/gcc/config/lm32/lm32.cc @@ -679,14 +679,18 @@ lm32_setup_incoming_varargs (cumulative_args_t cum_v, const function_arg_info &arg, int *pretend_size, int no_rtl) { - CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v); + CUMULATIVE_ARGS next_cum = *get_cumulative_args (cum_v); int first_anon_arg; tree fntype; fntype = TREE_TYPE (current_function_decl); + if (!TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (current_function_decl)) + || arg.type != NULL_TREE) + lm32_function_arg_advance (pack_cumulative_args (&next_cum), arg); + if (stdarg_p (fntype)) - first_anon_arg = *cum + LM32_FIRST_ARG_REG; + first_anon_arg = next_cum + LM32_FIRST_ARG_REG; else { /* this is the common case, we have been passed details setup @@ -697,7 +701,7 @@ lm32_setup_incoming_varargs (cumulative_args_t cum_v, int size = arg.promoted_size_in_bytes (); first_anon_arg = - *cum + LM32_FIRST_ARG_REG + + next_cum + LM32_FIRST_ARG_REG + ((size + UNITS_PER_WORD - 1) / UNITS_PER_WORD); } From patchwork Mon Jan 13 20:08:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Packard X-Patchwork-Id: 104709 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 671403857724 for ; Mon, 13 Jan 2025 20:33:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 671403857724 Authentication-Results: sourceware.org; dkim=fail reason="signature verification failed" (2048-bit key, unprotected) header.d=keithp.com header.i=@keithp.com header.a=rsa-sha256 header.s=mail header.b=hPNLUNhD; dkim=fail reason="signature verification failed" (2048-bit key) header.d=keithp.com header.i=@keithp.com header.a=rsa-sha256 header.s=mail header.b=WsoBORXg X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from elaine.keithp.com (home.keithp.com [63.227.221.253]) by sourceware.org (Postfix) with ESMTPS id A783E3858CDB for ; Mon, 13 Jan 2025 20:26:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A783E3858CDB Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=keithp.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=keithp.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A783E3858CDB Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=63.227.221.253 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736799972; cv=none; b=nXU6+O8mEMQAVcgQEwsmzI2YR6aKYpy4cv8h+24jIGja/VP+jBIWXNvePwMd4+ZGwBJXBqeUqO+PpdxVhhSo/OUdm2TTuPkdIfbBfYGFECw8Dr9eBvUsKoEMjKA69u6o2tuBsJeCxER8gF4SMteCDQw9cnqv1HdBGQOuZL0k3zY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736799972; c=relaxed/simple; bh=j1v/5yz01sCWnUh6HAPa7cPz/eX0oRmqwpEzpTkl3ac=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=IYJIns5q4gqLkGyeizTvs7/Of1+2mnlcr/Cly8aBRzqvzPGBB5B4LKHXk+yJ/u9+eWBHMUt1I3KjBBK35sGkAR7U1cGJ7QxWNzNYR0TnwAHKd7PnZkvjxyHoIf12kKiQbJL91ovg32i6Cn31w2lVzk+nAtC+pBQ6FRpmPYt9UjI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A783E3858CDB DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=keithp.com; s=mail; t=1736799971; bh=j1v/5yz01sCWnUh6HAPa7cPz/eX0oRmqwpEzpTkl3ac=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hPNLUNhDoGK7WtH7qQktnmPgP5VUjMsY5PU7Co0NabJVRxWyJxzH3aXpng0qmFujo PQtSSsrYIb+I1ExW3BwJUoVe/CjmkKrlx+MJkFF5hVJ0XmagcCmlW/4dhY75SFwNZ/ PlOV91kjYfNMrYV+Uc38FENv5aik/wmRMXFcn7M8zKHlX3431sSdSVru3tL5xSoVHa OrtiGHaXk860gbKCZRiBcpLC/XZCKzvHJJKFSz3Vc/QuzLUjwsE0fee9EGD0+cuZdH v4+A5tiQW7Pl3hnbJ6kGtBZuPoAeFVLiGNDvUIhvuARIN0NYL7bsQWNWHh6+oUOTNn vfoa62lJNO66g== Received: from localhost (localhost [127.0.0.1]) by elaine.keithp.com (Postfix) with ESMTP id 6AF9E3F2060D for ; Mon, 13 Jan 2025 12:26:11 -0800 (PST) X-Virus-Scanned: Debian amavis at keithp.com Received: from elaine.keithp.com ([127.0.0.1]) by localhost (elaine.keithp.com [127.0.0.1]) (amavis, port 10024) with LMTP id pNHdGf1CGh8d; Mon, 13 Jan 2025 12:26:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=keithp.com; s=mail; t=1736799969; bh=j1v/5yz01sCWnUh6HAPa7cPz/eX0oRmqwpEzpTkl3ac=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WsoBORXgW9mjRbXv7WA7OjM5nPn4g3M24PSHINhMKtBRXTJsCDe3a58AZFt2sIkCO p/Zw0unRseIZx/tLGsCxC1Og+JMUXOV5R7mIa4179+rTcDCiY0WgcCzq3Db9eMkP7v HGieOeugnuXgu0KgzYY7LainspXtAdV9V39Dzeui1zM75c5sPwkg/pPhySXcsL4SVM 5t3quT33ubqitfen/rnASL1Pp5W03xfx9lsawrW5NutwuWbN8G4O+mwbg5G2pFd1oF a2tsUlfEztAzevu8AYjDJc6S0WICn5hWDo1oPDszmEhZG5uLrJXukdlbcIbgWvGOFR NDi640F2hLl3g== Received: from keithp.com (koto.keithp.com [192.168.11.2]) by elaine.keithp.com (Postfix) with ESMTPSA id D9B3A3F204E0; Mon, 13 Jan 2025 12:26:09 -0800 (PST) Received: by keithp.com (Postfix, from userid 1000) id A38941E60098; Mon, 13 Jan 2025 12:26:09 -0800 (PST) From: Keith Packard To: gcc-patches@gcc.gnu.org Cc: Keith Packard Subject: [PATCH 3/4] lm32: Compute pretend_size in setup_incoming_varargs even if no_rtl Date: Mon, 13 Jan 2025 12:08:33 -0800 Message-ID: <20250113202607.3288177-4-keithp@keithp.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250113202607.3288177-1-keithp@keithp.com> References: <20250113202607.3288177-1-keithp@keithp.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org Adjust the conditionals so that pretend_size is always computed, even if no_rtl is set. Signed-off-by: Keith Packard --- gcc/config/lm32/lm32.cc | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/gcc/config/lm32/lm32.cc b/gcc/config/lm32/lm32.cc index dfec28608a0..b677953bb4c 100644 --- a/gcc/config/lm32/lm32.cc +++ b/gcc/config/lm32/lm32.cc @@ -705,16 +705,18 @@ lm32_setup_incoming_varargs (cumulative_args_t cum_v, ((size + UNITS_PER_WORD - 1) / UNITS_PER_WORD); } - if ((first_anon_arg < (LM32_FIRST_ARG_REG + LM32_NUM_ARG_REGS)) && !no_rtl) + if (FUNCTION_ARG_REGNO_P (first_anon_arg)) { - int first_reg_offset = first_anon_arg; int size = LM32_FIRST_ARG_REG + LM32_NUM_ARG_REGS - first_anon_arg; - rtx regblock; - regblock = gen_rtx_MEM (BLKmode, - plus_constant (Pmode, arg_pointer_rtx, - FIRST_PARM_OFFSET (0))); - move_block_from_reg (first_reg_offset, regblock, size); + if (!no_rtl) + { + rtx regblock + = gen_rtx_MEM (BLKmode, + plus_constant (Pmode, arg_pointer_rtx, + FIRST_PARM_OFFSET (0))); + move_block_from_reg (first_anon_arg, regblock, size); + } *pretend_size = size * UNITS_PER_WORD; } From patchwork Mon Jan 13 20:08:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Packard X-Patchwork-Id: 104706 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A2BCC3857712 for ; Mon, 13 Jan 2025 20:28:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A2BCC3857712 Authentication-Results: sourceware.org; dkim=fail reason="signature verification failed" (2048-bit key, unprotected) header.d=keithp.com header.i=@keithp.com header.a=rsa-sha256 header.s=mail header.b=PzwcPm0L; dkim=fail reason="signature verification failed" (2048-bit key) header.d=keithp.com header.i=@keithp.com header.a=rsa-sha256 header.s=mail header.b=OVFRZgtH X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from elaine.keithp.com (home.keithp.com [63.227.221.253]) by sourceware.org (Postfix) with ESMTPS id 6F19F3858C39 for ; Mon, 13 Jan 2025 20:26:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6F19F3858C39 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=keithp.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=keithp.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6F19F3858C39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=63.227.221.253 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736799973; cv=none; b=psAwVo1ykDLoWEGOMAb9AQAy2DesnvIYXg76aY1yooCAO1xHueIFvdjNT7wI5w1yAaI8J3ibbaIf7qj5FvHhiBIW8jIz7+nsnjisUznCu4rqtn7yW+z97WLYveV9XxahWaaL6yap2E08Yi4w98CkxSRFg3EAHZ5QcY5m42XJHa4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736799973; c=relaxed/simple; bh=DQR2Dg8rolEwohfwaj80Q3sv4jYs8Y95YQpD7llnfvg=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=jHp+KjLV0/ZwQ8Tmf30lzWEOLUZ73neA/ytB3KMgDDhCt1aml0fwRLG/QMdNVkDuuNgKL5NWvDUv4euBbr020oKu7u89CikReihebxgAxF566AActe4anEo0C0USn6a2zYaTm9FR8rIOtzdgSeN6O2PJf6I7156JbQ71Qyc4C/M= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6F19F3858C39 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=keithp.com; s=mail; t=1736799972; bh=DQR2Dg8rolEwohfwaj80Q3sv4jYs8Y95YQpD7llnfvg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PzwcPm0LttXKCteMJ6gilXlWRs5/6ySB6Q9vpQ4oVkAGfIfiYELdAuFemCAOOCu6j zdxsR61JE63RTSnfG7N3zz8SaIgVBkcBtWG9b3+cIqTuSjgHOomvBWZIzFHWLrwoTX JqL8kErWirQfG5YWdnzYMIY+x1QKiJsrq/0+Qnk6ffj1qktPuKRgh4mamLxJjakkLH tD0fUiq6BIgYJikSc3DIa3DnEjhf5r7gCHYKTnisFMHQjauSw+Ef/gwHQ5H+1l6CQA TcRZHsPQX1BJifbiDXy3awMT4+2FwNUG5qUqhuWK/jLgWMXKVHCvRT5VvbHXXBXyIV 1wZZ9vUYzPSVQ== Received: from localhost (localhost [127.0.0.1]) by elaine.keithp.com (Postfix) with ESMTP id A17243F204E0 for ; Mon, 13 Jan 2025 12:26:12 -0800 (PST) X-Virus-Scanned: Debian amavis at keithp.com Received: from elaine.keithp.com ([127.0.0.1]) by localhost (elaine.keithp.com [127.0.0.1]) (amavis, port 10024) with LMTP id E0vye1I3ibtq; Mon, 13 Jan 2025 12:26:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=keithp.com; s=mail; t=1736799970; bh=DQR2Dg8rolEwohfwaj80Q3sv4jYs8Y95YQpD7llnfvg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OVFRZgtHSNTf19bhCWjGM++u3AVZWRLMw+VKwpdb8mMR5lcvDx5sG+6C7tSh0m26c hRPQsVFSwtJbc3IkZa6D4sGNTUlvIQpOtHvNwa+bKZrxfPbYTR6yz6tszpkhleaV9F VO2IzO5Sf92pUY7ODQni1pt6u4XtFMnoX2Keh10fE+1OwPPhyuPMdm4+uuFnpSxdqK EkOFyqHjbtFzVkTZKDPkxrdpJxRYt3LzHocRNiPew9wfDof2bvrfG3f/ZG7AL/fXZU ViKMT5EzvU+cuAg6BzcNljsQurzk3LbC4FRxJoG9nYk/f9gDLg8hE3qjJZGQ6k8/Ix aN/pK6bx34kDA== Received: from keithp.com (koto.keithp.com [192.168.11.2]) by elaine.keithp.com (Postfix) with ESMTPSA id 124663F22951; Mon, 13 Jan 2025 12:26:10 -0800 (PST) Received: by keithp.com (Postfix, from userid 1000) id A64B21E6009A; Mon, 13 Jan 2025 12:26:09 -0800 (PST) From: Keith Packard To: gcc-patches@gcc.gnu.org Cc: Keith Packard Subject: [PATCH 4/4] lm32: In va_arg, skip to stack args with too few remaining reg args Date: Mon, 13 Jan 2025 12:08:34 -0800 Message-ID: <20250113202607.3288177-5-keithp@keithp.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250113202607.3288177-1-keithp@keithp.com> References: <20250113202607.3288177-1-keithp@keithp.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org lm32 has 8 register parameter slots, so many vararg functions end up with several anonymous parameters passed in registers. If we run out of registers in the middle of a parameter, the entire parameter will be placed on the stack, skipping any remaining available registers. The receiving varargs function doesn't know this, and will save all of the possible parameter register values just below the stack parameters. When processing a va_arg call with a type size larger than a single register, we must check to see if it spans the boundary between register and stack parameters. If so, we need to skip to the stack parameters. This is done by making va_list a structure containing the arg pointer and the address of the start of the stack parameters. Boundary checks are inserted in va_arg calls to detect this case and the address of the parameter is set to the stack parameter start when the parameter crosses over. Signed-off-by: Keith Packard --- gcc/config/lm32/lm32.cc | 266 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 266 insertions(+) diff --git a/gcc/config/lm32/lm32.cc b/gcc/config/lm32/lm32.cc index b677953bb4c..15728969fad 100644 --- a/gcc/config/lm32/lm32.cc +++ b/gcc/config/lm32/lm32.cc @@ -44,6 +44,11 @@ #include "expr.h" #include "tm-constrs.h" #include "builtins.h" +#include "langhooks.h" +#include "stor-layout.h" +#include "fold-const.h" +#include "gimple.h" +#include "gimplify.h" /* This file should be included last. */ #include "target-def.h" @@ -66,6 +71,10 @@ static bool lm32_in_small_data_p (const_tree); static void lm32_setup_incoming_varargs (cumulative_args_t cum, const function_arg_info &, int *pretend_size, int no_rtl); +static tree lm32_build_builtin_va_list (void); +static void lm32_builtin_va_start (tree valist, rtx nextarg); +static tree lm32_gimplify_va_arg_expr (tree valist, tree type, gimple_seq *pre_p, + gimple_seq *post_p); static bool lm32_rtx_costs (rtx x, machine_mode mode, int outer_code, int opno, int *total, bool speed); static bool lm32_can_eliminate (const int, const int); @@ -92,6 +101,13 @@ static HOST_WIDE_INT lm32_starting_frame_offset (void); #define TARGET_PROMOTE_FUNCTION_MODE default_promote_function_mode_always_promote #undef TARGET_SETUP_INCOMING_VARARGS #define TARGET_SETUP_INCOMING_VARARGS lm32_setup_incoming_varargs +#undef TARGET_BUILD_BUILTIN_VA_LIST +#define TARGET_BUILD_BUILTIN_VA_LIST lm32_build_builtin_va_list +#undef TARGET_EXPAND_BUILTIN_VA_START +#define TARGET_EXPAND_BUILTIN_VA_START lm32_builtin_va_start +#undef TARGET_GIMPLIFY_VA_ARG_EXPR +#define TARGET_GIMPLIFY_VA_ARG_EXPR lm32_gimplify_va_arg_expr + #undef TARGET_FUNCTION_ARG #define TARGET_FUNCTION_ARG lm32_function_arg #undef TARGET_FUNCTION_ARG_ADVANCE @@ -721,6 +737,254 @@ lm32_setup_incoming_varargs (cumulative_args_t cum_v, *pretend_size = size * UNITS_PER_WORD; } } +/* This is the "struct __va_list". */ + +static GTY(()) tree va_list_type; + +/* Implement TARGET_BUILD_BUILTIN_VA_LIST. */ + +static tree +lm32_build_builtin_va_list (void) +{ + /* We keep one pointer and a count + + The pointer is the regular void * + + The count tracks how many registers arguments + remain. When that goes to zero, we have to skip + over the reserved space that was the top of the + stack at function entry + + */ + tree va_list_name; + tree ap_field; + tree ap_reg_field; + + va_list_type = lang_hooks.types.make_type (RECORD_TYPE); + /* Name it */ + va_list_name = build_decl (BUILTINS_LOCATION, + TYPE_DECL, + get_identifier ("__va_list"), + va_list_type); + + DECL_ARTIFICIAL (va_list_name) = 1; + TYPE_NAME (va_list_type) = va_list_name; + TYPE_STUB_DECL (va_list_type) = va_list_name; + + ap_field = build_decl (BUILTINS_LOCATION, + FIELD_DECL, + get_identifier("__ap"), + ptr_type_node); + DECL_ARTIFICIAL (ap_field) = 1; + DECL_FIELD_CONTEXT (ap_field) = va_list_type; + TYPE_FIELDS (va_list_type) = ap_field; + + ap_reg_field = build_decl(BUILTINS_LOCATION, + FIELD_DECL, + get_identifier("__ap_reg"), + ptr_type_node); + DECL_ARTIFICIAL (ap_reg_field) = 1; + DECL_FIELD_CONTEXT (ap_reg_field) = va_list_type; + DECL_CHAIN (ap_field) = ap_reg_field; + + layout_type (va_list_type); + + return va_list_type; +} + +/* Implement TARGET_EXPAND_BUILTIN_VA_START. */ + +static void +lm32_builtin_va_start (tree valist, rtx nextarg) +{ + const CUMULATIVE_ARGS *cum; + tree ap_field, ap_reg_field; + tree ap, ap_reg; + tree t; + int pretend_args_size = crtl->args.pretend_args_size; + cum = &crtl->args.info; + + ap_field = TYPE_FIELDS(TREE_TYPE (valist)); + ap = build3 (COMPONENT_REF, TREE_TYPE (ap_field), valist, + ap_field, NULL_TREE); + + std_expand_builtin_va_start (ap, nextarg); + + ap_reg_field = DECL_CHAIN(ap_field); + ap_reg = build3 (COMPONENT_REF, TREE_TYPE (ap_reg_field), valist, + ap_reg_field, NULL_TREE); + + /* Emit code to initialize __ap_reg */ + + rtx last_reg_arg = expand_binop (ptr_mode, add_optab, + crtl->args.internal_arg_pointer, + gen_int_mode (pretend_args_size, Pmode), + NULL_RTX, 0, OPTAB_LIB_WIDEN); + + rtx ap_reg_r = expand_expr (ap_reg, NULL_RTX, VOIDmode, EXPAND_WRITE); + convert_move (ap_reg_r, last_reg_arg, 0); +} + +#ifndef PAD_VARARGS_DOWN +#define PAD_VARARGS_DOWN BYTES_BIG_ENDIAN +#endif + +/* + * This was copied from "standard" implementation of va_arg, and then + * handling for overflow of the register paramters added + */ + +static tree +lm32_std_gimplify_va_arg_expr (tree valist, tree ap_reg, tree type, gimple_seq *pre_p, + gimple_seq *post_p) +{ + tree addr, t, type_size, rounded_size, valist_tmp; + unsigned HOST_WIDE_INT align, boundary; + bool indirect; + + /* All of the alignment and movement below is for args-grow-up machines. + As of 2004, there are only 3 ARGS_GROW_DOWNWARD targets, and they all + implement their own specialized gimplify_va_arg_expr routines. */ + if (ARGS_GROW_DOWNWARD) + gcc_unreachable (); + + indirect = pass_va_arg_by_reference (type); + if (indirect) + type = build_pointer_type (type); + + if (targetm.calls.split_complex_arg + && TREE_CODE (type) == COMPLEX_TYPE + && targetm.calls.split_complex_arg (type)) + { + tree real_part, imag_part; + + real_part = std_gimplify_va_arg_expr (valist, + TREE_TYPE (type), pre_p, NULL); + real_part = get_initialized_tmp_var (real_part, pre_p); + + imag_part = std_gimplify_va_arg_expr (unshare_expr (valist), + TREE_TYPE (type), pre_p, NULL); + imag_part = get_initialized_tmp_var (imag_part, pre_p); + + return build2 (COMPLEX_EXPR, type, real_part, imag_part); + } + + align = PARM_BOUNDARY / BITS_PER_UNIT; + boundary = targetm.calls.function_arg_boundary (TYPE_MODE (type), type); + + /* When we align parameter on stack for caller, if the parameter + alignment is beyond MAX_SUPPORTED_STACK_ALIGNMENT, it will be + aligned at MAX_SUPPORTED_STACK_ALIGNMENT. We will match callee + here with caller. */ + if (boundary > MAX_SUPPORTED_STACK_ALIGNMENT) + boundary = MAX_SUPPORTED_STACK_ALIGNMENT; + + boundary /= BITS_PER_UNIT; + + /* Hoist the valist value into a temporary for the moment. */ + valist_tmp = get_initialized_tmp_var (valist, pre_p); + + /* va_list pointer is aligned to PARM_BOUNDARY. If argument actually + requires greater alignment, we must perform dynamic alignment. */ + if (boundary > align + && !TYPE_EMPTY_P (type) + && !integer_zerop (TYPE_SIZE (type))) + { + t = build2 (MODIFY_EXPR, TREE_TYPE (valist), valist_tmp, + fold_build_pointer_plus_hwi (valist_tmp, boundary - 1)); + gimplify_and_add (t, pre_p); + + t = build2 (MODIFY_EXPR, TREE_TYPE (valist), valist_tmp, + fold_build2 (BIT_AND_EXPR, TREE_TYPE (valist), + valist_tmp, + build_int_cst (TREE_TYPE (valist), -boundary))); + gimplify_and_add (t, pre_p); + } + else + boundary = align; + + /* If the actual alignment is less than the alignment of the type, + adjust the type accordingly so that we don't assume strict alignment + when dereferencing the pointer. */ + boundary *= BITS_PER_UNIT; + if (boundary < TYPE_ALIGN (type)) + { + type = build_variant_type_copy (type); + SET_TYPE_ALIGN (type, boundary); + } + + /* Compute the rounded size of the type. */ + type_size = arg_size_in_bytes (type); + rounded_size = round_up (type_size, align); + + /* Reduce rounded_size so it's sharable with the postqueue. */ + gimplify_expr (&rounded_size, pre_p, post_p, is_gimple_val, fb_rvalue); + + /* + * Check for a large parameter which didn't fit in the remaining registers + * and got pushed off to the stack instead + */ + if (int_size_in_bytes(type) > UNITS_PER_WORD) { + + /* Hoist the ap_reg value into a temporary for the moment. */ + tree ap_reg_tmp = get_initialized_tmp_var (ap_reg, pre_p); + + t = fold_build2_loc (input_location, TRUTH_AND_EXPR, + boolean_type_node, + fold_build2_loc (input_location, LT_EXPR, boolean_type_node, + valist_tmp, ap_reg_tmp), + fold_build2_loc (input_location, GT_EXPR, boolean_type_node, + fold_build_pointer_plus (valist_tmp, rounded_size), ap_reg_tmp)); + + t = fold_build3 (COND_EXPR, TREE_TYPE(valist), t, ap_reg_tmp, valist_tmp); + + t = build2 (MODIFY_EXPR, TREE_TYPE (valist), valist_tmp, t); + + gimplify_and_add (t, pre_p); + } + + /* Get AP. */ + addr = valist_tmp; + if (PAD_VARARGS_DOWN && !integer_zerop (rounded_size)) + { + /* Small args are padded downward. */ + t = fold_build2_loc (input_location, GT_EXPR, sizetype, + rounded_size, size_int (align)); + t = fold_build3 (COND_EXPR, sizetype, t, size_zero_node, + size_binop (MINUS_EXPR, rounded_size, type_size)); + addr = fold_build_pointer_plus (addr, t); + } + + /* Compute new value for AP. */ + t = fold_build_pointer_plus (valist_tmp, rounded_size); + t = build2 (MODIFY_EXPR, TREE_TYPE (valist), valist, t); + gimplify_and_add (t, pre_p); + + addr = fold_convert (build_pointer_type (type), addr); + + if (indirect) + addr = build_va_arg_indirect_ref (addr); + + return build_va_arg_indirect_ref (addr); +} + +/* Return an expression of type "void *" pointing to the next + available argument in a variable-argument list. VALIST is the + user-level va_list object, of type __builtin_va_list. */ +/* Implement TARGET_GIMPLIFY_VA_ARG_EXPR. */ +static tree +lm32_gimplify_va_arg_expr (tree valist, tree type, gimple_seq *pre_p, + gimple_seq *post_p) +{ + tree ap_field = TYPE_FIELDS(TREE_TYPE (valist)); + tree ap_reg_field = DECL_CHAIN(ap_field); + tree ap = build3 (COMPONENT_REF, TREE_TYPE (ap_field), valist, + ap_field, NULL_TREE); + tree ap_reg = build3 (COMPONENT_REF, TREE_TYPE (ap_reg_field), valist, + ap_reg_field, NULL_TREE); + + return lm32_std_gimplify_va_arg_expr(ap, ap_reg, type, pre_p, post_p); +} /* Override command line options. */ static void @@ -1257,3 +1521,5 @@ lm32_starting_frame_offset (void) { return UNITS_PER_WORD; } + +#include "gt-lm32.h"