From patchwork Thu Aug 3 14:21:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Turko X-Patchwork-Id: 130661 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp1184986vqx; Thu, 3 Aug 2023 07:24:55 -0700 (PDT) X-Google-Smtp-Source: APBJJlHnwm2TM5zphWD5eg7M6WiKJ64NvtsCi+9hyDl9mY+7MMbvcQnFYW9I9gBoJGV9D4pR4ZKX X-Received: by 2002:a17:907:77cf:b0:982:26c5:6525 with SMTP id kz15-20020a17090777cf00b0098226c56525mr7777645ejc.60.1691072694934; Thu, 03 Aug 2023 07:24:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691072694; cv=none; d=google.com; s=arc-20160816; b=bTSfMIRKXRR5kZ6U/ClvEbTTKDBV/PfqaK3kGcyAnVWyeQHBCtnuTOuS/i6lKfcHoP /llCaNWdYocXGtyJ6/nXjCbZ1TOVAV4TPFTyS5KlcCxkjzIHa1t80mKBt2HYymnSUekJ bhNwq8gmwJUMYt4O7xSlf1tR7/PJyxxwwiN/bnyzKqRrFaKRJiKk6+jiQUhr6LISG6DW xuOZTfWuA3HpjoA3pVOK/Ra+EHW889bN4WskPnB7mtEVtR54BjXvK8XPLS2XASpDFrHh PislZ1EE+5Y3O3WRlVPDD3CQfrZFuyc2oN6+eXMwSu3b1sPcFgLmGIcsbbr876vv3LKm bg0w== 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=iK0cXAX0WIKgeX1/eUGGaXIoaF0/R0ECoYm9M+roBheXNRDS5pBLzDgJwrbk0YjbGq MeCq/IUY/P1tj40LYp4BT2+pqmnQmEtl0ZQ+vV39yLx/KWGpOAJcAfpnjRSWCfdlZBX9 Dz4dFwgPBJD4eAcGVn+OWGEyd+B+sJHovG/3CVyVEzLK5uEffJiNUhgOGayCOke3SLR0 WlXJkxzlI4FXL7PrE0V6bzoK96vtpXajjZOv+ZqnA0fNIL4GNWCAa26KoF5xzdcWE/n9 r3GQcW7eYfD59gVTTECf4stpcQDRkIOTZ46kYb1jevhF6fmkD32owBEvFCYjM1Yp4Fxq txeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=PzVbaYsr; 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 dv22-20020a170906b81600b00992bd86ece6si11905118ejb.725.2023.08.03.07.24.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 07:24:54 -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=PzVbaYsr; 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 F310B38555B9 for ; Thu, 3 Aug 2023 14:23:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F310B38555B9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1691072633; 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=PzVbaYsrVth40ZpOlZ6nuGPnm1mSCv+DExR/BO8DGbpZnS5TSSuRKm+fY/Nu/evpd MQTTloSX3F3YuH2scC/Y7tnVEyu5YIWVGa8lyM4pHMQS9iN1gwBCYxXSYkcCRLA10s r0oTFdCfv8sP65tpTqwXaw96IGikCmNB8FDDPra8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by sourceware.org (Postfix) with ESMTPS id 7A4223858D35 for ; Thu, 3 Aug 2023 14:23:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7A4223858D35 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-3fbea14706eso10251675e9.2 for ; Thu, 03 Aug 2023 07:23:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691072582; x=1691677382; 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=PpGI1tRcqg3RuDXvgTVqtF3l7/ePuUT4LF+AUksgEA4xnspSx34hbcRY2ch4rz+hPv mTvOu4t7ZBF2pZIm3Y0KkpgVKR+FQUMo5Wb1978aHCzQfPS3UQavV4P8Od5Nzph1ddFJ FfEbXjetlpIgBJ8UJ0kR8oC8FljMNKuhnhU4vGAjguk7+E5ykahqs5w/QjcbdqpAwzDG fd+Qy6B5xl/1eIib+ok+tlYC0A4CbwnGY/xMCM3EWx9p5LNIKVkES2UHgmRR60fLXpOw AqYRfP2PxlDN3Hil1P1eihHdLclCTkZm5mCBwVmwXwvpRxwBGhh8xRPT3AR2/UJzIYna TUvA== X-Gm-Message-State: ABy/qLaTOfD2YmSTrG8zv8eFhQ6CPBhPnGQjk3V+xYqOF0jl4DsMQBwU lEhhfgDQc+WkUeWvbwo0fmijsQ/5zApUNZV8 X-Received: by 2002:a05:600c:3644:b0:3fb:b1af:a455 with SMTP id y4-20020a05600c364400b003fbb1afa455mr7023923wmq.5.1691072581686; Thu, 03 Aug 2023 07:23:01 -0700 (PDT) Received: from amwld-aturko1.us.drwholdings.com ([149.14.21.6]) by smtp.gmail.com with ESMTPSA id f9-20020a7bc8c9000000b003fba92fad35sm4371349wml.26.2023.08.03.07.23.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 07:23:01 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Andrzej Turko Subject: [PATCH 1/3 v3] Support get_or_insert in ordered_hash_map Date: Thu, 3 Aug 2023 16:21:29 +0200 Message-Id: <20230803142131.250087-2-andrzej.turko@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230803142131.250087-1-andrzej.turko@gmail.com> References: <20230803142131.250087-1-andrzej.turko@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.6 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: 1773218242538924711 X-GMAIL-MSGID: 1773218242538924711 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 Thu Aug 3 14:21:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Turko X-Patchwork-Id: 130659 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp1184858vqx; Thu, 3 Aug 2023 07:24:46 -0700 (PDT) X-Google-Smtp-Source: APBJJlEydxxGhUi7EyY3QBEBc/jid+ozBA2JcSQTTw2EbOWA7RHUChnm4qIkbVG+WD/fdqcxHENb X-Received: by 2002:a17:906:3088:b0:992:a85d:278b with SMTP id 8-20020a170906308800b00992a85d278bmr7855554ejv.59.1691072686734; Thu, 03 Aug 2023 07:24:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691072686; cv=none; d=google.com; s=arc-20160816; b=whwRaJq0CfOjF4XhBKRo309RJA/5razm6xeB4R3ZLzNtLey9WOYaRejIUul76ruPPJ 8eoo6k0bRqkfAikHbctWCxKNYMNTcuEZbUtWbedO6CrxOTwN6o2KyGPioWM/ZRBLfRmY oozGlmlEydSEvJunxR20l/mWPtXHy03dwxFb88BEpopT+jMxJ39joiKtqJb/EvFGvc89 7IMJDttbf0IEI1vU8rs+F5JIgwl6XW1JBONa9iB9dOl3ljrca1j42lIx/mIivjCslDfe hAzCip8Qnu9LqSlXxDWBr9qRI9iHsRUdY6I77fLyP55ngGhHzrYLrOYCUnNQv5PTw/Dg LkbQ== 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=XZbOKHYO90QJaXXnLW7onViWHp0FUHcOBh9zbAW18p0xwCUfe9YeHKqZA0W4ARfiXK n8PJNC4y/W4jXZzUnioLj50YSr0jh8ThAcdngDH1NnOXz50VLiD9T+oqR2cmV0yMPXwt P/6RF2XLgSRoYek8HSau3vrchDo8U6ua4atJu9Hqhrw5QztICynsM0+VRgQmtvpyRBLR pD44cWqO9wM6dfAOj89wsrFKhldpI2Dkf84OawJ/+6yjYDMJHFiOLEJW3/tV3wkG3quw wuVYeSlQT2zSaSWjIZjo7bYSNx9SqxKk1zUPmACkAAcqknWRnMhw3aVZeACtaQXhx5WR Cgpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=XWwd43yt; 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 o5-20020a17090608c500b009787b15aa51si366986eje.713.2023.08.03.07.24.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 07:24:46 -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=XWwd43yt; 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 42F1C3853570 for ; Thu, 3 Aug 2023 14:23:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 42F1C3853570 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1691072630; 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=XWwd43yti56RVsdDDyl7L/MVs6AlWmnip/g9N7Tf50D0Oa1rtnrOQlg3aXiOBOFSR BYsxuX+yUMwYagzjwBajjt5U4FZOw7hC80cgvWdqmWvioqiPVaHwTYoti3iu8U4clx 8cEgJPdDpdW6JdAyRvC+TZcVdql23jF/WgKOXt3Q= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by sourceware.org (Postfix) with ESMTPS id C13373858C5E for ; Thu, 3 Aug 2023 14:23:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C13373858C5E Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-3fba8e2aa52so10344055e9.1 for ; Thu, 03 Aug 2023 07:23:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691072582; x=1691677382; 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=ModKxJbrtdqVM4ncIPIbmPfzp3eZS3Z2JmpjwSjRkoNuDp2MGjBh974br0/5Yi5WUM EWYNchR+HiAdsKPosQxnzyVJcE7Ln/T+I/XizHjhhuH3E+/zsMDfaOaPbnzALEsR9WPe WESF3wMF7pD/A0kEtfSrWdL/iEGs9gw2H5cIeI8EZ1ITXncWnEGyNn6EpLaaWOv5V2Et 7sZGQ0L0JFC1S1rFHGtsDoTafL/ifamqrKkJX4LvsGkAFqEBk83IQUscRkiJlzxfzJEl +3N0ytB8/Hx4U8lRcmyWqFmdLqXmGIm2ql2QU5Ek8MoFkfciG5SftXRfN6rMf5QYaJdU VNkw== X-Gm-Message-State: ABy/qLbq2N4yKUzLzC7gDYbhu9gnp7JGmGjoVRkYJBzMnbX8jutwCDBc O++Vfl3Q1LehZrRSWGXB7m3ArLyKvFumpmOE X-Received: by 2002:a1c:7419:0:b0:3fb:e2af:49f6 with SMTP id p25-20020a1c7419000000b003fbe2af49f6mr6932498wmc.39.1691072582229; Thu, 03 Aug 2023 07:23:02 -0700 (PDT) Received: from amwld-aturko1.us.drwholdings.com ([149.14.21.6]) by smtp.gmail.com with ESMTPSA id f9-20020a7bc8c9000000b003fba92fad35sm4371349wml.26.2023.08.03.07.23.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 07:23:01 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Andrzej Turko Subject: [PATCH 2/3 v3] genmatch: Reduce variability of generated code Date: Thu, 3 Aug 2023 16:21:30 +0200 Message-Id: <20230803142131.250087-3-andrzej.turko@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230803142131.250087-1-andrzej.turko@gmail.com> References: <20230803142131.250087-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: 1773218233820113147 X-GMAIL-MSGID: 1773218233820113147 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 Thu Aug 3 14:21:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Turko X-Patchwork-Id: 130660 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp1184865vqx; Thu, 3 Aug 2023 07:24:47 -0700 (PDT) X-Google-Smtp-Source: APBJJlHRiA6adx4GgL1d51V9pYo9MrlbsO6UDwug4CjMyW5fzbMTfkY0QwPAAzumwDCFct80mHYA X-Received: by 2002:a19:5e5e:0:b0:4fe:c98:789a with SMTP id z30-20020a195e5e000000b004fe0c98789amr7117712lfi.37.1691072687154; Thu, 03 Aug 2023 07:24:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691072687; cv=none; d=google.com; s=arc-20160816; b=L2mf4aP1DfDnqD6Sy7FrzSnUKsI9lywFV4K4urMXi/3+izd1YdDLzc3qdKhFf3/+zM 1LomWGWCW+hHEWy5aop7BXXJu1IFsSpOSils2WEBMZY7JEilGySzcCxQBugWuagK1K5F XRrvua5nDSririQ3DoYuMNu9mzVCBy7WWhE9z0HntZjmMb7wS4VnM1sq6I8irGeI0Z6k CEY2rwZLzdZFOBMv8QW9idEsyQkbBxagCxNHVwACP4vm3APrVOBZW6XZJ7OjTT7wP9hQ bRabYAEYVCYR60i39rp9WkJI+buwhZKi4Kpx4CBrtsfhlkQA+I1ILNagvftqvDH8X6pT ci6w== 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=n6en8mIQb0HndDtZT/jm9hhKHfoMy24mJ+F+IAWQZow=; fh=k/nQU4IX+jAQueq710KA8dCAcoPPe4cl6LpGj9WeH7w=; b=aWA1GAw0rWQCzgzFdDAgmYJezSRJcl2ag/RddeM4gc2GJz+ZYCMvHawdiIzh8EaL2v dFs9v35MTWdY4+wPnc0b0/OaobEGDv2LgvBqxyZTLTVsSn7jguA5TkOoLCJTTaneBqpJ nWOUA8xGtW9EISx/zGE6DZGHlLKTxFfNHo2gyTQBqQRKSlZS1wUCkTxtzCGN3H5uEXST QdWhw0bb7ZwFibtZF7zAiRQhtkIThJDqBtXLrAsx2p8KVGr7XGgsXXlc9AuuWkmkC9Xe kykhOjp7Mt6sPi1D7Sm/vRHvhqX7kZOWHGgXxQkItK5NCUfOlcwa9DvB8pQ+4K3ZPl3V eWXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=SEdtVviO; 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 m17-20020a17090607d100b0099bcb907318si8551378ejc.351.2023.08.03.07.24.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 07:24: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=SEdtVviO; 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 70CBA3857342 for ; Thu, 3 Aug 2023 14:23:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 70CBA3857342 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1691072630; bh=n6en8mIQb0HndDtZT/jm9hhKHfoMy24mJ+F+IAWQZow=; 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=SEdtVviOuevjRgTsC8+2SA2g6zgOWy3nrrVf2TszHL4HFDChkOYDheIOb4+/SxOQa +jwQf8joFUAElbGEuGS5/sNa+dIJwdjOvJefVT4ySvbSm/ENXkjHM2ppM2cgb4/+xK SkAumS3oHH5D9VmNU2+XxZK3iXGFfadjJq07eyv8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by sourceware.org (Postfix) with ESMTPS id B08D43858C2A for ; Thu, 3 Aug 2023 14:23:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B08D43858C2A Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-3fe1d462762so10464425e9.0 for ; Thu, 03 Aug 2023 07:23:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691072583; x=1691677383; 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=n6en8mIQb0HndDtZT/jm9hhKHfoMy24mJ+F+IAWQZow=; b=V2WVylRWMQkm9BqUswCY1oHAZ1lws8w5H2P56wLpIJ1URJF0Keeofuyxba82OYHm41 GB9Of9K+Y6086c2W8oSFtckgtm1fy9fCB8yAadfadAZm+hB44VSv4UiMlZP6X3rRwJnK jD7hYi7hekJlcjafs5ubqMJ0os5w201crsTU5nZDRXUqz+mnwUsXzuBEPyTEWdnq2m55 D+0flzYwmSQPVAAdy8NcF5vrWngwj5VLP6Unt1UdqxJuCME5MDf2YVsY4khls42fh3Kc G5BhzmW+spTrYyjEc0SG/lwxf+ZdPTVq00Eorh1BKLDLN6GgIVvCZHftcRR8rA9OmrHQ 0h3A== X-Gm-Message-State: ABy/qLb93AFt2eeX6z7N/j3xm/ViBXrLcpsGeI7dlJAXwcO4vO9aWCM3 caHvUCByyl0AYXNIhQc2eho0E0BIZ/z0SiGL X-Received: by 2002:a05:600c:b43:b0:3fe:26bf:6601 with SMTP id k3-20020a05600c0b4300b003fe26bf6601mr7737800wmr.11.1691072582967; Thu, 03 Aug 2023 07:23:02 -0700 (PDT) Received: from amwld-aturko1.us.drwholdings.com ([149.14.21.6]) by smtp.gmail.com with ESMTPSA id f9-20020a7bc8c9000000b003fba92fad35sm4371349wml.26.2023.08.03.07.23.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 07:23:02 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Andrzej Turko Subject: [PATCH 3/3 v3] genmatch: Log line numbers indirectly Date: Thu, 3 Aug 2023 16:21:31 +0200 Message-Id: <20230803142131.250087-4-andrzej.turko@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230803142131.250087-1-andrzej.turko@gmail.com> References: <20230803142131.250087-1-andrzej.turko@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773218234079809354 X-GMAIL-MSGID: 1773218234079809354 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 | 89 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 74 insertions(+), 15 deletions(-) diff --git a/gcc/genmatch.cc b/gcc/genmatch.cc index 1deca505603..63d6ba6dab0 100644 --- a/gcc/genmatch.cc +++ b/gcc/genmatch.cc @@ -217,9 +217,57 @@ 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_dump_logs (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:%%d, %%s:%%d\\n\",\n"); + fprintf_indent (f, 10, "simplify ? \"Applying pattern\" : " + "\"Matching expression\", file1, " + "dbg_line_numbers[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 +287,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 +3431,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 +3579,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 +3670,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 +3725,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 +3793,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 +5502,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 +5516,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 +5559,8 @@ main (int argc, char **argv) dt.gen (parts, gimple); + define_dump_logs (gimple, choose_output (parts)); + for (FILE *f : parts) { fprintf (f, "#pragma GCC diagnostic pop\n");