Commit 74644756 by Martin Liska Committed by Martin Liska

Remove cgraph_node::summary_uid and make cgraph_node::uid really unique.

2018-06-08  Martin Liska  <mliska@suse.cz>

	* cgraph.c (cgraph_node::remove): Do not recycle uid.
	* cgraph.h (symbol_table::release_symbol): Do not pass uid.
	(symbol_table::allocate_cgraph_symbol): Do not set uid.
	* passes.c (uid_hash_t): Record removed_nodes by their uids.
	(remove_cgraph_node_from_order): Use the removed_nodes set.
	(do_per_function_toporder): Likwise.
	* symbol-summary.h (symtab_insertion): Use cgraph_node::uid
	instead of summary_uid.
	(symtab_removal): Likewise.
	(symtab_duplication): Likewise.
2018-06-08  Martin Liska  <mliska@suse.cz>

	* lto-partition.c (lto_balanced_map): Use cgraph_node::uid
	instead of summary_uid.

From-SVN: r261315
parent 9d3e0adc
2018-06-08 Martin Liska <mliska@suse.cz> 2018-06-08 Martin Liska <mliska@suse.cz>
* cgraph.c (cgraph_node::remove): Do not recycle uid.
* cgraph.h (symbol_table::release_symbol): Do not pass uid.
(symbol_table::allocate_cgraph_symbol): Do not set uid.
* passes.c (uid_hash_t): Record removed_nodes by their uids.
(remove_cgraph_node_from_order): Use the removed_nodes set.
(do_per_function_toporder): Likwise.
* symbol-summary.h (symtab_insertion): Use cgraph_node::uid
instead of summary_uid.
(symtab_removal): Likewise.
(symtab_duplication): Likewise.
2018-06-08 Martin Liska <mliska@suse.cz>
* ipa-cp.c (ipcp_store_bits_results): Use * ipa-cp.c (ipcp_store_bits_results): Use
ipcp_transformation_sum. ipcp_transformation_sum.
(ipcp_store_vr_results): Likewise. (ipcp_store_vr_results): Likewise.
......
...@@ -1779,7 +1779,6 @@ void ...@@ -1779,7 +1779,6 @@ void
cgraph_node::remove (void) cgraph_node::remove (void)
{ {
cgraph_node *n; cgraph_node *n;
int uid = this->uid;
if (symtab->ipa_clones_dump_file && symtab->cloned_nodes.contains (this)) if (symtab->ipa_clones_dump_file && symtab->cloned_nodes.contains (this))
fprintf (symtab->ipa_clones_dump_file, fprintf (symtab->ipa_clones_dump_file,
...@@ -1875,7 +1874,7 @@ cgraph_node::remove (void) ...@@ -1875,7 +1874,7 @@ cgraph_node::remove (void)
call_site_hash = NULL; call_site_hash = NULL;
} }
symtab->release_symbol (this, uid); symtab->release_symbol (this);
} }
/* Likewise indicate that a node is having address taken. */ /* Likewise indicate that a node is having address taken. */
......
...@@ -1392,8 +1392,6 @@ public: ...@@ -1392,8 +1392,6 @@ public:
int count_materialization_scale; int count_materialization_scale;
/* Unique id of the node. */ /* Unique id of the node. */
int uid; int uid;
/* Summary unique id of the node. */
int summary_uid;
/* ID assigned by the profiling. */ /* ID assigned by the profiling. */
unsigned int profile_id; unsigned int profile_id;
/* Time profiler: first run of function. */ /* Time profiler: first run of function. */
...@@ -2013,7 +2011,7 @@ public: ...@@ -2013,7 +2011,7 @@ public:
friend class cgraph_node; friend class cgraph_node;
friend class cgraph_edge; friend class cgraph_edge;
symbol_table (): cgraph_max_summary_uid (1) symbol_table (): cgraph_max_uid (1)
{ {
} }
...@@ -2073,9 +2071,8 @@ public: ...@@ -2073,9 +2071,8 @@ public:
/* Allocate new callgraph node and insert it into basic data structures. */ /* Allocate new callgraph node and insert it into basic data structures. */
cgraph_node *create_empty (void); cgraph_node *create_empty (void);
/* Release a callgraph NODE with UID and put in to the list /* Release a callgraph NODE. */
of free nodes. */ void release_symbol (cgraph_node *node);
void release_symbol (cgraph_node *node, int uid);
/* Output all variables enqueued to be assembled. */ /* Output all variables enqueued to be assembled. */
bool output_variables (void); bool output_variables (void);
...@@ -2223,7 +2220,6 @@ public: ...@@ -2223,7 +2220,6 @@ public:
int cgraph_count; int cgraph_count;
int cgraph_max_uid; int cgraph_max_uid;
int cgraph_max_summary_uid;
int edges_count; int edges_count;
int edges_max_uid; int edges_max_uid;
...@@ -2586,7 +2582,7 @@ symbol_table::unregister (symtab_node *node) ...@@ -2586,7 +2582,7 @@ symbol_table::unregister (symtab_node *node)
/* Release a callgraph NODE with UID and put in to the list of free nodes. */ /* Release a callgraph NODE with UID and put in to the list of free nodes. */
inline void inline void
symbol_table::release_symbol (cgraph_node *node, int uid) symbol_table::release_symbol (cgraph_node *node)
{ {
cgraph_count--; cgraph_count--;
...@@ -2594,7 +2590,6 @@ symbol_table::release_symbol (cgraph_node *node, int uid) ...@@ -2594,7 +2590,6 @@ symbol_table::release_symbol (cgraph_node *node, int uid)
list. */ list. */
memset (node, 0, sizeof (*node)); memset (node, 0, sizeof (*node));
node->type = SYMTAB_FUNCTION; node->type = SYMTAB_FUNCTION;
node->uid = uid;
SET_NEXT_FREE_NODE (node, free_nodes); SET_NEXT_FREE_NODE (node, free_nodes);
free_nodes = node; free_nodes = node;
} }
...@@ -2612,12 +2607,9 @@ symbol_table::allocate_cgraph_symbol (void) ...@@ -2612,12 +2607,9 @@ symbol_table::allocate_cgraph_symbol (void)
free_nodes = NEXT_FREE_NODE (node); free_nodes = NEXT_FREE_NODE (node);
} }
else else
{ node = ggc_cleared_alloc<cgraph_node> ();
node = ggc_cleared_alloc<cgraph_node> ();
node->uid = cgraph_max_uid++;
}
node->summary_uid = cgraph_max_summary_uid++; node->uid = cgraph_max_uid++;
return node; return node;
} }
......
2018-06-08 Martin Liska <mliska@suse.cz> 2018-06-08 Martin Liska <mliska@suse.cz>
* lto-partition.c (lto_balanced_map): Use cgraph_node::uid
instead of summary_uid.
2018-06-08 Martin Liska <mliska@suse.cz>
* lto-partition.c (add_symbol_to_partition_1): Use get_create instead * lto-partition.c (add_symbol_to_partition_1): Use get_create instead
of get. of get.
(undo_partition): Likewise. (undo_partition): Likewise.
......
...@@ -500,12 +500,10 @@ account_reference_p (symtab_node *n1, symtab_node *n2) ...@@ -500,12 +500,10 @@ account_reference_p (symtab_node *n1, symtab_node *n2)
void void
lto_balanced_map (int n_lto_partitions, int max_partition_size) lto_balanced_map (int n_lto_partitions, int max_partition_size)
{ {
int n_nodes = 0;
int n_varpool_nodes = 0, varpool_pos = 0, best_varpool_pos = 0; int n_varpool_nodes = 0, varpool_pos = 0, best_varpool_pos = 0;
struct cgraph_node **order = XNEWVEC (cgraph_node *, symtab->cgraph_max_uid); auto_vec <cgraph_node *> order (symtab->cgraph_count);
auto_vec<cgraph_node *> noreorder; auto_vec<cgraph_node *> noreorder;
auto_vec<varpool_node *> varpool_order; auto_vec<varpool_node *> varpool_order;
int i;
struct cgraph_node *node; struct cgraph_node *node;
int64_t original_total_size, total_size = 0; int64_t original_total_size, total_size = 0;
int64_t partition_size; int64_t partition_size;
...@@ -513,7 +511,7 @@ lto_balanced_map (int n_lto_partitions, int max_partition_size) ...@@ -513,7 +511,7 @@ lto_balanced_map (int n_lto_partitions, int max_partition_size)
int last_visited_node = 0; int last_visited_node = 0;
varpool_node *vnode; varpool_node *vnode;
int64_t cost = 0, internal = 0; int64_t cost = 0, internal = 0;
int best_n_nodes = 0, best_i = 0; unsigned int best_n_nodes = 0, best_i = 0;
int64_t best_cost = -1, best_internal = 0, best_size = 0; int64_t best_cost = -1, best_internal = 0, best_size = 0;
int npartitions; int npartitions;
int current_order = -1; int current_order = -1;
...@@ -521,14 +519,14 @@ lto_balanced_map (int n_lto_partitions, int max_partition_size) ...@@ -521,14 +519,14 @@ lto_balanced_map (int n_lto_partitions, int max_partition_size)
FOR_EACH_VARIABLE (vnode) FOR_EACH_VARIABLE (vnode)
gcc_assert (!vnode->aux); gcc_assert (!vnode->aux);
FOR_EACH_DEFINED_FUNCTION (node) FOR_EACH_DEFINED_FUNCTION (node)
if (node->get_partitioning_class () == SYMBOL_PARTITION) if (node->get_partitioning_class () == SYMBOL_PARTITION)
{ {
if (node->no_reorder) if (node->no_reorder)
noreorder.safe_push (node); noreorder.safe_push (node);
else else
order[n_nodes++] = node; order.safe_push (node);
if (!node->alias) if (!node->alias)
total_size += ipa_fn_summaries->get_create (node)->size; total_size += ipa_fn_summaries->get_create (node)->size;
} }
...@@ -540,15 +538,15 @@ lto_balanced_map (int n_lto_partitions, int max_partition_size) ...@@ -540,15 +538,15 @@ lto_balanced_map (int n_lto_partitions, int max_partition_size)
unit tends to import a lot of global trees defined there. We should unit tends to import a lot of global trees defined there. We should
get better about minimizing the function bounday, but until that get better about minimizing the function bounday, but until that
things works smoother if we order in source order. */ things works smoother if we order in source order. */
qsort (order, n_nodes, sizeof (struct cgraph_node *), node_cmp); order.qsort (node_cmp);
noreorder.qsort (node_cmp); noreorder.qsort (node_cmp);
if (symtab->dump_file) if (symtab->dump_file)
{ {
for(i = 0; i < n_nodes; i++) for (unsigned i = 0; i < order.length (); i++)
fprintf (symtab->dump_file, "Balanced map symbol order:%s:%u\n", fprintf (symtab->dump_file, "Balanced map symbol order:%s:%u\n",
order[i]->name (), order[i]->tp_first_run); order[i]->name (), order[i]->tp_first_run);
for(i = 0; i < (int)noreorder.length(); i++) for (unsigned i = 0; i < noreorder.length (); i++)
fprintf (symtab->dump_file, "Balanced map symbol no_reorder:%s:%u\n", fprintf (symtab->dump_file, "Balanced map symbol no_reorder:%s:%u\n",
noreorder[i]->name (), noreorder[i]->tp_first_run); noreorder[i]->name (), noreorder[i]->tp_first_run);
} }
...@@ -577,7 +575,7 @@ lto_balanced_map (int n_lto_partitions, int max_partition_size) ...@@ -577,7 +575,7 @@ lto_balanced_map (int n_lto_partitions, int max_partition_size)
auto_vec<symtab_node *> next_nodes; auto_vec<symtab_node *> next_nodes;
for (i = 0; i < n_nodes; i++) for (unsigned i = 0; i < order.length (); i++)
{ {
if (symbol_partitioned_p (order[i])) if (symbol_partitioned_p (order[i]))
continue; continue;
...@@ -792,9 +790,9 @@ lto_balanced_map (int n_lto_partitions, int max_partition_size) ...@@ -792,9 +790,9 @@ lto_balanced_map (int n_lto_partitions, int max_partition_size)
"Partition insns: %i (want %" PRId64 ")\n", "Partition insns: %i (want %" PRId64 ")\n",
partition->insns, partition_size); partition->insns, partition_size);
/* When we are finished, avoid creating empty partition. */ /* When we are finished, avoid creating empty partition. */
while (i < n_nodes - 1 && symbol_partitioned_p (order[i + 1])) while (i < order.length () - 1 && symbol_partitioned_p (order[i + 1]))
i++; i++;
if (i == n_nodes - 1) if (i == order.length () - 1)
break; break;
total_size -= partition->insns; total_size -= partition->insns;
partition = new_partition (""); partition = new_partition ("");
...@@ -842,8 +840,6 @@ lto_balanced_map (int n_lto_partitions, int max_partition_size) ...@@ -842,8 +840,6 @@ lto_balanced_map (int n_lto_partitions, int max_partition_size)
gcc_assert (next_nodes.length () || npartitions != 1 || !best_cost || best_cost == -1); gcc_assert (next_nodes.length () || npartitions != 1 || !best_cost || best_cost == -1);
add_sorted_nodes (next_nodes, partition); add_sorted_nodes (next_nodes, partition);
free (order);
if (symtab->dump_file) if (symtab->dump_file)
{ {
fprintf (symtab->dump_file, "\nPartition sizes:\n"); fprintf (symtab->dump_file, "\nPartition sizes:\n");
...@@ -854,7 +850,7 @@ lto_balanced_map (int n_lto_partitions, int max_partition_size) ...@@ -854,7 +850,7 @@ lto_balanced_map (int n_lto_partitions, int max_partition_size)
ltrans_partition p = ltrans_partitions[i]; ltrans_partition p = ltrans_partitions[i];
fprintf (symtab->dump_file, "partition %d contains %d (%2.2f%%)" fprintf (symtab->dump_file, "partition %d contains %d (%2.2f%%)"
" symbols and %d (%2.2f%%) insns\n", i, p->symbols, " symbols and %d (%2.2f%%) insns\n", i, p->symbols,
100.0 * p->symbols / n_nodes, p->insns, 100.0 * p->symbols / order.length (), p->insns,
100.0 * p->insns / original_total_size); 100.0 * p->insns / original_total_size);
} }
......
...@@ -1635,22 +1635,16 @@ do_per_function (void (*callback) (function *, void *data), void *data) ...@@ -1635,22 +1635,16 @@ do_per_function (void (*callback) (function *, void *data), void *data)
static int nnodes; static int nnodes;
static GTY ((length ("nnodes"))) cgraph_node **order; static GTY ((length ("nnodes"))) cgraph_node **order;
#define uid_hash_t hash_set<int_hash <int, 0, -1>>
/* Hook called when NODE is removed and therefore should be /* Hook called when NODE is removed and therefore should be
excluded from order vector. DATA is an array of integers. excluded from order vector. DATA is a hash set with removed nodes. */
DATA[0] holds max index it may be accessed by. For cgraph
node DATA[node->uid + 1] holds index of this node in order
vector. */
static void static void
remove_cgraph_node_from_order (cgraph_node *node, void *data) remove_cgraph_node_from_order (cgraph_node *node, void *data)
{ {
int *order_idx = (int *)data; uid_hash_t *removed_nodes = (uid_hash_t *)data;
removed_nodes->add (node->uid);
if (node->uid >= order_idx[0])
return;
int idx = order_idx[node->uid + 1];
if (idx >= 0 && idx < nnodes && order[idx] == node)
order[idx] = NULL;
} }
/* If we are in IPA mode (i.e., current_function_decl is NULL), call /* If we are in IPA mode (i.e., current_function_decl is NULL), call
...@@ -1667,30 +1661,23 @@ do_per_function_toporder (void (*callback) (function *, void *data), void *data) ...@@ -1667,30 +1661,23 @@ do_per_function_toporder (void (*callback) (function *, void *data), void *data)
else else
{ {
cgraph_node_hook_list *hook; cgraph_node_hook_list *hook;
int *order_idx; uid_hash_t removed_nodes;
gcc_assert (!order); gcc_assert (!order);
order = ggc_vec_alloc<cgraph_node *> (symtab->cgraph_count); order = ggc_vec_alloc<cgraph_node *> (symtab->cgraph_count);
order_idx = XALLOCAVEC (int, symtab->cgraph_max_uid + 1);
memset (order_idx + 1, -1, sizeof (int) * symtab->cgraph_max_uid);
order_idx[0] = symtab->cgraph_max_uid;
nnodes = ipa_reverse_postorder (order); nnodes = ipa_reverse_postorder (order);
for (i = nnodes - 1; i >= 0; i--) for (i = nnodes - 1; i >= 0; i--)
{ order[i]->process = 1;
order[i]->process = 1;
order_idx[order[i]->uid + 1] = i;
}
hook = symtab->add_cgraph_removal_hook (remove_cgraph_node_from_order, hook = symtab->add_cgraph_removal_hook (remove_cgraph_node_from_order,
order_idx); &removed_nodes);
for (i = nnodes - 1; i >= 0; i--) for (i = nnodes - 1; i >= 0; i--)
{ {
cgraph_node *node = order[i];
/* Function could be inlined and removed as unreachable. */ /* Function could be inlined and removed as unreachable. */
if (!order[i]) if (node == NULL || removed_nodes.contains (node->uid))
continue; continue;
struct cgraph_node *node = order[i];
/* Allow possibly removed nodes to be garbage collected. */ /* Allow possibly removed nodes to be garbage collected. */
order[i] = NULL; order[i] = NULL;
node->process = 0; node->process = 0;
......
...@@ -90,13 +90,13 @@ public: ...@@ -90,13 +90,13 @@ public:
does not exist it will be created. */ does not exist it will be created. */
T* get_create (cgraph_node *node) T* get_create (cgraph_node *node)
{ {
return get (node->summary_uid, true); return get (node->uid, true);
} }
/* Getter for summary callgraph node pointer. */ /* Getter for summary callgraph node pointer. */
T* get (cgraph_node *node) T* get (cgraph_node *node)
{ {
return get (node->summary_uid, false); return get (node->uid, false);
} }
/* Return number of elements handled by data structure. */ /* Return number of elements handled by data structure. */
...@@ -108,7 +108,7 @@ public: ...@@ -108,7 +108,7 @@ public:
/* Return true if a summary for the given NODE already exists. */ /* Return true if a summary for the given NODE already exists. */
bool exists (cgraph_node *node) bool exists (cgraph_node *node)
{ {
return m_map.get (node->summary_uid) != NULL; return m_map.get (node->uid) != NULL;
} }
/* Enable insertion hook invocation. */ /* Enable insertion hook invocation. */
...@@ -216,7 +216,7 @@ template <typename T> ...@@ -216,7 +216,7 @@ template <typename T>
void void
function_summary<T *>::symtab_insertion (cgraph_node *node, void *data) function_summary<T *>::symtab_insertion (cgraph_node *node, void *data)
{ {
gcc_checking_assert (node->summary_uid); gcc_checking_assert (node->uid);
function_summary *summary = (function_summary <T *> *) (data); function_summary *summary = (function_summary <T *> *) (data);
if (summary->m_insertion_enabled) if (summary->m_insertion_enabled)
...@@ -227,11 +227,11 @@ template <typename T> ...@@ -227,11 +227,11 @@ template <typename T>
void void
function_summary<T *>::symtab_removal (cgraph_node *node, void *data) function_summary<T *>::symtab_removal (cgraph_node *node, void *data)
{ {
gcc_checking_assert (node->summary_uid); gcc_checking_assert (node->uid);
function_summary *summary = (function_summary <T *> *) (data); function_summary *summary = (function_summary <T *> *) (data);
int summary_uid = node->summary_uid; int uid = node->uid;
T **v = summary->m_map.get (summary_uid); T **v = summary->m_map.get (uid);
if (v) if (v)
{ {
...@@ -240,7 +240,7 @@ function_summary<T *>::symtab_removal (cgraph_node *node, void *data) ...@@ -240,7 +240,7 @@ function_summary<T *>::symtab_removal (cgraph_node *node, void *data)
if (!summary->m_ggc) if (!summary->m_ggc)
delete (*v); delete (*v);
summary->m_map.remove (summary_uid); summary->m_map.remove (uid);
} }
} }
...@@ -256,7 +256,7 @@ function_summary<T *>::symtab_duplication (cgraph_node *node, ...@@ -256,7 +256,7 @@ function_summary<T *>::symtab_duplication (cgraph_node *node,
{ {
/* This load is necessary, because we insert a new value! */ /* This load is necessary, because we insert a new value! */
T *duplicate = summary->allocate_new (); T *duplicate = summary->allocate_new ();
summary->m_map.put (node2->summary_uid, duplicate); summary->m_map.put (node2->uid, duplicate);
summary->duplicate (node, node2, v, duplicate); summary->duplicate (node, node2, v, duplicate);
} }
} }
......
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