From patchwork Sat Aug 1 18:46:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Sayle X-Patchwork-Id: 1339830 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: 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@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=nextmovesoftware.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=nextmovesoftware.com header.i=@nextmovesoftware.com header.a=rsa-sha256 header.s=default header.b=em96KNDT; 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BJtQW6vC3z9sSG for ; Sun, 2 Aug 2020 04:46:09 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8F6ED3857C7A; Sat, 1 Aug 2020 18:46:06 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from server.nextmovesoftware.com (server.nextmovesoftware.com [162.254.253.69]) by sourceware.org (Postfix) with ESMTPS id B0A513858D35 for ; Sat, 1 Aug 2020 18:46:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B0A513858D35 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=nextmovesoftware.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=roger@nextmovesoftware.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nextmovesoftware.com; s=default; h=Content-Type:MIME-Version:Message-ID: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=lr3UZXQsU2RpNQAbiQJHdCDc2JGEifNzejmLfD6AgVg=; b=em96KNDTlvtOqHdJP5/juWnU6C /VScGrcVX2yVlPxR+fCcI/Pk67jZvQack8jQ0pdhOHXchxVGCaKAeBBbMO6ts5x+83GOKU9ncW8k6 0avJtwNTQnkwB++Y0pfW+bg2SlvltkIxeruJ+S0xnXjx7HRqtIUwidX5PsgNOpAn7y8BxXleAkSLG F4kks4QyRLR6U7jEgvhzwEAtotEtwF76OJiRdUlS6ITxa/g5YiX+woPvc33wO4NcjAGDCWV50iaMh debrEOH48TNl7BREyf0KDriSrsc3Zw+BsXX6Z15pkXAREIoHONxz1ICpB13d7x/Ft7qc3dT9dDT9i RhtZF01Q==; Received: from host86-137-89-56.range86-137.btcentralplus.com ([86.137.89.56]:58464 helo=Dell) by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1k1wWA-0004kA-Tz for gcc-patches@gcc.gnu.org; Sat, 01 Aug 2020 14:46:03 -0400 From: "Roger Sayle" To: "'GCC Patches'" Subject: [PATCH] genmatch: Avoid unused parameter warnings in generated code. Date: Sat, 1 Aug 2020 19:46:01 +0100 Message-ID: <000c01d66834$01eaee10$05c0ca30$@nextmovesoftware.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdZoM6jF85NqiC5ARX+9uVbjlHJINg== Content-Language: en-gb X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - server.nextmovesoftware.com X-AntiAbuse: Original Domain - gcc.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - nextmovesoftware.com X-Get-Message-Sender-Via: server.nextmovesoftware.com: authenticated_id: roger@nextmovesoftware.com X-Authenticated-Sender: server.nextmovesoftware.com: roger@nextmovesoftware.com X-Source: X-Source-Args: X-Source-Dir: X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" This patch silences a number of unused parameter warnings whilst compiling both generic-match.c and gimple-match.c. The problem is that multiple (polymorphic) functions are generated for generic_simplify and gimple_simplify, each handling tree codes with a specific number of children. Currently, there are no simplifications for tree codes with four or five children, leading to functions with "empty" bodies and unused function arguments. This patch detects those cases, and generates stub functions (with anonymous arguments) to silence these warnings. Previously, genmatch would generate: static bool gimple_simplify (gimple_match_op *res_op, gimple_seq *seq, tree (*valueize)(tree) ATTRIBUTE_UNUSED, code_helper code, const tree type, tree _p0, tree _p1, tree _p2, tree _p3) { switch (code.get_rep()) { default:; } return false; } which results in: gimple_simplify (gimple_match_op *res_op, gimple_seq *seq, ^ gimple-match.c:130408:1: warning: unused parameter 'seq' [-Wunused-parameter] gimple-match.c:130408:1: warning: unused parameter 'type' [-Wunused-parameter] gimple-match.c:130408:1: warning: unused parameter '_p0' [-Wunused-parameter] gimple-match.c:130408:1: warning: unused parameter '_p1' [-Wunused-parameter] gimple-match.c:130408:1: warning: unused parameter '_p2' [-Wunused-parameter] gimple-match.c:130408:1: warning: unused parameter '_p3' [-Wunused-parameter] gimple-match.c:130420:1: warning: unused parameter 'res_op' [-Wunused-parameter] With this patch genmatch now generates: static bool gimple_simplify (gimple_match_op*, gimple_seq*, tree (*)(tree), code_helper, const tree, tree, tree, tree, tree) { return false; } which has the same signature but no compilation warnings. This patch has been tested on x86_64-pc-linux-gnu with a full "make bootstrap" and "make -k check" with no new failures. Ok for mainline? 2020-08-01 Roger Sayle * gcc/genmatch.c (decision_tree::gen): Emit stub functions for tree code operand counts that have no simplifications. (main): Correct comment typo. Thanks in advance, Roger --- Roger Sayle NextMove Software Cambridge, UK diff --git a/gcc/genmatch.c b/gcc/genmatch.c index 0a8cba6..022ad8d 100644 --- a/gcc/genmatch.c +++ b/gcc/genmatch.c @@ -3798,6 +3798,8 @@ decision_tree::gen (FILE *f, bool gimple) for (unsigned n = 1; n <= 5; ++n) { + bool has_kids_p = false; + /* First generate split-out functions. */ for (unsigned j = 0; j < root->kids.length (); j++) { @@ -3836,6 +3838,32 @@ decision_tree::gen (FILE *f, bool gimple) else fprintf (f, " return NULL_TREE;\n"); fprintf (f, "}\n"); + has_kids_p = true; + } + + /* If this main entry has no children, avoid generating code + with compiler warnings, by generating a simple stub. */ + if (! has_kids_p) + { + if (gimple) + fprintf (f, "\nstatic bool\n" + "gimple_simplify (gimple_match_op*, gimple_seq*,\n" + " tree (*)(tree), code_helper,\n" + " const tree"); + else + fprintf (f, "\ntree\n" + "generic_simplify (location_t, enum tree_code,\n" + " const tree"); + for (unsigned i = 0; i < n; ++i) + fprintf (f, ", tree"); + fprintf (f, ")\n"); + fprintf (f, "{\n"); + if (gimple) + fprintf (f, " return false;\n"); + else + fprintf (f, " return NULL_TREE;\n"); + fprintf (f, "}\n"); + continue; } /* Then generate the main entry with the outermost switch and @@ -5061,7 +5089,7 @@ round_alloc_size (size_t s) } -/* The genmatch generator progam. It reads from a pattern description +/* The genmatch generator program. It reads from a pattern description and outputs GIMPLE or GENERIC IL matching and simplification routines. */ int