Symbol table 5/many: Introduce symtab.c and commonize linked list of symbol table entries

Jan Hubicka hubicka@ucw.cz
Mon Apr 16 13:45:00 GMT 2012


Hi,
this patch starts with process of commonizing code that should be in symtab.c.
It moves linked lists out of cgraph and varpool nodes into the symbol base
type and compensates all remaining places we walk the lists directly to use
the accessor functions.

Finally bit of benefits and code unification...

Bootstrapped/regtested x86_64-linux, will commit it shortly.

	* cgraph.h (symtab_node_base): Add next and previous pointers.
	(cgraph_node): Remove next and preivous pointers.
	(varpool_node): Likewise; remove next/previous GTY marker;
	it is not type safe.
	(symtab_node_def): Update GTY marker
	(x_cgraph_nodes, cgraph_nodes): Remove.
	(symtab_nodes): New function.
	(cgraph_order): Rename to ...
	(symtab_order): ... this one.
	(symtab_register_node, symtab_unregister_node, symtab_remove_node):
	Declare.
	(x_varpool_nodes, varpool_nodes): Remove.
	(FOR_EACH_STATIC_VARIABLE): Update.
	(symtab_function_p, symtab_variable_p): New function.
	(FOR_EACH_VARIABLE): Update.
	(varpool_first_variable, varpool_next_variable): New functions.
	(FOR_EACH_VARIABLE): Update.
	(cgraph_first_defined_function): Update.
	(cgraph_next_defined_function, cgraph_next_defined_function): Update.
	(FOR_EACH_DEFINED_FUNCTION, FOR_EACH_FUNCTION): Update.
	(cgraph_first_function, cgraph_next_function): New.
	(FOR_EACH_FUNCTION): Update.
	(cgraph_first_function_with_gimple_body,
	cgraph_next_function_with_gimple_body): Update.
	* symtab.c: New file.
	* cgraph.c: Update copyright dates.
	(x_cgraph_nodes, cgraph_order): Remove.
	(NEXT_FREE_NODE): Update.
	(SET_NEXT_FREE_NODE): New.
	(cgraph_create_node_1): Remove common code.
	(cgraph_create_node); Remove common code; call symtab_register_node.
	(cgraph_remove_node): Remove common code; call symtab_unregister-node.
	(cgraph_add_asm_node); update.
	(cgraph_clone_node): Register new node.
	* cgraphunit.c (process_function_and_variable_attributes): Update.
	(cgraph_analyze_functions): Update.
	(cgraph_analyze_functions): Update.
	(cgraph_output_in_order): Update.
	* lto-cgraph.c (input_node, input_varpool_node, input_cgraph_1): Update.
	* ipa-inline.c (recursive_inlining); update.
	* lto-streamer-in.c (lto_input_toplevel_asms); Update.
	* ipa.c (cgraph_remove_unreachable_nodes): Update.
	* Makefile.in: Add symtab.o
	* varpool.c (x_varpool_nodes): Remove
	(varpool_node): Remove common code; call symtab_register_node.
	(varpool_remove_node); Remove common code; call symtab_unregister_node.
Index: cgraph.h
===================================================================
*** cgraph.h	(revision 186492)
--- cgraph.h	(working copy)
*************** struct GTY(()) symtab_node_base
*** 57,62 ****
--- 57,66 ----
    /* File stream where this node is being written to.  */
    struct lto_file_decl_data * lto_file_data;
  
+   /* Linked list of symbol table entries starting with symtab_nodes.  */
+   symtab_node next;
+   symtab_node previous;
+ 
    PTR GTY ((skip)) aux;
  
    /* Set when function has address taken.
*************** struct GTY(()) cgraph_node {
*** 190,201 ****
    struct symtab_node_base symbol;
    struct cgraph_edge *callees;
    struct cgraph_edge *callers;
-   struct cgraph_node *
-     GTY ((nested_ptr (union symtab_node_def, "(struct cgraph_node *)(%h)", "(symtab_node)%h")))
-     next;
-   struct cgraph_node *
-     GTY ((nested_ptr (union symtab_node_def, "(struct cgraph_node *)(%h)", "(symtab_node)%h")))
-     previous;
    /* List of edges representing indirect calls with a yet undetermined
       callee.  */
    struct cgraph_edge *indirect_calls;
--- 194,199 ----
*************** DEF_VEC_ALLOC_P(cgraph_edge_p,heap);
*** 417,433 ****
  /* The varpool data structure.
     Each static variable decl has assigned varpool_node.  */
  
