From patchwork Fri May 26 02:58:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 70110 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 401B33857714 for ; Fri, 26 May 2023 02:59:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 401B33857714 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685069962; bh=y901bITyAEAcknC8yAm+PpnzpoC6fLr8Ic6p20S/kGg=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=qQopuGqz8ST0M/nOeDrPsUY8e7+adi90rTOp2479zqAH4MlWTc+65uGJvyE9YyYqV V/bUAnxp27Gw2nIBSeJkBb4LfQaNOk7cVlyMHDFuWC/zyqJCFClJops0fYUDigmeEe 7WjTnKI6J52EvqRgB8T9yEsBpeMdGaFnP3C+nA8w= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by sourceware.org (Postfix) with ESMTPS id 512793858D39 for ; Fri, 26 May 2023 02:58:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 512793858D39 Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34Q1UfVr006513 for ; Thu, 25 May 2023 19:58:49 -0700 Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3qsspt5a0f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Thu, 25 May 2023 19:58:49 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Thu, 25 May 2023 19:58:47 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Thu, 25 May 2023 19:58:47 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 4DCA43F703F; Thu, 25 May 2023 19:58:47 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH] genmatch: Emit debug message right before "return x" instead of earlier Date: Thu, 25 May 2023 19:58:38 -0700 Message-ID: <20230526025838.2259892-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Proofpoint-GUID: XrmG5Flf8GLU639A37aw8RkE8xJrxDrq X-Proofpoint-ORIG-GUID: XrmG5Flf8GLU639A37aw8RkE8xJrxDrq X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-05-25_14,2023-05-25_03,2023-05-22_02 X-Spam-Status: No, score=-14.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Pinski via Gcc-patches From: Andrew Pinski Reply-To: Andrew Pinski Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" This is based on the review of https://gcc.gnu.org/pipermail/gcc-patches/2023-May/619342.html . Instead of emitting debug message even if we don't apply a pattern, this fixes the issue by only emitting it if it the pattern finally succeeded. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/ChangeLog: * genmatch.cc (emit_debug_printf): New function. (dt_simplify::gen_1): Emit printf into the code before the `return true` or returning the folded result instead of emitting it always. --- gcc/genmatch.cc | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/gcc/genmatch.cc b/gcc/genmatch.cc index 177c13d87cb..bd6ce3a28f8 100644 --- a/gcc/genmatch.cc +++ b/gcc/genmatch.cc @@ -3359,6 +3359,21 @@ dt_operand::gen (FILE *f, int indent, bool gimple, int depth) } } +/* Emit a fprintf to the debug file to the file F, with the INDENT from + either the RESULT location or the S's match location if RESULT is null. */ +static void +emit_debug_printf (FILE *f, int indent, class simplify *s, operand *result) +{ + fprintf_indent (f, indent, "if (UNLIKELY (debug_dump)) " + "fprintf (dump_file, \"%s ", + s->kind == simplify::SIMPLIFY + ? "Applying pattern" : "Matching expression"); + fprintf (f, "%%s:%%d, %%s:%%d\\n\", "); + output_line_directive (f, + result ? result->location : s->match->location, true, + true); + fprintf (f, ", __FILE__, __LINE__);\n"); +} /* Generate code for the '(if ...)', '(with ..)' and actual transform step of a '(simplify ...)' or '(match ...)'. This handles everything @@ -3488,21 +3503,12 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result) needs_label = true; } - fprintf_indent (f, indent, "if (UNLIKELY (debug_dump)) " - "fprintf (dump_file, \"%s ", - s->kind == simplify::SIMPLIFY - ? "Applying pattern" : "Matching expression"); - fprintf (f, "%%s:%%d, %%s:%%d\\n\", "); - output_line_directive (f, - result ? result->location : s->match->location, true, - true); - fprintf (f, ", __FILE__, __LINE__);\n"); - fprintf_indent (f, indent, "{\n"); indent += 2; if (!result) { /* If there is no result then this is a predicate implementation. */ + emit_debug_printf (f, indent, s, result); fprintf_indent (f, indent, "return true;\n"); } else if (gimple) @@ -3593,6 +3599,7 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result) } else gcc_unreachable (); + emit_debug_printf (f, indent, s, result); fprintf_indent (f, indent, "return true;\n"); } else /* GENERIC */ @@ -3646,7 +3653,10 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result) &cinfo, indexes); } if (is_predicate) - fprintf_indent (f, indent, "return true;\n"); + { + emit_debug_printf (f, indent, s, result); + fprintf_indent (f, indent, "return true;\n"); + } else { fprintf_indent (f, indent, "tree _r;\n"); @@ -3712,6 +3722,7 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result) i); } } + emit_debug_printf (f, indent, s, result); fprintf_indent (f, indent, "return _r;\n"); } }