From patchwork Wed Aug 2 09:55:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Turko X-Patchwork-Id: 129735 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp341050vqx; Wed, 2 Aug 2023 03:02:35 -0700 (PDT) X-Google-Smtp-Source: APBJJlHPl7Xqh6Hcj0q8Fkf8MJlTcEF5TFkC6UpTcalz5MjObv9xuQ/jxybjEtV36DoYMmOZ/eKD X-Received: by 2002:aa7:c795:0:b0:522:2c44:a915 with SMTP id n21-20020aa7c795000000b005222c44a915mr4830940eds.24.1690970555009; Wed, 02 Aug 2023 03:02:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690970554; cv=none; d=google.com; s=arc-20160816; b=pxAbDFj2ktWR8IWSX1Uahb7G5WbBZTBJWaaEQsfeSvIhuvQT9OfrFCkdAZjtrxHh4j XeSndOI4kVuWyO7Q8JiURAFi/TFU3rjymk9PUPgjQmjHDz5srNWyH0aLFiLXbHMk8RCZ REtO/ILfBxVhY4CFTxvLcmhYqOELOgpCgJsF7NG3IC8kJSTJdk0CEyccqTyWzaTDmSAC x8Y+Sn0AYb2dPvoF4m4v6vGVXhp6NcWprcPAeuEBVtDbglqGRHHKZ1CzYlzBGRvlRmmj QU6hg5jL2RSMZ9Wqx7PKrCof2UwKpydpRadWMZdNP8PbdQMZnVACvwA2QZak9QGCfN6H hUKw== 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=jx50U3YNwZqJZ5RNjN+doWjBr6mTI5xkGFSIOlXQQ00=; fh=k/nQU4IX+jAQueq710KA8dCAcoPPe4cl6LpGj9WeH7w=; b=PTDTfOY7aojpzo0IO+Q0qp7c8gudrcNYd/nNs9bCuy4e0vCYD/QIKrhFJKHyrGQqgD 8/ztslEVmJsHEGcagtQKHDXy9f3ICE2nck41GcMk4wkB8gjGF8Ug/EZOrAsWs0lDMN0L 2Jq9dTJX1HNpss+G89lX3RnlfJS2a2Q8PzudgB0EshFZfuDTgkn6oo2b7weApDRZd9hi qNi/cvdRVTMKlptIKo7J61+KF16FtguCJ9MAmjodZUsSj/gExzXpzLxurHlXfjHvSj6z hZeGRRyMX5bn3qmi+uKclEVTSgEkKLTTKh5tVJnRqNqoRRdPvaaXs6SplE/0VU6wpt/j 50Dw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ZBxNd0a8; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id j14-20020aa7c0ce000000b00521ab8e67dbsi9662689edp.226.2023.08.02.03.02.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Aug 2023 03:02:34 -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=ZBxNd0a8; 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 F0FFB3857C41 for ; Wed, 2 Aug 2023 10:01:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F0FFB3857C41 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1690970493; bh=jx50U3YNwZqJZ5RNjN+doWjBr6mTI5xkGFSIOlXQQ00=; 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=ZBxNd0a8lUzG8s7Wl7KC4ZjuTbjS2Si1nrYatavUr0WfNOq1qcG5SjulWvkucgCBd wGVuN4XOg+HQ0c7kUPY25Qd8LIiqbg+ZPt0lz5sNTKTT7oIkx44NzeqDPnii0T1bbm iKu5JxtLpXq2CA/ZTobtLSWuHNnLXWSVIPcR/7l0= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by sourceware.org (Postfix) with ESMTPS id B703C3858D37 for ; Wed, 2 Aug 2023 10:00:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B703C3858D37 Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-31759e6a4a1so5890985f8f.3 for ; Wed, 02 Aug 2023 03:00:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690970446; x=1691575246; 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=jx50U3YNwZqJZ5RNjN+doWjBr6mTI5xkGFSIOlXQQ00=; b=NUwiMkkK1NRfuDKL4It2d3Onw1LeNPv9y97rnYttqgjffMHhnWrS4EIn+9DcTlU8Hr ao/vXGTLqk6lI8IG/Zud26SqfIKo6ReeK+ubHClKhQ0weDGbaNzTkwTgkdv7DJvd18Nf cFcbXP69B0Ev+0E847EHD+RzHKYmGi0/+nct2Mz0Cok30l15rWnF4fp7Eu1C3o+yKosd UqcoeircnozC9HnmVr96zpVwBxIrP1tlzk1SBTE4NjxZLNTp2tfWc6drDTVjDJDYZvVh K/HnQVCr2NBeY/ncWTjbvJTKLuR61m3eszAu8g/uWBLH2h6yqs+2G6dmAEkJ+K8JSEyi mcpA== X-Gm-Message-State: ABy/qLbQhxGFx7Qq1EmV+CfwUONxuHXk/hdqYMULU9GgoGcTrsaBd9mb XDK4vgeR3SqkvgyQvcaTi07v4gg7CYk0nOri X-Received: by 2002:a05:6000:1205:b0:313:e953:65cf with SMTP id e5-20020a056000120500b00313e95365cfmr4343937wrx.17.1690970446093; Wed, 02 Aug 2023 03:00:46 -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.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Aug 2023 03:00:45 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Andrzej Turko Subject: [PATCH 1/3 v2] Support get_or_insert in ordered_hash_map Date: Wed, 2 Aug 2023 11:55:25 +0200 Message-Id: <20230802095527.100830-2-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=-11.7 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: 1773111141021916026 X-GMAIL-MSGID: 1773111141021916026 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. * ordered-hash-map-tests.cc: Use get_or_insert in tests. --- gcc/ordered-hash-map-tests.cc | 19 +++++++++++++++---- gcc/ordered-hash-map.h | 26 ++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 4 deletions(-) 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 Wed Aug 2 09:55:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Turko X-Patchwork-Id: 129736 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp341156vqx; Wed, 2 Aug 2023 03:02:45 -0700 (PDT) X-Google-Smtp-Source: APBJJlG1SzZjSwBO+8kolzvq2TsDaEdz175HCQiolIJIJojZsBzF0zMUy55olTOHfj8J/eIzCEsz X-Received: by 2002:a17:907:75d1:b0:993:f15f:efbe with SMTP id jl17-20020a17090775d100b00993f15fefbemr4285087ejc.5.1690970564823; Wed, 02 Aug 2023 03:02:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690970564; cv=none; d=google.com; s=arc-20160816; b=Us2E22DLUmCBva1Rz2aqbiNW3PGIoTZtoKtJPsBub8GVEA1sOzFeBKSYkVBJ9qfcqt 8/vZak5fuYGvIFuV1dSI7+1+kNvqTtt9R5y4mEQU9/W2A0CFi7GHVGdd7wdRkF5A+PTX lf8aFuS1iyXPfYL7PBwuzH3eHlm59HDZJgk4HPlzKChv5J7VrEAoqV5+vkCAk2O0234w GqIZn7FME0iG6ifgOi3hg2egQadQNJ0vV3+TqE7P9MSXIb/YmZ/cBB3xrP18wNgrD4d2 Tpp68zLW0vOrHgGPyguYxmHl+Zl7UX8hlJLDQUdoWYZVfduRdiVVO3QZzwt1u0P7Mk9x QTGg== 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=4ONfezsU+Y6Ocii25Q8nJtKgEUDTkvb/+sIK43Mafxs=; fh=k/nQU4IX+jAQueq710KA8dCAcoPPe4cl6LpGj9WeH7w=; b=eNTuJT7h3PkqgLz1O8C6KFrpavGObWcf5W/DGowqMzMJ72mVJWvlqzxE9Pve18VzZ6 gU94V0zUobSh7DH8yVlcgBe1Qn+pH1+e09S5RaeWmwZSMkRKim9OZ2T4/SqnLAE5+Tdt fdEor7VSB0zkownL3DcroIBq/hL56uWBrcSo+VxTOw467QVL8GmbDlqQeyi241H5CqOS zJD2ropVqZmUyGTuEyuZGMaXpJzpKE/59/NUd2lcT8ybvmAI4FdxzmaaaZGdn96JK0JK qv8dWeQgqCg3Y/UQifEwgU77zbfnsFtbxD87C9ggTUuaAEC9UdzQ/noJYGvLvL2WXLW6 6uZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=s92YE7be; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id um9-20020a170906cf8900b00992d6fa3b33si9688274ejb.440.2023.08.02.03.02.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Aug 2023 03:02:44 -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=s92YE7be; 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 176FB3853D06 for ; Wed, 2 Aug 2023 10:01:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 176FB3853D06 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1690970495; bh=4ONfezsU+Y6Ocii25Q8nJtKgEUDTkvb/+sIK43Mafxs=; 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=s92YE7bedc+mO8Scy4nLSAa0KOljFsuEKbuiS/4JoWo5HdpBFVhsDfbyOdjFIFyPd hANxIiYEpAUwoT3Wtq+yaGUHmEpMEu+4ObzzkulMFeMj6Z0FmNH0if1040Du/cKPVr x7aLN74k6teLHTbZ5sGV45r690bME4SPTy2eFKic= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id 3A9113858D39 for ; Wed, 2 Aug 2023 10:00:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3A9113858D39 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-31781e15a0cso5677837f8f.3 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=1690970446; x=1691575246; 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=4ONfezsU+Y6Ocii25Q8nJtKgEUDTkvb/+sIK43Mafxs=; b=L9Q2Z0TSEa2Iet2ERqIw3h3hf3jvmkcdsYVFn2Kr/L04T+sA+hZO0apKHdq2F+icHZ 9iL6rB1mu5S4dQyp8YwtofOCjYWidynm83Y8tL/FSh0sanqvlbOvCNsgkUna7zRHH5hP 4HNiHp7pYWzRQ5U0yfTISXBn/aD6GV0cFuti/jk43C+7Q9FCqDW3g/Q3L1KVLixiFX2U oZ9UIrCq4XgQxFQVArM5R8pSvsct1/+vWoYWe9/SsuosiDrWb8VLkcxmiqE20CXXPjPi 7yCtR8OuGeY5uH5nBcQqvxH7rST4PFh2PSLuzwHTvBiDyyK8hrb50bOQ87SghD1+ps00 BuOg== X-Gm-Message-State: ABy/qLY1VN5frNpVuro8DMf8FtxNzbIC3UTMUiILJUIaCt0Bh5wZ/Cgw pin5tRKbvZqX30q3/Yvm1vc3xJCbRxgZnkZX X-Received: by 2002:a5d:6904:0:b0:317:61d8:3c83 with SMTP id t4-20020a5d6904000000b0031761d83c83mr4297974wru.3.1690970446600; Wed, 02 Aug 2023 03:00:46 -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 2/3 v2] genmatch: Reduce variability of generated code Date: Wed, 2 Aug 2023 11:55:26 +0200 Message-Id: <20230802095527.100830-3-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=-11.9 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: 1773111151030291641 X-GMAIL-MSGID: 1773111151030291641 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. * Makefile.in: Require the ordered map header for genmatch.o. --- gcc/Makefile.in | 4 ++-- gcc/genmatch.cc | 3 ++- 2 files changed, 4 insertions(+), 3 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/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 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");