summaryrefslogtreecommitdiff
path: root/gcc/varpool.c
diff options
context:
space:
mode:
authorhubicka <hubicka@138bc75d-0d04-0410-961f-82ee72b054a4>2010-04-29 07:10:38 +0000
committerhubicka <hubicka@138bc75d-0d04-0410-961f-82ee72b054a4>2010-04-29 07:10:38 +0000
commit0cddb138341aafca38ae8d099c98750b5b34b8b2 (patch)
tree517f6bc2231e5c3e319637f9c9277e4cc2e99ffb /gcc/varpool.c
parent772046653bc34fc28305a3162b8759b09c96191f (diff)
downloadgcc-0cddb138341aafca38ae8d099c98750b5b34b8b2.tar.gz
* lto-symtab.c (lto_symtab_entry_def) Add vnode.
(lto_varpool_replace_node): New. (lto_symtab_resolve_symbols): Resolve varpool nodes. (lto_symtab_merge_decls_1): Prefer decls with varpool node. (lto_symtab_merge_cgraph_nodes_1): Merge varpools. * cgraph.h (varpool_node_ptr): New type. (varpool_node_ptr): New vector. (varpool_node_set_def): New structure. (varpool_node_set): New type. (varpool_node_set): New vector. (varpool_node_set_element_def): New structure. (varpool_node_set_element, const_varpool_node_set_element): New types. (varpool_node_set_iterator): New type. (varpool_node): Add prev pointers, add used_from_other_partition, in_other_partition. (varpool_node_set_new, varpool_node_set_find, varpool_node_set_add, varpool_node_set_remove, dump_varpool_node_set, debug_varpool_node_set, varpool_get_node, varpool_remove_node): Declare. (vsi_end_p, vsi_next, vsi_node, vsi_start, varpool_node_in_set_p, varpool_node_set_size): New inlines. * cgraph.c (dump_cgraph_node): Dump asm names of aliases. * tree-pass.h (varpool_node_set_def): Forward declare. (ipa_opt_pass_d): Summary writting takes vnode sets too. (ipa_write_optimization_summaries): Update prototype. * ipa-cp.c (ipcp_write_summary): Update. * ipa-reference.c (ipa_reference_write_summary): Update. * lto-cgraph.c (lto_output_varpool_node): New static function. (output_varpool): New function. (input_varpool_node): New static function. (input_varpool_1): New function. (input_cgraph): Input varpool. * ipa-pure-const.c (pure_const_write_summary): Update. * lto-streamer-out.c (lto_output): Update, output varpool too. (write_global_stream): Kill WPA hack. (produce_asm_for_decls): Update. (output_alias_pair_p): Handle variables. (output_unreferenced_globals): Output only needed partition of varpool. * ipa-inline.c (inline_write_summary): Update. * lto-streamer-in.c (lto_input_tree_ref, lto_input_tree): Do not build cgraph. * lto-section-in.c (lto_section_name): Add varpool and jump funcs. * ipa.c (hash_varpool_node_set_element, eq_varpool_node_set_element, varpool_node_set_new, varpool_node_set_add, varpool_node_set_remove, varpool_node_set_find, dump_varpool_node_set, debug_varpool_node_set): New functions. * passes.c (rest_of_decl_compilation): when in LTO do not finalize. (execute_one_pass): Process new decls too. (ipa_write_summaries_2): Pass around vsets. (ipa_write_summaries_1): Likewise. (ipa_write_summaries): Build vset; be more selective about cgraph nodes to add. (ipa_write_optimization_summaries_1): Pass around vsets. (ipa_write_optimization_summaries): Likewise. * varpool.c (varpool_get_node): New. (varpool_node): Update doubly linked lists. (varpool_remove_node): New. (dump_varpool_node): More dumping. (varpool_enqueue_needed_node): Update doubly linked lists. (decide_is_variable_needed): Kill ltrans hack. (varpool_finalize_decl): Kill lto hack. (varpool_assemble_decl): Skip decls in other partitions. (varpool_assemble_pending_decls): Update doubly linkes lists. (varpool_empty_needed_queue): Likewise. (varpool_extra_name_alias): Likewise. * lto-streamer.c (lto_get_section_name): Add vars section. * lto-streamer.h (lto_section_type): Update. (output_varpool, input_varpool): Declare. * lto.c (lto_varpool_node_sets): New. (lto_1_to_1_map): Partition varpool too. (globalize_context_t, globalize_cross_file_statics, lto_scan_statics_in_ref_table, lto_scan_statics_in_cgraph_node, lto_scan_statics_in_remaining_global_vars): Remove. (lto_promote_cross_file_statics): Rewrite. (get_filename_for_set): Take vset argument. (lto_wpa_write_files): Pass around vsets. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@158854 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/varpool.c')
-rw-r--r--gcc/varpool.c99
1 files changed, 80 insertions, 19 deletions
diff --git a/gcc/varpool.c b/gcc/varpool.c
index 40decfc867b..77f52c3dee6 100644
--- a/gcc/varpool.c
+++ b/gcc/varpool.c
@@ -105,6 +105,22 @@ eq_varpool_node (const void *p1, const void *p2)
return DECL_UID (n1->decl) == DECL_UID (n2->decl);
}
+/* Return varpool node assigned to DECL without creating new one. */
+struct varpool_node *
+varpool_get_node (tree decl)
+{
+ struct varpool_node key, **slot;
+
+ gcc_assert (DECL_P (decl) && TREE_CODE (decl) != FUNCTION_DECL);
+
+ if (!varpool_hash)
+ return NULL;
+ key.decl = decl;
+ slot = (struct varpool_node **)
+ htab_find_slot (varpool_hash, &key, INSERT);
+ return *slot;
+}
+
/* Return varpool node assigned to DECL. Create new one when needed. */
struct varpool_node *
varpool_node (tree decl)
@@ -125,11 +141,50 @@ varpool_node (tree decl)
node->decl = decl;
node->order = cgraph_order++;
node->next = varpool_nodes;
+ if (varpool_nodes)
+ varpool_nodes->prev = node;
varpool_nodes = node;
*slot = node;
return node;
}
+/* Remove node from the varpool. */
+void
+varpool_remove_node (struct varpool_node *node)
+{
+ void **slot;
+ slot = htab_find_slot (varpool_hash, node, NO_INSERT);
+ gcc_assert (*slot == node);
+ htab_clear_slot (varpool_hash, slot);
+ gcc_assert (!varpool_assembled_nodes_queue);
+ if (node->next)
+ node->next->prev = node->prev;
+ if (node->prev)
+ node->prev->next = node->next;
+ else if (node->next)
+ {
+ gcc_assert (varpool_nodes == node);
+ varpool_nodes = node->next;
+ }
+ if (varpool_first_unanalyzed_node == node)
+ varpool_first_unanalyzed_node = node->next_needed;
+ if (node->next_needed)
+ node->next_needed->prev_needed = node->prev_needed;
+ else if (node->prev_needed)
+ {
+ gcc_assert (varpool_last_needed_node);
+ varpool_last_needed_node = node->prev_needed;
+ }
+ if (node->prev_needed)
+ node->prev_needed->next_needed = node->next_needed;
+ else if (node->next_needed)
+ {
+ gcc_assert (varpool_nodes_queue == node);
+ varpool_nodes_queue = node->next_needed;
+ }
+ node->decl = NULL;
+}
+
/* Dump given cgraph node. */
void
dump_varpool_node (FILE *f, struct varpool_node *node)
@@ -139,8 +194,12 @@ dump_varpool_node (FILE *f, struct varpool_node *node)
cgraph_function_flags_ready
? cgraph_availability_names[cgraph_variable_initializer_availability (node)]
: "not-ready");
+ if (DECL_ASSEMBLER_NAME_SET_P (node->decl))
+ fprintf (f, " (asm: %s)", IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (node->decl)));
if (DECL_INITIAL (node->decl))
fprintf (f, " initialized");
+ if (TREE_ASM_WRITTEN (node->decl))
+ fprintf (f, " (asm written)");
if (node->needed)
fprintf (f, " needed");
if (node->analyzed)
@@ -151,6 +210,10 @@ dump_varpool_node (FILE *f, struct varpool_node *node)
fprintf (f, " output");
if (node->externally_visible)
fprintf (f, " externally_visible");
+ if (node->in_other_partition)
+ fprintf (f, " in_other_partition");
+ else if (node->used_from_other_partition)
+ fprintf (f, " used_from_other_partition");
fprintf (f, "\n");
}
@@ -192,7 +255,10 @@ static void
varpool_enqueue_needed_node (struct varpool_node *node)
{
if (varpool_last_needed_node)
- varpool_last_needed_node->next_needed = node;
+ {
+ varpool_last_needed_node->next_needed = node;
+ node->prev_needed = varpool_last_needed_node;
+ }
varpool_last_needed_node = node;
node->next_needed = NULL;
if (!varpool_nodes_queue)
@@ -230,11 +296,7 @@ varpool_reset_queue (void)
bool
decide_is_variable_needed (struct varpool_node *node, tree decl)
{
- /* We do not track variable references at all and thus have no idea if the
- variable was referenced in some other partition or not.
- FIXME: We really need address taken edges in callgraph and varpool to
- drive WPA and decide whether other partition might reference it or not. */
- if (flag_ltrans)
+ if (node->used_from_other_partition)
return true;
/* If the user told us it is used, then it must be so. */
if ((node->externally_visible && !DECL_COMDAT (decl))
@@ -288,17 +350,6 @@ varpool_finalize_decl (tree decl)
{
struct varpool_node *node = varpool_node (decl);
- /* FIXME: We don't really stream varpool datastructure and instead rebuild it
- by varpool_finalize_decl. This is not quite correct since this way we can't
- attach any info to varpool. Eventually we will want to stream varpool nodes
- and the flags.
-
- For the moment just prevent analysis of varpool nodes to happen again, so
- we will re-try to compute "address_taken" flag of varpool that breaks
- in presence of clones. */
- if (in_lto_p)
- node->analyzed = true;
-
/* The first declaration of a variable that comes through this function
decides whether it is global (in C, has external linkage)
or local (in C, has internal linkage). So do nothing more
@@ -364,7 +415,7 @@ varpool_analyze_pending_decls (void)
We however don't want to re-analyze already analyzed nodes. */
if (!analyzed)
{
- gcc_assert (!in_lto_p);
+ gcc_assert (!in_lto_p || cgraph_function_flags_ready);
/* Compute the alignment early so function body expanders are
already informed about increased alignment. */
align_variable (decl, 0);
@@ -385,6 +436,7 @@ varpool_assemble_decl (struct varpool_node *node)
if (!TREE_ASM_WRITTEN (decl)
&& !node->alias
+ && !node->in_other_partition
&& !DECL_EXTERNAL (decl)
&& (TREE_CODE (decl) != VAR_DECL || !DECL_HAS_VALUE_EXPR_P (decl)))
{
@@ -394,6 +446,9 @@ varpool_assemble_decl (struct varpool_node *node)
struct varpool_node *alias;
node->next_needed = varpool_assembled_nodes_queue;
+ node->prev_needed = NULL;
+ if (varpool_assembled_nodes_queue)
+ varpool_assembled_nodes_queue->prev_needed = node;
varpool_assembled_nodes_queue = node;
node->finalized = 1;
@@ -476,7 +531,10 @@ varpool_assemble_pending_decls (void)
if (varpool_assemble_decl (node))
changed = true;
else
- node->next_needed = NULL;
+ {
+ node->prev_needed = NULL;
+ node->next_needed = NULL;
+ }
}
/* varpool_nodes_queue is now empty, clear the pointer to the last element
in the queue. */
@@ -498,6 +556,7 @@ varpool_empty_needed_queue (void)
struct varpool_node *node = varpool_nodes_queue;
varpool_nodes_queue = varpool_nodes_queue->next_needed;
node->next_needed = NULL;
+ node->prev_needed = NULL;
}
/* varpool_nodes_queue is now empty, clear the pointer to the last element
in the queue. */
@@ -559,6 +618,8 @@ varpool_extra_name_alias (tree alias, tree decl)
alias_node->alias = 1;
alias_node->extra_name = decl_node;
alias_node->next = decl_node->extra_name;
+ if (decl_node->extra_name)
+ decl_node->extra_name->prev = alias_node;
decl_node->extra_name = alias_node;
*slot = alias_node;
return true;