From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7840) id EB40C3858CDA; Fri, 7 Oct 2022 20:06:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EB40C3858CDA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665173207; bh=jVOU/86p8Z+W4uCCI/Pu6VIWonocZTmQZhHJHMWVCfY=; h=From:To:Subject:Date:From; b=O1mc2eLKsQPtHv8qQNsQ0ARqaD+kIr1kKQ9kJK6V59AOhS9Iwi3dVSzs5iNvCBc4L byjmYpdX46qZ9EhYMRBLSwwX7+SpXS0R+DzpQvGclKoFNs/9CrjZwzyZp7QeZSo1tW zhN4W+gCQK7FgJ8n/9W6eRnN16ZlmiqRUE25YH1w= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Eugene Rozenfeld To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-3172] Set discriminators for call stmts on the same line within the same basic block. X-Act-Checkin: gcc X-Git-Author: Eugene Rozenfeld X-Git-Refname: refs/heads/master X-Git-Oldrev: b9ad850e86b863c24f6f4f5acf08d49944cc7bbe X-Git-Newrev: f30e9fd33e56a5a721346ea6140722e1b193db42 Message-Id: <20221007200647.EB40C3858CDA@sourceware.org> Date: Fri, 7 Oct 2022 20:06:46 +0000 (GMT) List-Id: https://gcc.gnu.org/g:f30e9fd33e56a5a721346ea6140722e1b193db42 commit r13-3172-gf30e9fd33e56a5a721346ea6140722e1b193db42 Author: Eugene Rozenfeld Date: Thu Apr 21 16:43:24 2022 -0700 Set discriminators for call stmts on the same line within the same basic block. Call statements are possible split points of a basic block so they may end up in different basic blocks by the time pass_ipa_auto_profile executes. This change will also simplify call site lookups since now location with discriminator will uniquely identify the call site (no callee function name is needed). This change is based on commit 1e6c4a7a8fb8e20545bb9f9032d3854f3f794c18 by Dehao Chen in vendors/google/heads/gcc-4_8. Tested on x86_64-pc-linux-gnu. gcc/ChangeLog: * tree-cfg.cc (assign_discriminators): Set discriminators for call stmts on the same line within the same basic block. Diff: --- gcc/tree-cfg.cc | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc index 42f40f17c56..41f2925665f 100644 --- a/gcc/tree-cfg.cc +++ b/gcc/tree-cfg.cc @@ -1203,8 +1203,40 @@ assign_discriminators (void) { edge e; edge_iterator ei; + gimple_stmt_iterator gsi; gimple *last = last_stmt (bb); location_t locus = last ? gimple_location (last) : UNKNOWN_LOCATION; + location_t curr_locus = UNKNOWN_LOCATION; + int curr_discr = 0; + + /* Traverse the basic block, if two function calls within a basic block + are mapped to the same line, assign a new discriminator because a call + stmt could be a split point of a basic block. */ + for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) + { + gimple *stmt = gsi_stmt (gsi); + expanded_location curr_locus_e; + if (curr_locus == UNKNOWN_LOCATION) + { + curr_locus = gimple_location (stmt); + curr_locus_e = expand_location (curr_locus); + } + else if (!same_line_p (curr_locus, &curr_locus_e, gimple_location (stmt))) + { + curr_locus = gimple_location (stmt); + curr_locus_e = expand_location (curr_locus); + curr_discr = 0; + } + else if (curr_discr != 0) + { + location_t loc = gimple_location (stmt); + location_t dloc = location_with_discriminator (loc, curr_discr); + gimple_set_location (stmt, dloc); + } + /* Allocate a new discriminator for CALL stmt. */ + if (gimple_code (stmt) == GIMPLE_CALL) + curr_discr = next_discriminator_for_locus (curr_locus); + } if (locus == UNKNOWN_LOCATION) continue;