From patchwork Mon Jul 31 11:03:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Turko X-Patchwork-Id: 1814944 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=server2.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=GxOQESih; dkim-atps=neutral Received: from server2.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 4RDwQR4Z75z20G9 for ; Mon, 31 Jul 2023 21:05:51 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 79E1E3857349 for ; Mon, 31 Jul 2023 11:05:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 79E1E3857349 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1690801549; bh=bCrTmaR5OeuoIQU1xXQyWnQzp7z/ddqZBwl2ONrW0is=; 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=GxOQESihAFBndSrM1NObCUtk6ge/jDgSh/hVfXemVVY0kimm5OO2/clbc+ptp6a73 hQ2d4eCBaN0uCeoskY0T8eXYMiZw/P7f+UdC7caaJmuQQiq+aZGQh86DzVfCt999uY vtWj5AbS8fhnPGsOKLCesALU7hhDcKUO4e7tXb1c= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by sourceware.org (Postfix) with ESMTPS id 6A0F73858CD1 for ; Mon, 31 Jul 2023 11:05:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6A0F73858CD1 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-3fbc54cab6fso40789245e9.0 for ; Mon, 31 Jul 2023 04:05:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690801517; x=1691406317; 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=bCrTmaR5OeuoIQU1xXQyWnQzp7z/ddqZBwl2ONrW0is=; b=HM5L61pvtj3EdMV8bYvwcFl3wv+78dFDP/DECwMvyzKOI0Y83gGDD2NyS6yCzHxvCE TvX+k3icTr7+PuuCqNbErhyPlT2JmO8iuXqu0WoIPMlJBQP7+gz94t05KZZv+3OFtV84 RODEd5S+WwTDA2r3hGOL5eIPDu31PGCISO/5KyExUiQXt5PBAErF9g9A/Bz4Z1wCvjXw U0sZ8B37FUmeYf7zqpQ4ZvfFSGuSmwVg5jI/wiJ3kG4OgC+Iq2iSsB1Bvm6ePxjRLpri I6D+dUSYkr/PIKRf6ODkkEBxNOwG2xaUK7Ps+OZukYgsrFNjBkj5qPWfvpFIgXFkpy+y cU1w== X-Gm-Message-State: ABy/qLa0ZTb1cahcZNlLOAOx4MjkVJ1x0RKWxFZwpjM6PGl4EiHxms6I 9Dugg8SOxDVk30oNW4umGUHLr8luNNR2htYy X-Google-Smtp-Source: APBJJlGaN5tMY3VF3Pi5LfdGuCgoZtr3a8sC7i8keXY42ZvMEAI9ORPWPJvxuCMafpjwun0QblGNUg== X-Received: by 2002:adf:face:0:b0:314:11ea:480d with SMTP id a14-20020adfface000000b0031411ea480dmr6165217wrs.9.1690801516885; Mon, 31 Jul 2023 04:05:16 -0700 (PDT) Received: from amwld-aturko1.us.drwholdings.com ([149.14.21.6]) by smtp.gmail.com with ESMTPSA id x9-20020a5d6509000000b00315af025098sm12655596wru.46.2023.07.31.04.05.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 04:05:16 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Andrzej Turko Subject: [PATCH 1/3] Support get_or_insert in ordered_hash_map Date: Mon, 31 Jul 2023 13:03:44 +0200 Message-Id: <20230731110346.174848-2-andrzej.turko@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230731110346.174848-1-andrzej.turko@gmail.com> References: <20230731110346.174848-1-andrzej.turko@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.8 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Get_or_insert method is already supported by the unordered hash map. Adding it to the ordered map enables us to replace the unordered map with the ordered one in cases where ordering may be useful. Signed-off-by: Andrzej Turko gcc/ChangeLog: * ordered-hash-map.h: Add get_or_insert. * Makefile.in: Require the ordered map header for genmatch.o. * ordered-hash-map-tests.cc: Use get_or_insert in tests. Signed-off-by: Andrzej Turko --- gcc/Makefile.in | 4 ++-- gcc/ordered-hash-map-tests.cc | 19 +++++++++++++++---- gcc/ordered-hash-map.h | 26 ++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/gcc/Makefile.in b/gcc/Makefile.in index e99628cec07..2429128cbf2 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -3004,8 +3004,8 @@ build/genhooks.o : genhooks.cc $(TARGET_DEF) $(C_TARGET_DEF) \ $(COMMON_TARGET_DEF) $(D_TARGET_DEF) $(BCONFIG_H) $(SYSTEM_H) errors.h build/genmddump.o : genmddump.cc $(RTL_BASE_H) $(BCONFIG_H) $(SYSTEM_H) \ $(CORETYPES_H) $(GTM_H) errors.h $(READ_MD_H) $(GENSUPPORT_H) -build/genmatch.o : genmatch.cc $(BCONFIG_H) $(SYSTEM_H) \ - $(CORETYPES_H) errors.h $(HASH_TABLE_H) hash-map.h $(GGC_H) is-a.h \ +build/genmatch.o : genmatch.cc $(BCONFIG_H) $(SYSTEM_H) $(CORETYPES_H) \ + errors.h $(HASH_TABLE_H) hash-map.h $(GGC_H) is-a.h ordered-hash-map.h \ tree.def builtins.def internal-fn.def case-cfn-macros.h $(CPPLIB_H) build/gencfn-macros.o : gencfn-macros.cc $(BCONFIG_H) $(SYSTEM_H) \ $(CORETYPES_H) errors.h $(HASH_TABLE_H) hash-set.h builtins.def \ diff --git a/gcc/ordered-hash-map-tests.cc b/gcc/ordered-hash-map-tests.cc index 1c26bbfa979..55894c25fa0 100644 --- a/gcc/ordered-hash-map-tests.cc +++ b/gcc/ordered-hash-map-tests.cc @@ -58,6 +58,7 @@ static void test_map_of_strings_to_int () { ordered_hash_map m; + bool existed; const char *ostrich = "ostrich"; const char *elephant = "elephant"; @@ -74,17 +75,23 @@ test_map_of_strings_to_int () ASSERT_EQ (false, m.put (ostrich, 2)); ASSERT_EQ (false, m.put (elephant, 4)); ASSERT_EQ (false, m.put (ant, 6)); - ASSERT_EQ (false, m.put (spider, 8)); + existed = true; + int &value = m.get_or_insert (spider, &existed); + value = 8; + ASSERT_EQ (false, existed); ASSERT_EQ (false, m.put (millipede, 750)); ASSERT_EQ (false, m.put (eric, 3)); + /* Verify that we can recover the stored values. */ ASSERT_EQ (6, m.elements ()); ASSERT_EQ (2, *m.get (ostrich)); ASSERT_EQ (4, *m.get (elephant)); ASSERT_EQ (6, *m.get (ant)); ASSERT_EQ (8, *m.get (spider)); - ASSERT_EQ (750, *m.get (millipede)); + existed = false; + ASSERT_EQ (750, m.get_or_insert (millipede, &existed)); + ASSERT_EQ (true, existed); ASSERT_EQ (3, *m.get (eric)); /* Verify that the order of insertion is preserved. */ @@ -113,6 +120,7 @@ test_map_of_int_to_strings () { const int EMPTY = -1; const int DELETED = -2; + bool existed; typedef int_hash int_hash_t; ordered_hash_map m; @@ -131,7 +139,9 @@ test_map_of_int_to_strings () ASSERT_EQ (false, m.put (2, ostrich)); ASSERT_EQ (false, m.put (4, elephant)); ASSERT_EQ (false, m.put (6, ant)); - ASSERT_EQ (false, m.put (8, spider)); + const char* &value = m.get_or_insert (8, &existed); + value = spider; + ASSERT_EQ (false, existed); ASSERT_EQ (false, m.put (750, millipede)); ASSERT_EQ (false, m.put (3, eric)); @@ -141,7 +151,8 @@ test_map_of_int_to_strings () ASSERT_EQ (*m.get (4), elephant); ASSERT_EQ (*m.get (6), ant); ASSERT_EQ (*m.get (8), spider); - ASSERT_EQ (*m.get (750), millipede); + ASSERT_EQ (m.get_or_insert (750, &existed), millipede); + ASSERT_EQ (existed, TRUE); ASSERT_EQ (*m.get (3), eric); /* Verify that the order of insertion is preserved. */ diff --git a/gcc/ordered-hash-map.h b/gcc/ordered-hash-map.h index 6b68cc96305..9fc875182e1 100644 --- a/gcc/ordered-hash-map.h +++ b/gcc/ordered-hash-map.h @@ -76,6 +76,32 @@ public: return m_map.get (k); } + /* Return a reference to the value for the passed in key, creating the entry + if it doesn't already exist. If existed is not NULL then it is set to + false if the key was not previously in the map, and true otherwise. */ + + Value &get_or_insert (const Key &k, bool *existed = NULL) + { + bool _existed; + Value &ret = m_map.get_or_insert (k, &_existed); + + if (!_existed) + { + bool key_present; + int &slot = m_key_index.get_or_insert (k, &key_present); + if (!key_present) + { + slot = m_keys.length (); + m_keys.safe_push (k); + } + } + + if (existed) + *existed = _existed; + + return ret; + } + /* Removing a key removes it from the map, but retains the insertion order. */ From patchwork Mon Jul 31 11:03:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Turko X-Patchwork-Id: 1814943 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=server2.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=YFz+Pdj1; dkim-atps=neutral Received: from server2.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 4RDwQR28RJz20G3 for ; Mon, 31 Jul 2023 21:05:51 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 382143857343 for ; Mon, 31 Jul 2023 11:05:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 382143857343 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1690801549; bh=iSIPyKt0sibT2CJE//PvT6rT1R1NUz/JQ8xskku3M08=; 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=YFz+Pdj14tVETuZbIQQpoqOBgN/YZcLeB7L4kr4QbMKRWpD3N6rdUfRNvj/snmeqC Fyp9WqPBmZyj+beZdBmCIqVtGUhe3AXbaw/0P6SGlI0tMAmnJG+snb0bwMmo9HwJ5X g4fzc5OFrGN2n5P6IVUvxgRKCunsZJd0W1h0Zo1E= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by sourceware.org (Postfix) with ESMTPS id 178173858C2F for ; Mon, 31 Jul 2023 11:05:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 178173858C2F Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-3fe1d462762so8772875e9.0 for ; Mon, 31 Jul 2023 04:05:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690801517; x=1691406317; 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=iSIPyKt0sibT2CJE//PvT6rT1R1NUz/JQ8xskku3M08=; b=IMBnUYiVDK8I6yuFc3wNNOLPoYKYRxkrOyjclSWDHbZvKgw30MvlnhBBBIzwGUdc6y n5g9H3sa/KRMUSZ+gAqnutAMpfX5XGZGjFayZKsbTg8sAYDfO3MqBBRdqd/vsWiFUPhL zHgBCvwYYDHOWLG38TuJPOF0bD/grYMMYp9H3pIRCofQ3UsJKXkkufy3uE39K4f0Vwvl QJQE2xnw62tnbb9c4YmMmtFV8WwcRjJ6tnl9pMlG/tcuZC0oXVnQBGWiAMUScm6H6yD2 adTBiuJmt94cwUAsruNXJY9hwtsSTD808Za3DrnnADxXq8bFnqbP1stzSRb5+RYvkfOs a19w== X-Gm-Message-State: ABy/qLZ5kuvM+qdbXWwok0jSlldU3ptqQZjv7sjXkEziJe6RDDQL8Moa 5w04saFztUrksR+2z4Rb7mNItbR/xRmEzEV7 X-Google-Smtp-Source: APBJJlFd0p2CDk8wKzyOTChkdEKUJrdSbpqZEQ8Pkn+dYq7jtp5Iagk7PwAC1BWP3ovYsSYITGBBnw== X-Received: by 2002:a7b:c7d6:0:b0:3f6:58ad:ed85 with SMTP id z22-20020a7bc7d6000000b003f658aded85mr6541648wmk.10.1690801517433; Mon, 31 Jul 2023 04:05:17 -0700 (PDT) Received: from amwld-aturko1.us.drwholdings.com ([149.14.21.6]) by smtp.gmail.com with ESMTPSA id x9-20020a5d6509000000b00315af025098sm12655596wru.46.2023.07.31.04.05.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 04:05:17 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Andrzej Turko Subject: [PATCH 2/3] genmatch: Reduce variability of generated code Date: Mon, 31 Jul 2023 13:03:45 +0200 Message-Id: <20230731110346.174848-3-andrzej.turko@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230731110346.174848-1-andrzej.turko@gmail.com> References: <20230731110346.174848-1-andrzej.turko@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.8 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" So far genmatch has been using an unordered map to store information about functions to be generated. Since corresponding locations from match.pd were used as keys in the map, even small changes to match.pd which caused line number changes would change the order in which the functions are generated. This would reshuffle the functions between the generated .cc files. This way even a minimal modification to match.pd forces recompilation of all object files originating from match.pd on rebuild. This commit makes sure that functions are generated in the order of their processing (in contrast to the random order based on hashes of their locations in match.pd). This is done by replacing the unordered map with an ordered one. This way small changes to match.pd does not cause function renaming and reshuffling among generated source files. Together with the subsequent change to logging fprintf calls, this removes unnecessary changes to the files generated by genmatch allowing for reuse of already built object files during rebuild. The aim is to make editing of match.pd and subsequent testing easier. Signed-off-by: Andrzej Turko gcc/ChangeLog: * genmatch.cc: Make sinfo map ordered. Signed-off-by: Andrzej Turko --- gcc/genmatch.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gcc/genmatch.cc b/gcc/genmatch.cc index 2302f2a7ff0..1deca505603 100644 --- a/gcc/genmatch.cc +++ b/gcc/genmatch.cc @@ -29,6 +29,7 @@ along with GCC; see the file COPYING3. If not see #include "hash-table.h" #include "hash-set.h" #include "is-a.h" +#include "ordered-hash-map.h" /* Stubs for GGC referenced through instantiations triggered by hash-map. */ @@ -1684,7 +1685,7 @@ struct sinfo_hashmap_traits : simple_hashmap_traits, template static inline void remove (T &) {} }; -typedef hash_map +typedef ordered_hash_map sinfo_map_t; /* Current simplifier ID we are processing during insertion into the From patchwork Mon Jul 31 11:03:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Turko X-Patchwork-Id: 1814946 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=server2.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=T3OKdUv+; dkim-atps=neutral Received: from server2.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 4RDwQg0vclz20G3 for ; Mon, 31 Jul 2023 21:06:03 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1B29F385C017 for ; Mon, 31 Jul 2023 11:06:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1B29F385C017 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1690801561; bh=gx9r3uxsHXaIZBCrzvAyKa1KN7nyc67MnEyogJScSBk=; 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=T3OKdUv+QVYdXIddUOWR3nPKNqVYI7V+gqCGKBQm2pUx+v4LZijkPWildh2SEBHPe ggTRVhjBrUm6Sn9fhY5TYVPZUE6bycbv8Ui4uUzIWds9SiNgR08i1sUFbz6gGE+U1C KAGLIGfZi/vO50W5Y2yXz3/HMiAXW+UFumchACWg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by sourceware.org (Postfix) with ESMTPS id BBD8A3858C39 for ; Mon, 31 Jul 2023 11:05:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BBD8A3858C39 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-3128fcd58f3so4605431f8f.1 for ; Mon, 31 Jul 2023 04:05:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690801518; x=1691406318; 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=gx9r3uxsHXaIZBCrzvAyKa1KN7nyc67MnEyogJScSBk=; b=Hk45E9zRUTsmfWdYQLhUbhciqnGX6NhT6mOFSe4ijx+D2MzVlT8ZQHQNDb/494iDtL titkRBJKE/is884g/9qYjCNu0RWYYIu4X/cD/23PGSqSYN6FWxK/qXJcO6OxwPhxSbFJ DlvmKDhdC5p/HgTmhP1xqopod4+4/BRk4tv39qBe5O7xdI4jKEENJd5t1txbqv6lzWfS QfB6f/zz08b9lkbV0f9E7SgrmJFsVXK6EpaFvdu6PNNUpwAyYTgDHXA7acqWpFJ/47zm 2arwQOgNb4Cx5HeDkNnZQ/JsmeyZvSqgILgjxqWwCwHHngrGEVEt0xGEXnxvs5tOSCwW wUjA== X-Gm-Message-State: ABy/qLayNIFAVJ1Wj/AzNnAp0f/4iXwd44UBa7SR3OJ/tI61MWRG0L89 E6tvXS35zs5fUpuVIGpjLMQHDlvI8JjkN9Ze X-Google-Smtp-Source: APBJJlGlmqXTS/W2qzaM2d27lJQagFZWj/NnV+8VvYilPLHdZ5dXdtKqP/CMQqIKmCDdBhTMHBghnw== X-Received: by 2002:a5d:5305:0:b0:313:f0d7:a43 with SMTP id e5-20020a5d5305000000b00313f0d70a43mr7468176wrv.23.1690801518130; Mon, 31 Jul 2023 04:05:18 -0700 (PDT) Received: from amwld-aturko1.us.drwholdings.com ([149.14.21.6]) by smtp.gmail.com with ESMTPSA id x9-20020a5d6509000000b00315af025098sm12655596wru.46.2023.07.31.04.05.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 04:05:17 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Andrzej Turko Subject: [PATCH 3/3] genmatch: Log line numbers indirectly Date: Mon, 31 Jul 2023 13:03:46 +0200 Message-Id: <20230731110346.174848-4-andrzej.turko@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230731110346.174848-1-andrzej.turko@gmail.com> References: <20230731110346.174848-1-andrzej.turko@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.8 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" 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. With this change those logging fprintf calls reference an array of line numbers, which is defined in one of the produced files. Thanks to this, when match.pd changes, it is enough to rebuild that single file and, of course, those actually affected by the change. Signed-off-by: Andrzej Turko gcc/ChangeLog: * genmatch.cc: Keep line numbers from match.pd in an array. Signed-off-by: Andrzej Turko --- gcc/genmatch.cc | 73 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 65 insertions(+), 8 deletions(-) diff --git a/gcc/genmatch.cc b/gcc/genmatch.cc index 1deca505603..0a480a140c9 100644 --- a/gcc/genmatch.cc +++ b/gcc/genmatch.cc @@ -217,9 +217,48 @@ 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) +{ + if (gimple) + fprintf (f, "\nextern int __gimple_dbg_line_numbers[];\n"); + else + fprintf (f, "\nextern int __generic_dbg_line_numbers[];\n"); +} + +static void +define_dbg_line_numbers (bool gimple, FILE *f) +{ + if (gimple) + fprintf (f, "\nint __gimple_dbg_line_numbers[%d] = {", + dbg_line_numbers.length ()); + else + fprintf (f, "\nint __generic_dbg_line_numbers[%d] = {", + dbg_line_numbers.length ()); + + if (dbg_line_numbers.is_empty ()) + { + fprintf (f, "};\n\n"); + return; + } + + 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 ()); +} + 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, bool gimple = false) { const line_map_ordinary *map; linemap_resolve_location (line_table, location, LRK_SPELLING_LOCATION, &map); @@ -239,7 +278,20 @@ output_line_directive (FILE *f, location_t location, ++file; if (fnargs) - fprintf (f, "\"%s\", %d", file, loc.line); + { + if (indirect_line_numbers) + { + if (gimple) + fprintf (f, "\"%s\", __gimple_dbg_line_numbers[%d]", + file, dbg_line_numbers.length ()); + else + fprintf (f, "\"%s\", __generic_dbg_line_numbers[%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); } @@ -3378,7 +3430,8 @@ 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 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_debug_printf (FILE *f, int indent, class simplify *s, operand *result, + bool gimple) { fprintf_indent (f, indent, "if (UNLIKELY (debug_dump)) " "fprintf (dump_file, \"%s ", @@ -3387,7 +3440,7 @@ emit_debug_printf (FILE *f, int indent, class simplify *s, operand *result) fprintf (f, "%%s:%%d, %%s:%%d\\n\", "); output_line_directive (f, result ? result->location : s->match->location, true, - true); + true, true, gimple); fprintf (f, ", __FILE__, __LINE__);\n"); } @@ -3524,7 +3577,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_debug_printf (f, indent, s, result, gimple); fprintf_indent (f, indent, "return true;\n"); } else if (gimple) @@ -3615,7 +3668,7 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result) } else gcc_unreachable (); - emit_debug_printf (f, indent, s, result); + emit_debug_printf (f, indent, s, result, gimple); fprintf_indent (f, indent, "return true;\n"); } else /* GENERIC */ @@ -3670,7 +3723,7 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result) } if (is_predicate) { - emit_debug_printf (f, indent, s, result); + emit_debug_printf (f, indent, s, result, gimple); fprintf_indent (f, indent, "return true;\n"); } else @@ -3738,7 +3791,7 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result) i); } } - emit_debug_printf (f, indent, s, result); + emit_debug_printf (f, indent, s, result, gimple); fprintf_indent (f, indent, "return _r;\n"); } } @@ -5447,6 +5500,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 +5514,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 +5557,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");