From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 670EC3857C70 for ; Mon, 28 Sep 2020 04:49:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 670EC3857C70 Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-263-f5dB1pQdPCecGsL6IOumsQ-1; Mon, 28 Sep 2020 00:49:04 -0400 X-MC-Unique: f5dB1pQdPCecGsL6IOumsQ-1 Received: by mail-qk1-f198.google.com with SMTP id m203so6064254qke.16 for ; Sun, 27 Sep 2020 21:49:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=I3ar3H2TbypomMSsZqwuiOBhdoVW8o5qI4d2CEmIcLU=; b=imTY7ClB6PMHWLARz3g48X5lDa79IEznr3eGxDF69ZMTKtGuhTLJrtPGk1Mm+Pzdmn sV/7nL4PkxCtZAtRhfpqSJdG86XoWMtA6lAUdSkRZsxBensB/RAhQhx46dMDKv7YBTg/ KwMlJN99zPYXrdexlRTs/ON7CxU+y7Umpvs3C9imZNngwpuX7rWodY0gagtI6YUJUKab QOPgj6rs3Q3WA5CZjotYZiIrqrgJM7grerWyFMsXMCJiQGJJoQOTf1uEyHVgkjeKnr6a JID78FWYLKtMozYRHpGXNAp6+kH7YzjkiSshDqvl1wZxYGE2ZZNKv3nNkbLeURq/Yqs2 E7sA== X-Gm-Message-State: AOAM530yn2QcgSCJk/4Y1ISjliIIRYr4f8fJlh7xY1mWNzlaYzYFWDIX 7fM+eRXVMPFQAb+Neva1SmfpOzez4za8KoaKnjMY9WxAa6rNA5NrzyGNlEDN+0YSIvm+HDmennw NVyUPoGAyuYGdUOHfJQ== X-Received: by 2002:a37:ad08:: with SMTP id f8mr10229232qkm.207.1601268543550; Sun, 27 Sep 2020 21:49:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+p4rZX0kDQ9OMwp01ZQp7XkRrrTJq71Mj1mJnhXZl6KOyDcFjnSPukdtJ+w5V/nOMFR7K7g== X-Received: by 2002:a37:ad08:: with SMTP id f8mr10229223qkm.207.1601268543230; Sun, 27 Sep 2020 21:49:03 -0700 (PDT) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id k5sm7847916qkc.45.2020.09.27.21.49.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Sep 2020 21:49:02 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Patrick Palka Subject: [PATCH 4/4] libstdc++: Rearrange some range adaptors' data members Date: Mon, 28 Sep 2020 00:48:54 -0400 Message-Id: <20200928044854.46674-4-ppalka@redhat.com> X-Mailer: git-send-email 2.28.0.618.g9bc233ae1c In-Reply-To: <20200928044854.46674-1-ppalka@redhat.com> References: <20200928044854.46674-1-ppalka@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=unavailable autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Sep 2020 04:49:07 -0000 Since the standard range adaptors are specified to derive from the empty class view_base, making their first data member store the underlying view is suboptimal, for if the underlying view also derives from view_base then the two view_base subobjects will be adjacent, thus preventing the compiler from applying the empty base optimization to elide away the storage for these two empty bases. This patch improves the situation by declaring the _M_base data member last instead of first in each range adaptor that has more than one data member, so that the empty base optimization can apply more often. Tested on x86_64-pc-linux-gnu with and wihout -m32. libstdc++-v3/ChangeLog: * include/std/ranges (filter_view::_M_base): Declare this data member last. (transform_view::_M_base): Likewise. (take_view::_M_base): Likewise. (take_while_view::_M_base): Likewise. (drop_view::_M_base): Likewise. (drop_while_view::_M_base): Likewise. (join_view::_M_base): Likewise. (split_view::_M_base): Likewise. * testsuite/std/ranges/adaptors/sizeof.cc: Adjust expected sizes. --- libstdc++-v3/include/std/ranges | 17 ++++++++--------- .../testsuite/std/ranges/adaptors/sizeof.cc | 18 +++++++++--------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges index 964a2b616a6..6fd8a85c2bf 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -1250,9 +1250,9 @@ namespace views { return __y.__equal(__x); } }; - _Vp _M_base = _Vp(); [[no_unique_address]] __detail::__box<_Pred> _M_pred; [[no_unique_address]] __detail::_CachedPosition<_Vp> _M_cached_begin; + _Vp _M_base = _Vp(); public: filter_view() = default; @@ -1588,8 +1588,8 @@ namespace views friend _Sentinel; }; - _Vp _M_base = _Vp(); [[no_unique_address]] __detail::__box<_Fp> _M_fun; + _Vp _M_base = _Vp(); public: transform_view() = default; @@ -1695,8 +1695,8 @@ namespace views friend _Sentinel; }; - _Vp _M_base = _Vp(); range_difference_t<_Vp> _M_count = 0; + _Vp _M_base = _Vp(); public: take_view() = default; @@ -1842,8 +1842,8 @@ namespace views friend _Sentinel; }; - _Vp _M_base = _Vp(); [[no_unique_address]] __detail::__box<_Pred> _M_pred; + _Vp _M_base = _Vp(); public: take_while_view() = default; @@ -1902,8 +1902,8 @@ namespace views class drop_view : public view_interface> { private: - _Vp _M_base = _Vp(); range_difference_t<_Vp> _M_count = 0; + _Vp _M_base = _Vp(); // ranges::next(begin(base), count, end(base)) is O(1) if _Vp satisfies // both random_access_range and sized_range. Otherwise, cache its result. @@ -2002,9 +2002,9 @@ namespace views class drop_while_view : public view_interface> { private: - _Vp _M_base = _Vp(); [[no_unique_address]] __detail::__box<_Pred> _M_pred; [[no_unique_address]] __detail::_CachedPosition<_Vp> _M_cached_begin; + _Vp _M_base = _Vp(); public: drop_while_view() = default; @@ -2300,12 +2300,11 @@ namespace views friend _Sentinel; }; - _Vp _M_base = _Vp(); - // XXX: _M_inner is "present only when !is_reference_v<_InnerRange>" [[no_unique_address]] __detail::__maybe_present_t, views::all_t<_InnerRange>> _M_inner; + _Vp _M_base = _Vp(); public: join_view() = default; @@ -2680,8 +2679,8 @@ namespace views { ranges::iter_swap(__x._M_i_current(), __y._M_i_current()); } }; - _Vp _M_base = _Vp(); _Pattern _M_pattern = _Pattern(); + _Vp _M_base = _Vp(); // XXX: _M_current is "present only if !forward_range" [[no_unique_address]] diff --git a/libstdc++-v3/testsuite/std/ranges/adaptors/sizeof.cc b/libstdc++-v3/testsuite/std/ranges/adaptors/sizeof.cc index 5fb1ab7e4da..a7f622bb725 100644 --- a/libstdc++-v3/testsuite/std/ranges/adaptors/sizeof.cc +++ b/libstdc++-v3/testsuite/std/ranges/adaptors/sizeof.cc @@ -33,17 +33,17 @@ using V = ranges::subrange; constexpr auto ptr = sizeof(int*); static_assert(sizeof(V) == 2*ptr); -static_assert(sizeof(ranges::take_view) == 4*ptr); -static_assert(sizeof(ranges::drop_view) == 4*ptr); +static_assert(sizeof(ranges::take_view) == 3*ptr); +static_assert(sizeof(ranges::drop_view) == 3*ptr); -static_assert(sizeof(ranges::filter_view) == 5*ptr); -static_assert(sizeof(ranges::take_while_view) == 4*ptr); -static_assert(sizeof(ranges::drop_while_view) == 5*ptr); -static_assert(sizeof(ranges::transform_view) == 4*ptr); +static_assert(sizeof(ranges::filter_view) == 4*ptr); +static_assert(sizeof(ranges::take_while_view) == 3*ptr); +static_assert(sizeof(ranges::drop_while_view) == 4*ptr); +static_assert(sizeof(ranges::transform_view) == 3*ptr); -static_assert(sizeof(ranges::filter_view) == 4*ptr); +static_assert(sizeof(ranges::filter_view) == 3*ptr); static_assert(sizeof(ranges::take_while_view) == 3*ptr); -static_assert(sizeof(ranges::drop_while_view) == 4*ptr); +static_assert(sizeof(ranges::drop_while_view) == 3*ptr); static_assert(sizeof(ranges::transform_view) == 3*ptr); -static_assert(sizeof(ranges::split_view) == 5*ptr); +static_assert(sizeof(ranges::split_view) == 4*ptr); -- 2.28.0.618.g9bc233ae1c