public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Ondrej Kubanek <kubaneko@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/kubaneko/heads/histogram)] adding histogram for empty bbs Date: Thu, 23 Feb 2023 23:21:16 +0000 (GMT) [thread overview] Message-ID: <20230223232116.B0D88385B50C@sourceware.org> (raw) https://gcc.gnu.org/g:0509b471bde3eff530fdc53c1707810fbc088602 commit 0509b471bde3eff530fdc53c1707810fbc088602 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 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<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 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;
next reply other threads:[~2023-02-23 23:21 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-02-23 23:21 Ondrej Kubanek [this message] -- strict thread matches above, loose matches on Subject: below -- 2023-02-16 16:27 Ondrej Kubanek
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20230223232116.B0D88385B50C@sourceware.org \ --to=kubaneko@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).