From patchwork Thu Aug 29 15:58:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 96711 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C4C4F385EC29 for ; Thu, 29 Aug 2024 15:58:47 +0000 (GMT) X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 4FD4A385DDD2 for ; Thu, 29 Aug 2024 15:58:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4FD4A385DDD2 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4FD4A385DDD2 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724947122; cv=none; b=IPr6wBIuqRAj6IBj34a0fDjRIqEQ/VUAQIhsU5K2XWcGBS8qV+7h9e9QlD8uFoME8PV6WttrtVrcrtwbJLmd24JhPHPdk7Uw7K2OCugcQNpYngaGR6Z7RpqKov6TNajBN6Q6fDXN8CmyOJxd7U6ux8Y/18qHkgv01nlUfWIFXUo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724947122; c=relaxed/simple; bh=k3lVjVn8dbVWtsr/BVhrn9LIl2xX4hJDevcc8FhpCQs=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=fdyvBzyt2bYACk+uQseSDhn4F82RTAZWwqiTFzrF7hfrOmZrdhtk1U9pezPdDq9UOAaJUjsA0VNWCi4Wna2qS/sojCtdEkpMJWnB4cKMGTWRLJ3xNLI4hZw4PtLHXKy6EFh26Pv7cJEEMKtErBin+zV3cuZ46ZGorucHopuAgxc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724947120; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=klAlnB2juCRPIQfyfevylUbpfN4LPckKmEZXJSLNRH8=; b=EG6xPMjXqOuRlI4InMme4Q/NEuPe/J+xdmSw0/jJX49vEUnxy1xp4fC80UzkUbYW7Dx1o7 cNwNqfB6ISgbQQz3ij34zicGa/T7XBPtrC3jprU7fGkTMsPHQ6888SwwiLE0TuqnaSGRtX hI1ASAZaJ8ajZ3RuRX5hWcdu9R4jsPI= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-227-iwP2aFxfOomzzWZT2xhmuQ-1; Thu, 29 Aug 2024 11:58:38 -0400 X-MC-Unique: iwP2aFxfOomzzWZT2xhmuQ-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-6bf70b800e9so11935426d6.0 for ; Thu, 29 Aug 2024 08:58:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724947117; x=1725551917; h=mime-version:user-agent:message-id:in-reply-to:date:references :organization:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=klAlnB2juCRPIQfyfevylUbpfN4LPckKmEZXJSLNRH8=; b=LRt62DSEnfoAK+3r7JUhYSfU2Vt3SX1BuuyMt9HUJ/cWjAgcgA2/HK59xn6QBrziZs f8gL4oOX5Qp5QBz8Yb1Czk/ToNn7lhZExSasvCNIq52e0yy5oQwcWW5D+unZN4KumXIz hSIYiqYjSJ7jIp4eqUBWt7w+DMnQJmkeylGBMzfykVYOGPxzgS6EYCL9olI+FhEA9Zyn HjuChjHHZQbQpEVoVi9lo9KcqvwIRqB4Q0uK8K5vj6lwrU8iFDVlzkt3q6d7078PJUi0 eErmtbTc7cRwvaq2Vlg58eu+csf7DWcroAC17axhAMn1a+EV72olvyyuh3g3mYug3STg jmUQ== X-Gm-Message-State: AOJu0YxkQpqA+7a3JFhQJYxH8U9nTgtCAPjn1N+C2PX9o8Rzinupwp0h tZP0MYEnVj9OrFMBFjom9Cc65vCqkqLZ6zek5OvVw4V0yRmhjr9CegnwjGd8zmpjLQYrU9X7jxv vYgvHztVsa18NIItAJIWAd03tT6Y9NCJjGRYy0n7NZauBOZE2cMbfJOuVlIt/4t9NOw== X-Received: by 2002:a05:6214:18e7:b0:6c3:3f77:78ba with SMTP id 6a1803df08f44-6c33f77790amr24796656d6.47.1724947117028; Thu, 29 Aug 2024 08:58:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE/y9DPTijHO7kKdb5VTma06hLz6Oh3WHBDliZVr351ddDCl8emRHz3Tn2CMYm+lU7V1BeLcQ== X-Received: by 2002:a05:6214:18e7:b0:6c3:3f77:78ba with SMTP id 6a1803df08f44-6c33f77790amr24796486d6.47.1724947116620; Thu, 29 Aug 2024 08:58:36 -0700 (PDT) Received: from localhost (88-120-130-27.subs.proxad.net. [88.120.130.27]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6c340c967e3sm6327686d6.95.2024.08.29.08.58.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2024 08:58:36 -0700 (PDT) Received: by localhost (Postfix, from userid 1000) id B70B5503C602; Thu, 29 Aug 2024 17:58:34 +0200 (CEST) From: Dodji Seketeli To: dodji@redhat.com Cc: libabigail@sourceware.org Subject: [PATCH 08/27] ir: Cache the result of scope_decl::get_sorted_member_types Organization: Me, myself and I References: <20240829154711.1883174-1-dodji@redhat.com> X-Operating-System: AlmaLinux 9.4 X-URL: http://www.seketeli.net/~dodji Date: Thu, 29 Aug 2024 17:58:34 +0200 In-Reply-To: <20240829154711.1883174-1-dodji@redhat.com> (dodji@redhat.com's message of "Thu, 29 Aug 2024 17:46:29 +0200") Message-ID: <87bk1bmic5.fsf@seketeli.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.0 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_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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: libabigail@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Mailing list of the Libabigail project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libabigail-bounces~patchwork=sourceware.org@sourceware.org Hello, Speed up ABIXML emitting by caching the result of scope_decl::get_sorted_member_types when it's called on a canonicalized type. * include/abg-ir.h (environment::canonicalization_started): Define new member functions. * src/abg-ir-priv.h (environment::priv::canonicalization_started_): Define new data member. (canonicalize_types): Call environment::canonicalization_started(true) right before starting type canonicalization and call environment::canonicalization_started(false) right after type canonicalization is done. * src/abg-ir.cc (environment::canonicalization_started): Define new methods. (environment::canonicalization_is_done): Set the new canonicalization_started flag to false when the canonicalization is done. (scope_decl::priv::clear_sorted_member_types_cache_): Declare new data member. (scope_decl::{add_member_decl, insert_member_type}): If we are adding a type to the scope, then flag the scope as needing to clear the sorted member types cache. (scope_decl::get_sorted_member_types): If type canonicalization is not yet started, then the sorted member types cache needs to be cleared. If the sorted member types cache is to be cleared, then clear it. If the cache is empty, fill it. Then return the content of the cache. Signed-off-by: Dodji Seketeli --- include/abg-ir.h | 6 ++++++ src/abg-ir-priv.h | 13 +++++++++++- src/abg-ir.cc | 53 +++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 69 insertions(+), 3 deletions(-) diff --git a/include/abg-ir.h b/include/abg-ir.h index 001db6d0..b4fec6c5 100644 --- a/include/abg-ir.h +++ b/include/abg-ir.h @@ -185,6 +185,12 @@ public: void canonicalization_is_done(bool); + bool + canonicalization_started() const; + + void + canonicalization_started(bool); + bool decl_only_class_equals_definition() const; diff --git a/src/abg-ir-priv.h b/src/abg-ir-priv.h index a184b804..0a960885 100644 --- a/src/abg-ir-priv.h +++ b/src/abg-ir-priv.h @@ -619,6 +619,7 @@ struct environment::priv // read from abixml and the type-id string it corresponds to. unordered_map pointer_type_id_map_; #endif + bool canonicalization_started_; bool canonicalization_is_done_; bool decl_only_class_equals_definition_; bool use_enum_binary_only_equality_; @@ -646,7 +647,8 @@ struct environment::priv #endif priv() - : canonicalization_is_done_(), + : canonicalization_started_(), + canonicalization_is_done_(), decl_only_class_equals_definition_(false), use_enum_binary_only_equality_(true), allow_type_comparison_results_caching_(false), @@ -1464,6 +1466,12 @@ canonicalize_types(const input_iterator& begin, if (begin == end) return; + auto first_iter = begin; + auto first = deref(first_iter); + environment& env = const_cast(first->get_environment()); + + env.canonicalization_started(true); + int i; input_iterator t; // First, let's compute the canonical type of this type. @@ -1481,6 +1489,9 @@ canonicalize_types(const input_iterator& begin, canonicalize(deref(t)); } + + env.canonicalization_is_done(true); + } /// Hash and canonicalize a sequence of types. diff --git a/src/abg-ir.cc b/src/abg-ir.cc index abc1b145..9ff4d3eb 100644 --- a/src/abg-ir.cc +++ b/src/abg-ir.cc @@ -3336,7 +3336,29 @@ environment::canonicalization_is_done() const /// @param f the new value of the flag. void environment::canonicalization_is_done(bool f) -{priv_->canonicalization_is_done_ = f;} +{ + priv_->canonicalization_is_done_ = f; + if (priv_->canonicalization_is_done_) + canonicalization_started(false); +} + +/// Getter of a flag saying if the canonicalization process has +/// started or not. +/// +/// @return the flag saying if the canonicalization process has +/// started or not. +bool +environment::canonicalization_started() const +{return priv_->canonicalization_started_;} + +/// Setter of a flag saying if the canonicalization process has +/// started or not. +/// +/// @param f the new value of the flag saying if the canonicalization +/// process has started or not. +void +environment::canonicalization_started(bool f) +{priv_->canonicalization_started_ = f;} /// Getter of the "decl-only-class-equals-definition" flag. /// @@ -7522,6 +7544,7 @@ struct scope_decl::priv scopes member_scopes_; canonical_type_sptr_set_type canonical_types_; type_base_sptrs_type sorted_canonical_types_; + bool clear_sorted_member_types_cache_ = false; }; // end struct scope_decl::priv /// Constructor of the @ref scope_decl type. @@ -7758,7 +7781,10 @@ scope_decl::add_member_decl(const decl_base_sptr& member) member->set_scope(this); priv_->members_.push_back(member); if (is_type(member)) - priv_->member_types_.push_back(is_type(member)); + { + priv_->member_types_.push_back(is_type(member)); + priv_->clear_sorted_member_types_cache_ = true; + } if (scope_decl_sptr m = dynamic_pointer_cast(member)) priv_->member_scopes_.push_back(m); @@ -7810,6 +7836,7 @@ scope_decl::insert_member_type(type_base_sptr t, ABG_ASSERT(!has_scope(d)); priv_->member_types_.push_back(t); + priv_->clear_sorted_member_types_cache_= true; insert_member_decl(d, before); } @@ -7864,9 +7891,26 @@ scope_decl::remove_member_type(type_base_sptr t) const type_base_sptrs_type& scope_decl::get_sorted_member_types() const { + if (priv_->clear_sorted_member_types_cache_) + { + priv_->sorted_member_types_.clear(); + priv_->clear_sorted_member_types_cache_ = false; + } + if (priv_->sorted_member_types_.empty()) { + unordered_set canonical_pointer_types; for (auto t : get_member_types()) + { + if (is_non_canonicalized_type(t)) + priv_->sorted_member_types_.push_back(t); + else if (auto c = t->get_canonical_type()) + canonical_pointer_types.insert(c); + else + canonical_pointer_types.insert(t); + } + + for (auto t : canonical_pointer_types) priv_->sorted_member_types_.push_back(t); type_topo_comp comp; @@ -7874,6 +7918,11 @@ scope_decl::get_sorted_member_types() const priv_->sorted_member_types_.end(), comp); } + + const ir::environment& env = get_environment(); + if (!env.canonicalization_started() && !env.canonicalization_is_done()) + priv_->clear_sorted_member_types_cache_ = true; + return priv_->sorted_member_types_; }