From patchwork Sat Jun 22 18:54:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Kleen X-Patchwork-Id: 1951115 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; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=iu7KAjc5; 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 4W63Nw44Hrz20Xt for ; Sun, 23 Jun 2024 04:56:48 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 36988385DDD8 for ; Sat, 22 Jun 2024 18:56:46 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) by sourceware.org (Postfix) with ESMTPS id E14273858C56 for ; Sat, 22 Jun 2024 18:56:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E14273858C56 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.intel.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=linux.intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E14273858C56 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=198.175.65.17 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719082570; cv=none; b=i4l506ehltIp1xea74qNuYL1YMt4VbiJKimVlivXgxTnF00pnfeDzn2B560vIa+kFnDd2OEMhSdXRXFHFFokiCOA/6RNZQHlbYOCK98wqnbaNLZYU6/IwNKxNIgjUnJAYCaSgLOrfINbc4QiI8jF4/wfkhUnA5sDMpi2dbAap6I= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719082570; c=relaxed/simple; bh=E1YIWS6tT9/dkiL3kVwo8TIwtDjiyXCn5kgTQMJpiek=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=fl7VkfSZCg+7GxKCmEwZrAAhJAWTIs5mxW3VC+5wEblDjHEXXJSBW5LYfSMIJH+wYSdMb44w3GDiSj/1p5EmwyXkiCGasi5o4E3mBN9Xtf1ua5M+kmLlooCSUtLY/8WVs4By3Dbclpp0D3NIvs5Rt1lO2jyLVBqbhM6OtIE3aU4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719082567; x=1750618567; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=E1YIWS6tT9/dkiL3kVwo8TIwtDjiyXCn5kgTQMJpiek=; b=iu7KAjc5+xB+5MzDPDu2tmrFzl0NqXC+h8doqMzAR8D7vXVdeYqEXeGL 5GY3lGldmFiLvpvhhaShyCOAA/avWNRmS2XaqP/gdijn06RqgWyy+qJwb lQhXvNUz2o0/VvgzUAMv3GPredOvQ1kWiV1OiQhzpR85R6osqcSOzDA2P IKJ7H8JY/dAIMWoL+ovlNSZEVAeG2UQD19RW/vYtRmgHDDHOxOoUydXVK A93ufasTfAmkgTaAwK0gXg/W6iid7x2HaIGYWjLSCxwT5qHi1pw1OEhag X04mhThUI0iT+anQh7WMi612Dfm/BODKVAZnT/CHveLbtUT9M/0+uvCgG A==; X-CSE-ConnectionGUID: N8BRpWxiQEmsoBy6bLUzGA== X-CSE-MsgGUID: Dp40DqVpSkmKvxyAjViVag== X-IronPort-AV: E=McAfee;i="6700,10204,11111"; a="16216437" X-IronPort-AV: E=Sophos;i="6.08,258,1712646000"; d="scan'208";a="16216437" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2024 11:56:05 -0700 X-CSE-ConnectionGUID: T/04zPo4SeSkhvlbJfVO9A== X-CSE-MsgGUID: vYt8Gfj4T8qkzIl2zHS1bw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,258,1712646000"; d="scan'208";a="42968331" Received: from tassilo.jf.intel.com ([10.54.38.190]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2024 11:56:04 -0700 From: Andi Kleen To: gcc-patches@gcc.gnu.org Cc: Andi Kleen Subject: [PATCH v8 01/12] Improve must tail in RTL backend Date: Sat, 22 Jun 2024 11:54:33 -0700 Message-ID: <20240622185557.1589179-2-ak@linux.intel.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240622185557.1589179-1-ak@linux.intel.com> References: <20240622185557.1589179-1-ak@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_NONE, TXREP 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 - Give error messages for all causes of non sibling call generation - When giving error messages clear the musttail flag to avoid ICEs - Error out when tree-tailcall failed to mark a must-tail call sibcall. In this case it doesn't know the true reason and only gives a vague message. PR83324 gcc/ChangeLog: * calls.cc (maybe_complain_about_tail_call): Clear must tail flag on error. (expand_call): Give error messages for all musttail failures. --- gcc/calls.cc | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/gcc/calls.cc b/gcc/calls.cc index 21d78f9779fe..883eb9971257 100644 --- a/gcc/calls.cc +++ b/gcc/calls.cc @@ -1249,6 +1249,7 @@ maybe_complain_about_tail_call (tree call_expr, const char *reason) return; error_at (EXPR_LOCATION (call_expr), "cannot tail-call: %s", reason); + CALL_EXPR_MUST_TAIL_CALL (call_expr) = 0; } /* Fill in ARGS_SIZE and ARGS array based on the parameters found in @@ -2650,7 +2651,13 @@ expand_call (tree exp, rtx target, int ignore) /* The type of the function being called. */ tree fntype; bool try_tail_call = CALL_EXPR_TAILCALL (exp); - bool must_tail_call = CALL_EXPR_MUST_TAIL_CALL (exp); + /* tree-tailcall decided not to do tail calls. Error for the musttail case, + unfortunately we don't know the reason so it's fairly vague. + When tree-tailcall reported an error it already cleared the flag, + so this shouldn't really happen unless the + the musttail pass gave up walking before finding the call. */ + if (!try_tail_call) + maybe_complain_about_tail_call (exp, "other reasons"); int pass; /* Register in which non-BLKmode value will be returned, @@ -3022,10 +3029,21 @@ expand_call (tree exp, rtx target, int ignore) pushed these optimizations into -O2. Don't try if we're already expanding a call, as that means we're an argument. Don't try if there's cleanups, as we know there's code to follow the call. */ - if (currently_expanding_call++ != 0 - || (!flag_optimize_sibling_calls && !CALL_FROM_THUNK_P (exp)) - || args_size.var - || dbg_cnt (tail_call) == false) + if (currently_expanding_call++ != 0) + { + maybe_complain_about_tail_call (exp, "inside another call"); + try_tail_call = 0; + } + if (!flag_optimize_sibling_calls + && !CALL_FROM_THUNK_P (exp) + && !CALL_EXPR_MUST_TAIL_CALL (exp)) + try_tail_call = 0; + if (args_size.var) + { + maybe_complain_about_tail_call (exp, "variable size arguments"); + try_tail_call = 0; + } + if (dbg_cnt (tail_call) == false) try_tail_call = 0; /* Workaround buggy C/C++ wrappers around Fortran routines with @@ -3046,13 +3064,15 @@ expand_call (tree exp, rtx target, int ignore) if (MEM_P (*iter)) { try_tail_call = 0; + maybe_complain_about_tail_call (exp, + "hidden string length argument passed on stack"); break; } } /* If the user has marked the function as requiring tail-call optimization, attempt it. */ - if (must_tail_call) + if (CALL_EXPR_MUST_TAIL_CALL (exp)) try_tail_call = 1; /* Rest of purposes for tail call optimizations to fail. */ From patchwork Sat Jun 22 18:54:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Kleen X-Patchwork-Id: 1951117 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; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=GFdRs/mC; 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 4W63PL29JPz1ydW for ; Sun, 23 Jun 2024 04:57:10 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4FEE8385DDE1 for ; Sat, 22 Jun 2024 18:57:08 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) by sourceware.org (Postfix) with ESMTPS id EA7F83858402 for ; Sat, 22 Jun 2024 18:56:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EA7F83858402 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.intel.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=linux.intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org EA7F83858402 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=198.175.65.17 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719082572; cv=none; b=b59SbSWhD61swFvnsTPZS2RfL3AnHyPuBCI05Y6Fwa+sALvgoOGR7Nd8SfVx/upsusXvjHzxEClpn3dBaCduDimPNU45ez3QBQVpuJlEKRJbyeA49ytqvWOYCgvrgUWDzFftrKTvaM3hkJPqAwLC42mkjZ2FRyPdMS8+RcCYSJ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719082572; c=relaxed/simple; bh=In43EDRnEajTO/SMb+TFU4pTRZIHRDr+gpjAS5ZYYL4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ogr6tWhbr+NaTEDOBEuHrcGYEk8Cy8U/W0yH+T3JvzESsdC2GW1xpwzKTY81rPn9I/XhSsizNKO0fV51ZJNg8l4ckPSCuEGlmvKE+Gwn2l9/xJ3uOFmJNnn2azmDRdBNpjDnAZlJg05Mq46ypuECdbTIhMKQNW2iPbf4MY/GJaY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719082571; x=1750618571; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=In43EDRnEajTO/SMb+TFU4pTRZIHRDr+gpjAS5ZYYL4=; b=GFdRs/mC8weMsj+jsPga1JwwGx9O6auHTFcz40ZIoXPUPE/xxTP77aY4 C6W+BFC/bUMh472KkzYTI+/d+oBP4qL+ckgSS9U6H25us5XmGuHDqzWqH yRkZ+5btZtP+rxX+rm+S6kdGEQVNV96lsLBV/tY5ZjJvpFuTKw7zs4DHd wG3S4JuxfKLJXbEOCIJdUPUu/BcrrRImxArfQ4839zdtR1QV9SO8w/Ngj f7zJb+93tJyPi9jL7rPE34gEaYtFOkjbHdUPBZS+0JMywJmiyOWA3YSXR RGVzIy0f5uWsSXlWRZT6R8eIrnb7VHEHodbVoI+Fk3mp6z7QxYgidiuNO Q==; X-CSE-ConnectionGUID: sPvAgl4kSia+haEuJR4/4A== X-CSE-MsgGUID: UUzV53QPTYej5T8l2Lovng== X-IronPort-AV: E=McAfee;i="6700,10204,11111"; a="16216438" X-IronPort-AV: E=Sophos;i="6.08,258,1712646000"; d="scan'208";a="16216438" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2024 11:56:05 -0700 X-CSE-ConnectionGUID: MKTdHNRGTLy9AqDyLwcc+A== X-CSE-MsgGUID: hDQ2csU/T46GB/GduXDJ3g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,258,1712646000"; d="scan'208";a="42968332" Received: from tassilo.jf.intel.com ([10.54.38.190]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2024 11:56:04 -0700 From: Andi Kleen To: gcc-patches@gcc.gnu.org Cc: Andi Kleen Subject: [PATCH v8 02/12] Fix pro_and_epilogue for sibcalls at -O0 Date: Sat, 22 Jun 2024 11:54:34 -0700 Message-ID: <20240622185557.1589179-3-ak@linux.intel.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240622185557.1589179-1-ak@linux.intel.com> References: <20240622185557.1589179-1-ak@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, SPF_HELO_NONE, SPF_NONE, TXREP 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 Some of the cfg fixups in pro_and_epilogue for sibcalls were dependent on "optimize". Make them check cfun->tail_call_marked instead to handle the -O0 musttail case. This fixes the musttail test cases on arm targets. PR115255 gcc/ChangeLog: * function.cc (thread_prologue_and_epilogue_insns): Check cfun->tail_call_marked for sibcalls too. (rest_of_handle_thread_prologue_and_epilogue): Dito. --- gcc/function.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gcc/function.cc b/gcc/function.cc index 4edd4da12474..7c9b181423d4 100644 --- a/gcc/function.cc +++ b/gcc/function.cc @@ -6261,6 +6261,7 @@ thread_prologue_and_epilogue_insns (void) /* Threading the prologue and epilogue changes the artificial refs in the entry and exit blocks, and may invalidate DF info for tail calls. */ if (optimize + || cfun->tail_call_marked || flag_optimize_sibling_calls || flag_ipa_icf_functions || in_lto_p) @@ -6557,7 +6558,7 @@ rest_of_handle_thread_prologue_and_epilogue (function *fun) { /* prepare_shrink_wrap is sensitive to the block structure of the control flow graph, so clean it up first. */ - if (optimize) + if (cfun->tail_call_marked || optimize) cleanup_cfg (0); /* On some machines, the prologue and epilogue code, or parts thereof, From patchwork Sat Jun 22 18:54:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Kleen X-Patchwork-Id: 1951116 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; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=M+qxjwoB; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; 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 [8.43.85.97]) (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 4W63P00GP1z1ydW for ; Sun, 23 Jun 2024 04:56:52 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2B2C0385DDDC for ; Sat, 22 Jun 2024 18:56:49 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) by sourceware.org (Postfix) with ESMTPS id EAB793858408 for ; Sat, 22 Jun 2024 18:56:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EAB793858408 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.intel.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=linux.intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org EAB793858408 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=198.175.65.17 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719082572; cv=none; b=EO08KGdgfmnZu3cxDvVtSjmmc0dYRODdmlpmyakt8mURS1KPEFrWYPIZPJzZRbkrqpnYqmg9Y3xhFlKmSHNclwqV76ijHtml4R4NekNkV9K23bJZrM3/S4bF58n8PDKXChsJQ19/5pVazDKMjZGUQ9MPqUKRbKle9R9C4LicoeQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719082572; c=relaxed/simple; bh=vpk7UNWgldwZgXa7roenR8DrYgm95bICO/yrWNHd12g=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=d/zbVfvi9MVbvUKaBgRBxv1FEcuDzuuEJmRglHxx9r73PDDG04SMm+5+WbK5G2dVPvU/pDtd8OIfPytJYE92gkx06IyYvdCz/eaAwL5tYqrEdPRZrWCBCuT3YqMiHtjHdcZRTtDVK6fSyZGdUPjrYCdqLvZww/9dw7oinKrAefg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719082571; x=1750618571; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vpk7UNWgldwZgXa7roenR8DrYgm95bICO/yrWNHd12g=; b=M+qxjwoB1HeZ2Be4HWQzpQ1vNVwJzicbL9964cAnyVA41TPxqWa82TU1 +fO5MbfryXK5ikybP9bceKSiPW6bp1Z8FFtP7DTUTlGn7a9FBJbVC5t++ AJqfPQ9Ju4zfJ33ZYY+iuq2ht0jXh/GhklKqE133B+N4GVnppxnS6VMFb YyqtdMgKgCDUBkCkU7ht+nLljYUvCQ8VE0iQBd+QTPf5PfzZkpfzmmxXv yLhRJutl26S4gLbSfsnqsid2vVF7WkKsaD4UBterGAs7RZrbVXEG6HL47 DVuZ+OPH5XYzDZxFDx9P3+2Faqb6A1z3v0CwMOMHT6ZnDBu2u3oHiJFgm A==; X-CSE-ConnectionGUID: vstb998uTf6ZCJ6tkaRjxw== X-CSE-MsgGUID: 611D/JkqSaCv/ND8ElL/bw== X-IronPort-AV: E=McAfee;i="6700,10204,11111"; a="16216439" X-IronPort-AV: E=Sophos;i="6.08,258,1712646000"; d="scan'208";a="16216439" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2024 11:56:06 -0700 X-CSE-ConnectionGUID: Kn0DzYMoSCe9v2f3l1O3UQ== X-CSE-MsgGUID: l2Frvw24SyOZlzyBKgvLQg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,258,1712646000"; d="scan'208";a="42968333" Received: from tassilo.jf.intel.com ([10.54.38.190]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2024 11:56:05 -0700 From: Andi Kleen To: gcc-patches@gcc.gnu.org Cc: Andi Kleen Subject: [PATCH v8 03/12] Add a musttail generic attribute to the c-attribs table Date: Sat, 22 Jun 2024 11:54:35 -0700 Message-ID: <20240622185557.1589179-4-ak@linux.intel.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240622185557.1589179-1-ak@linux.intel.com> References: <20240622185557.1589179-1-ak@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_NONE, TXREP 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 It does nothing currently since statement attributes are handled directly in the parser. gcc/c-family/ChangeLog: * c-attribs.cc (handle_musttail_attribute): Add. * c-common.h (handle_musttail_attribute): Add. --- gcc/c-family/c-attribs.cc | 15 +++++++++++++++ gcc/c-family/c-common.h | 1 + 2 files changed, 16 insertions(+) diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc index f9b229aba7fc..5adc7b775eaf 100644 --- a/gcc/c-family/c-attribs.cc +++ b/gcc/c-family/c-attribs.cc @@ -340,6 +340,8 @@ const struct attribute_spec c_common_gnu_attributes[] = { "common", 0, 0, true, false, false, false, handle_common_attribute, attr_common_exclusions }, + { "musttail", 0, 0, false, false, false, + false, handle_musttail_attribute, NULL }, /* FIXME: logically, noreturn attributes should be listed as "false, true, true" and apply to function types. But implementing this would require all the places in the compiler that use TREE_THIS_VOLATILE @@ -1222,6 +1224,19 @@ handle_common_attribute (tree *node, tree name, tree ARG_UNUSED (args), return NULL_TREE; } +/* Handle a "musttail" attribute; arguments as in + struct attribute_spec.handler. */ + +tree +handle_musttail_attribute (tree ARG_UNUSED (*node), tree name, tree ARG_UNUSED (args), + int ARG_UNUSED (flags), bool *no_add_attrs) +{ + /* Currently only a statement attribute, handled directly in parser. */ + warning (OPT_Wattributes, "%qE attribute ignored", name); + *no_add_attrs = true; + return NULL_TREE; +} + /* Handle a "noreturn" attribute; arguments as in struct attribute_spec.handler. */ diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index 48c89b603bcd..e84c9c47513b 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -1643,6 +1643,7 @@ extern tree find_tm_attribute (tree); extern const struct attribute_spec::exclusions attr_cold_hot_exclusions[]; extern const struct attribute_spec::exclusions attr_noreturn_exclusions[]; extern tree handle_noreturn_attribute (tree *, tree, tree, int, bool *); +extern tree handle_musttail_attribute (tree *, tree, tree, int, bool *); extern bool has_attribute (location_t, tree, tree, tree (*)(tree)); extern tree build_attr_access_from_parms (tree, bool); From patchwork Sat Jun 22 18:54:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Kleen X-Patchwork-Id: 1951119 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; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=jGH6Y2Hu; 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 4W63Qq3nYvz1ydW for ; Sun, 23 Jun 2024 04:58:27 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C8A01385DDC1 for ; Sat, 22 Jun 2024 18:58:25 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) by sourceware.org (Postfix) with ESMTPS id 8F1143858410 for ; Sat, 22 Jun 2024 18:56:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8F1143858410 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.intel.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=linux.intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8F1143858410 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=198.175.65.17 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719082573; cv=none; b=Fwe31NBbo9MZjdePRqcNrO2twl87xpPs10E9obU050QM4TZ8v8C4jILgQu9I8U35GgCBs3lTwyOyHDlSzmvFzSYRY0n9m0znm99W367tjt2hwuJjMGcZfgYA+182rlCuATdPa6EUXQk+PF9bOmMhN0XRIvhllc+KVyEw85BL/s8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719082573; c=relaxed/simple; bh=5dOi1lpH9EKa/Q0DX3W9g+T6WpeXRMF5OjQlaeQfwWE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=YnXM31sr0eI9hd/7sjo38xpn2XDHSiog7Wknx1fn2daXuwtoPZgNp2mn9YpO76hWa0rLvxWp82wyotLGrFlCVJP9NH4J89TVdlewIOonUn/zUVSWOqYkcBIhFd83FEFN/U+r9cAEMG52Y2DqSrprMjhLcKbK2h+6q1QsoRiVO4s= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719082572; x=1750618572; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5dOi1lpH9EKa/Q0DX3W9g+T6WpeXRMF5OjQlaeQfwWE=; b=jGH6Y2HuabKf6ZeMm+/eyEPfVTAEB+L9WrCzXldbriS8JU/XBvMQx5dm /hHnp5eh9MBLYADjzxCowZ96OfcJVxj0yDvtxSVRD20xZOxWP0OTwrwGd C2jkEpTkrEz1xUak7/99g0s7ftEs/fnEVH4tdGLsw23eNomVsxnBM1Hkl GX9q+jlyPfHpqjAa3XlJikGosOZPh00qsBQ6W0EUx2rqNnsMj4ILc85Vn Shazb4OEZvbY5CiN67AM5Tf5EblDOBHQF+0eLfTTRniZTr41PZEvRmsOq qsJhjuBjB94IFZwww+TnXzLOwLmXqMwnMpXEvX3gZ9z+yiB4jEs5hUMZN w==; X-CSE-ConnectionGUID: 0CAfQqhnSn6ysVY6zLNzbw== X-CSE-MsgGUID: 8iRfJ1TDR0aTq696tG7ppw== X-IronPort-AV: E=McAfee;i="6700,10204,11111"; a="16216440" X-IronPort-AV: E=Sophos;i="6.08,258,1712646000"; d="scan'208";a="16216440" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2024 11:56:06 -0700 X-CSE-ConnectionGUID: VRIbg4+ETfGzB09HE0CAow== X-CSE-MsgGUID: blUmjas+Qtqc19ei+n5tFQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,258,1712646000"; d="scan'208";a="42968334" Received: from tassilo.jf.intel.com ([10.54.38.190]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2024 11:56:05 -0700 From: Andi Kleen To: gcc-patches@gcc.gnu.org Cc: Andi Kleen Subject: [PATCH v8 04/12] C++: Support clang compatible [[musttail]] (PR83324) Date: Sat, 22 Jun 2024 11:54:36 -0700 Message-ID: <20240622185557.1589179-5-ak@linux.intel.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240622185557.1589179-1-ak@linux.intel.com> References: <20240622185557.1589179-1-ak@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_NONE, TXREP 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 This patch implements a clang compatible [[musttail]] attribute for returns. musttail is useful as an alternative to computed goto for interpreters. With computed goto the interpreter function usually ends up very big which causes problems with register allocation and other per function optimizations not scaling. With musttail the interpreter can be instead written as a sequence of smaller functions that call each other. To avoid unbounded stack growth this requires forcing a sibling call, which this attribute does. It guarantees an error if the call cannot be tail called which allows the programmer to fix it instead of risking a stack overflow. Unlike computed goto it is also type-safe. It turns out that David Malcolm had already implemented middle/backend support for a musttail attribute back in 2016, but it wasn't exposed to any frontend other than a special plugin. This patch adds a [[gnu::musttail]] attribute for C++ that can be added to return statements. The return statement must be a direct call (it does not follow dependencies), which is similar to what clang implements. It then uses the existing must tail infrastructure. For compatibility it also detects clang::musttail Passes bootstrap and full test PR83324 gcc/cp/ChangeLog: * parser.cc (cp_parser_statement): Handle musttail. (cp_parser_jump_statement): Dito. * pt.cc (tsubst_expr): Copy CALL_EXPR_MUST_TAIL_CALL. --- gcc/cp/parser.cc | 34 +++++++++++++++++++++++++++++++--- gcc/cp/pt.cc | 7 ++++++- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index e7409b856f11..c03c1aec2c01 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -2467,7 +2467,7 @@ static tree cp_parser_perform_range_for_lookup static tree cp_parser_range_for_member_function (tree, tree); static tree cp_parser_jump_statement - (cp_parser *); + (cp_parser *, tree &); static void cp_parser_declaration_statement (cp_parser *); @@ -12755,7 +12755,7 @@ cp_parser_statement (cp_parser* parser, tree in_statement_expr, case RID_CO_RETURN: case RID_GOTO: std_attrs = process_stmt_hotness_attribute (std_attrs, attrs_loc); - statement = cp_parser_jump_statement (parser); + statement = cp_parser_jump_statement (parser, std_attrs); break; /* Objective-C++ exception-handling constructs. */ @@ -14822,10 +14822,11 @@ cp_parser_init_statement (cp_parser *parser, tree *decl) jump-statement: goto * expression ; + STD_ATTRS are the statement attributes. They can be modified. Returns the new BREAK_STMT, CONTINUE_STMT, RETURN_EXPR, or GOTO_EXPR. */ static tree -cp_parser_jump_statement (cp_parser* parser) +cp_parser_jump_statement (cp_parser* parser, tree &std_attrs) { tree statement = error_mark_node; cp_token *token; @@ -14902,6 +14903,33 @@ cp_parser_jump_statement (cp_parser* parser) /* If the next token is a `;', then there is no expression. */ expr = NULL_TREE; + + if (keyword == RID_RETURN && expr) + { + bool musttail_p = false; + if (lookup_attribute ("gnu", "musttail", std_attrs)) + { + musttail_p = true; + std_attrs = remove_attribute ("gnu", "musttail", std_attrs); + } + /* Support this for compatibility. */ + if (lookup_attribute ("clang", "musttail", std_attrs)) + { + musttail_p = true; + std_attrs = remove_attribute ("clang", "musttail", std_attrs); + } + if (musttail_p) + { + tree t = expr; + if (t && TREE_CODE (t) == TARGET_EXPR) + t = TARGET_EXPR_INITIAL (t); + if (t && TREE_CODE (t) != CALL_EXPR) + error_at (token->location, "cannot tail-call: return value must be a call"); + else + CALL_EXPR_MUST_TAIL_CALL (t) = 1; + } + } + /* Build the return-statement, check co-return first, since type deduction is not valid there. */ if (keyword == RID_CO_RETURN) diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 607753ae6b7f..9addcc10bfd0 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -21111,12 +21111,17 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl) bool op = CALL_EXPR_OPERATOR_SYNTAX (t); bool ord = CALL_EXPR_ORDERED_ARGS (t); bool rev = CALL_EXPR_REVERSE_ARGS (t); - if (op || ord || rev) + bool mtc = false; + if (TREE_CODE (t) == CALL_EXPR) + mtc = CALL_EXPR_MUST_TAIL_CALL (t); + if (op || ord || rev || mtc) if (tree call = extract_call_expr (ret)) { CALL_EXPR_OPERATOR_SYNTAX (call) = op; CALL_EXPR_ORDERED_ARGS (call) = ord; CALL_EXPR_REVERSE_ARGS (call) = rev; + if (TREE_CODE (call) == CALL_EXPR) + CALL_EXPR_MUST_TAIL_CALL (call) = mtc; } if (warning_suppressed_p (t, OPT_Wpessimizing_move)) /* This also suppresses -Wredundant-move. */ From patchwork Sat Jun 22 18:54:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Kleen X-Patchwork-Id: 1951118 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; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=fUqU/cP7; 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 4W63Qd0Nwhz1ydW for ; Sun, 23 Jun 2024 04:58:17 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4C535385DDFE for ; Sat, 22 Jun 2024 18:58:15 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) by sourceware.org (Postfix) with ESMTPS id 02724385DDCE for ; Sat, 22 Jun 2024 18:56:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 02724385DDCE Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.intel.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=linux.intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 02724385DDCE Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=198.175.65.17 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719082584; cv=none; b=FkQ2A0xHWoPBkLIa0xEjt/+sqe1W1ZmEml0SLQ8+hoEK3yvqMvKmnuAYfW73T43fTYnNSZAc8RyMs/6Etn4Cdozk6fWJg5R/RR3I3xVw5dDFboI0PI5b9xBadTrt64RCSPntpYbuLGWVqY8rRDikjSWUOjL7wXZ55Z4ZLuZLwoQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719082584; c=relaxed/simple; bh=+RCrSqfvWnzWhm4RRJnnfHkOU0jV7B9/uBnqOsEFOFQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=dkPI9RBswVKsY2czReUIoprSTTYe850MR5ivposAaTSNWlcdm4bCVB1WG6wskBwYx+0D93hiVEKqEOmh/LcW4Aql4lVE+1I3xj1wz9WPD+3Hiu0myyMWdO0aIXkN27CuGsFdjdNqRApNx03igEY2TnQoEmq56M097XxW7i3d2C4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719082573; x=1750618573; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+RCrSqfvWnzWhm4RRJnnfHkOU0jV7B9/uBnqOsEFOFQ=; b=fUqU/cP7mSDLtx8RkiORVTumM25Y1Pixq6VSIl8LG+Vk3WIUHV3rcwq3 wJp5IjAeGNRF7K6by5sIubjMSk/ybAtKrXQVpKJtjHRpgEFz88QOBoQqA n+iIO30i/qV22sp5HR+6UZOad/LG3tbcQmsCdnxMS94PN7dU6DiMQf8LF wyzIiODTAiyGcyE54uw2mp1ZUdlE/bsIWIVrJHuzhMQoEPYk1W3WhhzPA yptS+yHCyHPGW9NLuWH0PhyGm8ErxF8HNL161COwBgQ9xxm2TIeQAIca2 NnEf18FcQaQIKxArW1XTN0TLaQKmkoLBsq+tpocZODIBGlrhLmE28Y86d g==; X-CSE-ConnectionGUID: g8rrfJo2QjmMO87PW//v2A== X-CSE-MsgGUID: FQsUFyW1SMqNO+kjZGAJtA== X-IronPort-AV: E=McAfee;i="6700,10204,11111"; a="16216441" X-IronPort-AV: E=Sophos;i="6.08,258,1712646000"; d="scan'208";a="16216441" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2024 11:56:06 -0700 X-CSE-ConnectionGUID: NRSEouvyRA+CLAi/o3g2Ng== X-CSE-MsgGUID: LQkPSRArQvOtWx4xE4vFxg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,258,1712646000"; d="scan'208";a="42968336" Received: from tassilo.jf.intel.com ([10.54.38.190]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2024 11:56:05 -0700 From: Andi Kleen To: gcc-patches@gcc.gnu.org Cc: Andi Kleen Subject: [PATCH v8 05/12] C: Implement musttail attribute for returns Date: Sat, 22 Jun 2024 11:54:37 -0700 Message-ID: <20240622185557.1589179-6-ak@linux.intel.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240622185557.1589179-1-ak@linux.intel.com> References: <20240622185557.1589179-1-ak@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_NONE, TXREP 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 Implement a C23 clang compatible musttail attribute similar to the earlier C++ implementation in the C parser. PR83324 gcc/c/ChangeLog: * c-parser.cc (struct attr_state): Define with musttail_p. (c_parser_statement_after_labels): Handle [[musttail]] (c_parser_std_attribute): Dito. (c_parser_handle_musttail): Dito. (c_parser_compound_statement_nostart): Dito. (c_parser_all_labels): Dito. (c_parser_statement): Dito. * c-tree.h (c_finish_return): Add musttail_p flag. * c-typeck.cc (c_finish_return): Handle musttail_p flag. --- gcc/c/c-parser.cc | 61 +++++++++++++++++++++++++++++++++++++---------- gcc/c/c-tree.h | 2 +- gcc/c/c-typeck.cc | 15 ++++++++++-- 3 files changed, 63 insertions(+), 15 deletions(-) diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc index e83e9c683f75..f47cde3c9d6e 100644 --- a/gcc/c/c-parser.cc +++ b/gcc/c/c-parser.cc @@ -1621,6 +1621,11 @@ struct omp_for_parse_data { bool fail : 1; }; +struct attr_state +{ + bool musttail_p; // parsed a musttail for return +}; + static bool c_parser_nth_token_starts_std_attributes (c_parser *, unsigned int); static tree c_parser_std_attribute_specifier_sequence (c_parser *); @@ -1665,7 +1670,7 @@ static location_t c_parser_compound_statement_nostart (c_parser *); static void c_parser_label (c_parser *, tree); static void c_parser_statement (c_parser *, bool *, location_t * = NULL); static void c_parser_statement_after_labels (c_parser *, bool *, - vec * = NULL); + vec * = NULL, attr_state = {}); static tree c_parser_c99_block_statement (c_parser *, bool *, location_t * = NULL); static void c_parser_if_statement (c_parser *, bool *, vec *); @@ -5763,6 +5768,8 @@ c_parser_std_attribute (c_parser *parser, bool for_tm) } goto out; } + else if (is_attribute_p ("musttail", name)) + error ("% attribute has arguments"); { location_t open_loc = c_parser_peek_token (parser)->location; matching_parens parens; @@ -6985,6 +6992,28 @@ c_parser_handle_directive_omp_attributes (tree &attrs, } } +/* Check if STD_ATTR contains a musttail attribute and handle it + PARSER is the parser and A is the output attr_state. */ + +static tree +c_parser_handle_musttail (c_parser *parser, tree std_attrs, attr_state &a) +{ + if (c_parser_next_token_is_keyword (parser, RID_RETURN)) + { + if (lookup_attribute ("gnu", "musttail", std_attrs)) + { + std_attrs = remove_attribute ("gnu", "musttail", std_attrs); + a.musttail_p = true; + } + if (lookup_attribute ("clang", "musttail", std_attrs)) + { + std_attrs = remove_attribute ("clang", "musttail", std_attrs); + a.musttail_p = true; + } + } + return std_attrs; +} + /* Parse a compound statement except for the opening brace. This is used for parsing both compound statements and statement expressions (which follow different paths to handling the opening). */ @@ -7001,6 +7030,7 @@ c_parser_compound_statement_nostart (c_parser *parser) bool in_omp_loop_block = omp_for_parse_state ? omp_for_parse_state->want_nested_loop : false; tree sl = NULL_TREE; + attr_state a = {}; if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) { @@ -7141,7 +7171,10 @@ c_parser_compound_statement_nostart (c_parser *parser) = c_parser_nth_token_starts_std_attributes (parser, 1); tree std_attrs = NULL_TREE; if (have_std_attrs) - std_attrs = c_parser_std_attribute_specifier_sequence (parser); + { + std_attrs = c_parser_std_attribute_specifier_sequence (parser); + std_attrs = c_parser_handle_musttail (parser, std_attrs, a); + } if (c_parser_next_token_is_keyword (parser, RID_CASE) || c_parser_next_token_is_keyword (parser, RID_DEFAULT) || (c_parser_next_token_is (parser, CPP_NAME) @@ -7289,7 +7322,7 @@ c_parser_compound_statement_nostart (c_parser *parser) last_stmt = true; mark_valid_location_for_stdc_pragma (false); if (!omp_for_parse_state) - c_parser_statement_after_labels (parser, NULL); + c_parser_statement_after_labels (parser, NULL, NULL, a); else { /* In canonical loop nest form, nested loops can only appear @@ -7331,15 +7364,18 @@ c_parser_compound_statement_nostart (c_parser *parser) /* Parse all consecutive labels, possibly preceded by standard attributes. In this context, a statement is required, not a declaration, so attributes must be followed by a statement that is - not just a semicolon. */ + not just a semicolon. Returns an attr_state. */ -static void +static attr_state c_parser_all_labels (c_parser *parser) { + attr_state a = {}; bool have_std_attrs; tree std_attrs = NULL; if ((have_std_attrs = c_parser_nth_token_starts_std_attributes (parser, 1))) - std_attrs = c_parser_std_attribute_specifier_sequence (parser); + std_attrs = c_parser_handle_musttail (parser, + c_parser_std_attribute_specifier_sequence (parser), a); + while (c_parser_next_token_is_keyword (parser, RID_CASE) || c_parser_next_token_is_keyword (parser, RID_DEFAULT) || (c_parser_next_token_is (parser, CPP_NAME) @@ -7361,6 +7397,7 @@ c_parser_all_labels (c_parser *parser) } else if (have_std_attrs && c_parser_next_token_is (parser, CPP_SEMICOLON)) c_parser_error (parser, "expected statement"); + return a; } /* Parse a label (C90 6.6.1, C99 6.8.1, C11 6.8.1). @@ -7604,11 +7641,11 @@ c_parser_label (c_parser *parser, tree std_attrs) static void c_parser_statement (c_parser *parser, bool *if_p, location_t *loc_after_labels) { - c_parser_all_labels (parser); + attr_state a = c_parser_all_labels (parser); if (loc_after_labels) *loc_after_labels = c_parser_peek_token (parser)->location; parser->omp_attrs_forbidden_p = false; - c_parser_statement_after_labels (parser, if_p, NULL); + c_parser_statement_after_labels (parser, if_p, NULL, a); } /* Parse a statement, other than a labeled statement. CHAIN is a vector @@ -7617,11 +7654,11 @@ c_parser_statement (c_parser *parser, bool *if_p, location_t *loc_after_labels) IF_P is used to track whether there's a (possibly labeled) if statement which is not enclosed in braces and has an else clause. This is used to - implement -Wparentheses. */ + implement -Wparentheses. A has an earlier parsed attribute state. */ static void c_parser_statement_after_labels (c_parser *parser, bool *if_p, - vec *chain) + vec *chain, attr_state a) { location_t loc = c_parser_peek_token (parser)->location; tree stmt = NULL_TREE; @@ -7689,7 +7726,7 @@ c_parser_statement_after_labels (c_parser *parser, bool *if_p, c_parser_consume_token (parser); if (c_parser_next_token_is (parser, CPP_SEMICOLON)) { - stmt = c_finish_return (loc, NULL_TREE, NULL_TREE); + stmt = c_finish_return (loc, NULL_TREE, NULL_TREE, a.musttail_p); c_parser_consume_token (parser); } else @@ -7698,7 +7735,7 @@ c_parser_statement_after_labels (c_parser *parser, bool *if_p, struct c_expr expr = c_parser_expression_conv (parser); mark_exp_read (expr.value); stmt = c_finish_return (EXPR_LOC_OR_LOC (expr.value, xloc), - expr.value, expr.original_type); + expr.value, expr.original_type, a.musttail_p); goto expect_semicolon; } break; diff --git a/gcc/c/c-tree.h b/gcc/c/c-tree.h index 15da875a0290..3dc6338bf061 100644 --- a/gcc/c/c-tree.h +++ b/gcc/c/c-tree.h @@ -827,7 +827,7 @@ extern tree c_begin_stmt_expr (void); extern tree c_finish_stmt_expr (location_t, tree); extern tree c_process_expr_stmt (location_t, tree); extern tree c_finish_expr_stmt (location_t, tree); -extern tree c_finish_return (location_t, tree, tree); +extern tree c_finish_return (location_t, tree, tree, bool = false); extern tree c_finish_bc_stmt (location_t, tree, bool); extern tree c_finish_goto_label (location_t, tree); extern tree c_finish_goto_ptr (location_t, c_expr val); diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc index ffcab7df4d3b..e47b10befd90 100644 --- a/gcc/c/c-typeck.cc +++ b/gcc/c/c-typeck.cc @@ -11693,10 +11693,10 @@ c_finish_goto_ptr (location_t loc, c_expr val) to return, or a null pointer for `return;' with no value. LOC is the location of the return statement, or the location of the expression, if the statement has any. If ORIGTYPE is not NULL_TREE, it - is the original type of RETVAL. */ + is the original type of RETVAL. MUSTTAIL_P indicates a musttail attribute. */ tree -c_finish_return (location_t loc, tree retval, tree origtype) +c_finish_return (location_t loc, tree retval, tree origtype, bool musttail_p) { tree valtype = TREE_TYPE (TREE_TYPE (current_function_decl)), ret_stmt; bool no_warning = false; @@ -11710,6 +11710,17 @@ c_finish_return (location_t loc, tree retval, tree origtype) warning_at (xloc, 0, "function declared % has a % statement"); + if (retval && musttail_p) + { + tree t = retval; + if (TREE_CODE (t) == TARGET_EXPR) + t = TARGET_EXPR_INITIAL (t); + if (TREE_CODE (t) != CALL_EXPR) + error_at (xloc, "cannot tail-call: return value must be call"); + else + CALL_EXPR_MUST_TAIL_CALL (t) = 1; + } + if (retval) { tree semantic_type = NULL_TREE; From patchwork Sat Jun 22 18:54:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Kleen X-Patchwork-Id: 1951121 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; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=hZfmGDos; 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 4W63Rj21Wcz1ydW for ; Sun, 23 Jun 2024 04:59:13 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8CDFD385E838 for ; Sat, 22 Jun 2024 18:59:11 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) by sourceware.org (Postfix) with ESMTPS id 12A9E385DDCF for ; Sat, 22 Jun 2024 18:56:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 12A9E385DDCF Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.intel.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=linux.intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 12A9E385DDCF Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=198.175.65.17 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719082584; cv=none; b=cgU2o276erQf5DJmJm3+kSFBxkf8KKuldUgPutaHsYsXvgwWDGEKOYys7093gEvlbdggFzwguwgCpu+INCRQcssdjQXLo7QJiDi8v/EPYmDt5dt0olGzDI5W1jpmjMz8lYnQZZXANmJbWj0AiyQUpCftcLmoUWl+Pde3KyZ2EKE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719082584; c=relaxed/simple; bh=MuCAPNdjzNi2MKwDjoibIP+EvH8ZVqyAZ1dproYlj+k=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=f0BE67aE6PAsPIObkvTAj5Gk3DdI6b3bqAPyGgHPGOlDuzTkUozf43AkrTXqjKrMKswBkfmi618PEPip2IlYSNdzTfoQjrACfkuXaT8yrcT+kbBPObF1bx1yFxESENlWIdSWgQTvEtqKbP0C0XcsJ5w/4vcNU1AXnh6AtMkbhR8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719082573; x=1750618573; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MuCAPNdjzNi2MKwDjoibIP+EvH8ZVqyAZ1dproYlj+k=; b=hZfmGDossM7G/FMCngYYNGg0vnhbgUhExlOvjtPIx+uMe3KhFwdsCTrx MOMOFu42LEX51gSfyiQlJ4L7idtIdFqZQzSh6brOLyk9iJRIckEz01JPB 8VyDNouvaKJPGXeLnSDR7SQAxwo2opCFnQ4ufVZvGhQ3/AcTNAzLTkG/e yIAhF3Vk0HzXyerW17C97qPXC1BS1WTwsRmeFx+vY4zWB+GdhWa14vJod 30s35hew5dKm6p+ozRSHInfHnwqriMsRmImIkiKjshwIvGbnbdSu7WXqu GjHeUt80Jis4WIUbQEHGxFdXCSIAhdFKjer66iWO3HmhLzUkUijL/K+mB w==; X-CSE-ConnectionGUID: Sn0rsAeFS5K+AXhNd5hOXA== X-CSE-MsgGUID: blyKbInaRX2g2QlpQSdVlw== X-IronPort-AV: E=McAfee;i="6700,10204,11111"; a="16216442" X-IronPort-AV: E=Sophos;i="6.08,258,1712646000"; d="scan'208";a="16216442" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2024 11:56:06 -0700 X-CSE-ConnectionGUID: WsQGsq5YQsiU/jx45cXfKg== X-CSE-MsgGUID: POsyXvwfTmK671/0CwMv1w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,258,1712646000"; d="scan'208";a="42968337" Received: from tassilo.jf.intel.com ([10.54.38.190]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2024 11:56:05 -0700 From: Andi Kleen To: gcc-patches@gcc.gnu.org Cc: Andi Kleen Subject: [PATCH v8 06/12] Add tests for C/C++ musttail attributes Date: Sat, 22 Jun 2024 11:54:38 -0700 Message-ID: <20240622185557.1589179-7-ak@linux.intel.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240622185557.1589179-1-ak@linux.intel.com> References: <20240622185557.1589179-1-ak@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_NONE, TXREP, UNWANTED_LANGUAGE_BODY 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 Some adopted from the existing C musttail plugin tests. gcc/testsuite/ChangeLog: * c-c++-common/musttail1.c: New test. * c-c++-common/musttail2.c: New test. * c-c++-common/musttail3.c: New test. * c-c++-common/musttail4.c: New test. * c-c++-common/musttail7.c: New test. * c-c++-common/musttail8.c: New test. * g++.dg/musttail6.C: New test. * g++.dg/musttail9.C: New test. * g++.dg/musttail10.C: New test. --- gcc/testsuite/c-c++-common/musttail1.c | 14 ++++++ gcc/testsuite/c-c++-common/musttail2.c | 33 ++++++++++++++ gcc/testsuite/c-c++-common/musttail3.c | 29 +++++++++++++ gcc/testsuite/c-c++-common/musttail4.c | 17 ++++++++ gcc/testsuite/c-c++-common/musttail5.c | 28 ++++++++++++ gcc/testsuite/c-c++-common/musttail7.c | 14 ++++++ gcc/testsuite/c-c++-common/musttail8.c | 17 ++++++++ gcc/testsuite/g++.dg/musttail10.C | 34 +++++++++++++++ gcc/testsuite/g++.dg/musttail6.C | 59 ++++++++++++++++++++++++++ gcc/testsuite/g++.dg/musttail9.C | 10 +++++ 10 files changed, 255 insertions(+) create mode 100644 gcc/testsuite/c-c++-common/musttail1.c create mode 100644 gcc/testsuite/c-c++-common/musttail2.c create mode 100644 gcc/testsuite/c-c++-common/musttail3.c create mode 100644 gcc/testsuite/c-c++-common/musttail4.c create mode 100644 gcc/testsuite/c-c++-common/musttail5.c create mode 100644 gcc/testsuite/c-c++-common/musttail7.c create mode 100644 gcc/testsuite/c-c++-common/musttail8.c create mode 100644 gcc/testsuite/g++.dg/musttail10.C create mode 100644 gcc/testsuite/g++.dg/musttail6.C create mode 100644 gcc/testsuite/g++.dg/musttail9.C diff --git a/gcc/testsuite/c-c++-common/musttail1.c b/gcc/testsuite/c-c++-common/musttail1.c new file mode 100644 index 000000000000..74efcc2a0bc6 --- /dev/null +++ b/gcc/testsuite/c-c++-common/musttail1.c @@ -0,0 +1,14 @@ +/* { dg-do compile { target { tail_call && { c || c++11 } } } } */ +/* { dg-additional-options "-fdelayed-branch" { target sparc*-*-* } } */ + +int __attribute__((noinline,noclone,noipa)) +callee (int i) +{ + return i * i; +} + +int __attribute__((noinline,noclone,noipa)) +caller (int i) +{ + [[gnu::musttail]] return callee (i + 1); +} diff --git a/gcc/testsuite/c-c++-common/musttail2.c b/gcc/testsuite/c-c++-common/musttail2.c new file mode 100644 index 000000000000..86f2c3d77404 --- /dev/null +++ b/gcc/testsuite/c-c++-common/musttail2.c @@ -0,0 +1,33 @@ +/* { dg-do compile { target { tail_call && { c || c++11 } } } } */ + +struct box { char field[256]; int i; }; + +int __attribute__((noinline,noclone,noipa)) +test_2_callee (int i, struct box b) +{ + if (b.field[0]) + return 5; + return i * i; +} + +int __attribute__((noinline,noclone,noipa)) +test_2_caller (int i) +{ + struct box b; + [[gnu::musttail]] return test_2_callee (i + 1, b); /* { dg-error "cannot tail-call: " } */ +} + +extern void setjmp (void); +void +test_3 (void) +{ + [[gnu::musttail]] return setjmp (); /* { dg-error "cannot tail-call: " } */ +} + +extern float f7(void); + +int +test_6 (void) +{ + [[gnu::musttail]] return f7(); /* { dg-error "cannot tail-call: " } */ +} diff --git a/gcc/testsuite/c-c++-common/musttail3.c b/gcc/testsuite/c-c++-common/musttail3.c new file mode 100644 index 000000000000..ea9589c59ef2 --- /dev/null +++ b/gcc/testsuite/c-c++-common/musttail3.c @@ -0,0 +1,29 @@ +/* { dg-do compile { target { tail_call && { c || c++11 } } } } */ + +extern int foo2 (int x, ...); + +struct str +{ + int a, b; +}; + +struct str +cstruct (int x) +{ + if (x < 10) + [[clang::musttail]] return cstruct (x + 1); + return ((struct str){ x, 0 }); +} + +int +foo (int x) +{ + if (x < 10) + [[clang::musttail]] return foo2 (x, 29); + if (x < 100) + { + int k = foo (x + 1); + [[clang::musttail]] return k; /* { dg-error "cannot tail-call: " } */ + } + return x; +} diff --git a/gcc/testsuite/c-c++-common/musttail4.c b/gcc/testsuite/c-c++-common/musttail4.c new file mode 100644 index 000000000000..23f4b5e1cd68 --- /dev/null +++ b/gcc/testsuite/c-c++-common/musttail4.c @@ -0,0 +1,17 @@ +/* { dg-do compile { target { tail_call && { c || c++11 } } } } */ + +struct box { char field[64]; int i; }; + +struct box __attribute__((noinline,noclone,noipa)) +returns_struct (int i) +{ + struct box b; + b.i = i * i; + return b; +} + +int __attribute__((noinline,noclone)) +test_1 (int i) +{ + [[gnu::musttail]] return returns_struct (i * 5).i; /* { dg-error "cannot tail-call: " } */ +} diff --git a/gcc/testsuite/c-c++-common/musttail5.c b/gcc/testsuite/c-c++-common/musttail5.c new file mode 100644 index 000000000000..234da0d3f2a9 --- /dev/null +++ b/gcc/testsuite/c-c++-common/musttail5.c @@ -0,0 +1,28 @@ +/* { dg-do compile } */ +/* { dg-options "-std=c23" { target c } } */ +/* { dg-options "-std=gnu++11" { target c++ } } */ + +[[musttail]] int j; /* { dg-warning "attribute" } */ +__attribute__((musttail)) int k; /* { dg-warning "attribute" } */ + +void foo(void) +{ + [[gnu::musttail]] j++; /* { dg-warning "attribute" } */ + [[gnu::musttail]] if (k > 0) /* { dg-warning "attribute" } */ + [[gnu::musttail]] k++; /* { dg-warning "attribute" } */ +} + +int foo2(int p) +{ + [[gnu::musttail(1)]] return foo2(p + 1); /* { dg-error "\(before numeric constant|attribute\)" } */ +} + +int i; + +int foo3(void) +{ + [[musttail]] i++; /* { dg-warning "attribute" } */ + [[musttail]] if (i > 10) /* { dg-warning "attribute" } */ + [[musttail]] return foo2(i); /* { dg-warning "attribute" } */ + return 0; +} diff --git a/gcc/testsuite/c-c++-common/musttail7.c b/gcc/testsuite/c-c++-common/musttail7.c new file mode 100644 index 000000000000..c753a3fe9b2a --- /dev/null +++ b/gcc/testsuite/c-c++-common/musttail7.c @@ -0,0 +1,14 @@ +/* { dg-do compile { target { tail_call && { c || c++11 } } } } */ +/* { dg-additional-options "-fdelayed-branch" { target sparc*-*-* } } */ + +void __attribute__((noipa)) f() {} + +void f2() +{ + [[gnu::musttail]] return f2(); +} + +void f3() +{ + [[gnu::musttail]] return f(); +} diff --git a/gcc/testsuite/c-c++-common/musttail8.c b/gcc/testsuite/c-c++-common/musttail8.c new file mode 100644 index 000000000000..9fa10e0b54c4 --- /dev/null +++ b/gcc/testsuite/c-c++-common/musttail8.c @@ -0,0 +1,17 @@ +/* { dg-do compile { target { tail_call && { c || c++11 } } } } */ + +float f1(void); + +int f2(void) +{ + [[gnu::musttail]] return f1 (); /* { dg-error "changed after call" } */ +} + + +int f3(int *); + +int f4(void) +{ + int x; + [[gnu::musttail]] return f3(&x); /* { dg-error "\(refers to locals|other reasons\)" } */ +} diff --git a/gcc/testsuite/g++.dg/musttail10.C b/gcc/testsuite/g++.dg/musttail10.C new file mode 100644 index 000000000000..836958ad40fe --- /dev/null +++ b/gcc/testsuite/g++.dg/musttail10.C @@ -0,0 +1,34 @@ +/* { dg-do compile { target { tail_call } } } */ +/* { dg-options "-std=gnu++11" } */ +/* { dg-additional-options "-fdelayed-branch" { target sparc*-*-* } } */ + +int f(); + +double h() { [[gnu::musttail]] return f(); } /* { dg-error "cannot tail-call" } */ + +template +__attribute__((noinline, noclone, noipa)) +T g1() { [[gnu::musttail]] return f(); } /* { dg-error "target is not able" "" { target powerpc*-*-* } } */ + +template +__attribute__((noinline, noclone, noipa)) +T g2() { [[gnu::musttail]] return f(); } /* { dg-error "cannot tail-call" } */ + +template +__attribute__((noinline, noclone, noipa)) +T g3() { [[gnu::musttail]] return f(); } /* { dg-error "cannot tail-call" } */ + +class C +{ + double x; +public: + C(double x) : x(x) {} + ~C() { asm("":::"memory"); } +}; + +int main() +{ + g1(); + g2(); + g3(); +} diff --git a/gcc/testsuite/g++.dg/musttail6.C b/gcc/testsuite/g++.dg/musttail6.C new file mode 100644 index 000000000000..cc733edc73cd --- /dev/null +++ b/gcc/testsuite/g++.dg/musttail6.C @@ -0,0 +1,59 @@ +/* { dg-do compile { target { tail_call } } } */ +/* { dg-skip-if "powerpc does not support sibcall to templates" { powerpc*-*-* } } */ +/* { dg-options "-std=gnu++11" } */ +/* { dg-additional-options "-fdelayed-branch" { target sparc*-*-* } } */ + +class Foo { +public: + int a, b; + Foo(int a, int b) : a(a), b(b) {} +}; + +Foo __attribute__((noinline,noclone,noipa)) +callee (int i) +{ + return Foo(i, i+1); +} + +Foo __attribute__((noinline,noclone,noipa)) +caller (int i) +{ + [[gnu::musttail]] return callee (i + 1); +} + +template +T __attribute__((noinline,noclone,noipa)) foo (T i) +{ + return i + 1; +} + +int +caller2 (int k) +{ + [[gnu::musttail]] return foo(1); +} + +template +T caller3 (T v) +{ + [[gnu::musttail]] return foo(v); +} + +int call3(int i) +{ + [[gnu::musttail]] return caller3(i + 1); +} + +struct Bar { + int a; + Bar(int a) : a(a) {} + Bar operator+(Bar o) { return Bar(a + o.a); } +}; + +#if __OPTIMIZE__ >= 1 +Bar +caller4 (Bar k) +{ + [[gnu::musttail]] return caller3(Bar(99)); +} +#endif diff --git a/gcc/testsuite/g++.dg/musttail9.C b/gcc/testsuite/g++.dg/musttail9.C new file mode 100644 index 000000000000..fb0262e751be --- /dev/null +++ b/gcc/testsuite/g++.dg/musttail9.C @@ -0,0 +1,10 @@ +/* { dg-do compile { target { tail_call } } } */ +/* { dg-options "-std=gnu++11" } */ +/* { dg-additional-options "-fdelayed-branch" { target sparc*-*-* } } */ + +extern void foo(); + +void f() noexcept +{ + [[gnu::musttail]] return foo(); /* { dg-error "call may throw exception that does not propagate" } */ +} From patchwork Sat Jun 22 18:54:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Kleen X-Patchwork-Id: 1951122 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; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=cZmHyo22; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; 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 [8.43.85.97]) (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 4W63Rx58nXz1ydW for ; Sun, 23 Jun 2024 04:59:25 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E309B385DDEE for ; Sat, 22 Jun 2024 18:59:23 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) by sourceware.org (Postfix) with ESMTPS id 082C5385DDE0 for ; Sat, 22 Jun 2024 18:56:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 082C5385DDE0 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.intel.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=linux.intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 082C5385DDE0 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=198.175.65.17 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719082584; cv=none; b=gwKvCxuyT/RsBtdPM+uBGN4BbtolW4aARFZbvSm5HI7WtYYhQvxc1TDDYBXqtkp2EgieTq6c22B45UaV8XgwvAYGXxO2if7UWPM6ZlxmXXm7TbQgMn4Nz7HDt+GeH34GkvkpMyAV84aLANdpZvocZAMq0rKR+QDpkAEOJUY0LJI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719082584; c=relaxed/simple; bh=dqUFozLolVFNqyqtTNs/N9Tra6N9+CuocD8WCyBZ3FQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=bnpPc+GbGX29ZRD2RQWqC8heH6u5K60RT1rr5MB2QmckyNtXcbleCaHyhKE2JuK5yVXTAG/+mpfbndqYo7Ix43YdQrkKHIMtmvZ9xsnbRbD1i/ygsdk7cTeCXhc2m1GV6k/LKOklodTzF0FztQQsP6ToaJheO7kpqVriEJvlVuk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719082574; x=1750618574; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dqUFozLolVFNqyqtTNs/N9Tra6N9+CuocD8WCyBZ3FQ=; b=cZmHyo22JMl6f/SSn+iaFdNovjJ7tgPmsxCCD7j+m1E8mwFwAhSXQxuE omiqpQYl/RIh/iCncCFM4GCtleuwJUWTJ+oMjdTh9y4mwRozizLHAY61L d790lB1Qqa+QNdYqwAexZMID3L/4eQ/F9EPU3/XUEREzHQZk+g7YOQZ85 AGma54BL5+ApvnbgGRUzAEV/Q2qLwvzm9RaymS5J6KSSv0coTebyhnRLB oXIcZQTQuw2DhNQEEkJSgWda3bEz/YkQ6e02Ge23bCmGTiBJxBMEo8DRm SC3D/gY2xCHLOs0fgVqmhx+8idrdxKVRG0rC9qINz7B/ZVmHgZ989i/Md A==; X-CSE-ConnectionGUID: Yi0G5nr+QCO4W5hk5RmTFQ== X-CSE-MsgGUID: p7ibKWWpRj+LwzDVATSelg== X-IronPort-AV: E=McAfee;i="6700,10204,11111"; a="16216443" X-IronPort-AV: E=Sophos;i="6.08,258,1712646000"; d="scan'208";a="16216443" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2024 11:56:06 -0700 X-CSE-ConnectionGUID: zjksWiyrStS2CZ0PcY+Djw== X-CSE-MsgGUID: 6RP/IyISQW6IsKmpb58LBg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,258,1712646000"; d="scan'208";a="42968338" Received: from tassilo.jf.intel.com ([10.54.38.190]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2024 11:56:05 -0700 From: Andi Kleen To: gcc-patches@gcc.gnu.org Cc: Andi Kleen Subject: [PATCH v8 07/12] Enable musttail tail conversion even when not optimizing Date: Sat, 22 Jun 2024 11:54:39 -0700 Message-ID: <20240622185557.1589179-8-ak@linux.intel.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240622185557.1589179-1-ak@linux.intel.com> References: <20240622185557.1589179-1-ak@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_NONE, TXREP 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 Enable the tailcall optimization for non optimizing builds, but in this case only checks calls that have the musttail attribute set. This makes musttail work without optimization. This is done with a new late musttail pass that is only active when not optimizing. The new pass relies on tree-cfg to discover musttails. This avoids a ~0.8% compiler run time penalty at -O0. gcc/ChangeLog: * function.h (struct function): Add has_musttail. * lto-streamer-in.cc (input_struct_function_base): Stream has_musttail. * lto-streamer-out.cc (output_struct_function_base): Dito. * passes.def (pass_musttail): Add. * tree-cfg.cc (notice_special_calls): Record has_musttail. (clear_special_calls): Clear has_musttail. * tree-pass.h (make_pass_musttail): Add. * tree-tailcall.cc (find_tail_calls): Handle only_musttail argument. (tree_optimize_tail_calls_1): Pass on only_musttail. (execute_tail_calls): Pass only_musttail as false. (class pass_musttail): Add. (make_pass_musttail): Add. --- gcc/function.h | 3 ++ gcc/lto-streamer-in.cc | 1 + gcc/lto-streamer-out.cc | 1 + gcc/passes.def | 1 + gcc/tree-cfg.cc | 3 ++ gcc/tree-pass.h | 1 + gcc/tree-tailcall.cc | 66 +++++++++++++++++++++++++++++++++++------ 7 files changed, 67 insertions(+), 9 deletions(-) diff --git a/gcc/function.h b/gcc/function.h index c0ba6cc1531a..fbeadeaf4104 100644 --- a/gcc/function.h +++ b/gcc/function.h @@ -430,6 +430,9 @@ struct GTY(()) function { /* Nonzero when the tail call has been identified. */ unsigned int tail_call_marked : 1; + /* Has musttail marked calls. */ + unsigned int has_musttail : 1; + /* Nonzero if the current function contains a #pragma GCC unroll. */ unsigned int has_unroll : 1; diff --git a/gcc/lto-streamer-in.cc b/gcc/lto-streamer-in.cc index ad0ca24007a0..2e592be80823 100644 --- a/gcc/lto-streamer-in.cc +++ b/gcc/lto-streamer-in.cc @@ -1325,6 +1325,7 @@ input_struct_function_base (struct function *fn, class data_in *data_in, fn->calls_eh_return = bp_unpack_value (&bp, 1); fn->has_force_vectorize_loops = bp_unpack_value (&bp, 1); fn->has_simduid_loops = bp_unpack_value (&bp, 1); + fn->has_musttail = bp_unpack_value (&bp, 1); fn->assume_function = bp_unpack_value (&bp, 1); fn->va_list_fpr_size = bp_unpack_value (&bp, 8); fn->va_list_gpr_size = bp_unpack_value (&bp, 8); diff --git a/gcc/lto-streamer-out.cc b/gcc/lto-streamer-out.cc index d4f728094ed5..0be381abbd96 100644 --- a/gcc/lto-streamer-out.cc +++ b/gcc/lto-streamer-out.cc @@ -2290,6 +2290,7 @@ output_struct_function_base (struct output_block *ob, struct function *fn) bp_pack_value (&bp, fn->calls_eh_return, 1); bp_pack_value (&bp, fn->has_force_vectorize_loops, 1); bp_pack_value (&bp, fn->has_simduid_loops, 1); + bp_pack_value (&bp, fn->has_musttail, 1); bp_pack_value (&bp, fn->assume_function, 1); bp_pack_value (&bp, fn->va_list_fpr_size, 8); bp_pack_value (&bp, fn->va_list_gpr_size, 8); diff --git a/gcc/passes.def b/gcc/passes.def index 041229e47a68..5b5390e6ac0b 100644 --- a/gcc/passes.def +++ b/gcc/passes.def @@ -444,6 +444,7 @@ along with GCC; see the file COPYING3. If not see NEXT_PASS (pass_tsan_O0); NEXT_PASS (pass_sanopt); NEXT_PASS (pass_cleanup_eh); + NEXT_PASS (pass_musttail); NEXT_PASS (pass_lower_resx); NEXT_PASS (pass_nrv); NEXT_PASS (pass_gimple_isel); diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc index 7fb7b92966be..e6fd1294b958 100644 --- a/gcc/tree-cfg.cc +++ b/gcc/tree-cfg.cc @@ -2290,6 +2290,8 @@ notice_special_calls (gcall *call) cfun->calls_alloca = true; if (flags & ECF_RETURNS_TWICE) cfun->calls_setjmp = true; + if (gimple_call_must_tail_p (call)) + cfun->has_musttail = true; } @@ -2301,6 +2303,7 @@ clear_special_calls (void) { cfun->calls_alloca = false; cfun->calls_setjmp = false; + cfun->has_musttail = false; } /* Remove PHI nodes associated with basic block BB and all edges out of BB. */ diff --git a/gcc/tree-pass.h b/gcc/tree-pass.h index edebb2be245d..59e53558034f 100644 --- a/gcc/tree-pass.h +++ b/gcc/tree-pass.h @@ -368,6 +368,7 @@ extern gimple_opt_pass *make_pass_sra (gcc::context *ctxt); extern gimple_opt_pass *make_pass_sra_early (gcc::context *ctxt); extern gimple_opt_pass *make_pass_tail_recursion (gcc::context *ctxt); extern gimple_opt_pass *make_pass_tail_calls (gcc::context *ctxt); +extern gimple_opt_pass *make_pass_musttail (gcc::context *ctxt); extern gimple_opt_pass *make_pass_fix_loops (gcc::context *ctxt); extern gimple_opt_pass *make_pass_tree_loop (gcc::context *ctxt); extern gimple_opt_pass *make_pass_tree_no_loop (gcc::context *ctxt); diff --git a/gcc/tree-tailcall.cc b/gcc/tree-tailcall.cc index e9f7f8a12b3a..0c6df10e64f7 100644 --- a/gcc/tree-tailcall.cc +++ b/gcc/tree-tailcall.cc @@ -408,10 +408,10 @@ static live_vars_map *live_vars; static vec live_vars_vec; /* Finds tailcalls falling into basic block BB. The list of found tailcalls is - added to the start of RET. */ + added to the start of RET. When ONLY_MUSTTAIL is set only handle musttail. */ static void -find_tail_calls (basic_block bb, struct tailcall **ret) +find_tail_calls (basic_block bb, struct tailcall **ret, bool only_musttail) { tree ass_var = NULL_TREE, ret_var, func, param; gimple *stmt; @@ -445,6 +445,9 @@ find_tail_calls (basic_block bb, struct tailcall **ret) if (is_gimple_call (stmt)) { call = as_a (stmt); + /* Handle only musttail calls when not optimizing. */ + if (only_musttail && !gimple_call_must_tail_p (call)) + return; ass_var = gimple_call_lhs (call); break; } @@ -467,7 +470,7 @@ find_tail_calls (basic_block bb, struct tailcall **ret) edge_iterator ei; /* Recurse to the predecessors. */ FOR_EACH_EDGE (e, ei, bb->preds) - find_tail_calls (e->src, ret); + find_tail_calls (e->src, ret, only_musttail); return; } @@ -528,7 +531,8 @@ find_tail_calls (basic_block bb, struct tailcall **ret) func = gimple_call_fndecl (call); if (func && !fndecl_built_in_p (func) - && recursive_call_p (current_function_decl, func)) + && recursive_call_p (current_function_decl, func) + && !only_musttail) { tree arg; @@ -1094,10 +1098,11 @@ create_tailcall_accumulator (const char *label, basic_block bb, tree init) } /* Optimizes tail calls in the function, turning the tail recursion - into iteration. */ + into iteration. When ONLY_MUSTCALL is true only optimize mustcall + marked calls. */ static unsigned int -tree_optimize_tail_calls_1 (bool opt_tailcalls) +tree_optimize_tail_calls_1 (bool opt_tailcalls, bool only_mustcall) { edge e; bool phis_constructed = false; @@ -1117,7 +1122,7 @@ tree_optimize_tail_calls_1 (bool opt_tailcalls) /* Only traverse the normal exits, i.e. those that end with return statement. */ if (safe_is_a (*gsi_last_bb (e->src))) - find_tail_calls (e->src, &tailcalls); + find_tail_calls (e->src, &tailcalls, only_mustcall); } if (live_vars) @@ -1228,7 +1233,7 @@ gate_tail_calls (void) static unsigned int execute_tail_calls (void) { - return tree_optimize_tail_calls_1 (true); + return tree_optimize_tail_calls_1 (true, false); } namespace { @@ -1261,7 +1266,7 @@ public: bool gate (function *) final override { return gate_tail_calls (); } unsigned int execute (function *) final override { - return tree_optimize_tail_calls_1 (false); + return tree_optimize_tail_calls_1 (false, false); } }; // class pass_tail_recursion @@ -1312,3 +1317,46 @@ make_pass_tail_calls (gcc::context *ctxt) { return new pass_tail_calls (ctxt); } + +namespace { + +const pass_data pass_data_musttail = +{ + GIMPLE_PASS, /* type */ + "musttail", /* name */ + OPTGROUP_NONE, /* optinfo_flags */ + TV_NONE, /* tv_id */ + ( PROP_cfg | PROP_ssa ), /* properties_required */ + 0, /* properties_provided */ + 0, /* properties_destroyed */ + 0, /* todo_flags_start */ + 0, /* todo_flags_finish */ +}; + +class pass_musttail : public gimple_opt_pass +{ +public: + pass_musttail (gcc::context *ctxt) + : gimple_opt_pass (pass_data_musttail, ctxt) + {} + + /* opt_pass methods: */ + /* This pass is only used when not optimizing to make [[musttail]] still + work. */ + bool gate (function *) final override { return !flag_optimize_sibling_calls; } + unsigned int execute (function *f) final override + { + if (!f->has_musttail) + return 0; + return tree_optimize_tail_calls_1 (true, true); + } + +}; // class pass_musttail + +} // anon namespace + +gimple_opt_pass * +make_pass_musttail (gcc::context *ctxt) +{ + return new pass_musttail (ctxt); +} From patchwork Sat Jun 22 18:54:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Kleen X-Patchwork-Id: 1951126 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; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=Etml8HjN; 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 4W63V83jBvz20X6 for ; Sun, 23 Jun 2024 05:01:20 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C412F385DDD9 for ; Sat, 22 Jun 2024 19:01:18 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) by sourceware.org (Postfix) with ESMTPS id 83610385DDD4 for ; Sat, 22 Jun 2024 18:56:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 83610385DDD4 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.intel.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=linux.intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 83610385DDD4 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=198.175.65.17 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719082591; cv=none; b=p++mOpeZoBf9BdJx/Jj26WOy+ljaE9bZRv/8AjtYeojIcH6tZgNZPeXN4kckkTZx2oXEJfW/qtwYTYOf4anjzALRbD1jpREk++Cx8yGSuQkXsimgZSOWs2ntR0GTsYT4Yir+tRJPG1IfcdNahAft0VPy/mXgvjcd31aujoYaoyY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719082591; c=relaxed/simple; bh=qDW9xqDp62jNVnG3BqX34Q+d++fLjLGOsM8/ER/V6TM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=naHtmVNGDM1S/xPbo+mWa5/9uMPsk+/6UT0BYp8Zc0ok5uPd06QDi/8OhSTH3XN94n8/4gi+k7O1J7Eraihl/+gkTwDnmdPV2erUEAhsb5S2/lQySaAwXZAXDiMv/46rEOlHeAsH30vD1mNrSX+C03htIXTt9GO976dAaoPJAIc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719082585; x=1750618585; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qDW9xqDp62jNVnG3BqX34Q+d++fLjLGOsM8/ER/V6TM=; b=Etml8HjNt/3VOybRXK1di0IVIztK3F4Q/IxU+UY6lkVuQXUu3tMt7P02 vUdoIpDNCDDSQVWJvwUaO0BnFw+tixYLKJz6+sBN2U44xp/blcUb5zkmu 84npGiXGxvkNEPwWOYUTCPTzl4o+VezWsJ09QmoVbH2HmO90N4SK7rCQ/ i5WeNh2eXqqa0gRk+Tz4PJKBeQXAP9SEGl7bStpwssJt4TUoQojwlmyIz 4BoUozS2uTmgVJ6dVK9SWGlvqzNMhqAuMwdFox3+wRV/3GuG2yKGNLMSq 64x0Ry76r+djbBGAFT8zH/g1gI1H8rRk5fqxCMnubqMp58uDxycmFzXAU A==; X-CSE-ConnectionGUID: KlQJrJ7YSvCqSWj5vSACkw== X-CSE-MsgGUID: rWvHunhPRPOJZ1zf2Uk2dA== X-IronPort-AV: E=McAfee;i="6700,10204,11111"; a="16216444" X-IronPort-AV: E=Sophos;i="6.08,258,1712646000"; d="scan'208";a="16216444" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2024 11:56:06 -0700 X-CSE-ConnectionGUID: 6r3hG4eeRN2g2P99u9cMIQ== X-CSE-MsgGUID: jfsBj9ZRQhmBgRNEL10Nag== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,258,1712646000"; d="scan'208";a="42968339" Received: from tassilo.jf.intel.com ([10.54.38.190]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2024 11:56:05 -0700 From: Andi Kleen To: gcc-patches@gcc.gnu.org Cc: Andi Kleen Subject: [PATCH v8 08/12] Give better error messages for musttail Date: Sat, 22 Jun 2024 11:54:40 -0700 Message-ID: <20240622185557.1589179-9-ak@linux.intel.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240622185557.1589179-1-ak@linux.intel.com> References: <20240622185557.1589179-1-ak@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_NONE, TXREP 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 When musttail is set, make tree-tailcall give error messages when it cannot handle a call. This avoids vague "other reasons" error messages later at expand time when it sees a musttail function not marked tail call. In various cases this requires delaying the error until the call is discovered. gcc/ChangeLog: * tree-tailcall.cc (maybe_error_musttail): New function. (bb_get_succ_edge_count): New function. (find_tail_calls): Add error reporting. Handle EH edges for error reporting. --- gcc/tree-tailcall.cc | 116 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 102 insertions(+), 14 deletions(-) diff --git a/gcc/tree-tailcall.cc b/gcc/tree-tailcall.cc index 0c6df10e64f7..4687e20e61d0 100644 --- a/gcc/tree-tailcall.cc +++ b/gcc/tree-tailcall.cc @@ -40,9 +40,11 @@ along with GCC; see the file COPYING3. If not see #include "tree-eh.h" #include "dbgcnt.h" #include "cfgloop.h" +#include "intl.h" #include "common/common-target.h" #include "ipa-utils.h" #include "tree-ssa-live.h" +#include "diagnostic-core.h" /* The file implements the tail recursion elimination. It is also used to analyze the tail calls in general, passing the results to the rtl level @@ -402,6 +404,41 @@ propagate_through_phis (tree var, edge e) return var; } +/* Report an error for failing to tail convert must call CALL + with error message ERR. Also clear the flag to prevent further + errors. */ + +static void +maybe_error_musttail (gcall *call, const char *err) +{ + if (gimple_call_must_tail_p (call)) + { + error_at (call->location, "cannot tail-call: %s", err); + /* Avoid another error. ??? If there are multiple reasons why tail + calls fail it might be useful to report them all to avoid + whack-a-mole for the user. But currently there is too much + redundancy in the reporting, so keep it simple. */ + gimple_call_set_must_tail (call, false); /* Avoid another error. */ + gimple_call_set_tail (call, false); + } +} + +/* Count succ edges for BB and return in NUM_OTHER and NUM_EH. */ + +static void +bb_get_succ_edge_count (basic_block bb, int &num_other, int &num_eh) +{ + edge e; + edge_iterator ei; + num_eh = 0; + num_other = 0; + FOR_EACH_EDGE (e, ei, bb->succs) + if (e->flags & EDGE_EH) + num_eh++; + else + num_other++; +} + /* Argument for compute_live_vars/live_vars_at_stmt and what compute_live_vars returns. Computed lazily, but just once for the function. */ static live_vars_map *live_vars; @@ -426,8 +463,16 @@ find_tail_calls (basic_block bb, struct tailcall **ret, bool only_musttail) tree var; if (!single_succ_p (bb)) - return; + { + int num_eh, num_other; + bb_get_succ_edge_count (bb, num_eh, num_other); + /* Allow EH edges so that we can give a better + error message later. */ + if (num_other != 1) + return; + } + bool bad_stmt = false; for (gsi = gsi_last_bb (bb); !gsi_end_p (gsi); gsi_prev (&gsi)) { stmt = gsi_stmt (gsi); @@ -448,6 +493,12 @@ find_tail_calls (basic_block bb, struct tailcall **ret, bool only_musttail) /* Handle only musttail calls when not optimizing. */ if (only_musttail && !gimple_call_must_tail_p (call)) return; + if (bad_stmt) + { + maybe_error_musttail (call, + _("memory reference or volatile after call")); + return; + } ass_var = gimple_call_lhs (call); break; } @@ -462,9 +513,14 @@ find_tail_calls (basic_block bb, struct tailcall **ret, bool only_musttail) /* If the statement references memory or volatile operands, fail. */ if (gimple_references_memory_p (stmt) || gimple_has_volatile_ops (stmt)) - return; + { + bad_stmt = true; + } } + if (bad_stmt) + return; + if (gsi_end_p (gsi)) { edge_iterator ei; @@ -489,13 +545,26 @@ find_tail_calls (basic_block bb, struct tailcall **ret, bool only_musttail) if (ass_var && !is_gimple_reg (ass_var) && !auto_var_in_fn_p (ass_var, cfun->decl)) - return; + { + maybe_error_musttail (call, _("return value in memory")); + return; + } + + if (cfun->calls_setjmp) + { + maybe_error_musttail (call, _("caller uses setjmp")); + return; + } /* If the call might throw an exception that wouldn't propagate out of cfun, we can't transform to a tail or sibling call (82081). */ - if (stmt_could_throw_p (cfun, stmt) - && !stmt_can_throw_external (cfun, stmt)) + if ((stmt_could_throw_p (cfun, stmt) + && !stmt_can_throw_external (cfun, stmt)) || !single_succ_p (bb)) + { + maybe_error_musttail (call, + _("call may throw exception that does not propagate")); return; + } /* If the function returns a value, then at present, the tail call must return the same type of value. There is conceptually a copy @@ -524,7 +593,10 @@ find_tail_calls (basic_block bb, struct tailcall **ret, bool only_musttail) if (result_decl && may_be_aliased (result_decl) && ref_maybe_used_by_stmt_p (call, result_decl, false)) - return; + { + maybe_error_musttail (call, _("tail call must be same type")); + return; + } /* We found the call, check whether it is suitable. */ tail_recursion = false; @@ -605,6 +677,7 @@ find_tail_calls (basic_block bb, struct tailcall **ret, bool only_musttail) { if (local_live_vars) BITMAP_FREE (local_live_vars); + maybe_error_musttail (call, _("call invocation refers to locals")); return; } else @@ -613,6 +686,7 @@ find_tail_calls (basic_block bb, struct tailcall **ret, bool only_musttail) if (bitmap_bit_p (local_live_vars, *v)) { BITMAP_FREE (local_live_vars); + maybe_error_musttail (call, _("call invocation refers to locals")); return; } } @@ -658,17 +732,21 @@ find_tail_calls (basic_block bb, struct tailcall **ret, bool only_musttail) continue; if (gimple_code (stmt) != GIMPLE_ASSIGN) - return; + { + maybe_error_musttail (call, _("unhandled code after call")); + return; + } /* This is a gimple assign. */ par ret = process_assignment (as_a (stmt), gsi, &tmp_m, &tmp_a, &ass_var, to_move_defs); - if (ret == FAIL) - return; + if (ret == FAIL || (ret == TRY_MOVE && !tail_recursion)) + { + maybe_error_musttail (call, _("return value changed after call")); + return; + } else if (ret == TRY_MOVE) { - if (! tail_recursion) - return; /* Do not deal with checking dominance, the real fix is to do path isolation for the transform phase anyway, removing the need to compute the accumulators with new stmts. */ @@ -716,16 +794,26 @@ find_tail_calls (basic_block bb, struct tailcall **ret, bool only_musttail) if (ret_var && (ret_var != ass_var && !(is_empty_type (TREE_TYPE (ret_var)) && !ass_var))) - return; + { + maybe_error_musttail (call, _("call must be the same type")); + return; + } /* If this is not a tail recursive call, we cannot handle addends or multiplicands. */ if (!tail_recursion && (m || a)) - return; + { + maybe_error_musttail (call, _("operations after non tail recursive call")); + return; + } /* For pointers only allow additions. */ if (m && POINTER_TYPE_P (TREE_TYPE (DECL_RESULT (current_function_decl)))) - return; + { + maybe_error_musttail (call, + _("tail recursion with pointers can only use additions")); + return; + } /* Move queued defs. */ if (tail_recursion) From patchwork Sat Jun 22 18:54:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Kleen X-Patchwork-Id: 1951123 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; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=U78BqOYr; 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 4W63Sq3Dlnz20X6 for ; Sun, 23 Jun 2024 05:00:11 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BBFBC385DDF9 for ; Sat, 22 Jun 2024 19:00:09 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) by sourceware.org (Postfix) with ESMTPS id 83A0E385DDF3 for ; Sat, 22 Jun 2024 18:56:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 83A0E385DDF3 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.intel.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=linux.intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 83A0E385DDF3 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=198.175.65.17 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719082591; cv=none; b=HjEK+Ms4JelHmcUD9caF4IcRUbFVQq5V7LtZkYXvZDBqnJ25MaRJp1mZDZ4An+JdBsEF4tXPO3jWdWwtHcnTuXuoXw/8gOOg9DxvV0y5yQUmw6Avy0CTAtkfKyXmkknDlQRRDeJRLx3hYvuJrhumtXZk3nL/rLMCIUg4FDErOcQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719082591; c=relaxed/simple; bh=7utk2TQu5gY9FUr2z+DKnMwEgWYL/jM3bu5tlpRdodk=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ivP4vAdQshT7q8VFdd+4Oyj07np1CK81NwCqKDsEIhLRoYkKDISePRGVq9bUNe6iRU0LahkmUxtrICKcq4+h11MiGt60Zj871gdrWinqf5asZarHrUl7JB3yuM3zihr1JkheaVthIgO4sQ28Wz84qI3+4JGUFz9s7vraiyJOFns= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719082585; x=1750618585; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7utk2TQu5gY9FUr2z+DKnMwEgWYL/jM3bu5tlpRdodk=; b=U78BqOYrvqHBgrXG7kOpa10sgkPmigbXldNvu/LddulOxkWkeh1BEBH7 RgxB1ks47j8/MBVwNFoXH3fo4vzzK5GAl1ZbmbTBqXAnEzv7lwN3pydBr fy4c5GRROf6RDrZTrH9ea3OUc7/SI6uIKZg5mCJcmVZkpLvpTvk0dRZk4 ZadNBMQyr7b7J4sLcMmQQKejfhDVm5qdMFnS5YYLxSCU/XE77nlOKyWYX 0ihu4/D2vW5CX6TK+/J4jSKstklVUkDUh7BlMqm5QjBz1iiRFs+txp6sq eZMuhjDRTvFcbOV16gghKu4vtjzkAcUY/XxlBirLbkkJYPSJvOHeMRCoV w==; X-CSE-ConnectionGUID: bLj2eN/QQ7azlAEoM8iV0w== X-CSE-MsgGUID: WZfPYlFxSEKJFydg4bHNPQ== X-IronPort-AV: E=McAfee;i="6700,10204,11111"; a="16216445" X-IronPort-AV: E=Sophos;i="6.08,258,1712646000"; d="scan'208";a="16216445" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2024 11:56:06 -0700 X-CSE-ConnectionGUID: NiPe/n1MRYeOzgvUKZMiHw== X-CSE-MsgGUID: TXLKx5suSnWC4Y3U4mBLpA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,258,1712646000"; d="scan'208";a="42968340" Received: from tassilo.jf.intel.com ([10.54.38.190]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2024 11:56:05 -0700 From: Andi Kleen To: gcc-patches@gcc.gnu.org Cc: Andi Kleen Subject: [PATCH v8 09/12] Delay caller error reporting for musttail Date: Sat, 22 Jun 2024 11:54:41 -0700 Message-ID: <20240622185557.1589179-10-ak@linux.intel.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240622185557.1589179-1-ak@linux.intel.com> References: <20240622185557.1589179-1-ak@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_NONE, TXREP 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 Move the error reporting for caller attributes to be after the tail call discovery, so that we can give proper error messages tagged to the calls. gcc/ChangeLog: * tree-tailcall.cc (maybe_error_musttail): Declare. (suitable_for_tail_opt_p): Take call and report errors. (suitable_for_tail_call_opt_p): Take call and report errors. (find_tail_calls): Report caller errors after discovery. (tree_optimize_tail_calls_1): Remove caller suitableness check. --- gcc/tree-tailcall.cc | 62 ++++++++++++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 19 deletions(-) diff --git a/gcc/tree-tailcall.cc b/gcc/tree-tailcall.cc index 4687e20e61d0..a77fa1511415 100644 --- a/gcc/tree-tailcall.cc +++ b/gcc/tree-tailcall.cc @@ -133,14 +133,20 @@ static tree m_acc, a_acc; static bitmap tailr_arg_needs_copy; +static void maybe_error_musttail (gcall *call, const char *err); + /* Returns false when the function is not suitable for tail call optimization - from some reason (e.g. if it takes variable number of arguments). */ + from some reason (e.g. if it takes variable number of arguments). CALL + is call to report for. */ static bool -suitable_for_tail_opt_p (void) +suitable_for_tail_opt_p (gcall *call) { if (cfun->stdarg) - return false; + { + maybe_error_musttail (call, _("caller uses stdargs")); + return false; + } return true; } @@ -148,35 +154,47 @@ suitable_for_tail_opt_p (void) /* Returns false when the function is not suitable for tail call optimization for some reason (e.g. if it takes variable number of arguments). This test must pass in addition to suitable_for_tail_opt_p in order to make - tail call discovery happen. */ + tail call discovery happen. CALL is call to report error for. */ static bool -suitable_for_tail_call_opt_p (void) +suitable_for_tail_call_opt_p (gcall *call) { tree param; /* alloca (until we have stack slot life analysis) inhibits sibling call optimizations, but not tail recursion. */ if (cfun->calls_alloca) - return false; + { + maybe_error_musttail (call, _("caller uses alloca")); + return false; + } /* If we are using sjlj exceptions, we may need to add a call to _Unwind_SjLj_Unregister at exit of the function. Which means that we cannot do any sibcall transformations. */ if (targetm_common.except_unwind_info (&global_options) == UI_SJLJ && current_function_has_exception_handlers ()) - return false; + { + maybe_error_musttail (call, _("caller uses sjlj exceptions")); + return false; + } /* Any function that calls setjmp might have longjmp called from any called function. ??? We really should represent this properly in the CFG so that this needn't be special cased. */ if (cfun->calls_setjmp) - return false; + { + maybe_error_musttail (call, _("caller uses setjmp")); + return false; + } /* Various targets don't handle tail calls correctly in functions that call __builtin_eh_return. */ if (cfun->calls_eh_return) - return false; + { + maybe_error_musttail (call, _("caller uses __builtin_eh_return")); + return false; + } /* ??? It is OK if the argument of a function is taken in some cases, but not in all cases. See PR15387 and PR19616. Revisit for 4.1. */ @@ -184,7 +202,10 @@ suitable_for_tail_call_opt_p (void) param; param = DECL_CHAIN (param)) if (TREE_ADDRESSABLE (param)) - return false; + { + maybe_error_musttail (call, _("address of caller arguments taken")); + return false; + } return true; } @@ -445,10 +466,12 @@ static live_vars_map *live_vars; static vec live_vars_vec; /* Finds tailcalls falling into basic block BB. The list of found tailcalls is - added to the start of RET. When ONLY_MUSTTAIL is set only handle musttail. */ + added to the start of RET. When ONLY_MUSTTAIL is set only handle musttail. + Update OPT_TAILCALLS as output parameter. */ static void -find_tail_calls (basic_block bb, struct tailcall **ret, bool only_musttail) +find_tail_calls (basic_block bb, struct tailcall **ret, bool only_musttail, + bool &opt_tailcalls) { tree ass_var = NULL_TREE, ret_var, func, param; gimple *stmt; @@ -526,11 +549,17 @@ find_tail_calls (basic_block bb, struct tailcall **ret, bool only_musttail) edge_iterator ei; /* Recurse to the predecessors. */ FOR_EACH_EDGE (e, ei, bb->preds) - find_tail_calls (e->src, ret, only_musttail); + find_tail_calls (e->src, ret, only_musttail, opt_tailcalls); return; } + if (!suitable_for_tail_opt_p (call)) + return; + + if (!suitable_for_tail_call_opt_p (call)) + opt_tailcalls = false; + /* If the LHS of our call is not just a simple register or local variable, we can't transform this into a tail or sibling call. This situation happens, in (e.g.) "*p = foo()" where foo returns a @@ -1200,17 +1229,12 @@ tree_optimize_tail_calls_1 (bool opt_tailcalls, bool only_mustcall) tree param; edge_iterator ei; - if (!suitable_for_tail_opt_p ()) - return 0; - if (opt_tailcalls) - opt_tailcalls = suitable_for_tail_call_opt_p (); - FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds) { /* Only traverse the normal exits, i.e. those that end with return statement. */ if (safe_is_a (*gsi_last_bb (e->src))) - find_tail_calls (e->src, &tailcalls, only_mustcall); + find_tail_calls (e->src, &tailcalls, only_mustcall, opt_tailcalls); } if (live_vars) From patchwork Sat Jun 22 18:54:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Kleen X-Patchwork-Id: 1951124 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; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=KMNcEDZA; 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 4W63T219fWz20X6 for ; Sun, 23 Jun 2024 05:00:22 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 635D9385DDE1 for ; Sat, 22 Jun 2024 19:00:20 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) by sourceware.org (Postfix) with ESMTPS id AB55F385DDE3 for ; Sat, 22 Jun 2024 18:56:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AB55F385DDE3 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.intel.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=linux.intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org AB55F385DDE3 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=198.175.65.17 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719082589; cv=none; b=XWXi6ZYTde5yx36TaoL8ucq1Cc0VxFNR66rnRfzwawwzrG+EkrWh36jwlnaNs2hNpe8yfL4vquuVP0yvBwdiDTNoxBruyd3o2cLsmwFWhGKAT8MhN/8UWl7YSHUD/kaCBPtlY3QjzQLJ0pwMT9J9vCC0p/Kx4b6nk9yMZfDXI1U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719082589; c=relaxed/simple; bh=Jryz1sYg/OJr3N4m1PAlmFhlf5Jd71+hw359hXOhCI4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=YeTabuVJyruX4lUqe1wPYGp5riRvjBoTLrLreqZmSGD364/ECa0YLVmAQqpCVkIKbNDcdrEWITjApVsuD5SFKpH+rhIh2bKk4h9+MsHpL9yOJsnc3+9mHRU/SochVzPeEZFOHij23tWfm93umZM5rg5AAgbyOyZBZ79N8pEkC/E= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719082585; x=1750618585; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Jryz1sYg/OJr3N4m1PAlmFhlf5Jd71+hw359hXOhCI4=; b=KMNcEDZApP3hkIxo0v1IzHo0SdKB2gDZPIyBGXdTZbzdAxqk2WzucIHA KusGfY0aESMM9V9sZNo3p3qksNGXJrftK6KLiQJHbGhYzlrkwtJLlNUw3 kCpWlZACusjI6hBVo6GpJ5ZB30kDjQBfJvx+wjLYdykQZQcTrinDV9Er2 hap3fGOBwapmKvedeEXk+n7Dzm/YzcF6HxbJRwM+YTJ1SEUncuUSY4fVC ct10HSOLbW8PVfFOqMwo9AZxMHcnYIcJ+E9HVmq+0qy9E3Exnh6Qq/ISr NSFRerIPNbh+Fs39J8jHRZZBQ5EFjQRlwFF3h7+1kxoYq6r8UzpaYMalb Q==; X-CSE-ConnectionGUID: E8EpS3OfRZGAFoRF/C5uXA== X-CSE-MsgGUID: vnHWUEKVRRynJnPI1+WszA== X-IronPort-AV: E=McAfee;i="6700,10204,11111"; a="16216446" X-IronPort-AV: E=Sophos;i="6.08,258,1712646000"; d="scan'208";a="16216446" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2024 11:56:06 -0700 X-CSE-ConnectionGUID: sWw99aFTSsKfou9NQO+sGA== X-CSE-MsgGUID: 3oFHoWOeSK2jnkfOfdnS5Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,258,1712646000"; d="scan'208";a="42968341" Received: from tassilo.jf.intel.com ([10.54.38.190]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2024 11:56:05 -0700 From: Andi Kleen To: gcc-patches@gcc.gnu.org Cc: Andi Kleen Subject: [PATCH v8 10/12] Add documentation for musttail attribute Date: Sat, 22 Jun 2024 11:54:42 -0700 Message-ID: <20240622185557.1589179-11-ak@linux.intel.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240622185557.1589179-1-ak@linux.intel.com> References: <20240622185557.1589179-1-ak@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_NONE, TXREP 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 gcc/ChangeLog: * doc/extend.texi: Document [[musttail]] --- gcc/doc/extend.texi | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index b2e41a581dd1..f83e643da19c 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -9921,7 +9921,7 @@ same manner as the @code{deprecated} attribute. @section Statement Attributes @cindex Statement Attributes -GCC allows attributes to be set on null statements. @xref{Attribute Syntax}, +GCC allows attributes to be set on statements. @xref{Attribute Syntax}, for details of the exact syntax for using attributes. Other attributes are available for functions (@pxref{Function Attributes}), variables (@pxref{Variable Attributes}), labels (@pxref{Label Attributes}), enumerators @@ -9978,6 +9978,25 @@ foo (int x, int y) @code{y} is not actually incremented and the compiler can but does not have to optimize it to just @code{return 42 + 42;}. +@cindex @code{musttail} statement attribute +@item musttail + +The @code{gnu::musttail} or @code{clang::musttail} attribute +can be applied to a @code{return} statement with a return-value expression +that is a function call. It asserts that the call must be a tail call that +does not allocate extra stack space, so it is safe to use tail recursion +to implement long running loops. + +@smallexample +[[gnu::musttail]] return foo(); +@end smallexample + +If the compiler cannot generate a @code{musttail} tail call it will report +an error. On some targets tail calls may never be supported. +Tail calls cannot reference locals in memory, which may affect +builds without optimization when passing small structures, or passing +or returning large structures. Enabling -O1 or -O2 can improve +the success of tail calls. @end table @node Attribute Syntax @@ -10101,7 +10120,9 @@ the constant expression, if present. @subsubheading Statement Attributes In GNU C, an attribute specifier list may appear as part of a null -statement. The attribute goes before the semicolon. +statement. The attribute goes before the semicolon. +Some attributes in new style syntax are also supported +on non-null statements. @subsubheading Type Attributes From patchwork Sat Jun 22 18:54:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Kleen X-Patchwork-Id: 1951125 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; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=SW7cLk1b; 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 4W63Tx0xB0z20X6 for ; Sun, 23 Jun 2024 05:01:09 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6AC4C385DDFE for ; Sat, 22 Jun 2024 19:01:07 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) by sourceware.org (Postfix) with ESMTPS id 9940C385DDC4 for ; Sat, 22 Jun 2024 18:56:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9940C385DDC4 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.intel.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=linux.intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9940C385DDC4 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=198.175.65.17 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719082592; cv=none; b=ZLu6u1uwqI5yBx06boU84JcsKDBG+FwIPSLWzsAU+ZbuqmkrIG3J4a4jv10YaO/vCFRSeLNlbBZrvhz3hFWLDzNT6B+8Xtq443tEFUejg0rfMp1ZeJx3xoLx4phEf/sHguC0JJx6PaujTMoy9CybITyhim8m+UeAucrzO9YPNu0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719082592; c=relaxed/simple; bh=uAXOksGL/SbBI6rO5m5wXziw0hcd2T3EcN1KTGNCG4g=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=r2YZjrH4CVNqcGooQ825/ZB+PHyPv8BtFpnPwPvheFMAwUOcsWk7w/awtwFp1cbXMB17CApysJsMjdijMFnV3mEW7WRRhygyC1r2MncQ4k/0zx/wWt3DU50h89wtuOSFH7kjh1oHUS8Q/06Iufz+D7gNzj0pPtEkhtXG+0isFyQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719082591; x=1750618591; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uAXOksGL/SbBI6rO5m5wXziw0hcd2T3EcN1KTGNCG4g=; b=SW7cLk1b6Xo028Hs3yn5e5VrBjD9ww93ZX80ci7h+/+u2hDpNRsdW/t8 +CUfA5wsC5x3Sb68WlpQfqJrw0Tk3UB4FWMgODNYICo2iXiqT0R0dYuu3 a9N5gDrBEYcZ5H6IdURtHdFl+wceQf1uHO7ZWlknkv02uj9C41EuPoo9o y9qObGS+wZoGUOcUgXvdD9ik9Q2896ZZdIWYUGWTNrajIlFiUYZz5Ekh1 Kji7VJ+o2wLnDzMhUIOcARKUHYtl0N+X6s9BG3LatKZaCZoVHnOLTduqS 4SHz0GHkLcKsLoNM0CtLD8jLKP3lviJ7MbLhGylsJbyHaaVlht228GBCM Q==; X-CSE-ConnectionGUID: mHw9dXMXSYqanHt8rgalqA== X-CSE-MsgGUID: 3SZUu0DATie2gbUhtM6lQQ== X-IronPort-AV: E=McAfee;i="6700,10204,11111"; a="16216447" X-IronPort-AV: E=Sophos;i="6.08,258,1712646000"; d="scan'208";a="16216447" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2024 11:56:06 -0700 X-CSE-ConnectionGUID: brJwgPqXS5mhFGe4ioRRuw== X-CSE-MsgGUID: FTdtH378RJmtyP5VaxpUxA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,258,1712646000"; d="scan'208";a="42968342" Received: from tassilo.jf.intel.com ([10.54.38.190]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2024 11:56:05 -0700 From: Andi Kleen To: gcc-patches@gcc.gnu.org Cc: Andi Kleen Subject: [PATCH v8 11/12] Dump reason for missing tail call into dump file Date: Sat, 22 Jun 2024 11:54:43 -0700 Message-ID: <20240622185557.1589179-12-ak@linux.intel.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240622185557.1589179-1-ak@linux.intel.com> References: <20240622185557.1589179-1-ak@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_NONE, TXREP 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 gcc/ChangeLog: * tree-tailcall.cc (maybe_error_musttail): Print reason to dump_file. (find_tail_calls): Print gimple stmt or other reasons that stop the search for tail calls into dump file. --- gcc/tree-tailcall.cc | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/gcc/tree-tailcall.cc b/gcc/tree-tailcall.cc index a77fa1511415..f69a9ad40bda 100644 --- a/gcc/tree-tailcall.cc +++ b/gcc/tree-tailcall.cc @@ -442,6 +442,11 @@ maybe_error_musttail (gcall *call, const char *err) gimple_call_set_must_tail (call, false); /* Avoid another error. */ gimple_call_set_tail (call, false); } + if (dump_file) + { + print_gimple_stmt (dump_file, call, 0, TDF_SLIM); + fprintf (dump_file, "Cannot convert: %s\n", err); + } } /* Count succ edges for BB and return in NUM_OTHER and NUM_EH. */ @@ -492,7 +497,12 @@ find_tail_calls (basic_block bb, struct tailcall **ret, bool only_musttail, /* Allow EH edges so that we can give a better error message later. */ if (num_other != 1) - return; + { + if (dump_file) + fprintf (dump_file, "Basic block %d has %d eh / %d other edges\n", + bb->index, num_eh, num_other); + return; + } } bool bad_stmt = false; @@ -537,6 +547,11 @@ find_tail_calls (basic_block bb, struct tailcall **ret, bool only_musttail, if (gimple_references_memory_p (stmt) || gimple_has_volatile_ops (stmt)) { + if (dump_file) + { + fprintf (dump_file, "Cannot handle "); + print_gimple_stmt (dump_file, stmt, 0); + } bad_stmt = true; } } From patchwork Sat Jun 22 18:54:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Kleen X-Patchwork-Id: 1951120 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; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=M1mH+Nh5; 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 4W63Qs1hYLz1ydW for ; Sun, 23 Jun 2024 04:58:29 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7E656385E003 for ; Sat, 22 Jun 2024 18:58:27 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) by sourceware.org (Postfix) with ESMTPS id 043BF385DDC0 for ; Sat, 22 Jun 2024 18:56:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 043BF385DDC0 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.intel.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=linux.intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 043BF385DDC0 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=198.175.65.17 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719082597; cv=none; b=qbvDxtPnSYMI30ZfriaX74vxSVYvns2Xi0Vc+v0UoHIf7Rj1KmAlxDofhMNM4S8RT/fBHUfgTRqTRo/AUmMWadijc7OAmF/1eb1mlsG2cqOSX4OCvM673ARwxPExpCtqWm8Qs2glNatEnwidBsZtPFeR6WJacQ6eoHZCwNQhjmw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719082597; c=relaxed/simple; bh=BYoc+sMDJXND2J4/MVfJQ7hSwM3zjbToRKynf4bPKzI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=phNYAzPUoH3sIo0CNCFgo5ooqgoqHaE8alor+wthR8YJtYD540osB2D9En9KVyh7R3GLo4fJKmDvvxkb3M4mUBdKOA+/O0Wbt/jyoZKIcYj6o9bqb4r8Ym620Kzl1IU4KsJBlisRvIO6IZ8AAEJq4q4JxJpceuiV6JoKHpKclvE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719082592; x=1750618592; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BYoc+sMDJXND2J4/MVfJQ7hSwM3zjbToRKynf4bPKzI=; b=M1mH+Nh55DHn5S+8EZLN3QdWE/4B7YCryxeA2Ris5Z4i/l/tHBnIJU3V V4v8tnlQig1KekFKP9jcH3/mDa50YVhTyel9ipPG8KzFJ/zMng9NtfXiR Zl0OcqjxFfwNVotp5vPMbi+Av7w+FBAl+enH+fjc86Gh8no3Mf3K0jqOY nDHu1Qmk5AnaaImn9mqkEr7qfUvJszfKXADSAc0oJ2xe6jAMIILDWlhrB dOFFDz5ebIAxZ454jeRn+w63VcuVBde8QZoYDZt4ZIETs00+HFCj0pnJC 2GpduijUU6ClCJ70PfZXFqW3cbYpaUuTYQTMVTjfFcvlaKzEOSYfQHe8I g==; X-CSE-ConnectionGUID: +E6nWbXpRkKGXQKiCjGXIA== X-CSE-MsgGUID: ZkPTvH/BTbWclcThNDSXSw== X-IronPort-AV: E=McAfee;i="6700,10204,11111"; a="16216448" X-IronPort-AV: E=Sophos;i="6.08,258,1712646000"; d="scan'208";a="16216448" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2024 11:56:06 -0700 X-CSE-ConnectionGUID: 2Sss40FGTkeFizY2ZBB3cQ== X-CSE-MsgGUID: snRcdRINR3aoAb97bguLWQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,258,1712646000"; d="scan'208";a="42968343" Received: from tassilo.jf.intel.com ([10.54.38.190]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2024 11:56:05 -0700 From: Andi Kleen To: gcc-patches@gcc.gnu.org Cc: Andi Kleen Subject: [PATCH v8 12/12] Mark expand musttail error messages for translation Date: Sat, 22 Jun 2024 11:54:44 -0700 Message-ID: <20240622185557.1589179-13-ak@linux.intel.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240622185557.1589179-1-ak@linux.intel.com> References: <20240622185557.1589179-1-ak@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_NONE, TXREP 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 The musttail error messages are reported to the user, so must be translated. gcc/ChangeLog: * calls.cc (initialize_argument_information): Mark messages for translation. (can_implement_as_sibling_call_p): Dito. (expand_call): Dito. --- gcc/calls.cc | 56 ++++++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/gcc/calls.cc b/gcc/calls.cc index 883eb9971257..f28c58217fdf 100644 --- a/gcc/calls.cc +++ b/gcc/calls.cc @@ -1420,9 +1420,9 @@ initialize_argument_information (int num_actuals ATTRIBUTE_UNUSED, { *may_tailcall = false; maybe_complain_about_tail_call (exp, - "a callee-copied argument is" - " stored in the current" - " function's frame"); + _("a callee-copied argument is" + " stored in the current" + " function's frame")); } args[i].tree_value = build_fold_addr_expr_loc (loc, @@ -1489,8 +1489,8 @@ initialize_argument_information (int num_actuals ATTRIBUTE_UNUSED, type = TREE_TYPE (args[i].tree_value); *may_tailcall = false; maybe_complain_about_tail_call (exp, - "argument must be passed" - " by copying"); + _("argument must be passed" + " by copying")); } arg.pass_by_reference = true; } @@ -2508,8 +2508,8 @@ can_implement_as_sibling_call_p (tree exp, { maybe_complain_about_tail_call (exp, - "machine description does not have" - " a sibcall_epilogue instruction pattern"); + _("machine description does not have" + " a sibcall_epilogue instruction pattern")); return false; } @@ -2519,7 +2519,7 @@ can_implement_as_sibling_call_p (tree exp, sibling calls will return a structure. */ if (structure_value_addr != NULL_RTX) { - maybe_complain_about_tail_call (exp, "callee returns a structure"); + maybe_complain_about_tail_call (exp, _("callee returns a structure")); return false; } @@ -2528,8 +2528,8 @@ can_implement_as_sibling_call_p (tree exp, if (!targetm.function_ok_for_sibcall (fndecl, exp)) { maybe_complain_about_tail_call (exp, - "target is not able to optimize the" - " call into a sibling call"); + _("target is not able to optimize the" + " call into a sibling call")); return false; } @@ -2537,18 +2537,18 @@ can_implement_as_sibling_call_p (tree exp, optimized. */ if (flags & ECF_RETURNS_TWICE) { - maybe_complain_about_tail_call (exp, "callee returns twice"); + maybe_complain_about_tail_call (exp, _("callee returns twice")); return false; } if (flags & ECF_NORETURN) { - maybe_complain_about_tail_call (exp, "callee does not return"); + maybe_complain_about_tail_call (exp, _("callee does not return")); return false; } if (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (addr)))) { - maybe_complain_about_tail_call (exp, "volatile function type"); + maybe_complain_about_tail_call (exp, _("volatile function type")); return false; } @@ -2567,7 +2567,7 @@ can_implement_as_sibling_call_p (tree exp, the argument areas are shared. */ if (fndecl && decl_function_context (fndecl) == current_function_decl) { - maybe_complain_about_tail_call (exp, "nested function"); + maybe_complain_about_tail_call (exp, _("nested function")); return false; } @@ -2579,8 +2579,8 @@ can_implement_as_sibling_call_p (tree exp, crtl->args.size - crtl->args.pretend_args_size)) { maybe_complain_about_tail_call (exp, - "callee required more stack slots" - " than the caller"); + _("callee required more stack slots" + " than the caller")); return false; } @@ -2594,15 +2594,15 @@ can_implement_as_sibling_call_p (tree exp, crtl->args.size))) { maybe_complain_about_tail_call (exp, - "inconsistent number of" - " popped arguments"); + _("inconsistent number of" + " popped arguments")); return false; } if (!lang_hooks.decls.ok_for_sibcall (fndecl)) { - maybe_complain_about_tail_call (exp, "frontend does not support" - " sibling call"); + maybe_complain_about_tail_call (exp, _("frontend does not support" + " sibling call")); return false; } @@ -2657,7 +2657,7 @@ expand_call (tree exp, rtx target, int ignore) so this shouldn't really happen unless the the musttail pass gave up walking before finding the call. */ if (!try_tail_call) - maybe_complain_about_tail_call (exp, "other reasons"); + maybe_complain_about_tail_call (exp, _("other reasons")); int pass; /* Register in which non-BLKmode value will be returned, @@ -3031,7 +3031,7 @@ expand_call (tree exp, rtx target, int ignore) there's cleanups, as we know there's code to follow the call. */ if (currently_expanding_call++ != 0) { - maybe_complain_about_tail_call (exp, "inside another call"); + maybe_complain_about_tail_call (exp, _("inside another call")); try_tail_call = 0; } if (!flag_optimize_sibling_calls @@ -3040,7 +3040,7 @@ expand_call (tree exp, rtx target, int ignore) try_tail_call = 0; if (args_size.var) { - maybe_complain_about_tail_call (exp, "variable size arguments"); + maybe_complain_about_tail_call (exp, _("variable size arguments")); try_tail_call = 0; } if (dbg_cnt (tail_call) == false) @@ -3065,7 +3065,7 @@ expand_call (tree exp, rtx target, int ignore) { try_tail_call = 0; maybe_complain_about_tail_call (exp, - "hidden string length argument passed on stack"); + _("hidden string length argument passed on stack")); break; } } @@ -3113,9 +3113,9 @@ expand_call (tree exp, rtx target, int ignore) { try_tail_call = 0; maybe_complain_about_tail_call (exp, - "caller and callee disagree in" - " promotion of function" - " return value"); + _("caller and callee disagree in" + " promotion of function" + " return value")); } } @@ -4025,7 +4025,7 @@ expand_call (tree exp, rtx target, int ignore) if (try_tail_call) /* Ideally we'd emit a message for all of the ways that it could have failed. */ - maybe_complain_about_tail_call (exp, "tail call production failed"); + maybe_complain_about_tail_call (exp, _("tail call production failed")); } currently_expanding_call--;