From patchwork Mon Aug 7 09:58:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Turko X-Patchwork-Id: 131778 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp1341985vqr; Mon, 7 Aug 2023 03:05:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGGbvsXv7yr8+Mpi/zNPqeBNMLQMUUSfnjQNpZS0atVbqQl4aSAssh08XDBsr28TG1aCwRo X-Received: by 2002:a17:906:519c:b0:99c:a23b:b4f4 with SMTP id y28-20020a170906519c00b0099ca23bb4f4mr8507492ejk.2.1691402726195; Mon, 07 Aug 2023 03:05:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691402726; cv=none; d=google.com; s=arc-20160816; b=W0speoOACxV3C9RLjFK6NN5Pq1nIjCpaiVVs/kJrRvUJcjd7Dh4Xc7Ugp3feneB86j UT4gTh2G/nwZj7tiaGLi3ptOZ78uA4SGVQogYmGMnAHMGLr6v6eg/eDeOHVZ1BVTliRo vaOFONDucVJJ39UCRXM124Iqa1XGo2yyNxVxipuawYcH3Cz4QKmx1drFmmbIhQLRQwVA 10YEpYSxGLlF26cm4TeWDw1XyOQgcpQaKq+wDkc8wC6t9vcxk4upn02LhQhNSNZnpZYl Is3yNUQWgX15+Rx2nvHxZMOX37sW2tlfAlmBkuJgL5Khn/BCr9FC6I4e1XTOUfGkTCnJ zaZw== 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=Yo2ByyRkNEaDu9X7hI9WCxKxqBIoNDutgIrFEk/DvWs=; b=ksE5xPKGwAoKTSRc0lYr8YZ2CaxWWOH6IEDiFWpbvRMkFuxV3BmDURY+x1gLkifoTY j3YqJS6Vn6UJPZV4Hihp9Q/s00L+Cz/Prz5yQgf3Z/qiDCgIWrv3GsUfxv5UgzFJTW3A tqY9/IqQaKONj7Cb5bK5AYmsTqChvUgba0D4Z12XvQ/zs/IT1drUfXUu+L/LPBNzdJwF C16ZyKyorGLf7CJURef4ajk9vHyhLnFgoqaACx1MUuWwyxsN9oXQxBlDMFSuApAo28mf ZTvQuXJVeUbdY+FLLNPfH1o4wRteJj8k34yWP6WPdRDHD7anf97fVpZDZtlTw/Xkw64r O0Bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Hz9Hfdp3; 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 o24-20020a1709064f9800b009930ef7f05dsi5021151eju.908.2023.08.07.03.05.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 03:05:26 -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=Hz9Hfdp3; 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 BB6E43855583 for ; Mon, 7 Aug 2023 10:04:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BB6E43855583 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1691402699; 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=Hz9Hfdp3NZDSmYRx8OPDxTWuAsHprDLKYKbNoqk6vTPpA10tebzpsBWFnc5TGpMwP a2FKBGzv89XFGmHnI+Jr6d/xPfaGI11zIylrJTkmy+0erySwCDtClWm/jyq8B3IgT+ zjuVwCfW1kWCL9w8P+BKjpmBMe+aCMb5jW4OsNNc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lj1-x22c.google.com (mail-lj1-x22c.google.com [IPv6:2a00:1450:4864:20::22c]) by sourceware.org (Postfix) with ESMTPS id AD2103858C39 for ; Mon, 7 Aug 2023 10:04:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AD2103858C39 Received: by mail-lj1-x22c.google.com with SMTP id 38308e7fff4ca-2b9db1de50cso65429011fa.3 for ; Mon, 07 Aug 2023 03:04:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691402644; x=1692007444; 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=Q4H5s6iu9Y1rfk0yeEvR8DZFgxSVNPDqi8wy3Bxi7QdE4k0F5x2NigjqdMeDiZA4Nc XynnszZf8X5E4Yxuj3e6SWAuTsckuAWfNuFSBp2yDSyKGpshhz7Zl21xQMZ2QfW5S+wG 3zKIqXHdz7MHNL3lxgM65EYMRDanGTZf3yx4Vm8YcrWobF9zFmdqX/DgiQTKfM2291Q1 hk6UUZs9ZPc2FfAHrxUvo1T859f4qujVkwP2hZ4sJpHD3etNUtgksWKvOmIMhtauM1uu q4gMamWC7/eQ989TCOzzjYf8NjuVHmNVKdpqq+xM2e5cAt6FjQWC41rJmWBJXNUGJyIU Mecw== X-Gm-Message-State: AOJu0YzO8uEEfioXcBV4XCCcnBnqB/5mR+CzEd4BEuY8JYT/BXFiJGdZ mXI8Aip67CGd3XefQO9VOHH2B07j0/FNU/IfoPg= X-Received: by 2002:a2e:88d6:0:b0:2b4:75f0:b9e9 with SMTP id a22-20020a2e88d6000000b002b475f0b9e9mr5792503ljk.10.1691402643502; Mon, 07 Aug 2023 03:04:03 -0700 (PDT) Received: from amwld-aturko1.us.drwholdings.com ([149.14.21.6]) by smtp.gmail.com with ESMTPSA id la4-20020a170906ad8400b0099bd682f317sm4881305ejb.206.2023.08.07.03.04.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 03:04:03 -0700 (PDT) To: gcc-patches@gcc.gnu.org, Richard Biener Cc: Andrzej Turko Subject: [PATCH 1/3 v4] Support get_or_insert in ordered_hash_map Date: Mon, 7 Aug 2023 11:58:59 +0200 Message-Id: <20230807095901.267099-2-andrzej.turko@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230807095901.267099-1-andrzej.turko@gmail.com> References: <20230807095901.267099-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 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: 1773564304882215908 X-GMAIL-MSGID: 1773564304882215908 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 Mon Aug 7 09:59:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Turko X-Patchwork-Id: 131780 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp1342534vqr; Mon, 7 Aug 2023 03:06:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHNHxXbWgK+lSyKbpLeVDbm4+GbPKKEwtCj6eL+RAiu16YyRp2+DHdxAnBsP+Opg6/2YjLl X-Received: by 2002:aa7:c7cf:0:b0:522:2ba9:6fce with SMTP id o15-20020aa7c7cf000000b005222ba96fcemr8177573eds.8.1691402795445; Mon, 07 Aug 2023 03:06:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691402795; cv=none; d=google.com; s=arc-20160816; b=lYnmvp4UScd6QJmtzCg+EtqaoOgRhsR0bKfExTA1Vo+UWKiDJFhBInkOMt0AXqC+r2 Ag8FCNUeRWtxeQeF7gEWBl5z6SsXzWOz6T0Dla7IgB34xFrMnBPqiolpNe0O3i/Avc+4 5vCEd/qwMB8ZJ1kCEgaW63fXVZrgeL+yLEJCZoOXFydiViJhg3NJ+xBVowPfcipF13lf 4vtN0289tl7WNLh+EvhnDXz6P0XAYHbim4NGD1ZHrxdQquZzejHOEkXX1RqCfKmWqiYK HtA7RNiVpE2Z0HV4FQTyIgs0i35jTMO3c0iSHniRzyOTqAPdEGTtA6QgNPM4Ek8envP3 uV6A== 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=Yo2ByyRkNEaDu9X7hI9WCxKxqBIoNDutgIrFEk/DvWs=; b=QFOjc5FKAQBbm9UZKnRLvuVemn54zjXBqcvSfkyI7KPczbHk1dQcHPk4pEYmkW9I3n rhZhSkPAF0cU4eIQ/bvKqzm6gyNynzZASpzmMB0XlExekSMpEr5sxciGN/2xPzBGYSWF sht0daUQzbhNP0eId/CNo4MKQNAVi3oqUtonoVwkBhooQVdtvdQEn2x+GkapboTF1i+A s0CBwrIfuuJUhWFnfGTZy3z/C1Vtjpo2BjxP2l/0AaBYeUNvxv0gkRAUgbY4ZPvNT64N NflG7j8xHQUmcQTrhnJ4C5wGho+B0FA5zFyWNP78Cw2T1oaCfAFjdFIYsFOYr2Fcuyrh ZVGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="JlG/uF/q"; 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 g25-20020a056402115900b005222d573a77si5670341edw.158.2023.08.07.03.06.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 03:06:35 -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="JlG/uF/q"; 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 269EA3857022 for ; Mon, 7 Aug 2023 10:05:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 269EA3857022 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1691402757; 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=JlG/uF/qzPcE5R9yDa9df7QlCjBjNxaHcHNGNqweChEDmwvl8+0sB+I3DtQWvEV+l MehhwmAG+3ELvqaiF2de2ijqUVSvHP6SlQqY9mNjz3q4bV0w2o/l01r5yup0H9lvH5 dA2wH1lvMTrIJb9k/Cb0kjssR0JTy8xvv97Tertk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [IPv6:2a00:1450:4864:20::22b]) by sourceware.org (Postfix) with ESMTPS id F39403858412 for ; Mon, 7 Aug 2023 10:04:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F39403858412 Received: by mail-lj1-x22b.google.com with SMTP id 38308e7fff4ca-2ba1e9b1fa9so43116471fa.3 for ; Mon, 07 Aug 2023 03:04:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691402644; x=1692007444; 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=TF3Crl00ljHV6fCePyG8IllrGLgHwX0YAwabP2XRJH/2ggP06rYFgIW4MfqrmA7a22 5AYEazfiRnRTW/39/Dsg0SnhK33T0m16ZLitLr+/BtmRQ6VK3wHZA8BUYsk1CR5FOt8a GF+CDV81El5wxhEAqXlKqwWVxhxpFVAkx7cVbQhm6+C+gW1ZF5ECObHK8/2K9GgjTWqb CxWLQ2UOtihGCLevK+AplpPJels47v3DZl6o0EiHuu021UK6eJ4ku97/1tVyWasWYFgw WTGbICZUBm4ZNoIGQ9Tt/zLHV/V4FSf6rgIdD/VPDoUjPyetYi72XULNGcZt2csB//qG 0Vpw== X-Gm-Message-State: AOJu0YwB+LXOooj36Efb7SR2zos6x8Bt33fpqLl9l+8WHTPtZzhvkyqi 4s697N9gBrjSRCLLNJYlcUKdBwtnp2BUZopcbkM= X-Received: by 2002:a2e:9f16:0:b0:2b9:eb0f:c733 with SMTP id u22-20020a2e9f16000000b002b9eb0fc733mr6751275ljk.35.1691402644096; Mon, 07 Aug 2023 03:04:04 -0700 (PDT) Received: from amwld-aturko1.us.drwholdings.com ([149.14.21.6]) by smtp.gmail.com with ESMTPSA id la4-20020a170906ad8400b0099bd682f317sm4881305ejb.206.2023.08.07.03.04.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 03:04:03 -0700 (PDT) To: gcc-patches@gcc.gnu.org, Richard Biener Cc: Andrzej Turko Subject: [PATCH 2/3 v4] genmatch: Reduce variability of generated code Date: Mon, 7 Aug 2023 11:59:00 +0200 Message-Id: <20230807095901.267099-3-andrzej.turko@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230807095901.267099-1-andrzej.turko@gmail.com> References: <20230807095901.267099-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 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: 1773564377680953826 X-GMAIL-MSGID: 1773564377680953826 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 Mon Aug 7 09:59:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Turko X-Patchwork-Id: 131779 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp1342252vqr; Mon, 7 Aug 2023 03:06:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFRVF0X1kCag7uod2UmilwkkDjVbvKeQbFGKOBADj5OYxc+R+haKoC6OuAzzyLZIjq1VMeU X-Received: by 2002:a17:906:104e:b0:99b:f50b:d7d5 with SMTP id j14-20020a170906104e00b0099bf50bd7d5mr8642586ejj.44.1691402762035; Mon, 07 Aug 2023 03:06:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691402762; cv=none; d=google.com; s=arc-20160816; b=P+rjM7rxfMC6Y4+j8Imqap7LA/wX54UhkAwHnl7jqlI7+x5wIMjdGpejh0tKidHwNA NpSrRhv2Ap5FGFzpl7Ah+2ZJvBWtqHtF3kqliqJORdu70LWMe0CS9xWAGhhpg47GCOMD EwLq+REE4EDHYyDsxG1SCtQUE1Go1y57QUKCFv4e969RPyi5Er+c9TjJAj22hfUjNQlF EI8YG/1YvhcmrkM7CocGzMFaTdy7oZApPr5ryExWE15HkRthNx32ToyNGAE8CleXihDN FhZ54ar0Oa4mj7dNNbMARAj6JU+IAXXLKvyeLMCPwJEuzTU5eAtTvIrBNlLDoJmtihHG sVCQ== 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=H7LJPb9v10UvTF/fKVJElHK2/J+vCc9iXs5aEhS1cd8=; fh=Yo2ByyRkNEaDu9X7hI9WCxKxqBIoNDutgIrFEk/DvWs=; b=SdM33tDGqZEmGnSzM0Zh6x3gADPSwJTF/RxAIWVtLwU+DyXF8fvVbDLHoFHNyH7G7d fqd3yo50Ydl9WdS4vrnBdPnYKBHsTt8TSMlY0TR1aYLg1TWC3UcFRro21Yg00YbHwOA0 pBVCx3FuVsTl7iOSRauXgTnxZIcfs++hTC0IBhqAlK2vE1fVlPgfmyzNdplmWKWmfEL1 eXnCpmb8B/h8302z+qe+E3tjZdNDyQY6IihiHtOSMtNGzvzkFf7Z6BM/HWB6AUqtZzgv mMnj9IGD//voKeRgXJoHdHv6omYW96RgejC33zaOnu5ILFDhhqP7TRNCkrEVf/KLkPrT +gMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=eE09K2HL; 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 bi1-20020a170906a24100b0099bd7b2663dsi4582331ejb.142.2023.08.07.03.06.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 03:06:02 -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=eE09K2HL; 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 A4E943857016 for ; Mon, 7 Aug 2023 10:05:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A4E943857016 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1691402721; bh=H7LJPb9v10UvTF/fKVJElHK2/J+vCc9iXs5aEhS1cd8=; 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=eE09K2HL9LYpaII/dHyQtNhnZTsmNI0qFh1Ejt7M8qlFb8wkCmeYX5QliUEuJvPpU xLIOjNymkMKCdNImCS0GjT6MnRYPO5gDMYAohdPzM2jUXiHLeeLfycl48sKyGvQ/6R hS3uphSTNhMdHeo4tRSyyukfj5LhHS6EOb02Hzuo= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by sourceware.org (Postfix) with ESMTPS id 911173858417 for ; Mon, 7 Aug 2023 10:04:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 911173858417 Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-99bcf2de59cso634910866b.0 for ; Mon, 07 Aug 2023 03:04:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691402645; x=1692007445; 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=H7LJPb9v10UvTF/fKVJElHK2/J+vCc9iXs5aEhS1cd8=; b=fZ6ry8gx3/IY3/9IChAXsDKgzck0Tt+UGSVGdYQdkU7Yc0fHnWQ68yNnkVb18LXymx yF0yDbkHCzDvLzNqw5yy+pS+z8X1PLWAtI39uYTh6hE0yxZ6aQ66oYYl4b3evi4bQvh6 elSqjFmowgGSIQ56jRIRCW4c7z0+QrGqrY55+fbyPU3sqG+QpuyaiSc7KvV9kTMKIAY4 tZ326FO8yGfe2zzH58O7EB7HUKhedHeaFxaYNzldQkSy/7jcZPtHPPkOBduasoJ4UcEu w2VC74zbks/n/fBGOUc3x1v2brDU3CkpDOFzr1DDViTqvUTzBEoEilfQSPSGjyT0ejeZ DKlA== X-Gm-Message-State: AOJu0YyfM6supe1mAACijwp3RDmW+zpXq2lrfQ+/WjlvO7qCFV68lKPU SZx4o1GnwEE0uB1DCO5bMfGHZUdsidVl+1hmDZU= X-Received: by 2002:a17:907:7857:b0:99c:7551:933e with SMTP id lb23-20020a170907785700b0099c7551933emr7883284ejc.64.1691402644681; Mon, 07 Aug 2023 03:04:04 -0700 (PDT) Received: from amwld-aturko1.us.drwholdings.com ([149.14.21.6]) by smtp.gmail.com with ESMTPSA id la4-20020a170906ad8400b0099bd682f317sm4881305ejb.206.2023.08.07.03.04.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 03:04:04 -0700 (PDT) To: gcc-patches@gcc.gnu.org, Richard Biener Cc: Andrzej Turko Subject: [PATCH 3/3 v4] genmatch: Log line numbers indirectly Date: Mon, 7 Aug 2023 11:59:01 +0200 Message-Id: <20230807095901.267099-4-andrzej.turko@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230807095901.267099-1-andrzej.turko@gmail.com> References: <20230807095901.267099-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 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: 1773564342764991806 X-GMAIL-MSGID: 1773564342764991806 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 | 95 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 80 insertions(+), 15 deletions(-) diff --git a/gcc/genmatch.cc b/gcc/genmatch.cc index 1deca505603..f46d2e1520d 100644 --- a/gcc/genmatch.cc +++ b/gcc/genmatch.cc @@ -217,10 +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_dump_logs (bool gimple, FILE *f) +{ + if (dbg_line_numbers.is_empty ()) + 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 (unsigned i = 0; i < 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) { + typedef pair_hash> location_hash; + static hash_map loc_id_map; const line_map_ordinary *map; linemap_resolve_location (line_table, location, LRK_SPELLING_LOCATION, &map); expanded_location loc = linemap_expand_location (line_table, map, location); @@ -239,7 +285,23 @@ output_line_directive (FILE *f, location_t location, ++file; if (fnargs) - fprintf (f, "\"%s\", %d", file, loc.line); + { + if (indirect_line_numbers) + { + bool existed; + int &loc_id = loc_id_map.get_or_insert ( + std::make_pair (file, loc.line), &existed); + if (!existed) + { + loc_id = dbg_line_numbers.length (); + dbg_line_numbers.safe_push (loc.line); + } + + fprintf (f, "\"%s\", %d", file, loc_id); + } + else + fprintf (f, "\"%s\", %d", file, loc.line); + } else fprintf (f, "%s:%d", file, loc.line); } @@ -3375,20 +3437,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 +3585,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 +3676,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 +3731,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 +3799,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 +5508,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 +5522,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 +5565,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");