[gcc(refs/users/kubaneko/heads/histogram)] adding histogram for empty bbs
Ondrej Kubanek
kubaneko@gcc.gnu.org
Sat Aug 20 21:53:39 GMT 2022
https://gcc.gnu.org/g:0e5d353f97592117115f8335a1a34313550a8868
commit 0e5d353f97592117115f8335a1a34313550a8868
Author: Ondrej Kubanek <kubanek0ondrej@gmail.com>
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 d79212afddb..977e33065ca 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 06a584b392a..e65421ba49e 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<edge> 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 91c46f2accb..0718f167ab1 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;
More information about the Gcc-cvs
mailing list