From patchwork Thu Oct 24 07:10:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangyu Chen X-Patchwork-Id: 2001471 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=GBem/roD; 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 4XYxsk0yKYz1xtp for ; Thu, 24 Oct 2024 18:11:22 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4A9383858C41 for ; Thu, 24 Oct 2024 07:11:20 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from out162-62-57-252.mail.qq.com (out162-62-57-252.mail.qq.com [162.62.57.252]) by sourceware.org (Postfix) with UTF8SMTPS id BC86F3858D28 for ; Thu, 24 Oct 2024 07:10:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BC86F3858D28 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 BC86F3858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=162.62.57.252 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729753858; cv=none; b=v3n4panV42jV1pO6BWZNXVyveN/Dc/XCGN/z514zrfjy+M6u41BDIXGCvszja0zACLhqtyoPpFn79YHMmsmMRmC6mmwL9rhDiy6WHL3xfnHqgJ7c95DWiTb2BcZY1i+u7eg0aq+nb4fJ7/PtuLHym/bAl7LX+2aGlmdgRx1vNZY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729753858; c=relaxed/simple; bh=lXMAYc7L2sxIgZTmSMn5v2FngDtw2GIc94+Q015aZzE=; h=DKIM-Signature:Message-ID:From:To:Subject:Date:MIME-Version; b=W4UR76zBYfvm/w9oZH0IJHjfPo00Mfsq65Sb2ovp2eFJ1ljjoYQyKRQUUkXp8yJ+Q9Zc3r0pFux/o66G8wTR+Gvfze2X7kWprXmLdasvh8I5JBYNrnQ7v0MXU5b1i+CHNScO2pp6+a8fI3v84ljeUfDeNgTqbLcGPjv4pyVrHm4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1729753846; bh=RrhrfYt1S04jta6XW/AyBqGHu3X9WJqDFo0lRleap7s=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=GBem/roDsj7pID6pGCu71HdNVzzFu4qBKXAZ/jc+Pt9hSXQkGM17z2qenaOfSVr5L 7K0KVrw2Qw1NMrLKLzfEGh7lW6PQq9Qs1AESiCyJC6C3s/JneloMteliwy8KEQVetQ LppzaiC1unACTaoPN7+4D+gSJBpYXInZjNbw7YVs= Received: from cyy-pc.lan ([240e:379:2265:5e00:1651:dae2:1a9c:8827]) by newxmesmtplogicsvrszb16-1.qq.com (NewEsmtp) with SMTP id 2AB832B0; Thu, 24 Oct 2024 15:10:43 +0800 X-QQ-mid: xmsmtpt1729753843tdh2zd47n Message-ID: X-QQ-XMAILINFO: NMGzQWUSIfvTK1K6HkGCTDxsydAFCEEuyhQMPhd1rIga3g6NnSis6IHoALn4fQ BZlVfQDhBO8KU8rvcwSIy8DzZ+eDmrEgXnELZpOHkypy+7BgsNoaz0jiLPc5JxprNaGvyAeXv0c9 +HqcgaA6pbq1dEYJ3AgTzYdgDC7bcaaJRZS5qHF0ysbuqoI6NjVvSVBLZ2fgn6lAkIrxoEUazYw/ r2BF4Ajvj3JLCNB1NpzBlHHhvhC4TbQ3YlespFToqNm4tNXhlZNmhfBGNnmctqdd5vRuwo9HRUhk Z31GkDv7pr04+3MapDVzmMg2DVU1zTMQy8BnlqzIs5v1+GsGN2K1RJqf3s/yvhp05NBML1MXSh+7 zzIoryOJ+QpaArxDyiTnQIpDs751MM4LPrRBZNz9GQ4oQCN+pu2B5ItXI5vGP/QUtj0kgY9OQB/u HVgUcnlfV73yB+3Y+97Eyw/YDxiluWsnPd6G1F56G6FS34/jPi5OOIl7hHt7ElnI/HXIA68YPUtf 3YJ2coRxYOsOedLTL42smlIFQzHBf5aWCNiW265VcD45JrdRFJv0HQIeITdjdQWrnhyFfX7enrxd bAr7Ja6vgry+NWLUSw5cXHIGBJyNemFn1RJ50kLCMRKTu2Cdr+vqI+9fkO0aB4T3K9c3EfCnwRTy UYYO2aBb6J4BMMchs0Jl+7JuwsmEpN/w78XRevI0eKqa0/CcNsKe9W303kPgU+qiJWA4djFbjzBY 7cP5voAqdsg6nrQCoTOGFTW1IrWQii61dcpY+jcwqRAS0LvEGMteqtm40akttPnsA1Aqb2/62PtI FZFTtxJi9HKChvcp9QANK6ni+HQf28xf+FKT4xzib6F0mMAkVQ0zUaDapmom8bTm6PtE+9OXyJQ4 HEr9Cn/z8mcivrYJ5G+yUj34v1rUEFrTj3IVuSnhsRyRoL98UUDb2WDk4Ow7WLX/swkmlbBTXqsz 0B6Jq6Yxjg6f8GfX78rarJkcHObYnjt4l4qrozpe5mXwwErEubHoUj8OX4DObJDWXVV9Sv9NPRRP l68ixnMA== X-QQ-XMRINFO: NS+P29fieYNw95Bth2bWPxk= 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 v3 01/11] Introduce TARGET_CLONES_ATTR_SEPARATOR for RISC-V Date: Thu, 24 Oct 2024 15:10:31 +0800 X-OQ-MSGID: <20241024071041.1834827-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.7 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 Some architectures may use ',' in the attribute string, but it is not used as the separator for different targets. To avoid conflict, we introduce a new macro TARGET_CLONES_ATTR_SEPARATOR to separate different clones. As an example, according to RISC-V C-API Specification [1], RISC-V allows ',' in the attribute string in the "arch=" option to specify one more ISA extensions in the same target function, which conflict with the default separator to separate different clones. This patch introduces TARGET_CLONES_ATTR_SEPARATOR for RISC-V and choose '#' as the separator, since '#' is not allowed in the target_clones option string. [1] https://github.com/riscv-non-isa/riscv-c-api-doc/blob/c6c5d6d9cf96b342293315a5dff3d25e96ef8191/src/c-api.adoc#__attribute__targetattr-string gcc/ChangeLog: * defaults.h (TARGET_CLONES_ATTR_SEPARATOR): Define new macro. * multiple_target.cc (get_attr_str): Use TARGET_CLONES_ATTR_SEPARATOR to separate attributes. (separate_attrs): Likewise. * attribs.cc (attr_strcmp): Likewise. (sorted_attr_string): Likewise. * tree.cc (get_target_clone_attr_len): Likewise. * config/riscv/riscv.h (TARGET_CLONES_ATTR_SEPARATOR): Define TARGET_CLONES_ATTR_SEPARATOR for RISC-V. --- gcc/attribs.cc | 17 ++++++++++------- gcc/config/riscv/riscv.h | 5 +++++ gcc/defaults.h | 4 ++++ gcc/multiple_target.cc | 19 ++++++++++++------- gcc/tree.cc | 4 +++- 5 files changed, 34 insertions(+), 15 deletions(-) diff --git a/gcc/attribs.cc b/gcc/attribs.cc index 0be7b83b264..ab46cb51425 100644 --- a/gcc/attribs.cc +++ b/gcc/attribs.cc @@ -1102,9 +1102,10 @@ attr_strcmp (const void *v1, const void *v2) } /* ARGLIST is the argument to target attribute. This function tokenizes - the comma separated arguments, sorts them and returns a string which - is a unique identifier for the comma separated arguments. It also - replaces non-identifier characters "=,-" with "_". */ + the TARGET_CLONES_ATTR_SEPARATOR separated arguments, sorts them and + returns a string which is a unique identifier for the + TARGET_CLONES_ATTR_SEPARATOR separated arguments. It also replaces + non-identifier characters "=,-" with "_". */ char * sorted_attr_string (tree arglist) @@ -1116,6 +1117,7 @@ sorted_attr_string (tree arglist) char *attr = NULL; unsigned int argnum = 1; unsigned int i; + static const char separator_str[] = { TARGET_CLONES_ATTR_SEPARATOR, 0 }; for (arg = arglist; arg; arg = TREE_CHAIN (arg)) { @@ -1125,7 +1127,7 @@ sorted_attr_string (tree arglist) if (arg != arglist) argnum++; for (i = 0; i < strlen (str); i++) - if (str[i] == ',') + if (str[i] == TARGET_CLONES_ATTR_SEPARATOR) argnum++; } @@ -1136,7 +1138,8 @@ sorted_attr_string (tree arglist) const char *str = TREE_STRING_POINTER (TREE_VALUE (arg)); size_t len = strlen (str); memcpy (attr_str + str_len_sum, str, len); - attr_str[str_len_sum + len] = TREE_CHAIN (arg) ? ',' : '\0'; + attr_str[str_len_sum + len] + = TREE_CHAIN (arg) ? TARGET_CLONES_ATTR_SEPARATOR : '\0'; str_len_sum += len + 1; } @@ -1151,12 +1154,12 @@ sorted_attr_string (tree arglist) args = XNEWVEC (char *, argnum); i = 0; - attr = strtok (attr_str, ","); + attr = strtok (attr_str, separator_str); while (attr != NULL) { args[i] = attr; i++; - attr = strtok (NULL, ","); + attr = strtok (NULL, separator_str); } qsort (args, argnum, sizeof (char *), attr_strcmp); diff --git a/gcc/config/riscv/riscv.h b/gcc/config/riscv/riscv.h index ca1b8329cdc..2ff9c1024f3 100644 --- a/gcc/config/riscv/riscv.h +++ b/gcc/config/riscv/riscv.h @@ -1298,4 +1298,9 @@ extern void riscv_remove_unneeded_save_restore_calls (void); STACK_BOUNDARY / BITS_PER_UNIT) \ : (crtl->outgoing_args_size + STACK_POINTER_OFFSET)) +/* According to the RISC-V C API, the arch string may contains ','. To avoid + the conflict with the default separator, we choose '#' as the separator for + the target attribute. */ +#define TARGET_CLONES_ATTR_SEPARATOR '#' + #endif /* ! GCC_RISCV_H */ diff --git a/gcc/defaults.h b/gcc/defaults.h index ac2d25852ab..918e3ec2f24 100644 --- a/gcc/defaults.h +++ b/gcc/defaults.h @@ -874,6 +874,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #define TARGET_HAS_FMV_TARGET_ATTRIBUTE 1 #endif +/* Select a attribute separator for function multiversioning. */ +#ifndef TARGET_CLONES_ATTR_SEPARATOR +#define TARGET_CLONES_ATTR_SEPARATOR ',' +#endif /* Select a format to encode pointers in exception handling data. We prefer those that result in fewer dynamic relocations. Assume no diff --git a/gcc/multiple_target.cc b/gcc/multiple_target.cc index 1fdd279da04..c1e358dfc1e 100644 --- a/gcc/multiple_target.cc +++ b/gcc/multiple_target.cc @@ -180,7 +180,7 @@ create_dispatcher_calls (struct cgraph_node *node) } } -/* Create string with attributes separated by comma. +/* Create string with attributes separated by TARGET_CLONES_ATTR_SEPARATOR. Return number of attributes. */ static int @@ -194,17 +194,21 @@ get_attr_str (tree arglist, char *attr_str) { const char *str = TREE_STRING_POINTER (TREE_VALUE (arg)); size_t len = strlen (str); - for (const char *p = strchr (str, ','); p; p = strchr (p + 1, ',')) + for (const char *p = strchr (str, TARGET_CLONES_ATTR_SEPARATOR); + p; + p = strchr (p + 1, TARGET_CLONES_ATTR_SEPARATOR)) argnum++; memcpy (attr_str + str_len_sum, str, len); - attr_str[str_len_sum + len] = TREE_CHAIN (arg) ? ',' : '\0'; + attr_str[str_len_sum + len] + = TREE_CHAIN (arg) ? TARGET_CLONES_ATTR_SEPARATOR : '\0'; str_len_sum += len + 1; argnum++; } return argnum; } -/* Return number of attributes separated by comma and put them into ARGS. +/* Return number of attributes separated by TARGET_CLONES_ATTR_SEPARATOR + and put them into ARGS. If there is no DEFAULT attribute return -1. If there is an empty string in attribute return -2. If there are multiple DEFAULT attributes return -3. @@ -215,9 +219,10 @@ separate_attrs (char *attr_str, char **attrs, int attrnum) { int i = 0; int default_count = 0; + static const char separator_str[] = { TARGET_CLONES_ATTR_SEPARATOR, 0 }; - for (char *attr = strtok (attr_str, ","); - attr != NULL; attr = strtok (NULL, ",")) + for (char *attr = strtok (attr_str, separator_str); + attr != NULL; attr = strtok (NULL, separator_str)) { if (strcmp (attr, "default") == 0) { @@ -305,7 +310,7 @@ static bool expand_target_clones (struct cgraph_node *node, bool definition) { int i; - /* Parsing target attributes separated by comma. */ + /* Parsing target attributes separated by TARGET_CLONES_ATTR_SEPARATOR. */ tree attr_target = lookup_attribute ("target_clones", DECL_ATTRIBUTES (node->decl)); /* No targets specified. */ diff --git a/gcc/tree.cc b/gcc/tree.cc index b40f4d31b2f..e9f7f4045a6 100644 --- a/gcc/tree.cc +++ b/gcc/tree.cc @@ -15228,7 +15228,9 @@ get_target_clone_attr_len (tree arglist) const char *str = TREE_STRING_POINTER (TREE_VALUE (arg)); size_t len = strlen (str); str_len_sum += len + 1; - for (const char *p = strchr (str, ','); p; p = strchr (p + 1, ',')) + for (const char *p = strchr (str, TARGET_CLONES_ATTR_SEPARATOR); + p; + p = strchr (p + 1, TARGET_CLONES_ATTR_SEPARATOR)) argnum++; argnum++; } From patchwork Thu Oct 24 07:10:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangyu Chen X-Patchwork-Id: 2001473 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=Rb8Luhrr; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; 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 [8.43.85.97]) (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 4XYxtM3QKgz1xtp for ; Thu, 24 Oct 2024 18:11:55 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 85CB23858D28 for ; Thu, 24 Oct 2024 07:11:53 +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 0FA5A3858C62 for ; Thu, 24 Oct 2024 07:11:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0FA5A3858C62 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 0FA5A3858C62 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=1729753885; cv=none; b=U1v9S+46Eh8IG+io+cvd3QkK8/LbV+8Nww/29p4oCSiE4u+1DQKuNV05LKj4UdI9QY5+E/2yl5+smZMAoSpl6i/Cy4NXiA1GsGDOOzDAVMu94qsjcVfYH/9nxXCsjKeqfJ1fJvyyc5ku6mmlRDR6q9dKaop7QywF0JXx6+kSiPo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729753885; c=relaxed/simple; bh=JsVP2LTj+wnHwv8HWYMBXIrSo/CZLF9c9CDQOP3BW6A=; h=DKIM-Signature:Message-ID:From:To:Subject:Date:MIME-Version; b=rTdoVMUbzlwKhYLlOmjNv1wdqbBqMc+Dh8BMFDw1mPbYiRx+7ZzmWXKrt4ByJqAVjOQEGYy0w2X5k/Xcm39Zql8O8zsIHbC+cGMemLfYu3i6Egt81uuCHMPgUvLT+wGGmAlNpYTXsLdc5k+FgfyDCFsEiexiJVuO+tnRXWFj/s8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1729753874; bh=e/XdXkHxh/76vKORlgA0ty6Fa81oH5rbEaC0rsw+poo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Rb8Luhrrc5mteq0NDTLooMMrUalWKuQY8yOzLGNWr6JMHAnxJCcnQvmvgooAScC9O UWnsrIGJdQ1YOAUQGFxtmWj+T7FygvlZUMW7Vc+SN++kEZ0phm4f6DGooa+px905GQ ecL0m5CXo+Fql2es0pykC85sI/SDkP9+62bKbs1I= Received: from cyy-pc.lan ([240e:379:2265:5e00:1651:dae2:1a9c:8827]) by newxmesmtplogicsvrszb21-0.qq.com (NewEsmtp) with SMTP id 2C02D453; Thu, 24 Oct 2024 15:11:00 +0800 X-QQ-mid: xmsmtpt1729753860tarwqoidl Message-ID: X-QQ-XMAILINFO: OZZSS56D9fAjvTw2tmudv0NNYsLhP5xSI0V1MKX6Yte/t3puTIASf7XJAmqRGY MP7Ec6ZZoKQVq6Exc5SWoDgn9LCzBFy2/IOYxUURZYr3Q13n+Ugi8tNvDAtB4GQnJ0/2r+mMk/7k e8IKX5wlqP3rr1ooiyVJ+FJr/1oiiNDUU1eJ27A2Kx6qMTT7wv+9l7r/VQpydRIGO4tK2ENyyLG0 XUjUWQKzDomdjsad40VYdjJYGzfP/JIYaIl/lUrdD4JMShnAl03dfYq8Azr+y1vbtjvVrkK6HSVY UexEDGueRSriTnJhg1uE34CnD6sfGCKE9bdLT1r3jMnabxo3djH0uZgqG/hU0icb1JnyUYHi4DaR Y3vBzpSHlZ6OYmbvgmHoBQZq+RRNKdrLarUrQAs+v9dJ006UxH/xbkKOp6iraXve77ybvpT1NDMI DtpacYNDDgTEooLmSmx+gm9mbV1fLb7fAzA34GFza7kktP9GUPSGuSU+FDlAenk4IepLUTCPdvuI P5FLrYBYrEUaHkmnWiOeZvCc5j0LxfpMHW9oyZdExT15czU2m9X27yhvIfS8jL9NJnCpfsTH4pGJ 1R0Nu4nJeZr74ZeccGWJqOfZ2+hgTim2ZduG5UJKRV3xcvKBOOY8aEp7KgTcITHX9ci6y2txbken VDvXpaUovU+FIuNczQUxwbZgaPlq7tWaOfWF4FQjzeyKGskUfu/MvQEuAy9qVD1yz9okG/MRCAxP ewDk8fdZzWT4HvAcFrcwmJ5wKvE7TgrGm4RdEhGQtYcH3H5n9i66uNe1HLW65P2AkcFfTIYwaBbH ukHhcxAOw0xYqwGJo4c45cQEPkSJloCJk4drLPs5CmrEO4DZn0KRU75rNv8sA4C3LDZZ36wW03Nz fgPDJ3UDnouoaU5jhUbVMMP27UE8XJyGkxtEuerWRkMIgMxT/PvCcUPXtlVZ+Cg8/88QMkPV3F10 1HVucWBVnIGy5jRA+1z1h316IWOo8fAckrdpXISK+kd6GuZEqEgexJyMFgndlnXtOkyeMkDqXmj5 p0OcA7YA== X-QQ-XMRINFO: NyFYKkN4Ny6FSmKK/uo/jdU= 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 v3 02/11] RISC-V: Split riscv_process_target_attr with const char *args argument Date: Thu, 24 Oct 2024 15:10:57 +0800 X-OQ-MSGID: <20241024071057.1835147-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.8 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 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, From patchwork Thu Oct 24 07:11:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangyu Chen X-Patchwork-Id: 2001476 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=kpCmQsSE; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; 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 [8.43.85.97]) (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 4XYxv80d7tz1xtp for ; Thu, 24 Oct 2024 18:12:36 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4EF873858423 for ; Thu, 24 Oct 2024 07:12:34 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from out162-62-57-49.mail.qq.com (out162-62-57-49.mail.qq.com [162.62.57.49]) by sourceware.org (Postfix) with UTF8SMTPS id A57023858D3C for ; Thu, 24 Oct 2024 07:11:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A57023858D3C 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 A57023858D3C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=162.62.57.49 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729753901; cv=none; b=NN6wQrTTg2O0b5mrDvGXVW7TXSSYi847ha5jrMbclI+jIu2N1SzgP4h+PNPOH718fJw+1LfGqGswBCBJjF8pXAbCBBRKFev8vsSDDt0z2QTc/10hetN4s/zGgp/EK3s2aCbbNryBh2CYs9WGbyn8j0ImrBIscVuxaAOzgWVrH5w= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729753901; c=relaxed/simple; bh=w+uZBHsLqwmxuBPtxxAytPpUgUyKrR3D8lB02dXZ5HA=; h=DKIM-Signature:Message-ID:From:To:Subject:Date:MIME-Version; b=QiF6/CU5CzQXqe/tLwQ4331PvDlD1Uy9UY+TaVcAxmNmSZIaMsBRqi1c+aSPgEspzDDUb0lpRoSUJ+W0QXXO8R2GWkBi5yoXOWZtmcyHNmUpIPFvgSNVf6UzgXzreu/YD7K3IkZTbCYpoMYH+ablKBXw78xEZaWQMdlrLQKSqQo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1729753887; bh=bRlOpPXSe0zMdnLYmVxHXHSQtenGIxGYvgP2OzvUjO8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=kpCmQsSEpJbtoY1SituaCNVDwGxghlzkmQ18DDycxysBpTC74Hf5KHyVuRSA9QWk8 zEgx2fa4jOGQVaFUZcHxZPv36tx9ocW95/7rBjRkfkZxN5Ml2tjo3eWm0fCU+lSOm4 5BJCzShTU/szlGkf2o8Kfn1bOi+MKN+IiwzsV1Wc= Received: from cyy-pc.lan ([240e:379:2265:5e00:1651:dae2:1a9c:8827]) by newxmesmtplogicsvrsza15-1.qq.com (NewEsmtp) with SMTP id 2D893829; Thu, 24 Oct 2024 15:11:24 +0800 X-QQ-mid: xmsmtpt1729753884t2jp8cqm1 Message-ID: X-QQ-XMAILINFO: MR/iVh5QLeiexUNVyYWNTlzeF7YcuzV2t/h81RXLApAGbNWO5CbpBqBlNWd6Ly sZ7LuinFtcIAJhVMPwJTmjItxpA78BCvKRKcB0AHwB1tj1oppmS69stJGBgT49ofYQLrygVw2bgl +0MpTLMMHv1KKJ0obuPAiRrDdDbKcbVptCkuo5GFkbujiHGVj5dDvY562Frlv2lejQJWj42yTUj3 853rcEbH6j0Zk4R0Imz37Y0S0xGRflo+Mepuilrd8pu8KBTiRjEPuHp7ak4uU3s3k55sHL2Fmeui 4LrqVVfLIYYVIXl2nMZWP8O9X5B/YLUW0IWZRofmiOnXTaKNBWdH3hCq9KWy17svrO3nbZyztBmB LpffsNuWc3KA63dh6UQgK07VIbJmHQBIorYgfjGkX9VScg0B4xrdkUfTsNAEmfIWaeu3ZWAow/RY u/wym/1XKiiesxSZQASIW9uZFhmTl0l2StOnAE+1jFWPaVpG8LYgev0qjl7qrr1lBr2shWrNa65D PCXi0WHSyfq//hjUWs0iNXV0U73l5AN8+j/Edz5NMV3AwdrlMLa9LQSvnJMndtoiCOAmxTrdsRkA YiqTkie4Qk400B69m6gWtCyBTdUDoLhzCRAz0b/DIqiRgLTuOto9jflqsRhx2Zouz/D/E+vwbObb 2oAoWI9hyE4waS1paXFaSkINaieUu0I2pB1FXRCA/rK/2zfHrVUXO+YlGqYKUqDS0jabTtmQiInq RLQMJ7DWcUR/VGooTMDFr0Ftcm7OQMFkZLeQstEi9pPg/mUz7IciLPAvihp56iPoVYlBfSj+dQfU d3LZsmapx59cWB2gVA6xZqIYeBu7T4uma/eTGjSZZrvWe+49zlpKEM1sOaUMR/ZlQ4rYZs2cwizQ HfDDYLzpP4V/xTvr6wOHGErv2unZtQ/vHJd9NOGNfrJEKkNC8Q/IuGX6XHEkjGvQO47Y+Dw+L8j/ I3wpJRXxmvQAKHNX1gcElUg8dXsoDDaqOkgL6uxRxh+up2c6Z9vPUXJa6qa6Ac3E7tDbVkgrtsSt zL/OEDMw== X-QQ-XMRINFO: Nq+8W0+stu50PRdwbJxPCL0= 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 v3 03/11] RISC-V: Implement Priority syntax parser for Function Multi-Versioning Date: Thu, 24 Oct 2024 15:11:21 +0800 X-OQ-MSGID: <20241024071121.1835519-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.8 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 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 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 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. (riscv_process_one_target_attr): Add const qualifier to arg_str and split arg_str with ';'. * config/riscv/riscv.opt: Add TargetVariable riscv_fmv_priority. --- gcc/config/riscv/riscv-target-attr.cc | 35 +++++++++++++++++++++++++-- gcc/config/riscv/riscv.opt | 3 +++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/gcc/config/riscv/riscv-target-attr.cc b/gcc/config/riscv/riscv-target-attr.cc index 8ce9607b3c9..087fbae77b0 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; }; } @@ -80,7 +85,8 @@ struct riscv_attribute_info static const struct riscv_attribute_info riscv_attributes[] = {{"arch", &riscv_target_attr_parser::handle_arch}, {"cpu", &riscv_target_attr_parser::handle_cpu}, - {"tune", &riscv_target_attr_parser::handle_tune}}; + {"tune", &riscv_target_attr_parser::handle_tune}, + {"priority", &riscv_target_attr_parser::handle_priority}}; bool riscv_target_attr_parser::parse_arch (const char *str) @@ -210,6 +216,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,13 +258,16 @@ 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. Show appropriate errors if any or return true if the attribute is valid. */ static bool -riscv_process_one_target_attr (char *arg_str, +riscv_process_one_target_attr (const char *arg_str, location_t loc, riscv_target_attr_parser &attr_parser) { @@ -271,6 +296,12 @@ riscv_process_one_target_attr (char *arg_str, arg[0] = '\0'; ++arg; + + /* Skip splitter ';' if it exists. */ + char *splitter = strchr (arg, ';'); + if (splitter) + splitter[0] = '\0'; + for (const auto &attr : riscv_attributes) { /* If the names don't match up, or the user has given an argument diff --git a/gcc/config/riscv/riscv.opt b/gcc/config/riscv/riscv.opt index 6360ed3984d..61def798ca0 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): From patchwork Thu Oct 24 07:11:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangyu Chen X-Patchwork-Id: 2001478 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=Ks2nv2Vw; 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 4XYxvj4lj5z1xtp for ; Thu, 24 Oct 2024 18:13:05 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DA6403858289 for ; Thu, 24 Oct 2024 07:13:03 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from out162-62-58-211.mail.qq.com (out162-62-58-211.mail.qq.com [162.62.58.211]) by sourceware.org (Postfix) with UTF8SMTPS id A69F83858406 for ; Thu, 24 Oct 2024 07:11:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A69F83858406 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 A69F83858406 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=162.62.58.211 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729753911; cv=none; b=jlqIMxNR41GsGqRQvc/s7owvpMnmiMuPLl/q3y9I8pVCnZiThzxQDzSW2icU2Im/2GMpUIxPHPRqv6XTIoTnSyrv0Yk75K5u01+rvJye3/j1hxctec5Zf7mh2nBylC4YY86JKO3sKca/1i1wpeKun8foXOI7P410WZLXOLuKhLE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729753911; c=relaxed/simple; bh=5almjEe+OiYZxW/JKWNx98mp123oz1AY2pqoltanmsE=; h=DKIM-Signature:Message-ID:From:To:Subject:Date:MIME-Version; b=NrwQRriRPhIjT3ONY1U+x+UYO9Gfr3lrlBZaWQroCJr/ijtYId1W1R5op8Q18AVp3BlkGONv27rM+UfYe1GhC1lGYpYpKQM/Oww8M4+seOezlWt2BV9+Wg25fb94kP1hRklcxrF19OZlepog0r8AWtyaGxaXCXRNZz+/shIKD8c= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1729753902; bh=Sa5qbaFhqbrKc274RgO1UXCt+JDYeMS1+2BrR3nKXDI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Ks2nv2Vw33n4BMMTBzSC1rjBVKFiqSP9lXP6VZNJIyqHyXUQppuiOn5fF4o+7Kmv0 aJ6JEE5lIAKW2kkVdJbF5dJHdme8geVE328qHdosceUmeYmeChHSLk8Ql+1MEfN7Ah 5oSFkkS8tFAdehM2j7mgRpqqYWkKWPZKz/zR/jq0= Received: from cyy-pc.lan ([240e:379:2265:5e00:1651:dae2:1a9c:8827]) by newxmesmtplogicsvrszb20-0.qq.com (NewEsmtp) with SMTP id 2E7A523C; Thu, 24 Oct 2024 15:11:39 +0800 X-QQ-mid: xmsmtpt1729753899tdlr7vurj Message-ID: X-QQ-XMAILINFO: MDbayGdXPuoe+hz6Sm3dZqoJVNKXcvwgg7PgC2izh0U7H4/OUrZX35zwcnYsBv yJPDH6TpBo7hSiQqjbiGqYJ//XOoTKUxZQL8fbaMngUMz5QPndiNzonLyzOfmU5WF1maVq/KPgUP My2U7+UXOcDWKiXjbv1FTl7kbiig0/Ya2ljLtJIhRNRWwQDCzcTmKEltyVCE7V4ip+MU5u6eA4/a XAAyu8qEd5Fpar0Tu6rU8BOZIRnLHpBDmtJZKFEl/xW4YFRvncP7DqOCpo3/HpGSBr0+cySKq12w 4d/IC41wx99rxrybo95HXDDOXnL7zlFgUzO/NCkFP/IGNUqgCeaeCS6z4q74yNUzn7/Cc4AQ8JPu 7U7wX4C33ul5Fx5Dze/5AQHfwK6/j+SnIjBeYtbluVqB75keTVpGudy9H+gOa3GmyTPRNvCupEr3 CRM9IY0iSXqCjfEwzWBkQSV1qJbVnlZPJKLUUX7As3RFkdwtiZ4J+TJ8xAfVZwjnsKGFp02A2NTA H7HFFvIOXUBEglXQcqTD8jlz3MVpsNNzkRfnvjqHLfCwh1mjx2LIHCDWjr3MA39Xf+m5lczSHJno eZb6MXkNBC5NBt6uyVEBfhyvF13+OMkFFFkHBDWDcswqkasAlJnTjvt3VWaO/9e//9p0hDzwD3oL szCaRvOveHZip2nMxampqG9j2AVWO3hGK98BKt67SpGsQidDGVx6HUFhdBTiMvGIyJ7/ZpfUHRAb XSjC/pmpbDalCFIVyQ7Uli1orgMw50fwIfqntgeVDnsvXDpaVfnSlI5x5qsmOSROrapiSFtgV9Ca i3wZ3ZA8lYHPKnRXJQjP4fXKeckzLJsudsNuC2v5c3GIzHcPA6/jfUn5JGYRrmXX7SmGyBJTSGnc 7LUQm6dKFuf4Ge7ROHVmFLEltGjNqVqoXrNXTJKuWlzl6l7Nsk/Qz14MlSjSOa2Vh0Ao+2eBf1Em f+Bv9A/KtRc8y3MAaayXVprtLBiRRGBsMMDQwa1Fi+Dl8HvMwcoT1YQZrG8ffNd4As2dKJQ082BS SZXdR2OaxCkrvrxuUm0yLfSmV7g2Ku2eSxg6zUkQ== X-QQ-XMRINFO: MSVp+SPm3vtS1Vd6Y4Mggwc= 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 v3 04/11] RISC-V: Implement riscv_minimal_hwprobe_feature_bits Date: Thu, 24 Oct 2024 15:11:34 +0800 X-OQ-MSGID: <20241024071134.1835771-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.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, HELO_DYNAMIC_IPADDR, KAM_SHORT, 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 implements the riscv_minimal_hwprobe_feature_bits feature for the RISC-V target. The feature bits are defined in the previous patch [1] to provide bitmasks of ISA extensions that defined in RISC-V C-API. Thus, we need a function to generate the feature bits for IFUNC resolver to dispatch between different functions based on the hardware features. The final version of the target_clones support on RISC-V is still under development, I am working on it. The minimal feature bits means to use the earliest extension appeard in the Linux hwprobe to cover the given ISA string. To allow older kernels without some implied extensions probe to run the FMV dispatcher correctly. For example, V implies Zve32x, but Zve32x appears in the Linux kernel since v6.11. If we use isa string directly to generate FMV dispatcher with functions with "arch=+v" extension, since we have V implied the Zve32x, FMV dispatcher will check if the Zve32x extension is supported by the host. If the Linux kernel is older than v6.11, the FMV dispatcher will fail to detect the Zve32x extension even it already implies by the V extension, thus making the FMV dispatcher fail to dispatch the correct function. Thus, we need to generate the minimal feature bits to cover the given ISA string to allow the FMV dispatcher to work correctly on older kernels. [1] https://patchwork.sourceware.org/project/gcc/patch/20241003182256.1765569-1-chenyangyu@isrc.iscas.ac.cn/ gcc/ChangeLog: * common/config/riscv/riscv-common.cc (RISCV_EXT_BITMASK): New macro. (struct riscv_ext_bitmask_table_t): New struct. (riscv_minimal_hwprobe_feature_bits): New function. * common/config/riscv/riscv-ext-bitmask.def: New file. * config/riscv/riscv-subset.h (GCC_RISCV_SUBSET_H): (riscv_minimal_hwprobe_feature_bits): Declare the function. * config/riscv/feature_bits.h: New file. --- 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-subset.h | 5 + 4 files changed, 226 insertions(+) create mode 100644 gcc/common/config/riscv/riscv-ext-bitmask.def create mode 100644 gcc/config/riscv/feature_bits.h diff --git a/gcc/common/config/riscv/riscv-common.cc b/gcc/common/config/riscv/riscv-common.cc index 2adebe0b6f2..ea5bfcd13fc 100644 --- a/gcc/common/config/riscv/riscv-common.cc +++ b/gcc/common/config/riscv/riscv-common.cc @@ -19,6 +19,7 @@ along with GCC; see the file COPYING3. If not see #include #include +#include #define INCLUDE_STRING #define INCLUDE_SET @@ -1760,6 +1761,24 @@ static const riscv_ext_flag_table_t riscv_ext_flag_table[] = {NULL, NULL, NULL, 0} }; +/* Types for recording extension to RISC-V C-API bitmask. */ +struct riscv_ext_bitmask_table_t { + const char *ext; + int groupid; + int bit_position; +}; + +/* Mapping table between extension to RISC-V C-API extension bitmask. + This table should sort the extension by Linux hwprobe order to get the + minimal feature bits. */ +static const riscv_ext_bitmask_table_t riscv_ext_bitmask_table[] = +{ +#define RISCV_EXT_BITMASK(NAME, GROUPID, BITPOS) \ + {NAME, GROUPID, BITPOS}, +#include "riscv-ext-bitmask.def" + {NULL, -1, -1} +}; + /* Apply SUBSET_LIST to OPTS if OPTS is not null. */ void @@ -1826,6 +1845,81 @@ riscv_x_target_flags_isa_mask (void) return mask; } +/* Get the minimal feature bits in Linux hwprobe of the given ISA string. + + Used for generating Function Multi-Versioning (FMV) dispatcher for RISC-V. + + The minimal feature bits refer to using the earliest extension that appeared + in the Linux hwprobe to support the specified ISA string. This ensures that + older kernels, which may lack certain implied extensions, can still run the + FMV dispatcher correctly. */ + +bool +riscv_minimal_hwprobe_feature_bits (const char *isa, + struct riscv_feature_bits *res, + location_t loc) +{ + riscv_subset_list *subset_list; + subset_list = riscv_subset_list::parse (isa, loc); + if (!subset_list) + return false; + + /* Initialize the result feature bits to zero. */ + res->length = RISCV_FEATURE_BITS_LENGTH; + for (int i = 0; i < RISCV_FEATURE_BITS_LENGTH; ++i) + res->features[i] = 0; + + /* Use a std::set to record all visited implied extensions. */ + std::set implied_exts; + + /* Iterate through the extension bitmask table in Linux hwprobe order to get + the minimal covered feature bits. Avoiding some sub-extensions which will + be implied by the super-extensions like V implied Zve32x. */ + const riscv_ext_bitmask_table_t *ext_bitmask_tab; + for (ext_bitmask_tab = &riscv_ext_bitmask_table[0]; + ext_bitmask_tab->ext; + ++ext_bitmask_tab) + { + /* Skip the extension if it is not in the subset list or already implied + by previous extension. */ + if (subset_list->lookup (ext_bitmask_tab->ext) == NULL + || implied_exts.count (ext_bitmask_tab->ext)) + continue; + + res->features[ext_bitmask_tab->groupid] + |= 1ULL << ext_bitmask_tab->bit_position; + + /* Find the sub-extension using BFS and set the corresponding bit. */ + std::queue search_q; + search_q.push (ext_bitmask_tab->ext); + + while (!search_q.empty ()) + { + const char * search_ext = search_q.front (); + search_q.pop (); + + /* Iterate through the implied extension table. */ + const riscv_implied_info_t *implied_info; + for (implied_info = &riscv_implied_info[0]; + implied_info->ext; + ++implied_info) + { + /* When the search extension matches the implied extension and + the implied extension has not been visited, mark the implied + extension in the implied_exts set and push it into the + queue. */ + if (implied_info->match (subset_list, search_ext) + && implied_exts.count (implied_info->implied_ext) == 0) + { + implied_exts.insert (implied_info->implied_ext); + search_q.push (implied_info->implied_ext); + } + } + } + } + return true; +} + /* Parse a RISC-V ISA string into an option mask. Must clear or set all arch dependent mask bits, in case more than one -march string is passed. */ diff --git a/gcc/common/config/riscv/riscv-ext-bitmask.def b/gcc/common/config/riscv/riscv-ext-bitmask.def new file mode 100644 index 00000000000..ca5df1740f3 --- /dev/null +++ b/gcc/common/config/riscv/riscv-ext-bitmask.def @@ -0,0 +1,83 @@ +/* RISC-V Extension Bitmask Definitions, corresponding to Extension Bitmask + Definitions in RISC-V C API Specification. + Copyright (C) 2024 Free Software Foundation, Inc. + Contributed by Yangyu Chen (cyy@cyyself.name). + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GCC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ + +#ifndef RISCV_EXT_BITMASK +#define RISCV_EXT_BITMASK(NAME, GROUP_ID, BIT_POSITION) +#endif + +/* This table should sort the extension by Linux hwprobe order to calculate the + minimal feature bits. */ + +RISCV_EXT_BITMASK ("i", 0, 8) +RISCV_EXT_BITMASK ("m", 0, 12) +RISCV_EXT_BITMASK ("a", 0, 0) +RISCV_EXT_BITMASK ("f", 0, 5) +RISCV_EXT_BITMASK ("d", 0, 3) +RISCV_EXT_BITMASK ("c", 0, 2) +RISCV_EXT_BITMASK ("v", 0, 21) +RISCV_EXT_BITMASK ("zba", 0, 27) +RISCV_EXT_BITMASK ("zbb", 0, 28) +RISCV_EXT_BITMASK ("zbs", 0, 33) +RISCV_EXT_BITMASK ("zicboz", 0, 37) +RISCV_EXT_BITMASK ("zbc", 0, 29) +RISCV_EXT_BITMASK ("zbkb", 0, 30) +RISCV_EXT_BITMASK ("zbkc", 0, 31) +RISCV_EXT_BITMASK ("zbkx", 0, 32) +RISCV_EXT_BITMASK ("zknd", 0, 41) +RISCV_EXT_BITMASK ("zkne", 0, 42) +RISCV_EXT_BITMASK ("zknh", 0, 43) +RISCV_EXT_BITMASK ("zksed", 0, 44) +RISCV_EXT_BITMASK ("zksh", 0, 45) +RISCV_EXT_BITMASK ("zkt", 0, 46) +RISCV_EXT_BITMASK ("zvbb", 0, 48) +RISCV_EXT_BITMASK ("zvbc", 0, 49) +RISCV_EXT_BITMASK ("zvkb", 0, 52) +RISCV_EXT_BITMASK ("zvkg", 0, 53) +RISCV_EXT_BITMASK ("zvkned", 0, 54) +RISCV_EXT_BITMASK ("zvknha", 0, 55) +RISCV_EXT_BITMASK ("zvknhb", 0, 56) +RISCV_EXT_BITMASK ("zvksed", 0, 57) +RISCV_EXT_BITMASK ("zvksh", 0, 58) +RISCV_EXT_BITMASK ("zvkt", 0, 59) +RISCV_EXT_BITMASK ("zfh", 0, 35) +RISCV_EXT_BITMASK ("zfhmin", 0, 36) +RISCV_EXT_BITMASK ("zihintntl", 0, 39) +RISCV_EXT_BITMASK ("zvfh", 0, 50) +RISCV_EXT_BITMASK ("zvfhmin", 0, 51) +RISCV_EXT_BITMASK ("zfa", 0, 34) +RISCV_EXT_BITMASK ("ztso", 0, 47) +RISCV_EXT_BITMASK ("zacas", 0, 26) +RISCV_EXT_BITMASK ("zicond", 0, 38) +RISCV_EXT_BITMASK ("zihintpause", 0, 40) +RISCV_EXT_BITMASK ("zve32x", 0, 60) +RISCV_EXT_BITMASK ("zve32f", 0, 61) +RISCV_EXT_BITMASK ("zve64x", 0, 62) +RISCV_EXT_BITMASK ("zve64f", 0, 63) +RISCV_EXT_BITMASK ("zve64d", 1, 0) +RISCV_EXT_BITMASK ("zimop", 1, 1) +RISCV_EXT_BITMASK ("zca", 1, 2) +RISCV_EXT_BITMASK ("zcb", 1, 3) +RISCV_EXT_BITMASK ("zcd", 1, 4) +RISCV_EXT_BITMASK ("zcf", 1, 5) +RISCV_EXT_BITMASK ("zcmop", 1, 6) +RISCV_EXT_BITMASK ("zawrs", 1, 7) + +#undef RISCV_EXT_BITMASK diff --git a/gcc/config/riscv/feature_bits.h b/gcc/config/riscv/feature_bits.h new file mode 100644 index 00000000000..19b7630e339 --- /dev/null +++ b/gcc/config/riscv/feature_bits.h @@ -0,0 +1,44 @@ +/* Definition of RISC-V feature bits corresponding to + libgcc/config/riscv/feature_bits.c + Copyright (C) 2024 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GCC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ + +#ifndef GCC_RISCV_FEATURE_BITS_H +#define GCC_RISCV_FEATURE_BITS_H + +#define RISCV_FEATURE_BITS_LENGTH 2 + +struct riscv_feature_bits { + unsigned length; + unsigned long long features[RISCV_FEATURE_BITS_LENGTH]; +}; + +#define RISCV_VENDOR_FEATURE_BITS_LENGTH 1 + +struct riscv_vendor_feature_bits { + unsigned length; + unsigned long long features[RISCV_VENDOR_FEATURE_BITS_LENGTH]; +}; + +struct riscv_cpu_model { + unsigned mvendorid; + unsigned long long marchid; + unsigned long long mimpid; +}; + +#endif /* GCC_RISCV_FEATURE_BITS_H */ diff --git a/gcc/config/riscv/riscv-subset.h b/gcc/config/riscv/riscv-subset.h index 1914a5317d7..75008be6613 100644 --- a/gcc/config/riscv/riscv-subset.h +++ b/gcc/config/riscv/riscv-subset.h @@ -22,6 +22,8 @@ along with GCC; see the file COPYING3. If not see #ifndef GCC_RISCV_SUBSET_H #define GCC_RISCV_SUBSET_H +#include "feature_bits.h" + #define RISCV_DONT_CARE_VERSION -1 /* Subset info. */ @@ -120,6 +122,9 @@ public: extern const riscv_subset_list *riscv_cmdline_subset_list (void); extern void riscv_set_arch_by_subset_list (riscv_subset_list *, struct gcc_options *); +extern bool riscv_minimal_hwprobe_feature_bits (const char *, + struct riscv_feature_bits *, + location_t); extern bool riscv_ext_is_subset (struct cl_target_option *, struct cl_target_option *); extern int riscv_x_target_flags_isa_mask (void); From patchwork Thu Oct 24 07:11:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangyu Chen X-Patchwork-Id: 2001481 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=adRlWEOr; 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 4XYxwP5qTmz1xtp for ; Thu, 24 Oct 2024 18:13:41 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 009013858408 for ; Thu, 24 Oct 2024 07:13:40 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from out203-205-221-209.mail.qq.com (out203-205-221-209.mail.qq.com [203.205.221.209]) by sourceware.org (Postfix) with UTF8SMTPS id 316C83858C33 for ; Thu, 24 Oct 2024 07:12:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 316C83858C33 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 316C83858C33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=203.205.221.209 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729753990; cv=none; b=KdGegbPxc5Zw7dqxOG/+H6vU9Wpw+6WB0ziCzEl+es5IThB1zZ2uSliRCTD04FJek9omaB8ZSuc7BedV/m3nKbN4taJsIgcHvT4Ei6ST+iLqIU133laMfdlsWb66e1QyFO7yd0ZIWLmGQoHjHyD2nFY4U8QUjgC4erEnQSnFX+k= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729753990; c=relaxed/simple; bh=gG1gtdKK5naMuTe57KIQCAN3eKn2w9c96ZJDmb6I1Rg=; h=DKIM-Signature:Message-ID:From:To:Subject:Date:MIME-Version; b=TmIlgIiZV60+v0Tfl2FVVwWsccpUxEXx+qZxJhOxybsZLFD1/oZ8bMcS9ngQBULBeT4yfJ6nOpV6gH4jtg8hz2fbHPjahYCYUTLkR2IERpBMOfKpJyIkBaygxhRR4GrlrtfPnqucRhLS/B8xkbTGRBYPD3wiGfiItSXLUyveFnE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1729753915; bh=vjie7E3g0JV09Bg7WoyDCk8T7ocj8awT39hqG2JvKyY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=adRlWEOrlV32QDjlMtRAdL9aNupeS32Ld6VJNuMYWqN304THe6t0SXfJoINYXSmU9 5t74SgTKZ+0XJhP8JKPVzFy3dsIx9vGvG/w4iexVWHJBT/ihl9Lf7LFWyIcAi55ZyG f6ka8gc+NuI3n+krEABPyZR0S036B1V1Vmo1mJXg= Received: from cyy-pc.lan ([240e:379:2265:5e00:1651:dae2:1a9c:8827]) by newxmesmtplogicsvrsza29-0.qq.com (NewEsmtp) with SMTP id 2F41E8ED; Thu, 24 Oct 2024 15:11:52 +0800 X-QQ-mid: xmsmtpt1729753912ti7si4545 Message-ID: X-QQ-XMAILINFO: OATpkVjS499uSXKkvweNyYJshk7P2PNimiDf8xntpNx3r8+sY68ytXDDudmil4 UwB36NGv+81dOP9TiQHmSjTCNtI5cVI6gJ1I+OuaWU2ODNO1NUGCHsRZkVFVgHKv1SIKyylUmrVr a+mX95K1zTi1O5SQkW42lAxSo8eXByHeFe5qA8Op5zupMPARfL0egxAWMM6H0WDha9zzKp91pi63 BXwNAlYA8rzN8Zeos854wJWeohdb4cTbGryw8b3xCIW+JUHI2S0W5RDTHHUy1tMmYPmTJOS4fEVy rlZ+MZPTszF8Ni2zeIO2Yqi8ADW/yIzjS477RpzZfaX45W2e9u1Ycc8aPlv+aZieMz9TQOL8yyGn ebu6/uCwDXBw7yMuRiN1g07ATYFsiGm9PMaoCcTS4g7SWnnVNTQnA9Vb+fD/w940gnLqCw6ZMsrD 9/AFW8jaKFnzhnaIvF/MlokHIxC+mRqLqWiMzcoKUrLXhGGT6L/ZYNPB6I72JBpMG0wDsZJBNMcF FOapqqzCe/5U3H0pkyuVCMrsX+lVszUFK5mRjOnA2bH2z6RSYWYLavjAzgEIeLB2f4LIAxLCcZpn xIBByrf0uDMI4fkf8DgtSDXC61MAIgJv60atfStEwSpJGw2ge/UkxyF0gg+vqU7K6WSwL1od1z/7 exwMkWObc8oJiRsX234QkBTVJJJdfVfNWIVeQE23lcNknsTys87RSsw2jyr7QJrCBFpIa1PG3bE5 NWIrxPBAvsfM9Q6C0o9IG82+huVGMSAdKapkrOoGP53oOuN8nXK0AuSuOwdj9spd+64ZShruvEJ8 xD2T8ppV8ZSvqPZ1l3/Xsp8xhS5GDzAsqB0d6khjJyNOFXzeiiO8fAmCpFWTMrh5X9QIE1OLmpiV xFt3Bxq702X7VswiyoQkSNtj4auXAvKDg1He8k4F3lfBYfHDKO4rQPFDbaW72WPdzebMgdtWIS/V MkRlgzN5OxV3CYFMJ0oZy9dNnwdoZcRA0EDcw2mfY3verALv1z5BWlsPpUMmUe1SrP0d0c4wTWv+ cXSBM2pIS8egeP+KZbEDpnIGM4CQJScNx9s28ry9UKRHarzMh4 X-QQ-XMRINFO: NI4Ajvh11aEj8Xl/2s1/T8w= 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 v3 05/11] RISC-V: Implement TARGET_COMPARE_VERSION_PRIORITY and TARGET_OPTION_FUNCTION_VERSIONS Date: Thu, 24 Oct 2024 15:11:50 +0800 X-OQ-MSGID: <20241024071150.1836072-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.9 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, 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 TARGET_COMPARE_VERSION_PRIORITY and TARGET_OPTION_FUNCTION_VERSIONS for RISC-V. The TARGET_COMPARE_VERSION_PRIORITY is implemented to compare the priority of two function versions based on the rules defined in the RISC-V C-API Doc PR #85: https://github.com/riscv-non-isa/riscv-c-api-doc/pull/85/files#diff-79a93ca266139524b8b642e582ac20999357542001f1f4666fbb62b6fb7a5824R721 If multiple versions have equal priority, we select the function with the most number of feature bits generated by riscv_minimal_hwprobe_feature_bits. When it comes to the same number of feature bits, we diff two versions and select the one with the least significant bit set. Since a feature appears earlier in the feature_bits might be more important to performance. The TARGET_OPTION_FUNCTION_VERSIONS is implemented to check whether the two function versions are the same. This Implementation reuses the code in TARGET_COMPARE_VERSION_PRIORITY and check it returns 0, which means the equal priority. Co-Developed-by: Hank Chang gcc/ChangeLog: * config/riscv/riscv-target-attr.cc (riscv_target_attr_parser::update_settings): never free the arch string. * config/riscv/riscv.cc (parse_features_for_version): New function. (compare_fmv_features): New function. (riscv_compare_version_priority): New function. (riscv_common_function_versions): New function. (TARGET_COMPARE_VERSION_PRIORITY): Implement it. (TARGET_OPTION_FUNCTION_VERSIONS): Implement it. * config/riscv/riscv.h (TARGET_HAS_FMV_TARGET_ATTRIBUTE): Define it to 0 to use "target_version" for function versioning. --- gcc/config/riscv/riscv-target-attr.cc | 4 - gcc/config/riscv/riscv.cc | 127 ++++++++++++++++++++++++++ gcc/config/riscv/riscv.h | 2 + 3 files changed, 129 insertions(+), 4 deletions(-) diff --git a/gcc/config/riscv/riscv-target-attr.cc b/gcc/config/riscv/riscv-target-attr.cc index 087fbae77b0..4c85ad60b72 100644 --- a/gcc/config/riscv/riscv-target-attr.cc +++ b/gcc/config/riscv/riscv-target-attr.cc @@ -239,10 +239,6 @@ riscv_target_attr_parser::update_settings (struct gcc_options *opts) const { std::string local_arch = m_subset_list->to_string (true); const char* local_arch_str = local_arch.c_str (); - struct cl_target_option *default_opts - = TREE_TARGET_OPTION (target_option_default_node); - if (opts->x_riscv_arch_string != default_opts->x_riscv_arch_string) - free (CONST_CAST (void *, (const void *) opts->x_riscv_arch_string)); opts->x_riscv_arch_string = xstrdup (local_arch_str); riscv_set_arch_by_subset_list (m_subset_list, opts); diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index 3ac40234345..947864fc3a6 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -12574,6 +12574,127 @@ riscv_c_mode_for_floating_type (enum tree_index ti) return default_mode_for_floating_type (ti); } +/* This parses the attribute arguments to target_version in DECL and modifies + the feature mask and priority required to select those targets. */ +static void +parse_features_for_version (tree decl, + struct riscv_feature_bits &res, + int &priority) +{ + tree version_attr = lookup_attribute ("target_version", + DECL_ATTRIBUTES (decl)); + if (version_attr == NULL_TREE) + { + res.length = 0; + priority = 0; + return; + } + + const char *version_string = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE + (version_attr))); + gcc_assert (version_string != NULL); + if (strcmp (version_string, "default") == 0) + { + res.length = 0; + priority = 0; + return; + } + struct cl_target_option cur_target; + cl_target_option_save (&cur_target, &global_options, + &global_options_set); + /* Always set to default option before parsing "arch=+..." */ + struct cl_target_option *default_opts + = TREE_TARGET_OPTION (target_option_default_node); + cl_target_option_restore (&global_options, &global_options_set, + default_opts); + + riscv_process_target_attr (version_string, + DECL_SOURCE_LOCATION (decl)); + + priority = global_options.x_riscv_fmv_priority; + const char *arch_string = global_options.x_riscv_arch_string; + bool parse_res + = riscv_minimal_hwprobe_feature_bits (arch_string, &res, + DECL_SOURCE_LOCATION (decl)); + gcc_assert (parse_res); + + if (arch_string != default_opts->x_riscv_arch_string) + free (CONST_CAST (void *, (const void *) arch_string)); + + cl_target_option_restore (&global_options, &global_options_set, + &cur_target); +} + +/* Compare priorities of two feature masks. Return: + 1: mask1 is higher priority + -1: mask2 is higher priority + 0: masks are equal. + Since riscv_feature_bits has total 128 bits to be used as mask, when counting + the total 1s in the mask, the 1s in group1 needs to multiply a weight. */ +static int +compare_fmv_features (const struct riscv_feature_bits &mask1, + const struct riscv_feature_bits &mask2, + int prio1, int prio2) +{ + unsigned length1 = mask1.length, length2 = mask2.length; + /* 1. Compare length, for length == 0 means default version, which should be + the lowest priority). */ + if (length1 != length2) + return length1 > length2 ? 1 : -1; + /* 2. Compare the priority. */ + if (prio1 != prio2) + return prio1 > prio2 ? 1 : -1; + /* 3. Compare the total number of 1s in the mask. */ + unsigned pop1 = 0, pop2 = 0; + for (unsigned i = 0; i < length1; i++) + { + pop1 += __builtin_popcountll (mask1.features[i]); + pop2 += __builtin_popcountll (mask2.features[i]); + } + if (pop1 != pop2) + return pop1 > pop2 ? 1 : -1; + /* 4. Compare the mask bit by bit order. */ + for (unsigned i = 0; i < length1; i++) + { + unsigned long long xor_mask = mask1.features[i] ^ mask2.features[i]; + if (xor_mask == 0) + continue; + return TEST_BIT (mask1.features[i], __builtin_ctzll (xor_mask)) ? 1 : -1; + } + /* 5. If all bits are equal, return 0. */ + return 0; +} + +/* Compare priorities of two version decls. Return: + 1: mask1 is higher priority + -1: mask2 is higher priority + 0: masks are equal. */ +int +riscv_compare_version_priority (tree decl1, tree decl2) +{ + struct riscv_feature_bits mask1, mask2; + int prio1, prio2; + + parse_features_for_version (decl1, mask1, prio1); + parse_features_for_version (decl2, mask2, prio2); + + return compare_fmv_features (mask1, mask2, prio1, prio2); +} + +/* This function returns true if FN1 and FN2 are versions of the same function, + that is, the target_version attributes of the function decls are different. + This assumes that FN1 and FN2 have the same signature. */ + +bool +riscv_common_function_versions (tree fn1, tree fn2) +{ + if (TREE_CODE (fn1) != FUNCTION_DECL + || TREE_CODE (fn2) != FUNCTION_DECL) + return false; + + return riscv_compare_version_priority (fn1, fn2) != 0; +} + /* On riscv we have an ABI defined safe buffer. This constant is used to determining the probe offset for alloca. */ @@ -12948,6 +13069,12 @@ riscv_stack_clash_protection_alloca_probe_range (void) #undef TARGET_C_MODE_FOR_FLOATING_TYPE #define TARGET_C_MODE_FOR_FLOATING_TYPE riscv_c_mode_for_floating_type +#undef TARGET_COMPARE_VERSION_PRIORITY +#define TARGET_COMPARE_VERSION_PRIORITY riscv_compare_version_priority + +#undef TARGET_OPTION_FUNCTION_VERSIONS +#define TARGET_OPTION_FUNCTION_VERSIONS riscv_common_function_versions + struct gcc_target targetm = TARGET_INITIALIZER; #include "gt-riscv.h" diff --git a/gcc/config/riscv/riscv.h b/gcc/config/riscv/riscv.h index 2ff9c1024f3..8a8b08b6b51 100644 --- a/gcc/config/riscv/riscv.h +++ b/gcc/config/riscv/riscv.h @@ -1303,4 +1303,6 @@ extern void riscv_remove_unneeded_save_restore_calls (void); the target attribute. */ #define TARGET_CLONES_ATTR_SEPARATOR '#' +#define TARGET_HAS_FMV_TARGET_ATTRIBUTE 0 + #endif /* ! GCC_RISCV_H */ From patchwork Thu Oct 24 07:12:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangyu Chen X-Patchwork-Id: 2001479 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=uG0zscQQ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; 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 [8.43.85.97]) (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 4XYxvv6Q81z1xtp for ; Thu, 24 Oct 2024 18:13:15 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E5466385840C for ; Thu, 24 Oct 2024 07:13:13 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from out162-62-57-252.mail.qq.com (out162-62-57-252.mail.qq.com [162.62.57.252]) by sourceware.org (Postfix) with UTF8SMTPS id 52B033858C50 for ; Thu, 24 Oct 2024 07:12:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 52B033858C50 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 52B033858C50 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=162.62.57.252 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729753967; cv=none; b=HU2zpDc1ROazzomqqxgZ56wr6KFUCvzELJ1/TlHNu6MFEX1d4tBI5fvvJHSxG4oafADNJNuVZMBFBTaKp4WS4PYuejFBfbX84dmiiVuF6HtoaGG9HGBCV0IHdLeSpBlV+KkuXODQR15yv8r0Qa+NxV8TEtyPw8o6NvA3zbw+JfQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729753967; c=relaxed/simple; bh=Nty6z1MCENZOrZYcjnX8aWBSD3rsy809m6Huxy7BSfM=; h=DKIM-Signature:Message-ID:From:To:Subject:Date:MIME-Version; b=cwjeLs5n37sRFmKmnxxI48WA9xes4NzDhF5I+pWIHWZW4BpOtNGaBVhkkGyhjI1irt6rHQlaB0mk2PxS2HNKkuimP//wDEsrGJEvYsBpGwyFzqCGYbyBRrm2Zcc8iLOuG8gyt1VHwxslDanmmqQ3CxfBioYgZy/qFGDGSwJ1l8I= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1729753948; bh=LaSo87VJUKKpEWm+ygm6FHbZU0RcJB+RTxock1queD4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=uG0zscQQ3s0gaY94EbIkFhD6soL12Xi70x19nxTVDdfXFKKBE1/Au2szuLDwt1nZS y7WHduy/Ry0WmDB6qXnUTiRYwlb9ryiMgrSRASGvhZaurWJ8Z0yuK7FWC+YUb93IRj JOW7/K12mM+/J7o96xWyjiaoeBssD9olXAoioa4k= Received: from cyy-pc.lan ([240e:379:2265:5e00:1651:dae2:1a9c:8827]) by newxmesmtplogicsvrszb21-0.qq.com (NewEsmtp) with SMTP id 31A11A34; Thu, 24 Oct 2024 15:12:26 +0800 X-QQ-mid: xmsmtpt1729753946texdjsc1j Message-ID: X-QQ-XMAILINFO: N7h1OCCDntujnNRNhosd+ownMpu3o2WCAirq3e61ltwa2lXSifmI7jC0Baw04s AJsm+1/I3aO+zuqZeP7L90+u9/bOPMaDnYGSn4ITv1VE+8t8ROIdVttMHpXnoo9STafx5UjIJ4+c GsEyMzubAenFNA1Ths703qiSqz4+O+j5mzo7rbNWSpuYro2UCH8XLeOb2Ry+iSXVvtGrKf1U6yxD z2QW9Jl7W0oBzMmOmlcROcXMbSRnod6h0764xFq0A9IqGJ/Xu6RRwlFtHbTI0OXIOBxGRtt45cFO 4jhfvHauC0Y1eRUN9G82502V//rky/rOG+iWgkBEoql5X2CW6Cc2PmaZNP8NKNchuPOG2Abg6bLM m98H+Z7B1PWvBKGDIXr42CNxXPy0ndCYHR6Yawjj2X6TxYj6iO5a7CaGD6jw+utasLiivW5yogJf Pr5Gn8xAbEjGV+9kEsHE2lWiDpUvg0mb+aE3GNJ6W06e8PUHxQugQv1iEW4gw+0i8eGkKmkfxCCW WHpOTz/yeLCfR58V76Z5A6asa9RYjelYJTf2FSe9dgL0/ZJJv1bEcdyFa/Ge+m62aN6nPD+QW/+m th9EvNbogyqrKtfm/cjijA852/i8CZA3tMZBQp3h9nm27B+o5yxydLSLE14Z2LChGW/NTersvKDb 9QFHxJ3nsGTT7ONAkDcPdRhcvIbkrBhvn49zKcuG2nc6kjgU41+0gvS0gY/wBz9VTtfBB3L403Ln t05XY5uG7W7BXpq0auT5AmO8JaJowtAt9T/rv8mDVDF7lZgmns62Y0Od2+2cRdaCZthPId9vem0Y py9BbaRJ+iUHEUnY8RYDtGafLsGKSMHTkLC/8un4xRzmQrlyyhlW1Ecz3ULQTUswn9TSLPAnTCZh xBiXvSAt/e/ucqRXDAGbiQgqb8BPxhN6m5lkY8SSHlGFz4aOlk8WdQf/hS5Ufzdc/71F7CPInImK /BitkQU8O5Iq5YnzJNTr9gsjQdwHMlYX9/yLrYQ7Aj+Bdla71MtYPg/IInd/PG73Sy5ByBQPj6Sj ZG34669wAqCMx7bPLJrme9IpIhPH0= X-QQ-XMRINFO: NS+P29fieYNw95Bth2bWPxk= 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 v3 06/11] RISC-V: Implement TARGET_OPTION_VALID_VERSION_ATTRIBUTE_P Date: Thu, 24 Oct 2024 15:12:05 +0800 X-OQ-MSGID: <20241024071205.1836403-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.9 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, 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" From patchwork Thu Oct 24 07:12:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangyu Chen X-Patchwork-Id: 2001482 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=VteySXWI; 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 4XYxwP65Svz1xx6 for ; Thu, 24 Oct 2024 18:13:41 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 00983385802C for ; Thu, 24 Oct 2024 07:13:40 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from out162-62-57-252.mail.qq.com (out162-62-57-252.mail.qq.com [162.62.57.252]) by sourceware.org (Postfix) with UTF8SMTPS id 8BE743858D28 for ; Thu, 24 Oct 2024 07:12:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8BE743858D28 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 8BE743858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=162.62.57.252 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729753990; cv=none; b=m04ZifQqudrTHfu6H7/pOBd/B2Hj6Uzw5QRPmys/X4MWHb9/9xWEwM7cfQkEcwppnqbZn6k4wjVuckL2B+ll8U1pYTRGlMZkBXmweVMlxAg5OlcZJfFT8M62zu5Cyo0JfKIXcdw7WNF+V6cnU2A1O++RK6dVs0LQ9Zjx8XBuFLY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729753990; c=relaxed/simple; bh=8X+To0/4WPpurtSFwGO3rVvNWnl01YCLfH1bxbXMPNg=; h=DKIM-Signature:Message-ID:From:To:Subject:Date:MIME-Version; b=A3DVgnMvbE3KCD8k8ffb+3df5nvo+YVh/cvFUYvWswJp4LeCxyATXroouFIK0sT9vh3srdSQezc6tJNFBdkurDj54wExX51NZ6THUsGv171fASL3RzGfb8HHajQ0G7++QKv+7mkx/sw4HTUjeSQNTzLSxzdB1Er/K+L/nKSAir4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1729753960; bh=xe/97D4bRpbJHUes1Dhfo4fjEi0xJOhadvLIalEzj+U=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=VteySXWI64p9VXwLExGnpKxJmUeUdmiTicR1szRWwSF1UkjIm5dnHg6MztNgMMLgM wx3k6K8mG2MJd8u+tXwOy9T5de5pZTGEvjje5CSCmjO9HToHIPRiLHR3O2BHcAAzFF sdmPd4qMUgetXpq7TIViTL2zzEPp5dhAUy3hmsZg= Received: from cyy-pc.lan ([240e:379:2265:5e00:1651:dae2:1a9c:8827]) by newxmesmtplogicsvrszc13-0.qq.com (NewEsmtp) with SMTP id 32500449; Thu, 24 Oct 2024 15:12:37 +0800 X-QQ-mid: xmsmtpt1729753957tbsx1oxin Message-ID: X-QQ-XMAILINFO: NQp/UN4soYLTvYsfMTCLLMLZqI5VGzMyqK64WRrPsht3M6uj+oaNQwCi7Bk6Ui 6dKZnxQd48/lQsjlP4H1nrmB8q/LFsxjvUQq/7mUCbdoux3MWrpasaiDW5wt33rP93f7wQ5+pZld d/Koyckv9qPDb5gjqQFkwdOFqFyXcbQMi1dKgmhTeb4TXWu1uDP5zV//o4Xb/MSCRGQzKtv5Z5Yl 9aNgMM5/Pyro+ct8amEtxSEkvdL/sOW2I6qiUAFw3iyhLDA2VX4p4U0LFdGQAMrF8B4Tq8xNfiG2 fqbXs0RAl9NVVSkmAoDV9o6t7zcwe7TIpYbO9kQpVYHbc0aa/Cx38gJzRNZGJzu4uqtUl/SehaU+ yrrsMXsEjtDSYt4NozRbCnw1f3PSSlLxgjR1J3YsjByizGZEMZk+zUaXdEnCdNFz1sgx/fTIo714 QtoHrDEyuyQcXQNLhdtTy6dOn0Ne2Z4X+WvQLuwXv6njmOQkMa3WhlL8kXsMuRQqINJOeH606PLV BHO+AL/QT9Xd/liwbti0W43q0LpPoJfoKHUkFm67bcTP7UA4J8EC9efRfBz67YZBNdd3NQ8P9qXp az+0fT2yz+hjfzCgTOwHv/YQCKqsv2dBsz4qrXMgAxP47w5CIkiwZj8SE49phq+0lMUpPhWE6rIE FP9cQXoUdyCJvnqV3+unJ3+UA2qkQZOgXnoOkG9Uayr6QnF8zNS8SaTyCCC5bwTw8qnLbYhKKKTC F5swpHZ2r8T7htxhiAjdMHaBNIHBTpAY7HfFaH6gGJRZ9gUmskd9FpOYAbGxn86xft1i1oGOyWJN XvmYXJJ6+kDFKwswFqjRFNtzfxNSJZYC0lcKtAV3yX8820mAxDObLS1ETS1d9KjL389vNkjniVaq RQ5Lg9F7xHZgwEZihC6eXfjsX6pojjvxPGCgUBp3SmwrtiZaWQz5YDP1z44IYrJUaV5sFcg+TUwS lUU3itmYiY5o2xUXQ3nsZmoncoaWCe7/orcnBwFXjxGOonOhSXLUVqJCPfSxuW9kYZ71265jBLti +P1RPVZrnPNGQEXBkeY+/wjt010R8= X-QQ-XMRINFO: OWPUhxQsoeAVDbp3OJHYyFg= 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 v3 07/11] RISC-V: Implement TARGET_MANGLE_DECL_ASSEMBLER_NAME Date: Thu, 24 Oct 2024 15:12:35 +0800 X-OQ-MSGID: <20241024071235.1837039-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.9 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, 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_MANGLE_DECL_ASSEMBLER_NAME for RISC-V. This is used to add function multiversioning suffixes to the assembler name. gcc/ChangeLog: * config/riscv/riscv.cc (riscv_mangle_decl_assembler_name): New function. (TARGET_MANGLE_DECL_ASSEMBLER_NAME): Define. --- gcc/config/riscv/riscv.cc | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index 789667da386..f7082df22ef 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -12695,6 +12695,42 @@ riscv_common_function_versions (tree fn1, tree fn2) return riscv_compare_version_priority (fn1, fn2) != 0; } +/* Implement TARGET_MANGLE_DECL_ASSEMBLER_NAME, to add function multiversioning + suffixes. */ + +tree +riscv_mangle_decl_assembler_name (tree decl, tree id) +{ + /* For function version, add the target suffix to the assembler name. */ + if (TREE_CODE (decl) == FUNCTION_DECL + && DECL_FUNCTION_VERSIONED (decl)) + { + std::string name = IDENTIFIER_POINTER (id) + std::string ("."); + tree target_attr = lookup_attribute ("target_version", + DECL_ATTRIBUTES (decl)); + + if (target_attr == NULL_TREE) + { + name += "default"; + return get_identifier (name.c_str ()); + } + + const char *version_string = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE + (target_attr))); + + /* Replace non-alphanumeric characters with underscores as the suffix. */ + for (const char *c = version_string; *c; c++) + name += ISALNUM (*c) == 0 ? '_' : *c; + + if (DECL_ASSEMBLER_NAME_SET_P (decl)) + SET_DECL_RTL (decl, NULL); + + id = get_identifier (name.c_str ()); + } + + return id; +} + /* On riscv we have an ABI defined safe buffer. This constant is used to determining the probe offset for alloca. */ @@ -13079,6 +13115,9 @@ riscv_stack_clash_protection_alloca_probe_range (void) #define TARGET_OPTION_VALID_VERSION_ATTRIBUTE_P \ riscv_option_valid_version_attribute_p +#undef TARGET_MANGLE_DECL_ASSEMBLER_NAME +#define TARGET_MANGLE_DECL_ASSEMBLER_NAME riscv_mangle_decl_assembler_name + struct gcc_target targetm = TARGET_INITIALIZER; #include "gt-riscv.h" From patchwork Thu Oct 24 07:12:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangyu Chen X-Patchwork-Id: 2001487 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=IQqEEIB/; 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 4XYxym2hbnz1xwy for ; Thu, 24 Oct 2024 18:15:44 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 92A7B385841D for ; Thu, 24 Oct 2024 07:15:42 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from out162-62-57-49.mail.qq.com (out162-62-57-49.mail.qq.com [162.62.57.49]) by sourceware.org (Postfix) with UTF8SMTPS id 3D61E3858D21 for ; Thu, 24 Oct 2024 07:13:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3D61E3858D21 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 3D61E3858D21 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=162.62.57.49 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729753999; cv=none; b=eTJzvk/y5OC3ax1AtUe3XvKyEKxTRRNnCu+76KfcfGrV/j9D/NJQt5ynz9xmw8FTxYjZJJc5ok3TM8YzUztzdhnyN7LLvF4+D/FoIz1fEDS8qFQff+UoJRvPjKUgNj3gBhJy8DjBBtzKPgoh2bGRsmsP5pVo/J2Wh3PH3l5MWuI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729753999; c=relaxed/simple; bh=zJJBr1+BualNjnuokGtuv2/uFHiwC8ToxDsdeMLqYPg=; h=DKIM-Signature:Message-ID:From:To:Subject:Date:MIME-Version; b=XCFG2o1aN5R6DMYxktPknPTc+ewVxTmAFP6Gx/+fm+xDtkGSprr2Yslvovn1sktokHzCSPR2aRnKzMO72Tj81mitOOBsRpTGdcYIhx8Vl1g1XWYHdhSsFBCJ2DRhN2/yXjShdUicFdGPk63UYDuWdc5GgxAGD8Z1rMljSiMjUyA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1729753984; bh=74VKz13Ljn4TaqLwiDPUXhDX4xASOK1NbeWOl8jiw0k=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=IQqEEIB/HdIFu1SePPBqwXI0Xj9RkfcLMG6LC8blz/MvLG0r60AXmxkHF1cvvgBwT xmruP8ysADQa5HGS+xXr9ne/sfRWtHB4O9WxrW/b45eC4w2etWmgn/nG5dPL4yBb4s twGpqwqY3D68SMvYls/9gmdDOdQU5xFkHsPJH64Y= Received: from cyy-pc.lan ([240e:379:2265:5e00:1651:dae2:1a9c:8827]) by newxmesmtplogicsvrszc16-0.qq.com (NewEsmtp) with SMTP id 32FA36C4; Thu, 24 Oct 2024 15:12:47 +0800 X-QQ-mid: xmsmtpt1729753967tgk1qvxgj Message-ID: X-QQ-XMAILINFO: NT7dO8ok7FP2uLLfOermKasDxn4YDg2llfw7DauP1hSsCtJJjzfpiEpq4bwxhU Ehtex8u4bGNpC0Beh0ngej/UnlwHe+sn/h2vUeTJg5lK0BXRs1vKjrGXn7caIGIqLpxiI56uo8EF niG7hap1F8E5o7oV+2TDnbI/1cJvFMVXUr5biPWqQhKTxx5G3jsgDpOrtjNbEcfu46Q/TgmqW7JO TAVIo4ucuYImZ6sKF58fWm5z3BT7M9xKA5BAvpuy/STYcRo8n90Kc1w4POGvSWWq1SZHpb02nEP4 E06WNtPYVNOrRBe+NqTF6GGXfanWKgyAW0K29bwAI49eWNA68wH8LTHxYNDfrKnAGjo83wKDruyP LPUw/tHzm/txgZyVaYbrSltiwQnjWOmh05zDHa26vImNNCn0VP+CkE6kVdkQ9MWjm/Z6wah6Yfxb 7f8uuDNXnkcRPPGFfgb/8DFO9Rq+q94Kn2OelvfAzm15Ui4QlZU1vD6xNlfFF8LRjsJUIvorr+M5 wlAQ5hZlrPesJpt6jVISiMeyQAglTJjub4yZ+/mw3ZNSIYZLT+W0jaKbsKxLhBIAEkr/Zzpivw9b 1nlkMXhjnQpMS+nWabaSsjbG2QeE5mvz5F9Ziu/K9wbZBCVcAgqQZBC/v7VLA/tSoc9JJc4hgnAq QeChEhqAkz2IWugHifMgzDCzkNqv0UImC9w178mP+VQjLF+IaZllXjRyAsk1kUQFR0Icn2q5Vena J9mFx7JCUaQrhwRsm2l9rgHlgsT+CEqMHdGJ1IbfESXCssBs/DhQbi37pjX3PqwObpIGDvTeYSRA RGWri7AFKL14xusLtkm3FIDFexjs3oPJcYD5dM9ssVS2BPJ3Ze9XO3YwV/9ngZ/xDVrhXcYKnUgj dcsaPKund3og7Yv/g27EJczU7esImmrOFqBF342dgUv9wnVTROpt2+E39BeKsP596zXcZ7gOhiy0 rnf/ycr+tJMCwqwhGL2WKYVV5UqRtwQnOkAN6j4uv4kimlPLAxvC00zhSuTy4unAvQF/R1fwcy2T 9do9715eVQLB7JK+dS2DKkf3U2/6UQkFSGFG7olM82K9fdyb4T 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 Subject: [PATCH v3 08/11] RISC-V: Do not inline when callee is versioned but caller is not Date: Thu, 24 Oct 2024 15:12:45 +0800 X-OQ-MSGID: <20241024071245.1837323-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 When the callee is versioned but the caller is not, we should not inline the callee into the caller, to prevent the default version of the callee from being inlined into a not versioned caller. gcc/ChangeLog: * config/riscv/riscv.cc (riscv_can_inline_p): Refuse to inline when callee is versioned but caller is not. --- gcc/config/riscv/riscv.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index f7082df22ef..46961360096 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -7666,6 +7666,10 @@ riscv_compute_frame_info (void) static bool riscv_can_inline_p (tree caller, tree callee) { + /* Do not inline when callee is versioned but caller is not. */ + if (DECL_FUNCTION_VERSIONED (callee) && ! DECL_FUNCTION_VERSIONED (caller)) + return false; + tree callee_tree = DECL_FUNCTION_SPECIFIC_TARGET (callee); tree caller_tree = DECL_FUNCTION_SPECIFIC_TARGET (caller); From patchwork Thu Oct 24 07:13: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: 2001485 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=aaTo4c5g; 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 4XYxxx5tz7z1xtp for ; Thu, 24 Oct 2024 18:15:01 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E424D3858403 for ; Thu, 24 Oct 2024 07:14:59 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from out162-62-57-252.mail.qq.com (out162-62-57-252.mail.qq.com [162.62.57.252]) by sourceware.org (Postfix) with UTF8SMTPS id 4F540385800F for ; Thu, 24 Oct 2024 07:13:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4F540385800F 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 4F540385800F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=162.62.57.252 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729754007; cv=none; b=tCFhgGntj4gl0SsM6mJMsDhGsB7xBpGvY+FEXvrtZ4CdHiyPCzuhexTW2Y3C43kWK0YkHh42+mexpQok6e07qoaVJJeRiDBmHPENBeFA+zgrq+Jxy4kCzW7SbcvED2xmA1O3ZvTIM7eCEAIZtpdmASBn8Cl0QswPcFguWOUJ22E= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729754007; c=relaxed/simple; bh=5z8uCbGh9od8DvPuiRZGnhwaPKjoImuKjxtBWCEvL7o=; h=DKIM-Signature:Message-ID:From:To:Subject:Date:MIME-Version; b=msv8dz3K3mRw0CL+UwuEV57Sw2zfZdjxeApfULywCxBRg9EhUTlHIl+oAeKTN4XDgJeZYWKi3BEUdf5GVUyA0KF5v5WNk6Upc/kS7CAVhqhdgAcnitscXtRqPv+Ofwi/Umn6h2yP2t5wjYDRFojR2YR1/WJliIKtk9CPfHvTfv8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1729753992; bh=1rd0Mca82UGNTRCF/bNX5xZ10Sp/bvE1s6FERplb4o8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=aaTo4c5gXvmIScnEamAr49yMuvUEw/XX5kp3U4Q7tD5LZMe3Ypk21yY+79G+xkTaF obhmPUQAt3npt+yTFAaAGTOnycTyJvvOEzwzCk9dSZZhOgLNBK/fs10+9NyxaWsy/H Jw37DXIPlyeFk24kSHxDF5WdooQ1gJ9yayS9lnls= Received: from cyy-pc.lan ([240e:379:2265:5e00:1651:dae2:1a9c:8827]) by newxmesmtplogicsvrszc13-0.qq.com (NewEsmtp) with SMTP id 3483D89F; Thu, 24 Oct 2024 15:13:08 +0800 X-QQ-mid: xmsmtpt1729753988t3u2ywmmm Message-ID: X-QQ-XMAILINFO: NmxDRtNfo6mL4ORAviNq1Q9EUO628Y/Tg5MOLhxnRV3WwZ1sIg9wvf74xxUDvG B3xuPuxaennQ7VTTMRGvghmjBx1oC3AtQHcriocygWYmBGh3ygFE4uHg1UwBa3YoYWzcIE+eYpdN 15uaQtBjZ+72isOfLdwsYDy+F5G7x4AWFyR/7YFG12BaUkBcYFaLAl1sANpT5zXi4Xpr+gXvu3mu gvVO3/ES8AMzbxUMZai0eWXiJLXEUCJRRkReUwDQ7xfqTeWqqh3pdLTU7aTBhGuIqtSqbg/txX68 bYvMbkHkUpWmukiiYEMNQNw6PbvNvIYraw+5GKr1qx/E6Po4pOxf9TPFR9rDQtT/l8wqpEhIEGYK gT+DTVBxC3gJHtZ/poHZ19reyvKWB99PEqioL9HBJfIc212wBSgcfAqtbMvabdZfBjv13pXtAsWL lAWiwCImpaeBC7FaxF+owA80zf1pjcRRbJGgV+cZ1HQ5abGKVRgxDUhzRzSmr52JN6C8fnKtxXJZ 9SwC5A59v0SSjU/KwUgfeScXKjX/rDwrKeMGqX7JcgX2cuWcUK/XiSOwFczJZrB8rTt5XXod+DdM EpFDAEky/Zlbgx6SgEJytrwdSLsX8a+gz0vyyIhgcNJV1IbMrA10WwZl5KnxPgIP3uDIIPRpCZkw 7IAHwhil1MJ6d1w8Ex2O3Vc2dlZY4oKoiBvRuZeYACXKThvV0368ld4r3xxb96hcA1ELUpYL2XPG mE4uaQyYxQk2IDe8KuQYVOyJdWcPFEUXcXmDifOELykV5ga+Wf9L09riLOVL6h51koCti18tSnYN jyS072R6Q9kqZJB2Tq9dGDUFDmZuCwVw1s5wva6ST6xU8q76uACDhhJt9jUelgzLKUKg2HLlcRPi 8FFVSnwpfqhADideLx9THYxmr5VHoYQip8SuOT6BrqZGUyYbtiuisUqxfjBDOxnO6bi55fi8x+Hd 6yqi4DKdFDRMAWFGGI1qJXJthrxo3+97ZFTN6OtwLWpKr4CEg1PtE3M2dUceqYZooJ4UiVa316kj zb7s6LHVATi1+39cmj0tQuIwq9TDBELeviYIY8mMkEtknd070w X-QQ-XMRINFO: NyFYKkN4Ny6FSmKK/uo/jdU= 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 v3 09/11] RISC-V: Reapply target_version attribute after target attribute Date: Thu, 24 Oct 2024 15:13:00 +0800 X-OQ-MSGID: <20241024071300.1837790-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.7 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 To ensure that the target_version attribute is applied after target attributes. gcc/ChangeLog: * config/riscv/riscv-target-attr.cc (riscv_option_valid_attribute_p): Reapply target_version attribute after target attribute --- gcc/config/riscv/riscv-target-attr.cc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/gcc/config/riscv/riscv-target-attr.cc b/gcc/config/riscv/riscv-target-attr.cc index 3042562c66b..7dcff0211ea 100644 --- a/gcc/config/riscv/riscv-target-attr.cc +++ b/gcc/config/riscv/riscv-target-attr.cc @@ -30,6 +30,8 @@ along with GCC; see the file COPYING3. If not see #include "diagnostic.h" #include "opts.h" #include "riscv-subset.h" +#include "stringpool.h" +#include "attribs.h" namespace { class riscv_target_attr_parser @@ -450,6 +452,17 @@ riscv_option_valid_attribute_p (tree fndecl, tree, tree args, int) ret = riscv_process_target_attr (args, loc); if (ret) { + tree version_attr = lookup_attribute ("target_version", + DECL_ATTRIBUTES (fndecl)); + if (version_attr != NULL_TREE) + { + // Reapply any target_version attribute after target attribute. + // This should be equivalent to applying the target_version once + // after processing all target attributes. + tree version_args = TREE_VALUE (version_attr); + riscv_process_target_version_attr (version_args, + DECL_SOURCE_LOCATION (fndecl)); + } riscv_override_options_internal (&global_options); new_target = build_target_option_node (&global_options, &global_options_set); From patchwork Thu Oct 24 07:13:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangyu Chen X-Patchwork-Id: 2001496 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=MJRGdO5i; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; 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 [8.43.85.97]) (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 4XYy076V0Nz1xwy for ; Thu, 24 Oct 2024 18:16:55 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D2D12385841D for ; Thu, 24 Oct 2024 07:16:53 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from out162-62-57-252.mail.qq.com (out162-62-57-252.mail.qq.com [162.62.57.252]) by sourceware.org (Postfix) with UTF8SMTPS id 750503858D39 for ; Thu, 24 Oct 2024 07:14:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 750503858D39 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 750503858D39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=162.62.57.252 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729754092; cv=none; b=WVkvwUFY9GLFUsIF9nNlIIJXZND55EsPn8Ws3xHqimEkvcQzZTKLUgi/62Etfe+ccijMp6tR+p5ENJKFa5Bm+Pa8oLtp7hmbmFyuu16egXbC0+C/WVwKwuQtDpQUAHF0MjSNIBwwWy0HE5oMHrCWIeNdb0j5uELLv26+t+I1hYI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729754092; c=relaxed/simple; bh=v3j3vAhIJxHdj2NGroiH91/vQZGUKZeXaW5ZRwnyTyY=; h=DKIM-Signature:Message-ID:From:To:Subject:Date:MIME-Version; b=GY11JasinN3lzv9z+sZdE2D8ydiwcluLWRt75BziT9TCu9HXsaOemiaEYPko5vP86GGPDmLfapKoc9gQppQU2qZVhPXLeqeC4HxSBxj9bmdyDEqOv+CLFi+DCWN1usRRP1EFNYOLuzrR8qCYtBDp10O1CjrfXm0dWRVDlXaKHs8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1729754084; bh=dmjzmU9bTcEUCvkxBorUxJIsFIkYyfV4ZGTbICvUx9E=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=MJRGdO5iGvlmyK0dz0haO/hzjQRtwoWaWZ47c6RLTiLan/WulApIFhsApKHl11bEF B+1wHtvzF3vvGvjirhWXDo2nlKGVxgRwjnuVFG9XgY6hI11hV/19NehlEids8PkeGo RVJLnfIQn7/Y6l6c80kTpyedkTSk2aJXGHDqABEU= Received: from cyy-pc.lan ([240e:379:2265:5e00:1651:dae2:1a9c:8827]) by newxmesmtplogicsvrszb16-1.qq.com (NewEsmtp) with SMTP id 359B78AC; Thu, 24 Oct 2024 15:13:25 +0800 X-QQ-mid: xmsmtpt1729754005ta9l1r721 Message-ID: X-QQ-XMAILINFO: MmpliBmRb3iCy16tAaa39EFB7TDbJq/ODWqewBDgFDmsOqlpvZilta2cJQbYlx MLYav7CTNI9NQ+6ImjUq9urOkqoPNdrBki/50JQGK/4DNSfmr3/IRE1cZ7+GIEhsnlEy05vw7Nmy BMh0jmqL16MD8Ig1P4wRZYV2c2HAf1Byuz3tiCmW1WhlU49OiAWv1v2bPsrHtcuuIP0dPB3JejM0 9puRlDvt3THr/lOeC/49i/ecEEbJC9QiY860qNrwx0S3vzJSOxpYYOJyEVPs5tln9EsJga8RH9q6 HL/fNh7dez0OFAq/SALFnIK79T6gwe2XJAgy7SrMVF0jwHJicCus9wNq1qE1XGk050Pu1nYRoeto naXL71p8psZy3NjGUl2d4/Jy+laWPYdSgRsvFqr+wf8uE54cPmRDPbyZrRNndOO/DIXMgw59uqsM 25uoXS6LVQYPT/SLaao4l+RYf9pbKJJPI9M760YDpxrYj8pCZ9lK8gRA/ff6ElKQos62lTnEgqUO 825AtOSMiR9PR2adRWeDFxfvXCN656mCfifNXiCMNYT7K8WBdtKKrkRcBEz2QfH+Ey8GTVOChix6 1RBjxJvKY/xmP3MXhjh7g6JliNTmbPcSyIgjaXsZpSJ1Zj/6j5dX0VlrhBapV99Dy7IoptfBb8Ae avVoytukZnYX0AlpZnUQBk2+O1wlA+I1ywCW0s3X2JXtXRTeXyIhlsDKVLgn9ECvImHhowzLVvEz TtcqHpi4kIrK79T+90E6G/YlAxiMYmsmxdj5Gbm7LWywcHc/83/0iBsWEU2kgx9Y8BqHpZS67+Wm jwD5R6uGrUFrt63cgVI63r7imCRgzKoeT3kJZKklmfy3PXuo+Pd3n/hD+ojyTrifYqS6jT7QridX cwP3YPdYVj1LC2VFGyW7kgEfhckVkc7McwOwPiAgsjEz/k63NLP4ZMbhK01vHEi1xDnV0GnWFSqe K5wEkw/UQ3JJ8/gt8yTMozbBINnvnFKxUgBSO2be6qRzY/9DDmtJk/U5Dk4bD8WsF9PbOb/v4xEm ZOOCkBLA== X-QQ-XMRINFO: OWPUhxQsoeAVDbp3OJHYyFg= 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 v3 10/11] RISC-V: Implement TARGET_GENERATE_VERSION_DISPATCHER_BODY and TARGET_GET_FUNCTION_VERSIONS_DISPATCHER Date: Thu, 24 Oct 2024 15:13:17 +0800 X-OQ-MSGID: <20241024071318.1838106-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.9 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, 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_GENERATE_VERSION_DISPATCHER_BODY and TARGET_GET_FUNCTION_VERSIONS_DISPATCHER for RISC-V. This is used to generate the dispatcher function and get the dispatcher function for function multiversioning. This patch copies many codes from commit 0cfde688e213 ("[aarch64] Add function multiversioning support") and modifies them to fit the RISC-V port. A key difference is the data structure of feature bits in RISC-V C-API is a array of unsigned long long, while in AArch64 is not a array. So we need to generate the array reference for each feature bits element in the dispatcher function. gcc/ChangeLog: * config/riscv/riscv.cc (add_condition_to_bb): New function. (dispatch_function_versions): New function. (get_suffixed_assembler_name): New function. (make_resolver_func): New function. (riscv_generate_version_dispatcher_body): New function. (riscv_get_function_versions_dispatcher): New function. (TARGET_GENERATE_VERSION_DISPATCHER_BODY): Implement it. (TARGET_GET_FUNCTION_VERSIONS_DISPATCHER): Implement it. --- gcc/config/riscv/riscv.cc | 582 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 582 insertions(+) diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index 46961360096..c8dbe5333ec 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -77,6 +77,9 @@ along with GCC; see the file COPYING3. If not see #include "tree-dfa.h" #include "target-globals.h" #include "riscv-v.h" +#include "cgraph.h" +#include "langhooks.h" +#include "gimplify.h" /* This file should be included last. */ #include "target-def.h" @@ -12735,6 +12738,577 @@ riscv_mangle_decl_assembler_name (tree decl, tree id) return id; } +/* This adds a condition to the basic_block NEW_BB in function FUNCTION_DECL + to return a pointer to VERSION_DECL if all feature bits specified in + FEATURE_MASK are not set in MASK_VAR. This function will be called during + version dispatch to decide which function version to execute. It returns + the basic block at the end, to which more conditions can be added. */ +static basic_block +add_condition_to_bb (tree function_decl, tree version_decl, + const struct riscv_feature_bits *features, + tree mask_var, basic_block new_bb) +{ + gimple *return_stmt; + tree convert_expr, result_var; + gimple *convert_stmt; + gimple *if_else_stmt; + + basic_block bb1, bb2, bb3; + edge e12, e23; + + gimple_seq gseq; + + push_cfun (DECL_STRUCT_FUNCTION (function_decl)); + + gcc_assert (new_bb != NULL); + gseq = bb_seq (new_bb); + + convert_expr = build1 (CONVERT_EXPR, ptr_type_node, + build_fold_addr_expr (version_decl)); + result_var = create_tmp_var (ptr_type_node); + convert_stmt = gimple_build_assign (result_var, convert_expr); + return_stmt = gimple_build_return (result_var); + + if (features->length == 0) + { + /* Default version. */ + gimple_seq_add_stmt (&gseq, convert_stmt); + gimple_seq_add_stmt (&gseq, return_stmt); + set_bb_seq (new_bb, gseq); + gimple_set_bb (convert_stmt, new_bb); + gimple_set_bb (return_stmt, new_bb); + pop_cfun (); + return new_bb; + } + + tree zero_llu = build_int_cst (long_long_unsigned_type_node, 0); + tree cond_status = create_tmp_var (boolean_type_node); + tree mask_array_ele_var = create_tmp_var (long_long_unsigned_type_node); + tree and_expr_var = create_tmp_var (long_long_unsigned_type_node); + tree eq_expr_var = create_tmp_var (boolean_type_node); + + /* cond_status = true. */ + gimple *cond_init_stmt = gimple_build_assign (cond_status, boolean_true_node); + gimple_set_block (cond_init_stmt, DECL_INITIAL (function_decl)); + gimple_set_bb (cond_init_stmt, new_bb); + gimple_seq_add_stmt (&gseq, cond_init_stmt); + + for (int i = 0; i < RISCV_FEATURE_BITS_LENGTH; i++) + { + tree index_expr = build_int_cst (unsigned_type_node, i); + /* mask_array_ele_var = mask_var[i] */ + tree mask_array_ref = build4 (ARRAY_REF, long_long_unsigned_type_node, + mask_var, index_expr, NULL_TREE, NULL_TREE); + + gimple *mask_stmt = gimple_build_assign (mask_array_ele_var, + mask_array_ref); + gimple_set_block (mask_stmt, DECL_INITIAL (function_decl)); + gimple_set_bb (mask_stmt, new_bb); + gimple_seq_add_stmt (&gseq, mask_stmt); + /* and_expr_var = mask_array_ele_var & features[i] */ + tree and_expr = build2 (BIT_AND_EXPR, + long_long_unsigned_type_node, + mask_array_ele_var, + build_int_cst (long_long_unsigned_type_node, + features->features[i])); + gimple *and_stmt = gimple_build_assign (and_expr_var, and_expr); + gimple_set_block (and_stmt, DECL_INITIAL (function_decl)); + gimple_set_bb (and_stmt, new_bb); + gimple_seq_add_stmt (&gseq, and_stmt); + /* eq_expr_var = and_expr_var == 0. */ + tree eq_expr = build2 (EQ_EXPR, boolean_type_node, + and_expr_var, zero_llu); + gimple *eq_stmt = gimple_build_assign (eq_expr_var, eq_expr); + gimple_set_block (eq_stmt, DECL_INITIAL (function_decl)); + gimple_set_bb (eq_stmt, new_bb); + gimple_seq_add_stmt (&gseq, eq_stmt); + /* cond_status = cond_status & eq_expr_var. */ + tree cond_expr = build2 (BIT_AND_EXPR, boolean_type_node, + cond_status, eq_expr_var); + gimple *cond_stmt = gimple_build_assign (cond_status, cond_expr); + gimple_set_block (cond_stmt, DECL_INITIAL (function_decl)); + gimple_set_bb (cond_stmt, new_bb); + gimple_seq_add_stmt (&gseq, cond_stmt); + } + if_else_stmt = gimple_build_cond (EQ_EXPR, cond_status, boolean_true_node, + NULL_TREE, NULL_TREE); + gimple_set_block (if_else_stmt, DECL_INITIAL (function_decl)); + gimple_set_bb (if_else_stmt, new_bb); + gimple_seq_add_stmt (&gseq, if_else_stmt); + + gimple_seq_add_stmt (&gseq, convert_stmt); + gimple_seq_add_stmt (&gseq, return_stmt); + set_bb_seq (new_bb, gseq); + + bb1 = new_bb; + e12 = split_block (bb1, if_else_stmt); + bb2 = e12->dest; + e12->flags &= ~EDGE_FALLTHRU; + e12->flags |= EDGE_TRUE_VALUE; + + e23 = split_block (bb2, return_stmt); + + gimple_set_bb (convert_stmt, bb2); + gimple_set_bb (return_stmt, bb2); + + bb3 = e23->dest; + make_edge (bb1, bb3, EDGE_FALSE_VALUE); + + remove_edge (e23); + make_edge (bb2, EXIT_BLOCK_PTR_FOR_FN (cfun), 0); + + pop_cfun (); + + return bb3; +} + +/* This function generates the dispatch function for + multi-versioned functions. DISPATCH_DECL is the function which will + contain the dispatch logic. FNDECLS are the function choices for + dispatch, and is a tree chain. EMPTY_BB is the basic block pointer + in DISPATCH_DECL in which the dispatch code is generated. */ + +static int +dispatch_function_versions (tree dispatch_decl, + void *fndecls_p, + basic_block *empty_bb) +{ + gimple *ifunc_cpu_init_stmt; + gimple_seq gseq; + vec *fndecls; + + gcc_assert (dispatch_decl != NULL + && fndecls_p != NULL + && empty_bb != NULL); + + push_cfun (DECL_STRUCT_FUNCTION (dispatch_decl)); + + gseq = bb_seq (*empty_bb); + /* Function version dispatch is via IFUNC. IFUNC resolvers fire before + constructors, so explicity call __init_riscv_feature_bits here. */ + tree init_fn_type = build_function_type_list (void_type_node, + long_unsigned_type_node, + ptr_type_node, + NULL); + tree init_fn_id = get_identifier ("__init_riscv_feature_bits"); + tree init_fn_decl = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL, + init_fn_id, init_fn_type); + ifunc_cpu_init_stmt = gimple_build_call (init_fn_decl, 0); + gimple_seq_add_stmt (&gseq, ifunc_cpu_init_stmt); + gimple_set_bb (ifunc_cpu_init_stmt, *empty_bb); + + /* Build the struct type for __riscv_feature_bits. */ + tree global_type = lang_hooks.types.make_type (RECORD_TYPE); + tree features_type = build_array_type_nelts (long_long_unsigned_type_node, + RISCV_FEATURE_BITS_LENGTH); + tree field1 = build_decl (UNKNOWN_LOCATION, FIELD_DECL, + get_identifier ("length"), + unsigned_type_node); + tree field2 = build_decl (UNKNOWN_LOCATION, FIELD_DECL, + get_identifier ("features"), + features_type); + DECL_FIELD_CONTEXT (field1) = global_type; + DECL_FIELD_CONTEXT (field2) = global_type; + TYPE_FIELDS (global_type) = field1; + DECL_CHAIN (field1) = field2; + layout_type (global_type); + + tree global_var = build_decl (UNKNOWN_LOCATION, VAR_DECL, + get_identifier ("__riscv_feature_bits"), + global_type); + DECL_EXTERNAL (global_var) = 1; + tree mask_var = create_tmp_var (features_type); + tree feature_ele_var = create_tmp_var (long_long_unsigned_type_node); + tree noted_var = create_tmp_var (long_long_unsigned_type_node); + + + for (int i = 0; i < RISCV_FEATURE_BITS_LENGTH; i++) + { + tree index_expr = build_int_cst (unsigned_type_node, i); + /* feature_ele_var = __riscv_feature_bits.features[i] */ + tree component_expr = build3 (COMPONENT_REF, features_type, + global_var, field2, NULL_TREE); + tree feature_array_ref = build4 (ARRAY_REF, long_long_unsigned_type_node, + component_expr, index_expr, + NULL_TREE, NULL_TREE); + gimple *feature_stmt = gimple_build_assign (feature_ele_var, + feature_array_ref); + gimple_set_block (feature_stmt, DECL_INITIAL (dispatch_decl)); + gimple_set_bb (feature_stmt, *empty_bb); + gimple_seq_add_stmt (&gseq, feature_stmt); + /* noted_var = ~feature_ele_var. */ + tree not_expr = build1 (BIT_NOT_EXPR, long_long_unsigned_type_node, + feature_ele_var); + gimple *not_stmt = gimple_build_assign (noted_var, not_expr); + gimple_set_block (not_stmt, DECL_INITIAL (dispatch_decl)); + gimple_set_bb (not_stmt, *empty_bb); + gimple_seq_add_stmt (&gseq, not_stmt); + /* mask_var[i] = noted_var. */ + tree mask_array_ref = build4 (ARRAY_REF, long_long_unsigned_type_node, + mask_var, index_expr, NULL_TREE, NULL_TREE); + gimple *mask_assign_stmt = gimple_build_assign (mask_array_ref, + noted_var); + gimple_set_block (mask_assign_stmt, DECL_INITIAL (dispatch_decl)); + gimple_set_bb (mask_assign_stmt, *empty_bb); + gimple_seq_add_stmt (&gseq, mask_assign_stmt); + } + + set_bb_seq (*empty_bb, gseq); + + pop_cfun (); + + /* fndecls_p is actually a vector. */ + fndecls = static_cast *> (fndecls_p); + + /* At least one more version other than the default. */ + unsigned int num_versions = fndecls->length (); + gcc_assert (num_versions >= 2); + + struct function_version_info + { + tree version_decl; + int prio; + struct riscv_feature_bits features; + } *function_versions; + + function_versions = (struct function_version_info *) + XNEWVEC (struct function_version_info, (num_versions)); + + unsigned int actual_versions = 0; + + for (tree version_decl : *fndecls) + { + function_versions[actual_versions].version_decl = version_decl; + // Get attribute string, parse it and find the right features. + parse_features_for_version (version_decl, + function_versions[actual_versions].features, + function_versions[actual_versions].prio); + actual_versions++; + } + + + auto compare_feature_version_info = [](const void *p1, const void *p2) + { + const function_version_info v1 = *(const function_version_info *)p1; + const function_version_info v2 = *(const function_version_info *)p2; + return - compare_fmv_features (v1.features, v2.features, + v1.prio, v2.prio); + }; + + /* Sort the versions according to descending order of dispatch priority. */ + qsort (function_versions, actual_versions, + sizeof (struct function_version_info), compare_feature_version_info); + + for (unsigned int i = 0; i < actual_versions; ++i) + { + *empty_bb = add_condition_to_bb (dispatch_decl, + function_versions[i].version_decl, + &function_versions[i].features, + mask_var, + *empty_bb); + } + + free (function_versions); + return 0; +} + +/* Return an identifier for the base assembler name of a versioned function. + This is computed by taking the default version's assembler name, and + stripping off the ".default" suffix if it's already been appended. */ + +static tree +get_suffixed_assembler_name (tree default_decl, const char *suffix) +{ + std::string name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (default_decl)); + + auto size = name.size (); + if (size >= 8 && name.compare (size - 8, 8, ".default") == 0) + name.resize (size - 8); + name += suffix; + return get_identifier (name.c_str ()); +} + +/* Make the resolver function decl to dispatch the versions of + a multi-versioned function, DEFAULT_DECL. IFUNC_ALIAS_DECL is + ifunc alias that will point to the created resolver. Create an + empty basic block in the resolver and store the pointer in + EMPTY_BB. Return the decl of the resolver function. */ + +static tree +make_resolver_func (const tree default_decl, + const tree ifunc_alias_decl, + basic_block *empty_bb) +{ + tree decl, type, t; + + /* Create resolver function name based on default_decl. We need to remove an + existing ".default" suffix if this has already been appended. */ + tree decl_name = get_suffixed_assembler_name (default_decl, ".resolver"); + const char *resolver_name = IDENTIFIER_POINTER (decl_name); + + /* The resolver function should have signature + (void *) resolver (uint64_t, void *) */ + type = build_function_type_list (ptr_type_node, + uint64_type_node, + ptr_type_node, + NULL_TREE); + + decl = build_fn_decl (resolver_name, type); + SET_DECL_ASSEMBLER_NAME (decl, decl_name); + + DECL_NAME (decl) = decl_name; + TREE_USED (decl) = 1; + DECL_ARTIFICIAL (decl) = 1; + DECL_IGNORED_P (decl) = 1; + TREE_PUBLIC (decl) = 0; + DECL_UNINLINABLE (decl) = 1; + + /* Resolver is not external, body is generated. */ + DECL_EXTERNAL (decl) = 0; + DECL_EXTERNAL (ifunc_alias_decl) = 0; + + DECL_CONTEXT (decl) = NULL_TREE; + DECL_INITIAL (decl) = make_node (BLOCK); + DECL_STATIC_CONSTRUCTOR (decl) = 0; + + if (DECL_COMDAT_GROUP (default_decl) + || TREE_PUBLIC (default_decl)) + { + /* In this case, each translation unit with a call to this + versioned function will put out a resolver. Ensure it + is comdat to keep just one copy. */ + DECL_COMDAT (decl) = 1; + make_decl_one_only (decl, DECL_ASSEMBLER_NAME (decl)); + } + else + TREE_PUBLIC (ifunc_alias_decl) = 0; + + /* Build result decl and add to function_decl. */ + t = build_decl (UNKNOWN_LOCATION, RESULT_DECL, NULL_TREE, ptr_type_node); + DECL_CONTEXT (t) = decl; + DECL_ARTIFICIAL (t) = 1; + DECL_IGNORED_P (t) = 1; + DECL_RESULT (decl) = t; + + /* Build parameter decls and add to function_decl. */ + tree arg1 = build_decl (UNKNOWN_LOCATION, PARM_DECL, + get_identifier ("hwcap"), + uint64_type_node); + tree arg2 = build_decl (UNKNOWN_LOCATION, PARM_DECL, + get_identifier ("hwprobe_func"), + ptr_type_node); + DECL_CONTEXT (arg1) = decl; + DECL_CONTEXT (arg2) = decl; + DECL_ARTIFICIAL (arg1) = 1; + DECL_ARTIFICIAL (arg2) = 1; + DECL_IGNORED_P (arg1) = 1; + DECL_IGNORED_P (arg2) = 1; + DECL_ARG_TYPE (arg1) = uint64_type_node; + DECL_ARG_TYPE (arg2) = ptr_type_node; + DECL_ARGUMENTS (decl) = arg1; + TREE_CHAIN (arg1) = arg2; + + gimplify_function_tree (decl); + push_cfun (DECL_STRUCT_FUNCTION (decl)); + *empty_bb = init_lowered_empty_function (decl, false, + profile_count::uninitialized ()); + + cgraph_node::add_new_function (decl, true); + symtab->call_cgraph_insertion_hooks (cgraph_node::get_create (decl)); + + pop_cfun (); + + gcc_assert (ifunc_alias_decl != NULL); + /* Mark ifunc_alias_decl as "ifunc" with resolver as resolver_name. */ + DECL_ATTRIBUTES (ifunc_alias_decl) + = make_attribute ("ifunc", resolver_name, + DECL_ATTRIBUTES (ifunc_alias_decl)); + + /* Create the alias for dispatch to resolver here. */ + cgraph_node::create_same_body_alias (ifunc_alias_decl, decl); + return decl; +} + +/* Implement TARGET_GENERATE_VERSION_DISPATCHER_BODY. */ + +tree +riscv_generate_version_dispatcher_body (void *node_p) +{ + tree resolver_decl; + basic_block empty_bb; + tree default_ver_decl; + struct cgraph_node *versn; + struct cgraph_node *node; + + struct cgraph_function_version_info *node_version_info = NULL; + struct cgraph_function_version_info *versn_info = NULL; + + node = (cgraph_node *)node_p; + + node_version_info = node->function_version (); + gcc_assert (node->dispatcher_function + && node_version_info != NULL); + + if (node_version_info->dispatcher_resolver) + return node_version_info->dispatcher_resolver; + + /* The first version in the chain corresponds to the default version. */ + default_ver_decl = node_version_info->next->this_node->decl; + + /* node is going to be an alias, so remove the finalized bit. */ + node->definition = false; + + resolver_decl = make_resolver_func (default_ver_decl, + node->decl, &empty_bb); + + node_version_info->dispatcher_resolver = resolver_decl; + + push_cfun (DECL_STRUCT_FUNCTION (resolver_decl)); + + auto_vec fn_ver_vec; + + for (versn_info = node_version_info->next; versn_info; + versn_info = versn_info->next) + { + versn = versn_info->this_node; + /* Check for virtual functions here again, as by this time it should + have been determined if this function needs a vtable index or + not. This happens for methods in derived classes that override + virtual methods in base classes but are not explicitly marked as + virtual. */ + if (DECL_VINDEX (versn->decl)) + sorry ("virtual function multiversioning not supported"); + + fn_ver_vec.safe_push (versn->decl); + } + + dispatch_function_versions (resolver_decl, &fn_ver_vec, &empty_bb); + cgraph_edge::rebuild_edges (); + pop_cfun (); + + /* Fix up symbol names. First we need to obtain the base name, which may + have already been mangled. */ + tree base_name = get_suffixed_assembler_name (default_ver_decl, ""); + + /* We need to redo the version mangling on the non-default versions for the + target_clones case. Redoing the mangling for the target_version case is + redundant but does no harm. We need to skip the default version, because + expand_clones will append ".default" later; fortunately that suffix is the + one we want anyway. */ + for (versn_info = node_version_info->next->next; versn_info; + versn_info = versn_info->next) + { + tree version_decl = versn_info->this_node->decl; + tree name = riscv_mangle_decl_assembler_name (version_decl, + base_name); + symtab->change_decl_assembler_name (version_decl, name); + } + + /* We also need to use the base name for the ifunc declaration. */ + symtab->change_decl_assembler_name (node->decl, base_name); + + return resolver_decl; +} + +/* Make a dispatcher declaration for the multi-versioned function DECL. + Calls to DECL function will be replaced with calls to the dispatcher + by the front-end. Returns the decl of the dispatcher function. */ + +tree +riscv_get_function_versions_dispatcher (void *decl) +{ + tree fn = (tree) decl; + struct cgraph_node *node = NULL; + struct cgraph_node *default_node = NULL; + struct cgraph_function_version_info *node_v = NULL; + struct cgraph_function_version_info *first_v = NULL; + + tree dispatch_decl = NULL; + + struct cgraph_function_version_info *default_version_info = NULL; + + gcc_assert (fn != NULL && DECL_FUNCTION_VERSIONED (fn)); + + node = cgraph_node::get (fn); + gcc_assert (node != NULL); + + node_v = node->function_version (); + gcc_assert (node_v != NULL); + + if (node_v->dispatcher_resolver != NULL) + return node_v->dispatcher_resolver; + + /* Find the default version and make it the first node. */ + first_v = node_v; + /* Go to the beginning of the chain. */ + while (first_v->prev != NULL) + first_v = first_v->prev; + default_version_info = first_v; + + while (default_version_info != NULL) + { + struct riscv_feature_bits res; + int priority; /* Unused. */ + parse_features_for_version (default_version_info->this_node->decl, + res, priority); + if (res.length == 0) + break; + default_version_info = default_version_info->next; + } + + /* If there is no default node, just return NULL. */ + if (default_version_info == NULL) + return NULL; + + /* Make default info the first node. */ + if (first_v != default_version_info) + { + default_version_info->prev->next = default_version_info->next; + if (default_version_info->next) + default_version_info->next->prev = default_version_info->prev; + first_v->prev = default_version_info; + default_version_info->next = first_v; + default_version_info->prev = NULL; + } + + default_node = default_version_info->this_node; + + if (targetm.has_ifunc_p ()) + { + struct cgraph_function_version_info *it_v = NULL; + struct cgraph_node *dispatcher_node = NULL; + struct cgraph_function_version_info *dispatcher_version_info = NULL; + + /* Right now, the dispatching is done via ifunc. */ + dispatch_decl = make_dispatcher_decl (default_node->decl); + TREE_NOTHROW (dispatch_decl) = TREE_NOTHROW (fn); + + dispatcher_node = cgraph_node::get_create (dispatch_decl); + gcc_assert (dispatcher_node != NULL); + dispatcher_node->dispatcher_function = 1; + dispatcher_version_info + = dispatcher_node->insert_new_function_version (); + dispatcher_version_info->next = default_version_info; + dispatcher_node->definition = 1; + + /* Set the dispatcher for all the versions. */ + it_v = default_version_info; + while (it_v != NULL) + { + it_v->dispatcher_resolver = dispatch_decl; + it_v = it_v->next; + } + } + else + { + error_at (DECL_SOURCE_LOCATION (default_node->decl), + "multiversioning needs % which is not supported " + "on this target"); + } + + return dispatch_decl; +} + /* On riscv we have an ABI defined safe buffer. This constant is used to determining the probe offset for alloca. */ @@ -13122,6 +13696,14 @@ riscv_stack_clash_protection_alloca_probe_range (void) #undef TARGET_MANGLE_DECL_ASSEMBLER_NAME #define TARGET_MANGLE_DECL_ASSEMBLER_NAME riscv_mangle_decl_assembler_name +#undef TARGET_GENERATE_VERSION_DISPATCHER_BODY +#define TARGET_GENERATE_VERSION_DISPATCHER_BODY \ + riscv_generate_version_dispatcher_body + +#undef TARGET_GET_FUNCTION_VERSIONS_DISPATCHER +#define TARGET_GET_FUNCTION_VERSIONS_DISPATCHER \ + riscv_get_function_versions_dispatcher + struct gcc_target targetm = TARGET_INITIALIZER; #include "gt-riscv.h" From patchwork Thu Oct 24 07:13:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangyu Chen X-Patchwork-Id: 2001486 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=L8gezPLa; 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 4XYxyd0sGqz1xwy for ; Thu, 24 Oct 2024 18:15:37 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2288B3858C66 for ; Thu, 24 Oct 2024 07:15:35 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from out162-62-57-49.mail.qq.com (out162-62-57-49.mail.qq.com [162.62.57.49]) by sourceware.org (Postfix) with UTF8SMTPS id 549D4385829B for ; Thu, 24 Oct 2024 07:13:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 549D4385829B 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 549D4385829B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=162.62.57.49 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729754034; cv=none; b=x4dAw2VERzCRvLONHU2sr1QdZYO0PIFoIovCCBQKQlZjZ82JONV3mTMrhDy6/85LcUooHA920qkiC3nXQYu+4BkRwzZ0bryq6vHHqm/MofbEi9ba3EOzdJ+KoC35AeQ7qP6X7FHSSfvgYihkh7F0F9pT6WgxrIvgGxwQB8X6Uog= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729754034; c=relaxed/simple; bh=7GpWIavZRsT8v9ojHnLqLbFl6QJOeZMKA1a3sPDomcY=; h=DKIM-Signature:Message-ID:From:To:Subject:Date:MIME-Version; b=bKTZIUlL/GJ7AomS10X9e6HSeNDXypOq0D8KAiKqe8jmECCb41EQ9PEbVsdqLjA9n5vRAxkrv+sxhkvwZV81s3rMnu2SRLlhRhzxVi6RUn/VTWKWF3szZeX0Fu2Mc49qqt3embBLaE8/Bm5N9VHXru31VDBaE295+N9EcCBNTrE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1729754021; bh=kaDZtV+9H3P1WxilHwQsoFPHhjFIyUMGh+4IRHrHk6U=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=L8gezPLaF9X6tzTJh8ihYD6wtEIlgESaN12BHIrUwDtHvdTrlptfvdQY4VzfMy1nI r5Hp7iJhD3PTz4mDzRrqWnv1W3zN+Jfo9KsBegHKGm5uOcqdhkgKRrAZIFuG42QpGM R9TMfI8l2dQJydph/uOXL2eD+pMtplgViSprHZBo= Received: from cyy-pc.lan ([240e:379:2265:5e00:1651:dae2:1a9c:8827]) by newxmesmtplogicsvrszb16-1.qq.com (NewEsmtp) with SMTP id 3653C24A; Thu, 24 Oct 2024 15:13:37 +0800 X-QQ-mid: xmsmtpt1729754017tvapqhfym Message-ID: X-QQ-XMAILINFO: Nxhse96oac3NVScQy5BlV2ZbFNxsavbOxY2fdhWf6MyDsYFR3LMaWFfiOhzG15 IOtw9gHdCYQfjrgAorGUIBvqiTpcB8exkHrn3JAnAforbVmAPPK6UdhGQf1RgwwmE+b9ovCn7JK4 uiZNAtmxOU14K6x4S3xWLJUO7iuWKfS0alm8MneDVEhf529QeeMXflvYw4ZmIoWeBqmbbOlFzI6b VnlKAXSvaYGwuwmlNsvSTgw3Z7gWJEU4lfaipgPDgQyrhyd8q5GaKQ5+5QW8gD5bHBDBEwbpowR5 S9/01m1MtevPUSppTplAGnECDiLZQZkDaCNc//+1OarZQw9GVP1kO6iMwkADcBOLGDLPDwg5SRk1 rxqDNJpYOYhSekihGIbG33+VJCpex2kVXhzLP2nYKVf2XR/Y45Ed/nIOmP3uC/DDmkd+y1g++qtb TqTn5Rm//MxrUbnWSL7eNpoV+SI//fUxZQ8Z+pNkJ5wtUoMTrT0YthUB5pvShOCO2uFeeQMewUjh SBuIfuGFN6W99q/uTvOZtcJn8nyectx4JUPtziymhZLd/06unGrdDqQzxbvZx72pKfW2daqppdh4 nIwVnJprrI9mtaM6iDxW/06rhdgI5yC4INGQjiFw71j2pMqnfjdpIGBGvnbXYjxOznmHSWHMbynO pqPjuUjbZJYhb2jG/fJqZN/RLXgtMDu+3TpdJR4XFIyaK/Hnr/cB6kIXmyof9q6MTzxGOvvTYuKm Uy6Qfw+HBIZ4KdjH+MW62tOOBjVxXjZK+VCb08FBSI0OzA/670Lzy8Rfud4F+YdqeCtA+XQK57sW /wH40TXWcLqIkBduInvKze/UEBvZ05JBpJPVtpS3J0hiuxmJGkL5+bpKA9O/dWLsOkCEj4XlEc1v ffupLdaFG8YjSH7WmkITxonyVgeXA/VJb/0bL3hUksUMeMYKRZhj65U/K8CQc/mwYb3N1HQpZIA+ OV7HaLPO0fVbDas8u/cXraUA6fO7jHxyb+qhxchB5fZL5u7jzWfOGzCyNf0ulfmtvko3OrpKKOaG KW78KZ0c/+jPH28i2Q X-QQ-XMRINFO: MPJ6Tf5t3I/ycC2BItcBVIA= 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 v3 11/11] RISC-V: Add Multi-Versioning Test Cases Date: Thu, 24 Oct 2024 15:13:35 +0800 X-OQ-MSGID: <20241024071335.1838363-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.8 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 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 adds test cases for the Function Multi-Versioning (FMV) feature for RISC-V, which reuses the existing test cases from the aarch64 and ported them to RISC-V. gcc/testsuite/ChangeLog: * g++.target/riscv/mv-symbols1.C: New test. * g++.target/riscv/mv-symbols2.C: New test. * g++.target/riscv/mv-symbols3.C: New test. * g++.target/riscv/mv-symbols4.C: New test. * g++.target/riscv/mv-symbols5.C: New test. * g++.target/riscv/mvc-symbols1.C: New test. * g++.target/riscv/mvc-symbols2.C: New test. * g++.target/riscv/mvc-symbols3.C: New test. * g++.target/riscv/mvc-symbols4.C: New test. --- 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 +++++++++ 9 files changed, 458 insertions(+) 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 diff --git a/gcc/testsuite/g++.target/riscv/mv-symbols1.C b/gcc/testsuite/g++.target/riscv/mv-symbols1.C new file mode 100644 index 00000000000..ffedd6dab41 --- /dev/null +++ b/gcc/testsuite/g++.target/riscv/mv-symbols1.C @@ -0,0 +1,70 @@ +/* { dg-do compile } */ +/* { dg-require-ifunc "" } */ +/* { dg-options "-O0 -march=rv64gc -mabi=lp64" } */ + +int foo () +{ + return 1; +} + +__attribute__((target_version("arch=+v"))) +int foo () +{ + return 3; +} +__attribute__((target_version("arch=+zba,+zbb"))) +int foo () +{ + return 5; +} + +__attribute__((target_version("arch=+zba,+zbb"))) +int foo (int) +{ + return 6; +} + +__attribute__((target_version("arch=+v"))) +int foo (int) +{ + return 4; +} + +int foo (int) +{ + return 2; +} + + +int bar() +{ + return foo (); +} + +int bar(int x) +{ + return foo (x); +} + +/* When updating any of the symbol names in these tests, make sure to also + update any tests for their absence in mv-symbolsN.C */ + +/* { dg-final { scan-assembler ".attribute arch, \"rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0_zifencei2p0_zaamo1p0_zalrsc1p0_zca1p0_zcd1p0\"" } } */ +/* { dg-final { scan-assembler-times ".option arch, rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_v1p0_zicsr2p0_zifencei2p0_zaamo1p0_zalrsc1p0_zca1p0_zcd1p0_zve32f1p0_zve32x1p0_zve64d1p0_zve64f1p0_zve64x1p0_zvl128b1p0_zvl32b1p0_zvl64b1p0" 2 } } */ +/* { dg-final { scan-assembler-times ".option arch, rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0_zifencei2p0_zaamo1p0_zalrsc1p0_zca1p0_zcd1p0_zba1p0_zbb1p0" 2 } } */ + +/* { dg-final { scan-assembler-times "\n_Z3foov\.default:\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n_Z3foov\.arch__v:\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n_Z3foov\.arch__zba__zbb:\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n_Z3foov\.resolver:\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n\t\call\t_Z3foov\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n\t\.type\t_Z3foov, @gnu_indirect_function\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n\t\.set\t_Z3foov,_Z3foov\.resolver\n" 1 } } */ + +/* { dg-final { scan-assembler-times "\n_Z3fooi\.default:\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n_Z3fooi\.arch__v:\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n_Z3fooi\.arch__zba__zbb:\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n_Z3fooi\.resolver:\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n\t\call\t_Z3fooi\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n\t\.type\t_Z3fooi, @gnu_indirect_function\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n\t\.set\t_Z3fooi,_Z3fooi\.resolver\n" 1 } } */ diff --git a/gcc/testsuite/g++.target/riscv/mv-symbols2.C b/gcc/testsuite/g++.target/riscv/mv-symbols2.C new file mode 100644 index 00000000000..672cd19126b --- /dev/null +++ b/gcc/testsuite/g++.target/riscv/mv-symbols2.C @@ -0,0 +1,61 @@ +/* { dg-do compile } */ +/* { dg-require-ifunc "" } */ +/* { dg-options "-O0 -march=rv64gc -mabi=lp64" } */ + +__attribute__((target_version("default"))) +int foo () +{ + return 1; +} + +__attribute__((target_version("arch=+v"))) +int foo () +{ + return 3; +} +__attribute__((target_version("arch=+zba,+zbb"))) +int foo () +{ + return 5; +} + +__attribute__((target_version("arch=+zba,+zbb"))) +int foo (int) +{ + return 6; +} + +__attribute__((target_version("arch=+v"))) +int foo (int) +{ + return 4; +} + +__attribute__((target_version("default"))) +int foo (int) +{ + return 2; +} + +/* When updating any of the symbol names in these tests, make sure to also + update any tests for their absence in mv-symbolsN.C */ + +/* { dg-final { scan-assembler ".attribute arch, \"rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0_zifencei2p0_zaamo1p0_zalrsc1p0_zca1p0_zcd1p0\"" } } */ +/* { dg-final { scan-assembler-times ".option arch, rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_v1p0_zicsr2p0_zifencei2p0_zaamo1p0_zalrsc1p0_zca1p0_zcd1p0_zve32f1p0_zve32x1p0_zve64d1p0_zve64f1p0_zve64x1p0_zvl128b1p0_zvl32b1p0_zvl64b1p0" 2 } } */ +/* { dg-final { scan-assembler-times ".option arch, rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0_zifencei2p0_zaamo1p0_zalrsc1p0_zca1p0_zcd1p0_zba1p0_zbb1p0" 2 } } */ + +/* { dg-final { scan-assembler-times "\n_Z3foov\.default:\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n_Z3foov\.arch__v:\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n_Z3foov\.arch__zba__zbb:\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n_Z3foov\.resolver:\n" 0 } } */ +/* { dg-final { scan-assembler-times "\n\tcall\t_Z3foov\n" 0 } } */ +/* { dg-final { scan-assembler-times "\n\t\.type\t_Z3foov, @gnu_indirect_function\n" 0 } } */ +/* { dg-final { scan-assembler-times "\n\t\.set\t_Z3foov,_Z3foov\.resolver\n" 0 } } */ + +/* { dg-final { scan-assembler-times "\n_Z3fooi\.default:\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n_Z3fooi\.arch__v:\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n_Z3fooi\.arch__zba__zbb:\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n_Z3fooi\.resolver:\n" 0 } } */ +/* { dg-final { scan-assembler-times "\n\tcall\t_Z3fooi\n" 0 } } */ +/* { dg-final { scan-assembler-times "\n\t\.type\t_Z3fooi, @gnu_indirect_function\n" 0 } } */ +/* { dg-final { scan-assembler-times "\n\t\.set\t_Z3fooi,_Z3fooi\.resolver\n" 0 } } */ diff --git a/gcc/testsuite/g++.target/riscv/mv-symbols3.C b/gcc/testsuite/g++.target/riscv/mv-symbols3.C new file mode 100644 index 00000000000..78e006c8cc0 --- /dev/null +++ b/gcc/testsuite/g++.target/riscv/mv-symbols3.C @@ -0,0 +1,50 @@ +/* { dg-do compile } */ +/* { dg-require-ifunc "" } */ +/* { dg-options "-O0 -march=rv64gc -mabi=lp64" } */ + +__attribute__((target_version("default"))) +int foo (); + +__attribute__((target_version("arch=+v"))) +int foo (); + +__attribute__((target_version("arch=+zba,+zbb"))) +int foo (); + +__attribute__((target_version("default"))) +int foo (int); + +__attribute__((target_version("arch=+v"))) +int foo (int); + +__attribute__((target_version("arch=+zba,+zbb"))) +int foo (int); + + +int bar() +{ + return foo (); +} + +/* When updating any of the symbol names in these tests, make sure to also + update any tests for their absence in mv-symbolsN.C */ + +/* { dg-final { scan-assembler ".attribute arch, \"rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0_zifencei2p0_zaamo1p0_zalrsc1p0_zca1p0_zcd1p0\"" } } */ +/* { dg-final { scan-assembler-times ".option arch, rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_v1p0_zicsr2p0_zifencei2p0_zaamo1p0_zalrsc1p0_zca1p0_zcd1p0_zve32f1p0_zve32x1p0_zve64d1p0_zve64f1p0_zve64x1p0_zvl128b1p0_zvl32b1p0_zvl64b1p0" 0 } } */ +/* { dg-final { scan-assembler-times ".option arch, rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0_zifencei2p0_zaamo1p0_zalrsc1p0_zca1p0_zcd1p0_zba1p0_zbb1p0" 0 } } */ + +/* { dg-final { scan-assembler-times "\n_Z3foov\.default:\n" 0 } } */ +/* { dg-final { scan-assembler-times "\n_Z3foov\.arch__v:\n" 0 } } */ +/* { dg-final { scan-assembler-times "\n_Z3foov\.arch__zba__zbb:\n" 0 } } */ +/* { dg-final { scan-assembler-times "\n_Z3foov\.resolver:\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n\tcall\t_Z3foov\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n\t\.type\t_Z3foov, @gnu_indirect_function\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n\t\.set\t_Z3foov,_Z3foov\.resolver\n" 1 } } */ + +/* { dg-final { scan-assembler-times "\n_Z3fooi\.default:\n" 0 } } */ +/* { dg-final { scan-assembler-times "\n_Z3fooi\.arch__v:\n" 0 } } */ +/* { dg-final { scan-assembler-times "\n_Z3fooi\.arch__zba__zbb:\n" 0 } } */ +/* { dg-final { scan-assembler-times "\n_Z3fooi\.resolver:\n" 0 } } */ +/* { dg-final { scan-assembler-times "\n\tcall\t_Z3fooi\n" 0 } } */ +/* { dg-final { scan-assembler-times "\n\t\.type\t_Z3fooi, @gnu_indirect_function\n" 0 } } */ +/* { dg-final { scan-assembler-times "\n\t\.set\t_Z3fooi,_Z3fooi\.resolver\n" 0 } } */ diff --git a/gcc/testsuite/g++.target/riscv/mv-symbols4.C b/gcc/testsuite/g++.target/riscv/mv-symbols4.C new file mode 100644 index 00000000000..c9fd395126e --- /dev/null +++ b/gcc/testsuite/g++.target/riscv/mv-symbols4.C @@ -0,0 +1,56 @@ +/* { dg-do compile } */ +/* { dg-require-ifunc "" } */ +/* { dg-options "-O0 -march=rv64gc -mabi=lp64" } */ + +__attribute__((target_version("default"))) +int foo () +{ + return 1; +} + +__attribute__((target_version("arch=+v"))) +int foo (); + +__attribute__((target_version("arch=+zba,+zbb"))) +int foo (); + +__attribute__((target_version("default"))) +int foo (int) +{ + return 2; +} + +__attribute__((target_version("arch=+v"))) +int foo (int); + +__attribute__((target_version("arch=+zba,+zbb"))) +int foo (int); + + +int bar() +{ + return foo (); +} + +/* When updating any of the symbol names in these tests, make sure to also + update any tests for their absence in mv-symbolsN.C */ + +/* { dg-final { scan-assembler ".attribute arch, \"rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0_zifencei2p0_zaamo1p0_zalrsc1p0_zca1p0_zcd1p0\"" } } */ +/* { dg-final { scan-assembler-times ".option arch, rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_v1p0_zicsr2p0_zifencei2p0_zaamo1p0_zalrsc1p0_zca1p0_zcd1p0_zve32f1p0_zve32x1p0_zve64d1p0_zve64f1p0_zve64x1p0_zvl128b1p0_zvl32b1p0_zvl64b1p0" 0 } } */ +/* { dg-final { scan-assembler-times ".option arch, rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0_zifencei2p0_zaamo1p0_zalrsc1p0_zca1p0_zcd1p0_zba1p0_zbb1p0" 0 } } */ + +/* { dg-final { scan-assembler-times "\n_Z3foov\.default:\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n_Z3foov\.arch__v:\n" 0 } } */ +/* { dg-final { scan-assembler-times "\n_Z3foov\.arch__zba__zbb:\n" 0 } } */ +/* { dg-final { scan-assembler-times "\n_Z3foov\.resolver:\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n\tcall\t_Z3foov\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n\t\.type\t_Z3foov, @gnu_indirect_function\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n\t\.set\t_Z3foov,_Z3foov\.resolver\n" 1 } } */ + +/* { dg-final { scan-assembler-times "\n_Z3fooi\.default:\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n_Z3fooi\.arch__v:\n" 0 } } */ +/* { dg-final { scan-assembler-times "\n_Z3fooi\.arch__zba__zbb:\n" 0 } } */ +/* { dg-final { scan-assembler-times "\n_Z3fooi\.resolver:\n" 0 } } */ +/* { dg-final { scan-assembler-times "\n\tcall\t_Z3fooi\n" 0 } } */ +/* { dg-final { scan-assembler-times "\n\t\.type\t_Z3fooi, @gnu_indirect_function\n" 0 } } */ +/* { dg-final { scan-assembler-times "\n\t\.set\t_Z3fooi,_Z3fooi\.resolver\n" 0 } } */ diff --git a/gcc/testsuite/g++.target/riscv/mv-symbols5.C b/gcc/testsuite/g++.target/riscv/mv-symbols5.C new file mode 100644 index 00000000000..87fbcd3da30 --- /dev/null +++ b/gcc/testsuite/g++.target/riscv/mv-symbols5.C @@ -0,0 +1,62 @@ +/* { dg-do compile } */ +/* { dg-require-ifunc "" } */ +/* { dg-options "-O0 -march=rv64gc -mabi=lp64" } */ + +__attribute__((target_version("default"))) +int foo (); + +__attribute__((target_version("arch=+v"))) +int foo () +{ + return 3; +} + +__attribute__((target_version("arch=+zba,+zbb"))) +int foo () +{ + return 5; +} + +__attribute__((target_version("default"))) +int foo (int); + +__attribute__((target_version("arch=+v"))) +int foo (int) +{ + return 4; +} + +__attribute__((target_version("arch=+zba,+zbb"))) +int foo (int) +{ + return 6; +} + + +int bar() +{ + return foo (); +} + +/* When updating any of the symbol names in these tests, make sure to also + update any tests for their absence in mv-symbolsN.C */ + +/* { dg-final { scan-assembler ".attribute arch, \"rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0_zifencei2p0_zaamo1p0_zalrsc1p0_zca1p0_zcd1p0\"" } } */ +/* { dg-final { scan-assembler-times ".option arch, rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_v1p0_zicsr2p0_zifencei2p0_zaamo1p0_zalrsc1p0_zca1p0_zcd1p0_zve32f1p0_zve32x1p0_zve64d1p0_zve64f1p0_zve64x1p0_zvl128b1p0_zvl32b1p0_zvl64b1p0" 2 } } */ +/* { dg-final { scan-assembler-times ".option arch, rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0_zifencei2p0_zaamo1p0_zalrsc1p0_zca1p0_zcd1p0_zba1p0_zbb1p0" 2 } } */ + +/* { dg-final { scan-assembler-times "\n_Z3foov\.default:\n" 0 } } */ +/* { dg-final { scan-assembler-times "\n_Z3foov\.arch__v:\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n_Z3foov\.arch__zba__zbb:\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n_Z3foov\.resolver:\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n\tcall\t_Z3foov\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n\t\.type\t_Z3foov, @gnu_indirect_function\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n\t\.set\t_Z3foov,_Z3foov\.resolver\n" 1 } } */ + +/* { dg-final { scan-assembler-times "\n_Z3fooi\.default:\n" 0 } } */ +/* { dg-final { scan-assembler-times "\n_Z3fooi\.arch__v:\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n_Z3fooi\.arch__zba__zbb:\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n_Z3fooi\.resolver:\n" 0 } } */ +/* { dg-final { scan-assembler-times "\n\tcall\t_Z3fooi\n" 0 } } */ +/* { dg-final { scan-assembler-times "\n\t\.type\t_Z3fooi, @gnu_indirect_function\n" 0 } } */ +/* { dg-final { scan-assembler-times "\n\t\.set\t_Z3fooi,_Z3fooi\.resolver\n" 0 } } */ diff --git a/gcc/testsuite/g++.target/riscv/mvc-symbols1.C b/gcc/testsuite/g++.target/riscv/mvc-symbols1.C new file mode 100644 index 00000000000..5d4b390b957 --- /dev/null +++ b/gcc/testsuite/g++.target/riscv/mvc-symbols1.C @@ -0,0 +1,49 @@ +/* { dg-do compile } */ +/* { dg-require-ifunc "" } */ +/* { dg-options "-O0 -march=rv64gc -mabi=lp64" } */ + +__attribute__((target_clones("default", "arch=+v", "arch=+zba,+zbb"))) +int foo () +{ + return 1; +} + +__attribute__((target_clones("arch=+zba,+zbb", "arch=+v", "default"))) +int foo (int) +{ + return 2; +} + + +int bar() +{ + return foo (); +} + +int bar(int x) +{ + return foo (x); +} + +/* When updating any of the symbol names in these tests, make sure to also + update any tests for their absence in mvc-symbolsN.C */ + +/* { dg-final { scan-assembler ".attribute arch, \"rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0_zifencei2p0_zaamo1p0_zalrsc1p0_zca1p0_zcd1p0\"" } } */ +/* { dg-final { scan-assembler-times ".option arch, rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_v1p0_zicsr2p0_zifencei2p0_zaamo1p0_zalrsc1p0_zca1p0_zcd1p0_zve32f1p0_zve32x1p0_zve64d1p0_zve64f1p0_zve64x1p0_zvl128b1p0_zvl32b1p0_zvl64b1p0" 2 } } */ +/* { dg-final { scan-assembler-times ".option arch, rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0_zifencei2p0_zaamo1p0_zalrsc1p0_zca1p0_zcd1p0_zba1p0_zbb1p0" 2 } } */ + +/* { dg-final { scan-assembler-times "\n_Z3foov\.default:\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n_Z3foov\.arch__v:\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n_Z3foov\.arch__zba__zbb:\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n_Z3foov\.resolver:\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n\tcall\t_Z3foov\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n\t\.type\t_Z3foov, @gnu_indirect_function\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n\t\.set\t_Z3foov,_Z3foov\.resolver\n" 1 } } */ + +/* { dg-final { scan-assembler-times "\n_Z3fooi\.default:\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n_Z3fooi\.arch__v:\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n_Z3fooi\.arch__zba__zbb:\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n_Z3fooi\.resolver:\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n\tcall\t_Z3fooi\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n\t\.type\t_Z3fooi, @gnu_indirect_function\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n\t\.set\t_Z3fooi,_Z3fooi\.resolver\n" 1 } } */ diff --git a/gcc/testsuite/g++.target/riscv/mvc-symbols2.C b/gcc/testsuite/g++.target/riscv/mvc-symbols2.C new file mode 100644 index 00000000000..48f59ee576f --- /dev/null +++ b/gcc/testsuite/g++.target/riscv/mvc-symbols2.C @@ -0,0 +1,36 @@ +/* { dg-do compile } */ +/* { dg-require-ifunc "" } */ +/* { dg-options "-O0 -march=rv64gc -mabi=lp64" } */ + +__attribute__((target_clones("default", "arch=+v", "arch=+zba,+zbb"))) +int foo () +{ + return 1; +} + +__attribute__((target_clones("arch=+zba,+zbb", "arch=+v", "default"))) +int foo (int) +{ + return 2; +} + +/* When updating any of the symbol names in these tests, make sure to also + update any tests for their absence in mvc-symbolsN.C */ + +/* { dg-final { scan-assembler ".attribute arch, \"rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0_zifencei2p0_zaamo1p0_zalrsc1p0_zca1p0_zcd1p0\"" } } */ +/* { dg-final { scan-assembler-times ".option arch, rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_v1p0_zicsr2p0_zifencei2p0_zaamo1p0_zalrsc1p0_zca1p0_zcd1p0_zve32f1p0_zve32x1p0_zve64d1p0_zve64f1p0_zve64x1p0_zvl128b1p0_zvl32b1p0_zvl64b1p0" 2 } } */ +/* { dg-final { scan-assembler-times ".option arch, rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0_zifencei2p0_zaamo1p0_zalrsc1p0_zca1p0_zcd1p0_zba1p0_zbb1p0" 2 } } */ + +/* { dg-final { scan-assembler-times "\n_Z3foov\.default:\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n_Z3foov\.arch__v:\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n_Z3foov\.arch__zba__zbb:\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n_Z3foov\.resolver:\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n\t\.type\t_Z3foov, @gnu_indirect_function\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n\t\.set\t_Z3foov,_Z3foov\.resolver\n" 1 } } */ + +/* { dg-final { scan-assembler-times "\n_Z3fooi\.default:\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n_Z3fooi\.arch__v:\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n_Z3fooi\.arch__zba__zbb:\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n_Z3fooi\.resolver:\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n\t\.type\t_Z3fooi, @gnu_indirect_function\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n\t\.set\t_Z3fooi,_Z3fooi\.resolver\n" 1 } } */ diff --git a/gcc/testsuite/g++.target/riscv/mvc-symbols3.C b/gcc/testsuite/g++.target/riscv/mvc-symbols3.C new file mode 100644 index 00000000000..24d229b4b19 --- /dev/null +++ b/gcc/testsuite/g++.target/riscv/mvc-symbols3.C @@ -0,0 +1,42 @@ +/* { dg-do compile } */ +/* { dg-require-ifunc "" } */ +/* { dg-options "-O0 -march=rv64gc -mabi=lp64" } */ + +__attribute__((target_clones("default", "arch=+v", "arch=+zba,+zbb"))) +int foo (); + +__attribute__((target_clones("arch=+zba,+zbb", "arch=+v", "default"))) +int foo (int); + +int bar() +{ + return foo (); +} + +int bar(int x) +{ + return foo (x); +} + +/* When updating any of the symbol names in these tests, make sure to also + update any tests for their absence in mvc-symbolsN.C */ + +/* { dg-final { scan-assembler ".attribute arch, \"rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0_zifencei2p0_zaamo1p0_zalrsc1p0_zca1p0_zcd1p0\"" } } */ +/* { dg-final { scan-assembler-times ".option arch, rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_v1p0_zicsr2p0_zifencei2p0_zaamo1p0_zalrsc1p0_zca1p0_zcd1p0_zve32f1p0_zve32x1p0_zve64d1p0_zve64f1p0_zve64x1p0_zvl128b1p0_zvl32b1p0_zvl64b1p0" 0 } } */ +/* { dg-final { scan-assembler-times ".option arch, rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0_zifencei2p0_zaamo1p0_zalrsc1p0_zca1p0_zcd1p0_zba1p0_zbb1p0" 0 } } */ + +/* { dg-final { scan-assembler-times "\n_Z3foov\.default:\n" 0 } } */ +/* { dg-final { scan-assembler-times "\n_Z3foov\.arch__v:\n" 0 } } */ +/* { dg-final { scan-assembler-times "\n_Z3foov\.arch__zba__zbb:\n" 0 } } */ +/* { dg-final { scan-assembler-times "\n_Z3foov\.resolver:\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n\tcall\t_Z3foov\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n\t\.type\t_Z3foov, @gnu_indirect_function\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n\t\.set\t_Z3foov,_Z3foov\.resolver\n" 1 } } */ + +/* { dg-final { scan-assembler-times "\n_Z3fooi\.default:\n" 0 } } */ +/* { dg-final { scan-assembler-times "\n_Z3fooi\.arch__v:\n" 0 } } */ +/* { dg-final { scan-assembler-times "\n_Z3fooi\.arch__zba__zbb:\n" 0 } } */ +/* { dg-final { scan-assembler-times "\n_Z3fooi\.resolver:\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n\tcall\t_Z3fooi\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n\t\.type\t_Z3fooi, @gnu_indirect_function\n" 1 } } */ +/* { dg-final { scan-assembler-times "\n\t\.set\t_Z3fooi,_Z3fooi\.resolver\n" 1 } } */ diff --git a/gcc/testsuite/g++.target/riscv/mvc-symbols4.C b/gcc/testsuite/g++.target/riscv/mvc-symbols4.C new file mode 100644 index 00000000000..d2685d5902b --- /dev/null +++ b/gcc/testsuite/g++.target/riscv/mvc-symbols4.C @@ -0,0 +1,32 @@ +/* { dg-do compile } */ +/* { dg-require-ifunc "" } */ +/* { dg-options "-O0 -march=rv64gc -mabi=lp64" } */ + +__attribute__((target_clones("default", "arch=+v", "arch=+zba,+zbb"))) +int foo (); + +__attribute__((target_clones("arch=+zba,+zbb", "arch=+v", "default"))) +int foo (int); + +/* When updating any of the symbol names in these tests, make sure to also + update any tests for their absence in mvc-symbolsN.C */ + +/* { dg-final { scan-assembler ".attribute arch, \"rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0_zifencei2p0_zaamo1p0_zalrsc1p0_zca1p0_zcd1p0\"" } } */ +/* { dg-final { scan-assembler-times ".option arch, rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_v1p0_zicsr2p0_zifencei2p0_zaamo1p0_zalrsc1p0_zca1p0_zcd1p0_zve32f1p0_zve32x1p0_zve64d1p0_zve64f1p0_zve64x1p0_zvl128b1p0_zvl32b1p0_zvl64b1p0" 0 } } */ +/* { dg-final { scan-assembler-times ".option arch, rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0_zifencei2p0_zaamo1p0_zalrsc1p0_zca1p0_zcd1p0_zba1p0_zbb1p0" 0 } } */ + +/* { dg-final { scan-assembler-times "\n_Z3foov\.default:\n" 0 } } */ +/* { dg-final { scan-assembler-times "\n_Z3foov\.arch__v:\n" 0 } } */ +/* { dg-final { scan-assembler-times "\n_Z3foov\.arch__zba__zbb:\n" 0 } } */ +/* { dg-final { scan-assembler-times "\n_Z3foov\.resolver:\n" 0 } } */ +/* { dg-final { scan-assembler-times "\n\tcall\t_Z3foov\n" 0 } } */ +/* { dg-final { scan-assembler-times "\n\t\.type\t_Z3foov, @gnu_indirect_function\n" 0 } } */ +/* { dg-final { scan-assembler-times "\n\t\.set\t_Z3foov,_Z3foov\.resolver\n" 0 } } */ + +/* { dg-final { scan-assembler-times "\n_Z3fooi\.default:\n" 0 } } */ +/* { dg-final { scan-assembler-times "\n_Z3fooi\.arch__v:\n" 0 } } */ +/* { dg-final { scan-assembler-times "\n_Z3fooi\.arch__zba__zbb:\n" 0 } } */ +/* { dg-final { scan-assembler-times "\n_Z3fooi\.resolver:\n" 0 } } */ +/* { dg-final { scan-assembler-times "\n\tcall\t_Z3fooi\n" 0 } } */ +/* { dg-final { scan-assembler-times "\n\t\.type\t_Z3fooi, @gnu_indirect_function\n" 0 } } */ +/* { dg-final { scan-assembler-times "\n\t\.set\t_Z3fooi,_Z3fooi\.resolver\n" 0 } } */