Commit 26e5b0fd by Jan Hubicka Committed by Jan Hubicka

cgraph.h (varpool_node_hook, [...]): Declare.


	* cgraph.h (varpool_node_hook, varpool_node_hook_list,
	varpool_add_node_removal_hook, varpool_add_variable_insertion_hook,
	varpool_remove_variable_insertion_hook): Declare.
	* varpool.c (varpool_node_hook_list): New structure.
	(first_varpool_node_removal_hook,
	first_varpool_variable_insertion_hook): New variables.
	(varpool_add_node_removal_hook, varpool_remove_node_removal_hook,
	varpool_call_node_removal_hooks, varpool_add_variable_insertion_hook,
	varpool_remove_variable_insertion_hook,
	varpool_call_variable_insertion_hooks): New functions.
	(varpool_remove_node): Use it.

From-SVN: r202367
parent 97f1f314
2013-09-08 Jan Hubicka <jh@suse.cz>
* cgraph.h (varpool_node_hook, varpool_node_hook_list,
varpool_add_node_removal_hook, varpool_add_variable_insertion_hook,
varpool_remove_variable_insertion_hook): Declare.
* varpool.c (varpool_node_hook_list): New structure.
(first_varpool_node_removal_hook,
first_varpool_variable_insertion_hook): New variables.
(varpool_add_node_removal_hook, varpool_remove_node_removal_hook,
varpool_call_node_removal_hooks, varpool_add_variable_insertion_hook,
varpool_remove_variable_insertion_hook,
varpool_call_variable_insertion_hooks): New functions.
(varpool_remove_node): Use it.
2013-09-08 Paolo Carlini <paolo.carlini@oracle.com> 2013-09-08 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/54941 PR c++/54941
......
...@@ -701,12 +701,14 @@ void cgraph_mark_address_taken_node (struct cgraph_node *); ...@@ -701,12 +701,14 @@ void cgraph_mark_address_taken_node (struct cgraph_node *);
typedef void (*cgraph_edge_hook)(struct cgraph_edge *, void *); typedef void (*cgraph_edge_hook)(struct cgraph_edge *, void *);
typedef void (*cgraph_node_hook)(struct cgraph_node *, void *); typedef void (*cgraph_node_hook)(struct cgraph_node *, void *);
typedef void (*varpool_node_hook)(struct varpool_node *, void *);
typedef void (*cgraph_2edge_hook)(struct cgraph_edge *, struct cgraph_edge *, typedef void (*cgraph_2edge_hook)(struct cgraph_edge *, struct cgraph_edge *,
void *); void *);
typedef void (*cgraph_2node_hook)(struct cgraph_node *, struct cgraph_node *, typedef void (*cgraph_2node_hook)(struct cgraph_node *, struct cgraph_node *,
void *); void *);
struct cgraph_edge_hook_list; struct cgraph_edge_hook_list;
struct cgraph_node_hook_list; struct cgraph_node_hook_list;
struct varpool_node_hook_list;
struct cgraph_2edge_hook_list; struct cgraph_2edge_hook_list;
struct cgraph_2node_hook_list; struct cgraph_2node_hook_list;
struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *); struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *);
...@@ -714,9 +716,15 @@ void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *); ...@@ -714,9 +716,15 @@ void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *);
struct cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook, struct cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook,
void *); void *);
void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list *); void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list *);
struct varpool_node_hook_list *varpool_add_node_removal_hook (varpool_node_hook,
void *);
void varpool_remove_node_removal_hook (struct varpool_node_hook_list *);
struct cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook, struct cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook,
void *); void *);
void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list *); void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list *);
struct varpool_node_hook_list *varpool_add_variable_insertion_hook (varpool_node_hook,
void *);
void varpool_remove_variable_insertion_hook (struct varpool_node_hook_list *);
void cgraph_call_function_insertion_hooks (struct cgraph_node *node); void cgraph_call_function_insertion_hooks (struct cgraph_node *node);
struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *); struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *);
void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *); void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *);
......
...@@ -36,6 +36,100 @@ along with GCC; see the file COPYING3. If not see ...@@ -36,6 +36,100 @@ along with GCC; see the file COPYING3. If not see
#include "tree-flow.h" #include "tree-flow.h"
#include "flags.h" #include "flags.h"
/* List of hooks triggered on varpool_node events. */
struct varpool_node_hook_list {
varpool_node_hook hook;
void *data;
struct varpool_node_hook_list *next;
};
/* List of hooks triggered when a node is removed. */
struct varpool_node_hook_list *first_varpool_node_removal_hook;
/* List of hooks triggered when an variable is inserted. */
struct varpool_node_hook_list *first_varpool_variable_insertion_hook;
/* Register HOOK to be called with DATA on each removed node. */
struct varpool_node_hook_list *
varpool_add_node_removal_hook (varpool_node_hook hook, void *data)
{
struct varpool_node_hook_list *entry;
struct varpool_node_hook_list **ptr = &first_varpool_node_removal_hook;
entry = (struct varpool_node_hook_list *) xmalloc (sizeof (*entry));
entry->hook = hook;
entry->data = data;
entry->next = NULL;
while (*ptr)
ptr = &(*ptr)->next;
*ptr = entry;
return entry;
}
/* Remove ENTRY from the list of hooks called on removing nodes. */
void
varpool_remove_node_removal_hook (struct varpool_node_hook_list *entry)
{
struct varpool_node_hook_list **ptr = &first_varpool_node_removal_hook;
while (*ptr != entry)
ptr = &(*ptr)->next;
*ptr = entry->next;
free (entry);
}
/* Call all node removal hooks. */
static void
varpool_call_node_removal_hooks (struct varpool_node *node)
{
struct varpool_node_hook_list *entry = first_varpool_node_removal_hook;
while (entry)
{
entry->hook (node, entry->data);
entry = entry->next;
}
}
/* Register HOOK to be called with DATA on each inserted node. */
struct varpool_node_hook_list *
varpool_add_variable_insertion_hook (varpool_node_hook hook, void *data)
{
struct varpool_node_hook_list *entry;
struct varpool_node_hook_list **ptr = &first_varpool_variable_insertion_hook;
entry = (struct varpool_node_hook_list *) xmalloc (sizeof (*entry));
entry->hook = hook;
entry->data = data;
entry->next = NULL;
while (*ptr)
ptr = &(*ptr)->next;
*ptr = entry;
return entry;
}
/* Remove ENTRY from the list of hooks called on inserted nodes. */
void
varpool_remove_variable_insertion_hook (struct varpool_node_hook_list *entry)
{
struct varpool_node_hook_list **ptr = &first_varpool_variable_insertion_hook;
while (*ptr != entry)
ptr = &(*ptr)->next;
*ptr = entry->next;
free (entry);
}
/* Call all node insertion hooks. */
void
varpool_call_variable_insertion_hooks (struct varpool_node *node)
{
struct varpool_node_hook_list *entry = first_varpool_variable_insertion_hook;
while (entry)
{
entry->hook (node, entry->data);
entry = entry->next;
}
}
/* Allocate new callgraph node and insert it into basic data structures. */ /* Allocate new callgraph node and insert it into basic data structures. */
struct varpool_node * struct varpool_node *
...@@ -65,8 +159,9 @@ varpool_node_for_decl (tree decl) ...@@ -65,8 +159,9 @@ varpool_node_for_decl (tree decl)
void void
varpool_remove_node (struct varpool_node *node) varpool_remove_node (struct varpool_node *node)
{ {
symtab_unregister_node ((symtab_node)node);
tree init; tree init;
varpool_call_node_removal_hooks (node);
symtab_unregister_node ((symtab_node)node);
/* Because we remove references from external functions before final compilation, /* Because we remove references from external functions before final compilation,
we may end up removing useful constructors. we may end up removing useful constructors.
...@@ -246,6 +341,7 @@ varpool_add_new_variable (tree decl) ...@@ -246,6 +341,7 @@ varpool_add_new_variable (tree decl)
struct varpool_node *node; struct varpool_node *node;
varpool_finalize_decl (decl); varpool_finalize_decl (decl);
node = varpool_node_for_decl (decl); node = varpool_node_for_decl (decl);
varpool_call_variable_insertion_hooks (node);
if (varpool_externally_visible_p (node)) if (varpool_externally_visible_p (node))
node->symbol.externally_visible = true; node->symbol.externally_visible = true;
} }
......
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