From patchwork Mon May 8 18:13:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Monakov X-Patchwork-Id: 1778522 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=PmFxuYJ+; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QFTw32Vdbz214S for ; Tue, 9 May 2023 04:14:43 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 519CB385E02A for ; Mon, 8 May 2023 18:14:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 519CB385E02A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683569681; bh=Xbm3j+Lc8oUX4o52PXBAZwUIbQPcAnjMUu3kiIhW4q8=; 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=PmFxuYJ+d580z/2BOWYsjmmgSeIA/6Xrgxeer44UOv4Z/HgTQcGUEXp7THm8HPCOY KVrJTp+IPle1GaLcVN4E7mh6dNbeNHxb4h17yKq089IiJQrvqUOJGdt04oK4rMlp+7 zlCEXdGUchJcPkc/kpkTlR1T3H2QA73E/XQR1Efo= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by sourceware.org (Postfix) with ESMTPS id A31753858D32 for ; Mon, 8 May 2023 18:13:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A31753858D32 Received: from localhost.intra.ispras.ru (unknown [10.10.3.121]) by mail.ispras.ru (Postfix) with ESMTP id 05BC144C1012; Mon, 8 May 2023 18:13:19 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 05BC144C1012 To: gcc-patches@gcc.gnu.org Cc: Alexander Monakov Subject: [PATCH 1/3] genmatch: clean up emit_func Date: Mon, 8 May 2023 21:13:09 +0300 Message-Id: <20230508181311.25961-2-amonakov@ispras.ru> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20230508181311.25961-1-amonakov@ispras.ru> References: <20230508181311.25961-1-amonakov@ispras.ru> MIME-Version: 1.0 X-Spam-Status: No, score=-9.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, 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: Alexander Monakov via Gcc-patches From: Alexander Monakov Reply-To: Alexander Monakov Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Eliminate boolean parameters of emit_func. The first ('open') just prints 'extern' to generated header, which is unnecessary. Introduce a separate function to use when finishing a declaration in place of the second ('close'). Rename emit_func to 'fp_decl' (matching 'fprintf' in length) to unbreak indentation in several places. Reshuffle emitted line breaks in a few places to make generated declarations less ugly. gcc/ChangeLog: * genmatch.cc (header_file): Make static. (emit_func): Rename to... (fp_decl): ... this. Adjust all uses. (fp_decl_done): New function. Use it... (decision_tree::gen): ... here and... (write_predicate): ... here. (main): Adjust. --- gcc/genmatch.cc | 97 ++++++++++++++++++++++++++----------------------- 1 file changed, 52 insertions(+), 45 deletions(-) diff --git a/gcc/genmatch.cc b/gcc/genmatch.cc index c593814871..d5e56e2d68 100644 --- a/gcc/genmatch.cc +++ b/gcc/genmatch.cc @@ -183,31 +183,37 @@ fprintf_indent (FILE *f, unsigned int indent, const char *format, ...) va_end (ap); } -/* Like fprintf, but print to two files, one header one C implementation. */ -FILE *header_file = NULL; +/* Secondary stream for fp_decl. */ +static FILE *header_file; +/* Start or continue emitting a declaration in fprintf-like manner, + printing both to F and global header_file, if non-null. */ static void #if GCC_VERSION >= 4001 -__attribute__((format (printf, 4, 5))) +__attribute__((format (printf, 2, 3))) #endif -emit_func (FILE *f, bool open, bool close, const char *format, ...) +fp_decl (FILE *f, const char *format, ...) { - va_list ap1, ap2; - if (header_file != NULL) - { - if (open) - fprintf (header_file, "extern "); - va_start (ap2, format); - vfprintf (header_file, format, ap2); - va_end (ap2); - if (close) - fprintf (header_file, ";\n"); - } + va_list ap; + va_start (ap, format); + vfprintf (f, format, ap); + va_end (ap); - va_start (ap1, format); - vfprintf (f, format, ap1); - va_end (ap1); - fputc ('\n', f); + if (!header_file) + return; + + va_start (ap, format); + vfprintf (header_file, format, ap); + va_end (ap); +} + +/* Finish a declaration being emitted by fp_decl. */ +static void +fp_decl_done (FILE *f, const char *trailer) +{ + fprintf (f, "%s\n", trailer); + if (header_file) + fprintf (header_file, "%s;", trailer); } static void @@ -3924,35 +3930,35 @@ decision_tree::gen (vec &files, bool gimple) s->fname = xasprintf ("%s_simplify_%u", gimple ? "gimple" : "generic", fcnt++); if (gimple) - emit_func (f, true, false, "\nbool\n" + fp_decl (f, "\nbool\n" "%s (gimple_match_op *res_op, gimple_seq *seq,\n" " tree (*valueize)(tree) ATTRIBUTE_UNUSED,\n" " const tree ARG_UNUSED (type), tree *ARG_UNUSED " - "(captures)\n", + "(captures)", s->fname); else { - emit_func (f, true, false, "\ntree\n" + fp_decl (f, "\ntree\n" "%s (location_t ARG_UNUSED (loc), const tree ARG_UNUSED (type),\n", (*iter).second->fname); for (unsigned i = 0; i < as_a (s->s->s->match)->ops.length (); ++i) - emit_func (f, false, false, " tree ARG_UNUSED (_p%d),", i); - emit_func (f, false, false, " tree *captures\n"); + fp_decl (f, " tree ARG_UNUSED (_p%d),", i); + fp_decl (f, " tree *captures"); } for (unsigned i = 0; i < s->s->s->for_subst_vec.length (); ++i) { if (! s->s->s->for_subst_vec[i].first->used) continue; if (is_a (s->s->s->for_subst_vec[i].second)) - emit_func (f, false, false, ", const enum tree_code ARG_UNUSED (%s)", + fp_decl (f, ",\n const enum tree_code ARG_UNUSED (%s)", s->s->s->for_subst_vec[i].first->id); else if (is_a (s->s->s->for_subst_vec[i].second)) - emit_func (f, false, false, ", const combined_fn ARG_UNUSED (%s)", + fp_decl (f, ",\n const combined_fn ARG_UNUSED (%s)", s->s->s->for_subst_vec[i].first->id); } - emit_func (f, false, true, ")"); + fp_decl_done (f, ")"); fprintf (f, "{\n"); fprintf_indent (f, 2, "const bool debug_dump = " "dump_file && (dump_flags & TDF_FOLDING);\n"); @@ -3988,22 +3994,22 @@ decision_tree::gen (vec &files, bool gimple) FILE *f = get_out_file (files); if (gimple) - emit_func (f, true, false,"\nbool\n" + fp_decl (f, "\nbool\n" "gimple_simplify_%s (gimple_match_op *res_op," " gimple_seq *seq,\n" " tree (*valueize)(tree) " "ATTRIBUTE_UNUSED,\n" " code_helper ARG_UNUSED (code), tree " - "ARG_UNUSED (type)\n", + "ARG_UNUSED (type)", e->operation->id); else - emit_func (f, true, false, "\ntree\n" + fp_decl (f, "\ntree\n" "generic_simplify_%s (location_t ARG_UNUSED (loc), enum " "tree_code ARG_UNUSED (code), const tree ARG_UNUSED (type)", e->operation->id); for (unsigned i = 0; i < n; ++i) - emit_func (f, false, false,", tree _p%d", i); - emit_func (f, false, true, ")"); + fp_decl (f, ", tree _p%d", i); + fp_decl_done (f, ")"); fprintf (f, "{\n"); fprintf_indent (f, 2, "const bool debug_dump = " "dump_file && (dump_flags & TDF_FOLDING);\n"); @@ -4025,17 +4031,17 @@ decision_tree::gen (vec &files, bool gimple) FILE *f = get_out_file (files); if (gimple) - emit_func (f, true, false, "\nbool\n" + fp_decl (f, "\nbool\n" "gimple_simplify (gimple_match_op*, gimple_seq*,\n" " tree (*)(tree), code_helper,\n" " const tree"); else - emit_func (f, true, false,"\ntree\n" + fp_decl (f, "\ntree\n" "generic_simplify (location_t, enum tree_code,\n" " const tree"); for (unsigned i = 0; i < n; ++i) - emit_func (f, false, false, ", tree"); - emit_func (f, false, true, ")"); + fp_decl (f, ", tree"); + fp_decl_done (f, ")"); fprintf (f, "{\n"); if (gimple) fprintf (f, " return false;\n"); @@ -4052,17 +4058,17 @@ decision_tree::gen (vec &files, bool gimple) /* Then generate the main entry with the outermost switch and tail-calls to the split-out functions. */ if (gimple) - emit_func (f, true, false, "\nbool\n" + fp_decl (f, "\nbool\n" "gimple_simplify (gimple_match_op *res_op, gimple_seq *seq,\n" " tree (*valueize)(tree) ATTRIBUTE_UNUSED,\n" " code_helper code, const tree type"); else - emit_func (f, true, false, "\ntree\n" + fp_decl (f, "\ntree\n" "generic_simplify (location_t loc, enum tree_code code, " "const tree type ATTRIBUTE_UNUSED"); for (unsigned i = 0; i < n; ++i) - emit_func (f, false, false, ", tree _p%d", i); - emit_func (f, false, true, ")"); + fp_decl (f, ", tree _p%d", i); + fp_decl_done (f, ")"); fprintf (f, "{\n"); if (gimple) @@ -4117,10 +4123,11 @@ decision_tree::gen (vec &files, bool gimple) void write_predicate (FILE *f, predicate_id *p, decision_tree &dt, bool gimple) { - emit_func (f, true, true, "\nbool\n%s%s (tree t%s%s)", - gimple ? "gimple_" : "tree_", p->id, - p->nargs > 0 ? ", tree *res_ops" : "", - gimple ? ", tree (*valueize)(tree) ATTRIBUTE_UNUSED" : ""); + fp_decl (f, "\nbool\n%s%s (tree t%s%s)", + gimple ? "gimple_" : "tree_", p->id, + p->nargs > 0 ? ", tree *res_ops" : "", + gimple ? ", tree (*valueize)(tree) ATTRIBUTE_UNUSED" : ""); + fp_decl_done (f, ""); fprintf (f, "{\n"); /* Conveniently make 'type' available. */ fprintf_indent (f, 2, "const tree type = TREE_TYPE (t);\n"); @@ -5484,7 +5491,7 @@ main (int argc, char **argv) if (header_file) { - fprintf (header_file, "#endif /* GCC_GIMPLE_MATCH_AUTO_H. */\n"); + fprintf (header_file, "\n#endif /* GCC_GIMPLE_MATCH_AUTO_H. */\n"); fclose (header_file); } From patchwork Mon May 8 18:13:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Monakov X-Patchwork-Id: 1778521 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=AUSsPfoJ; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QFTv22Ynqz214X for ; Tue, 9 May 2023 04:13:50 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 16E9738555BD for ; Mon, 8 May 2023 18:13:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 16E9738555BD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683569628; bh=sXu4vDlY5p6Y+pInEQVP1msog0eEzqoG2Vs9eFvlbdE=; 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=AUSsPfoJeftTKVVrhmHW27Yge9FxTzZPDlAyYjICO/jH4m0XyIibp4DBN6kMYEP4R yUr5NkfvP1/IPrY8s91xpxzfZYNbhKsUGHw6cauW9svsL0J6ZsHP55guiumyKmzZSk V6HS6xxLi1fJ/GlszwlG9L/NIMlA1VxGx4N3bM8s= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by sourceware.org (Postfix) with ESMTPS id ABB8E3858D3C for ; Mon, 8 May 2023 18:13:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ABB8E3858D3C Received: from localhost.intra.ispras.ru (unknown [10.10.3.121]) by mail.ispras.ru (Postfix) with ESMTP id 2411C44C1013; Mon, 8 May 2023 18:13:19 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 2411C44C1013 To: gcc-patches@gcc.gnu.org Cc: Alexander Monakov Subject: [PATCH 2/3] genmatch: clean up showUsage Date: Mon, 8 May 2023 21:13:10 +0300 Message-Id: <20230508181311.25961-3-amonakov@ispras.ru> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20230508181311.25961-1-amonakov@ispras.ru> References: <20230508181311.25961-1-amonakov@ispras.ru> MIME-Version: 1.0 X-Spam-Status: No, score=-9.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, 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: Alexander Monakov via Gcc-patches From: Alexander Monakov Reply-To: Alexander Monakov Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Display usage more consistently and get rid of camelCase. gcc/ChangeLog: * genmatch.cc (showUsage): Reimplement as ... (usage): ...this. Adjust all uses. (main): Print usage when no arguments. Add missing 'return 1'. --- gcc/genmatch.cc | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/gcc/genmatch.cc b/gcc/genmatch.cc index d5e56e2d68..baf93855a6 100644 --- a/gcc/genmatch.cc +++ b/gcc/genmatch.cc @@ -5301,13 +5301,12 @@ round_alloc_size (size_t s) /* Construct and display the help menu. */ static void -showUsage () +usage () { - fprintf (stderr, "Usage: genmatch [--gimple] [--generic] " - "[--header=] [--include=] [-v[v]] input " - "[...]\n"); - fprintf (stderr, "\nWhen more then one outputfile is specified --header " - "is required.\n"); + const char *usage = "Usage:\n" + " %s [--gimple|--generic] [-v[v]] \n" + " %s [options] [--include=FILE] --header=FILE ...\n"; + fprintf (stderr, usage, progname, progname); } /* Write out the correct include to the match-head fle containing the helper @@ -5332,9 +5331,6 @@ main (int argc, char **argv) progname = "genmatch"; - if (argc < 2) - return 1; - bool gimple = true; char *s_header_file = NULL; char *s_include_file = NULL; @@ -5359,14 +5355,17 @@ main (int argc, char **argv) files.safe_push (argv[i]); else { - showUsage (); + usage (); return 1; } } /* Validate if the combinations are valid. */ if ((files.length () > 1 && !s_header_file) || files.is_empty ()) - showUsage (); + { + usage (); + return 1; + } if (!s_include_file) s_include_file = s_header_file; From patchwork Mon May 8 18:13:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Monakov X-Patchwork-Id: 1778520 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=eXYhmOPJ; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QFTv12rpxz214S for ; Tue, 9 May 2023 04:13:49 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F39BB385558E for ; Mon, 8 May 2023 18:13:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F39BB385558E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683569626; bh=t2i/YmdO+2kv6OEpvtuOxTFRzNyBRSJz1kmBaj184NY=; 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=eXYhmOPJttcXytqyWQjGTkvjAO6FLcZhJlC5zwYfKI3rJScL39D7kUn3+02DCS9+C cnVZjgZt8Wfdtux0qRWAPeT9cGQ82ktd1zWf30pu9t4Fi/Obn23PTac4mDE/CKlt65 Rx9ZODGlBLi/Mnf24KpJest5EKge45tpl131bL5U= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by sourceware.org (Postfix) with ESMTPS id A91363858D35 for ; Mon, 8 May 2023 18:13:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A91363858D35 Received: from localhost.intra.ispras.ru (unknown [10.10.3.121]) by mail.ispras.ru (Postfix) with ESMTP id 42C5144C1028; Mon, 8 May 2023 18:13:19 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 42C5144C1028 To: gcc-patches@gcc.gnu.org Cc: Alexander Monakov Subject: [PATCH 3/3] genmatch: fixup get_out_file Date: Mon, 8 May 2023 21:13:11 +0300 Message-Id: <20230508181311.25961-4-amonakov@ispras.ru> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20230508181311.25961-1-amonakov@ispras.ru> References: <20230508181311.25961-1-amonakov@ispras.ru> MIME-Version: 1.0 X-Spam-Status: No, score=-9.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, 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: Alexander Monakov via Gcc-patches From: Alexander Monakov Reply-To: Alexander Monakov Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" get_out_file did not follow the coding conventions (mixing three-space and two-space indentation, missing linebreak before function name). Take that as an excuse to reimplement it in a more terse manner and rename as 'choose_output', which is hopefully more descriptive. gcc/ChangeLog: * genmatch.cc (get_out_file): Make static and rename to ... (choose_output): ... this. Reimplement. Update all uses ... (decision_tree::gen): ... here and ... (main): ... here. --- gcc/genmatch.cc | 41 +++++++++++++++++------------------------ 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/gcc/genmatch.cc b/gcc/genmatch.cc index baf93855a6..177c13d87c 100644 --- a/gcc/genmatch.cc +++ b/gcc/genmatch.cc @@ -255,28 +255,21 @@ output_line_directive (FILE *f, location_t location, #define SIZED_BASED_CHUNKS 1 -int current_file = 0; -FILE *get_out_file (vec &parts) +static FILE * +choose_output (const vec &parts) { #ifdef SIZED_BASED_CHUNKS - if (parts.length () == 1) - return parts[0]; - - FILE *f = NULL; - long min = 0; - /* We've started writing all the files at pos 0, so ftell is equivalent - to the size and should be much faster. */ - for (unsigned i = 0; i < parts.length (); i++) - { - long res = ftell (parts[i]); - if (!f || res < min) - { - min = res; - f = parts[i]; - } - } - return f; + FILE *shortest = NULL; + long min = 0; + for (FILE *part : parts) + { + long len = ftell (part); + if (!shortest || min > len) + shortest = part, min = len; + } + return shortest; #else + static int current_file; return parts[current_file++ % parts.length ()]; #endif } @@ -3924,7 +3917,7 @@ decision_tree::gen (vec &files, bool gimple) } /* Cycle the file buffers. */ - FILE *f = get_out_file (files); + FILE *f = choose_output (files); /* Generate a split out function with the leaf transform code. */ s->fname = xasprintf ("%s_simplify_%u", gimple ? "gimple" : "generic", @@ -3991,7 +3984,7 @@ decision_tree::gen (vec &files, bool gimple) /* Cycle the file buffers. */ - FILE *f = get_out_file (files); + FILE *f = choose_output (files); if (gimple) fp_decl (f, "\nbool\n" @@ -4028,7 +4021,7 @@ decision_tree::gen (vec &files, bool gimple) { /* Cycle the file buffers. */ - FILE *f = get_out_file (files); + FILE *f = choose_output (files); if (gimple) fp_decl (f, "\nbool\n" @@ -4053,7 +4046,7 @@ decision_tree::gen (vec &files, bool gimple) /* Cycle the file buffers. */ - FILE *f = get_out_file (files); + FILE *f = choose_output (files); /* Then generate the main entry with the outermost switch and tail-calls to the split-out functions. */ @@ -5461,7 +5454,7 @@ main (int argc, char **argv) dt.print (stderr); /* Cycle the file buffers. */ - FILE *f = get_out_file (parts); + FILE *f = choose_output (parts); write_predicate (f, pred, dt, gimple); }