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)