From patchwork Thu Oct 24 07:08:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangyu Chen X-Patchwork-Id: 2001465 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=qq.com header.i=@qq.com header.a=rsa-sha256 header.s=s201512 header.b=g//m7eYC; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XYxr30byVz1xw0 for ; Thu, 24 Oct 2024 18:09:55 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3FD6B3858C32 for ; Thu, 24 Oct 2024 07:09:53 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from out203-205-221-231.mail.qq.com (out203-205-221-231.mail.qq.com [203.205.221.231]) by sourceware.org (Postfix) with UTF8SMTPS id D044D385840C for ; Thu, 24 Oct 2024 07:09:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D044D385840C 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 D044D385840C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=203.205.221.231 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729753770; cv=none; b=Ko8oQHtP2AzMJ+vimYzfM35gl87YHb6CuUMvqzjT9Cru905HW5Jlzx3YTdmlJOcM3yOM6Qvt8viraNEinQSh7UALEWUngmuufkYS2bcyft/dzO6Ip5QYBvlAR1Qffae6xas4sOEiBc8UCCObW9vXPgSPauVdkusfVQAwI1IRC7w= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729753770; c=relaxed/simple; bh=d3cbQWY/oeRjXmHFxl3fW+I+mZcQCT+7a/kooOtkR/M=; h=DKIM-Signature:Message-ID:From:To:Subject:Date:MIME-Version; b=WuOD58WqBdbHZigqzvaU0tK6Coh7q4UYtoo/7DodJJR0g/VMqdqvzFAhGx87378sOHxvYwjU4qO0mwv9UR34DaBeu81nxatb49vlXZRm2cu/mIztl4l19Sqz7vQv0bKKxBVcNN8HLg4/x4fUN6RF6kpNuLurvfBQzBMrk3I13d8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1729753750; bh=agYtK6bIsJMUPJJMr5yUTkTFPh3on0d5+oJtSTSvjtY=; h=From:To:Cc:Subject:Date; b=g//m7eYCcD6UGPYKjmNkrEUDrdUj7Nxw9LRfCHedWKlmYI/X3EsFpjEVM7EOJOo7T s/3zWw7u/dXH9RPt95F5AhtndTMAtncmS+h13fb/niQq4e+yoTjVlvkecufPdw/jvB 0BfEz++jQ6PIjAjZyUQp6gTSyleC1whHO5WKR/Is= Received: from cyy-pc.lan ([240e:379:2265:5e00:1651:dae2:1a9c:8827]) by newxmesmtplogicsvrsza36-0.qq.com (NewEsmtp) with SMTP id 242AAA4D; Thu, 24 Oct 2024 15:09:02 +0800 X-QQ-mid: xmsmtpt1729753742twkezxpeb Message-ID: X-QQ-XMAILINFO: N7pVCJF/rxxTzPWO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: Yangyu Chen To: gcc-patches@gcc.gnu.org Cc: Kito Cheng , Palmer Dabbelt , Jiawei , Jeff Law , Evgeny Stupachenko , Andrew Carlotti , Yangyu Chen Subject: [PATCH v3 00/11] RISC-V: Add Function Multi-Versioning support Date: Thu, 24 Oct 2024 15:08:56 +0800 X-OQ-MSGID: <20241024070856.1833033-1-cyy@cyyself.name> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, HELO_DYNAMIC_IPADDR, RCVD_IN_DNSWL_NONE, RDNS_DYNAMIC, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=no 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~incoming=patchwork.ozlabs.org@gcc.gnu.org This patch series adds support for Function Multi-Versioning (FMV) to RISC-V. The FMV feature allows users to specify multiple versions of a function and select the version at runtime based on the target_clones and target_version attributes, which follow the RISC-V C-API Docs [1] and the existing proposal about priority syntax [2]. To test this series with the GLIBC dynamic loader, you should apply patch [3] for GLIBC to ensure the dynamic loader will initialize the gp register correctly. Changes since v2: - Add missing replacement for TARGET_CLONES_ATTR_SEPARATOR - Move RISC-V Extension Bitmask Definitions to riscv-ext-bitmask.def v2: https://patchwork.sourceware.org/project/gcc/list/?series=39772&state=* Changes since v1: - Add RISC-V FMV test cases - Split patches for better review - Fix commet typo in dispatch_function_versions - Severial improvements in function riscv_process_target_version_attr - Initialize m_priority in riscv_target_attr_parser constructor - Use unsigned to reference feature bits array in compare_fmv_features - Never check "default" target in riscv_process_target_attr since we have already checked it in riscv_process_target_version_attr v1: https://patchwork.sourceware.org/project/gcc/patch/tencent_3B2442361B6DF87E046FB4E71D55715D6309@qq.com/ [1] https://github.com/riscv-non-isa/riscv-c-api-doc/blob/c6c5d6d9cf96b342293315a5dff3d25e96ef8191/src/c-api.adoc#__attribute__targetattr-string [2] https://github.com/riscv-non-isa/riscv-c-api-doc/pull/85 [3] https://patchwork.sourceware.org/project/glibc/patch/tencent_71D182FBDA6E8E57B80731DD218D8D5C7C08@qq.com/ Yangyu Chen (11): Introduce TARGET_CLONES_ATTR_SEPARATOR for RISC-V RISC-V: Split riscv_process_target_attr with const char *args argument RISC-V: Implement Priority syntax parser for Function Multi-Versioning RISC-V: Implement riscv_minimal_hwprobe_feature_bits RISC-V: Implement TARGET_COMPARE_VERSION_PRIORITY and TARGET_OPTION_FUNCTION_VERSIONS RISC-V: Implement TARGET_OPTION_VALID_VERSION_ATTRIBUTE_P RISC-V: Implement TARGET_MANGLE_DECL_ASSEMBLER_NAME RISC-V: Do not inline when callee is versioned but caller is not RISC-V: Reapply target_version attribute after target attribute RISC-V: Implement TARGET_GENERATE_VERSION_DISPATCHER_BODY and TARGET_GET_FUNCTION_VERSIONS_DISPATCHER RISC-V: Add Multi-Versioning Test Cases gcc/attribs.cc | 17 +- gcc/common/config/riscv/riscv-common.cc | 94 +++ gcc/common/config/riscv/riscv-ext-bitmask.def | 83 ++ gcc/config/riscv/feature_bits.h | 44 + gcc/config/riscv/riscv-protos.h | 6 + gcc/config/riscv/riscv-subset.h | 5 + gcc/config/riscv/riscv-target-attr.cc | 198 ++++- gcc/config/riscv/riscv.cc | 756 ++++++++++++++++++ gcc/config/riscv/riscv.h | 7 + gcc/config/riscv/riscv.opt | 3 + gcc/defaults.h | 4 + gcc/multiple_target.cc | 19 +- gcc/testsuite/g++.target/riscv/mv-symbols1.C | 70 ++ gcc/testsuite/g++.target/riscv/mv-symbols2.C | 61 ++ gcc/testsuite/g++.target/riscv/mv-symbols3.C | 50 ++ gcc/testsuite/g++.target/riscv/mv-symbols4.C | 56 ++ gcc/testsuite/g++.target/riscv/mv-symbols5.C | 62 ++ gcc/testsuite/g++.target/riscv/mvc-symbols1.C | 49 ++ gcc/testsuite/g++.target/riscv/mvc-symbols2.C | 36 + gcc/testsuite/g++.target/riscv/mvc-symbols3.C | 42 + gcc/testsuite/g++.target/riscv/mvc-symbols4.C | 32 + gcc/tree.cc | 4 +- 22 files changed, 1649 insertions(+), 49 deletions(-) create mode 100644 gcc/common/config/riscv/riscv-ext-bitmask.def create mode 100644 gcc/config/riscv/feature_bits.h create mode 100644 gcc/testsuite/g++.target/riscv/mv-symbols1.C create mode 100644 gcc/testsuite/g++.target/riscv/mv-symbols2.C create mode 100644 gcc/testsuite/g++.target/riscv/mv-symbols3.C create mode 100644 gcc/testsuite/g++.target/riscv/mv-symbols4.C create mode 100644 gcc/testsuite/g++.target/riscv/mv-symbols5.C create mode 100644 gcc/testsuite/g++.target/riscv/mvc-symbols1.C create mode 100644 gcc/testsuite/g++.target/riscv/mvc-symbols2.C create mode 100644 gcc/testsuite/g++.target/riscv/mvc-symbols3.C create mode 100644 gcc/testsuite/g++.target/riscv/mvc-symbols4.C