From patchwork Fri Jan 5 16:28:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 1883068 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4T68605J1Kz1yP4 for ; Sat, 6 Jan 2024 03:28:40 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B68AC385332C for ; Fri, 5 Jan 2024 16:28:38 +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 C85743858CD1 for ; Fri, 5 Jan 2024 16:28:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C85743858CD1 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 C85743858CD1 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=1704472098; cv=none; b=oZTPboL201Mql8uGs7fP3PzZikycf/a7rhcIFLPeis5jxR+w/ggTXFco9aqbeIUFnkGnpq/tqOhPVWfpj5HfaqZ/A4JejPcJMRHqPub0yzgzkHYEK4IN8IdZC2LI+cS0BIfetnXY21z8Md4fVgKdcDSoOJjDDo2jM7B8WpV4Dwo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704472098; c=relaxed/simple; bh=yn7IkTBmPBbvwke9Bmq3tpjx5BTPgnuTg6uARhcT3gY=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=EvErDVf0h6B5lSG0vQibubfQxi4aI6pJXOEpmdTzyl0nYj94aGkna96iCHeV6mHX2Ll+4U4ihaVSJSdYu7m/0sfS1BwP5YbgINE8JZKgpHUZ6x9R+5o1n7i9s/uLoAd1DmLrtZKxjTZDmNF3lxbYszVmRc0xE+r+ZkcqCrECoYo= 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 DCD7DC15 for ; Fri, 5 Jan 2024 08:29:02 -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 28D713F64C for ; Fri, 5 Jan 2024 08:28:16 -0800 (PST) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: [PATCH] Keep track of the FUNCTION_BEG note Date: Fri, 05 Jan 2024 16:28:14 +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=-21.5 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+incoming=patchwork.ozlabs.org@gcc.gnu.org function.cc emits a NOTE_FUNCTION_BEG after all arguments have been copied to pseudos. It then records this note in parm_birth_insn. Various other pieces of code use this insn as a convenient place to insert things at the start of the function. However, cfgexpand later changes parm_birth_insn as follows: /* If we emitted any instructions for setting up the variables, emit them before the FUNCTION_START note. */ if (var_seq) { emit_insn_before (var_seq, parm_birth_insn); /* In expand_function_end we'll insert the alloca save/restore before parm_birth_insn. We've just insertted an alloca call. Adjust the pointer to match. */ parm_birth_insn = var_seq; } But the FUNCTION_BEG note is still useful for things that aren't sensitive to stack allocation, and it has the advantage that (unlike the var_seq above) it is never deleted or combined. This patch adds a separate variable to track it. Tested on aarch64-linux-gnu, where it's needed for fixing PR113196. OK to install? Richard gcc/ * emit-rtl.h (rtl_data::x_function_beg_note): New member variable. (function_beg_insn): New macro. * function.cc (expand_function_start): Initialize function_beg_insn. --- gcc/emit-rtl.h | 4 ++++ gcc/function.cc | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/gcc/emit-rtl.h b/gcc/emit-rtl.h index f749ca9f2a0..34f44cb2990 100644 --- a/gcc/emit-rtl.h +++ b/gcc/emit-rtl.h @@ -141,6 +141,9 @@ struct GTY(()) rtl_data { If stack grows up, this is the address for the next slot. */ poly_int64 x_frame_offset; + /* The function's FUNCTION_BEG note. */ + rtx_insn *x_function_beg_insn; + /* Insn after which register parms and SAVE_EXPRs are born, if nonopt. */ rtx_insn *x_parm_birth_insn; @@ -323,6 +326,7 @@ struct GTY(()) rtl_data { #define return_label (crtl->x_return_label) #define naked_return_label (crtl->x_naked_return_label) #define stack_slot_list (crtl->x_stack_slot_list) +#define function_beg_insn (crtl->x_function_beg_insn) #define parm_birth_insn (crtl->x_parm_birth_insn) #define frame_offset (crtl->x_frame_offset) #define stack_check_probe_note (crtl->x_stack_check_probe_note) diff --git a/gcc/function.cc b/gcc/function.cc index de356f7fba3..5ffd438475e 100644 --- a/gcc/function.cc +++ b/gcc/function.cc @@ -5202,7 +5202,7 @@ expand_function_start (tree subr) gcc_assert (NOTE_P (get_last_insn ())); - parm_birth_insn = get_last_insn (); + function_beg_insn = parm_birth_insn = get_last_insn (); /* If the function receives a non-local goto, then store the bits we need to restore the frame pointer. */