aboutsummaryrefslogtreecommitdiff
path: root/gcc/varpool.c
diff options
context:
space:
mode:
authorMartin Liska <mliska@suse.cz>2014-07-24 14:25:27 +0200
committerMartin Liska <marxin@gcc.gnu.org>2014-07-24 12:25:27 +0000
commit9041d2e6d2a783f2fbd0760f9ce6002194d63d00 (patch)
tree472ea9046d4a0e5c2441a25416c6e99fb4665350 /gcc/varpool.c
parent4a53d6a66043944d9534ceae8182b943f739b8a7 (diff)
downloadgcc-9041d2e6d2a783f2fbd0760f9ce6002194d63d00.zip
gcc-9041d2e6d2a783f2fbd0760f9ce6002194d63d00.tar.gz
gcc-9041d2e6d2a783f2fbd0760f9ce6002194d63d00.tar.bz2
IPA C++ refactoring 2/N
* cgraph.h (varpool_node): (availability get_availability (void)): created from cgraph_variable_initializer_availability (inline varpool_node *ultimate_alias_target (availability *availability = NULL) creted from: cgraph_variable_initializer_availability (inline varpool_node *get_alias_target (void)): created from varpool_alias_target (void finalize_named_section_flags (void)): created from varpool_finalize_named_section_flags (bool assemble_decl (void)): created from varpool_assemble_decl (void analyze (void)): created from varpool_analyze_node (bool call_for_node_and_aliases (bool (*callback) (varpool_node *, void *), void *data, bool include_overwritable)): created fromvarpool_for_node_and_aliases (void remove_initializer (void)): created from varpool_remove_initializer (tree get_constructor (void)): created from varpool_get_constructor (bool externally_visible_p (void)): created from varpool_externally_visible_p (bool ctor_useable_for_folding_p (void)): created from varpool_ctor_useable_for_folding_p (inline bool all_refs_explicit_p ()): created from varpool_all_refs_explicit_p (inline bool can_remove_if_no_refs_p (void)): created from varpool_can_remove_if_no_refs (static inline varpool_node *get (const_tree decl)): created from varpool_get_node (static void finalize_decl (tree decl)): created from varpool_finalize_decl (static bool output_variables (void)): created from varpool_output_variables (static varpool_node * create_extra_name_alias (tree alias, tree decl)): created from varpool_extra_name_alias (static varpool_node * create_alias (tree, tree)): created from varpool_create_variable_alias (static void dump_varpool (FILE *f)): created from dump_varpool (static void DEBUG_FUNCTION debug_varpool (void)): created from debug_varpool (static varpool_node *create_empty (void)): created from varpool_create_empty_node (static varpool_node *get_create (tree decl)): created from varpool_node_for_decl (static varpool_node *get_for_asmname (tree asmname)): created from varpool_node_for_asm (void assemble_aliases (void)): created from assemble_aliases From-SVN: r212984
Diffstat (limited to 'gcc/varpool.c')
-rw-r--r--gcc/varpool.c224
1 files changed, 113 insertions, 111 deletions
diff --git a/gcc/varpool.c b/gcc/varpool.c
index 6b31e73..74117e2 100644
--- a/gcc/varpool.c
+++ b/gcc/varpool.c
@@ -140,7 +140,7 @@ varpool_call_variable_insertion_hooks (varpool_node *node)
/* Allocate new callgraph node and insert it into basic data structures. */
varpool_node *
-varpool_create_empty_node (void)
+varpool_node::create_empty (void)
{
varpool_node *node = ggc_cleared_alloc<varpool_node> ();
node->type = SYMTAB_VARIABLE;
@@ -149,14 +149,14 @@ varpool_create_empty_node (void)
/* Return varpool node assigned to DECL. Create new one when needed. */
varpool_node *
-varpool_node_for_decl (tree decl)
+varpool_node::get_create (tree decl)
{
- varpool_node *node = varpool_get_node (decl);
+ varpool_node *node = varpool_node::get (decl);
gcc_checking_assert (TREE_CODE (decl) == VAR_DECL);
if (node)
return node;
- node = varpool_create_empty_node ();
+ node = varpool_node::create_empty ();
node->decl = decl;
node->register_symbol ();
return node;
@@ -176,19 +176,19 @@ varpool_node::remove (void)
/* Keep constructor when it may be used for folding. We remove
references to external variables before final compilation. */
else if (DECL_INITIAL (decl) && DECL_INITIAL (decl) != error_mark_node
- && !varpool_ctor_useable_for_folding_p (this))
- varpool_remove_initializer (this);
+ && !ctor_useable_for_folding_p ())
+ remove_initializer ();
ggc_free (this);
}
-/* Renove node initializer when it is no longer needed. */
+/* Remove node initializer when it is no longer needed. */
void
-varpool_remove_initializer (varpool_node *node)
+varpool_node::remove_initializer (void)
{
- if (DECL_INITIAL (node->decl)
- && !DECL_IN_CONSTANT_POOL (node->decl)
+ if (DECL_INITIAL (decl)
+ && !DECL_IN_CONSTANT_POOL (decl)
/* Keep vtables for BINFO folding. */
- && !DECL_VIRTUAL_P (node->decl)
+ && !DECL_VIRTUAL_P (decl)
/* FIXME: http://gcc.gnu.org/PR55395 */
&& debug_info_level == DINFO_LEVEL_NONE
/* When doing declaration merging we have duplicate
@@ -196,17 +196,17 @@ varpool_remove_initializer (varpool_node *node)
the boides, or we will end up remiving
wrong one. */
&& cgraph_state != CGRAPH_LTO_STREAMING)
- DECL_INITIAL (node->decl) = error_mark_node;
+ DECL_INITIAL (decl) = error_mark_node;
}
-/* Dump given cgraph node. */
+/* Dump given varpool node to F. */
void
varpool_node::dump (FILE *f)
{
dump_base (f);
fprintf (f, " Availability: %s\n",
cgraph_function_flags_ready
- ? cgraph_availability_names[cgraph_variable_initializer_availability (this)]
+ ? cgraph_availability_names[get_availability ()]
: "not-ready");
fprintf (f, " Varpool flags:");
if (DECL_INITIAL (decl))
@@ -217,7 +217,7 @@ varpool_node::dump (FILE *f)
fprintf (f, " used-by-single-function");
if (TREE_READONLY (decl))
fprintf (f, " read-only");
- if (varpool_ctor_useable_for_folding_p (this))
+ if (ctor_useable_for_folding_p ())
fprintf (f, " const-value-known");
if (writeonly)
fprintf (f, " write-only");
@@ -226,9 +226,16 @@ varpool_node::dump (FILE *f)
fprintf (f, "\n");
}
+
+/* Dump given varpool node to stderr. */
+void varpool_node::debug (void)
+{
+ varpool_node::dump (stderr);
+}
+
/* Dump the variable pool to F. */
void
-dump_varpool (FILE *f)
+varpool_node::dump_varpool (FILE *f)
{
varpool_node *node;
@@ -240,14 +247,14 @@ dump_varpool (FILE *f)
/* Dump the variable pool to stderr. */
DEBUG_FUNCTION void
-debug_varpool (void)
+varpool_node::debug_varpool (void)
{
dump_varpool (stderr);
}
/* Given an assembler name, lookup node. */
varpool_node *
-varpool_node_for_asm (tree asmname)
+varpool_node::get_for_asmname (tree asmname)
{
if (symtab_node *node = symtab_node_for_asm (asmname))
return dyn_cast <varpool_node *> (node);
@@ -255,23 +262,23 @@ varpool_node_for_asm (tree asmname)
return NULL;
}
-/* When doing LTO, read NODE's constructor from disk if it is not already present. */
+/* When doing LTO, read variable's constructor from disk if
+ it is not already present. */
tree
-varpool_get_constructor (struct varpool_node *node)
+varpool_node::get_constructor (void)
{
struct lto_file_decl_data *file_data;
const char *data, *name;
size_t len;
- tree decl = node->decl;
- if (DECL_INITIAL (node->decl) != error_mark_node
+ if (DECL_INITIAL (decl) != error_mark_node
|| !in_lto_p)
- return DECL_INITIAL (node->decl);
+ return DECL_INITIAL (decl);
timevar_push (TV_IPA_LTO_CTORS_IN);
- file_data = node->lto_file_data;
+ file_data = lto_file_data;
name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
/* We may have renamed the declaration, e.g., a static function. */
@@ -284,29 +291,29 @@ varpool_get_constructor (struct varpool_node *node)
file_data->file_name,
name);
- lto_input_variable_constructor (file_data, node, data);
+ lto_input_variable_constructor (file_data, this, data);
lto_stats.num_function_bodies++;
lto_free_section_data (file_data, LTO_section_function_body, name,
data, len);
- lto_free_function_in_decl_state_for_node (node);
+ lto_free_function_in_decl_state_for_node (this);
timevar_pop (TV_IPA_LTO_CTORS_IN);
- return DECL_INITIAL (node->decl);
+ return DECL_INITIAL (decl);
}
-/* Return ture if NODE has constructor that can be used for folding. */
+/* Return true if variable has constructor that can be used for folding. */
bool
-varpool_ctor_useable_for_folding_p (varpool_node *node)
+varpool_node::ctor_useable_for_folding_p (void)
{
- varpool_node *real_node = node;
+ varpool_node *real_node = this;
if (real_node->alias && real_node->definition)
- real_node = varpool_variable_node (node);
+ real_node = ultimate_alias_target ();
- if (TREE_CODE (node->decl) == CONST_DECL
- || DECL_IN_CONSTANT_POOL (node->decl))
+ if (TREE_CODE (decl) == CONST_DECL
+ || DECL_IN_CONSTANT_POOL (decl))
return true;
- if (TREE_THIS_VOLATILE (node->decl))
+ if (TREE_THIS_VOLATILE (decl))
return false;
/* If we do not have a constructor, we can't use it. */
@@ -316,7 +323,7 @@ varpool_ctor_useable_for_folding_p (varpool_node *node)
/* Vtables are defined by their types and must match no matter of interposition
rules. */
- if (DECL_VIRTUAL_P (node->decl))
+ if (DECL_VIRTUAL_P (decl))
{
/* The C++ front end creates VAR_DECLs for vtables of typeinfo
classes not defined in the current TU so that it can refer
@@ -327,14 +334,14 @@ varpool_ctor_useable_for_folding_p (varpool_node *node)
/* Alias of readonly variable is also readonly, since the variable is stored
in readonly memory. We also accept readonly aliases of non-readonly
locations assuming that user knows what he is asking for. */
- if (!TREE_READONLY (node->decl) && !TREE_READONLY (real_node->decl))
+ if (!TREE_READONLY (decl) && !TREE_READONLY (real_node->decl))
return false;
/* Variables declared 'const' without an initializer
have zero as the initializer if they may not be
overridden at link or run time. */
if (!DECL_INITIAL (real_node->decl)
- && (DECL_EXTERNAL (node->decl) || decl_replaceable_p (node->decl)))
+ && (DECL_EXTERNAL (decl) || decl_replaceable_p (decl)))
return false;
/* Variables declared `const' with an initializer are considered
@@ -345,9 +352,9 @@ varpool_ctor_useable_for_folding_p (varpool_node *node)
return true;
}
-/* If DECL is constant variable and its initial value is known (so we can
- do constant folding), return its constructor (DECL_INITIAL). This may
- be an expression or NULL when DECL is initialized to 0.
+/* If DECLARATION is constant variable and its initial value is known
+ (so we can do constant folding), return its constructor (DECL_INITIAL).
+ This may be an expression or NULL when DECL is initialized to 0.
Return ERROR_MARK_NODE otherwise.
In LTO this may actually trigger reading the constructor from disk.
@@ -381,10 +388,10 @@ ctor_for_folding (tree decl)
gcc_assert (TREE_CODE (decl) == VAR_DECL);
- real_node = node = varpool_get_node (decl);
+ real_node = node = varpool_node::get (decl);
if (node)
{
- real_node = varpool_variable_node (node);
+ real_node = node->ultimate_alias_target ();
real_decl = real_node->decl;
}
else
@@ -401,7 +408,7 @@ ctor_for_folding (tree decl)
|| DECL_INITIAL (decl) == error_mark_node);
if (node->weakref)
{
- node = varpool_alias_target (node);
+ node = node->get_alias_target ();
decl = node->decl;
}
}
@@ -409,7 +416,7 @@ ctor_for_folding (tree decl)
if ((!DECL_VIRTUAL_P (real_decl)
|| DECL_INITIAL (real_decl) == error_mark_node
|| !DECL_INITIAL (real_decl))
- && (!node || !varpool_ctor_useable_for_folding_p (node)))
+ && (!node || !node->ctor_useable_for_folding_p ()))
return error_mark_node;
/* OK, we can return constructor. See if we need to fetch it from disk
@@ -417,7 +424,7 @@ ctor_for_folding (tree decl)
if (DECL_INITIAL (real_decl) != error_mark_node
|| !in_lto_p)
return DECL_INITIAL (real_decl);
- return varpool_get_constructor (real_node);
+ return real_node->get_constructor ();
}
/* Add the variable DECL to the varpool.
@@ -428,90 +435,85 @@ void
varpool_add_new_variable (tree decl)
{
varpool_node *node;
- varpool_finalize_decl (decl);
- node = varpool_node_for_decl (decl);
+ varpool_node::finalize_decl (decl);
+ node = varpool_node::get_create (decl);
varpool_call_variable_insertion_hooks (node);
- if (varpool_externally_visible_p (node))
+ if (node->externally_visible_p ())
node->externally_visible = true;
}
/* Return variable availability. See cgraph.h for description of individual
return values. */
enum availability
-cgraph_variable_initializer_availability (varpool_node *node)
+varpool_node::get_availability (void)
{
- if (!node->definition)
+ if (!definition)
return AVAIL_NOT_AVAILABLE;
- if (!TREE_PUBLIC (node->decl))
+ if (!TREE_PUBLIC (decl))
return AVAIL_AVAILABLE;
- if (DECL_IN_CONSTANT_POOL (node->decl)
- || DECL_VIRTUAL_P (node->decl))
+ if (DECL_IN_CONSTANT_POOL (decl)
+ || DECL_VIRTUAL_P (decl))
return AVAIL_AVAILABLE;
- if (node->alias && node->weakref)
+ if (alias && weakref)
{
enum availability avail;
- cgraph_variable_initializer_availability
- (varpool_variable_node (node, &avail));
+ ultimate_alias_target (&avail)->get_availability ();
return avail;
}
/* If the variable can be overwritten, return OVERWRITABLE. Takes
care of at least one notable extension - the COMDAT variables
used to share template instantiations in C++. */
- if (decl_replaceable_p (node->decl)
- || DECL_EXTERNAL (node->decl))
+ if (decl_replaceable_p (decl)
+ || DECL_EXTERNAL (decl))
return AVAIL_INTERPOSABLE;
return AVAIL_AVAILABLE;
}
void
-varpool_analyze_node (varpool_node *node)
+varpool_node::analyze (void)
{
- tree decl = node->decl;
-
/* When reading back varpool at LTO time, we re-construct the queue in order
to have "needed" list right by inserting all needed nodes into varpool.
We however don't want to re-analyze already analyzed nodes. */
- if (!node->analyzed)
+ if (!analyzed)
{
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);
}
- if (node->alias)
- node->resolve_alias (varpool_get_node (node->alias_target));
+ if (alias)
+ resolve_alias (varpool_node::get (alias_target));
else if (DECL_INITIAL (decl))
- record_references_in_initializer (decl, node->analyzed);
- node->analyzed = true;
+ record_references_in_initializer (decl, analyzed);
+ analyzed = true;
}
-/* Assemble thunks and aliases associated to NODE. */
+/* Assemble thunks and aliases associated to varpool node. */
-static void
-assemble_aliases (varpool_node *node)
+void
+varpool_node::assemble_aliases (void)
{
struct ipa_ref *ref;
- FOR_EACH_ALIAS (node, ref)
+ FOR_EACH_ALIAS (this, ref)
{
varpool_node *alias = dyn_cast <varpool_node *> (ref->referring);
do_assemble_alias (alias->decl,
- DECL_ASSEMBLER_NAME (node->decl));
- assemble_aliases (alias);
+ DECL_ASSEMBLER_NAME (decl));
+ alias->assemble_aliases ();
}
}
/* Output one variable, if necessary. Return whether we output it. */
bool
-varpool_assemble_decl (varpool_node *node)
+varpool_node::assemble_decl (void)
{
- tree decl = node->decl;
-
/* Aliases are outout when their target is produced or by
output_weakrefs. */
- if (node->alias)
+ if (alias)
return false;
/* Constant pool is output from RTL land when the reference
@@ -535,14 +537,14 @@ varpool_assemble_decl (varpool_node *node)
&& TREE_CODE (decl) == VAR_DECL
&& !DECL_HAS_VALUE_EXPR_P (decl));
- if (!node->in_other_partition
+ if (!in_other_partition
&& !DECL_EXTERNAL (decl))
{
- varpool_get_constructor (node);
+ get_constructor ();
assemble_variable (decl, 0, 1, 0);
gcc_assert (TREE_ASM_WRITTEN (decl));
- gcc_assert (node->definition);
- assemble_aliases (node);
+ gcc_assert (definition);
+ assemble_aliases ();
return true;
}
@@ -584,7 +586,7 @@ varpool_remove_unreferenced_decls (void)
FOR_EACH_DEFINED_VARIABLE (node)
{
if (node->analyzed
- && (!varpool_can_remove_if_no_refs (node)
+ && (!node->can_remove_if_no_refs_p ()
/* We just expanded all function bodies. See if any of
them needed the variable. */
|| DECL_RTL_SET_P (node->decl)))
@@ -634,7 +636,7 @@ varpool_remove_unreferenced_decls (void)
if (cgraph_dump_file)
fprintf (cgraph_dump_file, " %s", node->asm_name ());
if (pointer_set_contains (referenced, node))
- varpool_remove_initializer (node);
+ node->remove_initializer ();
else
node->remove ();
}
@@ -649,21 +651,21 @@ varpool_remove_unreferenced_decls (void)
conflicts between read-only and read-only requiring relocations
sections can be resolved. */
void
-varpool_finalize_named_section_flags (varpool_node *node)
+varpool_node::finalize_named_section_flags (void)
{
- if (!TREE_ASM_WRITTEN (node->decl)
- && !node->alias
- && !node->in_other_partition
- && !DECL_EXTERNAL (node->decl)
- && TREE_CODE (node->decl) == VAR_DECL
- && !DECL_HAS_VALUE_EXPR_P (node->decl)
- && node->get_section ())
- get_variable_section (node->decl, false);
+ if (!TREE_ASM_WRITTEN (decl)
+ && !alias
+ && !in_other_partition
+ && !DECL_EXTERNAL (decl)
+ && TREE_CODE (decl) == VAR_DECL
+ && !DECL_HAS_VALUE_EXPR_P (decl)
+ && get_section ())
+ get_variable_section (decl, false);
}
/* Output all variables enqueued to be assembled. */
bool
-varpool_output_variables (void)
+varpool_node::output_variables (void)
{
bool changed = false;
varpool_node *node;
@@ -676,10 +678,10 @@ varpool_output_variables (void)
timevar_push (TV_VAROUT);
FOR_EACH_DEFINED_VARIABLE (node)
- varpool_finalize_named_section_flags (node);
+ node->finalize_named_section_flags ();
FOR_EACH_DEFINED_VARIABLE (node)
- if (varpool_assemble_decl (node))
+ if (node->assemble_decl ())
changed = true;
timevar_pop (TV_VAROUT);
return changed;
@@ -700,8 +702,8 @@ add_new_static_var (tree type)
DECL_CONTEXT (new_decl) = NULL_TREE;
DECL_ABSTRACT (new_decl) = 0;
lang_hooks.dup_lang_specific_decl (new_decl);
- new_node = varpool_node_for_decl (new_decl);
- varpool_finalize_decl (new_decl);
+ new_node = varpool_node::get_create (new_decl);
+ varpool_node::finalize_decl (new_decl);
return new_node->decl;
}
@@ -710,13 +712,13 @@ add_new_static_var (tree type)
Extra name aliases are output whenever DECL is output. */
varpool_node *
-varpool_create_variable_alias (tree alias, tree decl)
+varpool_node::create_alias (tree alias, tree decl)
{
varpool_node *alias_node;
gcc_assert (TREE_CODE (decl) == VAR_DECL);
gcc_assert (TREE_CODE (alias) == VAR_DECL);
- alias_node = varpool_node_for_decl (alias);
+ alias_node = varpool_node::get_create (alias);
alias_node->alias = true;
alias_node->definition = true;
alias_node->alias_target = decl;
@@ -729,7 +731,7 @@ varpool_create_variable_alias (tree alias, tree decl)
Extra name aliases are output whenever DECL is output. */
varpool_node *
-varpool_extra_name_alias (tree alias, tree decl)
+varpool_node::create_extra_name_alias (tree alias, tree decl)
{
varpool_node *alias_node;
@@ -737,7 +739,7 @@ varpool_extra_name_alias (tree alias, tree decl)
/* If aliases aren't supported by the assembler, fail. */
return NULL;
#endif
- alias_node = varpool_create_variable_alias (alias, decl);
+ alias_node = varpool_node::create_alias (alias, decl);
alias_node->cpp_implicit_alias = true;
/* Extra name alias mechanizm creates aliases really late
@@ -745,32 +747,32 @@ varpool_extra_name_alias (tree alias, tree decl)
This is unfortunate because they are not going through the
standard channels. Ensure they get output. */
if (cpp_implicit_aliases_done)
- alias_node->resolve_alias (varpool_node_for_decl (decl));
+ alias_node->resolve_alias (varpool_node::get_create (decl));
return alias_node;
}
-/* Call calback on NODE and aliases associated to NODE.
+/* Call calback on varpool symbol and aliases associated to varpool symbol.
When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
skipped. */
bool
-varpool_for_node_and_aliases (varpool_node *node,
- bool (*callback) (varpool_node *, void *),
- void *data,
- bool include_overwritable)
+varpool_node::call_for_node_and_aliases (bool (*callback) (varpool_node *,
+ void *),
+ void *data,
+ bool include_overwritable)
{
struct ipa_ref *ref;
- if (callback (node, data))
+ if (callback (this, data))
return true;
- FOR_EACH_ALIAS (node, ref)
+ FOR_EACH_ALIAS (this, ref)
{
varpool_node *alias = dyn_cast <varpool_node *> (ref->referring);
if (include_overwritable
- || cgraph_variable_initializer_availability (alias) > AVAIL_INTERPOSABLE)
- if (varpool_for_node_and_aliases (alias, callback, data,
- include_overwritable))
+ || alias->get_availability () > AVAIL_INTERPOSABLE)
+ if (alias->call_for_node_and_aliases (callback, data,
+ include_overwritable))
return true;
}
return false;