From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id C82DA3846020 for ; Thu, 25 Feb 2021 09:41:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org C82DA3846020 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tdevries@suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id DC0C8ADDB; Thu, 25 Feb 2021 09:41:22 +0000 (UTC) Date: Thu, 25 Feb 2021 10:41:21 +0100 From: Tom de Vries To: dwz@sourceware.org, jakub@redhat.com, mark@klomp.org Subject: [committed] Factor out same_ref_cus_p and cnt_ref_cus Message-ID: <20210225094119.GA14493@delia.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: dwz@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Dwz mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Feb 2021 09:41:25 -0000 Hi, Factor out new functions same_ref_cus_p and cnt_ref_cus out of partition_dups_1. Performance tested with cc1, no regression found. Committed to trunk. Thanks, - Tom Factor out same_ref_cus_p and cnt_ref_cus 2021-02-25 Tom de Vries * dwz.c (same_ref_cus_p, cnt_ref_cus): New function, factored out of ... (partition_dups_1): ... here. --- dwz.c | 120 ++++++++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 73 insertions(+), 47 deletions(-) diff --git a/dwz.c b/dwz.c index 4067997..e71b3fa 100644 --- a/dwz.c +++ b/dwz.c @@ -7915,6 +7915,76 @@ nr_bytes_for (uint64_t val) return n; } +/* Return true if duplicate chains REF1 and REF2 have the same set of + referrer CUs. If so, return the number of unique referrer CUs + in *CNT. */ +static inline unsigned int FORCE_INLINE +same_ref_cus_p (dw_die_ref ref1, dw_die_ref ref2, size_t *cnt) +{ + dw_cu_ref last_cu1 = NULL, last_cu2 = NULL; + + *cnt = 0; + + if (odr_active_p && odr_mode != ODR_BASIC) + { + dw_die_ref orig_ref1 = ref1, orig_ref2 = ref2; + while (ref1 && die_odr_state (ref1) == ODR_DECL) + ref1 = ref1->die_nextdup; + if (ref1 == NULL) + ref1 = orig_ref1; + while (ref2 && die_odr_state (ref2) == ODR_DECL) + ref2 = ref2->die_nextdup; + if (ref2 == NULL) + ref2 = orig_ref2; + } + for (;; ref1 = ref1->die_nextdup, ref2 = ref2->die_nextdup) + { + dw_cu_ref ref1cu = NULL; + dw_cu_ref ref2cu = NULL; + + while (ref1 && (ref1cu = die_cu (ref1)) == last_cu1) + ref1 = ref1->die_nextdup; + while (ref2 && (ref2cu = die_cu (ref2)) == last_cu2) + ref2 = ref2->die_nextdup; + if (ref1 == NULL || ref2 == NULL) + break; + + last_cu1 = ref1cu; + last_cu2 = ref2cu; + + if (last_cu1 != last_cu2) + break; + else + (*cnt)++; + } + + if (ref1 || ref2) + return false; + + return true; +} + +/* Return the number of unique referrer CUs in duplicate chain REF. */ +static inline size_t FORCE_INLINE +cnt_ref_cus (dw_die_ref ref) +{ + dw_cu_ref last_cu1 = NULL; + size_t cnt = 0; + + for (;; ref = ref->die_nextdup) + { + dw_cu_ref refcu = NULL; + while (ref && (refcu = die_cu (ref)) == last_cu1) + ref = ref->die_nextdup; + if (ref == NULL) + break; + last_cu1 = refcu; + cnt++; + } + + return cnt; +} + /* Helper function of partition_dups_1. Decide what DIEs matching in multiple CUs might be worthwhile to be moved into partial units, construct those partial units. */ @@ -7938,59 +8008,15 @@ partition_dups_1 (dw_die_ref *arr, size_t vec_size, } for (j = i + 1; j < vec_size; j++) { - dw_die_ref ref1, ref2; - dw_cu_ref last_cu1 = NULL, last_cu2 = NULL; - size_t this_cnt = 0; - ref1 = arr[i]; - ref2 = arr[j]; - if (odr_active_p && odr_mode != ODR_BASIC) - { - while (ref1 && die_odr_state (ref1) == ODR_DECL) - ref1 = ref1->die_nextdup; - if (ref1 == NULL) - ref1 = arr[i]; - while (ref2 && die_odr_state (ref2) == ODR_DECL) - ref2 = ref2->die_nextdup; - if (ref2 == NULL) - ref2 = arr[j]; - } - for (;; ref1 = ref1->die_nextdup, ref2 = ref2->die_nextdup) - { - dw_cu_ref ref1cu = NULL; - dw_cu_ref ref2cu = NULL; - while (ref1 && (ref1cu = die_cu (ref1)) == last_cu1) - ref1 = ref1->die_nextdup; - while (ref2 && (ref2cu = die_cu (ref2)) == last_cu2) - ref2 = ref2->die_nextdup; - if (ref1 == NULL || ref2 == NULL) - break; - last_cu1 = ref1cu; - last_cu2 = ref2cu; - if (last_cu1 != last_cu2) - break; - else - this_cnt++; - } - if (ref1 || ref2) + size_t this_cnt; + if (!same_ref_cus_p (arr[i], arr[j], &this_cnt)) break; cnt = this_cnt; } if (stats_p && !second_phase) stats->part_cnt++; if (cnt == 0) - { - dw_cu_ref last_cu1 = NULL; - for (ref = arr[i];; ref = ref->die_nextdup) - { - dw_cu_ref refcu = NULL; - while (ref && (refcu = die_cu (ref)) == last_cu1) - ref = ref->die_nextdup; - if (ref == NULL) - break; - last_cu1 = refcu; - cnt++; - } - } + cnt = cnt_ref_cus (arr[i]); enum dwarf_source_language part_lang = gen_cu_p ? partition_lang (arr[i]) : 0; for (k = i; k < j; k++)