+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>
PR c++/54941
typedef void (*cgraph_edge_hook)(struct cgraph_edge *, 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 *,
void *);
typedef void (*cgraph_2node_hook)(struct cgraph_node *, struct cgraph_node *,
void *);
struct cgraph_edge_hook_list;
struct cgraph_node_hook_list;
+struct varpool_node_hook_list;
struct cgraph_2edge_hook_list;
struct cgraph_2node_hook_list;
struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *);
struct cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook,
void *);
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,
void *);
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);
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 *);
#include "tree-flow.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. */
struct varpool_node *
void
varpool_remove_node (struct varpool_node *node)
{
- symtab_unregister_node ((symtab_node)node);
tree init;
+ varpool_call_node_removal_hooks (node);
+ symtab_unregister_node ((symtab_node)node);
/* Because we remove references from external functions before final compilation,
we may end up removing useful constructors.
struct varpool_node *node;
varpool_finalize_decl (decl);
node = varpool_node_for_decl (decl);
+ varpool_call_variable_insertion_hooks (node);
if (varpool_externally_visible_p (node))
node->symbol.externally_visible = true;
}