Commit 370df3ce by Jan Hubicka Committed by Jan Hubicka

bb-reorder.c (max_entry_frequency): Remove.

	* bb-reorder.c (max_entry_frequency): Remove.
	(find_traces, rotate_loop, mark_bb_visited, connect_better_edge_p,
	connect_traces, push_to_next_round_p): Remove prototypes.
	(find_traces_1_round): Use counts only.
	(push_to_next_round_p): Likewise.
	(find_traces): Likewise.
	(rotate_loop): Likewise.
	(find_traces_1_round): Likewise.
	(connect_traces): Likewise.
	(edge_order): Likewise.

From-SVN: r254602
parent 9f28fe39
2017-11-09 Jan Hubicka <hubicka@ucw.cz>
* bb-reorder.c (max_entry_frequency): Remove.
(find_traces, rotate_loop, mark_bb_visited, connect_better_edge_p,
connect_traces, push_to_next_round_p): Remove prototypes.
(find_traces_1_round): Use counts only.
(push_to_next_round_p): Likewise.
(find_traces): Likewise.
(rotate_loop): Likewise.
(find_traces_1_round): Likewise.
(connect_traces): Likewise.
(edge_order): Likewise.
2017-11-09 Thomas Preud'homme <thomas.preudhomme@arm.com> 2017-11-09 Thomas Preud'homme <thomas.preudhomme@arm.com>
* config/arm/arm.c (output_return_instruction): Add comments to * config/arm/arm.c (output_return_instruction): Add comments to
...@@ -197,24 +197,16 @@ struct trace ...@@ -197,24 +197,16 @@ struct trace
}; };
/* Maximum frequency and count of one of the entry blocks. */ /* Maximum frequency and count of one of the entry blocks. */
static int max_entry_frequency;
static profile_count max_entry_count; static profile_count max_entry_count;
/* Local function prototypes. */ /* Local function prototypes. */
static void find_traces (int *, struct trace *); static void find_traces_1_round (int, profile_count, struct trace *, int *,
static basic_block rotate_loop (edge, struct trace *, int);
static void mark_bb_visited (basic_block, int);
static void find_traces_1_round (int, int, gcov_type, struct trace *, int *,
int, bb_heap_t **, int); int, bb_heap_t **, int);
static basic_block copy_bb (basic_block, edge, basic_block, int); static basic_block copy_bb (basic_block, edge, basic_block, int);
static long bb_to_key (basic_block); static long bb_to_key (basic_block);
static bool better_edge_p (const_basic_block, const_edge, profile_probability, static bool better_edge_p (const_basic_block, const_edge, profile_probability,
int, profile_probability, int, const_edge); int, profile_probability, int, const_edge);
static bool connect_better_edge_p (const_edge, bool, int, const_edge,
struct trace *);
static void connect_traces (int, struct trace *);
static bool copy_bb_p (const_basic_block, int); static bool copy_bb_p (const_basic_block, int);
static bool push_to_next_round_p (const_basic_block, int, int, int, gcov_type);
/* Return the trace number in which BB was visited. */ /* Return the trace number in which BB was visited. */
...@@ -249,15 +241,14 @@ mark_bb_visited (basic_block bb, int trace) ...@@ -249,15 +241,14 @@ mark_bb_visited (basic_block bb, int trace)
static bool static bool
push_to_next_round_p (const_basic_block bb, int round, int number_of_rounds, push_to_next_round_p (const_basic_block bb, int round, int number_of_rounds,
int exec_th, gcov_type count_th) profile_count count_th)
{ {
bool there_exists_another_round; bool there_exists_another_round;
bool block_not_hot_enough; bool block_not_hot_enough;
there_exists_another_round = round < number_of_rounds - 1; there_exists_another_round = round < number_of_rounds - 1;
block_not_hot_enough = (bb->count.to_frequency (cfun) < exec_th block_not_hot_enough = (bb->count < count_th
|| bb->count.ipa () < count_th
|| probably_never_executed_bb_p (cfun, bb)); || probably_never_executed_bb_p (cfun, bb));
if (there_exists_another_round if (there_exists_another_round
...@@ -287,33 +278,26 @@ find_traces (int *n_traces, struct trace *traces) ...@@ -287,33 +278,26 @@ find_traces (int *n_traces, struct trace *traces)
number_of_rounds = N_ROUNDS - 1; number_of_rounds = N_ROUNDS - 1;
/* Insert entry points of function into heap. */ /* Insert entry points of function into heap. */
max_entry_frequency = 0;
max_entry_count = profile_count::zero (); max_entry_count = profile_count::zero ();
FOR_EACH_EDGE (e, ei, ENTRY_BLOCK_PTR_FOR_FN (cfun)->succs) FOR_EACH_EDGE (e, ei, ENTRY_BLOCK_PTR_FOR_FN (cfun)->succs)
{ {
bbd[e->dest->index].heap = heap; bbd[e->dest->index].heap = heap;
bbd[e->dest->index].node = heap->insert (bb_to_key (e->dest), e->dest); bbd[e->dest->index].node = heap->insert (bb_to_key (e->dest), e->dest);
if (e->dest->count.to_frequency (cfun) > max_entry_frequency) if (e->dest->count > max_entry_count)
max_entry_frequency = e->dest->count.to_frequency (cfun);
if (e->dest->count.ipa_p () && e->dest->count > max_entry_count)
max_entry_count = e->dest->count; max_entry_count = e->dest->count;
} }
/* Find the traces. */ /* Find the traces. */
for (i = 0; i < number_of_rounds; i++) for (i = 0; i < number_of_rounds; i++)
{ {
gcov_type count_threshold; profile_count count_threshold;
if (dump_file) if (dump_file)
fprintf (dump_file, "STC - round %d\n", i + 1); fprintf (dump_file, "STC - round %d\n", i + 1);
if (max_entry_count < INT_MAX / 1000) count_threshold = max_entry_count.apply_scale (exec_threshold[i], 1000);
count_threshold = max_entry_count.to_gcov_type () * exec_threshold[i] / 1000;
else
count_threshold = max_entry_count.to_gcov_type () / 1000 * exec_threshold[i];
find_traces_1_round (REG_BR_PROB_BASE * branch_threshold[i] / 1000, find_traces_1_round (REG_BR_PROB_BASE * branch_threshold[i] / 1000,
max_entry_frequency * exec_threshold[i] / 1000,
count_threshold, traces, n_traces, i, &heap, count_threshold, traces, n_traces, i, &heap,
number_of_rounds); number_of_rounds);
} }
...@@ -349,7 +333,6 @@ rotate_loop (edge back_edge, struct trace *trace, int trace_n) ...@@ -349,7 +333,6 @@ rotate_loop (edge back_edge, struct trace *trace, int trace_n)
/* Information about the best end (end after rotation) of the loop. */ /* Information about the best end (end after rotation) of the loop. */
basic_block best_bb = NULL; basic_block best_bb = NULL;
edge best_edge = NULL; edge best_edge = NULL;
int best_freq = -1;
profile_count best_count = profile_count::uninitialized (); profile_count best_count = profile_count::uninitialized ();
/* The best edge is preferred when its destination is not visited yet /* The best edge is preferred when its destination is not visited yet
or is a start block of some trace. */ or is a start block of some trace. */
...@@ -375,11 +358,8 @@ rotate_loop (edge back_edge, struct trace *trace, int trace_n) ...@@ -375,11 +358,8 @@ rotate_loop (edge back_edge, struct trace *trace, int trace_n)
|| bbd[e->dest->index].start_of_trace >= 0) || bbd[e->dest->index].start_of_trace >= 0)
{ {
/* The current edge E is also preferred. */ /* The current edge E is also preferred. */
int freq = EDGE_FREQUENCY (e); if (e->count () > best_count)
if (freq > best_freq || e->count () > best_count)
{ {
best_freq = freq;
if (e->count ().initialized_p ())
best_count = e->count (); best_count = e->count ();
best_edge = e; best_edge = e;
best_bb = bb; best_bb = bb;
...@@ -393,17 +373,14 @@ rotate_loop (edge back_edge, struct trace *trace, int trace_n) ...@@ -393,17 +373,14 @@ rotate_loop (edge back_edge, struct trace *trace, int trace_n)
{ {
/* The current edge E is preferred. */ /* The current edge E is preferred. */
is_preferred = true; is_preferred = true;
best_freq = EDGE_FREQUENCY (e);
best_count = e->count (); best_count = e->count ();
best_edge = e; best_edge = e;
best_bb = bb; best_bb = bb;
} }
else else
{ {
int freq = EDGE_FREQUENCY (e); if (!best_edge || e->count () > best_count)
if (!best_edge || freq > best_freq || e->count () > best_count)
{ {
best_freq = freq;
best_count = e->count (); best_count = e->count ();
best_edge = e; best_edge = e;
best_bb = bb; best_bb = bb;
...@@ -464,7 +441,7 @@ rotate_loop (edge back_edge, struct trace *trace, int trace_n) ...@@ -464,7 +441,7 @@ rotate_loop (edge back_edge, struct trace *trace, int trace_n)
*HEAP and store starting points for the next round into new *HEAP. */ *HEAP and store starting points for the next round into new *HEAP. */
static void static void
find_traces_1_round (int branch_th, int exec_th, gcov_type count_th, find_traces_1_round (int branch_th, profile_count count_th,
struct trace *traces, int *n_traces, int round, struct trace *traces, int *n_traces, int round,
bb_heap_t **heap, int number_of_rounds) bb_heap_t **heap, int number_of_rounds)
{ {
...@@ -494,7 +471,7 @@ find_traces_1_round (int branch_th, int exec_th, gcov_type count_th, ...@@ -494,7 +471,7 @@ find_traces_1_round (int branch_th, int exec_th, gcov_type count_th,
round. When optimizing for size, do not push to next round. */ round. When optimizing for size, do not push to next round. */
if (!for_size if (!for_size
&& push_to_next_round_p (bb, round, number_of_rounds, exec_th, && push_to_next_round_p (bb, round, number_of_rounds,
count_th)) count_th))
{ {
int key = bb_to_key (bb); int key = bb_to_key (bb);
...@@ -574,8 +551,7 @@ find_traces_1_round (int branch_th, int exec_th, gcov_type count_th, ...@@ -574,8 +551,7 @@ find_traces_1_round (int branch_th, int exec_th, gcov_type count_th,
if (!(e->flags & EDGE_CAN_FALLTHRU) || (e->flags & EDGE_COMPLEX) if (!(e->flags & EDGE_CAN_FALLTHRU) || (e->flags & EDGE_COMPLEX)
|| !prob.initialized_p () || !prob.initialized_p ()
|| ((prob.to_reg_br_prob_base () < branch_th || ((prob.to_reg_br_prob_base () < branch_th
|| EDGE_FREQUENCY (e) < exec_th || e->count () < count_th) && (!for_size)))
|| e->count ().ipa () < count_th) && (!for_size)))
continue; continue;
if (better_edge_p (bb, e, prob, freq, best_prob, best_freq, if (better_edge_p (bb, e, prob, freq, best_prob, best_freq,
...@@ -666,14 +642,12 @@ find_traces_1_round (int branch_th, int exec_th, gcov_type count_th, ...@@ -666,14 +642,12 @@ find_traces_1_round (int branch_th, int exec_th, gcov_type count_th,
bb_heap_t *which_heap = *heap; bb_heap_t *which_heap = *heap;
prob = e->probability; prob = e->probability;
freq = EDGE_FREQUENCY (e);
if (!(e->flags & EDGE_CAN_FALLTHRU) if (!(e->flags & EDGE_CAN_FALLTHRU)
|| (e->flags & EDGE_COMPLEX) || (e->flags & EDGE_COMPLEX)
|| !prob.initialized_p () || !prob.initialized_p ()
|| prob.to_reg_br_prob_base () < branch_th || prob.to_reg_br_prob_base () < branch_th
|| freq < exec_th || e->count () < count_th)
|| e->count ().ipa () < count_th)
{ {
/* When partitioning hot/cold basic blocks, make sure /* When partitioning hot/cold basic blocks, make sure
the cold blocks (and only the cold blocks) all get the cold blocks (and only the cold blocks) all get
...@@ -682,7 +656,7 @@ find_traces_1_round (int branch_th, int exec_th, gcov_type count_th, ...@@ -682,7 +656,7 @@ find_traces_1_round (int branch_th, int exec_th, gcov_type count_th,
if (!for_size && push_to_next_round_p (e->dest, round, if (!for_size && push_to_next_round_p (e->dest, round,
number_of_rounds, number_of_rounds,
exec_th, count_th)) count_th))
which_heap = new_heap; which_heap = new_heap;
} }
...@@ -707,8 +681,8 @@ find_traces_1_round (int branch_th, int exec_th, gcov_type count_th, ...@@ -707,8 +681,8 @@ find_traces_1_round (int branch_th, int exec_th, gcov_type count_th,
/* We do nothing with one basic block loops. */ /* We do nothing with one basic block loops. */
if (best_edge->dest != bb) if (best_edge->dest != bb)
{ {
if (EDGE_FREQUENCY (best_edge) if (best_edge->count ()
> 4 * best_edge->dest->count.to_frequency (cfun) / 5) > best_edge->dest->count.apply_scale (4, 5))
{ {
/* The loop has at least 4 iterations. If the loop /* The loop has at least 4 iterations. If the loop
header is not the first block of the function header is not the first block of the function
...@@ -759,9 +733,8 @@ find_traces_1_round (int branch_th, int exec_th, gcov_type count_th, ...@@ -759,9 +733,8 @@ find_traces_1_round (int branch_th, int exec_th, gcov_type count_th,
C C
where where
EDGE_FREQUENCY (AB) + EDGE_FREQUENCY (BC) AB->count () + BC->count () >= AC->count ().
>= EDGE_FREQUENCY (AC). (i.e. 2 * B->count >= AC->count )
(i.e. 2 * B->frequency >= EDGE_FREQUENCY (AC) )
Best ordering is then A B C. Best ordering is then A B C.
When optimizing for size, A B C is always the best order. When optimizing for size, A B C is always the best order.
...@@ -785,8 +758,8 @@ find_traces_1_round (int branch_th, int exec_th, gcov_type count_th, ...@@ -785,8 +758,8 @@ find_traces_1_round (int branch_th, int exec_th, gcov_type count_th,
& EDGE_CAN_FALLTHRU) & EDGE_CAN_FALLTHRU)
&& !(single_succ_edge (e->dest)->flags & EDGE_COMPLEX) && !(single_succ_edge (e->dest)->flags & EDGE_COMPLEX)
&& single_succ (e->dest) == best_edge->dest && single_succ (e->dest) == best_edge->dest
&& (2 * e->dest->count.to_frequency (cfun) && (e->dest->count.apply_scale (2, 1)
>= EDGE_FREQUENCY (best_edge) || for_size)) >= best_edge->count () || for_size))
{ {
best_edge = e; best_edge = e;
if (dump_file) if (dump_file)
...@@ -1086,15 +1059,10 @@ connect_traces (int n_traces, struct trace *traces) ...@@ -1086,15 +1059,10 @@ connect_traces (int n_traces, struct trace *traces)
int last_trace; int last_trace;
int current_pass; int current_pass;
int current_partition; int current_partition;
int freq_threshold; profile_count count_threshold;
gcov_type count_threshold;
bool for_size = optimize_function_for_size_p (cfun); bool for_size = optimize_function_for_size_p (cfun);
freq_threshold = max_entry_frequency * DUPLICATION_THRESHOLD / 1000; count_threshold = max_entry_count.apply_scale (DUPLICATION_THRESHOLD, 1000);
if (max_entry_count.to_gcov_type () < INT_MAX / 1000)
count_threshold = max_entry_count.to_gcov_type () * DUPLICATION_THRESHOLD / 1000;
else
count_threshold = max_entry_count.to_gcov_type () / 1000 * DUPLICATION_THRESHOLD;
connected = XCNEWVEC (bool, n_traces); connected = XCNEWVEC (bool, n_traces);
last_trace = -1; last_trace = -1;
...@@ -1291,8 +1259,7 @@ connect_traces (int n_traces, struct trace *traces) ...@@ -1291,8 +1259,7 @@ connect_traces (int n_traces, struct trace *traces)
&& bbd[di].start_of_trace >= 0 && bbd[di].start_of_trace >= 0
&& !connected[bbd[di].start_of_trace] && !connected[bbd[di].start_of_trace]
&& BB_PARTITION (e2->dest) == current_partition && BB_PARTITION (e2->dest) == current_partition
&& EDGE_FREQUENCY (e2) >= freq_threshold && e2->count () >= count_threshold
&& e2->count ().ipa () >= count_threshold
&& (!best2 && (!best2
|| e2->probability > best2->probability || e2->probability > best2->probability
|| (e2->probability == best2->probability || (e2->probability == best2->probability
...@@ -1317,9 +1284,8 @@ connect_traces (int n_traces, struct trace *traces) ...@@ -1317,9 +1284,8 @@ connect_traces (int n_traces, struct trace *traces)
&& BB_PARTITION (best->src) == BB_PARTITION (best->dest) && BB_PARTITION (best->src) == BB_PARTITION (best->dest)
&& copy_bb_p (best->dest, && copy_bb_p (best->dest,
optimize_edge_for_speed_p (best) optimize_edge_for_speed_p (best)
&& EDGE_FREQUENCY (best) >= freq_threshold
&& (!best->count ().initialized_p () && (!best->count ().initialized_p ()
|| best->count ().ipa () >= count_threshold))) || best->count () >= count_threshold)))
{ {
basic_block new_bb; basic_block new_bb;
...@@ -2312,7 +2278,7 @@ reorder_basic_blocks_software_trace_cache (void) ...@@ -2312,7 +2278,7 @@ reorder_basic_blocks_software_trace_cache (void)
static bool static bool
edge_order (edge e1, edge e2) edge_order (edge e1, edge e2)
{ {
return EDGE_FREQUENCY (e1) > EDGE_FREQUENCY (e2); return e1->count () > e2->count ();
} }
/* Reorder basic blocks using the "simple" algorithm. This tries to /* Reorder basic blocks using the "simple" algorithm. This tries to
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment