From patchwork Tue Nov 5 03:22:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangyu Chen X-Patchwork-Id: 2006602 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=qotjGrlt; 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 4XjDFd585Rz1xyD for ; Tue, 5 Nov 2024 14:23:49 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DC590385703B for ; Tue, 5 Nov 2024 03:23:47 +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 A560A385773C for ; Tue, 5 Nov 2024 03:23:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A560A385773C 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 A560A385773C 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=1730776992; cv=none; b=aoK2pp1Z9lxSqWYiGSYkKg78YIZwN99e5ESmVTX6aPnv0dA32b1OGSVDyDu7rFSV3+6U1qWAZUf3UDgkoI2AT/cR3EUdVTzo4yMw6C22wwyvfTCnAD4ZAvAg8b2hDocpZ1ReenvAq9t7PK10ZtWFf8rygMmU6+cD02Lp9KnQWYU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730776992; c=relaxed/simple; bh=jRG+OTFMY65Sumr4zKXdRLeM7CjACDaOtA6UM1Wz7Qk=; h=DKIM-Signature:Message-ID:From:To:Subject:Date:MIME-Version; b=NJek8x9DV4gqvcADyFNKm/cfjXZDbi+KhZ2mtwyMUbUby/wGN4223eVsI5K6E+xCcA2pTpe8ew7bGR+FR1VlwTVGITWggqPu3BSgrqEwtC9x9t6o4pHE4ZU/xaXTdmvvrXzzuqBd/8Yg3zY2egcr9QFCkK0x/tTXPpfrvH7qk5U= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1730776981; bh=tJ6vX/pFyWR3gNZvmdOT74H2+MPV8rdjxOSueigB4kU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=qotjGrltuYXJlYuvYrDfEDFdUCclbJJnX4FB/h5HvVwr0avH/8A0BuyEmIQM3dLOw yi7gaXHcVq776qsKz5vq3+KWwpNfshKzjnvNVzpve+PDmKPqR1MP6bGWcsJ7uaiIkZ /0diXbG5qvXQSTcpa0QNf1MFBYw5nieLcEvSBE8E= Received: from cyy-pc.lan ([240e:379:2276:5d00:cda0:97a5:84f4:5191]) by newxmesmtplogicsvrsza36-0.qq.com (NewEsmtp) with SMTP id 5BA3D070; Tue, 05 Nov 2024 11:22:58 +0800 X-QQ-mid: xmsmtpt1730776978tbxmbblq2 Message-ID: X-QQ-XMAILINFO: ODafEzNm5Exj1TmE9R9hp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Q-XMRINFO: MPJ6Tf5t3I/ycC2BItcBVIA= From: Yangyu Chen To: gcc-patches@gcc.gnu.org Cc: Kito Cheng , Palmer Dabbelt , Jiawei , Jeff Law , Evgeny Stupachenko , Andrew Carlotti , Hank Chang , Yangyu Chen Subject: [PATCH v5 6/8] RISC-V: Implement TARGET_MANGLE_DECL_ASSEMBLER_NAME Date: Tue, 5 Nov 2024 11:22:56 +0800 X-OQ-MSGID: <20241105032256.2646087-1-cyy@cyyself.name> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org This patch implements the TARGET_MANGLE_DECL_ASSEMBLER_NAME for RISC-V. This is used to add function multiversioning suffixes to the assembler name. Signed-off-by: Yangyu Chen 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 b7eec1654d4..f47b439df38 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -12807,6 +12807,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. */ @@ -13210,6 +13246,9 @@ riscv_use_by_pieces_infrastructure_p (unsigned HOST_WIDE_INT size, #undef TARGET_OPTION_FUNCTION_VERSIONS #define TARGET_OPTION_FUNCTION_VERSIONS riscv_common_function_versions +#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"