From patchwork Mon Oct 21 18:45:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangyu Chen X-Patchwork-Id: 2000062 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=QIfFB8+G; 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 4XXPQx2V9xz1xvv for ; Tue, 22 Oct 2024 05:46:17 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 88E0A3858CDB for ; Mon, 21 Oct 2024 18:46:15 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from out203-205-221-235.mail.qq.com (out203-205-221-235.mail.qq.com [203.205.221.235]) by sourceware.org (Postfix) with UTF8SMTPS id 964173858C53 for ; Mon, 21 Oct 2024 18:45:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 964173858C53 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 964173858C53 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=203.205.221.235 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729536353; cv=none; b=XxUuk8zgbfPLYTbVPXqriSr4C8LEyVhMkMjCYo3jhe1gAkzbhHtmLbuXbu2l5/DCFeJE4oeofYmydqx+FiHw+hfxGf5uzcVtDkUbKVjqbZoMioGst/cEJEgAMPjdixKYl6MM+0SYLcvk89b8nnD3AINAIA8iDyWsnTRD6vploes= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729536353; c=relaxed/simple; bh=JsVP2LTj+wnHwv8HWYMBXIrSo/CZLF9c9CDQOP3BW6A=; h=DKIM-Signature:Message-ID:From:To:Subject:Date:MIME-Version; b=O8XTraqo5Fo3QGW18VK2nyPN56z3HZyB3Fn1AAc4x8nNl4PbpWSxOz66lXM+kSQVxM5ztemnZ3o59uBatI9I2rOOIRK8iQab23RvMP//jYkwQ1FYhXjmoc8rjyRClEyF+JO0I8g2WPyUeqd80k8Eqc4vqjfGXshFgrvGMAmawno= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1729536338; bh=e/XdXkHxh/76vKORlgA0ty6Fa81oH5rbEaC0rsw+poo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=QIfFB8+G5vItlQQItPQr+xTOQG9mHZlWjDMas5hxqbOkNqznYjyddFG+DdBpO4Fo+ tZhTkBE054ukfoHDWcC3X2FCZhf3SxYCaom683RivwfikTLvVfsv5sLvwaoNoGwWp5 a065qcNIhEM1G+4s7XgYux6Pja9Siokq67MM/aEM= Received: from cyy-pc.lan ([240e:379:227f:d300:3578:1918:1859:abc5]) by newxmesmtplogicsvrszc16-0.qq.com (NewEsmtp) with SMTP id B63A4890; Tue, 22 Oct 2024 02:45:35 +0800 X-QQ-mid: xmsmtpt1729536335tf9fqyx4l Message-ID: X-QQ-XMAILINFO: N7h1OC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Q-XMRINFO: OD9hHCdaPRBwq3WW+NvGbIU= From: Yangyu Chen To: gcc-patches@gcc.gnu.org Cc: Kito Cheng , Palmer Dabbelt , Jiawei , Jeff Law , Evgeny Stupachenko , Andrew Carlotti , Yangyu Chen Subject: [PATCH v2 02/11] RISC-V: Split riscv_process_target_attr with const char *args argument Date: Tue, 22 Oct 2024 02:45:25 +0800 X-OQ-MSGID: <20241021184534.3258226-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=-10.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, HELO_DYNAMIC_IPADDR, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, 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~incoming=patchwork.ozlabs.org@gcc.gnu.org This patch splits static bool riscv_process_target_attr (tree args, location_t loc) into two functions: - bool riscv_process_target_attr (const char *args, location_t loc) - static bool riscv_process_target_attr (tree args, location_t loc) Thus, we can call `riscv_process_target_attr` with a `const char *` argument. This is useful for implementation of `target_version` attribute. gcc/ChangeLog: * config/riscv/riscv-target-attr.cc (riscv_process_target_attr): Split into two functions with const char *args argument --- gcc/config/riscv/riscv-protos.h | 2 + gcc/config/riscv/riscv-target-attr.cc | 65 +++++++++++++++------------ 2 files changed, 39 insertions(+), 28 deletions(-) diff --git a/gcc/config/riscv/riscv-protos.h b/gcc/config/riscv/riscv-protos.h index d690162bb0c..cee6bbddc10 100644 --- a/gcc/config/riscv/riscv-protos.h +++ b/gcc/config/riscv/riscv-protos.h @@ -799,6 +799,8 @@ extern bool riscv_use_divmod_expander (void); 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_process_target_attr (const char *, 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 bf14ade5ce0..8ce9607b3c9 100644 --- a/gcc/config/riscv/riscv-target-attr.cc +++ b/gcc/config/riscv/riscv-target-attr.cc @@ -304,35 +304,13 @@ num_occurrences_in_str (char c, char *str) return res; } -/* Parse the tree in ARGS that contains the target attribute information +/* Parse the string in ARGS that contains the target attribute information and update the global target options space. */ -static bool -riscv_process_target_attr (tree args, location_t loc) +bool +riscv_process_target_attr (const char *args, location_t loc) { - if (TREE_CODE (args) == TREE_LIST) - { - do - { - tree head = TREE_VALUE (args); - if (head) - { - if (!riscv_process_target_attr (head, loc)) - return false; - } - args = TREE_CHAIN (args); - } while (args); - - return true; - } - - if (TREE_CODE (args) != STRING_CST) - { - error_at (loc, "attribute % argument not a string"); - return false; - } - - size_t len = strlen (TREE_STRING_POINTER (args)); + size_t len = strlen (args); /* No need to emit warning or error on empty string here, generic code already handle this case. */ @@ -343,7 +321,7 @@ riscv_process_target_attr (tree args, location_t loc) std::unique_ptr buf (new char[len+1]); char *str_to_check = buf.get (); - strcpy (str_to_check, TREE_STRING_POINTER (args)); + strcpy (str_to_check, args); /* Used to catch empty spaces between semi-colons i.e. attribute ((target ("attr1;;attr2"))). */ @@ -366,7 +344,7 @@ riscv_process_target_attr (tree args, location_t loc) if (num_attrs != num_semicolons + 1) { error_at (loc, "malformed % attribute", - TREE_STRING_POINTER (args)); + args); return false; } @@ -376,6 +354,37 @@ riscv_process_target_attr (tree args, location_t loc) return true; } +/* Parse the tree in ARGS that contains the target attribute information + and update the global target options space. */ + +static bool +riscv_process_target_attr (tree args, location_t loc) +{ + if (TREE_CODE (args) == TREE_LIST) + { + do + { + tree head = TREE_VALUE (args); + if (head) + { + if (!riscv_process_target_attr (head, loc)) + return false; + } + args = TREE_CHAIN (args); + } while (args); + + return true; + } + + if (TREE_CODE (args) != STRING_CST) + { + error_at (loc, "attribute % argument not a string"); + return false; + } + + return riscv_process_target_attr (TREE_STRING_POINTER (args), loc); +} + /* Implement TARGET_OPTION_VALID_ATTRIBUTE_P. This is used to process attribute ((target ("..."))). Note, that riscv_set_current_function() has not been called before,