From patchwork Wed Aug 2 09:55:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Turko X-Patchwork-Id: 129737 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp341171vqx; Wed, 2 Aug 2023 03:02:46 -0700 (PDT) X-Google-Smtp-Source: APBJJlGa7k28eKT3JneDbZY8vngm5b7Rk6Sa4Z9SLfvAySu7Q31FwneEtsXamADqUXSclbStMVvf X-Received: by 2002:aa7:cfc8:0:b0:522:4964:d590 with SMTP id r8-20020aa7cfc8000000b005224964d590mr4664366edy.10.1690970566442; Wed, 02 Aug 2023 03:02:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690970566; cv=none; d=google.com; s=arc-20160816; b=CcgUyoCAzXEHOHGQRguAn1l1KECf7DjRjlr+iMQIRS/4ZUFcLykB15NgcjS6tbOy3M TjAjqcRiERqxqU6eCr+F9A0v6acT+bmT8UB1dl3yAx40vCmfxQUd0oIderF4lqwgr7aX GxchRfAV4w9azB69SS+j1NeOwHOG/1olYVfqdjE/7A4nC/96ybWpr2JXznXFTqo6i2rZ N9yVfxtPt8t31gx6putO8sYYHNFnJhMBSCKABc/jH8qg4EcY7lzCz3oB0FAzETHS/AFK qYnaH86Jn6iyG5zV0OHDUQUf/iliSjZuu/YmbCrD0eiklmFSU6Z1Pa4ychnERIto2oEB v/Wg== 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=vEq4cOVlcHCjNnuOwHmzh0OpMlkM1f/a8C7IkJ4Gx2M=; fh=k/nQU4IX+jAQueq710KA8dCAcoPPe4cl6LpGj9WeH7w=; b=uk4OgB09Tr6zyOmJz93khI2gCMWeln4LWadbNyDCNu8qSQQIXhVKnVC4opea2ZhbeS VcNWmjcNMSDNmhAQkGS8B1goHE6tA4ke1qdsnkNgXj3baBTbGLvN2uq5LUQQlweaS0ku jhE7+LTFkqjlsILujJQKRQ65CF8j37cwWjx5R2MY9n6puk5GCjPS+pVa4yP71psjbNYh nnbr22zSxnhieysE8vDzir3qVsdFuRkkeA8b2riXlsR9eEjvrOcWFr7yNIeRZr1czri6 fBPj6QqWp3uvC3XrqDi0mjj8xO3m/uhQTZYkvKObKo/htepPylzSM+PQi2gPbMwQCy1s hTIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=D3omZkf6; 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 d16-20020a05640208d000b0052227d6e699si10389577edz.686.2023.08.02.03.02.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Aug 2023 03:02:46 -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=D3omZkf6; 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 6D122385DC26 for ; Wed, 2 Aug 2023 10:01:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6D122385DC26 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1690970495; bh=vEq4cOVlcHCjNnuOwHmzh0OpMlkM1f/a8C7IkJ4Gx2M=; 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=D3omZkf6R7iKiiVx9rDnToR9t/8UU7iAbIh28w2IvDoF5GG2zqkTVrbbRqn8xWIgx Ulmzp9lqkf9Kr09XstzVnBQMtbumd+NlNtt8WnU5PEIWOzh8t9uUYHZsl6ELgkjDIQ lYyg9BMFJad2v3FtOftCX56lpr2rsqJzlnzx/T4U= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by sourceware.org (Postfix) with ESMTPS id DDAF23858CDA for ; Wed, 2 Aug 2023 10:00:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DDAF23858CDA Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-317b31203c7so992651f8f.2 for ; Wed, 02 Aug 2023 03:00:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690970447; x=1691575247; 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=vEq4cOVlcHCjNnuOwHmzh0OpMlkM1f/a8C7IkJ4Gx2M=; b=Dg2v7/eh4/uEost4QyhsXY0wK6mfqvwHVHzKFYbgX9PM6LaAefpBHEWMjU3EA3DJgl +f3fuXxvrd/St7S5RHYWSFlxOvHX7R21tM8SnIcIrKxZKhA2l/kWGbb9oqsjiNdx4jlK 5XXrUaBUgD+VoUWgWQOxgeya87JF9t+F5mPudOmKWVkptTVgPtRQYAvpheHlzoZam7yk +gV9y8h+9oNhD6kEbt//qwafnBbTas+EmGydSCqiQ9JL0TCE3pvvH7znfrav9MI0ROhz WuQQ9OtsGv6Qnr+WRk5SrSfCLbG58/tA/2HpPsfwK2ixoNaGqA/ebmAc05b3g2dJp1Rf bhrQ== X-Gm-Message-State: ABy/qLY0lcilMPcwN7704Q0GWqwWkF7AzXTGtXgt3PXxzjQ0+ha/cixy 18rO/Jbh/300cKcuPg6yF0cUQGkv5uINnfgR X-Received: by 2002:a5d:50d0:0:b0:314:3c84:4da2 with SMTP id f16-20020a5d50d0000000b003143c844da2mr4634961wrt.13.1690970447174; Wed, 02 Aug 2023 03:00:47 -0700 (PDT) Received: from amwld-aturko1.us.drwholdings.com ([149.14.21.6]) by smtp.gmail.com with ESMTPSA id s1-20020a5d4ec1000000b003063db8f45bsm18544560wrv.23.2023.08.02.03.00.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Aug 2023 03:00:46 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Andrzej Turko Subject: [PATCH 3/3 v2] genmatch: Log line numbers indirectly Date: Wed, 2 Aug 2023 11:55:27 +0200 Message-Id: <20230802095527.100830-4-andrzej.turko@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230802095527.100830-1-andrzej.turko@gmail.com> References: <20230802095527.100830-1-andrzej.turko@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.0 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, 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: 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: 1773111152503997129 X-GMAIL-MSGID: 1773111152503997129 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 | 88 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 73 insertions(+), 15 deletions(-) diff --git a/gcc/genmatch.cc b/gcc/genmatch.cc index 1deca505603..be6c11c347f 100644 --- a/gcc/genmatch.cc +++ b/gcc/genmatch.cc @@ -217,9 +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_dbg_line_numbers (bool gimple, FILE *f) +{ + + if (dbg_line_numbers.is_empty ()) + { + fprintf (f, "};\n\n"); + 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 (int i = 0; i < (int)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: __dbg_line_numbers[%%d], %%s:%%d\\n\",\n"); + fprintf_indent (f, 10, "simplify ? \"Applying pattern\" : " + "\"Matching expression\", file1, 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) { const line_map_ordinary *map; linemap_resolve_location (line_table, location, LRK_SPELLING_LOCATION, &map); @@ -239,7 +286,15 @@ output_line_directive (FILE *f, location_t location, ++file; if (fnargs) - fprintf (f, "\"%s\", %d", file, loc.line); + { + if (indirect_line_numbers) + { + fprintf (f, "\"%s\", %d", file, dbg_line_numbers.length ()); + dbg_line_numbers.safe_push (loc.line); + } + else + fprintf (f, "\"%s\", %d", file, loc.line); + } else fprintf (f, "%s:%d", file, loc.line); } @@ -3375,20 +3430,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 +3578,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 +3669,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 +3724,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 +3792,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 +5501,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 +5515,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 +5558,8 @@ main (int argc, char **argv) dt.gen (parts, gimple); + define_dbg_line_numbers (gimple, choose_output (parts)); + for (FILE *f : parts) { fprintf (f, "#pragma GCC diagnostic pop\n");