From patchwork Mon Feb 12 21:33:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 85637 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 1A5883858C52 for ; Mon, 12 Feb 2024 21:33:30 +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.133.124]) by sourceware.org (Postfix) with ESMTPS id 9BEF13858C2C for ; Mon, 12 Feb 2024 21:33:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9BEF13858C2C 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 9BEF13858C2C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707773604; cv=none; b=EDavTjsziKYFcso6S1kwDCiglFeNaeQzdMVtkQTWEiv0bHjYVkTuDpqHLno5IIQ+y+jEoco1PvMVVSBlVCmLvabus6Gw9bzfB+6ZgX0ZaekReA4ll/XiBRds0z7IapTD99qVM2e+28KNU2BOfVMMaNpPnqXlvjPw0wbae02+bvk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707773604; c=relaxed/simple; bh=+e66H1kzNcRjc780U5E9gVjpfbsPTp0AG8qV3tZni2Q=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=l0uJRXtitiqHhAFNLmlDhEsgcFOMb4PD3b4WH9PkQJwLPmLrWr09Q77dtedKSguCMGRpccd1JiYsZIiQohFF3tauLyGe2c7ntc+obyaUd8nmjTj9guJ/FyVDyBTeYVQiBw1pBzOMRTp9q+L2zPeNzyl5fP9HApVmRbJjD9nauQE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707773602; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=XkMgmzgB9fpcO7QY1Z6ac9L3Vd94ubNHGEsI4knuhQY=; b=Y/nR5UUicXkhPQBK+DMyChJ8iGldpNengDz9pdBbkydn+R+cQmT29QRf1fNcfD6SWKx+W2 u9piZVQtmoknHfSuddO74Yt9P6lOKrWhGJB8VlctCaS+1lfPWp+4ro3+Ubu/7ctDdLAOVo dT+piVk+9vdurOaJ8+MhStonaTHYr2s= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-640-1_LquVhqNriJnjdNQdJTdA-1; Mon, 12 Feb 2024 16:33:21 -0500 X-MC-Unique: 1_LquVhqNriJnjdNQdJTdA-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-783f4a68727so720087985a.0 for ; Mon, 12 Feb 2024 13:33:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707773600; x=1708378400; h=mime-version:user-agent:message-id:date:organization:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=XkMgmzgB9fpcO7QY1Z6ac9L3Vd94ubNHGEsI4knuhQY=; b=pzwq15FJJvhYkbcVci/jPhl+MsDf1hZ1N7MLJEzffz+vYjtie+rEUtw6UHb/41GiJ7 vMUatd2Qv8TMFOldhz9FgtjgLRBU3tyhTtULQNh3MMtxgjEhYuGJ5pP1Q7UkL1T2RxI5 Z5+VI2cLDmAuaAspjBmw2zm0Av1pXwyS/PxwiQX7XJISsH6hfqcRpAR8SZIN7glaRF0k wQ3z5BU5wHecZA9XVXcyOX14xa4eaQ81pLRaKH+o22WJlPqswF83RXw5SYUBA0Yk1V6N clQ+dN7Q5yIjAE1Y0ZV2mlZmuXayLi3dUBwEQPlXW0R/bwlPSK0+iddVrBWekcRTDIxT 93Xg== X-Gm-Message-State: AOJu0YwwbQq2rfreXLy4Ag4rwzPdujNFrvISFRaSXpS25+xYAyMucSLI kCfIFpo3orH92BiUkwIRurC95XiRrjrVrp/Lmn78MVu5B5pFwksH+r6ymur3dsUP4bItC6hmSSk eIWCXu6KV9Yoi2o7oYdnRpEVx6je/0reYUDK1kz14goIM4lI7/l8ueKdIbA== X-Received: by 2002:a05:620a:102b:b0:785:d739:1d10 with SMTP id a11-20020a05620a102b00b00785d7391d10mr1251911qkk.38.1707773600545; Mon, 12 Feb 2024 13:33:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IGRHfIxNwJEuY3ogNC/y1bHXwtMRZ8zSftxayKTBinj3JhOuIZ2FYpXA7AhTWmTnvCo2c+KXQ== X-Received: by 2002:a05:620a:102b:b0:785:d739:1d10 with SMTP id a11-20020a05620a102b00b00785d7391d10mr1251884qkk.38.1707773600103; Mon, 12 Feb 2024 13:33:20 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUi1xS5UdJuO8aM5K2IkFVVU7Xt+4YXZPh8/7Ba/nFotSp6GfYPqQOhKpL52TVCSF/+qKBKgEtlULWI7FShuk1n Received: from localhost (88-120-130-27.subs.proxad.net. [88.120.130.27]) by smtp.gmail.com with ESMTPSA id vq27-20020a05620a559b00b00785d997cb29sm848792qkn.50.2024.02.12.13.33.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 13:33:19 -0800 (PST) Received: by localhost (Postfix, from userid 1000) id E8042B4FCA; Mon, 12 Feb 2024 22:33:17 +0100 (CET) From: Dodji Seketeli To: libabigail@sourceware.org Subject: [PATCH, applying to mainline] dwarf-reader,corpus: Use interned string to lookup corpus interfaces by ID. Organization: Red Hat / France X-Operating-System: CentOS Stream release 9 X-URL: http://www.redhat.com Date: Mon, 12 Feb 2024 22:33:17 +0100 Message-ID: <87il2txt9e.fsf@redhat.com> 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.4 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_H4, 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, This patch speeds up the lookup of a function or variable using the function/variable ID. This patch is in preparation of many more function lookup made during ABIXML emitting by patches coming up in the future. * include/abg-corpus.h (corpus::lookup_functions): Take an interned_string instead of an std::string. Add an overload for const char* string too, for debugging purposes. * src/abg-corpus-priv.h (istr_fn_ptr_set_map_type) (istr_var_ptr_map_type): Define new typedefs. (corpus::exported_decls_builder::priv::{id_fns_map_, id_var_map_}): Use the new istr_fn_ptr_set_map_type and istr_var_ptr_map_type types for these data members. (corpus::exported_decls_builder::priv::{id_fns_map, id_var_map, add_fn_to_id_fns_map, var_id_is_in_id_var_map, add_var_to_map, add_var_to_exported}): Adjust. (corpus::priv::lookup_functions): Declare new member function. * src/abg-corpus.cc (corpus::exported_decls_builder::maybe_add_var_to_exported_vars): Adjust. (corpus::priv::lookup_functions): Define new member function. The code here comes from the code that was in corpus::lookup_functions. This is a factorization of corpus::lookup_functions. (corpus::lookup_functions): Take an interned_string instead of the previous. Factorize the code that was here into the new corpus::priv::lookup_functions. * src/abg-dwarf-reader.cc (reader::symbol_already_belongs_to_a_function): Adjust the call to corpus::lookup_functions to use an interned_string. Signed-off-by: Dodji Seketeli Applying to the master branch. --- include/abg-corpus.h | 5 ++++- src/abg-corpus-priv.h | 48 +++++++++++++++++++++++++++-------------- src/abg-corpus.cc | 48 ++++++++++++++++++++++++++++++++++------- src/abg-dwarf-reader.cc | 2 +- 4 files changed, 77 insertions(+), 26 deletions(-) diff --git a/include/abg-corpus.h b/include/abg-corpus.h index 6de251de..aafa3a1f 100644 --- a/include/abg-corpus.h +++ b/include/abg-corpus.h @@ -219,7 +219,10 @@ public: get_functions() const; const std::unordered_set* - lookup_functions(const string& id) const; + lookup_functions(const interned_string& id) const; + + const std::unordered_set* + lookup_functions(const char* id) const; void sort_functions(); diff --git a/src/abg-corpus-priv.h b/src/abg-corpus-priv.h index 412db377..6908142e 100644 --- a/src/abg-corpus-priv.h +++ b/src/abg-corpus-priv.h @@ -19,6 +19,7 @@ #include "abg-regex.h" #include "abg-sptr-utils.h" #include "abg-symtab-reader.h" +#include "abg-interned-str.h" namespace abigail { @@ -46,10 +47,22 @@ typedef unordered_map > str_fn_ptrs_map_type; typedef unordered_map > str_fn_ptr_set_map_type; +/// Convenience typedef for a hash map which key is an interned_string +/// and which data is a set of abigail::ir::function_decl* +typedef unordered_map, + hash_interned_string> istr_fn_ptr_set_map_type; + /// Convenience typedef for a hash map which key is a string and /// which data is an abigail::ir::var_decl*. typedef unordered_map str_var_ptr_map_type; +/// Convenience typedef for a hash map which key is an interned_string +/// and which data is an abigail::ir::var_decl*. +typedef unordered_map istr_var_ptr_map_type; + /// The type of the private data of @ref /// corpus::exported_decls_builder type. class corpus::exported_decls_builder::priv @@ -69,8 +82,8 @@ class corpus::exported_decls_builder::priv // template parameters of the second instantiation are just typedefs // of the first instantiation, for instance. So there can be cases // where one ID appertains to more than one function. - str_fn_ptr_set_map_type id_fns_map_; - str_var_ptr_map_type id_var_map_; + istr_fn_ptr_set_map_type id_fns_map_; + istr_var_ptr_map_type id_var_map_; strings_type& fns_suppress_regexps_; regex_t_sptrs_type compiled_fns_suppress_regexp_; strings_type& vars_suppress_regexps_; @@ -203,7 +216,7 @@ public: /// /// @return a map which key is a string and which data is a pointer /// to a function. - const str_fn_ptr_set_map_type& + const istr_fn_ptr_set_map_type& id_fns_map() const {return id_fns_map_;} @@ -216,7 +229,7 @@ public: /// /// @return a map which key is a string and which data is a pointer /// to a function. - str_fn_ptr_set_map_type& + istr_fn_ptr_set_map_type& id_fns_map() {return id_fns_map_;} @@ -229,7 +242,7 @@ public: /// /// @return a map which key is a string and which data is a pointer /// to a function. - const str_var_ptr_map_type& + const istr_var_ptr_map_type& id_var_map() const {return id_var_map_;} @@ -242,7 +255,7 @@ public: /// /// @return a map which key is a string and which data is a pointer /// to a function. - str_var_ptr_map_type& + istr_var_ptr_map_type& id_var_map() {return id_var_map_;} @@ -274,10 +287,10 @@ public: /// @return the pointer to the vector of functions with ID @p fn_id, /// or nil if no function with that ID exists. std::unordered_set* - fn_id_is_in_id_fns_map(const string& fn_id) + fn_id_is_in_id_fns_map(const interned_string& fn_id) { - str_fn_ptr_set_map_type& m = id_fns_map(); - str_fn_ptr_set_map_type::iterator i = m.find(fn_id); + istr_fn_ptr_set_map_type& m = id_fns_map(); + auto i = m.find(fn_id); if (i == m.end()) return 0; return &i->second; @@ -295,7 +308,7 @@ public: std::unordered_set* fn_id_is_in_id_fns_map(const function_decl* fn) { - string fn_id = fn->get_id(); + interned_string fn_id = fn->get_id(); return fn_id_is_in_id_fns_map(fn_id); } @@ -389,7 +402,7 @@ public: return; // First associate the function id to the function. - string fn_id = fn->get_id(); + interned_string fn_id = fn->get_id(); std::unordered_set* fns = fn_id_is_in_id_fns_map(fn_id); if (!fns) fns = &(id_fns_map()[fn_id] = std::unordered_set()); @@ -424,10 +437,10 @@ public: /// @return true iff the variable designated by @p fn_id is present /// in the set of exported variables. bool - var_id_is_in_id_var_map(const string& var_id) const + var_id_is_in_id_var_map(const interned_string& var_id) const { - const str_var_ptr_map_type& m = id_var_map(); - str_var_ptr_map_type::const_iterator i = m.find(var_id); + const istr_var_ptr_map_type& m = id_var_map(); + auto i = m.find(var_id); return i != m.end(); } @@ -440,7 +453,7 @@ public: { if (var) { - const string& var_id = get_id(*var); + const interned_string& var_id = get_id(*var); id_var_map()[var_id] = var; } } @@ -464,7 +477,7 @@ public: void add_var_to_exported(const var_decl* var) { - const string& id = get_id(*var); + const interned_string& id = get_id(*var); if (!var_id_is_in_id_var_map(id)) { vars_.push_back(const_cast(var)); @@ -813,6 +826,9 @@ public: unordered_set* get_public_types_pretty_representations(); + std::unordered_set* + lookup_functions(const interned_string& id); + ~priv(); }; // end struct corpus::priv diff --git a/src/abg-corpus.cc b/src/abg-corpus.cc index 4a4cb8bc..2a904079 100644 --- a/src/abg-corpus.cc +++ b/src/abg-corpus.cc @@ -184,7 +184,7 @@ corpus::exported_decls_builder::maybe_add_var_to_exported_vars(const var_decl* v if (!var->get_is_in_public_symbol_table()) return; - const string& var_id = priv_->get_id(*var); + const interned_string& var_id = priv_->get_id(*var); ABG_ASSERT(!var_id.empty()); if (priv_->var_id_is_in_id_var_map(var_id)) @@ -630,6 +630,34 @@ corpus::priv::get_public_types_pretty_representations() return pub_type_pretty_reprs_; } +/// Lookup the function which has a given function ID. +/// +/// Note that there can have been several functions with the same ID. +/// This is because debug info can declare the same function in +/// several different translation units. Normally, all these function +/// should be equal. But still, this function returns all these +/// functions. +/// +/// @param id the ID of the function to lookup. This ID must be +/// either the result of invoking function::get_id() of +/// elf_symbol::get_id_string(). +/// +/// @return the set of functions which ID is @p id, or nil if no +/// function with that ID was found. +std::unordered_set* +corpus::priv::lookup_functions(const interned_string& id) +{ + exported_decls_builder_sptr &b = exported_decls_builder; + if (b) + { + auto i = b->priv_->id_fns_map_.find(id); + if (i == b->priv_->id_fns_map_.end()) + return 0; + return &i->second; + } + return nullptr; +} + /// Destructor of the @ref corpus::priv type. corpus::priv::~priv() { @@ -1335,16 +1363,20 @@ corpus::get_functions() const /// either the result of invoking function::get_id() of /// elf_symbol::get_id_string(). /// -/// @return the vector functions which ID is @p id, or nil if no +/// @return the set of functions which ID is @p id, or nil if no /// function with that ID was found. const std::unordered_set* -corpus::lookup_functions(const string& id) const +corpus::lookup_functions(const interned_string& id) const +{return priv_->lookup_functions(id);} + +const std::unordered_set* +corpus::lookup_functions(const char* id) const { - exported_decls_builder_sptr b = get_exported_decls_builder(); - auto i = b->priv_->id_fns_map_.find(id); - if (i == b->priv_->id_fns_map_.end()) - return 0; - return &i->second; + if (!id) + return nullptr; + + interned_string string_id = priv_->env.intern(id); + return lookup_functions(string_id); } /// Sort the set of functions exported by this corpus. diff --git a/src/abg-dwarf-reader.cc b/src/abg-dwarf-reader.cc index dc491b93..36c8eea6 100644 --- a/src/abg-dwarf-reader.cc +++ b/src/abg-dwarf-reader.cc @@ -4486,7 +4486,7 @@ public: if (!corp) return false; - string id = fn->get_id_string(); + interned_string id = corp->get_environment().intern(fn->get_id_string()); const std::unordered_set *fns = corp->lookup_functions(id); if (!fns)