From patchwork Tue Nov 9 14:29:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Schwinge X-Patchwork-Id: 47287 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 DB3DC385840D for ; Tue, 9 Nov 2021 14:29:52 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa1.mentor.iphmx.com (esa1.mentor.iphmx.com [68.232.129.153]) by sourceware.org (Postfix) with ESMTPS id 953CE3858C60 for ; Tue, 9 Nov 2021 14:29:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 953CE3858C60 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com IronPort-SDR: 3cs6M8RUsEigDkWF9Z9PMJU9Gss7pvdyQucyPH7Zj0vsSz0shO80UZf1m0PKuEA0aJbRBKLxCc QIP64x6MKy+hld20ocBdQpffDmvlvx4CFlr6+NQ4wcw0fUhq8AcImz4HTLcY0p+mI+fbCs90KO UI0QO12I7NJxsjWU4Jh4yVHNaHqSRY3zS58xug6UmFMTJPF/jfYCnM/F9m2coe3mAB+YF6rwDg PW1RwNyUqOn4VVTrfZzmrZn1rHwepokcVjeajVciYJuM3ABtTSBieNqtvI/k+EiLYN55VfPqd/ R13zW+vYuPTId4r4KjPZVgur X-IronPort-AV: E=Sophos;i="5.87,220,1631606400"; d="scan'208,223";a="70724322" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa1.mentor.iphmx.com with ESMTP; 09 Nov 2021 06:29:35 -0800 IronPort-SDR: HF+2+iYi4QDh1ciDLG09fGs3U8Y5xtOZ350go4rtoGGxXn9sadhSjoO1k7V2HTXGWDOUhjbxYl BKBnbL+n3tynq2crbEbvpXJGC992s5l1Z8Ph1bno7biSwewIPjqYgFXP4v6yL9QkW+g19k5+UM 2Mu26VKOQk+/D2JuAB8204sUlS0EakAEcTCmClYA32OzyJdOncEuivs1KEGBqqEPqo/695Hq2X ruSEN70rE5tYCmFfTJTeK2rOfXTF9ypSK3tvSO25Tz8uLj7eFEOyS/mLSOwu+qV4XdnaFOAnMX eUQ= From: Thomas Schwinge To: Martin =?utf-8?b?TGnFoWth?= , Subject: Use 'location_hash' for 'seen_locations' in 'gcc/profile.c:branch_prob' (was: [PATCH] Fix GCOV CFG related issues) In-Reply-To: References: User-Agent: Notmuch/0.29.3+94~g74c3f1b (https://notmuchmail.org) Emacs/27.1 (x86_64-pc-linux-gnu) Date: Tue, 9 Nov 2021 15:29:27 +0100 Message-ID: <87fss5xv08.fsf@euler.schwinge.homeip.net> MIME-Version: 1.0 X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-09.mgc.mentorg.com (139.181.222.9) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_ASCII_DIVIDERS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: , Cc: Nathan Sidwell Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi! On 2018-07-25T15:40:24+0200, Martin Liška wrote: > --- a/gcc/profile.c > +++ b/gcc/profile.c > @@ -1256,6 +1256,8 @@ branch_prob (void) > /* Initialize the output. */ > output_location (NULL, 0, NULL, NULL); > > + hash_set > seen_locations; > + > FOR_EACH_BB_FN (bb, cfun) > { > gimple_stmt_iterator gsi; Given my recent commit 088199e5d0fc0d54f48af0783a2630a773bbb387 "Generalize 'gcc/input.h:struct location_hash'", OK to push the attached "Use 'location_hash' for 'seen_locations' in 'gcc/profile.c:branch_prob'"? Grüße Thomas > @@ -1263,8 +1265,9 @@ branch_prob (void) > > if (bb == ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb) > { > - expanded_location curr_location = > - expand_location (DECL_SOURCE_LOCATION (current_function_decl)); > + location_t loc = DECL_SOURCE_LOCATION (current_function_decl); > + seen_locations.add (loc); > + expanded_location curr_location = expand_location (loc); > output_location (curr_location.file, curr_location.line, > &offset, bb); > } > @@ -1272,17 +1275,25 @@ branch_prob (void) > for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) > { > gimple *stmt = gsi_stmt (gsi); > - if (!RESERVED_LOCATION_P (gimple_location (stmt))) > - output_location (gimple_filename (stmt), gimple_lineno (stmt), > - &offset, bb); > + location_t loc = gimple_location (stmt); > + if (!RESERVED_LOCATION_P (loc)) > + { > + seen_locations.add (loc); > + output_location (gimple_filename (stmt), gimple_lineno (stmt), > + &offset, bb); > + } > } > > - /* Notice GOTO expressions eliminated while constructing the CFG. */ > + /* Notice GOTO expressions eliminated while constructing the CFG. > + It's hard to distinguish such expression, but goto_locus should > + not be any of already seen location. */ > + location_t loc; > if (single_succ_p (bb) > - && !RESERVED_LOCATION_P (single_succ_edge (bb)->goto_locus)) > + && (loc = single_succ_edge (bb)->goto_locus) > + && !RESERVED_LOCATION_P (loc) > + && !seen_locations.contains (loc)) > { > - expanded_location curr_location > - = expand_location (single_succ_edge (bb)->goto_locus); > + expanded_location curr_location = expand_location (loc); > output_location (curr_location.file, curr_location.line, > &offset, bb); > } ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955 From 5d78a424466f3fc89f430c8b8282ce5820dffbe3 Mon Sep 17 00:00:00 2001 From: Thomas Schwinge Date: Tue, 31 Aug 2021 23:34:23 +0200 Subject: [PATCH] Use 'location_hash' for 'seen_locations' in 'gcc/profile.c:branch_prob' Follow-up to commit 102fcf94e625a2016a65829c73a42bd6c2420376 "Fix GCOV CFG related issues": considering the current 'int_hash ', per 'libcpp/include/line-map.h': Actual | Value | Meaning -----------+-------------------------------+------------------------------- 0x00000000 | UNKNOWN_LOCATION (gcc/input.h)| Unknown/invalid location. -----------+-------------------------------+------------------------------- 0x00000001 | BUILTINS_LOCATION | The location for declarations | (gcc/input.h) | in "" -----------+-------------------------------+------------------------------- 0x00000002 | RESERVED_LOCATION_COUNT | The first location to be | (also | handed out, and the | ordmap[0]->start_location) | first line in ordmap 0 ... this currently uses value '0' ('UNKNOWN_LOCATION') as spare values for 'Empty', and value '2' ('RESERVED_LOCATION_COUNT') as spare values for 'Deleted', which is questionable? What actually does get put into 'seen_locations' is (mostly...) restricted/gated by '!RESERVED_LOCATION_P' (which is true unless 'UNKNOWN_LOCATION' or 'BUILTINS_LOCATION'), thus we may simply use 'location_hash'. gcc/ * profile.c (branch_prob): Use 'location_hash' for 'seen_locations'. --- gcc/profile.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gcc/profile.c b/gcc/profile.c index c33c833167f..d07002d265e 100644 --- a/gcc/profile.c +++ b/gcc/profile.c @@ -1375,7 +1375,7 @@ branch_prob (bool thunk) /* Initialize the output. */ output_location (&streamed_locations, NULL, 0, NULL, NULL); - hash_set > seen_locations; + hash_set seen_locations; FOR_EACH_BB_FN (bb, cfun) { @@ -1385,6 +1385,7 @@ branch_prob (bool thunk) if (bb == ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb) { location_t loc = DECL_SOURCE_LOCATION (current_function_decl); + gcc_checking_assert (!RESERVED_LOCATION_P (loc)); seen_locations.add (loc); expanded_location curr_location = expand_location (loc); output_location (&streamed_locations, curr_location.file, -- 2.33.0