From patchwork Tue Nov 5 03:22:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangyu Chen X-Patchwork-Id: 2006600 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=a4S/kn6Q; 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 4XjDDV00P3z1xyD for ; Tue, 5 Nov 2024 14:22:49 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2A9743857037 for ; Tue, 5 Nov 2024 03:22:48 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from out162-62-58-216.mail.qq.com (out162-62-58-216.mail.qq.com [162.62.58.216]) by sourceware.org (Postfix) with UTF8SMTPS id 2B3903857706 for ; Tue, 5 Nov 2024 03:22:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2B3903857706 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 2B3903857706 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=162.62.58.216 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730776938; cv=none; b=gNbI8OulnclnYOcF/YbYpdcfb+KVHxhnG6G4pWC79gnLKLJ3MVLTXtJOYNfnAqY4NQ61Nb+aygW8/8lZG5+dxf+GgFRbf1BaMeNEkI0t7ggdnB1dXYz16p+7g/p0lmN+6mZ83D0l6YduUVnVzDI13Q5pvgJpzmjk7QoEEnhS+mo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730776938; c=relaxed/simple; bh=SCA7DgNuHFwWE0i1mIMGDtI9d0rXYB1zhyWBlm0S6lA=; h=DKIM-Signature:Message-ID:From:To:Subject:Date:MIME-Version; b=Ci2xn/XVo4Ljcl5uXl8k9//H13O2VlDvqWtvh/0+h56NXCDf8OI16JUyVBOa7BcZIF5yPhMBclLc6GI5+IDcjGubk56K23u9ygp6fa+abR6hx7/jFou2FNPA+V/eC1gEXMAK+GPHJ1/YD3QXXQbJ/VARyPVjeQhaKCtnVOU7hTE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1730776930; bh=ENk4V19HYiQZ7OEvb/I0zWP2xPmKNooYb2GxzfuTnd0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=a4S/kn6Qi3eLnMZ3QjgXWajZ/39qeVhcuXA6+KSdVh6Of3tSKKlygwTDKrR7Pvirh mwyxW/s1QJK15AWjeuWa5R+YoUnXSCFi7waERCyAV/RPQGfnDx45K9SxFEGHbFNygm YswjDnAnuzz8sV6BzlINCnSKiMya/3KwSpbHouf4= Received: from cyy-pc.lan ([240e:379:2276:5d00:cda0:97a5:84f4:5191]) by newxmesmtplogicsvrszc16-0.qq.com (NewEsmtp) with SMTP id 5878DA8A; Tue, 05 Nov 2024 11:22:07 +0800 X-QQ-mid: xmsmtpt1730776927t1yvewei3 Message-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giMEqjU8sj qLkdbkIlaSHPte6OvDkd2SYMPXv/AqW9q8ZmrjQg== X-QQ-XMRINFO: M/715EihBoGSf6IYSX1iLFg= From: Yangyu Chen To: gcc-patches@gcc.gnu.org Cc: Kito Cheng , Palmer Dabbelt , Jiawei , Jeff Law , Evgeny Stupachenko , Andrew Carlotti , Hank Chang , Yangyu Chen Subject: [PATCH v5 2/8] RISC-V: Implement Priority syntax parser for Function Multi-Versioning Date: Tue, 5 Nov 2024 11:22:00 +0800 X-OQ-MSGID: <20241105032200.2645476-1-cyy@cyyself.name> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 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 adds the priority syntax parser to support the Function Multi-Versioning (FMV) feature in RISC-V. This feature allows users to specify the priority of the function version in the attribute syntax. Chnages based on RISC-V C-API PR: https://github.com/riscv-non-isa/riscv-c-api-doc/pull/85 Signed-off-by: Yangyu Chen gcc/ChangeLog: * config/riscv/riscv-target-attr.cc (riscv_target_attr_parser::handle_priority): New function. (riscv_target_attr_parser::update_settings): Update priority attribute. * config/riscv/riscv.opt: Add TargetVariable riscv_fmv_priority. --- gcc/config/riscv/riscv-target-attr.cc | 24 ++++++++++++++++++++++++ gcc/config/riscv/riscv.opt | 3 +++ 2 files changed, 27 insertions(+) diff --git a/gcc/config/riscv/riscv-target-attr.cc b/gcc/config/riscv/riscv-target-attr.cc index 8ce9607b3c9..293d5321215 100644 --- a/gcc/config/riscv/riscv-target-attr.cc +++ b/gcc/config/riscv/riscv-target-attr.cc @@ -39,16 +39,19 @@ public: : m_found_arch_p (false) , m_found_tune_p (false) , m_found_cpu_p (false) + , m_found_priority_p (false) , m_subset_list (nullptr) , m_loc (loc) , m_cpu_info (nullptr) , m_tune (nullptr) + , m_priority (0) { } bool handle_arch (const char *); bool handle_cpu (const char *); bool handle_tune (const char *); + bool handle_priority (const char *); void update_settings (struct gcc_options *opts) const; private: @@ -58,10 +61,12 @@ private: bool m_found_arch_p; bool m_found_tune_p; bool m_found_cpu_p; + bool m_found_priority_p; riscv_subset_list *m_subset_list; location_t m_loc; const riscv_cpu_info *m_cpu_info; const char *m_tune; + int m_priority; }; } @@ -210,6 +215,22 @@ riscv_target_attr_parser::handle_tune (const char *str) return true; } +bool +riscv_target_attr_parser::handle_priority (const char *str) +{ + if (m_found_priority_p) + error_at (m_loc, "% attribute: priority appears more than once"); + m_found_priority_p = true; + + if (sscanf (str, "%d", &m_priority) != 1) + { + error_at (m_loc, "% attribute: invalid priority %qs", str); + return false; + } + + return true; +} + void riscv_target_attr_parser::update_settings (struct gcc_options *opts) const { @@ -236,6 +257,9 @@ riscv_target_attr_parser::update_settings (struct gcc_options *opts) const if (m_cpu_info) opts->x_riscv_tune_string = m_cpu_info->tune; } + + if (m_priority) + opts->x_riscv_fmv_priority = m_priority; } /* Parse ARG_STR which contains the definition of one target attribute. diff --git a/gcc/config/riscv/riscv.opt b/gcc/config/riscv/riscv.opt index 5bc5d300293..ab9d6e82723 100644 --- a/gcc/config/riscv/riscv.opt +++ b/gcc/config/riscv/riscv.opt @@ -523,6 +523,9 @@ Mask(XSFVCP) Var(riscv_sifive_subext) Mask(XSFCEASE) Var(riscv_sifive_subext) +TargetVariable +int riscv_fmv_priority = 0 + Enum Name(isa_spec_class) Type(enum riscv_isa_spec_class) Supported ISA specs (for use with the -misa-spec= option):