From patchwork Sat May 25 12:12:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 1939254 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=UAqJIxjt; dkim-atps=neutral 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 4Vmgls1J8sz20KL for ; Sat, 25 May 2024 22:12:55 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 91667385E833 for ; Sat, 25 May 2024 12:12:53 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by sourceware.org (Postfix) with ESMTPS id 8EC153858CD9 for ; Sat, 25 May 2024 12:12:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8EC153858CD9 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8EC153858CD9 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716639154; cv=none; b=WFGXHTfATw/8aFL3qnCf2kxlmjhV9cdqPoTLJhmcNNhsaApe4Lixs/I+gONW6v03DWkWfxkwwWMyjhsvbfxMYEYJy/5BqlZ/VNzBKswlP9We4UoLGARR5DgcAZnCndZKo9gIaGLjkO51koFENazJF0GDyluzOTA5xiRWYlNhkhM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716639154; c=relaxed/simple; bh=rmc7AObPd30KpXWsiOm5LDO0j35NGxPgLBNHjnyAm6s=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=rc/dKGcOKjLPCaY/czIClkNzb88COxxkfEFHGm2dcAIJjhgeP2DWqlLw+odWelJwVLMz9d4vJaHb0W61eYBaKpA/bFqpQct2LlKDW7fQACGLpBNJpnQns64ChyCIHX0PNJ2ogxBwlkdt4PO049MbRALPlX2JMABrE96uDilrzIY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1f44b594deeso12844405ad.2 for ; Sat, 25 May 2024 05:12:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1716639150; x=1717243950; darn=gcc.gnu.org; h=mime-version:user-agent:message-id:in-reply-to:date:references :organization:subject:cc:to:from:from:to:cc:subject:date:message-id :reply-to; bh=e9Tn+1dGvNHUB685ZWBH2VeA/vpEICQ1x+hXb62xwmY=; b=UAqJIxjtVGaSwSyEVXZXBjLipu/pvnyPKW4mMqoslWDi8Wch0GGJY75m95wB2o+XHA 5HroBEpRuonfhWaGjbPtanzOByS71nhITd364EgO0H3QPqgmFGbhSW8KWExdFoGKwC4h odfml7/S8Wl4ZAR34j5df0PxHcGNs59SDVs0tfi+0SXE3putpjf08hYc7iRpGCZ4fevS bwmf+gjPNQWNpuEl+RKtZoj9QEYB6BeSHCV+6Z875bUlb+V/xkbyop2l1Z/K6ZiJ554w eKa8vgcDJ1yMlnemVuEhJosAxcjIlcAMvWhYGW8s7DBHjvkYBD3pIOUyR/5qRiFrbKNG ihyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716639150; x=1717243950; h=mime-version:user-agent:message-id:in-reply-to:date:references :organization:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=e9Tn+1dGvNHUB685ZWBH2VeA/vpEICQ1x+hXb62xwmY=; b=l8EaN2H2Zhporcv0EzFF98BGKSHO2mW//exK/bWkY2gyl9FlwXrhqx4gxtNLL1WrZ6 nGi8SINGcogIdtMFM8KQaWlxwQWQDSOAHatmn63ksp2Bk0zJcnPG5nUVHRukqghPb2ql 5/+sQtNM09YU2gjTB1JP8DvqUhTcEV1IijhMuAc79reuBvb0eyKxmRMevwp044elFR2M OU1QOWIHulUV9RgDLRH3UQgNCHwGYGvEGLVW3X64GMVNUZnWfgT5tees4CRB0uzopzYj /V+E9ocFfyMLcvEMWqLYKoJB85CMGOu4Hh73ILm69U1xrW9mp/Aa+kgPPe60EOKdH01S n/1Q== X-Gm-Message-State: AOJu0Yw/86l0eL53SJbNiC7suvuQXhd9mmxBRgFvmYAFQNBwqWdS4Hg0 8aJ51UbLqTo5HuhSEwHLWALc/PjTr/b8vIvfnbTrl8bR/vK6LTbmsmg9wPDyX6RlLmxKXr5hDXv fAv81 X-Google-Smtp-Source: AGHT+IGiWfrOj0D7x/rin4s1PAgy4EiqyeLqf7Ti1WJZ1ON1/9ht+35mjLZKfdKxUA7MnUkh6AI2LQ== X-Received: by 2002:a17:902:ec8d:b0:1f4:5895:200f with SMTP id d9443c01a7336-1f458952222mr41045755ad.68.1716639150231; Sat, 25 May 2024 05:12:30 -0700 (PDT) Received: from free.home ([2804:7f1:218b:1961:ef8:d680:5399:8b1a]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f47bde1620sm2137945ad.249.2024.05.25.05.12.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 May 2024 05:12:29 -0700 (PDT) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTPS id 44PCC5b0263612 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 25 May 2024 09:12:06 -0300 From: Alexandre Oliva To: gcc-patches@gcc.gnu.org Cc: Tom Tromey , Jason Merrill , Cary Coutant , Jakub Jelinek , David Edelsohn , Segher Boessenkool , Kewen Lin Subject: [PATCH v3 #1/2] enable adjustment of return_pc debug attrs Organization: Free thinker, does not speak for AdaCore References: Date: Sat, 25 May 2024 09:12:05 -0300 In-Reply-To: (Alexandre Oliva's message of "Thu, 27 Apr 2023 06:40:21 -0300") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, WEIRD_QUOTING 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 On Apr 27, 2023, Alexandre Oliva wrote: > On Apr 14, 2023, Alexandre Oliva wrote: >> On Mar 23, 2023, Alexandre Oliva wrote: >>> This patch introduces infrastructure for targets to add an offset to >>> the label issued after the call_insn to set the call_return_pc >>> attribute. This will be used on rs6000, that sometimes issues another >>> instruction after the call proper as part of a call insn. >> Ping? >> https://gcc.gnu.org/pipermail/gcc-patches/2023-March/614452.html Ping? Refreshed, retested on ppc64le-linux-gnu. Ok to install? This patch introduces infrastructure for targets to add an offset to the label issued after the call_insn to set the call_return_pc attribute. This will be used on rs6000, that sometimes issues another instruction after the call proper as part of a call insn. for gcc/ChangeLog * target.def (call_offset_return_label): New hook. * gcc/doc/tm.texi.in (TARGET_CALL_OFFSET_RETURN_LABEL): Add placeholder. * gcc/doc/tm.texi: Rebuild. * dwarf2out.cc (struct call_arg_loc_node): Record call_insn instad of call_arg_loc_note. (add_AT_lbl_id): Add optional offset argument. (gen_call_site_die): Compute and pass on a return pc offset. (gen_subprogram_die): Move call_arg_loc_note computation... (dwarf2out_var_location): ... from here. Set call_insn. --- gcc/doc/tm.texi | 7 +++++++ gcc/doc/tm.texi.in | 2 ++ gcc/dwarf2out.cc | 26 +++++++++++++++++--------- gcc/target.def | 9 +++++++++ 4 files changed, 35 insertions(+), 9 deletions(-) diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index cd50078227d98..8a7aa70d605ba 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -5557,6 +5557,13 @@ except the last are treated as named. You need not define this hook if it always returns @code{false}. @end deftypefn +@deftypefn {Target Hook} int TARGET_CALL_OFFSET_RETURN_LABEL (rtx_insn *@var{call_insn}) +While generating call-site debug info for a CALL insn, or a SEQUENCE +insn starting with a CALL, this target hook is invoked to compute the +offset to be added to the debug label emitted after the call to obtain +the return address that should be recorded as the return PC. +@end deftypefn + @deftypefn {Target Hook} void TARGET_START_CALL_ARGS (cumulative_args_t @var{complete_args}) This target hook is invoked while generating RTL for a function call, after the argument values have been computed, and after stack arguments diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in index 058bd56487a9a..9e0830758aeea 100644 --- a/gcc/doc/tm.texi.in +++ b/gcc/doc/tm.texi.in @@ -3887,6 +3887,8 @@ These machine description macros help implement varargs: @hook TARGET_STRICT_ARGUMENT_NAMING +@hook TARGET_CALL_OFFSET_RETURN_LABEL + @hook TARGET_START_CALL_ARGS @hook TARGET_CALL_ARGS diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc index 5b064ffd78ad1..1092880738df4 100644 --- a/gcc/dwarf2out.cc +++ b/gcc/dwarf2out.cc @@ -3593,7 +3593,7 @@ typedef struct var_loc_list_def var_loc_list; /* Call argument location list. */ struct GTY ((chain_next ("%h.next"))) call_arg_loc_node { - rtx GTY (()) call_arg_loc_note; + rtx_insn * GTY (()) call_insn; const char * GTY (()) label; tree GTY (()) block; bool tail_call_p; @@ -3777,7 +3777,8 @@ static void remove_addr_table_entry (addr_table_entry *); static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx, bool); static inline rtx AT_addr (dw_attr_node *); static void add_AT_symview (dw_die_ref, enum dwarf_attribute, const char *); -static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *); +static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *, + int = 0); static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *); static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *); static void add_AT_range_list (dw_die_ref, enum dwarf_attribute, @@ -5353,14 +5354,17 @@ add_AT_symview (dw_die_ref die, enum dwarf_attribute attr_kind, static inline void add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, - const char *lbl_id) + const char *lbl_id, int offset) { dw_attr_node attr; attr.dw_attr = attr_kind; attr.dw_attr_val.val_class = dw_val_class_lbl_id; attr.dw_attr_val.val_entry = NULL; - attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id); + if (!offset) + attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id); + else + attr.dw_attr_val.v.val_lbl_id = xasprintf ("%s%+i", lbl_id, offset); if (dwarf_split_debug_info) attr.dw_attr_val.val_entry = add_addr_table_entry (attr.dw_attr_val.v.val_lbl_id, @@ -23515,7 +23519,9 @@ gen_call_site_die (tree decl, dw_die_ref subr_die, if (stmt_die == NULL) stmt_die = subr_die; die = new_die (dwarf_TAG (DW_TAG_call_site), stmt_die, NULL_TREE); - add_AT_lbl_id (die, dwarf_AT (DW_AT_call_return_pc), ca_loc->label); + add_AT_lbl_id (die, dwarf_AT (DW_AT_call_return_pc), + ca_loc->label, + targetm.calls.call_offset_return_label (ca_loc->call_insn)); if (ca_loc->tail_call_p) add_AT_flag (die, dwarf_AT (DW_AT_call_tail_call), 1); if (ca_loc->symbol_ref) @@ -24202,11 +24208,14 @@ gen_subprogram_die (tree decl, dw_die_ref context_die) { dw_die_ref die = NULL; rtx tloc = NULL_RTX, tlocc = NULL_RTX; + rtx call_arg_loc_note + = find_reg_note (ca_loc->call_insn, + REG_CALL_ARG_LOCATION, NULL_RTX); rtx arg, next_arg; tree arg_decl = NULL_TREE; - for (arg = (ca_loc->call_arg_loc_note != NULL_RTX - ? XEXP (ca_loc->call_arg_loc_note, 0) + for (arg = (call_arg_loc_note != NULL_RTX + ? XEXP (call_arg_loc_note, 0) : NULL_RTX); arg; arg = next_arg) { @@ -28251,8 +28260,7 @@ create_label: = ggc_cleared_alloc (); rtx_insn *prev = call_insn; - ca_loc->call_arg_loc_note - = find_reg_note (call_insn, REG_CALL_ARG_LOCATION, NULL_RTX); + ca_loc->call_insn = call_insn; ca_loc->next = NULL; ca_loc->label = last_label; gcc_assert (prev diff --git a/gcc/target.def b/gcc/target.def index c27df8095be15..70070caebc768 100644 --- a/gcc/target.def +++ b/gcc/target.def @@ -4890,6 +4890,15 @@ Most ports do not need to implement anything for this hook.", void, (cumulative_args_t complete_args), hook_void_CUMULATIVE_ARGS) +DEFHOOK +(call_offset_return_label, + "While generating call-site debug info for a CALL insn, or a SEQUENCE\n\ +insn starting with a CALL, this target hook is invoked to compute the\n\ +offset to be added to the debug label emitted after the call to obtain\n\ +the return address that should be recorded as the return PC.", + int, (rtx_insn *call_insn), + hook_int_rtx_insn_0) + DEFHOOK (push_argument, "This target hook returns @code{true} if push instructions will be\n\