! struct GTY((chain_next ("%h.next"), chain_prev ("%h.prev"))) varpool_node {
    struct symtab_node_base symbol;
    /* For aliases points to declaration DECL is alias of.  */
    tree alias_of;
-   /* Pointer to the next function in varpool_nodes.  */
-   struct varpool_node *
-     GTY ((nested_ptr (union symtab_node_def, "(struct varpool_node *)(%h)", "(symtab_node)%h")))
-     next;
-   struct varpool_node *
-     GTY ((nested_ptr (union symtab_node_def, "(struct varpool_node *)(%h)", "(symtab_node)%h")))
-     prev;
    /* Pointer to the next function in varpool_nodes_queue.  */
    struct varpool_node *
      GTY ((nested_ptr (union symtab_node_def, "(struct varpool_node *)(%h)", "(symtab_node)%h")))
--- 415,424 ----
  /* The varpool data structure.
     Each static variable decl has assigned varpool_node.  */
  
! struct GTY(()) varpool_node {
    struct symtab_node_base symbol;
    /* For aliases points to declaration DECL is alias of.  */
    tree alias_of;
    /* Pointer to the next function in varpool_nodes_queue.  */
    struct varpool_node *
      GTY ((nested_ptr (union symtab_node_def, "(struct varpool_node *)(%h)", "(symtab_node)%h")))
*************** struct GTY(()) cgraph_asm_node {
*** 467,473 ****
  };
  
  /* Symbol table entry.  */
! union GTY((desc ("%h.symbol.type"))) symtab_node_def {
    struct symtab_node_base GTY ((tag ("SYMTAB_SYMBOL"))) symbol;
    /* Use cgraph (symbol) accessor to get cgraph_node.  */
    struct cgraph_node GTY ((tag ("SYMTAB_FUNCTION"))) x_function;
--- 458,465 ----
  };
  
  /* Symbol table entry.  */
! union GTY((desc ("%h.symbol.type"), chain_next ("%h.symbol.next"),
! 	   chain_prev ("%h.symbol.previous"))) symtab_node_def {
    struct symtab_node_base GTY ((tag ("SYMTAB_SYMBOL"))) symbol;
    /* Use cgraph (symbol) accessor to get cgraph_node.  */
    struct cgraph_node GTY ((tag ("SYMTAB_FUNCTION"))) x_function;
*************** union GTY((desc ("%h.symbol.type"))) sym
*** 475,482 ****
    struct varpool_node GTY ((tag ("SYMTAB_VARIABLE"))) x_variable;
  };
  
! extern GTY(()) symtab_node x_cgraph_nodes;
! #define cgraph_nodes ((struct cgraph_node *)x_cgraph_nodes)
  extern GTY(()) int cgraph_n_nodes;
  extern GTY(()) int cgraph_max_uid;
  extern GTY(()) int cgraph_edge_max_uid;
--- 467,473 ----
    struct varpool_node GTY ((tag ("SYMTAB_VARIABLE"))) x_variable;
  };
  
! extern GTY(()) symtab_node symtab_nodes;
  extern GTY(()) int cgraph_n_nodes;
  extern GTY(()) int cgraph_max_uid;
  extern GTY(()) int cgraph_edge_max_uid;
*************** extern GTY(()) symtab_node x_cgraph_node
*** 501,509 ****
  extern GTY(()) struct cgraph_node *cgraph_new_nodes;
  
  extern GTY(()) struct cgraph_asm_node *cgraph_asm_nodes;
! extern GTY(()) int cgraph_order;
  extern bool same_body_aliases_done;
  
  /* In cgraph.c  */
  void dump_cgraph (FILE *);
  void debug_cgraph (void);
--- 492,505 ----
  extern GTY(()) struct cgraph_node *cgraph_new_nodes;
  
  extern GTY(()) struct cgraph_asm_node *cgraph_asm_nodes;
! extern GTY(()) int symtab_order;
  extern bool same_body_aliases_done;
  
+ /* In symtab.c  */
+ void symtab_register_node (symtab_node);
+ void symtab_unregister_node (symtab_node);
+ void symtab_remove_node (symtab_node);
+ 
  /* In cgraph.c  */
  void dump_cgraph (FILE *);
  void debug_cgraph (void);
*************** bool cgraph_optimize_for_size_p (struct 
*** 684,692 ****
  
  /* In varpool.c  */
  extern GTY(()) symtab_node x_varpool_nodes_queue;
- extern GTY(()) symtab_node x_varpool_nodes;
  #define varpool_nodes_queue ((struct varpool_node *)x_varpool_nodes_queue)
- #define varpool_nodes ((struct varpool_node *)x_varpool_nodes)
  
  struct varpool_node *varpool_node (tree);
  struct varpool_node *varpool_node_for_asm (tree asmname);
--- 680,686 ----
*************** bool varpool_for_node_and_aliases (struc
*** 721,729 ****
  			           void *, bool);
  void varpool_add_new_variable (tree);
  
! /* Walk all reachable static variables.  */
! #define FOR_EACH_STATIC_VARIABLE(node) \
!    for ((node) = varpool_nodes_queue; (node); (node) = (node)->next_needed)
  
  /* Return callgraph node for given symbol and check it is a function. */
  static inline struct cgraph_node *
--- 715,733 ----
  			           void *, bool);
  void varpool_add_new_variable (tree);
  
! /* Return true when NODE is function.  */
! static inline bool
! symtab_function_p (symtab_node node)
! {
!   return node->symbol.type == SYMTAB_FUNCTION;
! }
! 
! /* Return true when NODE is variable.  */
! static inline bool
! symtab_variable_p (symtab_node node)
! {
!   return node->symbol.type == SYMTAB_VARIABLE;
! }
  
  /* Return callgraph node for given symbol and check it is a function. */
  static inline struct cgraph_node *
*************** varpool_next_static_initializer (struct 
*** 769,781 ****
    return NULL;
  }
  
  /* Walk all static variables with initializer set.  */
  #define FOR_EACH_STATIC_INITIALIZER(node) \
     for ((node) = varpool_first_static_initializer (); (node); \
          (node) = varpool_next_static_initializer (node))
  /* Walk all variables.  */
  #define FOR_EACH_VARIABLE(node) \
!    for ((node) = varpool_nodes; (node); (node) = (node)->next)
  /* Walk all variables with definitions in current unit.  */
  #define FOR_EACH_DEFINED_VARIABLE(node) \
     for ((node) = varpool_nodes_queue; (node); (node) = (node)->next_needed)
--- 773,816 ----
    return NULL;
  }
  
