Commit 8d261514 by Martin Liska Committed by Martin Liska

fibonacci_heap is used for bb-reoder purpose.

	* bb-reorder.c (mark_bb_visited): New fibonacci_heap is used.
	(find_traces): Likewise.
	(find_traces_1_round): Likewise.

From-SVN: r217721
parent 4a910049
2014-11-18 Martin Liska <mliska@suse.cz> 2014-11-18 Martin Liska <mliska@suse.cz>
* bb-reorder.c (mark_bb_visited): New fibonacci_heap is used.
(find_traces): Likewise.
(find_traces_1_round): Likewise.
2014-11-18 Martin Liska <mliska@suse.cz>
* fibonacci_heap.h: New file. * fibonacci_heap.h: New file.
(fibonacci_heap::insert): Created from fibheap_insert. (fibonacci_heap::insert): Created from fibheap_insert.
(fibonacci_heap::empty): Created from fibheap_empty. (fibonacci_heap::empty): Created from fibheap_empty.
...@@ -87,7 +87,6 @@ ...@@ -87,7 +87,6 @@
#include "regs.h" #include "regs.h"
#include "flags.h" #include "flags.h"
#include "output.h" #include "output.h"
#include "fibheap.h"
#include "target.h" #include "target.h"
#include "hashtab.h" #include "hashtab.h"
#include "hash-set.h" #include "hash-set.h"
...@@ -120,6 +119,7 @@ ...@@ -120,6 +119,7 @@
#include "ipa-ref.h" #include "ipa-ref.h"
#include "cgraph.h" #include "cgraph.h"
#include "except.h" #include "except.h"
#include "fibonacci_heap.h"
/* 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
...@@ -153,6 +153,9 @@ static const int exec_threshold[N_ROUNDS] = {500, 200, 50, 0, 0}; ...@@ -153,6 +153,9 @@ static const int exec_threshold[N_ROUNDS] = {500, 200, 50, 0, 0};
block the edge destination is not duplicated while connecting traces. */ block the edge destination is not duplicated while connecting traces. */
#define DUPLICATION_THRESHOLD 100 #define DUPLICATION_THRESHOLD 100
typedef fibonacci_heap <long, basic_block_def> bb_heap_t;
typedef fibonacci_node <long, basic_block_def> bb_heap_node_t;
/* 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
{ {
...@@ -169,10 +172,10 @@ typedef struct bbro_basic_block_data_def ...@@ -169,10 +172,10 @@ typedef struct bbro_basic_block_data_def
int visited; int visited;
/* Which heap is BB in (if any)? */ /* Which heap is BB in (if any)? */
fibheap_t heap; bb_heap_t *heap;
/* Which heap node is BB in (if any)? */ /* Which heap node is BB in (if any)? */
fibnode_t node; bb_heap_node_t *node;
} bbro_basic_block_data; } bbro_basic_block_data;
/* The current size of the following dynamic array. */ /* The current size of the following dynamic array. */
...@@ -210,9 +213,9 @@ static void find_traces (int *, struct trace *); ...@@ -210,9 +213,9 @@ static void find_traces (int *, struct trace *);
static basic_block rotate_loop (edge, struct trace *, int); static basic_block rotate_loop (edge, struct trace *, int);
static void mark_bb_visited (basic_block, int); static void mark_bb_visited (basic_block, int);
static void find_traces_1_round (int, int, gcov_type, struct trace *, int *, static void find_traces_1_round (int, int, gcov_type, struct trace *, int *,
int, fibheap_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 fibheapkey_t bb_to_key (basic_block); static long bb_to_key (basic_block);
static bool better_edge_p (const_basic_block, const_edge, int, int, int, int, static bool better_edge_p (const_basic_block, const_edge, int, int, int, int,
const_edge); const_edge);
static bool connect_better_edge_p (const_edge, bool, int, const_edge, static bool connect_better_edge_p (const_edge, bool, int, const_edge,
...@@ -238,7 +241,7 @@ mark_bb_visited (basic_block bb, int trace) ...@@ -238,7 +241,7 @@ mark_bb_visited (basic_block bb, int trace)
bbd[bb->index].visited = trace; bbd[bb->index].visited = trace;
if (bbd[bb->index].heap) if (bbd[bb->index].heap)
{ {
fibheap_delete_node (bbd[bb->index].heap, bbd[bb->index].node); bbd[bb->index].heap->delete_node (bbd[bb->index].node);
bbd[bb->index].heap = NULL; bbd[bb->index].heap = NULL;
bbd[bb->index].node = NULL; bbd[bb->index].node = NULL;
} }
...@@ -283,7 +286,7 @@ find_traces (int *n_traces, struct trace *traces) ...@@ -283,7 +286,7 @@ find_traces (int *n_traces, struct trace *traces)
int number_of_rounds; int number_of_rounds;
edge e; edge e;
edge_iterator ei; edge_iterator ei;
fibheap_t heap; bb_heap_t *heap = new bb_heap_t (LONG_MIN);
/* Add one extra round of trace collection when partitioning hot/cold /* Add one extra round of trace collection when partitioning hot/cold
basic blocks into separate sections. The last round is for all the basic blocks into separate sections. The last round is for all the
...@@ -292,14 +295,12 @@ find_traces (int *n_traces, struct trace *traces) ...@@ -292,14 +295,12 @@ 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. */
heap = fibheap_new ();
max_entry_frequency = 0; max_entry_frequency = 0;
max_entry_count = 0; max_entry_count = 0;
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 = fibheap_insert (heap, bb_to_key (e->dest), bbd[e->dest->index].node = heap->insert (bb_to_key (e->dest), e->dest);
e->dest);
if (e->dest->frequency > max_entry_frequency) if (e->dest->frequency > max_entry_frequency)
max_entry_frequency = e->dest->frequency; max_entry_frequency = e->dest->frequency;
if (e->dest->count > max_entry_count) if (e->dest->count > max_entry_count)
...@@ -324,7 +325,7 @@ find_traces (int *n_traces, struct trace *traces) ...@@ -324,7 +325,7 @@ find_traces (int *n_traces, struct trace *traces)
count_threshold, traces, n_traces, i, &heap, count_threshold, traces, n_traces, i, &heap,
number_of_rounds); number_of_rounds);
} }
fibheap_delete (heap); delete heap;
if (dump_file) if (dump_file)
{ {
...@@ -470,22 +471,22 @@ rotate_loop (edge back_edge, struct trace *trace, int trace_n) ...@@ -470,22 +471,22 @@ rotate_loop (edge back_edge, struct trace *trace, int trace_n)
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,
struct trace *traces, int *n_traces, int round, struct trace *traces, int *n_traces, int round,
fibheap_t *heap, int number_of_rounds) bb_heap_t **heap, int number_of_rounds)
{ {
/* Heap for discarded basic blocks which are possible starting points for /* Heap for discarded basic blocks which are possible starting points for
the next round. */ the next round. */
fibheap_t new_heap = fibheap_new (); bb_heap_t *new_heap = new bb_heap_t (LONG_MIN);
bool for_size = optimize_function_for_size_p (cfun); bool for_size = optimize_function_for_size_p (cfun);
while (!fibheap_empty (*heap)) while (!(*heap)->empty ())
{ {
basic_block bb; basic_block bb;
struct trace *trace; struct trace *trace;
edge best_edge, e; edge best_edge, e;
fibheapkey_t key; long key;
edge_iterator ei; edge_iterator ei;
bb = (basic_block) fibheap_extract_min (*heap); bb = (*heap)->extract_min ();
bbd[bb->index].heap = NULL; bbd[bb->index].heap = NULL;
bbd[bb->index].node = NULL; bbd[bb->index].node = NULL;
...@@ -503,7 +504,7 @@ find_traces_1_round (int branch_th, int exec_th, gcov_type count_th, ...@@ -503,7 +504,7 @@ find_traces_1_round (int branch_th, int exec_th, gcov_type count_th,
{ {
int key = bb_to_key (bb); int key = bb_to_key (bb);
bbd[bb->index].heap = new_heap; bbd[bb->index].heap = new_heap;
bbd[bb->index].node = fibheap_insert (new_heap, key, bb); bbd[bb->index].node = new_heap->insert (key, bb);
if (dump_file) if (dump_file)
fprintf (dump_file, fprintf (dump_file,
...@@ -633,23 +634,23 @@ find_traces_1_round (int branch_th, int exec_th, gcov_type count_th, ...@@ -633,23 +634,23 @@ find_traces_1_round (int branch_th, int exec_th, gcov_type count_th,
if (bbd[e->dest->index].heap) if (bbd[e->dest->index].heap)
{ {
/* E->DEST is already in some heap. */ /* E->DEST is already in some heap. */
if (key != bbd[e->dest->index].node->key) if (key != bbd[e->dest->index].node->get_key ())
{ {
if (dump_file) if (dump_file)
{ {
fprintf (dump_file, fprintf (dump_file,
"Changing key for bb %d from %ld to %ld.\n", "Changing key for bb %d from %ld to %ld.\n",
e->dest->index, e->dest->index,
(long) bbd[e->dest->index].node->key, (long) bbd[e->dest->index].node->get_key (),
key); key);
} }
fibheap_replace_key (bbd[e->dest->index].heap, bbd[e->dest->index].heap->decrease_key
bbd[e->dest->index].node, key); (bbd[e->dest->index].node, key);
} }
} }
else else
{ {
fibheap_t which_heap = *heap; bb_heap_t *which_heap = *heap;
prob = e->probability; prob = e->probability;
freq = EDGE_FREQUENCY (e); freq = EDGE_FREQUENCY (e);
...@@ -671,8 +672,7 @@ find_traces_1_round (int branch_th, int exec_th, gcov_type count_th, ...@@ -671,8 +672,7 @@ find_traces_1_round (int branch_th, int exec_th, gcov_type count_th,
} }
bbd[e->dest->index].heap = which_heap; bbd[e->dest->index].heap = which_heap;
bbd[e->dest->index].node = fibheap_insert (which_heap, bbd[e->dest->index].node = which_heap->insert (key, e->dest);
key, e->dest);
if (dump_file) if (dump_file)
{ {
...@@ -803,24 +803,23 @@ find_traces_1_round (int branch_th, int exec_th, gcov_type count_th, ...@@ -803,24 +803,23 @@ find_traces_1_round (int branch_th, int exec_th, gcov_type count_th,
if (bbd[e->dest->index].heap) if (bbd[e->dest->index].heap)
{ {
key = bb_to_key (e->dest); key = bb_to_key (e->dest);
if (key != bbd[e->dest->index].node->key) if (key != bbd[e->dest->index].node->get_key ())
{ {
if (dump_file) if (dump_file)
{ {
fprintf (dump_file, fprintf (dump_file,
"Changing key for bb %d from %ld to %ld.\n", "Changing key for bb %d from %ld to %ld.\n",
e->dest->index, e->dest->index,
(long) bbd[e->dest->index].node->key, key); (long) bbd[e->dest->index].node->get_key (), key);
} }
fibheap_replace_key (bbd[e->dest->index].heap, bbd[e->dest->index].heap->decrease_key
bbd[e->dest->index].node, (bbd[e->dest->index].node, key);
key);
} }
} }
} }
} }
fibheap_delete (*heap); delete (*heap);
/* "Return" the new heap. */ /* "Return" the new heap. */
*heap = new_heap; *heap = new_heap;
...@@ -885,7 +884,7 @@ copy_bb (basic_block old_bb, edge e, basic_block bb, int trace) ...@@ -885,7 +884,7 @@ copy_bb (basic_block old_bb, edge e, basic_block bb, int trace)
/* Compute and return the key (for the heap) of the basic block BB. */ /* Compute and return the key (for the heap) of the basic block BB. */
static fibheapkey_t static long
bb_to_key (basic_block bb) bb_to_key (basic_block bb)
{ {
edge e; edge e;
......
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