From patchwork Tue Oct 7 12:44:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangyu Chen X-Patchwork-Id: 121418 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 A2AE33858C83 for ; Tue, 7 Oct 2025 12:50:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A2AE33858C83 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=qq.com header.i=@qq.com header.a=rsa-sha256 header.s=s201512 header.b=h8ERIAcs X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from out203-205-221-190.mail.qq.com (out203-205-221-190.mail.qq.com [203.205.221.190]) by sourceware.org (Postfix) with UTF8SMTPS id 75C043858C62 for ; Tue, 7 Oct 2025 12:45:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 75C043858C62 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=cyyself.name Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=cyyself.name ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 75C043858C62 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=203.205.221.190 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1759841103; cv=none; b=r5DdPgqUuKDEeGcq25JEwFTl/PFxq73CZvz9j8lv7NEvLgp503p5aeXCKVxX0+2lrB6k3k7H6gqISpDKTS4vSKa+oyClvg/eoHKl3wiv6ic+16tv11Z0bRPsjHtjBWRqZjCplq6LxXQ73WnmrjAcHPGasDy5COQPLb5e67pzGC4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1759841103; c=relaxed/simple; bh=SVDEl38NFyi3XinkHnmTMPqYYkqbTWaR1jjIlZdr/7g=; h=DKIM-Signature:Message-ID:From:To:Subject:Date:MIME-Version; b=FWFDfko1n9ghf0Vlg/yixYS0n3f6O5C+GGQW+2wtOViu4neftwmkdfFMnLeudxxh3eoqveuw4qtGKbGb4TOqi++iJoHiyqG3bKYzsZhLelsjE5SbhbPefA6k3skOWpcU8/XyT8440+I5agmjODVblz4ryNDE4/ZdEUWmTl7rAXE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 75C043858C62 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1759841099; bh=U5RxtsPJltEU0JGJXC8VOt77Oe1d3IMBCmqb5StgWw4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=h8ERIAcsdX1CeEcFzgCg+uhV4Qeowb+3xgT0gds7SPwV9H8rYGCn7pviXLjwxLly/ EK3xh2VaczoCCTXeGiuYK4dsOS8yxS0IC8Z2G1uj9gMR3tjaJSq/yCDJGG9/9G+a/m 5AeA4yL6KRJysOVq9pnbI1IXXmLT8S0W5eu3HWNc= Received: from cyy-pc.lan ([240e:379:2266:a000:785f:fad1:3646:61bf]) by newxmesmtplogicsvrszb20-0.qq.com (NewEsmtp) with SMTP id B39336D6; Tue, 07 Oct 2025 20:44:57 +0800 X-QQ-mid: xmsmtpt1759841097tgndxaufg Message-ID: X-QQ-XMAILINFO: NbgegmlEc3Ju1TqDTTKjLSxlBtDw6nLdJGR7WIdI27SPEWz7cf4n7riQWPYYis 03Ib5ZtFh9Xs+iIBCTYyf+lxR8wefCE/oSrq3pEW/tDgqyxyY0LNKPp+XtsuBXRyM76KEbNh9dy7 qyaq7GP3rJZHkvFoTAfdxHy2VsKeGd/GKY3iNzadrptcRT2Euxr4EgC2/QQoX0rEvZo8jp6BOnaj BW5pQVWDl/ZXEKjx82S5gSpcE0u11pT9cX6AlS4FfBW47HKnoDQIZKlchUrYlZJmxIxHe97W55qw oP85c+7JHHWl4BuJEXm6Z3CzQkhmPtawoW8T9y8a2hznraTDtggUuyTa3T0dPCQAIbSHHbNYzU1t TMO/3w19RvcgHVoyaRtSZOCxAGH4zAb3YbcfGJVEnIcXvnPuHpM1SMhGCwkDP0XE+nZ1zKdJDM9r H+YwiDo8Il1q/P9Ovnzwg0HyD2OQU5JobetKdZL6ApNM0We3jiXMYWqCsXkFRnUPrpLflWICLpsV fJ0QiVOBoN6zUN5i/54u8VM/KMeJn4SXLlDHLQ/YGvg+Z0vaaTmdDPzwo6lxvw6+l/l2AcZQIz6L lJe7uTxk8Gp4zSxLR53hXIw7RJW9G+FtenPZEqtnrFuixGSO/ivYnc/M4wE7AMsH8q+sZLJtVbs+ O/JW3EmXabA1Fz1DACQWbfL512FYeIza2TEonOArffyrj250lXYx3y9lJ8HrFr0st6lqiGLfmQw9 +eW6u2o+FESpgORJ+1/phuDOPpUZGERuLfktOrWwLynNJI9rjNUKwNbhgyLqkhP33O6kWTrQ/aiz 2uR13RLu+aMgXfAjl/4MTm7JyBVjUvDX0dE77ZViQuikYGOX5Xu5k3SeF5OY4ddSHcDHMVGpyTdJ Kh4koXIzusctbovyPwwhn9HhZpU0PT65TE3q7bgMgRmBnPo1RUYIYufIzLMtqc2ORxGPhWbkEhq/ v7QD7AwUTXd8MQIDD8wY4T1rGmxgJaaub/XpAGBfcVChwlp9A8aqHnVMkBOOSWVEBYf4huq6iGNW PtLg8siYavIU9RCx3D3euqmlQQ7CyyNWgLgBjbQfaR9R2F7AU3FKWE/4ON01hgwen/lutt9gSOOL SEUPD0bs8AJwOcSxqumsNqwHh5jsTtcwmXQ5zR X-QQ-XMRINFO: OWPUhxQsoeAVDbp3OJHYyFg= From: Yangyu Chen To: gcc-patches@gcc.gnu.org Cc: Evgeny Stupachenko , Andrew Carlotti , Alfie Richards , Kito Cheng , Palmer Dabbelt , Jiawei , Jeff Law , David Malcolm , Yangyu Chen Subject: [PATCH v6 1/3] Fortran: Do not make_decl_rtl in trans_function_start Date: Tue, 7 Oct 2025 20:44:55 +0800 X-OQ-MSGID: <20251007124455.2984869-1-cyy@cyyself.name> X-Mailer: git-send-email 2.49.0 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-8.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, HELO_DYNAMIC_IPADDR, RCVD_IN_DNSWL_NONE, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, RDNS_DYNAMIC, 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 This patch is a preparation for the function multi-versioning support in Fortran. The function multi-versioning support requires changing the change_decl_assembler_name to add the target suffix, which is not allowed after make_decl_rtl is called, since the assembler name will be in the constant pool. This patch removes the make_decl_rtl call in trans_function_start, and it will finally be called in all my testcases since we will check it whenever using the DECL_RTL macro. Signed-off-by: Yangyu Chen gcc/fortran/ChangeLog: * trans-decl.cc (trans_function_start): Remove call make_decl_rtl. --- gcc/fortran/trans-decl.cc | 3 --- 1 file changed, 3 deletions(-) diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc index 055698b1efd..31b4ee0ee52 100644 --- a/gcc/fortran/trans-decl.cc +++ b/gcc/fortran/trans-decl.cc @@ -3056,9 +3056,6 @@ trans_function_start (gfc_symbol * sym) rest_of_decl_compilation (fndecl, 1, 0); } - /* Create RTL for function definition. */ - make_decl_rtl (fndecl); - allocate_struct_function (fndecl, false); /* function.cc requires a push at the start of the function. */ From patchwork Tue Oct 7 12:45:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangyu Chen X-Patchwork-Id: 121417 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 102723858C50 for ; Tue, 7 Oct 2025 12:47:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 102723858C50 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=qq.com header.i=@qq.com header.a=rsa-sha256 header.s=s201512 header.b=NR8CpF3I X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from out203-205-221-233.mail.qq.com (out203-205-221-233.mail.qq.com [203.205.221.233]) by sourceware.org (Postfix) with UTF8SMTPS id B98573858D1E for ; Tue, 7 Oct 2025 12:45:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B98573858D1E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=cyyself.name Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=cyyself.name ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B98573858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=203.205.221.233 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1759841116; cv=none; b=R0xRXEc4BlzFw0pK5WvdVYVg0rJaULbAQlk9Aqb9jtc0Itl3jGoHEjD2SBMD/k+AOtQfr7e5wWXepPCmlmyuToh6PcGnk8GQbGzVtu0jGKLaCq8CLK1n6Cqdoi4S09CqF6ZmCJb3T8l3FdE2kQgjDZ2wJMdbJk4UT3+G4g9lmeE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1759841116; c=relaxed/simple; bh=97Ioo5LOlc8yxTVDhTyYw4uxux4vSemywE97VNiobl4=; h=DKIM-Signature:Message-ID:From:To:Subject:Date:MIME-Version; b=JkB0qo/MU/dazepbrvRuisdD3GpMeHoZBzScbdHabaDDKWESDQGeX5PB/SadWcOuZ0KhIxV/s7ZmkR/e7Bh97QMcKRVejgPYZ5F6UTrX80SsEWiVopUWAy5HiqD9pkXQPqfj+c0rQo/dA8NHyWQg+uLuf9YyUa20gArACfgvNj4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B98573858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1759841113; bh=5ZEUfu2jQ3vfNncdU2faFhO2igiN0GBhkeWNjCXADOs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=NR8CpF3Io5htbyD0aRMEC7pFVZ0HgGtc7PgLFd8BIbTDPoL7qK7T5NtaZvLFb6lJx OsCxLFnPlGgpNFZxNXPZWiEDYBn+jA+giRc829lBciKfbHJWDQCtN36hVw2HhpDLsJ 7bK+SOtSJct693JgiPR3MUUWWZNB21zUbFkw8ajw= Received: from cyy-pc.lan ([240e:379:2266:a000:785f:fad1:3646:61bf]) by newxmesmtplogicsvrsza56-0.qq.com (NewEsmtp) with SMTP id B4A2F49B; Tue, 07 Oct 2025 20:45:10 +0800 X-QQ-mid: xmsmtpt1759841110toq1smd2x Message-ID: X-QQ-XMAILINFO: MVrhzCz4YLrfLUHIt7mmfJts6/1sv3Vvm974t8DjMdLXftTi4AH7I66gN8pSuQ OiKtyQ5RvCZoofShSxe4qV+m9EYznE3+oARrj0naGBFKHE1/0SXByIqR7AzHVtN+Rklk+W0fghzO R1T80erEKEHCrcY9Xj/Vg7dar0YOB3F/lvR0v3a6sfs6CwCqsx1OBO0b7x3X3cuxA4fVD238B+53 ZAY7CZigHWL4OMFpwZ4kqMuYUgXFvYNxJStwrbFvq1qJ3HNUcjfJjY4XuVMHU/M39wm9hFX/hauw POL4WLsvy1vH1ZOr3nPh+u+9PWSj23mtFgbtl5tMbUCUsny0mHVx+gM4CH3KCzMhkWFEbLoafDpf IKjX3QDhEV9W0c78wNNcNSmrlgEP7tXuY7FS6tdBiuWj11ilrzIFjNOYSmbR1AdBxRbUDC3rd+Ow JeKwND4TWGygUgmqHxT92BDWPEAH9wsIfwZjb3D7to6WJr9MmAF1AJrTUcpmSvmuX6AqGoAPZ+zp Mhz7mLfWlLsgS9W0uFhQeysEteIDB3A1rzGDvUIS72IstwiJhHScoPIiEqAf+tfhsIhEsy0or6sL X20x/x7Xqa+cedy7T8dnUDT4cWx0uPZqcDOrj6xpoK6hn/Be4nOMqKcKJiunSa+dt3xr1BSsdsxF wzKc237oedgJqf0B0x+kO9l0ICJRLfNN2YlnQJRXxtfIaoqHohTWygevM/KxVmMP+osykxpiYStM 8ItiwXCKvIwKqoT1QDuUK7jyJOa80bIPn/takgZwr7rIbIiaijR011yElxlv7agCBfQADbtMiEnL jtqkXqyvHJddQCAM17cPUWz5tm+718Cg9sufDbvVqBQIXA7PcCpX8PmWwkdVj6MbpNeEdGVNFNjc 9H4lOysOWom2xApBQIsmI6eAiFQ1S5NoEkTscz7gEhJ1G00VXqutncjqZAm9JZ9IgRbUb2GkxEVD GyjWZx2V4WUg6L7yHl045SkyH+9Pun2LmLgV2Gj/3Sq/4ayqPNTGaGka0xdrI21NCeIiCUoDq3bA XuKpFUZIuIxwiEb5T60qRoPjcnpGHD/OFB9QdSXTUAToqVT3wIyrJLxXyP2l8BYw3njUwZhA== X-QQ-XMRINFO: OD9hHCdaPRBwq3WW+NvGbIU= From: Yangyu Chen To: gcc-patches@gcc.gnu.org Cc: Evgeny Stupachenko , Andrew Carlotti , Alfie Richards , Kito Cheng , Palmer Dabbelt , Jiawei , Jeff Law , David Malcolm , Yangyu Chen Subject: [PATCH v6 2/3] json: add iterate method to object class Date: Tue, 7 Oct 2025 20:45:09 +0800 X-OQ-MSGID: <20251007124509.2985640-1-cyy@cyyself.name> X-Mailer: git-send-email 2.49.0 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-8.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, HELO_DYNAMIC_IPADDR, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, RDNS_DYNAMIC, 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 Currently, the object class in json.h does not provide a way to iterate over its keys. This commit adds an `iterate` method to the object class, allowing users to iterate over the keys of a JSON object. Signed-off-by: Yangyu Chen gcc/ChangeLog: * json.h (class object): Add iterate method to object class. --- gcc/json.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gcc/json.h b/gcc/json.h index c706f2a4fe9..b87da9464de 100644 --- a/gcc/json.h +++ b/gcc/json.h @@ -183,6 +183,11 @@ class object : public value /* Set to literal true/false. */ void set_bool (const char *key, bool v); + bool iterate (unsigned i, const char **key) const + { + return m_keys.iterate (i, key); + } + static int compare (const json::object &obj_a, const json::object &obj_b); size_t get_num_keys () const { return m_keys.length (); } From patchwork Tue Oct 7 12:45:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangyu Chen X-Patchwork-Id: 121419 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 02B6A3858C56 for ; Tue, 7 Oct 2025 12:52:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 02B6A3858C56 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=qq.com header.i=@qq.com header.a=rsa-sha256 header.s=s201512 header.b=x4QYMVip X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from out203-205-221-245.mail.qq.com (out203-205-221-245.mail.qq.com [203.205.221.245]) by sourceware.org (Postfix) with UTF8SMTPS id 4E43A3858C42 for ; Tue, 7 Oct 2025 12:45:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4E43A3858C42 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=cyyself.name Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=cyyself.name ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4E43A3858C42 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=203.205.221.245 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1759841126; cv=none; b=mXWYG6Nex8yy93hJFaeOdmcEzE0O55iuWGAHpt/RulFzMbhdXfiaCA+28rC+fWjZtwbGeWa1MdF0kZC8uVAhNo6LAO2ZUgd6u+mBCzYwTTfMQuC7bIGhbK5B2jwwbIWLeBxl9qw/HHUxL7Eaz1SJPCkCbHRVSGeKzfQ7Vp06a1s= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1759841126; c=relaxed/simple; bh=kCoTiEFiQO1ujWSn7mafstB4yrQuPT9YOfyij8mUfig=; h=DKIM-Signature:Message-ID:From:To:Subject:Date:MIME-Version; b=SQFEnRjtUVJFCmQJqUQdfhEltBsNDwr2dgr57ge0/pFWmSFOo2l3j9SeC60jmvooRIWQ74mH8WQLz8OlDSHmt/Dg2avjSUN76UK7+E/t/coe4ye/k2eAhy0e5Q9ED8H7/IO1ZTeHuAN03vMlzxwS9HjntmduAscCrdf8/irDdzI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4E43A3858C42 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1759841122; bh=mj2LMCavYd04p+nvkqwNxuRzHK+pI3Uh1LD/SI50Bbw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=x4QYMViplun3QFcxzEs34CKNtYhl3PAxGaMk/ggM/eorHxQVX2PYiL49/PXmd9QpU LFbJ4qa6OjFQtgm43vSU1dh724SA1KeyHt82gyF/uk3xJreJOwSgMV9OR8vVAsgAjN VMmZwQjoc2pktKN3vE6qQUYW0o/UNqUyelP7x+o0= Received: from cyy-pc.lan ([240e:379:2266:a000:785f:fad1:3646:61bf]) by newxmesmtplogicsvrszb20-0.qq.com (NewEsmtp) with SMTP id B549FA7B; Tue, 07 Oct 2025 20:45:20 +0800 X-QQ-mid: xmsmtpt1759841120twdfhbfe7 Message-ID: X-QQ-XMAILINFO: NAuAIaytDrXpmwBgMEJ6LZ+nxln1rXTbq/pEJJGTJgBQ3Wj0pkiTjSTxACsO8a GcvdrN7nGGLw1ZMeeezjk1PV3u9kBTglt9XLgwPDUlJsm8tbqFkQhxq7t5ugxzkmaI9RNwoofzhF a3EafweFUNyKV2/EComCnSePzjowjOyyBXZXNgpPbssJlzqlVCeG0FGyPnzPbeDIzQFCVdmZyT/1 y8beLf3Oil7jWrw03KIX28X/0/DSbnJwW/PHXZV7OoatM3SE7TcYJkbqza6DryMjLkIdoYz0lQ4L w7WSzZbcThDIuZaDv60yfriF/xf4EC5fX7J2TXgL0Ld78NsIZiXeW/YBIcxzO5x/B7F1DEWCfJ6q IU2EG43uTc0KGIm8tlVRfdMwzzEFAzRlTHZ/9PpsYAB5ha32jBBL0DwFlo5CCiWPEDAJ7C0Oyxs0 4k5Jag2LH6iEAfQ6bittA4IclJJQdiSnNSQjmF2IvUvCJ0myJd1AJXDcksyDWWzjQ4GvIfL2e88D pKK+jpkEPr5YLdN26u14XFP1omibtUW7x90+ixfCoGk98s2rPG7mrHbaa996/DYJovvs5kKjY7PW Y+IoJGpmZV3UhpmgoVKLRHysx9KFtx42E9bkwaVbH5J3rngDQEyFs1h3zY7EYxQKLrIDxOQ80m/w AJEP83Zu08woXNrjvPH34Kpvs0k9fQKxQ4/o5iMF6IbgSetiHH/WPuepTLnxJvh02Ylz5QPc7SNt geZtmac2jUwB/hpN/24IlPFAabx/om9T23YACEmpJp7Y07hMo3+JDYU/Uc7UEnbOKEvr3ad1pv42 pV+hfHL16QP9BcKEs1DBT4ZWIBwl4EZLZ6siA6nGmyiR1Kfp2Wiei0sCX5ICeIcVryZBlii6g5gp zkYZ7isywtN+MW7oKAReAgKVTMazqH5I8hQYY/MpSVEJ6RNh429jivDrYZokJiiiO0tHVJKQYAak 4kjWjPljfSZeJzt/gAZhzTvaTIfc5v8kDogz6dUn+9TpacNKG656Swh3aFiafuM2qXR3ysUUU/V0 op6RFVKxDtHsTg49yNb/kvRSfjztWsZlJXOY7kXBYY6y8I2IdKn3hOqEOS2i8YXXokgTIlclNP4H xtr1mbIfBaHBQdTBJyFRFa2qgfqA+aZsugcWtds7PxwUX2IlE= X-QQ-XMRINFO: NS+P29fieYNw95Bth2bWPxk= From: Yangyu Chen To: gcc-patches@gcc.gnu.org Cc: Evgeny Stupachenko , Andrew Carlotti , Alfie Richards , Kito Cheng , Palmer Dabbelt , Jiawei , Jeff Law , David Malcolm , Yangyu Chen Subject: [PATCH v6 3/3] fmv: Add -ftarget-clones-table option support Date: Tue, 7 Oct 2025 20:45:20 +0800 X-OQ-MSGID: <20251007124520.2986390-1-cyy@cyyself.name> X-Mailer: git-send-email 2.49.0 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-8.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, HELO_DYNAMIC_IPADDR, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, RDNS_DYNAMIC, 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 This patch adds support for target_clones table option. The target_clones table option allows users to specify multiple versions of a function and select the version at runtime based on the specified table. The target clone table is a JSON object where function names serve as keys, and their values are nested objects. Each nested object maps architecture names to lists of target clone attributes. This structure allows specifying function clones for different architectures. Below is an example: ``` { "foo": { "x86_64": ["avx2", "avx512f"], "riscv64": ["arch=+v", "arch=+zba,+zbb", ...], ... // more architectures }, // more functions } ``` A example of the table is as follows on RISC-V: C source code "ror32.c": ``` void ror32(unsigned int *a, unsigned int b, unsigned long size) { for (unsigned long i = 0; i < size; i++) { a[i] = a[i] >> b | (a[i] << (32 - b)); } } ``` Table "ror32.target_clones": ``` { "ror32": { "riscv64": ["arch=+zvbb,+zbb", "arch=+zbb"] } } ``` Then use: gcc -O3 -ftarget-clones-table=ror32.target_clones -S ror32.c to compile the source code. This will generate 3 versions and its IFUNC resolver for the ror32 function which is "arch=+zvbb,+zbb" and "arch=+zbb" and the default version. Signed-off-by: Yangyu Chen gcc/ChangeLog: * Makefile.in: Add -DTARGET_NAME to CFLAGS-multiple_target.o. * common.opt: Add target clone table option. * multiple_target.cc (expand_target_clones): Add support for target_clones table option. (node_versionable_function_p): New function to check if a function can be versioned. (init_clone_map): Ditto. (ipa_target_clone): Ditto. * doc/invoke.texi: Add document for target clone table option. gcc/testsuite/ChangeLog: * gcc.target/i386/tct-0.c: New test. * gcc.target/i386/tct-0.json: New test. --- gcc/Makefile.in | 1 + gcc/common.opt | 7 + gcc/doc/invoke.texi | 69 +++++++++- gcc/multiple_target.cc | 158 +++++++++++++++++++++-- gcc/testsuite/gcc.target/i386/tct-0.c | 11 ++ gcc/testsuite/gcc.target/i386/tct-0.json | 5 + 6 files changed, 241 insertions(+), 10 deletions(-) create mode 100644 gcc/testsuite/gcc.target/i386/tct-0.c create mode 100644 gcc/testsuite/gcc.target/i386/tct-0.json diff --git a/gcc/Makefile.in b/gcc/Makefile.in index 4503dab6037..99ed204f036 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -2694,6 +2694,7 @@ s-bversion: BASE-VER $(STAMP) s-bversion CFLAGS-toplev.o += -DTARGET_NAME=\"$(target_noncanonical)\" +CFLAGS-multiple_target.o += -DTARGET_NAME=\"$(target_noncanonical)\" CFLAGS-tree-diagnostic-client-data-hooks.o += -DTARGET_NAME=\"$(target_noncanonical)\" CFLAGS-optinfo-emit-json.o += -DTARGET_NAME=\"$(target_noncanonical)\" $(ZLIBINC) CFLAGS-analyzer/engine.o += $(ZLIBINC) diff --git a/gcc/common.opt b/gcc/common.opt index f6d93dc05fb..102e03496b8 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -2718,6 +2718,13 @@ fprofile-reorder-functions Common Var(flag_profile_reorder_functions) Optimization Enable function reordering that improves code placement. +ftarget-clones-table= +Common Joined RejectNegative Var(target_clones_table) +Enable target clones attributes specified in the JSON file. + +Variable +const char *target_clones_table = NULL + fpatchable-function-entry= Common Var(flag_patchable_function_entry) Joined Optimization Insert NOP instructions at each function entry. diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 99607a09b89..2d7a883bf9b 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -651,7 +651,7 @@ Objective-C and Objective-C++ Dialects}. -fsplit-paths -fsplit-wide-types -fsplit-wide-types-early -fssa-backprop -fssa-phiopt -fstdarg-opt -fstore-merging -fstrict-aliasing -fipa-strict-aliasing --fthread-jumps -ftracer -ftree-bit-ccp +-ftarget-clones-table=@var{path} -fthread-jumps -ftracer -ftree-bit-ccp -ftree-builtin-call-dce -ftree-ccp -ftree-ch -ftree-coalesce-vars -ftree-copy-prop -ftree-cselim -ftree-dce -ftree-dominator-opts -ftree-dse -ftree-forwprop -ftree-fre -fcode-hoisting @@ -13581,6 +13581,73 @@ assumptions based on that. The default is @option{-fzero-initialized-in-bss} except in Ada. +@opindex ftarget-clones-table +@item -ftarget-clones-table=@var{path} +Read JSON formatted target_clone table to insert @code{target_clones} +attribute to functions based on the table contents. Where @var{path} is a +file path to the JSON formatted target_clone table. When attribute +@code{target_clones} is applied to a function, the compiler creates +multiple versions of the function for different targets. When attribute +@code{target_clones} also exist on the function definition, the targets +specified in the attribute and the targets specified in the JSON formatted +target_clone table are merged. + +This is useful when you want to optimize a function for different CPU +features and select the appropriate version at runtime based on the CPU +features of the machine the program is running on without source code +modification. + +This table is formatted as: + +@smallexample +@{ + "mangled_function_name1": @{ + "target1": ["attr1", ...], + ... + @}, + ... +@} +@end smallexample + +For example, say you have a C++ function named @code{foo} with return type +@code{void} without parameters, and you want to clone it for targets +@code{arch=x86-64-v3} and @code{arch=x86-64-v4} on x86-64 architecture. +You can create a JSON formatted target_clone table file named +@file{target_clones.json} with the following contents: + +@smallexample +@{ + "_Z3foov": @{ + "x86_64": ["arch=x86-64-v3", "arch=x86-64-v4"] + @} +@} +@end smallexample + +Then, you can use @option{-ftarget-clones-table=target_clones.json} +to clone the function @code{foo} for the targets +@code{arch=x86-64-v3} and @code{arch=x86-64-v4}. This is equivalent +to adding the following attribute to the function definition: + +@smallexample +#ifdef __x86_64__ +__attribute__ ((target_clones ("arch=x86-64-v3", "arch=x86-64-v4", "default"))) +#endif +void foo (void) @{ ... @} +@end smallexample + +This design also support to have multiple architectures in the same JSON +formatted target_clone table. For other architectures like aarch64 and +riscv64, you can add entries like the following: + +@smallexample +@{ + "_Z3barv": @{ + "aarch64": ["sve2"], + "riscv64": ["arch=+v,+zvfh"] + @} +@} +@end smallexample + @opindex fthread-jumps @item -fthread-jumps Perform optimizations that check to see if a jump branches to a diff --git a/gcc/multiple_target.cc b/gcc/multiple_target.cc index e85d7e71442..bf1fbc0ffdf 100644 --- a/gcc/multiple_target.cc +++ b/gcc/multiple_target.cc @@ -21,6 +21,10 @@ along with GCC; see the file COPYING3. If not see . */ #include "config.h" +#include +#define INCLUDE_MAP +#define INCLUDE_STRING +#define INCLUDE_SSTREAM #include "system.h" #include "coretypes.h" #include "backend.h" @@ -38,6 +42,7 @@ along with GCC; see the file COPYING3. If not see #include "gimple-walk.h" #include "tree-inline.h" #include "intl.h" +#include "json-parsing.h" /* Walker callback that replaces all FUNCTION_DECL of a function that's going to be versioned. */ @@ -252,30 +257,71 @@ create_target_clone (cgraph_node *node, bool definition, char *name, return new_node; } +/* Skip functions that are declared but not defined. Also skip C++ + virtual functions, as they cannot be cloned. The same logic is in the + function expand_target_clones below. */ +static bool node_versionable_function_p (cgraph_node *node) +{ + return (!node->definition + || (!node->alias && tree_versionable_function_p (node->decl))) + && !DECL_VIRTUAL_P (node->decl); +} + /* If the function in NODE has multiple target attributes create the appropriate clone for each valid target attribute. */ static bool -expand_target_clones (struct cgraph_node *node, bool definition) +expand_target_clones (struct cgraph_node *node, bool definition, + std::map > + &clone_map) { /* Parsing target attributes separated by TARGET_CLONES_ATTR_SEPARATOR. */ tree attr_target = lookup_attribute ("target_clones", DECL_ATTRIBUTES (node->decl)); - /* No targets specified. */ - if (!attr_target) - return false; - int num_defaults = 0; auto_vec attr_list = get_clone_versions (node->decl, &num_defaults); - - /* If the target clones list is empty after filtering, remove this node. */ - if (!TARGET_HAS_FMV_TARGET_ATTRIBUTE && attr_list.is_empty ()) + /* When target_clones attribute is present, but there is no valid + entries, we believe there can be another function with the same name + but has "target_version" specified, so we remove this function, this + only applies to aarch64 for now. For RISC-V, it will give an error + earlier. + + This can barely happen in practice as the "default" attribute can + always be added to avoid this. Thus, we even skip target clones table + lookup in this case. Any following architectures that use + "target_version" semantics should aware of this behaviour if it will + not give error but just skip during attribute checking. */ + if (!TARGET_HAS_FMV_TARGET_ATTRIBUTE && attr_list.is_empty () && attr_target) { node->remove (); return false; } + if (DECL_INITIAL (node->decl) != NULL_TREE) + { + auto it = clone_map.find (IDENTIFIER_POINTER ( + DECL_ASSEMBLER_NAME_RAW (node->decl))); + if (it != clone_map.end () && node_versionable_function_p (node)) + { + /* Merge valid target attributes from -ftarget-clones-table. */ + for (string_slice attr : it->second) + if (targetm.check_target_clone_version (attr, NULL)) + attr_list.safe_push (attr); + + if (num_defaults == 0) + { + /* No default in the source attribute, add one. */ + attr_list.safe_push ("default"); + num_defaults = 1; + } + } + } + + /* If there is no target_clones attribute, nothing to do. */ + if (attr_list.is_empty ()) + return false; + /* No need to clone for 1 target attribute. */ if (attr_list.length () == 1 && TARGET_HAS_FMV_TARGET_ATTRIBUTE) { @@ -506,11 +552,105 @@ is_simple_target_clones_case (cgraph_node *node) return true; } +/* Initialize the clone map from the target clone table JSON file. Specified + by the -ftarget-clone-table option. The map is a mapping from symbol name + to a string with target clones attributes separated by + TARGET_CLONES_ATTR_SEPARATOR. */ +static std::map > +init_clone_map (void) +{ + std::map > res; + if (! target_clones_table) + return res; + + /* Take target string from TARGET_NAME, this macro looks like + "x86_64-linux-gnu" and we need to strip all the suffixes + after the first dash, so it becomes "x86_64". */ + std::string target = TARGET_NAME; + if (target.find ('-') != std::string::npos) + target.erase (target.find ('-')); + + /* Open the target clone table file and read to a string. */ + std::ifstream json_file (target_clones_table); + if (json_file.fail ()) + { + error ("cannot open target clone table file %s", + target_clones_table); + return res; + } + std::stringstream ss_buf; + ss_buf << json_file.rdbuf (); + std::string json_str = ss_buf.str (); + + /* Parse the JSON string. + The JSON string format looks like this: + { + "symbol_name1": { + "target1": ["clone1", "clone2", ...], + "target2": ["clone1", "clone2", ...], + }, + ... + } + where symbol_name is the ASM name of the function mangled by the + frontend. The target1 and target2 are the targets, which can be + "x86_64", "aarch64", "riscv64", etc. The clone1, clone2, etc are the + target clones attributes, which can be "avx2", "avx512" etc. Note that + there is no need to specify the "default" target clone, it is + automatically added by the pass. */ + json::parser_result_t result = json::parse_utf8_string ( + json_str.size (), json_str.c_str (), true, NULL); + if (auto json_err = result.m_err.get ()) + { + error ("error parsing target clone table file %s: %s", + target_clones_table, json_err->get_msg ()); + return res; + } + + auto json_val = result.m_val.get (); + auto kind = json_val->get_kind (); + if (kind != json::JSON_OBJECT) + { + error ("target clone table file %s is not a JSON object", + target_clones_table); + return res; + } + auto json_obj = static_cast (json_val); + unsigned i; + const char *symbol_name; + FOR_EACH_VEC_ELT (*json_obj, i, symbol_name) + { + auto symbol_val = json_obj->get (symbol_name); + if (!symbol_val || symbol_val->get_kind () != json::JSON_OBJECT) + continue; + auto symbol_obj = static_cast (symbol_val); + auto cur_target_val = symbol_obj->get (target.c_str ()); + if (!cur_target_val + || cur_target_val->get_kind () != json::JSON_ARRAY) + continue; + auto cur_target_array = static_cast + (cur_target_val); + for (unsigned j = 0; j < cur_target_array->length (); j++) + { + auto target_str_val = cur_target_array->get (j); + if (target_str_val->get_kind () != json::JSON_STRING) + error ("target clones attribute is not a string"); + const char *target_str + = static_cast (target_str_val)->get_string (); + if (strcmp (target_str, "default") == 0) + error ("No need to specify \"default\" in target clones table"); + res[symbol_name].safe_push (string_slice (ggc_strdup (target_str))); + } + } + return res; +} + static unsigned int ipa_target_clone (bool early) { struct cgraph_node *node; auto_vec to_dispatch; + std::map > clone_map + = init_clone_map (); /* Don't need to do anything early for target attribute semantics. */ if (early && TARGET_HAS_FMV_TARGET_ATTRIBUTE) @@ -543,7 +683,7 @@ ipa_target_clone (bool early) the simple case. Simple cases are dispatched in the later stage. */ if (early == !is_simple_target_clones_case (node)) - if (expand_target_clones (node, node->definition) + if (expand_target_clones (node, node->definition, clone_map) && TARGET_HAS_FMV_TARGET_ATTRIBUTE) /* In non target_version semantics, dispatch all target clones. */ to_dispatch.safe_push (node); diff --git a/gcc/testsuite/gcc.target/i386/tct-0.c b/gcc/testsuite/gcc.target/i386/tct-0.c new file mode 100644 index 00000000000..0de0938e9fd --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/tct-0.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-require-ifunc "" } */ +/* { dg-options "-ftarget-clones-table=${srcdir}/gcc.target/i386/tct-0.json" } */ +/* { dg-final { scan-assembler "foo\.default" } } */ +/* { dg-final { scan-assembler "foo\.arch_x86_64_v2" } } */ +/* { dg-final { scan-assembler "foo\.arch_x86_64_v3" } } */ +/* { dg-final { scan-assembler "foo\.arch_x86_64_v4" } } */ + +void foo() { + +} diff --git a/gcc/testsuite/gcc.target/i386/tct-0.json b/gcc/testsuite/gcc.target/i386/tct-0.json new file mode 100644 index 00000000000..9dc712e66e2 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/tct-0.json @@ -0,0 +1,5 @@ +{ + "foo": { + "x86_64": ["arch=x86-64-v2", "arch=x86-64-v3", "arch=x86-64-v4"] + } +}