+ /* Walk all reachable static variables.  */
+ #define FOR_EACH_STATIC_VARIABLE(node) \
+    for ((node) = varpool_nodes_queue; (node); (node) = (node)->next_needed)
  /* Walk all static variables with initializer set.  */
  #define FOR_EACH_STATIC_INITIALIZER(node) \
     for ((node) = varpool_first_static_initializer (); (node); \
          (node) = varpool_next_static_initializer (node))
+ 
+ /* Return first variable.  */
+ static inline struct varpool_node *
+ varpool_first_variable (void)
+ {
+   symtab_node node;
+   for (node = symtab_nodes; node; node = node->symbol.next)
+     {
+       if (symtab_variable_p (node))
+ 	return varpool (node);
+     }
+   return NULL;
+ }
+ 
+ /* Return next variable after NODE.  */
+ static inline struct varpool_node *
+ varpool_next_variable (struct varpool_node *node)
+ {
+   symtab_node node1 = (symtab_node) node->symbol.next;
+   for (; node1; node1 = node1->symbol.next)
+     {
+       if (symtab_variable_p (node1))
+ 	return varpool (node1);
+     }
+   return NULL;
+ }
  /* Walk all variables.  */
  #define FOR_EACH_VARIABLE(node) \
!    for ((node) = varpool_first_variable (); \
!         (node); \
! 	(node) = varpool_next_variable ((node)))
  /* Walk all variables with definitions in current unit.  */
  #define FOR_EACH_DEFINED_VARIABLE(node) \
     for ((node) = varpool_nodes_queue; (node); (node) = (node)->next_needed)
