Commit 4700dd70 by Eric Botcazou Committed by Eric Botcazou

bb-reorder.c: Clarify a few points in the head comment and fix long lines in other comments.

	* bb-reorder.c: Clarify a few points in the head comment and fix
	long lines in other comments.
	(find_traces): Fix long line.
	(find_traces_1_round): Likewise.
	(better_edge_p): Likewise.
	(connect_traces): Likewise.
	(duplicate_computed_gotos): Likewise.
	(find_rarely_executed_basic_blocks_and_cr): Remove trailing spaces.
	(fix_up_fall_thru_edges): Fix formatting.

From-SVN: r190979
parent 18eb76eb
2012-09-05 Eric Botcazou <ebotcazou@adacore.com>
* bb-reorder.c: Clarify a few points in the head comment and fix
long lines in other comments.
(find_traces): Fix long line.
(find_traces_1_round): Likewise.
(better_edge_p): Likewise.
(connect_traces): Likewise.
(duplicate_computed_gotos): Likewise.
(find_rarely_executed_basic_blocks_and_cr): Remove trailing spaces.
(fix_up_fall_thru_edges): Fix formatting.
2012-09-05 Richard Guenther <rguenther@suse.de> 2012-09-05 Richard Guenther <rguenther@suse.de>
PR tree-optimization/46590 PR tree-optimization/46590
......
...@@ -20,41 +20,41 @@ ...@@ -20,41 +20,41 @@
/* This (greedy) algorithm constructs traces in several rounds. /* This (greedy) algorithm constructs traces in several rounds.
The construction starts from "seeds". The seed for the first round The construction starts from "seeds". The seed for the first round
is the entry point of function. When there are more than one seed is the entry point of the function. When there are more than one seed,
that one is selected first that has the lowest key in the heap the one with the lowest key in the heap is selected first (see bb_to_key).
(see function bb_to_key). Then the algorithm repeatedly adds the most Then the algorithm repeatedly adds the most probable successor to the end
probable successor to the end of a trace. Finally it connects the traces. of a trace. Finally it connects the traces.
There are two parameters: Branch Threshold and Exec Threshold. There are two parameters: Branch Threshold and Exec Threshold.
If the edge to a successor of the actual basic block is lower than If the probability of an edge to a successor of the current basic block is
Branch Threshold or the frequency of the successor is lower than lower than Branch Threshold or its frequency is lower than Exec Threshold,
Exec Threshold the successor will be the seed in one of the next rounds. then the successor will be the seed in one of the next rounds.
Each round has these parameters lower than the previous one. Each round has these parameters lower than the previous one.
The last round has to have these parameters set to zero The last round has to have these parameters set to zero so that the
so that the remaining blocks are picked up. remaining blocks are picked up.
The algorithm selects the most probable successor from all unvisited The algorithm selects the most probable successor from all unvisited
successors and successors that have been added to this trace. successors and successors that have been added to this trace.
The other successors (that has not been "sent" to the next round) will be The other successors (that has not been "sent" to the next round) will be
other seeds for this round and the secondary traces will start in them. other seeds for this round and the secondary traces will start from them.
If the successor has not been visited in this trace it is added to the trace If the successor has not been visited in this trace, it is added to the
(however, there is some heuristic for simple branches). trace (however, there is some heuristic for simple branches).
If the successor has been visited in this trace the loop has been found. If the successor has been visited in this trace, a loop has been found.
If the loop has many iterations the loop is rotated so that the If the loop has many iterations, the loop is rotated so that the source
source block of the most probable edge going out from the loop block of the most probable edge going out of the loop is the last block
is the last block of the trace. of the trace.
If the loop has few iterations and there is no edge from the last block of If the loop has few iterations and there is no edge from the last block of
the loop going out from loop the loop header is duplicated. the loop going out of the loop, the loop header is duplicated.
Finally, the construction of the trace is terminated.
When connecting traces it first checks whether there is an edge from the When connecting traces, the algorithm first checks whether there is an edge
last block of one trace to the first block of another trace. from the last block of a trace to the first block of another trace.
When there are still some unconnected traces it checks whether there exists When there are still some unconnected traces it checks whether there exists
a basic block BB such that BB is a successor of the last bb of one trace a basic block BB such that BB is a successor of the last block of a trace
and BB is a predecessor of the first block of another trace. In this case, and BB is a predecessor of the first block of another trace. In this case,
BB is duplicated and the traces are connected through this duplicate. BB is duplicated, added at the end of the first trace and the traces are
connected through it.
The rest of traces are simply connected so there will be a jump to the The rest of traces are simply connected so there will be a jump to the
beginning of the rest of trace. beginning of the rest of traces.
References: References:
...@@ -89,11 +89,11 @@ ...@@ -89,11 +89,11 @@
/* The number of rounds. In most cases there will only be 4 rounds, but /* The number of rounds. In most cases there will only be 4 rounds, but
when partitioning hot and cold basic blocks into separate sections of when partitioning hot and cold basic blocks into separate sections of
the .o file there will be an extra round.*/ the object file there will be an extra round. */
#define N_ROUNDS 5 #define N_ROUNDS 5
/* Stubs in case we don't have a return insn. /* Stubs in case we don't have a return insn.
We have to check at runtime too, not only compiletime. */ We have to check at run time too, not only compile time. */
#ifndef HAVE_return #ifndef HAVE_return
#define HAVE_return 0 #define HAVE_return 0
...@@ -122,10 +122,10 @@ static int exec_threshold[N_ROUNDS] = {500, 200, 50, 0, 0}; ...@@ -122,10 +122,10 @@ static int exec_threshold[N_ROUNDS] = {500, 200, 50, 0, 0};
/* Structure to hold needed information for each basic block. */ /* Structure to hold needed information for each basic block. */
typedef struct bbro_basic_block_data_def typedef struct bbro_basic_block_data_def
{ {
/* Which trace is the bb start of (-1 means it is not a start of a trace). */ /* Which trace is the bb start of (-1 means it is not a start of any). */
int start_of_trace; int start_of_trace;
/* Which trace is the bb end of (-1 means it is not an end of a trace). */ /* Which trace is the bb end of (-1 means it is not an end of any). */
int end_of_trace; int end_of_trace;
/* Which trace is the bb in? */ /* Which trace is the bb in? */
...@@ -179,7 +179,8 @@ static void find_traces_1_round (int, int, gcov_type, struct trace *, int *, ...@@ -179,7 +179,8 @@ static void find_traces_1_round (int, int, gcov_type, struct trace *, int *,
int, fibheap_t *, int); int, fibheap_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 fibheapkey_t bb_to_key (basic_block); static fibheapkey_t bb_to_key (basic_block);
static bool better_edge_p (const_basic_block, const_edge, int, int, int, int, const_edge); static bool better_edge_p (const_basic_block, const_edge, int, int, int, int,
const_edge);
static void connect_traces (int, 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); static bool push_to_next_round_p (const_basic_block, int, int, int, gcov_type);
...@@ -296,7 +297,9 @@ find_traces (int *n_traces, struct trace *traces) ...@@ -296,7 +297,9 @@ find_traces (int *n_traces, struct trace *traces)
basic_block bb; basic_block bb;
fprintf (dump_file, "Trace %d (round %d): ", i + 1, fprintf (dump_file, "Trace %d (round %d): ", i + 1,
traces[i].round + 1); traces[i].round + 1);
for (bb = traces[i].first; bb != traces[i].last; bb = (basic_block) bb->aux) for (bb = traces[i].first;
bb != traces[i].last;
bb = (basic_block) bb->aux)
fprintf (dump_file, "%d [%d] ", bb->index, bb->frequency); fprintf (dump_file, "%d [%d] ", bb->index, bb->frequency);
fprintf (dump_file, "%d [%d]\n", bb->index, bb->frequency); fprintf (dump_file, "%d [%d]\n", bb->index, bb->frequency);
} }
...@@ -421,13 +424,13 @@ rotate_loop (edge back_edge, struct trace *trace, int trace_n) ...@@ -421,13 +424,13 @@ rotate_loop (edge back_edge, struct trace *trace, int trace_n)
return best_bb; return best_bb;
} }
/* One round of finding traces. Find traces for BRANCH_TH and EXEC_TH i.e. do /* One round of finding traces. Find traces for BRANCH_TH and EXEC_TH i.e. do
not include basic blocks their probability is lower than BRANCH_TH or their not include basic blocks whose probability is lower than BRANCH_TH or whose
frequency is lower than EXEC_TH into traces (or count is lower than frequency is lower than EXEC_TH into traces (or whose count is lower than
COUNT_TH). It stores the new traces into TRACES and modifies the number of COUNT_TH). Store the new traces into TRACES and modify the number of
traces *N_TRACES. Sets the round (which the trace belongs to) to ROUND. It traces *N_TRACES. Set the round (which the trace belongs to) to ROUND.
expects that starting basic blocks are in *HEAP and at the end it deletes The function expects starting basic blocks to be in *HEAP and will delete
*HEAP and stores 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, int exec_th, gcov_type count_th,
...@@ -453,7 +456,7 @@ find_traces_1_round (int branch_th, int exec_th, gcov_type count_th, ...@@ -453,7 +456,7 @@ find_traces_1_round (int branch_th, int exec_th, gcov_type count_th,
if (dump_file) if (dump_file)
fprintf (dump_file, "Getting bb %d\n", bb->index); fprintf (dump_file, "Getting bb %d\n", bb->index);
/* If the BB's frequency is too low send BB to the next round. When /* If the BB's frequency is too low, send BB to the next round. When
partitioning hot/cold blocks into separate sections, make sure all partitioning hot/cold blocks into separate sections, make sure all
the cold blocks (and ONLY the cold blocks) go into the (extra) final the cold blocks (and ONLY the cold blocks) go into the (extra) final
round. */ round. */
...@@ -653,7 +656,8 @@ find_traces_1_round (int branch_th, int exec_th, gcov_type count_th, ...@@ -653,7 +656,8 @@ find_traces_1_round (int branch_th, int exec_th, gcov_type count_th,
if (single_succ_p (bb) if (single_succ_p (bb)
&& copy_bb_p (best_edge->dest, && copy_bb_p (best_edge->dest,
optimize_edge_for_speed_p (best_edge))) optimize_edge_for_speed_p
(best_edge)))
{ {
bb = copy_bb (best_edge->dest, best_edge, bb, bb = copy_bb (best_edge->dest, best_edge, bb,
*n_traces); *n_traces);
...@@ -843,6 +847,7 @@ bb_to_key (basic_block bb) ...@@ -843,6 +847,7 @@ bb_to_key (basic_block bb)
if (priority) if (priority)
/* The block with priority should have significantly lower key. */ /* The block with priority should have significantly lower key. */
return -(100 * BB_FREQ_MAX + 100 * priority + bb->frequency); return -(100 * BB_FREQ_MAX + 100 * priority + bb->frequency);
return -bb->frequency; return -bb->frequency;
} }
...@@ -854,8 +859,8 @@ bb_to_key (basic_block bb) ...@@ -854,8 +859,8 @@ bb_to_key (basic_block bb)
BEST_PROB; similarly for frequency. */ BEST_PROB; similarly for frequency. */
static bool static bool
better_edge_p (const_basic_block bb, const_edge e, int prob, int freq, int best_prob, better_edge_p (const_basic_block bb, const_edge e, int prob, int freq,
int best_freq, const_edge cur_best_edge) int best_prob, int best_freq, const_edge cur_best_edge)
{ {
bool is_better_edge; bool is_better_edge;
...@@ -1081,9 +1086,9 @@ connect_traces (int n_traces, struct trace *traces) ...@@ -1081,9 +1086,9 @@ connect_traces (int n_traces, struct trace *traces)
&& !(e2->flags & EDGE_COMPLEX) && !(e2->flags & EDGE_COMPLEX)
&& 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) && EDGE_FREQUENCY (e2) >= freq_threshold
&& (e2->count >= count_threshold) && e2->count >= count_threshold
&& (!best2 && (!best2
|| e2->probability > best2->probability || e2->probability > best2->probability
|| (e2->probability == best2->probability || (e2->probability == best2->probability
...@@ -1361,7 +1366,7 @@ find_rarely_executed_basic_blocks_and_crossing_edges (void) ...@@ -1361,7 +1366,7 @@ find_rarely_executed_basic_blocks_and_crossing_edges (void)
FOR_EACH_EDGE (e, ei, bb->succs) FOR_EACH_EDGE (e, ei, bb->succs)
{ {
unsigned int flags = e->flags; unsigned int flags = e->flags;
/* We should never have EDGE_CROSSING set yet. */ /* We should never have EDGE_CROSSING set yet. */
gcc_checking_assert ((flags & EDGE_CROSSING) == 0); gcc_checking_assert ((flags & EDGE_CROSSING) == 0);
...@@ -1591,13 +1596,13 @@ fix_up_fall_thru_edges (void) ...@@ -1591,13 +1596,13 @@ fix_up_fall_thru_edges (void)
block are crossing edges. Here we will fix up the block are crossing edges. Here we will fix up the
fall through edge. The jump edge will be taken care fall through edge. The jump edge will be taken care
of later. The EDGE_CROSSING flag of fall_thru edge of later. The EDGE_CROSSING flag of fall_thru edge
is unset before the call to force_nonfallthru is unset before the call to force_nonfallthru
function because if a new basic-block is created function because if a new basic-block is created
this edge remains in the current section boundary this edge remains in the current section boundary
while the edge between new_bb and the fall_thru->dest while the edge between new_bb and the fall_thru->dest
becomes EDGE_CROSSING. */ becomes EDGE_CROSSING. */
fall_thru->flags &= ~EDGE_CROSSING; fall_thru->flags &= ~EDGE_CROSSING;
new_bb = force_nonfallthru (fall_thru); new_bb = force_nonfallthru (fall_thru);
if (new_bb) if (new_bb)
...@@ -1611,12 +1616,12 @@ fix_up_fall_thru_edges (void) ...@@ -1611,12 +1616,12 @@ fix_up_fall_thru_edges (void)
BB_COPY_PARTITION (new_bb, cur_bb); BB_COPY_PARTITION (new_bb, cur_bb);
single_succ_edge (new_bb)->flags |= EDGE_CROSSING; single_succ_edge (new_bb)->flags |= EDGE_CROSSING;
} }
else else
{ {
/* If a new basic-block was not created; restore /* If a new basic-block was not created; restore
the EDGE_CROSSING flag. */ the EDGE_CROSSING flag. */
fall_thru->flags |= EDGE_CROSSING; fall_thru->flags |= EDGE_CROSSING;
} }
/* Add barrier after new jump */ /* Add barrier after new jump */
emit_barrier_after_bb (new_bb ? new_bb : cur_bb); emit_barrier_after_bb (new_bb ? new_bb : cur_bb);
...@@ -2132,7 +2137,8 @@ duplicate_computed_gotos (void) ...@@ -2132,7 +2137,8 @@ duplicate_computed_gotos (void)
if (uncond_jump_length == 0) if (uncond_jump_length == 0)
uncond_jump_length = get_uncond_jump_length (); uncond_jump_length = get_uncond_jump_length ();
max_size = uncond_jump_length * PARAM_VALUE (PARAM_MAX_GOTO_DUPLICATION_INSNS); max_size
= uncond_jump_length * PARAM_VALUE (PARAM_MAX_GOTO_DUPLICATION_INSNS);
candidates = BITMAP_ALLOC (NULL); candidates = BITMAP_ALLOC (NULL);
/* Look for blocks that end in a computed jump, and see if such blocks /* Look for blocks that end in a computed jump, and see if such blocks
......
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