From patchwork Tue Oct 15 06:18:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangyu Chen X-Patchwork-Id: 1997198 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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 4XSP7q4D8Qz1xvK for ; Tue, 15 Oct 2024 17:19:19 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AEE833857C6D for ; Tue, 15 Oct 2024 06:19:17 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from cstnet.cn (smtp21.cstnet.cn [159.226.251.21]) by sourceware.org (Postfix) with ESMTPS id B1BDC3858417 for ; Tue, 15 Oct 2024 06:18:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B1BDC3858417 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=isrc.iscas.ac.cn Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=isrc.iscas.ac.cn ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B1BDC3858417 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=159.226.251.21 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728973137; cv=none; b=iQOSUZxbVnlA5H9VzUbU8o0T8HKvmACnWAmyyYWfeQkoBlZVAf1a8SmIFhMn18GARL4bSKo2aJfg8jhqDkBpG57Bq28EI9dlantC1/lulevkZ3EkGU6J3yqMVbolKtcO90PhpUT2KLFCBDEwAqoLTe5EX/01tUuim0k7igGRPvs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728973137; c=relaxed/simple; bh=ycEiZXTZvLABKSMJk5YRKzR8pU97iIn3jM9lrHckFIs=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=j5Zg5hI5Y618HpJb/OIFduHME2GZfRlHrbD0y0abQJtqFwSN8asPk0jgnJwIWpvwbVf9KK7iVHe6rRIyyJP2gqlBPCxsNRTAMJwoK27zipK1ZuE9vHjqDRdbkcQXZ4EHjlylAtObrYpnaTsnLcNCqi2KdPITqvHYpaQLIiMXFsw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from cyy-pc.lan (unknown [120.41.211.70]) by APP-01 (Coremail) with SMTP id qwCowAC3vSlGCQ5nihCnBw--.38639S2; Tue, 15 Oct 2024 14:18:48 +0800 (CST) 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] Introduce TARGET_FMV_ATTR_SEPARATOR Date: Tue, 15 Oct 2024 14:18:43 +0800 Message-ID: <20241015061843.3005429-1-chenyangyu@isrc.iscas.ac.cn> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 X-CM-TRANSID: qwCowAC3vSlGCQ5nihCnBw--.38639S2 X-Coremail-Antispam: 1UD129KBjvJXoWxJF4kCry3tw13Xr15GF1xXwb_yoWrtF4xpF WDAFy2vws5Jr43K393tr4xWw15Gws3Zr45CrW8Ar48Aan8GFs3trZ2krsrtFWUJF4UGrZr Z3W0kF17Caya9w7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkm14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26r1j6r1xM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r1j 6r4UM28EF7xvwVC2z280aVAFwI0_Jr0_Gr1l84ACjcxK6I8E87Iv6xkF7I0E14v26r1j6r 4UM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xII jxv20xvE14v26r106r15McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr 1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7MxkF7I0En4kS14v26r12 6r1DMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI 0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y 0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxV WUJVW8JwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1l IxAIcVC2z280aVCY1x0267AKxVWUJVW8JbIYCTnIWIevJa73UjIFyTuYvjfUr2-eDUUUU X-Originating-IP: [120.41.211.70] X-CM-SenderInfo: xfkh055dqj53w6lv2u4olvutnvoduhdfq/ X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_PASS, 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_FMV_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_FMV_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_FMV_ATTR_SEPARATOR): Define new macro. * multiple_target.cc (get_attr_str): Use TARGET_FMV_ATTR_SEPARATOR to separate attributes. (separate_attrs): Likewise. * config/riscv/riscv.h (TARGET_FMV_ATTR_SEPARATOR): Define TARGET_FMV_ATTR_SEPARATOR for RISC-V. --- gcc/config/riscv/riscv.h | 5 +++++ gcc/defaults.h | 4 ++++ gcc/multiple_target.cc | 19 ++++++++++++------- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/gcc/config/riscv/riscv.h b/gcc/config/riscv/riscv.h index ca1b8329cdc..858cab72a4c 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_FMV_ATTR_SEPARATOR '#' + #endif /* ! GCC_RISCV_H */ diff --git a/gcc/defaults.h b/gcc/defaults.h index ac2d25852ab..f451efcb33e 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_FMV_ATTR_SEPARATOR +#define TARGET_FMV_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..5a056b44571 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_FMV_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_FMV_ATTR_SEPARATOR); + p; + p = strchr (p + 1, TARGET_FMV_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_FMV_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_FMV_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; + char separator_str[] = {TARGET_FMV_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_FMV_ATTR_SEPARATOR. */ tree attr_target = lookup_attribute ("target_clones", DECL_ATTRIBUTES (node->decl)); /* No targets specified. */