*************** varpool_next_static_initializer (struct 
*** 784,794 ****
  static inline struct cgraph_node *
  cgraph_first_defined_function (void)
  {
!   struct cgraph_node *node;
!   for (node = cgraph_nodes; node; node = node->next)
      {
!       if (node->analyzed)
! 	return node;
      }
    return NULL;
  }
--- 819,829 ----
  static inline struct cgraph_node *
  cgraph_first_defined_function (void)
  {
!   symtab_node node;
!   for (node = symtab_nodes; node; node = node->symbol.next)
      {
!       if (symtab_function_p (node) && cgraph (node)->analyzed)
! 	return cgraph (node);
      }
    return NULL;
  }
*************** cgraph_first_defined_function (void)
*** 797,806 ****
  static inline struct cgraph_node *
  cgraph_next_defined_function (struct cgraph_node *node)
  {
!   for (node = node->next; node; node = node->next)
      {
!       if (node->analyzed)
! 	return node;
      }
    return NULL;
  }
--- 832,842 ----
  static inline struct cgraph_node *
  cgraph_next_defined_function (struct cgraph_node *node)
  {
!   symtab_node node1 = (symtab_node) node->symbol.next;
!   for (; node1; node1 = node1->symbol.next)
      {
!       if (symtab_function_p (node1) && cgraph (node1)->analyzed)
! 	return cgraph (node1);
      }
    return NULL;
  }
*************** cgraph_next_defined_function (struct cgr
*** 808,817 ****
  /* Walk all functions with body defined.  */
  #define FOR_EACH_DEFINED_FUNCTION(node) \
     for ((node) = cgraph_first_defined_function (); (node); \
!         (node) = cgraph_next_defined_function (node))
  /* Walk all functions.  */
  #define FOR_EACH_FUNCTION(node) \
!    for ((node) = cgraph_nodes; (node); (node) = (node)->next)
  
  /* Return true when NODE is a function with Gimple body defined
     in current unit.  Functions can also be define externally or they
--- 844,880 ----
  /* Walk all functions with body defined.  */
  #define FOR_EACH_DEFINED_FUNCTION(node) \
     for ((node) = cgraph_first_defined_function (); (node); \
!         (node) = cgraph_next_defined_function ((node)))
! 
! /* Return first function.  */
! static inline struct cgraph_node *
! cgraph_first_function (void)
! {
!   symtab_node node;
!   for (node = symtab_nodes; node; node = node->symbol.next)
!     {
!       if (symtab_function_p (node))
! 	return cgraph (node);
!     }
!   return NULL;
! }
! 
! /* Return next function.  */
! static inline struct cgraph_node *
! cgraph_next_function (struct cgraph_node *node)
! {
!   symtab_node node1 = (symtab_node) node->symbol.next;
!   for (; node1; node1 = node1->symbol.next)
!     {
!       if (symtab_function_p (node1))
! 	return cgraph (node1);
!     }
!   return NULL;
! }
  /* Walk all functions.  */
  #define FOR_EACH_FUNCTION(node) \
!    for ((node) = cgraph_first_function (); (node); \
!         (node) = cgraph_next_function ((node)))
  
  /* Return true when NODE is a function with Gimple body defined
     in current unit.  Functions can also be define externally or they
*************** cgraph_function_with_gimple_body_p (stru
*** 829,839 ****
  static inline struct cgraph_node *
  cgraph_first_function_with_gimple_body (void)
  {
!   struct cgraph_node *node;
!   for (node = cgraph_nodes; node; node = node->next)
      {
!       if (cgraph_function_with_gimple_body_p (node))
! 	return node;
      }
    return NULL;
  }
--- 892,903 ----
  static inline struct cgraph_node *
  cgraph_first_function_with_gimple_body (void)
  {
!   symtab_node node;
!   for (node = symtab_nodes; node; node = node->symbol.next)
      {
!       if (symtab_function_p (node)
! 	  && cgraph_function_with_gimple_body_p (cgraph (node)))
! 	return cgraph (node);
      }
    return NULL;
  }
*************** cgraph_first_function_with_gimple_body (
*** 842,851 ****
  static inline struct cgraph_node *
  cgraph_next_function_with_gimple_body (struct cgraph_node *node)
  {
!   for (node = node->next; node; node = node->next)
      {
!       if (cgraph_function_with_gimple_body_p (node))
! 	return node;
      }
    return NULL;
  }
--- 906,917 ----
  static inline struct cgraph_node *
  cgraph_next_function_with_gimple_body (struct cgraph_node *node)
  {
!   symtab_node node1 = node->symbol.next;
!   for (; node1; node1 = node1->symbol.next)
      {
!       if (symtab_function_p (node1)
! 	  && cgraph_function_with_gimple_body_p (cgraph (node1)))
! 	return cgraph (node1);
      }
    return NULL;
  }
Index: symtab.c
===================================================================
*** symtab.c	(revision 0)
--- symtab.c	(revision 0)
***************
*** 0 ****
--- 1,97 ----
+ /* Symbol table.
+    Copyright (C) 2012 Free Software Foundation, Inc.
+    Contributed by Jan Hubicka
+ 
+ This file is part of GCC.
+ 
+ GCC is free software; you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free
+ Software Foundation; either version 3, or (at your option) any later
+ version.
+ 
+ GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ for more details.
+ 
+ You should have received a copy of the GNU General Public License
+ along with GCC; see the file COPYING3.  If not see
+ <http://www.gnu.org/licenses/>.  */
+ 
+ #include "config.h"
+ #include "system.h"
+ #include "coretypes.h"
+ #include "tm.h"
+ #include "tree.h"
+ #include "tree-inline.h"
+ #include "hashtab.h"
+ #include "cgraph.h"
+ 
+ /* Linked list of symbol table nodes.  */
+ symtab_node symtab_nodes;
+ 
+ /* The order index of the next symtab node to be created.  This is
+    used so that we can sort the cgraph nodes in order by when we saw
+    them, to support -fno-toplevel-reorder.  */
+ int symtab_order;
+ 
+ /* Add node into symbol table.  This function is not used directly, but via
+    cgraph/varpool node creation routines.  */
+ 
+ void
+ symtab_register_node (symtab_node node)
+ {
+   node->symbol.next = symtab_nodes;
+   node->symbol.previous = NULL;
+   if (symtab_nodes)
+     symtab_nodes->symbol.previous = node;
+   symtab_nodes = node;
+ 
+   node->symbol.order = symtab_order++;
+ 
+   ipa_empty_ref_list (&node->symbol.ref_list);
+ }
+ 
+ /* Remove node from symbol table.  This function is not used directly, but via
+    cgraph/varpool node removal routines.  */
+ 
+ void
+ symtab_unregister_node (symtab_node node)
+ {
+   ipa_remove_all_references (&node->symbol.ref_list);
+   ipa_remove_all_refering (&node->symbol.ref_list);
+ 
+   if (node->symbol.same_comdat_group)
+     {
+       symtab_node prev;
+       for (prev = node->symbol.same_comdat_group;
+ 	   prev->symbol.same_comdat_group != (symtab_node)node;
+ 	   prev = prev->symbol.same_comdat_group)
+ 	;
+       if (node->symbol.same_comdat_group == prev)
+ 	prev->symbol.same_comdat_group = NULL;
+       else
+ 	prev->symbol.same_comdat_group = node->symbol.same_comdat_group;
+       node->symbol.same_comdat_group = NULL;
+     }
+ 
+   if (node->symbol.previous)
+     node->symbol.previous->symbol.next = node->symbol.next;
+   else
+     symtab_nodes = node->symbol.next;
+   if (node->symbol.next)
+     node->symbol.next->symbol.previous = node->symbol.previous;
+   node->symbol.next = NULL;
+   node->symbol.previous = NULL;
+ }
+ 
+ /* Remove symtab NODE from the symbol table.  */
+ 
+ void
+ symtab_remove_node (symtab_node node)
+ {
+   if (symtab_function_p (node))
+     cgraph_remove_node (cgraph (node));
+   else if (symtab_variable_p (node))
+     varpool_remove_node (varpool (node));
+ }
Index: cgraph.c
===================================================================
*** cgraph.c	(revision 186492)
--- cgraph.c	(working copy)
***************
*** 1,6 ****
  /* Callgraph handling code.
!    Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
!    Free Software Foundation, Inc.
     Contributed by Jan Hubicka
  
  This file is part of GCC.
--- 1,6 ----
  /* Callgraph handling code.
!    Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
!    2011, 2012 Free Software Foundation, Inc.
     Contributed by Jan Hubicka
  
  This file is part of GCC.
*************** static GTY((param_is (union symtab_node_
*** 124,132 ****
  /* Hash table used to convert assembler names into nodes.  */
  static GTY((param_is (union symtab_node_def))) htab_t assembler_name_hash;
  
- /* The linked list of cgraph nodes.  */
- symtab_node x_cgraph_nodes;
- 
  /* Queue of cgraph nodes scheduled to be lowered.  */
  symtab_node x_cgraph_nodes_queue;
  #define cgraph_nodes_queue ((struct cgraph_node *)x_cgraph_nodes_queue)
--- 124,129 ----
*************** struct cgraph_asm_node *cgraph_asm_nodes
*** 160,170 ****
  /* Last node in cgraph_asm_nodes.  */
  static GTY(()) struct cgraph_asm_node *cgraph_asm_last_node;
  
- /* The order index of the next cgraph node to be created.  This is
-    used so that we can sort the cgraph nodes in order by when we saw
-    them, to support -fno-toplevel-reorder.  */
- int cgraph_order;
- 
  /* List of hooks triggered on cgraph_edge events.  */
  struct cgraph_edge_hook_list {
    cgraph_edge_hook hook;
--- 157,162 ----
*************** bool same_body_aliases_done;
*** 216,222 ****
  
  /* Macros to access the next item in the list of free cgraph nodes and
     edges. */
! #define NEXT_FREE_NODE(NODE) (NODE)->next
  #define NEXT_FREE_EDGE(EDGE) (EDGE)->prev_caller
  
  /* Register HOOK to be called with DATA on each removed edge.  */
--- 208,215 ----
  
  /* Macros to access the next item in the list of free cgraph nodes and
     edges. */
! #define NEXT_FREE_NODE(NODE) cgraph ((NODE)->symbol.next)
! #define SET_NEXT_FREE_NODE(NODE,NODE2) ((NODE))->symbol.next = (symtab_node)NODE2
  #define NEXT_FREE_EDGE(EDGE) (EDGE)->prev_caller
  
  /* Register HOOK to be called with DATA on each removed edge.  */
*************** cgraph_create_node_1 (void)
*** 475,489 ****
    struct cgraph_node *node = cgraph_allocate_node ();
  
    node->symbol.type = SYMTAB_FUNCTION;
-   node->next = cgraph_nodes;
-   node->symbol.order = cgraph_order++;
-   if (cgraph_nodes)
-     cgraph_nodes->previous = node;
-   node->previous = NULL;
    node->frequency = NODE_FREQUENCY_NORMAL;
    node->count_materialization_scale = REG_BR_PROB_BASE;
-   ipa_empty_ref_list (&node->symbol.ref_list);
-   x_cgraph_nodes = (symtab_node)node;
    cgraph_n_nodes++;
    return node;
  }
--- 468,475 ----
*************** cgraph_create_node (tree decl)
*** 506,511 ****
--- 492,498 ----
  
    node = cgraph_create_node_1 ();
    node->symbol.decl = decl;
+   symtab_register_node ((symtab_node)node);
    *slot = node;
    if (DECL_CONTEXT (decl) && TREE_CODE (DECL_CONTEXT (decl)) == FUNCTION_DECL)
      {
*************** cgraph_remove_node (struct cgraph_node *
*** 1418,1425 ****
    cgraph_call_node_removal_hooks (node);
    cgraph_node_remove_callers (node);
    cgraph_node_remove_callees (node);
-   ipa_remove_all_references (&node->symbol.ref_list);
-   ipa_remove_all_refering (&node->symbol.ref_list);
    VEC_free (ipa_opt_pass, heap,
              node->ipa_transforms_to_apply);
  
--- 1405,1410 ----
*************** cgraph_remove_node (struct cgraph_node *
*** 1437,1450 ****
  	node2 = &(*node2)->next_nested;
        *node2 = node->next_nested;
      }
!   if (node->previous)
!     node->previous->next = node->next;
!   else
!     x_cgraph_nodes = (symtab_node)node->next;
!   if (node->next)
!     node->next->previous = node->previous;
!   node->next = NULL;
!   node->previous = NULL;
    slot = htab_find_slot (cgraph_hash, node, NO_INSERT);
    if (*slot == node)
      {
--- 1422,1428 ----
  	node2 = &(*node2)->next_nested;
        *node2 = node->next_nested;
      }
!   symtab_unregister_node ((symtab_node)node);
    slot = htab_find_slot (cgraph_hash, node, NO_INSERT);
    if (*slot == node)
      {
*************** cgraph_remove_node (struct cgraph_node *
*** 1567,1586 ****
  	}
      }
  
-   if (node->symbol.same_comdat_group)
-     {
-       symtab_node prev;
-       for (prev = node->symbol.same_comdat_group;
- 	   prev->symbol.same_comdat_group != (symtab_node)node;
- 	   prev = prev->symbol.same_comdat_group)
- 	;
-       if (node->symbol.same_comdat_group == prev)
- 	prev->symbol.same_comdat_group = NULL;
-       else
- 	prev->symbol.same_comdat_group = node->symbol.same_comdat_group;
-       node->symbol.same_comdat_group = NULL;
-     }
- 
    /* While all the clones are removed after being proceeded, the function
       itself is kept in the cgraph even after it is compiled.  Check whether
       we are done with this body and reclaim it proactively if this is the case.
--- 1545,1550 ----
*************** cgraph_remove_node (struct cgraph_node *
*** 1621,1627 ****
    memset (node, 0, sizeof(*node));
    node->symbol.type = SYMTAB_FUNCTION;
    node->uid = uid;
!   NEXT_FREE_NODE (node) = free_nodes;
    free_nodes = node;
  }
  
--- 1585,1591 ----
    memset (node, 0, sizeof(*node));
    node->symbol.type = SYMTAB_FUNCTION;
    node->uid = uid;
!   SET_NEXT_FREE_NODE (node, free_nodes);
    free_nodes = node;
  }
  
*************** cgraph_add_asm_node (tree asm_str)
*** 2029,2035 ****
  
    node = ggc_alloc_cleared_cgraph_asm_node ();
    node->asm_str = asm_str;
!   node->order = cgraph_order++;
    node->next = NULL;
    if (cgraph_asm_nodes == NULL)
      cgraph_asm_nodes = node;
--- 1993,1999 ----
  
    node = ggc_alloc_cleared_cgraph_asm_node ();
    node->asm_str = asm_str;
!   node->order = symtab_order++;
    node->next = NULL;
    if (cgraph_asm_nodes == NULL)
      cgraph_asm_nodes = node;
*************** cgraph_clone_node (struct cgraph_node *n
*** 2134,2139 ****
--- 2098,2104 ----
    unsigned i;
  
    new_node->symbol.decl = decl;
+   symtab_register_node ((symtab_node)new_node);
    new_node->origin = n->origin;
    if (new_node->origin)
      {
Index: cgraphunit.c
===================================================================
*** cgraphunit.c	(revision 186492)
--- cgraphunit.c	(working copy)
*************** process_function_and_variable_attributes
*** 1085,1091 ****
    struct cgraph_node *node;
    struct varpool_node *vnode;
  
!   for (node = cgraph_nodes; node != first; node = node->next)
      {
        tree decl = node->symbol.decl;
        if (DECL_PRESERVE_P (decl))
--- 1085,1092 ----
    struct cgraph_node *node;
    struct varpool_node *vnode;
  
!   for (node = cgraph_first_function (); node != first;
!        node = cgraph_next_function (node))
      {
        tree decl = node->symbol.decl;
        if (DECL_PRESERVE_P (decl))
*************** process_function_and_variable_attributes
*** 1126,1132 ****
       
        process_common_attributes (decl);
      }
!   for (vnode = varpool_nodes; vnode != first_var; vnode = vnode->next)
      {
        tree decl = vnode->symbol.decl;
        if (DECL_PRESERVE_P (decl))
--- 1127,1134 ----
       
        process_common_attributes (decl);
      }
!   for (vnode = varpool_first_variable (); vnode != first_var;
!        vnode = varpool_next_variable (vnode))
      {
        tree decl = vnode->symbol.decl;
        if (DECL_PRESERVE_P (decl))
*************** cgraph_analyze_functions (void)
*** 1184,1196 ****
    bitmap_obstack_initialize (NULL);
    process_function_and_variable_attributes (first_processed,
  					    first_analyzed_var);
!   first_processed = cgraph_nodes;
!   first_analyzed_var = varpool_nodes;
    varpool_analyze_pending_decls ();
    if (cgraph_dump_file)
      {
        fprintf (cgraph_dump_file, "Initial entry points:");
!       for (node = cgraph_nodes; node != first_analyzed; node = node->next)
  	if (node->needed)
  	  fprintf (cgraph_dump_file, " %s", cgraph_node_name (node));
        fprintf (cgraph_dump_file, "\n");
--- 1186,1199 ----
    bitmap_obstack_initialize (NULL);
    process_function_and_variable_attributes (first_processed,
  					    first_analyzed_var);
!   first_processed = cgraph_first_function ();
!   first_analyzed_var = varpool_first_variable ();
    varpool_analyze_pending_decls ();
    if (cgraph_dump_file)
      {
        fprintf (cgraph_dump_file, "Initial entry points:");
!       for (node = cgraph_first_function (); node != first_analyzed;
! 	   node = cgraph_next_function (node))
  	if (node->needed)
  	  fprintf (cgraph_dump_file, " %s", cgraph_node_name (node));
        fprintf (cgraph_dump_file, "\n");
*************** cgraph_analyze_functions (void)
*** 1255,1262 ****
           edges.  Process their attributes too.  */
        process_function_and_variable_attributes (first_processed,
  						first_analyzed_var);
!       first_processed = cgraph_nodes;
!       first_analyzed_var = varpool_nodes;
        varpool_analyze_pending_decls ();
        cgraph_process_new_functions ();
      }
--- 1258,1265 ----
           edges.  Process their attributes too.  */
        process_function_and_variable_attributes (first_processed,
  						first_analyzed_var);
!       first_processed = cgraph_first_function ();
!       first_analyzed_var = varpool_first_variable ();
        varpool_analyze_pending_decls ();
        cgraph_process_new_functions ();
      }
*************** cgraph_analyze_functions (void)
*** 1265,1271 ****
    if (cgraph_dump_file)
      {
        fprintf (cgraph_dump_file, "Unit entry points:");
!       for (node = cgraph_nodes; node != first_analyzed; node = node->next)
  	if (node->needed)
  	  fprintf (cgraph_dump_file, " %s", cgraph_node_name (node));
        fprintf (cgraph_dump_file, "\n\nInitial ");
--- 1268,1275 ----
    if (cgraph_dump_file)
      {
        fprintf (cgraph_dump_file, "Unit entry points:");
!       for (node = cgraph_first_function (); node != first_analyzed;
! 	   node = cgraph_next_function (node))
  	if (node->needed)
  	  fprintf (cgraph_dump_file, " %s", cgraph_node_name (node));
        fprintf (cgraph_dump_file, "\n\nInitial ");
*************** cgraph_analyze_functions (void)
*** 1276,1285 ****
    if (cgraph_dump_file)
      fprintf (cgraph_dump_file, "\nReclaiming functions:");
  
!   for (node = cgraph_nodes; node != first_analyzed; node = next)
      {
        tree decl = node->symbol.decl;
!       next = node->next;
  
        if (node->local.finalized && !gimple_has_body_p (decl)
  	  && (!node->alias || !node->thunk.alias)
--- 1280,1290 ----
    if (cgraph_dump_file)
      fprintf (cgraph_dump_file, "\nReclaiming functions:");
  
!   for (node = cgraph_first_function (); node != first_analyzed;
!        node = next)
      {
        tree decl = node->symbol.decl;
!       next = cgraph_next_function (node);
  
        if (node->local.finalized && !gimple_has_body_p (decl)
  	  && (!node->alias || !node->thunk.alias)
*************** cgraph_analyze_functions (void)
*** 1309,1315 ****
        dump_varpool (cgraph_dump_file);
      }
    bitmap_obstack_release (NULL);
!   first_analyzed = cgraph_nodes;
    ggc_collect ();
  }
  
--- 1314,1320 ----
        dump_varpool (cgraph_dump_file);
      }
    bitmap_obstack_release (NULL);
!   first_analyzed = cgraph_first_function ();
    ggc_collect ();
  }
  
*************** cgraph_output_in_order (void)
*** 2076,2082 ****
    struct varpool_node *pv;
    struct cgraph_asm_node *pa;
  
!   max = cgraph_order;
    nodes = XCNEWVEC (struct cgraph_order_sort, max);
  
    varpool_analyze_pending_decls ();
--- 2081,2087 ----
    struct varpool_node *pv;
    struct cgraph_asm_node *pa;
  
!   max = symtab_order;
    nodes = XCNEWVEC (struct cgraph_order_sort, max);
  
    varpool_analyze_pending_decls ();
Index: lto-cgraph.c
===================================================================
*** lto-cgraph.c	(revision 186492)
--- lto-cgraph.c	(working copy)
*************** input_node (struct lto_file_decl_data *f
*** 998,1005 ****
      node = cgraph_get_create_node (fn_decl);
  
    node->symbol.order = order;
!   if (order >= cgraph_order)
!     cgraph_order = order + 1;
  
    node->count = streamer_read_hwi (ib);
    node->count_materialization_scale = streamer_read_hwi (ib);
--- 998,1005 ----
      node = cgraph_get_create_node (fn_decl);
  
    node->symbol.order = order;
!   if (order >= symtab_order)
!     symtab_order = order + 1;
  
    node->count = streamer_read_hwi (ib);
    node->count_materialization_scale = streamer_read_hwi (ib);
*************** input_varpool_node (struct lto_file_decl
*** 1069,1076 ****
    var_decl = lto_file_decl_data_get_var_decl (file_data, decl_index);
    node = varpool_node (var_decl);
    node->symbol.order = order;
!   if (order >= cgraph_order)
!     cgraph_order = order + 1;
    node->symbol.lto_file_data = file_data;
  
    bp = streamer_read_bitpack (ib);
--- 1069,1076 ----
    var_decl = lto_file_decl_data_get_var_decl (file_data, decl_index);
    node = varpool_node (var_decl);
    node->symbol.order = order;
!   if (order >= symtab_order)
!     symtab_order = order + 1;
    node->symbol.lto_file_data = file_data;
  
    bp = streamer_read_bitpack (ib);
*************** input_cgraph_1 (struct lto_file_decl_dat
*** 1210,1216 ****
    unsigned i;
  
    tag = streamer_read_enum (ib, LTO_cgraph_tags, LTO_cgraph_last_tag);
!   order_base = cgraph_order;
    while (tag)
      {
        if (tag == LTO_cgraph_edge)
--- 1210,1216 ----
    unsigned i;
  
    tag = streamer_read_enum (ib, LTO_cgraph_tags, LTO_cgraph_last_tag);
!   order_base = symtab_order;
    while (tag)
      {
        if (tag == LTO_cgraph_edge)
Index: ipa-inline.c
===================================================================
*** ipa-inline.c	(revision 186492)
--- ipa-inline.c	(working copy)
*************** recursive_inlining (struct cgraph_edge *
*** 1267,1276 ****
    /* Remove master clone we used for inlining.  We rely that clones inlined
       into master clone gets queued just before master clone so we don't
       need recursion.  */
!   for (node = cgraph_nodes; node != master_clone;
         node = next)
      {
!       next = node->next;
        if (node->global.inlined_to == master_clone)
  	cgraph_remove_node (node);
      }
--- 1267,1276 ----
    /* Remove master clone we used for inlining.  We rely that clones inlined
       into master clone gets queued just before master clone so we don't
       need recursion.  */
!   for (node = cgraph_first_function (); node != master_clone;
         node = next)
      {
!       next = cgraph_next_function (node);
        if (node->global.inlined_to == master_clone)
  	cgraph_remove_node (node);
      }
Index: lto-streamer-in.c
===================================================================
*** lto-streamer-in.c	(revision 186491)
--- lto-streamer-in.c	(working copy)
*************** lto_input_toplevel_asms (struct lto_file
*** 1225,1232 ****
      {
        struct cgraph_asm_node *node = cgraph_add_asm_node (str);
        node->order = streamer_read_hwi (&ib) + order_base;
!       if (node->order >= cgraph_order)
! 	cgraph_order = node->order + 1;
      }
  
    clear_line_info (data_in);
--- 1225,1232 ----
      {
        struct cgraph_asm_node *node = cgraph_add_asm_node (str);
        node->order = streamer_read_hwi (&ib) + order_base;
!       if (node->order >= symtab_order)
! 	symtab_order = node->order + 1;
      }
  
    clear_line_info (data_in);
Index: ipa.c
===================================================================
*** ipa.c	(revision 186492)
--- ipa.c	(working copy)
*************** cgraph_remove_unreachable_nodes (bool be
*** 329,337 ****
       Also we need to care functions that are unreachable but we need to keep them around
       for later clonning.  In this case we also turn them to unanalyzed nodes, but
       keep the body around.  */
!   for (node = cgraph_nodes; node; node = next)
      {
!       next = node->next;
        if (node->symbol.aux && !node->reachable)
          {
  	  cgraph_node_remove_callees (node);
--- 329,337 ----
       Also we need to care functions that are unreachable but we need to keep them around
       for later clonning.  In this case we also turn them to unanalyzed nodes, but
       keep the body around.  */
!   for (node = cgraph_first_function (); node; node = next)
      {
!       next = cgraph_next_function (node);
        if (node->symbol.aux && !node->reachable)
          {
  	  cgraph_node_remove_callees (node);
*************** cgraph_remove_unreachable_nodes (bool be
*** 425,433 ****
  
    if (file)
      fprintf (file, "Reclaiming variables:");
!   for (vnode = varpool_nodes; vnode; vnode = vnext)
      {
!       vnext = vnode->next;
        if (!vnode->needed)
          {
  	  if (file)
--- 425,433 ----
  
    if (file)
      fprintf (file, "Reclaiming variables:");
!   for (vnode = varpool_first_variable (); vnode; vnode = vnext)
      {
!       vnext = varpool_next_variable (vnode);
        if (!vnode->needed)
          {
  	  if (file)
Index: Makefile.in
===================================================================
*** Makefile.in	(revision 186491)
--- Makefile.in	(working copy)
*************** OBJS = \
*** 1173,1178 ****
--- 1173,1179 ----
  	cfgloopanal.o \
  	cfgloopmanip.o \
  	cfgrtl.o \
+ 	symtab.o \
  	cgraph.o \
  	cgraphbuild.o \
  	cgraphunit.o \
*************** simplify-rtx.o : simplify-rtx.c $(CONFIG
*** 2909,2914 ****
--- 2910,2918 ----
     $(RTL_H) $(REGS_H) hard-reg-set.h $(FLAGS_H) insn-config.h \
     $(RECOG_H) $(EXPR_H) $(DIAGNOSTIC_CORE_H) output.h $(FUNCTION_H) $(GGC_H) $(TM_P_H) \
     $(TREE_H) $(TARGET_H)
+ symtab.o : symtab.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \
+    langhooks.h toplev.h $(DIAGNOSTIC_CORE_H) $(FLAGS_H) $(GGC_H) $(TARGET_H) $(CGRAPH_H) \
+    $(HASHTAB_H) 
  cgraph.o : cgraph.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \
     langhooks.h toplev.h $(DIAGNOSTIC_CORE_H) $(FLAGS_H) $(GGC_H) $(TARGET_H) $(CGRAPH_H) \
     gt-cgraph.h output.h intl.h $(BASIC_BLOCK_H) debug.h $(HASHTAB_H) \
Index: varpool.c
===================================================================
*** varpool.c	(revision 186492)
--- varpool.c	(working copy)
*************** along with GCC; see the file COPYING3.  
*** 51,60 ****
  /* Hash table used to convert declarations into nodes.  */
  static GTY((param_is (union symtab_node_def))) htab_t varpool_hash;
  
- /* The linked list of cgraph varpool nodes.
-    Linked via node->next pointer.  */
- symtab_node x_varpool_nodes;
- 
  /* Queue of cgraph nodes scheduled to be lowered and output.
     The queue is maintained via mark_needed_node, linked via node->next_needed
     pointer.
--- 51,56 ----
*************** varpool_node (tree decl)
*** 146,157 ****
    node = ggc_alloc_cleared_varpool_node ();
    node->symbol.type = SYMTAB_VARIABLE;
    node->symbol.decl = decl;
!   node->symbol.order = cgraph_order++;
!   node->next = varpool_nodes;
!   ipa_empty_ref_list (&node->symbol.ref_list);
!   if (varpool_nodes)
!     varpool (x_varpool_nodes)->prev = node;
!   x_varpool_nodes = (symtab_node)node;
    *slot = node;
    return node;
  }
--- 142,148 ----
    node = ggc_alloc_cleared_varpool_node ();
    node->symbol.type = SYMTAB_VARIABLE;
    node->symbol.decl = decl;
!   symtab_register_node ((symtab_node)node);
    *slot = node;
    return node;
  }
*************** varpool_remove_node (struct varpool_node
*** 165,179 ****
    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
!     {
!       gcc_assert (varpool_nodes == node);
!       x_varpool_nodes = (symtab_node)node->next;
!     }
    if (varpool_first_unanalyzed_node == node)
      x_varpool_first_unanalyzed_node = (symtab_node)node->next_needed;
    if (node->next_needed)
--- 156,162 ----
    gcc_assert (*slot == node);
    htab_clear_slot (varpool_hash, slot);
    gcc_assert (!varpool_assembled_nodes_queue);
!   symtab_unregister_node ((symtab_node)node);
    if (varpool_first_unanalyzed_node == node)
      x_varpool_first_unanalyzed_node = (symtab_node)node->next_needed;
    if (node->next_needed)
*************** varpool_remove_node (struct varpool_node
*** 190,210 ****
        gcc_assert (varpool_nodes_queue == node);
        x_varpool_nodes_queue = (symtab_node)node->next_needed;
      }
-   if (node->symbol.same_comdat_group)
-     {
-       symtab_node prev;
-       for (prev = node->symbol.same_comdat_group;
- 	   prev->symbol.same_comdat_group != (symtab_node)node;
- 	   prev = prev->symbol.same_comdat_group)
- 	;
-       if (node->symbol.same_comdat_group == prev)
- 	prev->symbol.same_comdat_group = NULL;
-       else
- 	prev->symbol.same_comdat_group = (symtab_node)node->symbol.same_comdat_group;
-       node->symbol.same_comdat_group = NULL;
-     }
-   ipa_remove_all_references (&node->symbol.ref_list);
-   ipa_remove_all_refering (&node->symbol.ref_list);
    ggc_free (node);
  }
  
--- 173,178 ----



More information about the Gcc-patches mailing list