From patchwork Mon Oct 21 18:46: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: 2000066 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=jymQnl9q; 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 4XXPTZ3zZ3z1xvv for ; Tue, 22 Oct 2024 05:48:34 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B418D385801B for ; Mon, 21 Oct 2024 18:48:32 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from out203-205-221-191.mail.qq.com (out203-205-221-191.mail.qq.com [203.205.221.191]) by sourceware.org (Postfix) with UTF8SMTPS id 7AC133858D28 for ; Mon, 21 Oct 2024 18:47:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7AC133858D28 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 7AC133858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=203.205.221.191 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729536446; cv=none; b=NSgWwWwHTsPVctc2Bbj+7u593WAqgDFwpHDqrE3h0CpHRRamsFCGN5IUwO3kXoIIdP2EEz9OKw7MzlMMcRTQS/3MDxlNlPSwxrkqRsBw9X3xULQSUQw2YH2CKhiBoKt4LF+w1BDZVcZ+ylRKEbEsl5y99sGtArzb0xNTnpJl/bA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729536446; c=relaxed/simple; bh=Nty6z1MCENZOrZYcjnX8aWBSD3rsy809m6Huxy7BSfM=; h=DKIM-Signature:Message-ID:From:To:Subject:Date:MIME-Version; b=d6l579E4ue+jV3EMEG5WCjYiWjCoLPRamK5Y1tRcTyemXjViu7hP+2DlpFqTMVRyqnF8onQzxFOx3XBiSC5X2D7wdc8UUL+i4p9XD402qWWj9/4ahCSZtHu5G0emqY1G1tbsigQrKlROFD1NEbBMUKJeClKqu3rdP3TTpALEvJE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1729536420; bh=LaSo87VJUKKpEWm+ygm6FHbZU0RcJB+RTxock1queD4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=jymQnl9qPjqs5mJFnergqDB7578d9MVCxGhMamc3sCFQRF9RybXytTd92118iUK7L s7ASIiU215Q1m2mKGR9rW3WGqiTxPV098RxYHpXQHQuzj+nsAbDEnYKhYwSN/bt4ET AMuhyHJxXHJMjXCTPN1B01EMnLT2tjjr8X3tGB38= Received: from cyy-pc.lan ([240e:379:227f:d300:3578:1918:1859:abc5]) by newxmesmtplogicsvrszb21-0.qq.com (NewEsmtp) with SMTP id BBA3A217; Tue, 22 Oct 2024 02:46:58 +0800 X-QQ-mid: xmsmtpt1729536418tp70x8fou Message-ID: X-QQ-XMAILINFO: M1rD3f8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ZcBmk+rGaHB39IOB3GRMzcuy5Z7N8BZ4Ra6I= X-QQ-XMRINFO: Mp0Kj//9VHAxr69bL5MkOOs= From: Yangyu Chen To: gcc-patches@gcc.gnu.org Cc: Kito Cheng , Palmer Dabbelt , Jiawei , Jeff Law , Evgeny Stupachenko , Andrew Carlotti , Yangyu Chen , Hank Chang Subject: [PATCH v2 06/11] RISC-V: Implement TARGET_OPTION_VALID_VERSION_ATTRIBUTE_P Date: Tue, 22 Oct 2024 02:46:56 +0800 X-OQ-MSGID: <20241021184656.3259330-1-cyy@cyyself.name> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-9.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, HELO_DYNAMIC_IPADDR, RCVD_IN_DNSWL_NONE, RDNS_DYNAMIC, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLACK 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~incoming=patchwork.ozlabs.org@gcc.gnu.org This patch implements the TARGET_OPTION_VALID_VERSION_ATTRIBUTE_P for RISC-V. This hook is used to process attribute ((target_version ("..."))). Co-Developed-by: Hank Chang gcc/ChangeLog: * config/riscv/riscv-protos.h (riscv_option_valid_version_attribute_p): Declare. (riscv_process_target_version_attr): Declare. * config/riscv/riscv-target-attr.cc (riscv_process_target_version_attr): New function. (riscv_option_valid_version_attribute_p): New function. * config/riscv/riscv.cc (TARGET_OPTION_VALID_VERSION_ATTRIBUTE_P): Implement it. --- gcc/config/riscv/riscv-protos.h | 4 ++ gcc/config/riscv/riscv-target-attr.cc | 81 +++++++++++++++++++++++++++ gcc/config/riscv/riscv.cc | 4 ++ 3 files changed, 89 insertions(+) diff --git a/gcc/config/riscv/riscv-protos.h b/gcc/config/riscv/riscv-protos.h index cee6bbddc10..ed001729317 100644 --- a/gcc/config/riscv/riscv-protos.h +++ b/gcc/config/riscv/riscv-protos.h @@ -800,7 +800,11 @@ void riscv_init_cumulative_args (CUMULATIVE_ARGS *, tree, rtx, tree, int); extern bool riscv_option_valid_attribute_p (tree, tree, tree, int); extern bool +riscv_option_valid_version_attribute_p (tree, tree, tree, int); +extern bool riscv_process_target_attr (const char *, location_t); +extern bool +riscv_process_target_version_attr (tree, location_t); extern void riscv_override_options_internal (struct gcc_options *); extern void riscv_option_override (void); diff --git a/gcc/config/riscv/riscv-target-attr.cc b/gcc/config/riscv/riscv-target-attr.cc index 4c85ad60b72..3042562c66b 100644 --- a/gcc/config/riscv/riscv-target-attr.cc +++ b/gcc/config/riscv/riscv-target-attr.cc @@ -460,3 +460,84 @@ riscv_option_valid_attribute_p (tree fndecl, tree, tree args, int) cl_target_option_restore (&global_options, &global_options_set, &cur_target); return ret; } + +/* Parse the tree in ARGS that contains the target_version attribute + information and update the global target options space. */ + +bool +riscv_process_target_version_attr (tree args, location_t loc) +{ + if (TREE_CODE (args) == TREE_LIST) + { + if (TREE_CHAIN (args)) + { + error ("attribute % has multiple values"); + return false; + } + args = TREE_VALUE (args); + } + + if (!args || TREE_CODE (args) != STRING_CST) + { + error ("attribute % argument not a string"); + return false; + } + + const char *str = TREE_STRING_POINTER (args); + if (strcmp (str, "default") == 0) + return true; + + return riscv_process_target_attr (str, loc); +} + + +/* Implement TARGET_OPTION_VALID_VERSION_ATTRIBUTE_P. This is used to + process attribute ((target_version ("..."))). */ + +bool +riscv_option_valid_version_attribute_p (tree fndecl, tree, tree args, int) +{ + struct cl_target_option cur_target; + bool ret; + tree new_target; + tree existing_target = DECL_FUNCTION_SPECIFIC_TARGET (fndecl); + location_t loc = DECL_SOURCE_LOCATION (fndecl); + + /* Save the current target options to restore at the end. */ + cl_target_option_save (&cur_target, &global_options, &global_options_set); + + /* If fndecl already has some target attributes applied to it, unpack + them so that we add this attribute on top of them, rather than + overwriting them. */ + if (existing_target) + { + struct cl_target_option *existing_options + = TREE_TARGET_OPTION (existing_target); + + if (existing_options) + cl_target_option_restore (&global_options, &global_options_set, + existing_options); + } + else + cl_target_option_restore (&global_options, &global_options_set, + TREE_TARGET_OPTION (target_option_current_node)); + + ret = riscv_process_target_version_attr (args, loc); + + /* Set up any additional state. */ + if (ret) + { + riscv_override_options_internal (&global_options); + new_target = build_target_option_node (&global_options, + &global_options_set); + } + else + new_target = NULL; + + if (fndecl && ret) + DECL_FUNCTION_SPECIFIC_TARGET (fndecl) = new_target; + + cl_target_option_restore (&global_options, &global_options_set, &cur_target); + + return ret; +} diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index 947864fc3a6..789667da386 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -13075,6 +13075,10 @@ riscv_stack_clash_protection_alloca_probe_range (void) #undef TARGET_OPTION_FUNCTION_VERSIONS #define TARGET_OPTION_FUNCTION_VERSIONS riscv_common_function_versions +#undef TARGET_OPTION_VALID_VERSION_ATTRIBUTE_P +#define TARGET_OPTION_VALID_VERSION_ATTRIBUTE_P \ + riscv_option_valid_version_attribute_p + struct gcc_target targetm = TARGET_INITIALIZER; #include "gt-riscv.h"