From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7880) id B0D88385B50C; Thu, 23 Feb 2023 23:21:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B0D88385B50C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677194476; bh=ejmf84e9iz8u0TIksHcXd3JEKWnT+VekYQSaLvGs2NU=; h=From:To:Subject:Date:From; b=X/8LCD5yGB4CEsf5Xz1f1UF6U21+PUajoXUTTn/W/1tdu16Tz9ll5LKflEJOaOAgU Pj0M4bVmFnhkcYMXhlGKJf0+L2JifIIDSPb1glsyYvB566Kxv16U+zc41x2/ZedR7A rYf1wFoRjh1gyQuJXu+Ch+vN0EOiuzdKwqtejnBE= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Ondrej Kubanek To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/kubaneko/heads/histogram)] adding histogram for empty bbs X-Act-Checkin: gcc X-Git-Author: Ondrej Kubanek X-Git-Refname: refs/users/kubaneko/heads/histogram X-Git-Oldrev: b0aaccee120686f44dd2a0365270ccb034082ec4 X-Git-Newrev: 0509b471bde3eff530fdc53c1707810fbc088602 Message-Id: <20230223232116.B0D88385B50C@sourceware.org> Date: Thu, 23 Feb 2023 23:21:16 +0000 (GMT) List-Id: https://gcc.gnu.org/g:0509b471bde3eff530fdc53c1707810fbc088602 commit 0509b471bde3eff530fdc53c1707810fbc088602 Author: Ondrej Kubanek Date: Sat Aug 20 23:37:39 2022 +0200 adding histogram for empty bbs Diff: --- gcc/tree-profile.cc | 48 +++++++++++++++++++++++++++++++++++------------- gcc/value-prof.cc | 24 ++++++++++++++++++++---- gcc/value-prof.h | 1 + 3 files changed, 56 insertions(+), 17 deletions(-) diff --git a/gcc/tree-profile.cc b/gcc/tree-profile.cc index 868fcb01ef3..327fb701144 100644 --- a/gcc/tree-profile.cc +++ b/gcc/tree-profile.cc @@ -352,25 +352,47 @@ gimple_gen_pow2_profiler (histogram_value value, unsigned tag) gsi_insert_before (&gsi, call, GSI_NEW_STMT); } -/* Output instructions as GIMPLE trees to increment the power of two histogram +/* Output instructions as GIMPLE trees to increment the histogram counter. VALUE is the expression whose value is profiled. TAG is the tag of the section for counters. */ void -gimple_gen_histogram_profiler (histogram_value value, unsigned tag) +gimple_gen_histogram_profiler (histogram_value value, unsigned tag) // , edge_def* edge { gimple *stmt = value->hvalue.stmt; - gimple_stmt_iterator gsi = gsi_for_stmt (stmt); - tree ref_ptr = tree_coverage_counter_addr (tag, 0); - // TODO why does it crash - gcall *call; - tree val; - - ref_ptr = force_gimple_operand_gsi (&gsi, ref_ptr, - true, NULL_TREE, true, GSI_SAME_STMT); - val = prepare_instrumented_value (&gsi, value); - call = gimple_build_call (tree_histogram_profiler_fn, 2, ref_ptr, val); - gsi_insert_before (&gsi, call, GSI_NEW_STMT); + if (stmt){ + gimple_stmt_iterator gsi = gsi_for_stmt (stmt); + tree ref_ptr = tree_coverage_counter_addr (tag, 0); + gcall *call; + tree val; + + ref_ptr = force_gimple_operand_gsi (&gsi, ref_ptr, + true, NULL_TREE, true, GSI_SAME_STMT); + val = prepare_instrumented_value (&gsi, value); + call = gimple_build_call (tree_histogram_profiler_fn, 2, ref_ptr, val); + gsi_insert_before (&gsi, call, GSI_NEW_STMT); + } else { + edge_def *edge = value->hvalue.edge; + if (edge==NULL){ + // BAD + } + gimple_stmt_iterator gsi; + gimple_seq seq = NULL; + gsi = gsi_start (seq); + + tree ref_ptr = tree_coverage_counter_addr (tag, 0); + gcall *call; + tree val; + + ref_ptr = force_gimple_operand_gsi (&gsi, ref_ptr, + true, NULL_TREE, true, GSI_SAME_STMT); + val = prepare_instrumented_value (&gsi, value); + call = gimple_build_call (tree_histogram_profiler_fn, 2, ref_ptr, val); + gsi_insert_before (&gsi, call, GSI_NEW_STMT); // might crash + + seq = gsi_seq (gsi); + gsi_insert_seq_on_edge (edge, seq); + } } /* Output instructions as GIMPLE trees for code to find the most N common diff --git a/gcc/value-prof.cc b/gcc/value-prof.cc index bb0a752ce30..3cd68b6a584 100644 --- a/gcc/value-prof.cc +++ b/gcc/value-prof.cc @@ -119,6 +119,19 @@ gimple_alloc_histogram_value (struct function *fun ATTRIBUTE_UNUSED, histogram_value hist = (histogram_value) xcalloc (1, sizeof (*hist)); hist->hvalue.value = value; hist->hvalue.stmt = stmt; + hist->hvalue.edge = NULL; + hist->type = type; + return hist; +} + +histogram_value +gimple_alloc_histogram_value_edge (struct function *fun ATTRIBUTE_UNUSED, + enum hist_type type, gimple *stmt, tree value, edge_def *edge) +{ + histogram_value hist = (histogram_value) xcalloc (1, sizeof (*hist)); + hist->hvalue.value = value; + hist->hvalue.stmt = stmt; + hist->hvalue.edge = stmt ? NULL : edge; hist->type = type; return hist; } @@ -1921,14 +1934,16 @@ gimple_histogram_values_to_profile(function *fun, histogram_values * values){ tree var; gimple_stmt_iterator gsi; gsi = gsi_last_bb (loop->latch); - create_iv (build_int_cst_type (var, 0), build_int_cst (var, 1), NULL_TREE, + create_iv3 (build_int_cst_type (get_gcov_type(), 0), build_int_cst (get_gcov_type(), 1), NULL_TREE, loop, &gsi, true, &var, NULL); auto_vec exits = get_loop_exit_edges (loop); for ( auto exit : exits ){ if (single_pred_p (exit->dest)){ - values->safe_push (gimple_alloc_histogram_value (fun, + gimple_stmt_iterator gsi_edge = gsi_start_bb (exit->src); + gimple_seq seq = gsi_seq (gsi_edge); + values->safe_push (gimple_alloc_histogram_value_edge (fun, HIST_TYPE_HISTOGRAM, - exit->src, var)); + seq, var, exit)); } //pridate ulozeni var do histogramu na zacated basic blocku exit->dest // TREE_TYPE (name) @@ -1937,6 +1952,7 @@ gimple_histogram_values_to_profile(function *fun, histogram_values * values){ } } } + gsi_commit_edge_inserts (); } /* Find values inside STMT for that we want to measure histograms and adds @@ -1958,8 +1974,8 @@ gimple_find_values_to_profile (histogram_values *values) unsigned i; histogram_value hist = NULL; values->create (0); + gimple_histogram_values_to_profile(cfun, values); FOR_EACH_BB_FN (bb, cfun) - gimple_histogram_values_to_profile(cfun, values); for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) gimple_values_to_profile (gsi_stmt (gsi), values); diff --git a/gcc/value-prof.h b/gcc/value-prof.h index 991f29f8c6b..0097c7a6f4f 100644 --- a/gcc/value-prof.h +++ b/gcc/value-prof.h @@ -48,6 +48,7 @@ struct histogram_value_t { tree value; /* The value to profile. */ gimple *stmt; /* Insn containing the value. */ + edge_def *edge; /* For adding to empty bbs */ gcov_type *counters; /* Pointer to first counter. */ struct histogram_value_t *next; /* Linked list pointer. */ } hvalue;