From patchwork Wed Oct 18 15:42:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Carlotti X-Patchwork-Id: 154936 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4883350vqb; Wed, 18 Oct 2023 08:43:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGXV+gikVBML/p95b39yjpkrdrZ0uK8n7hsUigXf163aw1zjfhLJbglwfsVOt2S8fhtmAEy X-Received: by 2002:a05:6808:2a6f:b0:3a3:95f9:c99b with SMTP id fu15-20020a0568082a6f00b003a395f9c99bmr5161728oib.35.1697643796839; Wed, 18 Oct 2023 08:43:16 -0700 (PDT) Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id u9-20020a05620a430900b007771d46fd48si87978qko.768.2023.10.18.08.43.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 08:43:16 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b="for+ff/8"; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b="for+ff/8"; arc=fail (previous hop failed); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 91C753858024 for ; Wed, 18 Oct 2023 15:43:16 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2079.outbound.protection.outlook.com [40.107.21.79]) by sourceware.org (Postfix) with ESMTPS id 4E4463858C52 for ; Wed, 18 Oct 2023 15:42:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4E4463858C52 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4E4463858C52 Authentication-Results: server2.sourceware.org; arc=fail smtp.remote-ip=40.107.21.79 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1697643771; cv=fail; b=cbycWuffxmdvEcbvut0/nJJEoN+FVOrJgHnC8+v5cDg48EXdio7BCEPUvVRnhrNg8Zk/FvYBK3qLBptqkENd5b5iiIeivnMG4abBIMCED9Y5PXBdeW4YFctx3dr7zNV+V1ZepzF9fU91nJoJOVKeYjg4Pj7TthQOcO0xRJm3Fqw= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1697643771; c=relaxed/simple; bh=5z4sPrAm29abdN96KGFGWSesbfI4mVyV1EyqOpJTvfg=; h=DKIM-Signature:DKIM-Signature:Date:From:To:Subject:Message-ID: MIME-Version; b=c0Rxd/SKmg3/ZsySxvYjWYMozeG/VuHjMGhAKijpV/2OyjserSrjyCwd8cyOV7aFdXS9F2SwFObI4NaxYBHoOLAdnbA+3qzBizTgeQTeL342moguSbLLyC3iWY2agwwF2E4bm6oSAukx7pdz4Eh26pHE9N/zGBFne0gBRv1N1fs= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/kfGncVLTnt37qRLkbwZdBKnrdGiKmrumBhqm8X3ZgU=; b=for+ff/8TzzV90QzYyj3m/OYdkl9Iq8K1KoB9eQhPjZwMlS511CLKigg9yxnUKK+H7+f9bQLB+e05xf0E1y17tE6oHPXdpz6KoEUEqH1/Y8vZ8S1aClcvLKtJFK4uhy8WSLlWwqyhuxQTxcidw2VY/8BsxGH7UPux26Y/b137uI= Received: from AS4P195CA0011.EURP195.PROD.OUTLOOK.COM (2603:10a6:20b:5e2::15) by PAXPR08MB6511.eurprd08.prod.outlook.com (2603:10a6:102:12d::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.34; Wed, 18 Oct 2023 15:42:45 +0000 Received: from AM4PEPF00025F98.EURPRD83.prod.outlook.com (2603:10a6:20b:5e2:cafe::b0) by AS4P195CA0011.outlook.office365.com (2603:10a6:20b:5e2::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.21 via Frontend Transport; Wed, 18 Oct 2023 15:42:45 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM4PEPF00025F98.mail.protection.outlook.com (10.167.16.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.4 via Frontend Transport; Wed, 18 Oct 2023 15:42:45 +0000 Received: ("Tessian outbound 028b72acc2da:v215"); Wed, 18 Oct 2023 15:42:45 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: fc57c022725a83d1 X-CR-MTA-TID: 64aa7808 Received: from a84b1a920ab3.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 4D546082-E81A-401B-85F6-64775A13BBEB.1; Wed, 18 Oct 2023 15:42:39 +0000 Received: from EUR05-DB8-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id a84b1a920ab3.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 18 Oct 2023 15:42:39 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cF6vyXO6kStErWKTu0BSclqiI23M04BGrEBQKvDHOmThZJ4IwaAXk8JT1NkyIf8R5LlYWc4Bte4VO4x/jRFJfQtmsW2qYHXoiC7TqCMgdbB+GJl7Qex+txhywy6zb39Ar3T+OYwfoM4tGuqXlgSPk4pd4ZwVxtIUzxFBHvSrNUsLwOx1t3VsW8wlhyRIJRFu8saJ62gKqd/tNp+o7X+lNiY/q+iKk9hTDDwRRbjgKjA2PaPv7bpBr3Y4PCL/C8XvyvWu9UL9J5SbGNJzYA892it6PhGNJdJxtS4yUw9+AoEfNoQMVHHqKx/aajxo0GHWWqnAlCHBKDiz41juh6bzcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=/kfGncVLTnt37qRLkbwZdBKnrdGiKmrumBhqm8X3ZgU=; b=a5mjHHmjszLQbhTn0UJpShoNyesdbvPizuXN9WT85XNfMC6kOFcNrhuQVSK7Ib1yfF27qsH4ptL5z4raz3FF1bdGRlZCQfsIysUhGfizu242BPaDBVkqyKASVgq0QrYf1sig7DsBami9nNvryHF9DvMj3/hJeV4RVblgYuTQuxZgmWD2BF5w6pFCVpco0I7m8DR5QAMLA0oayaggXxOIyLVwjxvLCKfr064VcqYGrw+k0iYhjFb0WHeP+bFFESNKbcObS0+/1oo5amK4z52xmncTLVHipPc3JqsdbSLwhmaPji13Lj9EbbT4g1DYQNW8JMV9DTsqDr1V+QbrYx7Jhg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/kfGncVLTnt37qRLkbwZdBKnrdGiKmrumBhqm8X3ZgU=; b=for+ff/8TzzV90QzYyj3m/OYdkl9Iq8K1KoB9eQhPjZwMlS511CLKigg9yxnUKK+H7+f9bQLB+e05xf0E1y17tE6oHPXdpz6KoEUEqH1/Y8vZ8S1aClcvLKtJFK4uhy8WSLlWwqyhuxQTxcidw2VY/8BsxGH7UPux26Y/b137uI= Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from AS8PR08MB6678.eurprd08.prod.outlook.com (2603:10a6:20b:398::8) by AS2PR08MB8927.eurprd08.prod.outlook.com (2603:10a6:20b:5fa::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.36; Wed, 18 Oct 2023 15:42:37 +0000 Received: from AS8PR08MB6678.eurprd08.prod.outlook.com ([fe80::3880:6a2c:60e:3f3e]) by AS8PR08MB6678.eurprd08.prod.outlook.com ([fe80::3880:6a2c:60e:3f3e%7]) with mapi id 15.20.6886.034; Wed, 18 Oct 2023 15:42:37 +0000 Date: Wed, 18 Oct 2023 16:42:36 +0100 From: Andrew Carlotti To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, nathan@acm.org, rguenther@suse.de, richard.sandiford@arm.com Subject: [1/3] Add support for target_version attribute Message-ID: <2a9e5b6e-9720-602b-5449-28fb5d88a40c@e124511.cambridge.arm.com> References: <26bbc7e4-9d5a-fef3-2f78-1b7a03865050@e124511.cambridge.arm.com> Content-Disposition: inline In-Reply-To: <26bbc7e4-9d5a-fef3-2f78-1b7a03865050@e124511.cambridge.arm.com> X-ClientProxiedBy: LO2P123CA0076.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:138::9) To AS8PR08MB6678.eurprd08.prod.outlook.com (2603:10a6:20b:398::8) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: AS8PR08MB6678:EE_|AS2PR08MB8927:EE_|AM4PEPF00025F98:EE_|PAXPR08MB6511:EE_ X-MS-Office365-Filtering-Correlation-Id: 1f4776f9-a62f-4eb6-5780-08dbcff0dfd9 x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: bv8bLzbCk1Sby/zBQekOKp38QfFY5MX1RI/rK8e0QXVwn3kVDf0sihhO6+DoPYc6LX4WL4xMKsU+2TSQOVKJ3ptSg+aokEYsaTy7H8jHNMPn+aOOX9x8yadUq0UZU1kx0KQMyHdRrslNrCtIpgGw1x5vsJqivDanzRY2kojmMUuvLr6AjAmpoRqAO4TbYemSYwwpIwJ9T/GepQnovY7cNpZLkBoOmuzAY+D2lqh2/2jYdHECl9GmbqWzYyzicM4AjCRSs6vNMA9FkI2Ut4IvVHh647we9Njsy7j6vr+5IMU5d+2Ihh3ck2yHf3wLcoKQ73PTWo44ShXfytoj6nSVGiBfTPCaV+ezmiUt6EKZ47ZR6nfEnW6fiqPyaOuu87kJulB4ns1TXgjsuyRY5uFPv9cs2zeekJ/l2DbO6/CCplEu7V4IwbSLR5eKjs0TUn45CXEb3Ph/TlnoCPbzzRXPH41sUiFMuqVW3K2h/+gFUMzOG8ix+hagR0D77taXJHA5dHcQkabPGlFgLHVF5WstG7nUCak4KyRU69dY3G0ehykAxk+0gV29owQpzkDMGqFh X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR08MB6678.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(346002)(376002)(396003)(366004)(39860400002)(136003)(230922051799003)(1800799009)(451199024)(64100799003)(186009)(8676002)(4326008)(30864003)(8936002)(38100700002)(44832011)(41300700001)(5660300002)(86362001)(31696002)(2906002)(6506007)(6512007)(478600001)(6486002)(26005)(83380400001)(31686004)(66556008)(66946007)(6916009)(66476007)(316002); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS2PR08MB8927 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM4PEPF00025F98.EURPRD83.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 32cccb9d-dc96-4e37-2048-08dbcff0dada X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zrU4JZeYOfXJgVqQtwpQkEwN1fYJCP9DqJCe/DFXQwTrOy/MKYvNWrvVYutGZl8qZ0GeGXEHO9c6qXDV9Cji+j1/pQRxcJhoWFF0z4AMts8FwVpRYKS0bT4PuasO2BlLql/EZrn670AztcGfUn4T1FfvKGB4hYXQdq52E2QKHHW2IEeitvGt2Jg8J5i0nECjh4hWrmVdx1u6D+/UTwGsFd1AIq9z73JDycFvtiORg+1QitgzJRL38QTJYY7itYdA14vPtMnOdJ4bl7cXs6jeKkpvbfSlNFwIzDRD3EoRDeTOvmnOGFqDTmB09oVO4DK1Sh5517l8AJ1cXh0b3riNZm5QmDwQ/1bu08fzAgNbL42lmBp23Rp2LfSgEBQqav6lR0pWTmPxo3x78t0m3g5X3tgxlrQTF8h+5Aske1BVbR+G3+88f89xpfecdCQ/fsv6uKwge8TXG/dF5M1FHUBrfU9uWIGB9Xi0H1Qly9hPg3iKVWDnQYKdkcITbTKLSQP/maM+L+tNDNx+kFK1UhWhCjs9v/++oJhn0JwHzM3ZBjO6JUXd/rNVil8C7toxsKN4z3VH+gnDwmRJoYsJ6xKHAKVFujOewl5HJN0VgI4dEPTgbbD6sfYw7TRj0f1Fwy4NePKvcQNcB0f4h0sHu+tvMRs9ryI7OpZ6dAST97Nk9JBJgoKNOdsDvzpT2X2rEbP1gffCYMd3anncDeJPbjp1Lu0xKVhS/plWD04Vfwy+2H3eqc7wCNTDAYbY2H68l7WM X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(13230031)(4636009)(136003)(39860400002)(346002)(376002)(396003)(230922051799003)(1800799009)(186009)(82310400011)(64100799003)(451199024)(46966006)(40470700004)(36840700001)(2906002)(30864003)(40460700003)(41300700001)(70586007)(70206006)(47076005)(86362001)(478600001)(36860700001)(316002)(81166007)(6506007)(356005)(6486002)(6512007)(31696002)(83380400001)(6916009)(82740400003)(44832011)(40480700001)(5660300002)(26005)(336012)(8936002)(8676002)(31686004)(4326008); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Oct 2023 15:42:45.6939 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1f4776f9-a62f-4eb6-5780-08dbcff0dfd9 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM4PEPF00025F98.EURPRD83.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR08MB6511 X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_NONE, KAM_LOTSOFHASH, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP, UNPARSEABLE_RELAY 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780108541570345765 X-GMAIL-MSGID: 1780108541570345765 This patch adds support for the "target_version" attribute to the middle end and the C++ frontend, which will be used to implement function multiversioning in the aarch64 backend. Note that C++ is currently the only frontend which supports multiversioning using the "target" attribute, whereas the "target_clones" attribute is additionally supported in C, D and Ada. Support for the target_version attribute will be extended to C at a later date. Targets that currently use the "target" attribute for function multiversioning (i.e. i386 and rs6000) are not affected by this patch. I could have implemented the target hooks slightly differently, by reusing the valid_attribute_p hook and adding attribute name checks to each backend implementation (c.f. the aarch64 implementation in patch 2/3). Would this be preferable? Otherwise, is this ok for master? gcc/c-family/ChangeLog: * c-attribs.cc (handle_target_version_attribute): New. (c_common_attribute_table): Add target_version. (handle_target_clones_attribute): Add conflict with target_version attribute. gcc/ChangeLog: * attribs.cc (is_function_default_version): Update comment to specify incompatibility with target_version attributes. * cgraphclones.cc (cgraph_node::create_version_clone_with_body): Call valid_version_attribute_p for target_version attributes. * target.def (valid_version_attribute_p): New hook. (expanded_clones_attribute): New hook. * doc/tm.texi.in: Add new hooks. * doc/tm.texi: Regenerate. * multiple_target.cc (create_dispatcher_calls): Remove redundant is_function_default_version check. (expand_target_clones): Use target hook for attribute name. * targhooks.cc (default_target_option_valid_version_attribute_p): New. * targhooks.h (default_target_option_valid_version_attribute_p): New. * tree.h (DECL_FUNCTION_VERSIONED): Update comment to include target_version attributes. gcc/cp/ChangeLog: * decl2.cc (check_classfn): Update comment to include target_version attributes. diff --git a/gcc/attribs.cc b/gcc/attribs.cc index b1300018d1e8ed8e02ded1ea721dc192a6d32a49..a3c4a81e8582ea4fd06b9518bf51fad7c998ddd6 100644 --- a/gcc/attribs.cc +++ b/gcc/attribs.cc @@ -1233,8 +1233,9 @@ make_dispatcher_decl (const tree decl) return func_decl; } -/* Returns true if decl is multi-versioned and DECL is the default function, - that is it is not tagged with target specific optimization. */ +/* Returns true if DECL is multi-versioned using the target attribute, and this + is the default version. This function can only be used for targets that do + not support the "target_version" attribute. */ bool is_function_default_version (const tree decl) diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc index 072cfb69147bd6b314459c0bd48a0c1fb92d3e4d..1a224c036277d51ab4dc0d33a403177bd226e48a 100644 --- a/gcc/c-family/c-attribs.cc +++ b/gcc/c-family/c-attribs.cc @@ -148,6 +148,7 @@ static tree handle_alloc_align_attribute (tree *, tree, tree, int, bool *); static tree handle_assume_aligned_attribute (tree *, tree, tree, int, bool *); static tree handle_assume_attribute (tree *, tree, tree, int, bool *); static tree handle_target_attribute (tree *, tree, tree, int, bool *); +static tree handle_target_version_attribute (tree *, tree, tree, int, bool *); static tree handle_target_clones_attribute (tree *, tree, tree, int, bool *); static tree handle_optimize_attribute (tree *, tree, tree, int, bool *); static tree ignore_attribute (tree *, tree, tree, int, bool *); @@ -480,6 +481,8 @@ const struct attribute_spec c_common_attribute_table[] = handle_error_attribute, NULL }, { "target", 1, -1, true, false, false, false, handle_target_attribute, NULL }, + { "target_version", 1, -1, true, false, false, false, + handle_target_version_attribute, NULL }, { "target_clones", 1, -1, true, false, false, false, handle_target_clones_attribute, NULL }, { "optimize", 1, -1, true, false, false, false, @@ -5569,6 +5572,45 @@ handle_target_attribute (tree *node, tree name, tree args, int flags, return NULL_TREE; } +/* Handle a "target_version" attribute. */ + +static tree +handle_target_version_attribute (tree *node, tree name, tree args, int flags, + bool *no_add_attrs) +{ + /* Ensure we have a function type. */ + if (TREE_CODE (*node) != FUNCTION_DECL) + { + warning (OPT_Wattributes, "%qE attribute ignored", name); + *no_add_attrs = true; + } + else if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (*node))) + { + warning (OPT_Wattributes, "%qE attribute ignored due to conflict " + "with %qs attribute", name, "target_clones"); + *no_add_attrs = true; + } + else if (!targetm.target_option.valid_version_attribute_p (*node, name, args, + flags)) + *no_add_attrs = true; + + /* Check that there's no empty string in values of the attribute. */ + for (tree t = args; t != NULL_TREE; t = TREE_CHAIN (t)) + { + tree value = TREE_VALUE (t); + if (TREE_CODE (value) == STRING_CST + && TREE_STRING_LENGTH (value) == 1 + && TREE_STRING_POINTER (value)[0] == '\0') + { + warning (OPT_Wattributes, + "empty string in attribute %"); + *no_add_attrs = true; + } + } + + return NULL_TREE; +} + /* Handle a "target_clones" attribute. */ static tree @@ -5601,6 +5643,12 @@ handle_target_clones_attribute (tree *node, tree name, tree ARG_UNUSED (args), "with %qs attribute", name, "target"); *no_add_attrs = true; } + else if (lookup_attribute ("target_version", DECL_ATTRIBUTES (*node))) + { + warning (OPT_Wattributes, "%qE attribute ignored due to conflict " + "with %qs attribute", name, "target_version"); + *no_add_attrs = true; + } else if (get_target_clone_attr_len (args) == -1) { warning (OPT_Wattributes, diff --git a/gcc/cgraphclones.cc b/gcc/cgraphclones.cc index 29d28ef895a73a223695cbb86aafbc845bbe7688..8af6b23d8c0306920e0fdcb3559ef047a16689f4 100644 --- a/gcc/cgraphclones.cc +++ b/gcc/cgraphclones.cc @@ -78,6 +78,7 @@ along with GCC; see the file COPYING3. If not see #include "tree-eh.h" #include "tree-cfg.h" #include "tree-inline.h" +#include "attribs.h" #include "dumpfile.h" #include "gimple-pretty-print.h" #include "alloc-pool.h" @@ -1048,7 +1049,17 @@ cgraph_node::create_version_clone_with_body location_t saved_loc = input_location; tree v = TREE_VALUE (target_attributes); input_location = DECL_SOURCE_LOCATION (new_decl); - bool r = targetm.target_option.valid_attribute_p (new_decl, NULL, v, 1); + bool r; + tree name_id = get_attribute_name (target_attributes); + const char* name_str = IDENTIFIER_POINTER (name_id); + if (strcmp (name_str, "target") == 0) + r = targetm.target_option.valid_attribute_p (new_decl, name_id, v, 1); + else if (strcmp (name_str, "target_version") == 0) + r = targetm.target_option.valid_version_attribute_p (new_decl, name_id, + v, 1); + else + gcc_assert(false); + input_location = saved_loc; if (!r) return NULL; diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc index 9594be4092c3c00fddc9d4c6da5931ea3b7e8792..ec78d5a5440bedd360ac8e5bc44e164da3dab410 100644 --- a/gcc/cp/decl2.cc +++ b/gcc/cp/decl2.cc @@ -829,8 +829,8 @@ check_classfn (tree ctype, tree function, tree template_parms) tree c2 = get_constraints (fndecl); /* While finding a match, same types and params are not enough - if the function is versioned. Also check version ("target") - attributes. */ + if the function is versioned. Also check for different target + specific attributes. */ if (same_type_p (TREE_TYPE (TREE_TYPE (function)), TREE_TYPE (TREE_TYPE (fndecl))) && compparms (p1, p2) diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index 33e7ffc8af5a9d48430145ef9b8e7924613b7dd7..97b3e9c31631a943d95f1cf7739716a574afcfb7 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -10507,6 +10507,23 @@ the function declaration to hold a pointer to a target-specific @code{struct cl_target_option} structure. @end deftypefn +@deftypefn {Target Hook} bool TARGET_OPTION_VALID_VERSION_ATTRIBUTE_P (tree @var{fndecl}, tree @var{name}, tree @var{args}, int @var{flags}) +This hook is called to parse @code{attribute(target_version("..."))}, +which allows setting target-specific options on individual function versions. +These function-specific options may differ +from the options specified on the command line. The hook should return +@code{true} if the options are valid. + +The hook should set the @code{DECL_FUNCTION_SPECIFIC_TARGET} field in +the function declaration to hold a pointer to a target-specific +@code{struct cl_target_option} structure. +@end deftypefn + +@deftypevr {Target Hook} {const char *} TARGET_OPTION_EXPANDED_CLONES_ATTRIBUTE +Contains the name of the attribute used for the version description string +when expanding clones for a function with the target_clones attribute. +@end deftypevr + @deftypefn {Target Hook} void TARGET_OPTION_SAVE (struct cl_target_option *@var{ptr}, struct gcc_options *@var{opts}, struct gcc_options *@var{opts_set}) This hook is called to save any additional target-specific information in the @code{struct cl_target_option} structure for function-specific diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in index c98b2447e28aa17996b1cbf8af7ed02d70db54f2..56fa3de6bba06bc0ac124bb3a41324be1997e209 100644 --- a/gcc/doc/tm.texi.in +++ b/gcc/doc/tm.texi.in @@ -6979,6 +6979,10 @@ on this implementation detail. @hook TARGET_OPTION_VALID_ATTRIBUTE_P +@hook TARGET_OPTION_VALID_VERSION_ATTRIBUTE_P + +@hook TARGET_OPTION_EXPANDED_CLONES_ATTRIBUTE + @hook TARGET_OPTION_SAVE @hook TARGET_OPTION_RESTORE diff --git a/gcc/multiple_target.cc b/gcc/multiple_target.cc index a2ed048d7dd28ec470953fcd8a0dc86817e4b7dc..3db57c2b13d612a37240d9dcf58ad21b2286633c 100644 --- a/gcc/multiple_target.cc +++ b/gcc/multiple_target.cc @@ -66,10 +66,6 @@ create_dispatcher_calls (struct cgraph_node *node) { ipa_ref *ref; - if (!DECL_FUNCTION_VERSIONED (node->decl) - || !is_function_default_version (node->decl)) - return; - if (!targetm.has_ifunc_p ()) { error_at (DECL_SOURCE_LOCATION (node->decl), @@ -377,6 +373,7 @@ expand_target_clones (struct cgraph_node *node, bool definition) return false; } + const char *new_attr_name = targetm.target_option.expanded_clones_attribute; cgraph_function_version_info *decl1_v = NULL; cgraph_function_version_info *decl2_v = NULL; cgraph_function_version_info *before = NULL; @@ -392,7 +389,7 @@ expand_target_clones (struct cgraph_node *node, bool definition) char *attr = attrs[i]; /* Create new target clone. */ - tree attributes = make_attribute ("target", attr, + tree attributes = make_attribute (new_attr_name, attr, DECL_ATTRIBUTES (node->decl)); char *suffix = XNEWVEC (char, strlen (attr) + 1); @@ -430,7 +427,7 @@ expand_target_clones (struct cgraph_node *node, bool definition) XDELETEVEC (attr_str); /* Setting new attribute to initial function. */ - tree attributes = make_attribute ("target", "default", + tree attributes = make_attribute (new_attr_name, "default", DECL_ATTRIBUTES (node->decl)); DECL_ATTRIBUTES (node->decl) = attributes; node->local = false; diff --git a/gcc/target.def b/gcc/target.def index cda6c51e5167f85625168c7c26b777d6c8ccad82..39acea04db01ebaf918910b7dd73d397de6a84ec 100644 --- a/gcc/target.def +++ b/gcc/target.def @@ -6492,6 +6492,31 @@ the function declaration to hold a pointer to a target-specific\n\ bool, (tree fndecl, tree name, tree args, int flags), default_target_option_valid_attribute_p) +/* Function to validate the attribute((target_version(...))) strings. If + the option is validated, the hook should also fill in + DECL_FUNCTION_SPECIFIC_TARGET in the function decl node. */ +DEFHOOK +(valid_version_attribute_p, + "This hook is called to parse @code{attribute(target_version(\"...\"))},\n\ +which allows setting target-specific options on individual function versions.\n\ +These function-specific options may differ\n\ +from the options specified on the command line. The hook should return\n\ +@code{true} if the options are valid.\n\ +\n\ +The hook should set the @code{DECL_FUNCTION_SPECIFIC_TARGET} field in\n\ +the function declaration to hold a pointer to a target-specific\n\ +@code{struct cl_target_option} structure.", + bool, (tree fndecl, tree name, tree args, int flags), + default_target_option_valid_version_attribute_p) + +/* Attribute to be used when expanding clones for functions with + target_clones attribute. */ +DEFHOOKPOD +(expanded_clones_attribute, + "Contains the name of the attribute used for the version description string\n\ +when expanding clones for a function with the target_clones attribute.", + const char *, "target") + /* Function to save any extra target state in the target options structure. */ DEFHOOK (save, diff --git a/gcc/targhooks.h b/gcc/targhooks.h index 1a0db8dddd594d9b1fb04ae0d9a66ad6b7a396dc..0efc993d82ef59b581a1df74ee0de71135a28703 100644 --- a/gcc/targhooks.h +++ b/gcc/targhooks.h @@ -192,6 +192,7 @@ extern bool default_hard_regno_scratch_ok (unsigned int); extern bool default_mode_dependent_address_p (const_rtx, addr_space_t); extern bool default_new_address_profitable_p (rtx, rtx_insn *, rtx); extern bool default_target_option_valid_attribute_p (tree, tree, tree, int); +extern bool default_target_option_valid_version_attribute_p (tree, tree, tree, int); extern bool default_target_option_pragma_parse (tree, tree); extern bool default_target_can_inline_p (tree, tree); extern bool default_update_ipa_fn_target_info (unsigned int &, const gimple *); diff --git a/gcc/targhooks.cc b/gcc/targhooks.cc index e190369f87a92e6a92372dc348d9374c3a965c0a..7fc7bf455e80c333cced1bac7085210c2b108f8d 100644 --- a/gcc/targhooks.cc +++ b/gcc/targhooks.cc @@ -1787,7 +1787,19 @@ default_target_option_valid_attribute_p (tree ARG_UNUSED (fndecl), int ARG_UNUSED (flags)) { warning (OPT_Wattributes, - "target attribute is not supported on this machine"); + "% attribute is not supported on this machine"); + + return false; +} + +bool +default_target_option_valid_version_attribute_p (tree ARG_UNUSED (fndecl), + tree ARG_UNUSED (name), + tree ARG_UNUSED (args), + int ARG_UNUSED (flags)) +{ + warning (OPT_Wattributes, + "% attribute is not supported on this machine"); return false; } diff --git a/gcc/tree.h b/gcc/tree.h index 0b72663e6a1a94406127f6253460f498b7a3ea9c..ebd89ce79566c350eaaab210c0dca3cc1ac2048e 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -3438,8 +3438,8 @@ extern vec **decl_debug_args_insert (tree); (FUNCTION_DECL_CHECK (NODE)->function_decl.function_specific_optimization) /* In FUNCTION_DECL, this is set if this function has other versions generated - using "target" attributes. The default version is the one which does not - have any "target" attribute set. */ + to support different architecture feature sets, e.g. using "target" or + "target_version" attributes. */ #define DECL_FUNCTION_VERSIONED(NODE)\ (FUNCTION_DECL_CHECK (NODE)->function_decl.versioned_function) From patchwork Wed Oct 18 15:44:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Carlotti X-Patchwork-Id: 154937 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4884404vqb; Wed, 18 Oct 2023 08:45:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEEsyvIWkXxo9lUleGm/YhkdrGcJk9082Ca84RSZxd1lfSThKzqeEYakdcEMC4U2VDanQoI X-Received: by 2002:ac8:4e83:0:b0:417:953c:ff57 with SMTP id 3-20020ac84e83000000b00417953cff57mr7629698qtp.14.1697643900520; Wed, 18 Oct 2023 08:45:00 -0700 (PDT) Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id n13-20020ac85a0d000000b003eb14b07a6dsi104499qta.125.2023.10.18.08.45.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 08:45:00 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b="i6vP8/JN"; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b="i6vP8/JN"; arc=fail (previous hop failed); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E9EC738582A1 for ; Wed, 18 Oct 2023 15:44:59 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2076.outbound.protection.outlook.com [40.107.22.76]) by sourceware.org (Postfix) with ESMTPS id BC0F43858C30 for ; Wed, 18 Oct 2023 15:44:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BC0F43858C30 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BC0F43858C30 Authentication-Results: server2.sourceware.org; arc=fail smtp.remote-ip=40.107.22.76 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1697643871; cv=fail; b=rQYLOeybfytLhzETbxCSUC79VwxG6IdexW+kPpxrSSoTrPyTO+Sw/V1yeHOMUvpOxSxrJFRFHYbjpzkpx/nOGsDVA9aFHU2VGhufniLSzFE+zC2QSMGbXDuwy74TbP71GFlTd/slpEyTjoDHXummXF1DekT+tTM0QKWS/Ahgli0= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1697643871; c=relaxed/simple; bh=09M1XeWlmEyyws1/9hHVSolRtfDomehU2wNL2wLxxUM=; h=DKIM-Signature:DKIM-Signature:Date:From:To:Subject:Message-ID: MIME-Version; b=jeeYfVvpq9maGGb6gBzzfQtzKctVWbN04cOTmEPdyEi7fPDo9elVvCU78e9TcKlYKpyJIwPJPZQxJKdN9ogRi28Ab0lfkQsySo8Sc9bIfjL9do+oDqfYczO970z0wH9CVSIhlWji6xpA7HKoDFPkseh2nsLMPHRrZVat6873H7Q= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cwPfC1BqvQ3HVitZ4OVHcUuu1ZzUyYsnYs6u2ObZWAE=; b=i6vP8/JNz5rPisBNXRUA2GfMjyFpUMEPBX8Dp8D9/pa98n7DWbPNhCTOlTQEjE+hQGLw6zZcm5RWO+cb2T0um71mzCFfhZnzXIFBFoWjwhwaZir3bLhF63d9Ms3m0MClnDI30sKsxl75gLF+rYL9bOFeWTaMlAjnU4/atyZelmA= Received: from AS4PR10CA0020.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:5d8::10) by PA6PR08MB10782.eurprd08.prod.outlook.com (2603:10a6:102:3d0::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.21; Wed, 18 Oct 2023 15:44:23 +0000 Received: from AM4PEPF00025F9A.EURPRD83.prod.outlook.com (2603:10a6:20b:5d8:cafe::e9) by AS4PR10CA0020.outlook.office365.com (2603:10a6:20b:5d8::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.23 via Frontend Transport; Wed, 18 Oct 2023 15:44:23 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM4PEPF00025F9A.mail.protection.outlook.com (10.167.16.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.4 via Frontend Transport; Wed, 18 Oct 2023 15:44:23 +0000 Received: ("Tessian outbound 80b6fe5915e6:v215"); Wed, 18 Oct 2023 15:44:22 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 6e5a393f5bbd145c X-CR-MTA-TID: 64aa7808 Received: from 9b4f0fb783b9.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 43476DCB-B6BF-4A41-995C-5EF6CC0C83E1.1; Wed, 18 Oct 2023 15:44:11 +0000 Received: from EUR01-VE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 9b4f0fb783b9.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 18 Oct 2023 15:44:11 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=alChxhZbEExafpzzwdTqnDzBCih7g1bXlWvsAmoKk8mSBq088FvKKSr6aI7KgVwyDYcDTn444gz898CEkmurmt05hCZyD7Z9XIeF86w0zSRu92qvWz/2TWA++Chp265cmo030C2K5KkJo8k1P9JeCX47Kg8tg1ry7zxVZJ/DZQzyMoQFdZL9h5TBRpQdqGAdDv2s7vvHqpG06VFo7J46Chx5hvDK4m3TTEGrzRmnt+xhk1GlpMtcDXo8e0+cJYs6yg0IVZq89Xuxy2PxLJ48zSNxKwcFF/YQnhU2/XsFAMdzy/9Oeoeej8ve/+3Fvv6b9YypiugucvvJNVINB0NawQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=cwPfC1BqvQ3HVitZ4OVHcUuu1ZzUyYsnYs6u2ObZWAE=; b=kB9WG+f8y/oCI9iI1jFbcKEYlEmw/umTYiNfkY5Z0hWA8VBBeH0b7o0Z3BgwGUiSIsMe+p4YrDCr3SvIfbJiD6L0S9a9QjtwxliAD79psQR419+daFIEXcZtGvphFdkXuTyQdQwAKXRiRBC3n+L8FgDKfBKfUCHjN19eR1lQ+QLpRFP7iDDLnPRlKBdLAp3KIOy9A7Ow+BkUhnBWfpT9t2E10pvHjTfpdc8/Hh8Ajk8Ds/x+7kMsu3UXvNunwN4ebLqT4LWOqEV6Zz0a/Zg7ID3UPEDLJ2hDTJhHFu5DRXjTIEt4QytdhM3xefB+1n4ItfvJK1EyjUYsn7gRGjn9+A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cwPfC1BqvQ3HVitZ4OVHcUuu1ZzUyYsnYs6u2ObZWAE=; b=i6vP8/JNz5rPisBNXRUA2GfMjyFpUMEPBX8Dp8D9/pa98n7DWbPNhCTOlTQEjE+hQGLw6zZcm5RWO+cb2T0um71mzCFfhZnzXIFBFoWjwhwaZir3bLhF63d9Ms3m0MClnDI30sKsxl75gLF+rYL9bOFeWTaMlAjnU4/atyZelmA= Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from AS8PR08MB6678.eurprd08.prod.outlook.com (2603:10a6:20b:398::8) by AS8PR08MB9120.eurprd08.prod.outlook.com (2603:10a6:20b:5c1::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.36; Wed, 18 Oct 2023 15:44:09 +0000 Received: from AS8PR08MB6678.eurprd08.prod.outlook.com ([fe80::3880:6a2c:60e:3f3e]) by AS8PR08MB6678.eurprd08.prod.outlook.com ([fe80::3880:6a2c:60e:3f3e%7]) with mapi id 15.20.6886.034; Wed, 18 Oct 2023 15:44:09 +0000 Date: Wed, 18 Oct 2023 16:44:08 +0100 From: Andrew Carlotti To: gcc-patches@gcc.gnu.org Cc: richard.earnshaw@arm.com, richard.sandiford@arm.com Subject: [2/3] [aarch64] Add function multiversioning support Message-ID: <3ab87b1b-04c8-bf92-f678-9b7a58611f1a@e124511.cambridge.arm.com> References: <26bbc7e4-9d5a-fef3-2f78-1b7a03865050@e124511.cambridge.arm.com> Content-Disposition: inline In-Reply-To: <26bbc7e4-9d5a-fef3-2f78-1b7a03865050@e124511.cambridge.arm.com> X-ClientProxiedBy: LO2P265CA0030.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:61::18) To AS8PR08MB6678.eurprd08.prod.outlook.com (2603:10a6:20b:398::8) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: AS8PR08MB6678:EE_|AS8PR08MB9120:EE_|AM4PEPF00025F9A:EE_|PA6PR08MB10782:EE_ X-MS-Office365-Filtering-Correlation-Id: 1b294e3f-5983-4076-04e3-08dbcff119ec x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: cMCZ90jxKF3ADuJnB59YE5ifsQFe0t0QI9XI+uJLHPzcIruyUsdVR3bNqBuKgEzbHHoRqOTBIGfCLfe7r6p4vIZX4dynBXIgKbRp5KlMFWMEMInUKWmWips+bPVN7ARg40B+v3q3RL049Y95FOrESrpmn9eGrbhreSu/tTtM6eNW41h/Kzm/JNjiLsGn3i+RvAVyvMPcWf+Rvw3LKpB+gxgLmaarTuXD+lq3apvnTnyu5wWaXyInd59Uy/euig+8G7TEZ2h2SnYFb/HwFWk9d1wsjhJjwkluhxmQeCcBFzcMNiT/5uSAIgvPf0VXMZcCWBiRqj967MybZDyDz6bIfMh7t/nBrGIlQLLsWnta2ScFICabceZsIBP64JhQfVTA4BC8QaxH7GdiJF3yVuMODP8bcZb5rM2lPquZvmw0DqtYlf17xTm2DfCUYfePGewGPOen31bcGPDaUeNGpuM468g+Oyz0jJ2mw9ZbMM9QUf5Wihy7O0RCUuAraqHFqbimh4DxIk4rDC5YM5YFvgf6nMHPs4WiJq5EPXejtom5rcU= X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR08MB6678.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(396003)(39860400002)(366004)(136003)(346002)(376002)(230922051799003)(1800799009)(451199024)(186009)(64100799003)(26005)(6506007)(8936002)(966005)(83380400001)(66946007)(5660300002)(44832011)(41300700001)(8676002)(30864003)(478600001)(2906002)(6486002)(4326008)(316002)(6916009)(66556008)(66476007)(86362001)(31696002)(38100700002)(31686004)(6512007); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB9120 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM4PEPF00025F9A.EURPRD83.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: a2893e36-ee02-4165-b85d-08dbcff11169 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NrVWr8stDisXPXK8HTfhBVn6+i2Hx0S3Fx9dv1YKkBzMnGlA9WKOkTML5RvCRRRtwadrQn3BJJMyWd6NEsfuBu+o65pLUJnx1fOndXMdMeiF0snPO3YfD57JXWoNhsI8rano0WlHaw50oPvS524Xd55O9ml52CpS9g84h56f8nEdYlFv/M2c4QF4rScZos4GRsvIw6zlACAtrMAq/+QhmrczypVPzcujerBsKmJl/uyz3oOINBCm+/7hyG6NWl6CwILTOTwzta3QWeUX6S2eIqfHCFqd3ZuR1vfEEAh1vgSk81h6aavpIEXKSbHTNkrC1j5Z2pmh91V2BXvswPEChwT1AxlT6u1jKTY788Fe3lZX0XVL7JEg6cjM+fLeuIAOz1VhjA06swXi2ag9msysAzxMMXUkxpwzYfP/UAj8Lk2C1u9fAinPyDzYXBqfO6lhy5pk79oY/1+gHd48AL5SOjv8lRL2oWOBC7yk5FKh58vC00E03fZD7YJ+XBIOmakeSWd0OHuJ+ifzupzSoV6PQX/a07ltDD1LhM7+GRVDH+0KVnLreg4sok1p07lG4JdVms0VpzHEPlxs9Qa8J5GmK0hxSV1GDYMaw7h0oxXRPX8wQjukPPPNc7r8WfbXdkkqU7FC71lIBVgVC8UoO7eWOYsQSi13CROc2jlUVkVb32cMiFahdifQoRLhoGPspdghOwZlld24IG/mKwCCx5IWaPqdD+Uy9T+vbc0foPfc1AQ= X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(13230031)(4636009)(136003)(346002)(39860400002)(376002)(396003)(230922051799003)(451199024)(64100799003)(82310400011)(186009)(1800799009)(36840700001)(46966006)(40470700004)(26005)(40460700003)(6506007)(8676002)(8936002)(966005)(336012)(47076005)(83380400001)(5660300002)(6512007)(41300700001)(44832011)(4326008)(2906002)(30864003)(6486002)(478600001)(316002)(31696002)(70206006)(6916009)(81166007)(356005)(82740400003)(70586007)(36860700001)(40480700001)(86362001)(31686004); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Oct 2023 15:44:23.1241 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1b294e3f-5983-4076-04e3-08dbcff119ec X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM4PEPF00025F9A.EURPRD83.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA6PR08MB10782 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_NONE, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP, UNPARSEABLE_RELAY 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780108650625834164 X-GMAIL-MSGID: 1780108650625834164 This adds initial support for function multiversion on aarch64 using the target_version and target_clones attributes. This mostly follows the Beta specification in the ACLE [1], with a few diffences that remain to be fixed: - Symbol mangling for target_clones differs from that for target_version and does not match the mangling specified in the ACLE. This inconsistency is also present in i386 and rs6000 mangling. - The target_clones attribute does not currently support an implicit "default" version. - Unrecognised target names in a target_clones attribute should be ignored (with an optional warning), but currently cause an error to be raised instead. - There is no option to disable function multiversioning at compile time. - There is no support for function multiversioning in C, since this is not yet enabled in the frontend. On the other hand, this patch happens to enable multiversioning in Ada and D as well, using their existing frontend support. This patch relies on adding functionality to libgcc, to support: - struct { unsigned long long features; } __aarch64_cpu_features; - void __init_cpu_features (void); - void __init_cpu_features_resolver (unsigned long hwcap, const __ifunc_arg_t *arg); This support matches the interface currently used in LLVM's compiler-rt, and will be implemented in a future patch (which will be merged before merging this patch). This version of the patch incorrectly uses __init_cpu_features in the ifunc resolvers, which could lead to invalid library calls at load time. I will fix this to use __init_cpu_features_resolver in a future version of the patch. [1] https://github.com/ARM-software/acle/blob/main/main/acle.md#function-multi-versioning gcc/ChangeLog: * attribs.cc (decl_attributes): Pass attribute name to target hook. * config/aarch64/aarch64.cc (aarch64_process_target_version_attr): New. (aarch64_option_valid_attribute_p): Add check and support for target_version attribute. (enum CPUFeatures): New list of for bitmask positions. (aarch64_fmv_feature_data): New. (get_feature_bit): New. (get_feature_mask_for_version): New. (compare_feature_masks): New. (aarch64_compare_version_priority): New. (make_resolver_func): New. (add_condition_to_bb): New. (compare_feature_version_info): New. (dispatch_function_versions): New. (aarch64_generate_version_dispatcher_body): New. (aarch64_get_function_versions_dispatcher): New. (aarch64_common_function_versions): New. (aarch64_mangle_decl_assembler_name): New. (TARGET_OPTION_VALID_VERSION_ATTRIBUTE_P): New implementation. (TARGET_OPTION_EXPANDED_CLONES_ATTRIBUTE): New implementation. (TARGET_OPTION_FUNCTION_VERSIONS): New implementation. (TARGET_COMPARE_VERSION_PRIORITY): New implementation. (TARGET_GENERATE_VERSION_DISPATCHER_BODY): New implementation. (TARGET_GET_FUNCTION_VERSIONS_DISPATCHER): New implementation. (TARGET_MANGLE_DECL_ASSEMBLER_NAME): New implementation. diff --git a/gcc/attribs.cc b/gcc/attribs.cc index a3c4a81e8582ea4fd06b9518bf51fad7c998ddd6..cc935b502028392ebdc105f940900f01f79196a7 100644 --- a/gcc/attribs.cc +++ b/gcc/attribs.cc @@ -657,7 +657,8 @@ decl_attributes (tree *node, tree attributes, int flags, options to the attribute((target(...))) list. */ if (TREE_CODE (*node) == FUNCTION_DECL && current_target_pragma - && targetm.target_option.valid_attribute_p (*node, NULL_TREE, + && targetm.target_option.valid_attribute_p (*node, + get_identifier("target"), current_target_pragma, 0)) { tree cur_attr = lookup_attribute ("target", attributes); diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc index 9c3c0e705e2e6ea3b55b4a5f1e7d3360f91eb51d..ca0e2a2507ffdbf99e17b77240504bf2d175b9c0 100644 --- a/gcc/config/aarch64/aarch64.cc +++ b/gcc/config/aarch64/aarch64.cc @@ -19088,11 +19088,70 @@ aarch64_process_target_attr (tree args) return true; } +/* Parse the tree in ARGS that contains the targeti_version attribute + information and update the global target options space. */ + +bool +aarch64_process_target_version_attr (tree args) +{ + 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; + + auto with_plus = std::string ("+") + str; + enum aarch_parse_opt_result parse_res; + auto isa_flags = aarch64_asm_isa_flags; + + std::string invalid_extension; + parse_res = aarch64_parse_extension (with_plus.c_str(), &isa_flags, + &invalid_extension); + + if (parse_res == AARCH_PARSE_OK) + { + aarch64_set_asm_isa_flags (isa_flags); + return true; + } + + switch (parse_res) + { + case AARCH_PARSE_MISSING_ARG: + error ("missing value in % attribute"); + break; + + case AARCH_PARSE_INVALID_FEATURE: + error ("invalid feature modifier %qs of value %qs in " + "% attribute", invalid_extension.c_str (), + with_plus.c_str()); + break; + + default: + gcc_unreachable (); + } + + return false; +} + /* Implement TARGET_OPTION_VALID_ATTRIBUTE_P. This is used to process attribute ((target ("..."))). */ static bool -aarch64_option_valid_attribute_p (tree fndecl, tree, tree args, int) +aarch64_option_valid_attribute_p (tree fndecl, tree name, tree args, int) { struct cl_target_option cur_target; bool ret; @@ -19100,13 +19159,22 @@ aarch64_option_valid_attribute_p (tree fndecl, tree, tree args, int) tree new_target, new_optimize; tree existing_target = DECL_FUNCTION_SPECIFIC_TARGET (fndecl); + bool target_version_p; + const char *attr_name = IDENTIFIER_POINTER (name); + if (strcmp (attr_name, "target") == 0) + target_version_p = false; + else if (strcmp (attr_name, "target_version") == 0) + target_version_p = true; + else + gcc_assert (false); + /* If what we're processing is the current pragma string then the target option node is already stored in target_option_current_node by aarch64_pragma_target_parse in aarch64-c.cc. Use that to avoid having to re-parse the string. This is especially useful to keep arm_neon.h compile times down since that header contains a lot of intrinsics enclosed in pragmas. */ - if (!existing_target && args == current_target_pragma) + if (!target_version_p && !existing_target && args == current_target_pragma) { DECL_FUNCTION_SPECIFIC_TARGET (fndecl) = target_option_current_node; return true; @@ -19142,7 +19210,25 @@ aarch64_option_valid_attribute_p (tree fndecl, tree, tree args, int) cl_target_option_restore (&global_options, &global_options_set, TREE_TARGET_OPTION (target_option_current_node)); - ret = aarch64_process_target_attr (args); + if (!target_version_p) + { + ret = aarch64_process_target_attr (args); + 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); + ret = aarch64_process_target_version_attr (version_args); + } + } + } + else + ret = aarch64_process_target_version_attr (args); /* Set up any additional state. */ if (ret) @@ -19173,6 +19259,730 @@ aarch64_option_valid_attribute_p (tree fndecl, tree, tree args, int) return ret; } +/* This enum needs to match the enum used in libgcc cpuinfo.c. */ +//TODO: Does this clash with or overlap an existing list of target features? +enum CPUFeatures { + FEAT_RNG, + FEAT_FLAGM, + FEAT_FLAGM2, + FEAT_FP16FML, + FEAT_DOTPROD, + FEAT_SM4, + FEAT_RDM, + FEAT_LSE, + FEAT_FP, + FEAT_SIMD, + FEAT_CRC, + FEAT_SHA1, + FEAT_SHA2, + FEAT_SHA3, + FEAT_AES, + FEAT_PMULL, + FEAT_FP16, + FEAT_DIT, + FEAT_DPB, + FEAT_DPB2, + FEAT_JSCVT, + FEAT_FCMA, + FEAT_RCPC, + FEAT_RCPC2, + FEAT_FRINTTS, + FEAT_DGH, + FEAT_I8MM, + FEAT_BF16, + FEAT_EBF16, + FEAT_RPRES, + FEAT_SVE, + FEAT_SVE_BF16, + FEAT_SVE_EBF16, + FEAT_SVE_I8MM, + FEAT_SVE_F32MM, + FEAT_SVE_F64MM, + FEAT_SVE2, + FEAT_SVE_AES, + FEAT_SVE_PMULL128, + FEAT_SVE_BITPERM, + FEAT_SVE_SHA3, + FEAT_SVE_SM4, + FEAT_SME, + FEAT_MEMTAG, + FEAT_MEMTAG2, + FEAT_MEMTAG3, + FEAT_SB, + FEAT_PREDRES, + FEAT_SSBS, + FEAT_SSBS2, + FEAT_BTI, + FEAT_LS64, + FEAT_LS64_V, + FEAT_LS64_ACCDATA, + FEAT_WFXT, + FEAT_SME_F64, + FEAT_SME_I64, + FEAT_SME2, + FEAT_RCPC3, //TODO: Check this index - needs to agree with LLVM. + FEAT_MAX +}; + +typedef struct +{ + const char *name; + int priority; + unsigned long long feature_mask; +} aarch64_fmv_feature_datum; + +/* List these in priority order, to make it easier to sort target strings. */ +static aarch64_fmv_feature_datum aarch64_fmv_feature_data[] = { + {"default", 0, 0ULL}, + {"rng", 10, 1ULL << FEAT_RNG}, + {"flagm", 20, 1ULL << FEAT_FLAGM}, + {"flagm2", 30, 1ULL << FEAT_FLAGM2}, + {"fp16fml", 40, 1ULL << FEAT_FP16FML}, + {"dotprod", 50, 1ULL << FEAT_DOTPROD}, + {"sm4", 60, 1ULL << FEAT_SM4}, + {"rdm", 70, 1ULL << FEAT_RDM}, + {"lse", 80, 1ULL << FEAT_LSE}, + {"fp", 90, 1ULL << FEAT_FP}, + {"simd", 100, 1ULL << FEAT_SIMD}, + {"crc", 110, 1ULL << FEAT_CRC}, + {"sha1", 120, 1ULL << FEAT_SHA1}, + {"sha2", 130, 1ULL << FEAT_SHA2}, + {"sha3", 140, 1ULL << FEAT_SHA3}, + {"aes", 150, 1ULL << FEAT_AES}, + {"pmull", 160, 1ULL << FEAT_PMULL}, + {"fp16", 170, 1ULL << FEAT_FP16}, + {"dit", 180, 1ULL << FEAT_DIT}, + {"dpb", 190, 1ULL << FEAT_DPB}, + {"dpb2", 200, 1ULL << FEAT_DPB2}, + {"jscvt", 210, 1ULL << FEAT_JSCVT}, + {"fcma", 220, 1ULL << FEAT_FCMA}, + {"rcpc", 230, 1ULL << FEAT_RCPC}, + {"rcpc2", 240, 1ULL << FEAT_RCPC2}, + {"rcpc3", 241, 1ULL << FEAT_RCPC3}, + {"frintts", 250, 1ULL << FEAT_FRINTTS}, + {"dgh", 260, 1ULL << FEAT_DGH}, + {"i8mm", 270, 1ULL << FEAT_I8MM}, + {"bf16", 280, 1ULL << FEAT_BF16}, + {"ebf16", 290, 1ULL << FEAT_EBF16}, + {"rpres", 300, 1ULL << FEAT_RPRES}, + {"sve", 310, 1ULL << FEAT_SVE}, + {"sve-bf16", 320, 1ULL << FEAT_SVE_BF16}, + {"sve-ebf16", 330, 1ULL << FEAT_SVE_EBF16}, + {"sve-i8mm", 340, 1ULL << FEAT_SVE_I8MM}, + {"f32mm", 350, 1ULL << FEAT_SVE_F32MM}, + {"f64mm", 360, 1ULL << FEAT_SVE_F64MM}, + {"sve2", 370, 1ULL << FEAT_SVE2}, + {"sve2-aes", 380, 1ULL << FEAT_SVE_AES}, + {"sve2-pmull128", 390, 1ULL << FEAT_SVE_PMULL128}, + {"sve2-bitperm", 400, 1ULL << FEAT_SVE_BITPERM}, + {"sve2-sha3", 410, 1ULL << FEAT_SVE_SHA3}, + {"sve2-sm4", 420, 1ULL << FEAT_SVE_SM4}, + {"sme", 430, 1ULL << FEAT_SME}, + {"memtag", 440, 1ULL << FEAT_MEMTAG}, + {"memtag2", 450, 1ULL << FEAT_MEMTAG2}, + {"memtag3", 460, 1ULL << FEAT_MEMTAG3}, + {"sb", 470, 1ULL << FEAT_SB}, + {"predres", 480, 1ULL << FEAT_PREDRES}, + {"ssbs", 490, 1ULL << FEAT_SSBS}, + {"ssbs2", 500, 1ULL << FEAT_SSBS2}, + {"bti", 510, 1ULL << FEAT_BTI}, + {"ls64", 520, 1ULL << FEAT_LS64}, + {"ls64_v", 530, 1ULL << FEAT_LS64_V}, + {"ls64_accdata", 540, 1ULL << FEAT_LS64_ACCDATA}, + {"wfxt", 550, 1ULL << FEAT_WFXT}, + {"sme-f64f64", 560, 1ULL << FEAT_SME_F64}, + {"sme-i16i64", 570, 1ULL << FEAT_SME_I64}, + {"sme2", 580, 1ULL << FEAT_SME2} +}; + +/* Look up a single feature name, and return the bitmask. */ +unsigned long long +get_feature_bit (char *name) +{ + /* Skip default entry here. */ + for (int i = 1; i < FEAT_MAX; i++) + if (strcmp(aarch64_fmv_feature_data[i].name, name) == 0) + return aarch64_fmv_feature_data[i].feature_mask; + return 0; +} + +/* This parses the attribute arguments to target_version in DECL and the + feature mask required to select those targets. No adjustments are made to + add or remove redundant feature requirements. */ + +unsigned long long +get_feature_mask_for_version (tree decl) +{ + tree version_attr = lookup_attribute ("target_version", DECL_ATTRIBUTES (decl)); + if (version_attr == NULL) + return 0; + + const char *version_string = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE + (version_attr))); + if (strcmp (version_string, "default") == 0 + || strcmp (version_string, "") == 0) + return 0; + + int attr_len = strlen (version_string); + + char *feature_string = XNEWVEC (char, attr_len+ 1); + strcpy (feature_string, version_string); + + int count = 1; + for (int i = 0; i < attr_len; i++) + { + if (feature_string[i] == '+') + { + feature_string[i] = '\0'; + count++; + } + } + + unsigned long long feature_mask = 0ULL; + char *cur_feature = feature_string; + for (int i = 0; i < count; i++) + { + unsigned long long feature_bit = get_feature_bit (cur_feature); + if (feature_bit == 0) + { + /* TODO: For target_clones, we should just ignore this version + instead. */ + error_at (DECL_SOURCE_LOCATION (decl), 0, + "Unrecognised feature %s in function version string", + cur_feature); + feature_mask = -1ULL; + } + feature_mask |= feature_bit; + cur_feature += strlen(cur_feature) + 1; + } + XDELETEVEC (feature_string); + return feature_mask; +} + +/* Compare priorities of two feature masks. Return: + 1: mask1 is higher priority + -1: mask2 is higher priority + 0: masks are equal. */ + +int +compare_feature_masks (unsigned long long mask1, unsigned long long mask2) +{ + int pop1 = __builtin_popcountll(mask1); + int pop2 = __builtin_popcountll(mask2); + if (pop1 > pop2) + return 1; + if (pop2 > pop1) + return -1; + + unsigned long long diff_mask = mask1 ^ mask2; + if (diff_mask == 0ULL) + return 0; + for (int i = FEAT_MAX - 1; i > 0; i--) + { + unsigned long long bit_mask = aarch64_fmv_feature_data[i].feature_mask; + if (diff_mask & bit_mask) + return (mask1 & bit_mask) ? 1 : -1; + } + gcc_unreachable(); +} + +int +aarch64_compare_version_priority (tree decl1, tree decl2) +{ + unsigned long long mask1 = get_feature_mask_for_version (decl1); + unsigned long long mask2 = get_feature_mask_for_version (decl2); + + return compare_feature_masks (mask1, mask2); +} + +/* 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. */ + tree decl_name = clone_function_name (default_decl, "resolver"); + const char *resolver_name = IDENTIFIER_POINTER (decl_name); + + /* The resolver function should return a (void *). */ + type = build_function_type_list (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; + + 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; +} + +/* 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, + unsigned long long feature_mask, + 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 (feature_mask == 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 and_expr_var = create_tmp_var (long_long_unsigned_type_node); + tree and_expr = build2 (BIT_AND_EXPR, + long_long_unsigned_type_node, + mask_var, + build_int_cst (long_long_unsigned_type_node, + feature_mask)); + 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); + + tree zero_llu = build_int_cst (long_long_unsigned_type_node, 0); + if_else_stmt = gimple_build_cond (EQ_EXPR, and_expr_var, zero_llu, + 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; +} + +/* Used when sorting the decls into dispatch order. */ +static int compare_feature_version_info (const void *p1, const void *p2) +{ + typedef struct _function_version_info + { + tree version_decl; + unsigned long long feature_mask; + } function_version_info; + const function_version_info v1 = *(const function_version_info *)p1; + const function_version_info v2 = *(const function_version_info *)p2; + return - compare_feature_masks (v1.feature_mask, v2.feature_mask); +} + +static int +dispatch_function_versions (tree dispatch_decl, + void *fndecls_p, + basic_block *empty_bb) +{ + gimple *ifunc_cpu_init_stmt; + gimple_seq gseq; + int ix; + tree ele; + vec *fndecls; + unsigned int num_versions = 0; + unsigned int actual_versions = 0; + unsigned int i; + + struct _function_version_info + { + tree version_decl; + unsigned long long feature_mask; + }*function_version_info; + + gcc_assert (dispatch_decl != NULL + && fndecls_p != NULL + && empty_bb != NULL); + + /*fndecls_p is actually a vector. */ + fndecls = static_cast *> (fndecls_p); + + /* At least one more version other than the default. */ + num_versions = fndecls->length (); + gcc_assert (num_versions >= 2); + + function_version_info = (struct _function_version_info *) + XNEWVEC (struct _function_version_info, (num_versions)); + + 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 __builtin_cpu_init here. */ + tree init_fn_type = build_function_type_list (void_type_node, NULL); + tree init_fn_decl = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL, + get_identifier ("init_cpu_features"), + 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 __aarch64_cpu_features. */ + tree global_type = lang_hooks.types.make_type (RECORD_TYPE); + tree field1 = build_decl (UNKNOWN_LOCATION, FIELD_DECL, + get_identifier ("features"), + long_long_unsigned_type_node); + DECL_FIELD_CONTEXT (field1) = global_type; + TYPE_FIELDS (global_type) = field1; + layout_type (global_type); + + tree global_var = build_decl (UNKNOWN_LOCATION, VAR_DECL, get_identifier + ("__aarch64_cpu_features"), global_type); + DECL_EXTERNAL (global_var) = 1; + tree mask_var = create_tmp_var (long_long_unsigned_type_node); + + tree component_expr = build3 (COMPONENT_REF, long_long_unsigned_type_node, + global_var, field1, NULL_TREE); + gimple *component_stmt = gimple_build_assign (mask_var, component_expr); + gimple_set_block (component_stmt, DECL_INITIAL (dispatch_decl)); + gimple_set_bb (component_stmt, *empty_bb); + gimple_seq_add_stmt (&gseq, component_stmt); + + tree not_expr = build1 (BIT_NOT_EXPR, long_long_unsigned_type_node, mask_var); + gimple *not_stmt = gimple_build_assign (mask_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); + + set_bb_seq (*empty_bb, gseq); + + pop_cfun (); + + for (ix = 0; fndecls->iterate (ix, &ele); ++ix) + { + tree version_decl = ele; + unsigned long long feature_mask; + /* Get attribute string, parse it and find the right features. */ + feature_mask = get_feature_mask_for_version (version_decl); + function_version_info [actual_versions].version_decl = version_decl; + function_version_info [actual_versions].feature_mask = feature_mask; + actual_versions++; + } + + /* Sort the versions according to descending order of dispatch priority. */ + qsort (function_version_info, actual_versions, + sizeof (struct _function_version_info), compare_feature_version_info); + + for (i = 0; i < actual_versions; ++i) + *empty_bb = add_condition_to_bb (dispatch_decl, + function_version_info[i].version_decl, + function_version_info[i].feature_mask, + mask_var, + *empty_bb); + + free (function_version_info); + return 0; +} + + +tree +aarch64_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 (); + 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 +aarch64_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) + { + if (get_feature_mask_for_version + (default_version_info->this_node->decl) == 0ULL) + 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; +} + +bool +aarch64_common_function_versions (tree fn1, tree fn2) +{ + if (TREE_CODE (fn1) != FUNCTION_DECL + || TREE_CODE (fn2) != FUNCTION_DECL) + return false; + + return (aarch64_compare_version_priority (fn1, fn2) != 0); +} + + +tree +aarch64_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)) + { + unsigned long long feature_mask = get_feature_mask_for_version (decl); + + /* No suffix for the default version. */ + if (feature_mask == 0ULL) + return id; + + char suffix[2048]; + int pos = 0; + const char *base = IDENTIFIER_POINTER (id); + + for (int i = 1; i < FEAT_MAX; i++) + { + if (feature_mask & aarch64_fmv_feature_data[i].feature_mask) + { + suffix[pos] = 'M'; + strcpy (&suffix[pos+1], aarch64_fmv_feature_data[i].name); + pos += strlen(aarch64_fmv_feature_data[i].name) + 1; + } + } + suffix[pos] = '\0'; + + char *ret = XNEWVEC (char, strlen (base) + strlen (suffix) + 3); + sprintf (ret, "%s._%s", base, suffix); + + if (DECL_ASSEMBLER_NAME_SET_P (decl)) + SET_DECL_RTL (decl, NULL); + + id = get_identifier (ret); + } + return id; +} + + /* Helper for aarch64_can_inline_p. In the case where CALLER and CALLEE are tri-bool options (yes, no, don't care) and the default value is DEF, determine whether to reject inlining. */ @@ -27804,6 +28614,12 @@ aarch64_libgcc_floating_mode_supported_p #undef TARGET_OPTION_VALID_ATTRIBUTE_P #define TARGET_OPTION_VALID_ATTRIBUTE_P aarch64_option_valid_attribute_p +#undef TARGET_OPTION_VALID_VERSION_ATTRIBUTE_P +#define TARGET_OPTION_VALID_VERSION_ATTRIBUTE_P aarch64_option_valid_attribute_p + +#undef TARGET_OPTION_EXPANDED_CLONES_ATTRIBUTE +#define TARGET_OPTION_EXPANDED_CLONES_ATTRIBUTE "target_version" + #undef TARGET_SET_CURRENT_FUNCTION #define TARGET_SET_CURRENT_FUNCTION aarch64_set_current_function @@ -28128,6 +28944,24 @@ aarch64_libgcc_floating_mode_supported_p #undef TARGET_CONST_ANCHOR #define TARGET_CONST_ANCHOR 0x1000000 +#undef TARGET_OPTION_FUNCTION_VERSIONS +#define TARGET_OPTION_FUNCTION_VERSIONS aarch64_common_function_versions + +#undef TARGET_COMPARE_VERSION_PRIORITY +#define TARGET_COMPARE_VERSION_PRIORITY aarch64_compare_version_priority + +#undef TARGET_GENERATE_VERSION_DISPATCHER_BODY +#define TARGET_GENERATE_VERSION_DISPATCHER_BODY \ + aarch64_generate_version_dispatcher_body + +#undef TARGET_GET_FUNCTION_VERSIONS_DISPATCHER +#define TARGET_GET_FUNCTION_VERSIONS_DISPATCHER \ + aarch64_get_function_versions_dispatcher + +#undef TARGET_MANGLE_DECL_ASSEMBLER_NAME +#define TARGET_MANGLE_DECL_ASSEMBLER_NAME aarch64_mangle_decl_assembler_name + + struct gcc_target targetm = TARGET_INITIALIZER; #include "gt-aarch64.h" From patchwork Wed Oct 18 15:44:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Carlotti X-Patchwork-Id: 154938 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4884799vqb; Wed, 18 Oct 2023 08:45:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFB6erbumTSmB87cQmxRxulaoeTa+HPZCvfEYkUaFm0rrykj2zpsBZaItBRdzIR0ZrrMtgI X-Received: by 2002:a05:6214:248e:b0:66d:5cfe:82a6 with SMTP id gi14-20020a056214248e00b0066d5cfe82a6mr10112820qvb.27.1697643934515; Wed, 18 Oct 2023 08:45:34 -0700 (PDT) Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id qr2-20020a05620a390200b00777722d8abfsi104072qkn.244.2023.10.18.08.45.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 08:45:34 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b="MY3JIK+/"; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b="MY3JIK+/"; arc=fail (previous hop failed); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 49ADC3858028 for ; Wed, 18 Oct 2023 15:45:34 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2041.outbound.protection.outlook.com [40.107.7.41]) by sourceware.org (Postfix) with ESMTPS id 4DBB3385700B for ; Wed, 18 Oct 2023 15:45:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4DBB3385700B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4DBB3385700B Authentication-Results: server2.sourceware.org; arc=fail smtp.remote-ip=40.107.7.41 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1697643910; cv=fail; b=UvQWkCgF39Ssg2NBhjfh2zTIUf5qFDxyd3L8kvRR6JHksuVrTkDCASbgC4pdd63gwb0Vl5uarqBgRctZVCR1M69YngZACv+4qQdMspz2CfZGxMYZ4b0bOwrQqe/KtFQ+45eBi8Y4AcEWyYkV/9vDnBvF/NQKm+Ww44G3wpebDCs= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1697643910; c=relaxed/simple; bh=nvCx2IRxATf5Pizj0kIfHjqpQdeeHph8EyagqkHqJiw=; h=DKIM-Signature:DKIM-Signature:Date:From:To:Subject:Message-ID: MIME-Version; b=klruKMl2M/Fd21toP+7y9HiJgrb6CHWSPCqDTGV22j6ctSbC8bltaBXXbj1+C4+RFPvKs1qhplIqHw21EI3KALfkQpeRiZO/lDobfwkHMW70nyiQ1HbY3ImrXrtW0VtXhA7c5PHU9a6FHzN9+nZLqV3jEeGWrz2GOJ4ab7CjP4k= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=O4bg6xqwEwKFS9na7gvCdrlJ5gGGHLvrQFtaT1Sw9gg=; b=MY3JIK+/GD9ck2e6bGz46ELGhDSw+N8iu5lRQgRtP/PD+AzGkHNJYBc8m/OLmyUWNMC4AQRuEe2Izb46XL8tvQev0kmw43qI1sYSl5O16WhyrsMscIRusiiJ9mDUaJLG0kZ/wdxyerPOjhAvtVAoAuWdcdhmQrq5Xpl9YsqitUs= Received: from AM0PR02CA0187.eurprd02.prod.outlook.com (2603:10a6:20b:28e::24) by DU0PR08MB9902.eurprd08.prod.outlook.com (2603:10a6:10:476::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.36; Wed, 18 Oct 2023 15:45:04 +0000 Received: from AM7EUR03FT043.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:28e:cafe::7) by AM0PR02CA0187.outlook.office365.com (2603:10a6:20b:28e::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.36 via Frontend Transport; Wed, 18 Oct 2023 15:45:04 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM7EUR03FT043.mail.protection.outlook.com (100.127.140.160) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.24 via Frontend Transport; Wed, 18 Oct 2023 15:45:04 +0000 Received: ("Tessian outbound 028b72acc2da:v215"); Wed, 18 Oct 2023 15:45:04 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: c42813379dbd4448 X-CR-MTA-TID: 64aa7808 Received: from f3b770d2b5fa.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id C48A3D16-4555-4B3F-9F03-DCCEA5889E08.1; Wed, 18 Oct 2023 15:44:57 +0000 Received: from EUR01-VE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id f3b770d2b5fa.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 18 Oct 2023 15:44:57 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=h8LVp1dzYBt52XwSjQMjwjBvP/ZF0AzOwR3zNTeRKZP4MRotsGK4TYQiPD+rWS80b5qHfNmCnkyu5HgOZ8JaPyH/uO7/KCAt6ZLJ2qYNxgyMlEW0s1TdjUlMcIW5UapMJz/Q5zELyrW03gfWtsplw0KH29M+7aj+ojizR/ZvySS/pSbY1GwZ8FRvzGZQlKyoJ9SfCE4QFblXouDL0WR+QuYcwEmkQjnLoyyH9FV5AjQOYUlsIt4CqPAJVjSCHW3yO5DMjeR8wTz3HaVVmpoFWbI4v3zHmHVabqUXhomPHLT2GcCAFkS/R5O6HsTRCYI+5Tqp5rVVmFZoXBDOYtSt3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=O4bg6xqwEwKFS9na7gvCdrlJ5gGGHLvrQFtaT1Sw9gg=; b=Wxia46M7jA9JOUGzibw9H12vCawdo5ibaMux5Xri7CHAvXtfB0GR5Uh87W00xqETrVF9QJ3E2N+iR6wU0qz8lloZCbhL3rLCOC1BUi6Nj1zU4nA7/2DJAJUmc/I4mIEEjyFEbtWhh7r3hXChJ3jqijPfetHCEWZ00gJyK+FGurLme07IFbYqPovf5Dz8KPYKpbDhCU8mskhzjn1O6WpHTzCn0FEQrygYcRUc+LQUv2FFEJbAqKUMakMTxJqqpE7gTgWLGfjgfxz0f9yYhWmsnT1WDZaZdHG1YBdAZVQOx8Nm+s0QzDJrdTEWHLP0sfXKCeVfbKdRJfOp/GiYqfP2Mw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=O4bg6xqwEwKFS9na7gvCdrlJ5gGGHLvrQFtaT1Sw9gg=; b=MY3JIK+/GD9ck2e6bGz46ELGhDSw+N8iu5lRQgRtP/PD+AzGkHNJYBc8m/OLmyUWNMC4AQRuEe2Izb46XL8tvQev0kmw43qI1sYSl5O16WhyrsMscIRusiiJ9mDUaJLG0kZ/wdxyerPOjhAvtVAoAuWdcdhmQrq5Xpl9YsqitUs= Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from AS8PR08MB6678.eurprd08.prod.outlook.com (2603:10a6:20b:398::8) by AS8PR08MB9120.eurprd08.prod.outlook.com (2603:10a6:20b:5c1::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.36; Wed, 18 Oct 2023 15:44:56 +0000 Received: from AS8PR08MB6678.eurprd08.prod.outlook.com ([fe80::3880:6a2c:60e:3f3e]) by AS8PR08MB6678.eurprd08.prod.outlook.com ([fe80::3880:6a2c:60e:3f3e%7]) with mapi id 15.20.6886.034; Wed, 18 Oct 2023 15:44:56 +0000 Date: Wed, 18 Oct 2023 16:44:55 +0100 From: Andrew Carlotti To: gcc-patches@gcc.gnu.org Subject: [3/3] WIP/RFC: Fix name mangling for target_clones Message-ID: <36b6307f-10f5-c03e-0263-0671d3219eb9@e124511.cambridge.arm.com> References: <26bbc7e4-9d5a-fef3-2f78-1b7a03865050@e124511.cambridge.arm.com> Content-Disposition: inline In-Reply-To: <26bbc7e4-9d5a-fef3-2f78-1b7a03865050@e124511.cambridge.arm.com> X-ClientProxiedBy: LO2P265CA0262.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:8a::34) To AS8PR08MB6678.eurprd08.prod.outlook.com (2603:10a6:20b:398::8) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: AS8PR08MB6678:EE_|AS8PR08MB9120:EE_|AM7EUR03FT043:EE_|DU0PR08MB9902:EE_ X-MS-Office365-Filtering-Correlation-Id: 9bd06bed-960b-4076-2979-08dbcff132ae x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: qcz8PerVgm5ij/U1/fwamruy/GAII0h73QkH8ALCKGdlLblYG12PH9k/U4U3F67sYZO2cEdgukKuWBwIhLDiwrM2rva0y9Td2z/oVhINmQNsZJP1F1it2tl23L6U5jLS9hscNWuc4X4BcNmxqwtHYEdFTeSxQG3MtScUtcDHmBZI0mLVlEVsmlCyvAyBYd7cl/x5/NSmpU2bmJz0aq+pTmQrcc84XpY9PZ0XsyNq77O1h3u1xVp8pyNk7pw6gTk1v002Hrnst6gGHcyoKeBe2aBLuJsihzHo/7Trzw7HJSY8Se0RxqGwpU+ufbm4JGEkYrXLYbM5ZqcSXC5NALB/AROQI5DD282n2EVwK/oWhc5oj3zwsPU1x0brQDhQ4vlULU+xmm33lIyMf/0ZIhuGsWEqH2Kh7wmpnJbe99QzexwruWL8d1FL6bBu8jwG8K3ogOBNQa6fq3mPa8GdCgWEoCRfQBHdsHb+Wh0O1OEMhmMU1Fclu4FxyaeGMRAMayuPMkJTy87PYS3sL2md+b4TXVaYb/Uikb2/r3htNHbIfv22fO9pVoGVjutSzO0thp9u X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR08MB6678.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(396003)(39860400002)(366004)(136003)(346002)(376002)(230922051799003)(1800799009)(451199024)(186009)(64100799003)(26005)(6506007)(8936002)(66946007)(5660300002)(44832011)(41300700001)(8676002)(478600001)(2906002)(6486002)(316002)(6916009)(66556008)(66476007)(86362001)(31696002)(38100700002)(31686004)(6512007); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB9120 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM7EUR03FT043.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 5b5f76b8-2119-4905-5817-08dbcff12d64 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: up+vVDa8D0LmmnGmW7frCi/UbP24PN4Q8AFE4KnfXjWrDmFOcDDncW5hekKzXM9QS0kfpKPBgGHVH82pKEtK9Jg9k38AUuq8EpNgkdW8vkKMhnPVjBEErjzzyumxh/O7en6W4L/HiEpYBgTw9VAp3+HwOCcGeS9/xj3bMCjG2s0sajQLxAmjd65XBFlQVzzY8+hSUi9O7b37Kzkhxiou/Oo5uPDlx5KuMioqRpB9l3plxh1+RczBUn45mnza8wWgeGUt0G8AC95PRz3q/gi1W5+seGHZEIv1VX33OKM5CfnoArFNwyeT4/47hznBG1l/b1k+Dgn4QFeSE7G7WFZ2Dougo3TKPvxiB9K3KZTOGTSZ92qKtozSzPVrpkdyGRIvNwZs3T09kwlaAB0ls6Kpxzk5IJUFkgCFV8BgKoS40WoQTykJ4Tb6IiEg0XC4hto8IdoDSFIxSHsum2EtH/Seg3Qdt3ikxoET2/+kQK6mylVwsX6cCbdHg9Tp5EjVvRMCIqirdiVqq9li1mVdroDn819OCY7eLiaiY15AV4gWCrYDqff149AQXWvqZrUBE03KUnOud98RXMQUKI4VcOl6NmG14S+lMI21eCxI/OOmvGVAXb7bwmPW6XZqJChQhpSY/tfwMKHndR0VDaRY/KfyTAcuOOEOb9l9ZjPLN0+BBIri9NLaw7/j5S8nRvhar4MSF7oJnvWI4mLgRczgOr9n/jsWsmlvi2uBU0jmKS+h3qb/JJpE+AIQmZQwIHpHMM7v X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(13230031)(4636009)(396003)(39860400002)(376002)(136003)(346002)(230922051799003)(1800799009)(186009)(64100799003)(82310400011)(451199024)(36840700001)(40470700004)(46966006)(6486002)(478600001)(6506007)(6512007)(44832011)(336012)(2906002)(8676002)(8936002)(5660300002)(70206006)(70586007)(6916009)(41300700001)(316002)(47076005)(36860700001)(31696002)(86362001)(81166007)(82740400003)(356005)(26005)(40460700003)(40480700001)(31686004); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Oct 2023 15:45:04.6774 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9bd06bed-960b-4076-2979-08dbcff132ae X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM7EUR03FT043.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR08MB9902 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_NONE, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP, UNPARSEABLE_RELAY 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780108685989035737 X-GMAIL-MSGID: 1780108685989035737 This is a partial patch to make the mangling of function version names for target_clones match those generated using the target or target_version attributes. It modifies the name of function versions, but does not yet rename the resolved symbol, resulting in a duplicate symbol name (and an error at assembly time). Is this sort of approach ok? Should I create an extra target hook to be called here, so that the target_clones mangling can be target-specific but not necessarily the same as for target attribute versioning? diff --git a/gcc/cgraphclones.cc b/gcc/cgraphclones.cc index 8af6b23d8c0306920e0fdcb3559ef047a16689f4..15672c02c6f9d6043a36bf081067f08d1ab834e5 100644 --- a/gcc/cgraphclones.cc +++ b/gcc/cgraphclones.cc @@ -1033,11 +1033,6 @@ cgraph_node::create_version_clone_with_body else new_decl = copy_node (old_decl); - /* Generate a new name for the new version. */ - tree fnname = (version_decl ? clone_function_name_numbered (old_decl, suffix) - : clone_function_name (old_decl, suffix)); - DECL_NAME (new_decl) = fnname; - SET_DECL_ASSEMBLER_NAME (new_decl, fnname); SET_DECL_RTL (new_decl, NULL); DECL_VIRTUAL_P (new_decl) = 0; @@ -1065,6 +1060,24 @@ cgraph_node::create_version_clone_with_body return NULL; } + /* Generate a new name for the new version. */ + if (version_decl) + { + tree fnname = (clone_function_name_numbered (old_decl, suffix)); + DECL_NAME (new_decl) = fnname; + SET_DECL_ASSEMBLER_NAME (new_decl, fnname); + } + else + { + /* Add target version mangling. We assume that the target hook will + produce the same mangled name as it would have produced if the decl + had already been versioned when the hook was previously called. */ + tree fnname = DECL_ASSEMBLER_NAME (old_decl); + DECL_NAME (new_decl) = fnname; + fnname = targetm.mangle_decl_assembler_name (new_decl, fnname); + SET_DECL_ASSEMBLER_NAME (new_decl, fnname); + } + /* When the old decl was a con-/destructor make sure the clone isn't. */ DECL_STATIC_CONSTRUCTOR (new_decl) = 0; DECL_STATIC_DESTRUCTOR (new_decl) = 0; diff --git a/gcc/multiple_target.cc b/gcc/multiple_target.cc index 3db57c2b13d612a37240d9dcf58ad21b2286633c..d9aec9a5ab532701b4a1877b440f3a553ffa28e2 100644 --- a/gcc/multiple_target.cc +++ b/gcc/multiple_target.cc @@ -162,7 +162,12 @@ create_dispatcher_calls (struct cgraph_node *node) } } - tree fname = clone_function_name (node->decl, "default"); + /* Add version mangling to default decl name. We assume that the target + hook will produce the same mangled name as it would have produced if the + decl had already been versioned when the hook was previously called. */ + tree fname = DECL_ASSEMBLER_NAME (node->decl); + DECL_NAME (node->decl) = fname; + fname = targetm.mangle_decl_assembler_name (node->decl, fname); symtab->change_decl_assembler_name (node->decl, fname); if (node->definition)