From patchwork Sun Nov 5 18:49:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 161763 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp2261267vqu; Sun, 5 Nov 2023 10:49:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IEYu9EVjVkNZkm/1ls05PYgh02ArqxVhpXMeIcjXW0vlC4BucnIzmPNfSgAZVtV4XD1jnh4 X-Received: by 2002:a05:620a:3c81:b0:775:cf5e:a66d with SMTP id tp1-20020a05620a3c8100b00775cf5ea66dmr23896878qkn.24.1699210187901; Sun, 05 Nov 2023 10:49:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1699210187; cv=pass; d=google.com; s=arc-20160816; b=boz1KoKv6IG4MFMk02G0CDr0Y9E2JJ1S0clYqG7UcuxAajz9TGIFCE2XpwUoZutVBE J6mB/IfjVP8zBWWKgWr5RzVP6j0UW58/QUtMHkmDKhWe2Ywj6jW19OANmt9i2j9vY6ze l/KLZDhRrKyiGFMYnQKk+VHOYA0ZOCTy01vsc2m7j5cWtqhB+H/sAEj/PXOQ1YAX0iVk 6Zkg6r7Dh72lme3Ug3PwPpgPtGTtSK4t9AAOtWIsHRHPIAfvuti9hnLXJ1vbAZ+ASEJZ 4AUjsdRGsVxuuxXhiAQwmRr8qqWU+7g2yN+K1trwC1axUR3CIX+yyJ7u4QcgaSDmTl6o FJxA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version:user-agent :message-id:in-reply-to:date:references:subject:cc:mail-followup-to :to:from:arc-filter:dmarc-filter:delivered-to; bh=tran55Tm2MEL4UJ/PnchaWqusJOKsX0MGUQFXyS3h5o=; fh=+zKahnQ9dI9rCMQA/vTUSn1PPyLwgfSULGOjxoIZkos=; b=lYR6ndSTWbZQl3gwhAfnhhfqsumLurd5IwrSQ3N5MoDH8zXs1sVstz9YzXVpIa30Jr vXs/+Sn8t63hzSGSA3gTaANk4LJ3o6umYh0LDKpBwNIg2XFA/gH187LR/bsYvBBP18Dg mir/t/U7xDNK7/rLEgwO+84vVjk/tmhQEOMT9bjKzb9Yi/E4ZLNOFpFpgUYq++3kiJhc 156ECcQm8IYGDgx7bmrFYpG8dnKpoi5xwiR+rwhxvqeerjD4uz1K5jODBd6W8m5xEk0v zUTStXohn7Ba4pnbGvRyNm4Sn/Nf/CZK3Yy9idcnoZIfO/GTWfrmRTlKVekjuc8nZt2M ziqw== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id s16-20020a05620a255000b007770bfc26d8si4686782qko.39.2023.11.05.10.49.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Nov 2023 10:49:47 -0800 (PST) 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; arc=pass (i=1); 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 A77CE3856969 for ; Sun, 5 Nov 2023 18:49:47 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 440023858422 for ; Sun, 5 Nov 2023 18:49:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 440023858422 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 440023858422 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699210165; cv=none; b=Lp7K3JNa2pl9G66D4Re+Dxk2ZUoaykekmtTuYcYAmkm7IeNhMeg7DOcmY5C8jybsfgF5jzAzOucw8Gk2jDL2Vsx7smFNWJ9YmBdN/CXfxFj/g7Q7olgqMm7MuVZqQCd3s/ruQUINkN6g5snWWREfIR3AmgKS+EyTXwlbBzl2bsQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699210165; c=relaxed/simple; bh=TbZRlXcQykvaZnYLfa0s/H/XmiXrmUQjMGdU6HNMbSc=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=vgHt6hcpWOQKvUfntyKJSH7SnyKxS5qo+aprXRkO8zJAzrhSxZmf9OXjsvfbMLUWQ5hRXfq2i4GplcoVqLrSM9cNljlG9ZR7tADnpHWPhXvHKrq6wwB13dmNzncHZa7mxSj98sTURe2v8awSuvnstRU2tNvw45tjsijowZxHRhI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D17C9C15; Sun, 5 Nov 2023 10:50:07 -0800 (PST) Received: from localhost (e121540-lin.manchester.arm.com [10.32.110.72]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8E48E3F703; Sun, 5 Nov 2023 10:49:23 -0800 (PST) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, jlaw@ventanamicro.com, richard.sandiford@arm.com Cc: jlaw@ventanamicro.com Subject: [PATCH 09/12] mode-switching: Pass the set of live registers to the after hook References: Date: Sun, 05 Nov 2023 18:49:22 +0000 In-Reply-To: (Richard Sandiford's message of "Sun, 05 Nov 2023 18:45:29 +0000") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 X-Spam-Status: No, score=-22.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE, URIBL_BLACK 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: 1781751022168097644 X-GMAIL-MSGID: 1781751022168097644 This patch passes the set of live hard registers to the after hook, like the previous one did for the needed hook. gcc/ * target.def (mode_switching.after): Add a regs_live parameter. * doc/tm.texi: Regenerate. * config/epiphany/epiphany-protos.h (epiphany_mode_after): Update accordingly. * config/epiphany/epiphany.cc (epiphany_mode_needed): Likewise. (epiphany_mode_after): Likewise. * config/i386/i386.cc (ix86_mode_after): Likewise. * config/riscv/riscv.cc (riscv_mode_after): Likewise. * config/sh/sh.cc (sh_mode_after): Likewise. * mode-switching.cc (optimize_mode_switching): Likewise. --- gcc/config/epiphany/epiphany-protos.h | 3 ++- gcc/config/epiphany/epiphany.cc | 5 +++-- gcc/config/i386/i386.cc | 2 +- gcc/config/riscv/riscv.cc | 2 +- gcc/config/sh/sh.cc | 5 +++-- gcc/doc/tm.texi | 4 +++- gcc/mode-switching.cc | 8 ++++---- gcc/target.def | 4 +++- 8 files changed, 20 insertions(+), 13 deletions(-) diff --git a/gcc/config/epiphany/epiphany-protos.h b/gcc/config/epiphany/epiphany-protos.h index ef49a1e06a4..ff8987ea99e 100644 --- a/gcc/config/epiphany/epiphany-protos.h +++ b/gcc/config/epiphany/epiphany-protos.h @@ -46,8 +46,9 @@ extern void epiphany_insert_mode_switch_use (rtx_insn *insn, int, int); extern void epiphany_expand_set_fp_mode (rtx *operands); #ifdef HARD_CONST extern int epiphany_mode_needed (int entity, rtx_insn *insn, HARD_REG_SET); +extern int epiphany_mode_after (int entity, int last_mode, rtx_insn *insn, + HARD_REG_SET); #endif -extern int epiphany_mode_after (int entity, int last_mode, rtx_insn *insn); extern bool epiphany_epilogue_uses (int regno); extern bool epiphany_optimize_mode_switching (int entity); extern bool epiphany_is_interrupt_p (tree); diff --git a/gcc/config/epiphany/epiphany.cc b/gcc/config/epiphany/epiphany.cc index 60a9b49d8a4..68e748c688e 100644 --- a/gcc/config/epiphany/epiphany.cc +++ b/gcc/config/epiphany/epiphany.cc @@ -2437,7 +2437,7 @@ epiphany_mode_needed (int entity, rtx_insn *insn, HARD_REG_SET) return 2; case EPIPHANY_MSW_ENTITY_ROUND_KNOWN: if (recog_memoized (insn) == CODE_FOR_set_fp_mode) - mode = (enum attr_fp_mode) epiphany_mode_after (entity, mode, insn); + mode = (enum attr_fp_mode) epiphany_mode_after (entity, mode, insn, {}); /* Fall through. */ case EPIPHANY_MSW_ENTITY_NEAREST: case EPIPHANY_MSW_ENTITY_TRUNC: @@ -2498,7 +2498,8 @@ epiphany_mode_entry_exit (int entity, bool exit) } int -epiphany_mode_after (int entity, int last_mode, rtx_insn *insn) +epiphany_mode_after (int entity, int last_mode, rtx_insn *insn, + HARD_REG_SET) { /* We have too few call-saved registers to hope to keep the masks across calls. */ diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc index 7a5a9a966e8..7b72aabf0da 100644 --- a/gcc/config/i386/i386.cc +++ b/gcc/config/i386/i386.cc @@ -15110,7 +15110,7 @@ ix86_avx_u128_mode_after (int mode, rtx_insn *insn) /* Return the mode that an insn results in. */ static int -ix86_mode_after (int entity, int mode, rtx_insn *insn) +ix86_mode_after (int entity, int mode, rtx_insn *insn, HARD_REG_SET) { switch (entity) { diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index f915de7ed56..e36b5fb9bd0 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -9514,7 +9514,7 @@ riscv_frm_mode_after (rtx_insn *insn, int mode) /* Return the mode that an insn results in. */ static int -riscv_mode_after (int entity, int mode, rtx_insn *insn) +riscv_mode_after (int entity, int mode, rtx_insn *insn, HARD_REG_SET) { switch (entity) { diff --git a/gcc/config/sh/sh.cc b/gcc/config/sh/sh.cc index c363490e852..6ec2eecf754 100644 --- a/gcc/config/sh/sh.cc +++ b/gcc/config/sh/sh.cc @@ -196,7 +196,7 @@ static HOST_WIDE_INT rounded_frame_size (int); static bool sh_frame_pointer_required (void); static void sh_emit_mode_set (int, int, int, HARD_REG_SET); static int sh_mode_needed (int, rtx_insn *, HARD_REG_SET); -static int sh_mode_after (int, int, rtx_insn *); +static int sh_mode_after (int, int, rtx_insn *, HARD_REG_SET); static int sh_mode_entry (int); static int sh_mode_exit (int); static int sh_mode_priority (int entity, int n); @@ -12537,7 +12537,8 @@ sh_mode_needed (int entity ATTRIBUTE_UNUSED, rtx_insn *insn, HARD_REG_SET) } static int -sh_mode_after (int entity ATTRIBUTE_UNUSED, int mode, rtx_insn *insn) +sh_mode_after (int entity ATTRIBUTE_UNUSED, int mode, rtx_insn *insn, + HARD_REG_SET) { if (TARGET_HITACHI && recog_memoized (insn) >= 0 && get_attr_fp_set (insn) != FP_SET_NONE) diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index 144b3f88c37..b730b5bf658 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -10423,12 +10423,14 @@ such requirement. @var{regs_live} contains the set of hard registers that are live before @var{insn}. @end deftypefn -@deftypefn {Target Hook} int TARGET_MODE_AFTER (int @var{entity}, int @var{mode}, rtx_insn *@var{insn}) +@deftypefn {Target Hook} int TARGET_MODE_AFTER (int @var{entity}, int @var{mode}, rtx_insn *@var{insn}, HARD_REG_SET @var{regs_live}) @var{entity} is an integer specifying a mode-switched entity. If this hook is defined, it is evaluated for every @var{insn} during mode switching. It returns the mode that @var{entity} is in after @var{insn} has been executed. @var{mode} is the mode that @var{entity} was in before @var{insn} was executed, taking account of @var{TARGET_MODE_NEEDED}. +@var{regs_live} is the set of hard registers that are live after @var{insn} +has been executed. @var{mode} is equal to the number of modes defined for @var{entity} if the mode before @var{insn} is unknown. The hook should likewise return diff --git a/gcc/mode-switching.cc b/gcc/mode-switching.cc index c5fe90ba449..7a5c4993d65 100644 --- a/gcc/mode-switching.cc +++ b/gcc/mode-switching.cc @@ -632,10 +632,6 @@ optimize_mode_switching (void) last_mode = mode; } - if (targetm.mode_switching.after) - last_mode = targetm.mode_switching.after (e, last_mode, - insn); - /* Update LIVE_NOW. */ for (link = REG_NOTES (insn); link; link = XEXP (link, 1)) if (REG_NOTE_KIND (link) == REG_DEAD) @@ -645,6 +641,10 @@ optimize_mode_switching (void) for (link = REG_NOTES (insn); link; link = XEXP (link, 1)) if (REG_NOTE_KIND (link) == REG_UNUSED) reg_dies (XEXP (link, 0), &live_now); + + if (targetm.mode_switching.after) + last_mode = targetm.mode_switching.after (e, last_mode, + insn, live_now); } } diff --git a/gcc/target.def b/gcc/target.def index 50bad184aca..9b14c037d3f 100644 --- a/gcc/target.def +++ b/gcc/target.def @@ -7042,6 +7042,8 @@ If this hook is defined, it is evaluated for every @var{insn} during mode\n\ switching. It returns the mode that @var{entity} is in after @var{insn}\n\ has been executed. @var{mode} is the mode that @var{entity} was in\n\ before @var{insn} was executed, taking account of @var{TARGET_MODE_NEEDED}.\n\ +@var{regs_live} is the set of hard registers that are live after @var{insn}\n\ +has been executed.\n\ \n\ @var{mode} is equal to the number of modes defined for @var{entity}\n\ if the mode before @var{insn} is unknown. The hook should likewise return\n\ @@ -7049,7 +7051,7 @@ the number of modes if it does not know what mode @var{entity} has after\n\ @var{insn}.\n\ \n\ Not defining the hook is equivalent to returning @var{mode}.", - int, (int entity, int mode, rtx_insn *insn), NULL) + int, (int entity, int mode, rtx_insn *insn, HARD_REG_SET regs_live), NULL) DEFHOOK (entry,