From patchwork Tue May 23 23:16:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 98199 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2475827vqo; Tue, 23 May 2023 16:17:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5gRcWgF56X357BvLc/1PpyHonPaQ/SvIdxvSrncaRr5WCwkjCfMiSOycve4XClE+kMjdct X-Received: by 2002:a17:906:9c82:b0:96a:a0fd:d43e with SMTP id fj2-20020a1709069c8200b0096aa0fdd43emr14926720ejc.49.1684883825554; Tue, 23 May 2023 16:17:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684883825; cv=none; d=google.com; s=arc-20160816; b=yXRC4Ken6uY3C32DxwAoD+oSIA2dS4jcZI7fn3AySMrQyP41+v/cSRE/Vfwk2679/A UlGf0AQkuadl0CsSZFd1MHlyhzgMLrF5+tOX8frHYS/N35lkTrWaJwyXpyCc1V6Aybdj g8WvMD7WFygerMyiNwM3bZjOa2WOU5Fm5j539PSPO5r5IdRi0fd2eYrCApTrR/XpgB5v M7SoSEXCXXbGNaAxxBM1P5f7SEM2lwIO5Lfv50dJWr1bKchTH1XoET7QcKIqwLB8QxH0 LTgDWMGM98oCWFE5tYp2udq6EG/+iBMT0CX0bSC5R6lNKjc1HPA3lILJ/hq+9LYwNlEM sZKA== 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=7MR8Yi29o5TvfMsdiD5UR5/2+DHkm+5dZEMpIQYGN34=; b=B1xqgePH7AKXLWV9vxNIXABrBDl2Wk/E50pZzGvNFMv/Soyk9q5tvDBy8GHK1OcOLH Ru9V1tq0XmRb71Ui7sZwAicdP160K5dV2p9+C4jneznumqLqzCJE37ZGECA74ruxSRG4 liP5WEC4ADbX5nYNTZnUJA+7oA+S6acggXQ4sh652mF3jvfU2NxMN0apcjMP7MSq/6ae NfzizF/8Sgk6GPkw7eqFeZrFQWDLVvrJDuVbEPSzqkhxqRjlD/GBx+kRRuX+eUY1k34H xBE7/A+tuHK3SvkXwgO/E3w+/exO37t8ZXISj+Ng1RaVgcZDxIpj9KD9rB9hYzL/sa5f vgUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=eRDpyNPw; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id ss18-20020a170907039200b0094f1ca57c41si2521785ejb.388.2023.05.23.16.17.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 May 2023 16:17:05 -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=eRDpyNPw; 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 786693858438 for ; Tue, 23 May 2023 23:17:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 786693858438 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684883824; bh=7MR8Yi29o5TvfMsdiD5UR5/2+DHkm+5dZEMpIQYGN34=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=eRDpyNPwZ0d4w1ThZDy++y11EVAEE73ETsnHuhyxLqSX4TnIu6lgeox+Ly0h0jzuW 3uT2PxzTJukogJkw9U/+o0Hu4CpVBX8AxSBEqKAfQQR4RhAyzeZ777lsCmh0zl+u60 zkIk34kLtC6RadVAEF/kYLi8EcNAINFdTyXlzJdw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by sourceware.org (Postfix) with ESMTPS id 978C83858D35 for ; Tue, 23 May 2023 23:16:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 978C83858D35 Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34NKKxEJ029256 for ; Tue, 23 May 2023 16:16:15 -0700 Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3qrm46n476-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Tue, 23 May 2023 16:16:15 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Tue, 23 May 2023 16:16:13 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Tue, 23 May 2023 16:16:13 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.76.242.112]) by maili.marvell.com (Postfix) with ESMTP id 3DE043F7098; Tue, 23 May 2023 16:16:12 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH] Dump if a pattern fails after having printed applying it Date: Tue, 23 May 2023 16:16:01 -0700 Message-ID: <20230523231601.2130715-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: OcOHt4L-AqwpoDye3bOZoCLbQpiF3GtQ X-Proofpoint-GUID: OcOHt4L-AqwpoDye3bOZoCLbQpiF3GtQ 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-23_15,2023-05-23_02,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, 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?1766728741911745093?= X-GMAIL-MSGID: =?utf-8?q?1766728741911745093?= While trying to understand how to use the ! operand for match patterns, I noticed that the debug dumps would print out applying a pattern but nothing when it was rejected in the end. This was confusing me. This adds that by emitting a dump for the failed case. Note the patch is little more complex as we don't want to print out if debug counter rejected the pattern and then we need to fix up when we mark needing a label or not. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/ChangeLog: * genmatch.cc (needs_label): New variable (expr::gen_transform): Set needs_label if we use the local_label. (dt_simplify::gen_1): Use `_1` for the debug count label. After the local label, emit debug print for the failure. Emit `_1` label if needed. --- gcc/genmatch.cc | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/gcc/genmatch.cc b/gcc/genmatch.cc index 177c13d87cb..2ea80d341a2 100644 --- a/gcc/genmatch.cc +++ b/gcc/genmatch.cc @@ -2433,6 +2433,7 @@ capture_info::walk_c_expr (c_expr *e) /* The current label failing the current matched pattern during code generation. */ static char *fail_label; +static bool needs_label; /* Code generation off the decision tree and the refered AST nodes. */ @@ -2611,6 +2612,7 @@ expr::gen_transform (FILE *f, int indent, const char *dest, bool gimple, fprintf_indent (f, indent, "if (!_r%d) goto %s;\n", depth, fail_label); + needs_label = true; if (*opr == CONVERT_EXPR) { indent -= 4; @@ -2640,11 +2642,13 @@ expr::gen_transform (FILE *f, int indent, const char *dest, bool gimple, { fprintf_indent (f, indent, "if (!_r%d)\n", depth); fprintf_indent (f, indent, " goto %s;\n", fail_label); + needs_label = true; } if (force_leaf) { fprintf_indent (f, indent, "if (EXPR_P (_r%d))\n", depth); fprintf_indent (f, indent, " goto %s;\n", fail_label); + needs_label = true; } if (*opr == CONVERT_EXPR) { @@ -3409,7 +3413,8 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result) char local_fail_label[256]; snprintf (local_fail_label, 256, "next_after_fail%u", ++fail_label_cnt); fail_label = local_fail_label; - bool needs_label = false; + needs_label = false; + bool needs_label_1 = false; /* Analyze captures and perform early-outs on the incoming arguments that cover cases we cannot handle. */ @@ -3484,8 +3489,8 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result) if (s->kind == simplify::SIMPLIFY) { - fprintf_indent (f, indent, "if (UNLIKELY (!dbg_cnt (match))) goto %s;\n", fail_label); - needs_label = true; + fprintf_indent (f, indent, "if (UNLIKELY (!dbg_cnt (match))) goto %s_1;\n", fail_label); + needs_label_1 = true; } fprintf_indent (f, indent, "if (UNLIKELY (debug_dump)) " @@ -3718,7 +3723,22 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result) indent -= 2; fprintf_indent (f, indent, "}\n"); if (needs_label) - fprintf (f, "%s:;\n", fail_label); + { + fprintf (f, "%s:;\n", fail_label); + if (s->kind == simplify::SIMPLIFY) + { + fprintf_indent (f, indent, "if (UNLIKELY (debug_dump)) " + "fprintf (dump_file, \"Pattern failed "); + fprintf (f, "%%s:%%d, %%s:%%d\\n\", "); + output_line_directive (f, + result ? result->location : s->match->location, true, + true); + fprintf (f, ", __FILE__, __LINE__);\n"); + } + } + if (needs_label_1) + fprintf (f, "%s_1:;\n", fail_label); + needs_label = false; fail_label = NULL; }