public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/kubaneko/heads/histogram)] fixed what I broke
@ 2022-09-19 13:49 Ondrej Kubanek
0 siblings, 0 replies; 3+ messages in thread
From: Ondrej Kubanek @ 2022-09-19 13:49 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:2b2a6a7ed305466da993c6b239a7273c7b2e5dac
commit 2b2a6a7ed305466da993c6b239a7273c7b2e5dac
Author: kubaneko <kubanek0ondrej@gmail.com>
Date: Sun Sep 18 16:23:28 2022 +0000
fixed what I broke
Diff:
---
gcc/tree-profile.cc | 7 +-
gcc/tree-ssa-loop-manip.cc | 198 ---------------------------------------------
gcc/value-prof.cc | 28 +++----
3 files changed, 11 insertions(+), 222 deletions(-)
diff --git a/gcc/tree-profile.cc b/gcc/tree-profile.cc
index 977e33065ca..f2e67e5314d 100644
--- a/gcc/tree-profile.cc
+++ b/gcc/tree-profile.cc
@@ -373,9 +373,7 @@ gimple_gen_histogram_profiler (histogram_value value, unsigned tag) // , edge_de
gsi_insert_before (&gsi, call, GSI_NEW_STMT);
} else {
edge_def *edge = value->hvalue.edge;
- if (edge==NULL){
- // BAD
- }
+ gcc_assert(edge);
gimple_stmt_iterator gsi;
gimple_seq seq = NULL;
gsi = gsi_start (seq);
@@ -388,9 +386,8 @@ gimple_gen_histogram_profiler (histogram_value value, unsigned tag) // , edge_de
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_before (&gsi, call, GSI_NEW_STMT);
gsi_insert_seq_on_edge (edge, seq);
}
}
diff --git a/gcc/tree-ssa-loop-manip.cc b/gcc/tree-ssa-loop-manip.cc
index 4f801c8d400..c531f1f12fd 100644
--- a/gcc/tree-ssa-loop-manip.cc
+++ b/gcc/tree-ssa-loop-manip.cc
@@ -180,204 +180,6 @@ find_sibling_superloop (class loop *use_loop, class loop *def_loop)
return use_loop;
}
-// create_iv2 simplified version of create iv nor requiring pre-headers
-void
-create_iv2 (tree base, tree step, tree var, class loop *loop,
- gimple_stmt_iterator *incr_pos, bool after,
- tree *var_before, tree *var_after)
-{
- gassign *stmt;
- gphi *phi;
- tree initial, step1;
- gimple_seq stmts;
- tree vb, va;
- enum tree_code incr_op = PLUS_EXPR;
-
- if (var != NULL_TREE)
- {
- vb = make_ssa_name (var);
- va = make_ssa_name (var);
- }
- else
- {
- vb = make_temp_ssa_name (TREE_TYPE (base), NULL, "ivtmp");
- va = make_temp_ssa_name (TREE_TYPE (base), NULL, "ivtmp");
- }
- if (var_before)
- *var_before = vb;
- if (var_after)
- *var_after = va;
-
- /* For easier readability of the created code, produce MINUS_EXPRs
- when suitable. */
- if (TREE_CODE (step) == INTEGER_CST)
- {
- if (TYPE_UNSIGNED (TREE_TYPE (step)))
- {
- step1 = fold_build1 (NEGATE_EXPR, TREE_TYPE (step), step);
- if (tree_int_cst_lt (step1, step))
- {
- incr_op = MINUS_EXPR;
- step = step1;
- }
- }
- else
- {
- bool ovf;
-
- if (!tree_expr_nonnegative_warnv_p (step, &ovf)
- && may_negate_without_overflow_p (step))
- {
- incr_op = MINUS_EXPR;
- step = fold_build1 (NEGATE_EXPR, TREE_TYPE (step), step);
- }
- }
- }
- if (POINTER_TYPE_P (TREE_TYPE (base)))
- {
- if (TREE_CODE (base) == ADDR_EXPR)
- mark_addressable (TREE_OPERAND (base, 0));
- step = convert_to_ptrofftype (step);
- if (incr_op == MINUS_EXPR)
- step = fold_build1 (NEGATE_EXPR, TREE_TYPE (step), step);
- incr_op = POINTER_PLUS_EXPR;
- }
- /* Gimplify the step if necessary. We put the computations in front of the
- loop (i.e. the step should be loop invariant). */
- step = force_gimple_operand (step, &stmts, true, NULL_TREE);
-
- stmt = gimple_build_assign (va, incr_op, vb, step);
- /* Prevent the increment from inheriting a bogus location if it is not put
- immediately after a statement whose location is known. */
- if (after)
- {
- if (gsi_end_p (*incr_pos)
- || (is_gimple_debug (gsi_stmt (*incr_pos))
- && gsi_bb (*incr_pos)
- && gsi_end_p (gsi_last_nondebug_bb (gsi_bb (*incr_pos)))))
- {
- edge e = single_succ_edge (gsi_bb (*incr_pos));
- gimple_set_location (stmt, e->goto_locus);
- }
- gsi_insert_after (incr_pos, stmt, GSI_NEW_STMT);
- }
- else
- {
- gimple_stmt_iterator gsi = *incr_pos;
- if (!gsi_end_p (gsi) && is_gimple_debug (gsi_stmt (gsi)))
- gsi_next_nondebug (&gsi);
- if (!gsi_end_p (gsi))
- gimple_set_location (stmt, gimple_location (gsi_stmt (gsi)));
- gsi_insert_before (incr_pos, stmt, GSI_NEW_STMT);
- }
-
- initial = force_gimple_operand (base, &stmts, true, var);
-
- phi = create_phi_node (vb, loop->header);
- add_phi_arg (phi, va, loop_latch_edge (loop), UNKNOWN_LOCATION);
-}
-
-void
-create_iv3 (tree base, tree step, tree var, class loop *loop,
- gimple_stmt_iterator *incr_pos, bool after,
- tree *var_before, tree *var_after)
-{
- gassign *stmt;
- gphi *phi;
- tree initial, step1;
- gimple_seq stmts;
- tree vb, va;
- enum tree_code incr_op = PLUS_EXPR;
-
- if (var != NULL_TREE)
- {
- vb = make_ssa_name (var);
- va = make_ssa_name (var);
- }
- else
- {
- vb = make_temp_ssa_name (TREE_TYPE (base), NULL, "ivtmp");
- va = make_temp_ssa_name (TREE_TYPE (base), NULL, "ivtmp");
- }
- if (var_before)
- *var_before = vb;
- if (var_after)
- *var_after = va;
-
- /* For easier readability of the created code, produce MINUS_EXPRs
- when suitable. */
- if (TREE_CODE (step) == INTEGER_CST)
- {
- if (TYPE_UNSIGNED (TREE_TYPE (step)))
- {
- step1 = fold_build1 (NEGATE_EXPR, TREE_TYPE (step), step);
- if (tree_int_cst_lt (step1, step))
- {
- incr_op = MINUS_EXPR;
- step = step1;
- }
- }
- else
- {
- bool ovf;
-
- if (!tree_expr_nonnegative_warnv_p (step, &ovf)
- && may_negate_without_overflow_p (step))
- {
- incr_op = MINUS_EXPR;
- step = fold_build1 (NEGATE_EXPR, TREE_TYPE (step), step);
- }
- }
- }
- if (POINTER_TYPE_P (TREE_TYPE (base)))
- {
- if (TREE_CODE (base) == ADDR_EXPR)
- mark_addressable (TREE_OPERAND (base, 0));
- step = convert_to_ptrofftype (step);
- if (incr_op == MINUS_EXPR)
- step = fold_build1 (NEGATE_EXPR, TREE_TYPE (step), step);
- incr_op = POINTER_PLUS_EXPR;
- }
- /* Gimplify the step if necessary. We put the computations in front of the
- loop (i.e. the step should be loop invariant). */
- step = force_gimple_operand (step, &stmts, true, NULL_TREE);
- if (stmts)
- gsi_insert_seq_on_edge_immediate (loop_preheader_edge (loop), stmts);
-
- stmt = gimple_build_assign (va, incr_op, vb, step);
- /* Prevent the increment from inheriting a bogus location if it is not put
- immediately after a statement whose location is known. */
- if (after)
- {
- if (gsi_end_p (*incr_pos)
- || (is_gimple_debug (gsi_stmt (*incr_pos))
- && gsi_bb (*incr_pos)
- && gsi_end_p (gsi_last_nondebug_bb (gsi_bb (*incr_pos)))))
- {
- edge e = single_succ_edge (gsi_bb (*incr_pos));
- gimple_set_location (stmt, e->goto_locus);
- }
- gsi_insert_after (incr_pos, stmt, GSI_NEW_STMT);
- }
- else
- {
- gimple_stmt_iterator gsi = *incr_pos;
- if (!gsi_end_p (gsi) && is_gimple_debug (gsi_stmt (gsi)))
- gsi_next_nondebug (&gsi);
- if (!gsi_end_p (gsi))
- gimple_set_location (stmt, gimple_location (gsi_stmt (gsi)));
- gsi_insert_before (incr_pos, stmt, GSI_NEW_STMT);
- }
-
- initial = force_gimple_operand (base, &stmts, true, var);
- if (stmts)
- gsi_insert_seq_on_edge_immediate (loop_preheader_edge (loop), stmts);
-
- phi = create_phi_node (vb, loop->header);
- add_phi_arg (phi, initial, loop_preheader_edge (loop), UNKNOWN_LOCATION);
- add_phi_arg (phi, va, loop_latch_edge (loop), UNKNOWN_LOCATION);
-}
-
/* DEF_BB is a basic block containing a DEF that needs rewriting into
loop-closed SSA form. USE_BLOCKS is the set of basic blocks containing
uses of DEF that "escape" from the loop containing DEF_BB (i.e. blocks in
diff --git a/gcc/value-prof.cc b/gcc/value-prof.cc
index e65421ba49e..d9dbf4e5240 100644
--- a/gcc/value-prof.cc
+++ b/gcc/value-prof.cc
@@ -126,12 +126,12 @@ gimple_alloc_histogram_value (struct function *fun ATTRIBUTE_UNUSED,
histogram_value
gimple_alloc_histogram_value_edge (struct function *fun ATTRIBUTE_UNUSED,
- enum hist_type type, gimple *stmt, tree value, edge_def *edge)
+ enum hist_type type, 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->hvalue.stmt = NULL;
+ hist->hvalue.edge = edge;
hist->type = type;
return hist;
}
@@ -396,7 +396,7 @@ stream_in_histogram_value (class lto_input_block *ib, gimple *stmt)
break;
case HIST_TYPE_HISTOGRAM:
- ncounters = 69;
+ ncounters = 70;
break;
case HIST_TYPE_POW2:
case HIST_TYPE_AVERAGE:
@@ -1838,9 +1838,6 @@ gimple_divmod_values_to_profile (gimple *stmt, histogram_values *values)
values->safe_push (gimple_alloc_histogram_value (cfun,
HIST_TYPE_TOPN_VALUES,
stmt, divisor));
- values->safe_push (gimple_alloc_histogram_value (cfun,
- HIST_TYPE_HISTOGRAM,
- stmt, divisor));
}
/* For mod, check whether it is not often a noop (or replaceable by
@@ -1930,28 +1927,21 @@ gimple_stringops_values_to_profile (gimple *gs, histogram_values *values)
static void
gimple_histogram_values_to_profile(function *fun, histogram_values * values){
+ calculate_dominance_info (CDI_DOMINATORS);
for (auto loop : loops_list (fun, 0)){
tree var;
gimple_stmt_iterator gsi;
gsi = gsi_last_bb (loop->latch);
- create_iv3 (build_int_cst_type (get_gcov_type(), 0), build_int_cst (get_gcov_type(), 1), NULL_TREE,
+ create_iv (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)){
- 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,
- seq, var, exit));
- }
- //pridate ulozeni var do histogramu na zacated basic blocku exit->dest
- // TREE_TYPE (name)
- else
- {
- }
+ var, exit));
}
}
+ free_dominance_info (CDI_DOMINATORS);
gsi_commit_edge_inserts ();
}
@@ -2012,7 +2002,7 @@ gimple_find_values_to_profile (histogram_values *values)
break;
case HIST_TYPE_HISTOGRAM:
- hist->n_counters = 69;
+ hist->n_counters = 70;
break;
default:
^ permalink raw reply [flat|nested] 3+ messages in thread
* [gcc(refs/users/kubaneko/heads/histogram)] fixed what I broke
@ 2023-02-23 23:21 Ondrej Kubanek
0 siblings, 0 replies; 3+ messages in thread
From: Ondrej Kubanek @ 2023-02-23 23:21 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:ffdd7efad3e558ebca67106207ac4202b17dca9c
commit ffdd7efad3e558ebca67106207ac4202b17dca9c
Author: kubaneko <kubanek0ondrej@gmail.com>
Date: Sun Sep 18 16:23:28 2022 +0000
fixed what I broke
Diff:
---
gcc/tree-profile.cc | 7 +-
gcc/tree-ssa-loop-manip.cc | 198 ---------------------------------------------
gcc/value-prof.cc | 28 +++----
3 files changed, 11 insertions(+), 222 deletions(-)
diff --git a/gcc/tree-profile.cc b/gcc/tree-profile.cc
index 327fb701144..52e94ee95d9 100644
--- a/gcc/tree-profile.cc
+++ b/gcc/tree-profile.cc
@@ -373,9 +373,7 @@ gimple_gen_histogram_profiler (histogram_value value, unsigned tag) // , edge_de
gsi_insert_before (&gsi, call, GSI_NEW_STMT);
} else {
edge_def *edge = value->hvalue.edge;
- if (edge==NULL){
- // BAD
- }
+ gcc_assert(edge);
gimple_stmt_iterator gsi;
gimple_seq seq = NULL;
gsi = gsi_start (seq);
@@ -388,9 +386,8 @@ gimple_gen_histogram_profiler (histogram_value value, unsigned tag) // , edge_de
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_before (&gsi, call, GSI_NEW_STMT);
gsi_insert_seq_on_edge (edge, seq);
}
}
diff --git a/gcc/tree-ssa-loop-manip.cc b/gcc/tree-ssa-loop-manip.cc
index 748621a6143..09acc1c94cc 100644
--- a/gcc/tree-ssa-loop-manip.cc
+++ b/gcc/tree-ssa-loop-manip.cc
@@ -180,204 +180,6 @@ find_sibling_superloop (class loop *use_loop, class loop *def_loop)
return use_loop;
}
-// create_iv2 simplified version of create iv nor requiring pre-headers
-void
-create_iv2 (tree base, tree step, tree var, class loop *loop,
- gimple_stmt_iterator *incr_pos, bool after,
- tree *var_before, tree *var_after)
-{
- gassign *stmt;
- gphi *phi;
- tree initial, step1;
- gimple_seq stmts;
- tree vb, va;
- enum tree_code incr_op = PLUS_EXPR;
-
- if (var != NULL_TREE)
- {
- vb = make_ssa_name (var);
- va = make_ssa_name (var);
- }
- else
- {
- vb = make_temp_ssa_name (TREE_TYPE (base), NULL, "ivtmp");
- va = make_temp_ssa_name (TREE_TYPE (base), NULL, "ivtmp");
- }
- if (var_before)
- *var_before = vb;
- if (var_after)
- *var_after = va;
-
- /* For easier readability of the created code, produce MINUS_EXPRs
- when suitable. */
- if (TREE_CODE (step) == INTEGER_CST)
- {
- if (TYPE_UNSIGNED (TREE_TYPE (step)))
- {
- step1 = fold_build1 (NEGATE_EXPR, TREE_TYPE (step), step);
- if (tree_int_cst_lt (step1, step))
- {
- incr_op = MINUS_EXPR;
- step = step1;
- }
- }
- else
- {
- bool ovf;
-
- if (!tree_expr_nonnegative_warnv_p (step, &ovf)
- && may_negate_without_overflow_p (step))
- {
- incr_op = MINUS_EXPR;
- step = fold_build1 (NEGATE_EXPR, TREE_TYPE (step), step);
- }
- }
- }
- if (POINTER_TYPE_P (TREE_TYPE (base)))
- {
- if (TREE_CODE (base) == ADDR_EXPR)
- mark_addressable (TREE_OPERAND (base, 0));
- step = convert_to_ptrofftype (step);
- if (incr_op == MINUS_EXPR)
- step = fold_build1 (NEGATE_EXPR, TREE_TYPE (step), step);
- incr_op = POINTER_PLUS_EXPR;
- }
- /* Gimplify the step if necessary. We put the computations in front of the
- loop (i.e. the step should be loop invariant). */
- step = force_gimple_operand (step, &stmts, true, NULL_TREE);
-
- stmt = gimple_build_assign (va, incr_op, vb, step);
- /* Prevent the increment from inheriting a bogus location if it is not put
- immediately after a statement whose location is known. */
- if (after)
- {
- if (gsi_end_p (*incr_pos)
- || (is_gimple_debug (gsi_stmt (*incr_pos))
- && gsi_bb (*incr_pos)
- && gsi_end_p (gsi_last_nondebug_bb (gsi_bb (*incr_pos)))))
- {
- edge e = single_succ_edge (gsi_bb (*incr_pos));
- gimple_set_location (stmt, e->goto_locus);
- }
- gsi_insert_after (incr_pos, stmt, GSI_NEW_STMT);
- }
- else
- {
- gimple_stmt_iterator gsi = *incr_pos;
- if (!gsi_end_p (gsi) && is_gimple_debug (gsi_stmt (gsi)))
- gsi_next_nondebug (&gsi);
- if (!gsi_end_p (gsi))
- gimple_set_location (stmt, gimple_location (gsi_stmt (gsi)));
- gsi_insert_before (incr_pos, stmt, GSI_NEW_STMT);
- }
-
- initial = force_gimple_operand (base, &stmts, true, var);
-
- phi = create_phi_node (vb, loop->header);
- add_phi_arg (phi, va, loop_latch_edge (loop), UNKNOWN_LOCATION);
-}
-
-void
-create_iv3 (tree base, tree step, tree var, class loop *loop,
- gimple_stmt_iterator *incr_pos, bool after,
- tree *var_before, tree *var_after)
-{
- gassign *stmt;
- gphi *phi;
- tree initial, step1;
- gimple_seq stmts;
- tree vb, va;
- enum tree_code incr_op = PLUS_EXPR;
-
- if (var != NULL_TREE)
- {
- vb = make_ssa_name (var);
- va = make_ssa_name (var);
- }
- else
- {
- vb = make_temp_ssa_name (TREE_TYPE (base), NULL, "ivtmp");
- va = make_temp_ssa_name (TREE_TYPE (base), NULL, "ivtmp");
- }
- if (var_before)
- *var_before = vb;
- if (var_after)
- *var_after = va;
-
- /* For easier readability of the created code, produce MINUS_EXPRs
- when suitable. */
- if (TREE_CODE (step) == INTEGER_CST)
- {
- if (TYPE_UNSIGNED (TREE_TYPE (step)))
- {
- step1 = fold_build1 (NEGATE_EXPR, TREE_TYPE (step), step);
- if (tree_int_cst_lt (step1, step))
- {
- incr_op = MINUS_EXPR;
- step = step1;
- }
- }
- else
- {
- bool ovf;
-
- if (!tree_expr_nonnegative_warnv_p (step, &ovf)
- && may_negate_without_overflow_p (step))
- {
- incr_op = MINUS_EXPR;
- step = fold_build1 (NEGATE_EXPR, TREE_TYPE (step), step);
- }
- }
- }
- if (POINTER_TYPE_P (TREE_TYPE (base)))
- {
- if (TREE_CODE (base) == ADDR_EXPR)
- mark_addressable (TREE_OPERAND (base, 0));
- step = convert_to_ptrofftype (step);
- if (incr_op == MINUS_EXPR)
- step = fold_build1 (NEGATE_EXPR, TREE_TYPE (step), step);
- incr_op = POINTER_PLUS_EXPR;
- }
- /* Gimplify the step if necessary. We put the computations in front of the
- loop (i.e. the step should be loop invariant). */
- step = force_gimple_operand (step, &stmts, true, NULL_TREE);
- if (stmts)
- gsi_insert_seq_on_edge_immediate (loop_preheader_edge (loop), stmts);
-
- stmt = gimple_build_assign (va, incr_op, vb, step);
- /* Prevent the increment from inheriting a bogus location if it is not put
- immediately after a statement whose location is known. */
- if (after)
- {
- if (gsi_end_p (*incr_pos)
- || (is_gimple_debug (gsi_stmt (*incr_pos))
- && gsi_bb (*incr_pos)
- && gsi_end_p (gsi_last_nondebug_bb (gsi_bb (*incr_pos)))))
- {
- edge e = single_succ_edge (gsi_bb (*incr_pos));
- gimple_set_location (stmt, e->goto_locus);
- }
- gsi_insert_after (incr_pos, stmt, GSI_NEW_STMT);
- }
- else
- {
- gimple_stmt_iterator gsi = *incr_pos;
- if (!gsi_end_p (gsi) && is_gimple_debug (gsi_stmt (gsi)))
- gsi_next_nondebug (&gsi);
- if (!gsi_end_p (gsi))
- gimple_set_location (stmt, gimple_location (gsi_stmt (gsi)));
- gsi_insert_before (incr_pos, stmt, GSI_NEW_STMT);
- }
-
- initial = force_gimple_operand (base, &stmts, true, var);
- if (stmts)
- gsi_insert_seq_on_edge_immediate (loop_preheader_edge (loop), stmts);
-
- phi = create_phi_node (vb, loop->header);
- add_phi_arg (phi, initial, loop_preheader_edge (loop), UNKNOWN_LOCATION);
- add_phi_arg (phi, va, loop_latch_edge (loop), UNKNOWN_LOCATION);
-}
-
/* DEF_BB is a basic block containing a DEF that needs rewriting into
loop-closed SSA form. USE_BLOCKS is the set of basic blocks containing
uses of DEF that "escape" from the loop containing DEF_BB (i.e. blocks in
diff --git a/gcc/value-prof.cc b/gcc/value-prof.cc
index 3cd68b6a584..2331a1c0163 100644
--- a/gcc/value-prof.cc
+++ b/gcc/value-prof.cc
@@ -126,12 +126,12 @@ gimple_alloc_histogram_value (struct function *fun ATTRIBUTE_UNUSED,
histogram_value
gimple_alloc_histogram_value_edge (struct function *fun ATTRIBUTE_UNUSED,
- enum hist_type type, gimple *stmt, tree value, edge_def *edge)
+ enum hist_type type, 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->hvalue.stmt = NULL;
+ hist->hvalue.edge = edge;
hist->type = type;
return hist;
}
@@ -396,7 +396,7 @@ stream_in_histogram_value (class lto_input_block *ib, gimple *stmt)
break;
case HIST_TYPE_HISTOGRAM:
- ncounters = 69;
+ ncounters = 70;
break;
case HIST_TYPE_POW2:
case HIST_TYPE_AVERAGE:
@@ -1838,9 +1838,6 @@ gimple_divmod_values_to_profile (gimple *stmt, histogram_values *values)
values->safe_push (gimple_alloc_histogram_value (cfun,
HIST_TYPE_TOPN_VALUES,
stmt, divisor));
- values->safe_push (gimple_alloc_histogram_value (cfun,
- HIST_TYPE_HISTOGRAM,
- stmt, divisor));
}
/* For mod, check whether it is not often a noop (or replaceable by
@@ -1930,28 +1927,21 @@ gimple_stringops_values_to_profile (gimple *gs, histogram_values *values)
static void
gimple_histogram_values_to_profile(function *fun, histogram_values * values){
+ calculate_dominance_info (CDI_DOMINATORS);
for (auto loop : loops_list (fun, 0)){
tree var;
gimple_stmt_iterator gsi;
gsi = gsi_last_bb (loop->latch);
- create_iv3 (build_int_cst_type (get_gcov_type(), 0), build_int_cst (get_gcov_type(), 1), NULL_TREE,
+ create_iv (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)){
- 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,
- seq, var, exit));
- }
- //pridate ulozeni var do histogramu na zacated basic blocku exit->dest
- // TREE_TYPE (name)
- else
- {
- }
+ var, exit));
}
}
+ free_dominance_info (CDI_DOMINATORS);
gsi_commit_edge_inserts ();
}
@@ -2012,7 +2002,7 @@ gimple_find_values_to_profile (histogram_values *values)
break;
case HIST_TYPE_HISTOGRAM:
- hist->n_counters = 69;
+ hist->n_counters = 70;
break;
default:
^ permalink raw reply [flat|nested] 3+ messages in thread
* [gcc(refs/users/kubaneko/heads/histogram)] fixed what I broke
@ 2023-02-16 16:27 Ondrej Kubanek
0 siblings, 0 replies; 3+ messages in thread
From: Ondrej Kubanek @ 2023-02-16 16:27 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:0d1ebd267d96f0b2bfeb3a99fffa32db6028a0a4
commit 0d1ebd267d96f0b2bfeb3a99fffa32db6028a0a4
Author: kubaneko <kubanek0ondrej@gmail.com>
Date: Sun Sep 18 16:23:28 2022 +0000
fixed what I broke
Diff:
---
gcc/tree-profile.cc | 7 +-
gcc/tree-ssa-loop-manip.cc | 198 ---------------------------------------------
gcc/value-prof.cc | 28 +++----
3 files changed, 11 insertions(+), 222 deletions(-)
diff --git a/gcc/tree-profile.cc b/gcc/tree-profile.cc
index 977e33065ca..f2e67e5314d 100644
--- a/gcc/tree-profile.cc
+++ b/gcc/tree-profile.cc
@@ -373,9 +373,7 @@ gimple_gen_histogram_profiler (histogram_value value, unsigned tag) // , edge_de
gsi_insert_before (&gsi, call, GSI_NEW_STMT);
} else {
edge_def *edge = value->hvalue.edge;
- if (edge==NULL){
- // BAD
- }
+ gcc_assert(edge);
gimple_stmt_iterator gsi;
gimple_seq seq = NULL;
gsi = gsi_start (seq);
@@ -388,9 +386,8 @@ gimple_gen_histogram_profiler (histogram_value value, unsigned tag) // , edge_de
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_before (&gsi, call, GSI_NEW_STMT);
gsi_insert_seq_on_edge (edge, seq);
}
}
diff --git a/gcc/tree-ssa-loop-manip.cc b/gcc/tree-ssa-loop-manip.cc
index 2d76b7888f8..410a8516370 100644
--- a/gcc/tree-ssa-loop-manip.cc
+++ b/gcc/tree-ssa-loop-manip.cc
@@ -180,204 +180,6 @@ find_sibling_superloop (class loop *use_loop, class loop *def_loop)
return use_loop;
}
-// create_iv2 simplified version of create iv nor requiring pre-headers
-void
-create_iv2 (tree base, tree step, tree var, class loop *loop,
- gimple_stmt_iterator *incr_pos, bool after,
- tree *var_before, tree *var_after)
-{
- gassign *stmt;
- gphi *phi;
- tree initial, step1;
- gimple_seq stmts;
- tree vb, va;
- enum tree_code incr_op = PLUS_EXPR;
-
- if (var != NULL_TREE)
- {
- vb = make_ssa_name (var);
- va = make_ssa_name (var);
- }
- else
- {
- vb = make_temp_ssa_name (TREE_TYPE (base), NULL, "ivtmp");
- va = make_temp_ssa_name (TREE_TYPE (base), NULL, "ivtmp");
- }
- if (var_before)
- *var_before = vb;
- if (var_after)
- *var_after = va;
-
- /* For easier readability of the created code, produce MINUS_EXPRs
- when suitable. */
- if (TREE_CODE (step) == INTEGER_CST)
- {
- if (TYPE_UNSIGNED (TREE_TYPE (step)))
- {
- step1 = fold_build1 (NEGATE_EXPR, TREE_TYPE (step), step);
- if (tree_int_cst_lt (step1, step))
- {
- incr_op = MINUS_EXPR;
- step = step1;
- }
- }
- else
- {
- bool ovf;
-
- if (!tree_expr_nonnegative_warnv_p (step, &ovf)
- && may_negate_without_overflow_p (step))
- {
- incr_op = MINUS_EXPR;
- step = fold_build1 (NEGATE_EXPR, TREE_TYPE (step), step);
- }
- }
- }
- if (POINTER_TYPE_P (TREE_TYPE (base)))
- {
- if (TREE_CODE (base) == ADDR_EXPR)
- mark_addressable (TREE_OPERAND (base, 0));
- step = convert_to_ptrofftype (step);
- if (incr_op == MINUS_EXPR)
- step = fold_build1 (NEGATE_EXPR, TREE_TYPE (step), step);
- incr_op = POINTER_PLUS_EXPR;
- }
- /* Gimplify the step if necessary. We put the computations in front of the
- loop (i.e. the step should be loop invariant). */
- step = force_gimple_operand (step, &stmts, true, NULL_TREE);
-
- stmt = gimple_build_assign (va, incr_op, vb, step);
- /* Prevent the increment from inheriting a bogus location if it is not put
- immediately after a statement whose location is known. */
- if (after)
- {
- if (gsi_end_p (*incr_pos)
- || (is_gimple_debug (gsi_stmt (*incr_pos))
- && gsi_bb (*incr_pos)
- && gsi_end_p (gsi_last_nondebug_bb (gsi_bb (*incr_pos)))))
- {
- edge e = single_succ_edge (gsi_bb (*incr_pos));
- gimple_set_location (stmt, e->goto_locus);
- }
- gsi_insert_after (incr_pos, stmt, GSI_NEW_STMT);
- }
- else
- {
- gimple_stmt_iterator gsi = *incr_pos;
- if (!gsi_end_p (gsi) && is_gimple_debug (gsi_stmt (gsi)))
- gsi_next_nondebug (&gsi);
- if (!gsi_end_p (gsi))
- gimple_set_location (stmt, gimple_location (gsi_stmt (gsi)));
- gsi_insert_before (incr_pos, stmt, GSI_NEW_STMT);
- }
-
- initial = force_gimple_operand (base, &stmts, true, var);
-
- phi = create_phi_node (vb, loop->header);
- add_phi_arg (phi, va, loop_latch_edge (loop), UNKNOWN_LOCATION);
-}
-
-void
-create_iv3 (tree base, tree step, tree var, class loop *loop,
- gimple_stmt_iterator *incr_pos, bool after,
- tree *var_before, tree *var_after)
-{
- gassign *stmt;
- gphi *phi;
- tree initial, step1;
- gimple_seq stmts;
- tree vb, va;
- enum tree_code incr_op = PLUS_EXPR;
-
- if (var != NULL_TREE)
- {
- vb = make_ssa_name (var);
- va = make_ssa_name (var);
- }
- else
- {
- vb = make_temp_ssa_name (TREE_TYPE (base), NULL, "ivtmp");
- va = make_temp_ssa_name (TREE_TYPE (base), NULL, "ivtmp");
- }
- if (var_before)
- *var_before = vb;
- if (var_after)
- *var_after = va;
-
- /* For easier readability of the created code, produce MINUS_EXPRs
- when suitable. */
- if (TREE_CODE (step) == INTEGER_CST)
- {
- if (TYPE_UNSIGNED (TREE_TYPE (step)))
- {
- step1 = fold_build1 (NEGATE_EXPR, TREE_TYPE (step), step);
- if (tree_int_cst_lt (step1, step))
- {
- incr_op = MINUS_EXPR;
- step = step1;
- }
- }
- else
- {
- bool ovf;
-
- if (!tree_expr_nonnegative_warnv_p (step, &ovf)
- && may_negate_without_overflow_p (step))
- {
- incr_op = MINUS_EXPR;
- step = fold_build1 (NEGATE_EXPR, TREE_TYPE (step), step);
- }
- }
- }
- if (POINTER_TYPE_P (TREE_TYPE (base)))
- {
- if (TREE_CODE (base) == ADDR_EXPR)
- mark_addressable (TREE_OPERAND (base, 0));
- step = convert_to_ptrofftype (step);
- if (incr_op == MINUS_EXPR)
- step = fold_build1 (NEGATE_EXPR, TREE_TYPE (step), step);
- incr_op = POINTER_PLUS_EXPR;
- }
- /* Gimplify the step if necessary. We put the computations in front of the
- loop (i.e. the step should be loop invariant). */
- step = force_gimple_operand (step, &stmts, true, NULL_TREE);
- if (stmts)
- gsi_insert_seq_on_edge_immediate (loop_preheader_edge (loop), stmts);
-
- stmt = gimple_build_assign (va, incr_op, vb, step);
- /* Prevent the increment from inheriting a bogus location if it is not put
- immediately after a statement whose location is known. */
- if (after)
- {
- if (gsi_end_p (*incr_pos)
- || (is_gimple_debug (gsi_stmt (*incr_pos))
- && gsi_bb (*incr_pos)
- && gsi_end_p (gsi_last_nondebug_bb (gsi_bb (*incr_pos)))))
- {
- edge e = single_succ_edge (gsi_bb (*incr_pos));
- gimple_set_location (stmt, e->goto_locus);
- }
- gsi_insert_after (incr_pos, stmt, GSI_NEW_STMT);
- }
- else
- {
- gimple_stmt_iterator gsi = *incr_pos;
- if (!gsi_end_p (gsi) && is_gimple_debug (gsi_stmt (gsi)))
- gsi_next_nondebug (&gsi);
- if (!gsi_end_p (gsi))
- gimple_set_location (stmt, gimple_location (gsi_stmt (gsi)));
- gsi_insert_before (incr_pos, stmt, GSI_NEW_STMT);
- }
-
- initial = force_gimple_operand (base, &stmts, true, var);
- if (stmts)
- gsi_insert_seq_on_edge_immediate (loop_preheader_edge (loop), stmts);
-
- phi = create_phi_node (vb, loop->header);
- add_phi_arg (phi, initial, loop_preheader_edge (loop), UNKNOWN_LOCATION);
- add_phi_arg (phi, va, loop_latch_edge (loop), UNKNOWN_LOCATION);
-}
-
/* DEF_BB is a basic block containing a DEF that needs rewriting into
loop-closed SSA form. USE_BLOCKS is the set of basic blocks containing
uses of DEF that "escape" from the loop containing DEF_BB (i.e. blocks in
diff --git a/gcc/value-prof.cc b/gcc/value-prof.cc
index e65421ba49e..d9dbf4e5240 100644
--- a/gcc/value-prof.cc
+++ b/gcc/value-prof.cc
@@ -126,12 +126,12 @@ gimple_alloc_histogram_value (struct function *fun ATTRIBUTE_UNUSED,
histogram_value
gimple_alloc_histogram_value_edge (struct function *fun ATTRIBUTE_UNUSED,
- enum hist_type type, gimple *stmt, tree value, edge_def *edge)
+ enum hist_type type, 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->hvalue.stmt = NULL;
+ hist->hvalue.edge = edge;
hist->type = type;
return hist;
}
@@ -396,7 +396,7 @@ stream_in_histogram_value (class lto_input_block *ib, gimple *stmt)
break;
case HIST_TYPE_HISTOGRAM:
- ncounters = 69;
+ ncounters = 70;
break;
case HIST_TYPE_POW2:
case HIST_TYPE_AVERAGE:
@@ -1838,9 +1838,6 @@ gimple_divmod_values_to_profile (gimple *stmt, histogram_values *values)
values->safe_push (gimple_alloc_histogram_value (cfun,
HIST_TYPE_TOPN_VALUES,
stmt, divisor));
- values->safe_push (gimple_alloc_histogram_value (cfun,
- HIST_TYPE_HISTOGRAM,
- stmt, divisor));
}
/* For mod, check whether it is not often a noop (or replaceable by
@@ -1930,28 +1927,21 @@ gimple_stringops_values_to_profile (gimple *gs, histogram_values *values)
static void
gimple_histogram_values_to_profile(function *fun, histogram_values * values){
+ calculate_dominance_info (CDI_DOMINATORS);
for (auto loop : loops_list (fun, 0)){
tree var;
gimple_stmt_iterator gsi;
gsi = gsi_last_bb (loop->latch);
- create_iv3 (build_int_cst_type (get_gcov_type(), 0), build_int_cst (get_gcov_type(), 1), NULL_TREE,
+ create_iv (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)){
- 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,
- seq, var, exit));
- }
- //pridate ulozeni var do histogramu na zacated basic blocku exit->dest
- // TREE_TYPE (name)
- else
- {
- }
+ var, exit));
}
}
+ free_dominance_info (CDI_DOMINATORS);
gsi_commit_edge_inserts ();
}
@@ -2012,7 +2002,7 @@ gimple_find_values_to_profile (histogram_values *values)
break;
case HIST_TYPE_HISTOGRAM:
- hist->n_counters = 69;
+ hist->n_counters = 70;
break;
default:
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-02-23 23:21 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-19 13:49 [gcc(refs/users/kubaneko/heads/histogram)] fixed what I broke Ondrej Kubanek
2023-02-16 16:27 Ondrej Kubanek
2023-02-23 23:21 Ondrej Kubanek
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).