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: 99265 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp190857vqr; Thu, 25 May 2023 19:59:39 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7HxdRLmY+eDdUSpFsYwb265odWAVhFfCBscemVADULMZlCCh9HYMS2IXTJy4mQ4QPybQ0b X-Received: by 2002:a17:907:25c6:b0:96a:5e38:ba49 with SMTP id ae6-20020a17090725c600b0096a5e38ba49mr781625ejc.2.1685069979295; Thu, 25 May 2023 19:59:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685069979; cv=none; d=google.com; s=arc-20160816; b=yXS4q9cVMtJfO2Cqbz4q//LHyNs71LAFajvdld1F7ufvBV7WaS7OQXNJ1VunmuJUOs PtVXT+Xt9G0ksIFC2o2ZJ9fHdMxy22Wg+0gSwJBRJUNV30ioSy0X2f8W1dp7bKkJIzfZ jCNHaNwQMrEJej2AsOGWkfK6dJ00DGst4SG1rInHBvWCMjcdtYRl8VwzvN6ujZorNcrh qgutz01Uudmb+T6HwktVsNcaMWMXlbLHPP+y+55qd7jxEyh0Ujy74wsYQRayHMc2pIIL hZ5j7PbKY+zKP/8azQ62hGqrP3Pv2fw1jltx/kJccaRWw4XMgKmtzgucQ4pBggc3zW2v XbTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=y901bITyAEAcknC8yAm+PpnzpoC6fLr8Ic6p20S/kGg=; b=BVLaEIBwvxUOSxlZO+Ffih/EVaH/VAPxPf/T5QKWrZxnTjUz277rQIyhMv7t3681lk uFqAQHami6ITE0BNZTW9fR71GXIb5a39Je+A7N8Qe1M40OO/FLkkqkku1tK6wBDcRemi 07yb9gtP3KUJkqpWn29HqjK+5/EbIKNLHNlBAm40LMgCX3gkpL7O1dW17wiFN+hLx9XK qdNtREXILLT6GDr4I2GB8eSudQ8mlPbQ73BQ8P8RpHOItJUGzRcDuCt5wpmoKAufeLZE MNPjmeE+/zH0MaZpRDuSeJDwd/s45RJpg3czbN7891uL2FXloD48gPruFQRyZ1aJQyFz ZOpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="BBPY/AbP"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id q24-20020a170906a09800b0094f1de9030dsi1440445ejy.897.2023.05.25.19.59.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 May 2023 19:59:39 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="BBPY/AbP"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 403493858C2F for ; Fri, 26 May 2023 02:59:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 403493858C2F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685069978; 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=BBPY/AbPdw+cOo19ChnXgPPkIrAfU66R9YOxxbNrRNEPOU6kCwCoDZGTpaL7niC7g 7+lTS0tHDgWYFvQ55LzmQJ8Bev5DHAzyMmvXfJotJXPOuf+RnHfTQpMfXogL00TzTb sNK5U/Y9PW/aDiIrnBE6vsVkhevBh2WNzjQcSZaY= 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766923938454074783?= X-GMAIL-MSGID: =?utf-8?q?1766923938454074783?= 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"); } }