From patchwork Tue Oct 17 20:47:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Coplan X-Patchwork-Id: 154527 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4390379vqb; Tue, 17 Oct 2023 13:48:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHnc89AOeJO2zsxepkJKlHmoMkdclZRt8onQEI0r85t6lOdDak/PGM+FscrVCRMT0gTxkk6 X-Received: by 2002:a05:620a:248c:b0:774:32a7:fe91 with SMTP id i12-20020a05620a248c00b0077432a7fe91mr3783809qkn.48.1697575727628; Tue, 17 Oct 2023 13:48:47 -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 pi21-20020a05620a379500b0076841128d10si1602972qkn.533.2023.10.17.13.48.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 13:48:47 -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=kZJDx+Ko; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=kZJDx+Ko; 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 0A8E4385734B for ; Tue, 17 Oct 2023 20:48:47 +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-he1eur04on2078.outbound.protection.outlook.com [40.107.7.78]) by sourceware.org (Postfix) with ESMTPS id 14191385701B for ; Tue, 17 Oct 2023 20:48:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 14191385701B 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 14191385701B Authentication-Results: server2.sourceware.org; arc=fail smtp.remote-ip=40.107.7.78 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1697575690; cv=fail; b=xy/1dbGx5E6g+MUHa1GmqT4RZRte6MRO9LpsMcD5iZXtZBMFHYUXCDZayIJhS0uuvffuNrLyE1oq2CAokA5VSgeijhTllcZ6VNbIMSOIDLPAJlka1hZYA7Wj4Rko461GPjKcNQ8oNdfdLbeqc4yvfJidqlWwtWycElCmOUxopfw= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1697575690; c=relaxed/simple; bh=+8q6dP+Oj1YbK3tcvscl2ovTsruq+hgBI+9dpdN6ZKA=; h=DKIM-Signature:DKIM-Signature:Date:From:To:Subject:Message-ID: MIME-Version; b=LZiR08RyVXI41D220LF4SntSuGVbYFXtGftyvlRb2qNmlhhA9qvzuQlnpJyc0fORPCZIxcePIq4aZrlkBxfay0TVrpD0krBwem6BOuVD8+fXe/mTsrgPyUe3mdAEbOKbmqcwjLJ5vXv/hXKeQCfjtUg+2Dk/nVM9wttfFdYW1ao= 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=9PKyTnAB9fsbDkfWEpHoPJ61GGvvR7xfGfqjFPCgo10=; b=kZJDx+Ko5o3S5kAYv8IQ3sMb617SU5I75jBDXxubF3I55RJ8s/H5v3wKhB2XFIi9y5ITEBPEENfa+otWaMni1J9EDSDjB9MyJDE2Q+Meo01/O/G+oVFhU6s8hrjQYLNy8F+0ZQrZC0bVCrMw9hGkhRR1GA5jt15cZg2Bx2p5KoE= Received: from AM6PR0502CA0047.eurprd05.prod.outlook.com (2603:10a6:20b:56::24) by PAXPR08MB6608.eurprd08.prod.outlook.com (2603:10a6:102:150::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.34; Tue, 17 Oct 2023 20:48:04 +0000 Received: from AM3PEPF0000A78E.eurprd04.prod.outlook.com (2603:10a6:20b:56:cafe::37) by AM6PR0502CA0047.outlook.office365.com (2603:10a6:20b:56::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; Tue, 17 Oct 2023 20:48: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 AM3PEPF0000A78E.mail.protection.outlook.com (10.167.16.117) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.21 via Frontend Transport; Tue, 17 Oct 2023 20:48:04 +0000 Received: ("Tessian outbound fdf44c93bd44:v211"); Tue, 17 Oct 2023 20:48:04 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 04f9c2496c535850 X-CR-MTA-TID: 64aa7808 Received: from 6832a30d6091.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 9FDE390B-DC35-4B6B-B903-C31FA7F14652.1; Tue, 17 Oct 2023 20:47:57 +0000 Received: from EUR05-DB8-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 6832a30d6091.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 17 Oct 2023 20:47:57 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SZUFxrU9dugVci8fDaN3qyKLIOhmU8kglJIHf3wfnWx7KMVhp26KX3KZmTVlzz+ccKw4PGrH43sSRQpb9KBctHjQyyaQZjJwf4mOM6lumwWndrHU9gkhpAlU2Iqf9qMCMPQi8K8s9H5/xR6w1I5a+u2/93p32Pnvn+/yAnDFmskS98QwJd5wXn8PvbhJFdjVAix7ZkgzxwnuiHWomPjTiL4CzdmrWinURLieASgsooU4dHDwLCkDf1NrqYN2Qjw6t3c4oCKDFQaDY7F1MUCga6WcRU9F7MSkzurq+klzb8rC9PyaPA4HyF6vD4miNzaP6Adz62a2HKlWhYW4FzS8Xg== 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=9PKyTnAB9fsbDkfWEpHoPJ61GGvvR7xfGfqjFPCgo10=; b=b5pBJPaZRzb3FnHo9/Bdxeg5JBsPKSFr997/4dtijyZ+XVDieOhdaskgEQETn+3SYBCEgvLac9KpACVwQn6TN6bQ4s1W0DOc1GJrZQdHYklfmGenWF49p5PD73OhjPh2TYeQkigm6i8maGtvZ0GO18hi8KJFmkhIBSRVXYWZ4V4WOo6h6LWPyJmApi141TzwFCckwgk1IcifSa4bKMaa9yUZWTGY1CGXUKPe6eSoh7XZ4KQkeXDovWCiG6H3JN9LypCCFjDfoNgbNgRC3/ZARY42v5/+F3+lc7d935qKAan2+CZzMx04l1lNAWXXedmvEr84t8HTVCwyESyjLFrNDw== 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=9PKyTnAB9fsbDkfWEpHoPJ61GGvvR7xfGfqjFPCgo10=; b=kZJDx+Ko5o3S5kAYv8IQ3sMb617SU5I75jBDXxubF3I55RJ8s/H5v3wKhB2XFIi9y5ITEBPEENfa+otWaMni1J9EDSDjB9MyJDE2Q+Meo01/O/G+oVFhU6s8hrjQYLNy8F+0ZQrZC0bVCrMw9hGkhRR1GA5jt15cZg2Bx2p5KoE= Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from PAWPR08MB8958.eurprd08.prod.outlook.com (2603:10a6:102:33e::15) by AS4PR08MB7580.eurprd08.prod.outlook.com (2603:10a6:20b:4ff::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.36; Tue, 17 Oct 2023 20:47:56 +0000 Received: from PAWPR08MB8958.eurprd08.prod.outlook.com ([fe80::f41:4ae1:dba2:70f4]) by PAWPR08MB8958.eurprd08.prod.outlook.com ([fe80::f41:4ae1:dba2:70f4%6]) with mapi id 15.20.6863.046; Tue, 17 Oct 2023 20:47:55 +0000 Date: Tue, 17 Oct 2023 21:47:53 +0100 From: Alex Coplan To: gcc-patches@gcc.gnu.org Cc: Richard Sandiford Subject: [PATCH 05/11] rtl-ssa: Support for inserting new insns Message-ID: Content-Disposition: inline X-ClientProxiedBy: LO2P265CA0387.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:f::15) To PAWPR08MB8958.eurprd08.prod.outlook.com (2603:10a6:102:33e::15) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: PAWPR08MB8958:EE_|AS4PR08MB7580:EE_|AM3PEPF0000A78E:EE_|PAXPR08MB6608:EE_ X-MS-Office365-Filtering-Correlation-Id: 61d08c8f-6aa2-4b8a-152d-08dbcf525c45 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: +vcwgkWhMhQt6rrs+BDBsc1x5MP39fnkNDuN+IO4jGBTONT6uG615xDCYEuKV6+Afwqm4+dcp0gAo2ozoNSUdT3fLnl3o0iULk6mmhE0tPoFiFFIDRy9ShpZ93Id47Pn42mzEhz3Ape2uKcDn+IAWL5Dz21bfdnj5R76b0OkUOErMHggosW4m7KakLGpb4gsqZSx9SLkHbjvwPtjKI3LZKJ8i/UQnEu9pM3CTVoDnjHkIRes169EO0FOkP3gFvAzd01aahTMo2qqZPVeVSre8zYCRwaff4Acm7r4c4WHHWxzdLT0Cluq0JXeVDBqaohgKXziZhYktw/5YaJE0MbMzLYMHMyi7zI9cpZ3Oc3TTEjNPBGFQ1fOekIOeDyz6VLcjxmP86fty351+61XxEaiDAlX6trMJg+prrkuknTBIAQYVUToN0GSSxJcxI+5EdaVZ6ViqyQ+7oVX0tAgXEa6l7F0wxWUJjqcPlC7YvVTrfUlHH6AIG1pKxfVKQgPkw11gUD9L0Tq5Qos+ZoYfRjLApMKNuVsgKb5RJcciFAHKYwWQVzS6CVjVzV9EsRj1ZhgBPNTWq1/4XLxS/gqqMmjLRolLHngE0HOXXEW2DgZfkZe1m1M5dBLbyVBuvlbZzkDu+h9qeDK2WpFbgdvEMVp/w== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PAWPR08MB8958.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(346002)(396003)(366004)(136003)(39860400002)(376002)(230922051799003)(64100799003)(451199024)(1800799009)(186009)(316002)(66556008)(66946007)(66476007)(8936002)(8676002)(6916009)(38100700002)(6512007)(478600001)(2616005)(6486002)(44144004)(33964004)(6506007)(83380400001)(4326008)(26005)(235185007)(2906002)(5660300002)(44832011)(86362001)(41300700001)(36756003)(2700100001)(67856001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS4PR08MB7580 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: AM3PEPF0000A78E.eurprd04.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: a8995dec-8b49-4d0f-2b38-08dbcf525707 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5dAR8xTCAMUvKCfX6OTP6XVvsVRfcUO+mhYS0F6c5LrOLn8iT+D2vk8cLGu3EC58+MH8IYLHTi0Rk2KzrWxZth+FgR5xVqNsa+yq0ekFWTL5xbHY5jBxZt/4U0mFY+6B1DeT/9UVLK+2ten6WcCZmFrQ62bdVyvDA1wXuzk6hl0Su1LLVGSSBYj7L22lUAQnckWVUmkkEsxWkmVNL2Yza35yg0EYWGFaOV5MFUH0Eb395OPmV22IfeDeznCd3mv/7h+PnqFR3Qp8ajxFX7m/5Gc2u97Xl4C++4L4HuymDD04x4v73TBhDiJx5B9PvqKndbf9ZUwY/X/tI4rfA069uNFo7BA5q6aOQZQ4YcFdfbK5Cy0O2xRUK0ywKizJR8qA90dIx0FAzXR9xqUYEAwPT5lfUBlmJHmVzCqUgRoQ8QtPvCMLyR2AQn2cQKIdLnrnQJs5gVjvvqatC4IwHv9Vq8udEL3jypZYnmu4nsJVSuSGAUbDlt1ChGARfO0+xTux/QaiK9vQb0khOIS3xfwQtu8ZYCIWqoskO7L961QBMm9Ahorh1V3H06E5wzpodRHW+sSyDUGJ5Lkis7FAkPR3/9QAE0yWF0NaW/ClQvqYyF2TJ9rUq8bUaaKheRsKSBhvKl3bcBStvzR9nPU6MOlJmbS7avez5DkS+Wei2AYJa0ciFlJwUcSVIe6RkychWMm48iQq5L4M5/c5G1VN4eevjJE9LBzTH+91IzkCnPC3cy4Rtxyv6KiHZxYg21GBWgx8qqLhy8RG+NfcYpD5vomm80yKeTP5YXQGnkaaWq4U2Qg= 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)(136003)(346002)(376002)(39860400002)(230922051799003)(1800799009)(186009)(451199024)(82310400011)(64100799003)(46966006)(36840700001)(40470700004)(478600001)(36860700001)(44144004)(2616005)(26005)(6506007)(33964004)(6512007)(4326008)(47076005)(5660300002)(8936002)(8676002)(41300700001)(44832011)(83380400001)(6916009)(316002)(70206006)(70586007)(235185007)(2906002)(82740400003)(336012)(6486002)(356005)(81166007)(86362001)(40460700003)(36756003)(40480700001)(2700100001)(67856001); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Oct 2023 20:48:04.4731 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 61d08c8f-6aa2-4b8a-152d-08dbcf525c45 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: AM3PEPF0000A78E.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR08MB6608 X-Spam-Status: No, score=-12.0 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: 1780037166414414753 X-GMAIL-MSGID: 1780037166414414753 The upcoming aarch64 load pair pass needs to form store pairs, and can re-order stores over loads when alias analysis determines this is safe. In the case that both mem defs have uses in the RTL-SSA IR, and both stores require re-ordering over their uses, we represent that as (tentative) deletion of the original store insns and creation of a new insn, to prevent requiring repeated re-parenting of uses during the pass. We then update all mem uses that require re-parenting in one go at the end of the pass. To support this, RTL-SSA needs to handle inserting new insns (rather than just changing existing ones), so this patch adds support for that. New insns (and new accesses) are temporaries, allocated above a temporary obstack_watermark, such that the user can easily back out of a change without awkward bookkeeping. Bootstrapped/regtested as a series on aarch64-linux-gnu, OK for trunk? gcc/ChangeLog: * rtl-ssa/accesses.cc (function_info::create_set): New. * rtl-ssa/accesses.h (access_info::is_temporary): New. * rtl-ssa/changes.cc (move_insn): Handle new (temporary) insns. (function_info::finalize_new_accesses): Handle new/temporary user-created accesses. (function_info::apply_changes_to_insn): Ensure m_is_temp flag on new insns gets cleared. (function_info::change_insns): Handle new/temporary insns. (function_info::create_insn): New. * rtl-ssa/changes.h (class insn_change): Make function_info a friend class. * rtl-ssa/functions.h (function_info): Declare new entry points: create_set, create_insn. Declare new change_alloc helper. * rtl-ssa/insns.cc (insn_info::print_full): Identify temporary insns in dump. * rtl-ssa/insns.h (insn_info): Add new m_is_temp flag and accompanying is_temporary accessor. * rtl-ssa/internals.inl (insn_info::insn_info): Initialize m_is_temp to false. * rtl-ssa/member-fns.inl (function_info::change_alloc): New. * rtl-ssa/movement.h (restrict_movement_for_defs_ignoring): Add handling for temporary defs. --- gcc/rtl-ssa/accesses.cc | 10 ++++++ gcc/rtl-ssa/accesses.h | 4 +++ gcc/rtl-ssa/changes.cc | 73 +++++++++++++++++++++++++++++++------- gcc/rtl-ssa/changes.h | 2 ++ gcc/rtl-ssa/functions.h | 14 ++++++++ gcc/rtl-ssa/insns.cc | 5 +++ gcc/rtl-ssa/insns.h | 7 +++- gcc/rtl-ssa/internals.inl | 1 + gcc/rtl-ssa/member-fns.inl | 12 +++++++ gcc/rtl-ssa/movement.h | 8 ++++- 10 files changed, 122 insertions(+), 14 deletions(-) diff --git a/gcc/rtl-ssa/accesses.cc b/gcc/rtl-ssa/accesses.cc index 774ab9d99ee..edf8b75f4d6 100644 --- a/gcc/rtl-ssa/accesses.cc +++ b/gcc/rtl-ssa/accesses.cc @@ -1398,6 +1398,16 @@ function_info::make_uses_available (obstack_watermark &watermark, return use_array (new_uses, num_uses); } +set_info * +function_info::create_set (obstack_watermark &watermark, + insn_info *insn, + resource_info resource) +{ + auto set = change_alloc (watermark, insn, resource); + set->m_is_temp = true; + return set; +} + // Return true if ACCESS1 can represent ACCESS2 and if ACCESS2 can // represent ACCESS1. static bool diff --git a/gcc/rtl-ssa/accesses.h b/gcc/rtl-ssa/accesses.h index fce31d46717..7e7a90ece97 100644 --- a/gcc/rtl-ssa/accesses.h +++ b/gcc/rtl-ssa/accesses.h @@ -204,6 +204,10 @@ public: // in the main instruction pattern. bool only_occurs_in_notes () const { return m_only_occurs_in_notes; } + // Return true if this is a temporary access, e.g. one created for + // an insn that is about to be inserted. + bool is_temporary () const { return m_is_temp; } + protected: access_info (resource_info, access_kind); diff --git a/gcc/rtl-ssa/changes.cc b/gcc/rtl-ssa/changes.cc index 523ad60d7d8..b11a88e0919 100644 --- a/gcc/rtl-ssa/changes.cc +++ b/gcc/rtl-ssa/changes.cc @@ -345,14 +345,20 @@ move_insn (insn_change &change, insn_info *after) // At the moment we don't support moving instructions between EBBs, // but this would be worth adding if it's useful. insn_info *insn = change.insn (); - gcc_assert (after->ebb () == insn->ebb ()); + bb_info *bb = after->bb (); basic_block cfg_bb = bb->cfg_bb (); - if (insn->bb () != bb) - // Force DF to mark the old block as dirty. - df_insn_delete (rtl); - ::remove_insn (rtl); + if (!insn->is_temporary ()) + { + gcc_assert (after->ebb () == insn->ebb ()); + + if (insn->bb () != bb) + // Force DF to mark the old block as dirty. + df_insn_delete (rtl); + ::remove_insn (rtl); + } + ::add_insn_after (rtl, after_rtl, cfg_bb); } @@ -390,10 +396,15 @@ function_info::finalize_new_accesses (insn_change &change, insn_info *pos) gcc_assert (def); if (def->m_is_temp) { - // At present, the only temporary instruction definitions we - // create are clobbers, such as those added during recog. - gcc_assert (is_a (def)); - def = allocate (change.insn (), ref.regno); + if (is_a (def)) + def = allocate (change.insn (), ref.regno); + else if (is_a (def)) + { + def->m_is_temp = false; + def = allocate (change.insn (), def->resource ()); + } + else + gcc_unreachable (); } else if (!def->m_has_been_superceded) { @@ -452,7 +463,9 @@ function_info::finalize_new_accesses (insn_change &change, insn_info *pos) unsigned int i = 0; for (use_info *use : change.new_uses) { - if (!use->m_has_been_superceded) + if (use->m_is_temp) + use->m_has_been_superceded = true; + else if (!use->m_has_been_superceded) { use = allocate_temp (insn, use->resource (), use->def ()); use->m_has_been_superceded = true; @@ -588,6 +601,7 @@ function_info::apply_changes_to_insn (insn_change &change) } add_reg_unused_notes (insn); + insn->m_is_temp = false; } // Add a temporary placeholder instruction after AFTER. @@ -620,7 +634,8 @@ function_info::change_insns (array_slice changes) if (!change->is_deletion ()) { // Remove any notes that are no longer relevant. - update_notes (change->rtl ()); + if (!change->insn ()->m_is_temp) + update_notes (change->rtl ()); // Make sure that the placement of this instruction would still // leave room for previous instructions. @@ -629,6 +644,17 @@ function_info::change_insns (array_slice changes) // verify_insn_changes is supposed to make sure that this holds. gcc_unreachable (); min_insn = later_insn (min_insn, change->move_range.first); + + if (change->insn ()->m_is_temp) + { + change->m_insn = allocate (change->insn ()->bb (), + change->rtl (), + change->insn_uid ()); + + // Set the flag again so subsequent logic is aware. + // It will be cleared later on. + change->m_insn->m_is_temp = true; + } } } @@ -721,7 +747,8 @@ function_info::change_insns (array_slice changes) // Remove the placeholder first so that we have a wider range of // program points when inserting INSN. insn_info *after = placeholder->prev_any_insn (); - remove_insn (insn); + if (!insn->is_temporary ()) + remove_insn (insn); remove_insn (placeholder); insn->set_bb (after->bb ()); add_insn_after (insn, after); @@ -1034,6 +1061,28 @@ function_info::perform_pending_updates () return changed_cfg; } +insn_info * +function_info::create_insn (obstack_watermark &watermark, + rtx_code insn_code, + rtx pat) +{ + rtx_insn *rti = nullptr; + + // TODO: extend, move in to emit-rtl.cc. + switch (insn_code) + { + case INSN: + rti = make_insn_raw (pat); + break; + default: + gcc_unreachable (); + } + + auto insn = change_alloc (watermark, nullptr, rti, INSN_UID (rti)); + insn->m_is_temp = true; + return insn; +} + // Print a description of CHANGE to PP. void rtl_ssa::pp_insn_change (pretty_printer *pp, const insn_change &change) diff --git a/gcc/rtl-ssa/changes.h b/gcc/rtl-ssa/changes.h index d56e3a646e2..d91cf432afe 100644 --- a/gcc/rtl-ssa/changes.h +++ b/gcc/rtl-ssa/changes.h @@ -32,6 +32,8 @@ namespace rtl_ssa { // something that we might do. class insn_change { + friend class function_info; + public: enum delete_action { DELETE }; diff --git a/gcc/rtl-ssa/functions.h b/gcc/rtl-ssa/functions.h index 73690a0e63b..c122fe70e42 100644 --- a/gcc/rtl-ssa/functions.h +++ b/gcc/rtl-ssa/functions.h @@ -68,6 +68,16 @@ public: // Return the SSA information for CFG_BB. bb_info *bb (basic_block cfg_bb) const { return m_bbs[cfg_bb->index]; } + // Create a temporary def. + set_info *create_set (obstack_watermark &watermark, + insn_info *insn, + resource_info resource); + + // Create a temporary insn with code INSN_CODE and pattern PAT. + insn_info *create_insn (obstack_watermark &watermark, + rtx_code insn_code, + rtx pat); + // Return a list of all the instructions in the function, in reverse // postorder. The list includes both real and artificial instructions. // @@ -181,6 +191,10 @@ public: // Print the contents of the function to PP. void print (pretty_printer *pp) const; + // Allocate an object of type T above the obstack watermark WM. + template + T *change_alloc (obstack_watermark &wm, Ts... args); + private: class bb_phi_info; class build_info; diff --git a/gcc/rtl-ssa/insns.cc b/gcc/rtl-ssa/insns.cc index f970375d906..f2898859779 100644 --- a/gcc/rtl-ssa/insns.cc +++ b/gcc/rtl-ssa/insns.cc @@ -192,6 +192,11 @@ insn_info::print_full (pretty_printer *pp) const pp_newline_and_indent (pp, 0); pp_string (pp, "has volatile refs"); } + if (m_is_temp) + { + pp_newline_and_indent (pp, 0); + pp_string (pp, "temporary"); + } } pp_indentation (pp) -= 2; } diff --git a/gcc/rtl-ssa/insns.h b/gcc/rtl-ssa/insns.h index a604fe295cd..6d0506706ad 100644 --- a/gcc/rtl-ssa/insns.h +++ b/gcc/rtl-ssa/insns.h @@ -306,6 +306,8 @@ public: // Print a full description of the instruction. void print_full (pretty_printer *) const; + bool is_temporary () const { return m_is_temp; } + private: // The first-order way of representing the order between instructions // is to assign "program points", with higher point numbers coming @@ -414,8 +416,11 @@ private: unsigned int m_has_pre_post_modify : 1; unsigned int m_has_volatile_refs : 1; + // Indicates the insn is a temporary / new user-allocated insn. + unsigned int m_is_temp : 1; + // For future expansion. - unsigned int m_spare : 27; + unsigned int m_spare : 26; // The program point at which the instruction occurs. // diff --git a/gcc/rtl-ssa/internals.inl b/gcc/rtl-ssa/internals.inl index e49297c12b3..907c4504352 100644 --- a/gcc/rtl-ssa/internals.inl +++ b/gcc/rtl-ssa/internals.inl @@ -415,6 +415,7 @@ inline insn_info::insn_info (bb_info *bb, rtx_insn *rtl, int cost_or_uid) m_is_asm (false), m_has_pre_post_modify (false), m_has_volatile_refs (false), + m_is_temp (false), m_spare (0), m_point (0), m_cost_or_uid (cost_or_uid), diff --git a/gcc/rtl-ssa/member-fns.inl b/gcc/rtl-ssa/member-fns.inl index c127fab8b98..f7185c92751 100644 --- a/gcc/rtl-ssa/member-fns.inl +++ b/gcc/rtl-ssa/member-fns.inl @@ -953,4 +953,16 @@ function_info::add_regno_clobber (obstack_watermark &watermark, return true; } +template +inline T * +function_info::change_alloc (obstack_watermark &wm, Ts... args) +{ + static_assert (std::is_trivially_destructible::value, + "destructor won't be called"); + static_assert (alignof (T) <= obstack_alignment, + "too much alignment required"); + void *addr = XOBNEW (wm, T); + return new (addr) T (std::forward (args)...); +} + } diff --git a/gcc/rtl-ssa/movement.h b/gcc/rtl-ssa/movement.h index d9945f49172..0e94a9870fc 100644 --- a/gcc/rtl-ssa/movement.h +++ b/gcc/rtl-ssa/movement.h @@ -177,6 +177,11 @@ restrict_movement_for_defs_ignoring (insn_range_info &move_range, { for (def_info *def : defs) { + // Skip fresh defs that are being inserted, as these shouldn't + // constrain movement. + if (def->is_temporary ()) + continue; + // If the definition is a clobber, we can move it with respect // to other clobbers. // @@ -242,7 +247,8 @@ restrict_movement_for_defs_ignoring (insn_range_info &move_range, // Make sure that we don't move stores between basic blocks, since we // don't have enough information to tell whether it's safe. - if (def_info *def = memory_access (defs)) + def_info *def = memory_access (defs); + if (def && !def->is_temporary ()) { move_range = move_later_than (move_range, def->bb ()->head_insn ()); move_range = move_earlier_than (move_range, def->bb ()->end_insn ());