From patchwork Sun Nov 5 18:48:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 161761 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp2261002vqu; Sun, 5 Nov 2023 10:48:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IGpRiBAJYgPgxy4Hu3p3arkWFFcdGEcmBtWrbzT1Z8jp4h0ZJJgjIOgqA2k7SifOIiIAW6V X-Received: by 2002:ac8:7dd1:0:b0:419:4d8a:336 with SMTP id c17-20020ac87dd1000000b004194d8a0336mr32743281qte.60.1699210134853; Sun, 05 Nov 2023 10:48:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1699210134; cv=pass; d=google.com; s=arc-20160816; b=vWdverzMS3YKXGhVfHXj0h7s+3wztBwp8jbBo09fvsLdcVqzzsDvI92QRv6tXxY+16 uV/YYyXZADJmL6BXqRq53dJJ2SjYwSKqCelaTgNTa1+PL2SLMaNcX0u9VagRmG3l9+mU Q3YwIJycmMLMHOl9hvJMTxV/F+5A6BRFIZbrIUIMkY/YkMtAOihsUXe8hrf+/yCEPNF7 pd6oT2WTOK4T4fWFuSLa03C4DA8Lxp4uQenq0Mg3keNzNzyFiEBc+P5pLP1Acaz4dmzm LlGON7YNQhgRihueecF4pXW4uE6BGXOMmrAhvZNgwIQWD1Ss7G8NKKRW1Wd2tDaWLXLL bEQA== 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=fTy5pmMHvAVoil8cXSnVa8Bg3Aha5mAGYgEY6S1CWLE=; fh=+zKahnQ9dI9rCMQA/vTUSn1PPyLwgfSULGOjxoIZkos=; b=TxPCmQmL0JufjvRrjjFgs0ziK1lwX60AclpurvxqbnwfEtTqW+GD7CWAiMGNBI8YHe JPffUnZomBH6+KlkggPWbVZELfmbGjqEQ6PWZT1TWgHfik7IvJhuYq3hBxd5uFpg/Si1 uGshbblcOhP9RerXU/SSXRFZ8QO3rkkmy9o0GE8yMxB020wi/cibnmdPscVFO/dVH0Px QfbFVPHQl6VvnWbXfh31+YjQBnAqVvu3SGATcpVDIvxE5vRH5Q0Xi3MyXtg+z4q6rNNJ 7UZhzZwDC6roMv4hp8K/Bq2PUJtiu9uibT52wUZIMd0ORSiESVV4j55I9f+B5DhYshrt bJxw== 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 z7-20020a05622a060700b00419578c5b2fsi4501733qta.281.2023.11.05.10.48.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Nov 2023 10:48:54 -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 902D13857BA4 for ; Sun, 5 Nov 2023 18:48:54 +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 9ADBA3856943 for ; Sun, 5 Nov 2023 18:48:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9ADBA3856943 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 9ADBA3856943 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=1699210112; cv=none; b=CAGJXGZu0Q/jC/3Mb9hcsRtHT1L+kwyadS6dlgt/9zMFdPyNQhP8PC7QjDTLH5mzDvC1/katlG5aXn10rkptsxzqX3Ev7P75zVw3qGREq6L67hzjjU+Bdx9tjevPGydxdnKFtVkb+ZhKuhSV9zAnLOg7hXmix3zwqPtJWhzqVFQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699210112; c=relaxed/simple; bh=i5vhLQVtM7W+fzUGxizUHvdV3xavEj0J1gsNHxXqJGE=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=jj6T2qnVR4rECFYgwCX0QX1slhufj5kHzJaFUCUsX/3oZj9E8pcymu2LjORxuXucAJb/bK/d0gQC0XbHhac/MfKG/Nzwp09Fm8yrvb5zyk8Ew6JdpSnNpQPRcWmlEk3syggzqOJ1mzwGwSO2UrTipHUzLiTyI3bwfyKrHkK39Bs= 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 30C6EC15; Sun, 5 Nov 2023 10:49:15 -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 E1B7F3F703; Sun, 5 Nov 2023 10:48:30 -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 07/12] mode-switching: Allow targets to set the mode for EH handlers References: Date: Sun, 05 Nov 2023 18:48:29 +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=-23.4 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 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: 1781750966429540547 X-GMAIL-MSGID: 1781750966429540547 The mode-switching pass already had hooks to say what mode an entity is in on entry to a function and what mode it must be in on return. For SME, we also want to say what mode an entity is guaranteed to be in on entry to an exception handler. gcc/ * target.def (mode_switching.eh_handler): New hook. * doc/tm.texi.in (TARGET_MODE_EH_HANDLER): New @hook. * doc/tm.texi: Regenerate. * mode-switching.cc (optimize_mode_switching): Use eh_handler to get the mode on entry to an exception handler. --- gcc/doc/tm.texi | 6 ++++++ gcc/doc/tm.texi.in | 2 ++ gcc/mode-switching.cc | 5 ++++- gcc/target.def | 7 +++++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index 759331a2c96..1a825c5004e 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -10455,6 +10455,12 @@ If @code{TARGET_MODE_EXIT} is defined then @code{TARGET_MODE_ENTRY} must be defined. @end deftypefn +@deftypefn {Target Hook} int TARGET_MODE_EH_HANDLER (int @var{entity}) +If this hook is defined, it should return the mode that @var{entity} is +guaranteed to be in on entry to an exception handler, or the number of modes +if there is no such guarantee. +@end deftypefn + @deftypefn {Target Hook} int TARGET_MODE_PRIORITY (int @var{entity}, int @var{n}) This hook specifies the order in which modes for @var{entity} are processed. 0 is the highest priority, diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in index a7b7aa289d8..5360c1bb2d8 100644 --- a/gcc/doc/tm.texi.in +++ b/gcc/doc/tm.texi.in @@ -6979,6 +6979,8 @@ mode or ``no mode'', depending on context. @hook TARGET_MODE_EXIT +@hook TARGET_MODE_EH_HANDLER + @hook TARGET_MODE_PRIORITY @node Target Attributes diff --git a/gcc/mode-switching.cc b/gcc/mode-switching.cc index 1145350ca26..b8a887d81f7 100644 --- a/gcc/mode-switching.cc +++ b/gcc/mode-switching.cc @@ -597,7 +597,10 @@ optimize_mode_switching (void) gcc_assert (NOTE_INSN_BASIC_BLOCK_P (ins_pos)); if (ins_pos != BB_END (bb)) ins_pos = NEXT_INSN (ins_pos); - ptr = new_seginfo (no_mode, no_mode, ins_pos, live_now); + if (bb_has_eh_pred (bb) + && targetm.mode_switching.eh_handler) + last_mode = targetm.mode_switching.eh_handler (e); + ptr = new_seginfo (no_mode, last_mode, ins_pos, live_now); add_seginfo (&tail_ptr, ptr); bitmap_clear_bit (transp_all, bb->index); } diff --git a/gcc/target.def b/gcc/target.def index 3dae33522f1..a70275b8abd 100644 --- a/gcc/target.def +++ b/gcc/target.def @@ -7070,6 +7070,13 @@ If @code{TARGET_MODE_EXIT} is defined then @code{TARGET_MODE_ENTRY}\n\ must be defined.", int, (int entity), NULL) +DEFHOOK +(eh_handler, + "If this hook is defined, it should return the mode that @var{entity} is\n\ +guaranteed to be in on entry to an exception handler, or the number of modes\n\ +if there is no such guarantee.", + int, (int entity), NULL) + DEFHOOK (priority, "This hook specifies the order in which modes for @var{entity}\n\