From patchwork Mon Aug 7 09:59:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Turko X-Patchwork-Id: 131779 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp1342252vqr; Mon, 7 Aug 2023 03:06:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFRVF0X1kCag7uod2UmilwkkDjVbvKeQbFGKOBADj5OYxc+R+haKoC6OuAzzyLZIjq1VMeU X-Received: by 2002:a17:906:104e:b0:99b:f50b:d7d5 with SMTP id j14-20020a170906104e00b0099bf50bd7d5mr8642586ejj.44.1691402762035; Mon, 07 Aug 2023 03:06:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691402762; cv=none; d=google.com; s=arc-20160816; b=P+rjM7rxfMC6Y4+j8Imqap7LA/wX54UhkAwHnl7jqlI7+x5wIMjdGpejh0tKidHwNA NpSrRhv2Ap5FGFzpl7Ah+2ZJvBWtqHtF3kqliqJORdu70LWMe0CS9xWAGhhpg47GCOMD EwLq+REE4EDHYyDsxG1SCtQUE1Go1y57QUKCFv4e969RPyi5Er+c9TjJAj22hfUjNQlF EI8YG/1YvhcmrkM7CocGzMFaTdy7oZApPr5ryExWE15HkRthNx32ToyNGAE8CleXihDN FhZ54ar0Oa4mj7dNNbMARAj6JU+IAXXLKvyeLMCPwJEuzTU5eAtTvIrBNlLDoJmtihHG sVCQ== 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:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=H7LJPb9v10UvTF/fKVJElHK2/J+vCc9iXs5aEhS1cd8=; fh=Yo2ByyRkNEaDu9X7hI9WCxKxqBIoNDutgIrFEk/DvWs=; b=SdM33tDGqZEmGnSzM0Zh6x3gADPSwJTF/RxAIWVtLwU+DyXF8fvVbDLHoFHNyH7G7d fqd3yo50Ydl9WdS4vrnBdPnYKBHsTt8TSMlY0TR1aYLg1TWC3UcFRro21Yg00YbHwOA0 pBVCx3FuVsTl7iOSRauXgTnxZIcfs++hTC0IBhqAlK2vE1fVlPgfmyzNdplmWKWmfEL1 eXnCpmb8B/h8302z+qe+E3tjZdNDyQY6IihiHtOSMtNGzvzkFf7Z6BM/HWB6AUqtZzgv mMnj9IGD//voKeRgXJoHdHv6omYW96RgejC33zaOnu5ILFDhhqP7TRNCkrEVf/KLkPrT +gMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=eE09K2HL; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id bi1-20020a170906a24100b0099bd7b2663dsi4582331ejb.142.2023.08.07.03.06.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 03:06:02 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=eE09K2HL; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 A4E943857016 for ; Mon, 7 Aug 2023 10:05:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A4E943857016 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1691402721; bh=H7LJPb9v10UvTF/fKVJElHK2/J+vCc9iXs5aEhS1cd8=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=eE09K2HL9LYpaII/dHyQtNhnZTsmNI0qFh1Ejt7M8qlFb8wkCmeYX5QliUEuJvPpU xLIOjNymkMKCdNImCS0GjT6MnRYPO5gDMYAohdPzM2jUXiHLeeLfycl48sKyGvQ/6R hS3uphSTNhMdHeo4tRSyyukfj5LhHS6EOb02Hzuo= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by sourceware.org (Postfix) with ESMTPS id 911173858417 for ; Mon, 7 Aug 2023 10:04:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 911173858417 Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-99bcf2de59cso634910866b.0 for ; Mon, 07 Aug 2023 03:04:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691402645; x=1692007445; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=H7LJPb9v10UvTF/fKVJElHK2/J+vCc9iXs5aEhS1cd8=; b=fZ6ry8gx3/IY3/9IChAXsDKgzck0Tt+UGSVGdYQdkU7Yc0fHnWQ68yNnkVb18LXymx yF0yDbkHCzDvLzNqw5yy+pS+z8X1PLWAtI39uYTh6hE0yxZ6aQ66oYYl4b3evi4bQvh6 elSqjFmowgGSIQ56jRIRCW4c7z0+QrGqrY55+fbyPU3sqG+QpuyaiSc7KvV9kTMKIAY4 tZ326FO8yGfe2zzH58O7EB7HUKhedHeaFxaYNzldQkSy/7jcZPtHPPkOBduasoJ4UcEu w2VC74zbks/n/fBGOUc3x1v2brDU3CkpDOFzr1DDViTqvUTzBEoEilfQSPSGjyT0ejeZ DKlA== X-Gm-Message-State: AOJu0YyfM6supe1mAACijwp3RDmW+zpXq2lrfQ+/WjlvO7qCFV68lKPU SZx4o1GnwEE0uB1DCO5bMfGHZUdsidVl+1hmDZU= X-Received: by 2002:a17:907:7857:b0:99c:7551:933e with SMTP id lb23-20020a170907785700b0099c7551933emr7883284ejc.64.1691402644681; Mon, 07 Aug 2023 03:04:04 -0700 (PDT) Received: from amwld-aturko1.us.drwholdings.com ([149.14.21.6]) by smtp.gmail.com with ESMTPSA id la4-20020a170906ad8400b0099bd682f317sm4881305ejb.206.2023.08.07.03.04.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 03:04:04 -0700 (PDT) To: gcc-patches@gcc.gnu.org, Richard Biener Cc: Andrzej Turko Subject: [PATCH 3/3 v4] genmatch: Log line numbers indirectly Date: Mon, 7 Aug 2023 11:59:01 +0200 Message-Id: <20230807095901.267099-4-andrzej.turko@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230807095901.267099-1-andrzej.turko@gmail.com> References: <20230807095901.267099-1-andrzej.turko@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrzej Turko via Gcc-patches From: Andrzej Turko Reply-To: Andrzej Turko Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773564342764991806 X-GMAIL-MSGID: 1773564342764991806 Currently fprintf calls logging to a dump file take line numbers in the match.pd file directly as arguments. When match.pd is edited, referenced code changes line numbers, which causes changes to many fprintf calls and, thus, to many (usually all) .cc files generated by genmatch. This forces make to (unnecessarily) rebuild many .o files. This change replaces those logging fprintf calls with calls to a dedicated logging function. Because it reads the line numbers from the lookup table, it is enough to pass a corresponding index. Thanks to this, when match.pd changes, it is enough to rebuild the file containing the lookup table and, of course, those actually affected by the change. Signed-off-by: Andrzej Turko gcc/ChangeLog: * genmatch.cc: Log line numbers indirectly. --- gcc/genmatch.cc | 95 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 80 insertions(+), 15 deletions(-) diff --git a/gcc/genmatch.cc b/gcc/genmatch.cc index 1deca505603..f46d2e1520d 100644 --- a/gcc/genmatch.cc +++ b/gcc/genmatch.cc @@ -217,10 +217,56 @@ fp_decl_done (FILE *f, const char *trailer) fprintf (header_file, "%s;", trailer); } +/* Line numbers for use by indirect line directives. */ +static vec dbg_line_numbers; + +static void +write_header_declarations (bool gimple, FILE *f) +{ + fprintf (f, "\nextern void\n%s_dump_logs (const char *file1, int line1_id, " + "const char *file2, int line2, bool simplify);\n", + gimple ? "gimple" : "generic"); +} + +static void +define_dump_logs (bool gimple, FILE *f) +{ + if (dbg_line_numbers.is_empty ()) + return; + + fprintf (f , "void\n%s_dump_logs (const char *file1, int line1_id, " + "const char *file2, int line2, bool simplify)\n{\n", + gimple ? "gimple" : "generic"); + + fprintf_indent (f, 2, "static int dbg_line_numbers[%d] = {", + dbg_line_numbers.length ()); + + for (unsigned i = 0; i < dbg_line_numbers.length () - 1; i++) + { + if (i % 20 == 0) + fprintf (f, "\n\t"); + + fprintf (f, "%d, ", dbg_line_numbers[i]); + } + fprintf (f, "%d\n };\n\n", dbg_line_numbers.last ()); + + + fprintf_indent (f, 2, "fprintf (dump_file, \"%%s " + "%%s:%%d, %%s:%%d\\n\",\n"); + fprintf_indent (f, 10, "simplify ? \"Applying pattern\" : " + "\"Matching expression\", file1, " + "dbg_line_numbers[line1_id], file2, line2);"); + + fprintf (f, "\n}\n\n"); +} + static void output_line_directive (FILE *f, location_t location, - bool dumpfile = false, bool fnargs = false) + bool dumpfile = false, bool fnargs = false, + bool indirect_line_numbers = false) { + typedef pair_hash> location_hash; + static hash_map loc_id_map; const line_map_ordinary *map; linemap_resolve_location (line_table, location, LRK_SPELLING_LOCATION, &map); expanded_location loc = linemap_expand_location (line_table, map, location); @@ -239,7 +285,23 @@ output_line_directive (FILE *f, location_t location, ++file; if (fnargs) - fprintf (f, "\"%s\", %d", file, loc.line); + { + if (indirect_line_numbers) + { + bool existed; + int &loc_id = loc_id_map.get_or_insert ( + std::make_pair (file, loc.line), &existed); + if (!existed) + { + loc_id = dbg_line_numbers.length (); + dbg_line_numbers.safe_push (loc.line); + } + + fprintf (f, "\"%s\", %d", file, loc_id); + } + else + fprintf (f, "\"%s\", %d", file, loc.line); + } else fprintf (f, "%s:%d", file, loc.line); } @@ -3375,20 +3437,19 @@ 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 +/* Emit a logging call 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) +emit_logging_call (FILE *f, int indent, class simplify *s, operand *result, + bool gimple) { 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\", "); + "%s_dump_logs (", gimple ? "gimple" : "generic"); output_line_directive (f, - result ? result->location : s->match->location, true, - true); - fprintf (f, ", __FILE__, __LINE__);\n"); + result ? result->location : s->match->location, + true, true, true); + fprintf (f, ", __FILE__, __LINE__, %s);\n", + s->kind == simplify::SIMPLIFY ? "true" : "false"); } /* Generate code for the '(if ...)', '(with ..)' and actual transform @@ -3524,7 +3585,7 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result) if (!result) { /* If there is no result then this is a predicate implementation. */ - emit_debug_printf (f, indent, s, result); + emit_logging_call (f, indent, s, result, gimple); fprintf_indent (f, indent, "return true;\n"); } else if (gimple) @@ -3615,7 +3676,7 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result) } else gcc_unreachable (); - emit_debug_printf (f, indent, s, result); + emit_logging_call (f, indent, s, result, gimple); fprintf_indent (f, indent, "return true;\n"); } else /* GENERIC */ @@ -3670,7 +3731,7 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result) } if (is_predicate) { - emit_debug_printf (f, indent, s, result); + emit_logging_call (f, indent, s, result, gimple); fprintf_indent (f, indent, "return true;\n"); } else @@ -3738,7 +3799,7 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result) i); } } - emit_debug_printf (f, indent, s, result); + emit_logging_call (f, indent, s, result, gimple); fprintf_indent (f, indent, "return _r;\n"); } } @@ -5447,6 +5508,7 @@ main (int argc, char **argv) parts.quick_push (stdout); write_header (stdout, s_include_file); write_header_includes (gimple, stdout); + write_header_declarations (gimple, stdout); } else { @@ -5460,6 +5522,7 @@ main (int argc, char **argv) fprintf (header_file, "#ifndef GCC_GIMPLE_MATCH_AUTO_H\n" "#define GCC_GIMPLE_MATCH_AUTO_H\n"); write_header_includes (gimple, header_file); + write_header_declarations (gimple, header_file); } /* Go over all predicates defined with patterns and perform @@ -5502,6 +5565,8 @@ main (int argc, char **argv) dt.gen (parts, gimple); + define_dump_logs (gimple, choose_output (parts)); + for (FILE *f : parts) { fprintf (f, "#pragma GCC diagnostic pop\n");