From patchwork Sun Nov 5 18:32:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 161752 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp2256173vqu; Sun, 5 Nov 2023 10:32:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IHoU0w26NDzxHFwR1o1eba/mNv7JjMCG+9sJ9spRmrFOKgBrKmZKDzo/RBkZId+/x47IZPV X-Received: by 2002:a05:620a:2846:b0:779:deb9:72c6 with SMTP id h6-20020a05620a284600b00779deb972c6mr30725042qkp.14.1699209163074; Sun, 05 Nov 2023 10:32:43 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1699209163; cv=pass; d=google.com; s=arc-20160816; b=tgcACCQ0BKdLFr+K/DIv9xBzEIBCFhnpehTCgyz9vRj/2H0wnukzzm/ykIjVYAhJCM 5nmgx34NfMmGr2IX/4zzAW7MAhAMgK65oU0A3ehHlEYk+Nr6875/N8qpR5GNPp2xfyP6 RpS0Amdq950E3WH9ldzwvelGa36fsBFNkWhu1/DO9QS3z6d367agTJuJpDdORJUZAhNs wAn4m4iLy6By93ZKblqoK4j/fsupqeG2GIOUOsKW0fjFbVc+HA27e/jqWZnHmFjlvxts zC+DKtsO7ArZ7SOegyTbVhlD+QbnwB+i6SeOff89WOmnp1QOwgaM5FxcCuQ4it5jJJxM Uy5Q== 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:date:subject:mail-followup-to:to:from:arc-filter :dmarc-filter:delivered-to; bh=i/LNsGKWkZvPCFBgRpbab0covYHzZ33JpCl+w6dNAC4=; fh=hPrbWPhweUx4V0GV9uXJqbyAzg2ABmTz7kczrAQqMmM=; b=CGZR4mBvNBWpci2aW4kzi0VNwlqWsagmV6kXHC79xOIgq1XY9BzDOc9mG6ngJs1P09 ZTLSpkP+M3SgB7WI7SZhSYLdKRg2hCEv8ESgkzvMrdRDXCgkusZPGJLYPJ/qymrSfggO Xo03E2kcT8LMDZmxwZ5gtbFs8YfjvgpP707SwiBXYmVC5Bm5Spkzgvda9fvd++qUtROP SWraf4tyHXMkuh37KEHVgcIICnJS1v4h292x6oPjb9s4M0IaedVJ583jvujsgXm58KDn YHA8DqiDNLpl/VMU5Qkn6KmJoFix1BVH7ssQAY1CSVLdNzN6lWCuePNDohWfJOK2QUD4 O0Qg== 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 f1-20020a05620a280100b007788fc003aasi4716610qkp.618.2023.11.05.10.32.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Nov 2023 10:32:43 -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 C0B623857006 for ; Sun, 5 Nov 2023 18:32:42 +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 0EE133858CDB for ; Sun, 5 Nov 2023 18:32:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0EE133858CDB 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 0EE133858CDB 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=1699209140; cv=none; b=RIZ8atsi59NEBweTb7xa8M/YdzE1cAZWNlkyNDmziTCteUPx2b3s0iFEoqSWxPGtcu0B7OgXkLbCcbLYE8QZ/1GBfG7qsY6xka5zDCC6/SZ5XJJsVVCMWEBLsbpvvgnCYaINd8aJC7m0r1v4ZqJz278oNliVClTtSDB9y/GKTXs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699209140; c=relaxed/simple; bh=01BBfUOdlUxn2MNx/Rws8FYvN27NfZDlTWSQkaRhkG0=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=RoIZy3zhOSri57vUjiuYmrsvQpH9nSVS2Rp2vEDX3VgClivOhkw+rSiVn8cnT+qIo1eKZnVH9UXXAxQwdiHvwGD00aHzx4VBSc88hgGuWR/SwBkilOnP28xdu3shfZ0d78sSomxAgWoACROH4gGXSVXSqaMvOaBBucGKWFvtKBE= 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 880EAC15 for ; Sun, 5 Nov 2023 10:33: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 613993F703 for ; Sun, 5 Nov 2023 10:32:18 -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] explow: Allow dynamic allocations after vregs Date: Sun, 05 Nov 2023 18:32:17 +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: 1781749947261158019 X-GMAIL-MSGID: 1781749947261158019 This patch allows allocate_dynamic_stack_space to be called before or after virtual registers have been instantiated. It uses the same approach as allocate_stack_local, which already supported this. Tested on aarch64-linux-gnu & x86_64-linux-gnu. OK to install? Richard gcc/ * function.h (get_stack_dynamic_offset): Declare. * function.cc (get_stack_dynamic_offset): New function, split out from... (get_stack_dynamic_offset): ...here. * explow.cc (allocate_dynamic_stack_space): Handle calls made after virtual registers have been instantiated. --- gcc/explow.cc | 10 +++++++--- gcc/function.cc | 12 +++++++++++- gcc/function.h | 1 + 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/gcc/explow.cc b/gcc/explow.cc index 0c03ac350bb..aa64d5e906c 100644 --- a/gcc/explow.cc +++ b/gcc/explow.cc @@ -1375,12 +1375,16 @@ allocate_dynamic_stack_space (rtx size, unsigned size_align, HOST_WIDE_INT stack_usage_size = -1; rtx_code_label *final_label; rtx final_target, target; + rtx addr = (virtuals_instantiated + ? plus_constant (Pmode, stack_pointer_rtx, + get_stack_dynamic_offset ()) + : virtual_stack_dynamic_rtx); /* If we're asking for zero bytes, it doesn't matter what we point to since we can't dereference it. But return a reasonable address anyway. */ if (size == const0_rtx) - return virtual_stack_dynamic_rtx; + return addr; /* Otherwise, show we're calling alloca or equivalent. */ cfun->calls_alloca = 1; @@ -1532,7 +1536,7 @@ allocate_dynamic_stack_space (rtx size, unsigned size_align, poly_int64 saved_stack_pointer_delta; if (!STACK_GROWS_DOWNWARD) - emit_move_insn (target, virtual_stack_dynamic_rtx); + emit_move_insn (target, force_operand (addr, target)); /* Check stack bounds if necessary. */ if (crtl->limit_stack) @@ -1575,7 +1579,7 @@ allocate_dynamic_stack_space (rtx size, unsigned size_align, stack_pointer_delta = saved_stack_pointer_delta; if (STACK_GROWS_DOWNWARD) - emit_move_insn (target, virtual_stack_dynamic_rtx); + emit_move_insn (target, force_operand (addr, target)); } suppress_reg_args_size = false; diff --git a/gcc/function.cc b/gcc/function.cc index afb0b33da9e..527ea4807b0 100644 --- a/gcc/function.cc +++ b/gcc/function.cc @@ -1943,6 +1943,16 @@ instantiate_decls (tree fndecl) vec_free (cfun->local_decls); } +/* Return the value of STACK_DYNAMIC_OFFSET for the current function. + This is done through a function wrapper so that the macro sees a + predictable set of included files. */ + +poly_int64 +get_stack_dynamic_offset () +{ + return STACK_DYNAMIC_OFFSET (current_function_decl); +} + /* Pass through the INSNS of function FNDECL and convert virtual register references to hard register references. */ @@ -1954,7 +1964,7 @@ instantiate_virtual_regs (void) /* Compute the offsets to use for this function. */ in_arg_offset = FIRST_PARM_OFFSET (current_function_decl); var_offset = targetm.starting_frame_offset (); - dynamic_offset = STACK_DYNAMIC_OFFSET (current_function_decl); + dynamic_offset = get_stack_dynamic_offset (); out_arg_offset = STACK_POINTER_OFFSET; #ifdef FRAME_POINTER_CFA_OFFSET cfa_offset = FRAME_POINTER_CFA_OFFSET (current_function_decl); diff --git a/gcc/function.h b/gcc/function.h index 5caf1e153ea..29846564bc6 100644 --- a/gcc/function.h +++ b/gcc/function.h @@ -715,6 +715,7 @@ extern vec convert_jumps_to_returns (basic_block last_bb, bool simple_p, extern basic_block emit_return_for_exit (edge exit_fallthru_edge, bool simple_p); extern void reposition_prologue_and_epilogue_notes (void); +extern poly_int64 get_stack_dynamic_offset (); /* Returns the name of the current function. */ extern const char *fndecl_name (tree);