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: 91220 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2340409vqo; Mon, 8 May 2023 11:14:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4+2y5kO2+e+DxHWAImkOvhshQ6gC337GrmROcl7yV3wGLHbt56H6UJWwHr5cqXayEW+SU/ X-Received: by 2002:a17:907:3f18:b0:966:31a1:8d6e with SMTP id hq24-20020a1709073f1800b0096631a18d6emr5510849ejc.57.1683569687746; Mon, 08 May 2023 11:14:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683569687; cv=none; d=google.com; s=arc-20160816; b=aTx1oKyiqQWz90i7nEaTKJxYpWfOeZRmLSkoAyelaGLlgZqeCzrc9/Puv3AGeCP03g JqnaOKrNFjOkUn8wv0/ZxEUnejz8azmF47RuD7RJfEAs7gSRVFkhj5hgCpvRT9wPJv3o Sz9kbRVu7mIJcMtlsHGDR+TE0F5b2JPd5tH4H0YBypiqQOAAdiv2Qh7MMLSvUgAue52M +sn5nZ4o/1rsM/aM0XeK8n1+L1B3aKLth5mBPT4dCT8GfA5h2FMUKLWT1d4V7Ajf08FE 5w4M+js6edccfa0IBEzJLakABwjH4WgcTN0JvskpKL6AM5DUI75kbxShn9Azsw1MrueD Nn7A== 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:dkim-filter:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=t2i/YmdO+2kv6OEpvtuOxTFRzNyBRSJz1kmBaj184NY=; b=foa9MGf7MVnbLlBfMsriSL+wH/3sVhVmio8N7/zyBfAtOEBHC+4QT1eeJcnhyLxmGb 6iQAj7Cai8qUePd0d0g2XrQI7xqI0kyZlL8KxtVr9WGywJUhztM54HIeWB+nX+3feI5P 9cGm9KLhI81zSgjc8G3Wi7LpmmotMWndlSvmcJyWhT+FV4Apsoop1i7dSXwwkksoXDjc AJt+BqecV8BWqbUrUDKVY5SsiZsG48wJA59/nmWUibd549UGhfof9/vFY1WWQIgjJUnZ jY0skDY3UXXhX2ottioeT/EadyxZVsM7p6fugZ8wRrsSUTQdj34t8ILoL+4H0uIrdOBo C/9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=BJvtPtOv; 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 t12-20020a170906948c00b0096628c30c8esi334143ejx.230.2023.05.08.11.14.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 May 2023 11:14:47 -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=BJvtPtOv; 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 88E91385357A for ; Mon, 8 May 2023 18:14:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 88E91385357A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683569650; 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=BJvtPtOvhkkjxTW0uJauUDWEg9TZb1VFszbndYGJQVZZMiOVhCW+s00UNdMZsii+1 ACOl6lr9i0bGMltB42m5JPG1KkHRh1waoBN09vT3wX0p8FQu/goTWnu2UCmXmU3p/f qr1HMEaK99QABDquE5cpWpQgqXrIPRcPs84hpHlg= 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765350768710748461?= X-GMAIL-MSGID: =?utf-8?q?1765350768710748461?= 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); }