Symbol table 4/many: Use FOR_EACH constructs more consistently

Jan Hubicka hubicka@ucw.cz
Mon Apr 16 10:40:00 GMT 2012


Hi,
this patch makes more consistent use of FOR_EACH constructs to walk
callgraph/varpool, so we could move away from linked lists for each symbol type
to single linked list of all symbols more easilly.
Other motivation is to avoid accesses to analyzed/finalized/lowered flags,
since I want to replace these by symbol state enum.

Bootstrapped/regtsted x86_64-linux, will commit it after re-testing with last
minute change in.
Honza

	
	* cgraph.h (FOR_EACH_VARIABLE, FOR_EACH_VARIABLE, FOR_EACH_FUNCTION):
	New macros.
	* lto-symtab.c (lto_symtab_merge_cgraph_nodes): Use FOR_EACH
	walkers to walk cgraph and varpool.
	* cgraph.c (cgraph_node_for_asm): Likewise.
	(dump_cgraph): Likewise.
	* value-prof.c (init_node_map): Likewise.
	* tree.c (free_lang_data_in_cgraph): Likewise.
	* tree-emutls.c: (ipa_lower_emutls): Likewise.
	* ipa-reference.c (generate_summary, propagate): Likewise.
	* cgraphunit.c (verify_cgraph, cgraph_process_same_body_aliases,
	cgraph_mark_functions_to_output, cgraph_output_in_order,
	output_weakrefs, cgraph_materialize_all_clones,
	cgraph_optimize): Likewise.
	* lto-cgraph.c (merge_profile_summaries): Likewise.
	(input_cgraph): Likewise.
	* ipa-pure-const.c (generate_summary): Likewise.
	(propagate): Likwise.
	* ipa-utils.c (ipa_reduced_postorder): Likewise.
	(ipa_free_postorder_info): Likewise.
	(ipa_reverse_postorder): Likewise.
	* ipa-inline.c (ipa_inline): Likewise.
	* matrix-reorg.c (find_matrices_decl): Likewise.
	(matrix_reorg): Likewise.
	* tree-vectorizer.c (increase_alignment): Likewise.
	* ipa.c (cgraph_remove_unreachable_nodes): Likewise.
	(function_and_variable_visibility): Likewise.
	(whole_program_function_and_variable_visibility): Likewise.
	(ipa_cdtor_merge): Likewise.
	* trans-mem.c (ipa_tm_execute): Likewise.
	* ipa-inline-analysis.c (dump_inline_summaries): Likewise.
	* ipa-prop.c (ipa_print_all_jump_functions): Likewise.
	(ipa_print_all_params): Likewise.
	(ipa_update_after_lto_read): Likewise.
	* tree-profie.c (tree_profiling): Likewise.
	* tree-ssa-structalias.c (ipa_pta_execute): Likewise.
	* passes.c (dump_passes): Likewise.
	(do_per_function): Likewise.
	(ipa_write_summaries): Likewise.
	* varpool.c (dump_varpool): Likewise.
	(varpool_node_for_asm): Likewise.
	(varpool_assemble_pending_decls): Likewise.


	* decl2.c (collect_candidates_for_java_method_alias): Use FOR_EACH
        walkers to walk cgraph and varpool.

	* lto.c (read_cgraph_and_symbols): Use FOR_EACH
        walkers to walk cgraph and varpool.
	(materialize_cgraph): Likewise.
	* lto-partition.c (lto_1_to_1_map): Likewise.
	(lto_balanced_map): Likewise.
	(lto_promote_cross_file_statics): Likewise.
Index: lto-symtab.c
===================================================================
*** lto-symtab.c	(revision 186466)
--- lto-symtab.c	(working copy)
*************** lto_symtab_merge_cgraph_nodes (void)
*** 761,771 ****
    lto_symtab_maybe_init_hash_table ();
    htab_traverse (lto_symtab_identifiers, lto_symtab_merge_cgraph_nodes_1, NULL);
  
!   for (node = cgraph_nodes; node; node = node->next)
      if ((node->thunk.thunk_p || node->alias)
  	&& node->thunk.alias)
        node->thunk.alias = lto_symtab_prevailing_decl (node->thunk.alias);
!   for (vnode = varpool_nodes; vnode; vnode = vnode->next)
      if (vnode->alias_of)
        vnode->alias_of = lto_symtab_prevailing_decl (vnode->alias_of);
  }
--- 761,771 ----
    lto_symtab_maybe_init_hash_table ();
    htab_traverse (lto_symtab_identifiers, lto_symtab_merge_cgraph_nodes_1, NULL);
  
!   FOR_EACH_FUNCTION (node)
      if ((node->thunk.thunk_p || node->alias)
  	&& node->thunk.alias)
        node->thunk.alias = lto_symtab_prevailing_decl (node->thunk.alias);
!   FOR_EACH_VARIABLE (vnode)
      if (vnode->alias_of)
        vnode->alias_of = lto_symtab_prevailing_decl (vnode->alias_of);
  }
Index: cgraph.c
===================================================================
*** cgraph.c	(revision 186466)
--- cgraph.c	(working copy)
*************** cgraph_node_for_asm (tree asmname)
*** 711,717 ****
        assembler_name_hash =
  	htab_create_ggc (10, hash_node_by_assembler_name, eq_assembler_name,
  			 NULL);
!       for (node = cgraph_nodes; node; node = node->next)
          if (!node->global.inlined_to)
  	  {
  	    tree name = DECL_ASSEMBLER_NAME (node->symbol.decl);
--- 711,717 ----
        assembler_name_hash =
  	htab_create_ggc (10, hash_node_by_assembler_name, eq_assembler_name,
  			 NULL);
!       FOR_EACH_FUNCTION (node)
          if (!node->global.inlined_to)
  	  {
  	    tree name = DECL_ASSEMBLER_NAME (node->symbol.decl);
*************** dump_cgraph (FILE *f)
*** 1962,1968 ****
    struct cgraph_node *node;
  
    fprintf (f, "callgraph:\n\n");
!   for (node = cgraph_nodes; node; node = node->next)
      dump_cgraph_node (f, node);
  }
  
--- 1962,1968 ----
    struct cgraph_node *node;
  
    fprintf (f, "callgraph:\n\n");
!   FOR_EACH_FUNCTION (node)
      dump_cgraph_node (f, node);
  }
  
Index: cgraph.h
===================================================================
*** cgraph.h	(revision 186466)
--- cgraph.h	(working copy)
*************** varpool_next_static_initializer (struct 
*** 773,778 ****
--- 773,784 ----
  #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)
  
  /* Return first function with body defined.  */
  static inline struct cgraph_node *
*************** cgraph_next_defined_function (struct cgr
*** 803,809 ****
  #define FOR_EACH_DEFINED_FUNCTION(node) \
     for ((node) = cgraph_first_defined_function (); (node); \
          (node) = cgraph_next_defined_function (node))
! 
  
  /* Return true when NODE is a function with Gimple body defined
     in current unit.  Functions can also be define externally or they
--- 809,817 ----
  #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
Index: value-prof.c
===================================================================
*** value-prof.c	(revision 186466)
--- value-prof.c	(working copy)
*************** init_node_map (void)
*** 1073,1079 ****
      VEC_safe_grow_cleared (cgraph_node_ptr, heap,
                             cgraph_node_map, get_last_funcdef_no ());
  
!   for (n = cgraph_nodes; n; n = n->next)
      {
        if (DECL_STRUCT_FUNCTION (n->symbol.decl))
          VEC_replace (cgraph_node_ptr, cgraph_node_map,
--- 1073,1079 ----
      VEC_safe_grow_cleared (cgraph_node_ptr, heap,
                             cgraph_node_map, get_last_funcdef_no ());
  
!   FOR_EACH_FUNCTION (n)
      {
        if (DECL_STRUCT_FUNCTION (n->symbol.decl))
          VEC_replace (cgraph_node_ptr, cgraph_node_map,
Index: tree.c
===================================================================
*** tree.c	(revision 186466)
--- tree.c	(working copy)
*************** free_lang_data_in_cgraph (void)
*** 5176,5189 ****
    fld.types = VEC_alloc (tree, heap, 100);
  
    /* Find decls and types in the body of every function in the callgraph.  */
!   for (n = cgraph_nodes; n; n = n->next)
      find_decls_types_in_node (n, &fld);
  
    FOR_EACH_VEC_ELT (alias_pair, alias_pairs, i, p)
      find_decls_types (p->decl, &fld);
  
    /* Find decls and types in every varpool symbol.  */
!   for (v = varpool_nodes; v; v = v->next)
      find_decls_types_in_var (v, &fld);
  
    /* Set the assembler name on every decl found.  We need to do this
--- 5176,5189 ----
    fld.types = VEC_alloc (tree, heap, 100);
  
    /* Find decls and types in the body of every function in the callgraph.  */
!   FOR_EACH_FUNCTION (n)
      find_decls_types_in_node (n, &fld);
  
    FOR_EACH_VEC_ELT (alias_pair, alias_pairs, i, p)
      find_decls_types (p->decl, &fld);
  
    /* Find decls and types in every varpool symbol.  */
!   FOR_EACH_VARIABLE (v)
      find_decls_types_in_var (v, &fld);
  
    /* Set the assembler name on every decl found.  We need to do this
Index: tree-emutls.c
===================================================================
*** tree-emutls.c	(revision 186466)
--- tree-emutls.c	(working copy)
*************** ipa_lower_emutls (void)
*** 741,747 ****
    tls_vars = varpool_node_set_new ();
  
    /* Examine all global variables for TLS variables.  */
!   for (var = varpool_nodes; var ; var = var->next)
      if (DECL_THREAD_LOCAL_P (var->symbol.decl))
        {
  	gcc_checking_assert (TREE_STATIC (var->symbol.decl)
--- 741,747 ----
    tls_vars = varpool_node_set_new ();
  
    /* Examine all global variables for TLS variables.  */
!   FOR_EACH_VARIABLE (var)
      if (DECL_THREAD_LOCAL_P (var->symbol.decl))
        {
  	gcc_checking_assert (TREE_STATIC (var->symbol.decl)
*************** ipa_lower_emutls (void)
*** 790,796 ****
      }
  
    /* Adjust all uses of TLS variables within the function bodies.  */
!   for (func = cgraph_nodes; func; func = func->next)
      if (func->reachable && func->lowered)
        lower_emutls_function_body (func);
  
--- 790,796 ----
      }
  
    /* Adjust all uses of TLS variables within the function bodies.  */
!   FOR_EACH_DEFINED_FUNCTION (func)
      if (func->reachable && func->lowered)
        lower_emutls_function_body (func);
  
Index: ipa-reference.c
===================================================================
*** ipa-reference.c	(revision 186466)
--- ipa-reference.c	(working copy)
*************** generate_summary (void)
*** 530,538 ****
    bm_temp = BITMAP_ALLOC (&local_info_obstack);
  
    /* Process all of the functions next.  */
!   for (node = cgraph_nodes; node; node = node->next)
!     if (node->analyzed)
!       analyze_function (node);
  
    if (dump_file)
      EXECUTE_IF_SET_IN_BITMAP (all_module_statics, 0, index, bi)
--- 530,537 ----
    bm_temp = BITMAP_ALLOC (&local_info_obstack);
  
    /* Process all of the functions next.  */
!   FOR_EACH_DEFINED_FUNCTION (node)
!     analyze_function (node);
  
    if (dump_file)
      EXECUTE_IF_SET_IN_BITMAP (all_module_statics, 0, index, bi)
*************** generate_summary (void)
*** 544,550 ****
    BITMAP_FREE(bm_temp);
  
    if (dump_file)
!     for (node = cgraph_nodes; node; node = node->next)
        if (cgraph_function_body_availability (node) >= AVAIL_OVERWRITABLE)
  	{
  	  ipa_reference_local_vars_info_t l;
--- 543,549 ----
    BITMAP_FREE(bm_temp);
  
    if (dump_file)
!     FOR_EACH_DEFINED_FUNCTION (node)
        if (cgraph_function_body_availability (node) >= AVAIL_OVERWRITABLE)
  	{
  	  ipa_reference_local_vars_info_t l;
*************** propagate (void)
*** 884,896 ****
      }
  
    /* Cleanup. */
!   for (node = cgraph_nodes; node; node = node->next)
      {
        ipa_reference_vars_info_t node_info;
        ipa_reference_global_vars_info_t node_g;
        ipa_reference_optimization_summary_t opt;
  
!       if (!node->analyzed || node->alias)
          continue;
  
        node_info = get_reference_vars_info (node);
--- 883,895 ----
      }
  
    /* Cleanup. */
!   FOR_EACH_DEFINED_FUNCTION (node)
      {
        ipa_reference_vars_info_t node_info;
        ipa_reference_global_vars_info_t node_g;
        ipa_reference_optimization_summary_t opt;
  
!       if (node->alias)
          continue;
  
        node_info = get_reference_vars_info (node);
Index: cgraphunit.c
===================================================================
*** cgraphunit.c	(revision 186466)
--- cgraphunit.c	(working copy)
*************** verify_cgraph (void)
*** 890,896 ****
    if (seen_error ())
      return;
  
!   for (node = cgraph_nodes; node; node = node->next)
      verify_cgraph_node (node);
  }
  
--- 890,896 ----
    if (seen_error ())
      return;
  
!   FOR_EACH_FUNCTION (node)
      verify_cgraph_node (node);
  }
  
*************** void
*** 1026,1032 ****
  cgraph_process_same_body_aliases (void)
  {
    struct cgraph_node *node;
!   for (node = cgraph_nodes; node; node = node->next)
      if (node->same_body_alias
  	&& !VEC_length (ipa_ref_t, node->symbol.ref_list.references))
        {
--- 1026,1032 ----
  cgraph_process_same_body_aliases (void)
  {
    struct cgraph_node *node;
!   FOR_EACH_FUNCTION (node)
      if (node->same_body_alias
  	&& !VEC_length (ipa_ref_t, node->symbol.ref_list.references))
        {
*************** cgraph_mark_functions_to_output (void)
*** 1398,1408 ****
  #ifdef ENABLE_CHECKING
    bool check_same_comdat_groups = false;
  
!   for (node = cgraph_nodes; node; node = node->next)
      gcc_assert (!node->process);
  #endif
  
!   for (node = cgraph_nodes; node; node = node->next)
      {
        tree decl = node->symbol.decl;
        struct cgraph_edge *e;
--- 1398,1408 ----
  #ifdef ENABLE_CHECKING
    bool check_same_comdat_groups = false;
  
!   FOR_EACH_FUNCTION (node)
      gcc_assert (!node->process);
  #endif
  
!   FOR_EACH_FUNCTION (node)
      {
        tree decl = node->symbol.decl;
        struct cgraph_edge *e;
*************** cgraph_mark_functions_to_output (void)
*** 1472,1478 ****
      }
  #ifdef ENABLE_CHECKING
    if (check_same_comdat_groups)
!     for (node = cgraph_nodes; node; node = node->next)
        if (node->symbol.same_comdat_group && !node->process)
  	{
  	  tree decl = node->symbol.decl;
--- 1472,1478 ----
      }
  #ifdef ENABLE_CHECKING
    if (check_same_comdat_groups)
!     FOR_EACH_FUNCTION (node)
        if (node->symbol.same_comdat_group && !node->process)
  	{
  	  tree decl = node->symbol.decl;
*************** cgraph_output_in_order (void)
*** 2081,2087 ****
  
    varpool_analyze_pending_decls ();
  
!   for (pf = cgraph_nodes; pf; pf = pf->next)
      {
        if (pf->process && !pf->thunk.thunk_p && !pf->alias)
  	{
--- 2081,2087 ----
  
    varpool_analyze_pending_decls ();
  
!   FOR_EACH_DEFINED_FUNCTION (pf)
      {
        if (pf->process && !pf->thunk.thunk_p && !pf->alias)
  	{
*************** cgraph_output_in_order (void)
*** 2092,2098 ****
  	}
      }
  
!   for (pv = varpool_nodes_queue; pv; pv = pv->next_needed)
      {
        i = pv->symbol.order;
        gcc_assert (nodes[i].kind == ORDER_UNDEFINED);
--- 2092,2098 ----
  	}
      }
  
!   FOR_EACH_DEFINED_VARIABLE (pv)
      {
        i = pv->symbol.order;
        gcc_assert (nodes[i].kind == ORDER_UNDEFINED);
*************** output_weakrefs (void)
*** 2246,2259 ****
  {
    struct cgraph_node *node;
    struct varpool_node *vnode;
!   for (node = cgraph_nodes; node; node = node->next)
      if (node->alias && DECL_EXTERNAL (node->symbol.decl)
          && !TREE_ASM_WRITTEN (node->symbol.decl)
  	&& lookup_attribute ("weakref", DECL_ATTRIBUTES (node->symbol.decl)))
        assemble_alias (node->symbol.decl,
  		      node->thunk.alias ? DECL_ASSEMBLER_NAME (node->thunk.alias)
  		      : get_alias_symbol (node->symbol.decl));
!   for (vnode = varpool_nodes; vnode; vnode = vnode->next)
      if (vnode->alias && DECL_EXTERNAL (vnode->symbol.decl)
          && !TREE_ASM_WRITTEN (vnode->symbol.decl)
  	&& lookup_attribute ("weakref", DECL_ATTRIBUTES (vnode->symbol.decl)))
--- 2246,2259 ----
  {
    struct cgraph_node *node;
    struct varpool_node *vnode;
!   FOR_EACH_FUNCTION (node)
      if (node->alias && DECL_EXTERNAL (node->symbol.decl)
          && !TREE_ASM_WRITTEN (node->symbol.decl)
  	&& lookup_attribute ("weakref", DECL_ATTRIBUTES (node->symbol.decl)))
        assemble_alias (node->symbol.decl,
  		      node->thunk.alias ? DECL_ASSEMBLER_NAME (node->thunk.alias)
  		      : get_alias_symbol (node->symbol.decl));
!   FOR_EACH_VARIABLE (vnode)
      if (vnode->alias && DECL_EXTERNAL (vnode->symbol.decl)
          && !TREE_ASM_WRITTEN (vnode->symbol.decl)
  	&& lookup_attribute ("weakref", DECL_ATTRIBUTES (vnode->symbol.decl)))
*************** cgraph_copy_node_for_versioning (struct 
*** 2320,2326 ****
     new_version->analyzed = old_version->analyzed;
     new_version->local = old_version->local;
     new_version->symbol.externally_visible = false;
!    new_version->local.local = true;
     new_version->global = old_version->global;
     new_version->rtl = old_version->rtl;
     new_version->reachable = true;
--- 2320,2326 ----
     new_version->analyzed = old_version->analyzed;
     new_version->local = old_version->local;
     new_version->symbol.externally_visible = false;
!    new_version->local.local = old_version->analyzed;
     new_version->global = old_version->global;
     new_version->rtl = old_version->rtl;
     new_version->reachable = true;
*************** cgraph_materialize_all_clones (void)
*** 2578,2584 ****
    while (!stabilized)
      {
        stabilized = true;
!       for (node = cgraph_nodes; node; node = node->next)
          {
  	  if (node->clone_of && node->symbol.decl != node->clone_of->symbol.decl
  	      && !gimple_has_body_p (node->symbol.decl))
--- 2578,2584 ----
    while (!stabilized)
      {
        stabilized = true;
!       FOR_EACH_FUNCTION (node)
          {
  	  if (node->clone_of && node->symbol.decl != node->clone_of->symbol.decl
  	      && !gimple_has_body_p (node->symbol.decl))
*************** cgraph_materialize_all_clones (void)
*** 2628,2634 ****
  	    }
  	}
      }
!   for (node = cgraph_nodes; node; node = node->next)
      if (!node->analyzed && node->callees)
        cgraph_node_remove_callees (node);
    if (cgraph_dump_file)
--- 2628,2634 ----
  	    }
  	}
      }
!   FOR_EACH_FUNCTION (node)
      if (!node->analyzed && node->callees)
        cgraph_node_remove_callees (node);
    if (cgraph_dump_file)
*************** cgraph_optimize (void)
*** 2745,2754 ****
        struct cgraph_node *node;
        bool error_found = false;
  
!       for (node = cgraph_nodes; node; node = node->next)
! 	if (node->analyzed
! 	    && (node->global.inlined_to
! 		|| gimple_has_body_p (node->symbol.decl)))
  	  {
  	    error_found = true;
  	    dump_cgraph_node (stderr, node);
--- 2745,2753 ----
        struct cgraph_node *node;
        bool error_found = false;
  
!       FOR_EACH_DEFINED_FUNCTION (node)
! 	if (node->global.inlined_to
! 	    || gimple_has_body_p (node->symbol.decl))
  	  {
  	    error_found = true;
  	    dump_cgraph_node (stderr, node);
Index: cp/decl2.c
===================================================================
*** cp/decl2.c	(revision 186466)
--- cp/decl2.c	(working copy)
*************** collect_candidates_for_java_method_alias
*** 3489,3495 ****
    return candidates;
  #endif
  
!   for (node = cgraph_nodes; node ; node = node->next)
      {
        tree fndecl = node->symbol.decl;
  
--- 3489,3495 ----
    return candidates;
  #endif
  
!   FOR_EACH_FUNCTION (node)
      {
        tree fndecl = node->symbol.decl;
  
*************** build_java_method_aliases (struct pointe
*** 3523,3529 ****
    return;
  #endif
  
!   for (node = cgraph_nodes; node ; node = node->next)
      {
        tree fndecl = node->symbol.decl;
  
--- 3523,3529 ----
    return;
  #endif
  
!   FOR_EACH_FUNCTION (node)
      {
        tree fndecl = node->symbol.decl;
  
Index: lto-cgraph.c
===================================================================
*** lto-cgraph.c	(revision 186466)
--- lto-cgraph.c	(working copy)
*************** merge_profile_summaries (struct lto_file
*** 1422,1428 ****
    /* Now compute count_materialization_scale of each node.
       During LTRANS we already have values of count_materialization_scale
       computed, so just update them.  */
!   for (node = cgraph_nodes; node; node = node->next)
      if (node->symbol.lto_file_data
  	&& node->symbol.lto_file_data->profile_info.runs)
        {
--- 1422,1428 ----
    /* Now compute count_materialization_scale of each node.
       During LTRANS we already have values of count_materialization_scale
       computed, so just update them.  */
!   FOR_EACH_FUNCTION (node)
      if (node->symbol.lto_file_data
  	&& node->symbol.lto_file_data->profile_info.runs)
        {
*************** input_cgraph (void)
*** 1501,1507 ****
  
    /* Clear out the aux field that was used to store enough state to
       tell which nodes should be overwritten.  */
!   for (node = cgraph_nodes; node; node = node->next)
      {
        /* Some nodes may have been created by cgraph_node.  This
  	 happens when the callgraph contains nested functions.  If the
--- 1501,1507 ----
  
    /* Clear out the aux field that was used to store enough state to
       tell which nodes should be overwritten.  */
!   FOR_EACH_FUNCTION (node)
      {
        /* Some nodes may have been created by cgraph_node.  This
  	 happens when the callgraph contains nested functions.  If the
Index: ipa-pure-const.c
===================================================================
*** ipa-pure-const.c	(revision 186466)
--- ipa-pure-const.c	(working copy)
*************** generate_summary (void)
*** 924,930 ****
       by default, but the info can be used at LTO with -fwhole-program or
       when function got cloned and the clone is AVAILABLE.  */
  
!   for (node = cgraph_nodes; node; node = node->next)
      if (cgraph_function_body_availability (node) >= AVAIL_OVERWRITABLE)
        set_function_state (node, analyze_function (node, true));
  
--- 924,930 ----
       by default, but the info can be used at LTO with -fwhole-program or
       when function got cloned and the clone is AVAILABLE.  */
  
!   FOR_EACH_DEFINED_FUNCTION (node)
      if (cgraph_function_body_availability (node) >= AVAIL_OVERWRITABLE)
        set_function_state (node, analyze_function (node, true));
  
*************** propagate (void)
*** 1475,1481 ****
    propagate_pure_const ();
  
    /* Cleanup. */
!   for (node = cgraph_nodes; node; node = node->next)
      if (has_function_state (node))
        free (get_function_state (node));
    VEC_free (funct_state, heap, funct_state_vec);
--- 1475,1481 ----
    propagate_pure_const ();
  
    /* Cleanup. */
!   FOR_EACH_DEFINED_FUNCTION (node)
      if (has_function_state (node))
        free (get_function_state (node));
    VEC_free (funct_state, heap, funct_state_vec);
Index: ipa-utils.c
===================================================================
*** ipa-utils.c	(revision 186466)
--- ipa-utils.c	(working copy)
*************** ipa_reduced_postorder (struct cgraph_nod
*** 178,184 ****
    env.reduce = reduce;
    env.allow_overwritable = allow_overwritable;
  
!   for (node = cgraph_nodes; node; node = node->next)
      {
        enum availability avail = cgraph_function_body_availability (node);
  
--- 178,184 ----
    env.reduce = reduce;
    env.allow_overwritable = allow_overwritable;
  
!   FOR_EACH_DEFINED_FUNCTION (node)
      {
        enum availability avail = cgraph_function_body_availability (node);
  
*************** void
*** 222,228 ****
  ipa_free_postorder_info (void)
  {
    struct cgraph_node *node;
!   for (node = cgraph_nodes; node; node = node->next)
      {
        /* Get rid of the aux information.  */
        if (node->symbol.aux)
--- 222,228 ----
  ipa_free_postorder_info (void)
  {
    struct cgraph_node *node;
!   FOR_EACH_DEFINED_FUNCTION (node)
      {
        /* Get rid of the aux information.  */
        if (node->symbol.aux)
*************** ipa_reverse_postorder (struct cgraph_nod
*** 261,270 ****
       output algorithm.  Ignore the fact that some functions won't need
       to be output and put them into order as well, so we get dependencies
       right through inline functions.  */
!   for (node = cgraph_nodes; node; node = node->next)
      node->symbol.aux = NULL;
    for (pass = 0; pass < 2; pass++)
!     for (node = cgraph_nodes; node; node = node->next)
        if (!node->symbol.aux
  	  && (pass
  	      || (!node->symbol.address_taken
--- 261,270 ----
       output algorithm.  Ignore the fact that some functions won't need
       to be output and put them into order as well, so we get dependencies
       right through inline functions.  */
!   FOR_EACH_FUNCTION (node)
      node->symbol.aux = NULL;
    for (pass = 0; pass < 2; pass++)
!     FOR_EACH_FUNCTION (node)
        if (!node->symbol.aux
  	  && (pass
  	      || (!node->symbol.address_taken
*************** ipa_reverse_postorder (struct cgraph_nod
*** 317,323 ****
  	    }
  	}
    free (stack);
!   for (node = cgraph_nodes; node; node = node->next)
      node->symbol.aux = NULL;
    return order_pos;
  }
--- 317,323 ----
  	    }
  	}
    free (stack);
!   FOR_EACH_FUNCTION (node)
      node->symbol.aux = NULL;
    return order_pos;
  }
Index: ipa-inline.c
===================================================================
*** ipa-inline.c	(revision 186466)
--- ipa-inline.c	(working copy)
*************** ipa_inline (void)
*** 1685,1691 ****
  
    nnodes = ipa_reverse_postorder (order);
  
!   for (node = cgraph_nodes; node; node = node->next)
      node->symbol.aux = 0;
  
    if (dump_file)
--- 1685,1691 ----
  
    nnodes = ipa_reverse_postorder (order);
  
!   FOR_EACH_FUNCTION (node)
      node->symbol.aux = 0;
  
    if (dump_file)
*************** ipa_inline (void)
*** 1742,1748 ****
  	 to be hot.  */
        for (cold = 0; cold <= 1; cold ++)
  	{
! 	  for (node = cgraph_nodes; node; node = node->next)
  	    {
  	      if (want_inline_function_called_once_p (node)
  		  && (cold
--- 1742,1748 ----
  	 to be hot.  */
        for (cold = 0; cold <= 1; cold ++)
  	{
! 	  FOR_EACH_DEFINED_FUNCTION (node)
  	    {
  	      if (want_inline_function_called_once_p (node)
  		  && (cold
Index: matrix-reorg.c
===================================================================
*** matrix-reorg.c	(revision 186466)
--- matrix-reorg.c	(working copy)
*************** find_matrices_decl (void)
*** 548,554 ****
  
    /* For every global variable in the program:
       Check to see if it's of a candidate type and record it.  */
!   for (vnode = varpool_nodes_queue; vnode; vnode = vnode->next_needed)
      {
        tree var_decl = vnode->symbol.decl;
  
--- 548,554 ----
  
    /* For every global variable in the program:
       Check to see if it's of a candidate type and record it.  */
!   FOR_EACH_DEFINED_VARIABLE (vnode)
      {
        tree var_decl = vnode->symbol.decl;
  
*************** matrix_reorg (void)
*** 2266,2365 ****
    else
      check_transpose_p = false;
    /* If there are hand written vectors, we skip this optimization.  */
!   for (node = cgraph_nodes; node; node = node->next)
      if (!may_flatten_matrices (node))
        return 0;
    matrices_to_reorg = htab_create (37, mtt_info_hash, mtt_info_eq, mat_free);
    /* Find and record all potential matrices in the program.  */
    find_matrices_decl ();
    /* Analyze the accesses of the matrices (escaping analysis).  */
!   for (node = cgraph_nodes; node; node = node->next)
!     if (node->analyzed)
!       {
! 	tree temp_fn;
  
! 	temp_fn = current_function_decl;
! 	current_function_decl = node->symbol.decl;
! 	push_cfun (DECL_STRUCT_FUNCTION (node->symbol.decl));
! 	bitmap_obstack_initialize (NULL);
! 	gimple_register_cfg_hooks ();
  
! 	if (!gimple_in_ssa_p (cfun))
! 	  {
! 	    free_dominance_info (CDI_DOMINATORS);
! 	    free_dominance_info (CDI_POST_DOMINATORS);
! 	    pop_cfun ();
! 	    current_function_decl = temp_fn;
! 	    bitmap_obstack_release (NULL);
  
! 	    return 0;
! 	  }
  
  #ifdef ENABLE_CHECKING
! 	verify_flow_info ();
  #endif
  
! 	if (!matrices_to_reorg)
! 	  {
! 	    free_dominance_info (CDI_DOMINATORS);
! 	    free_dominance_info (CDI_POST_DOMINATORS);
! 	    pop_cfun ();
! 	    current_function_decl = temp_fn;
! 	    bitmap_obstack_release (NULL);
! 
! 	    return 0;
! 	  }
! 
! 	/* Create htap for phi nodes.  */
! 	htab_mat_acc_phi_nodes = htab_create (37, mat_acc_phi_hash,
! 					      mat_acc_phi_eq, free);
! 	if (!check_transpose_p)
! 	  find_sites_in_func (false);
! 	else
! 	  {
! 	    find_sites_in_func (true);
! 	    loop_optimizer_init (LOOPS_NORMAL);
! 	    if (current_loops)
! 	      scev_initialize ();
! 	    htab_traverse (matrices_to_reorg, analyze_transpose, NULL);
! 	    if (current_loops)
! 	      {
! 		scev_finalize ();
! 		loop_optimizer_finalize ();
! 		current_loops = NULL;
! 	      }
! 	  }
! 	/* If the current function is the allocation function for any of
! 	   the matrices we check its allocation and the escaping level.  */
! 	htab_traverse (matrices_to_reorg, check_allocation_function, NULL);
! 	free_dominance_info (CDI_DOMINATORS);
! 	free_dominance_info (CDI_POST_DOMINATORS);
! 	pop_cfun ();
! 	current_function_decl = temp_fn;
! 	bitmap_obstack_release (NULL);
!       }
    htab_traverse (matrices_to_reorg, transform_allocation_sites, NULL);
    /* Now transform the accesses.  */
!   for (node = cgraph_nodes; node; node = node->next)
!     if (node->analyzed)
!       {
! 	/* Remember that allocation sites have been handled.  */
! 	tree temp_fn;
  
! 	temp_fn = current_function_decl;
! 	current_function_decl = node->symbol.decl;
! 	push_cfun (DECL_STRUCT_FUNCTION (node->symbol.decl));
! 	bitmap_obstack_initialize (NULL);
! 	gimple_register_cfg_hooks ();
! 	record_all_accesses_in_func ();
! 	htab_traverse (matrices_to_reorg, transform_access_sites, NULL);
!         cgraph_rebuild_references ();
! 	free_dominance_info (CDI_DOMINATORS);
! 	free_dominance_info (CDI_POST_DOMINATORS);
! 	pop_cfun ();
! 	current_function_decl = temp_fn;
! 	bitmap_obstack_release (NULL);
!       }
    htab_traverse (matrices_to_reorg, dump_matrix_reorg_analysis, NULL);
  
    current_function_decl = NULL;
--- 2266,2363 ----
    else
      check_transpose_p = false;
    /* If there are hand written vectors, we skip this optimization.  */
!   FOR_EACH_FUNCTION (node)
      if (!may_flatten_matrices (node))
        return 0;
    matrices_to_reorg = htab_create (37, mtt_info_hash, mtt_info_eq, mat_free);
    /* Find and record all potential matrices in the program.  */
    find_matrices_decl ();
    /* Analyze the accesses of the matrices (escaping analysis).  */
!   FOR_EACH_DEFINED_FUNCTION (node)
!     {
!       tree temp_fn;
  
!       temp_fn = current_function_decl;
!       current_function_decl = node->symbol.decl;
!       push_cfun (DECL_STRUCT_FUNCTION (node->symbol.decl));
!       bitmap_obstack_initialize (NULL);
!       gimple_register_cfg_hooks ();
  
!       if (!gimple_in_ssa_p (cfun))
! 	{
! 	  free_dominance_info (CDI_DOMINATORS);
! 	  free_dominance_info (CDI_POST_DOMINATORS);
! 	  pop_cfun ();
! 	  current_function_decl = temp_fn;
! 	  bitmap_obstack_release (NULL);
  
! 	  return 0;
! 	}
  
  #ifdef ENABLE_CHECKING
!       verify_flow_info ();
  #endif
  
!       if (!matrices_to_reorg)
! 	{
! 	  free_dominance_info (CDI_DOMINATORS);
! 	  free_dominance_info (CDI_POST_DOMINATORS);
! 	  pop_cfun ();
! 	  current_function_decl = temp_fn;
! 	  bitmap_obstack_release (NULL);
! 
! 	  return 0;
! 	}
! 
!       /* Create htap for phi nodes.  */
!       htab_mat_acc_phi_nodes = htab_create (37, mat_acc_phi_hash,
! 					    mat_acc_phi_eq, free);
!       if (!check_transpose_p)
! 	find_sites_in_func (false);
!       else
! 	{
! 	  find_sites_in_func (true);
! 	  loop_optimizer_init (LOOPS_NORMAL);
! 	  if (current_loops)
! 	    scev_initialize ();
! 	  htab_traverse (matrices_to_reorg, analyze_transpose, NULL);
! 	  if (current_loops)
! 	    {
! 	      scev_finalize ();
! 	      loop_optimizer_finalize ();
! 	      current_loops = NULL;
! 	    }
! 	}
!       /* If the current function is the allocation function for any of
! 	 the matrices we check its allocation and the escaping level.  */
!       htab_traverse (matrices_to_reorg, check_allocation_function, NULL);
!       free_dominance_info (CDI_DOMINATORS);
!       free_dominance_info (CDI_POST_DOMINATORS);
!       pop_cfun ();
!       current_function_decl = temp_fn;
!       bitmap_obstack_release (NULL);
!     }
    htab_traverse (matrices_to_reorg, transform_allocation_sites, NULL);
    /* Now transform the accesses.  */
!   FOR_EACH_DEFINED_FUNCTION (node)
!     {
!       /* Remember that allocation sites have been handled.  */
!       tree temp_fn;
  
!       temp_fn = current_function_decl;
!       current_function_decl = node->symbol.decl;
!       push_cfun (DECL_STRUCT_FUNCTION (node->symbol.decl));
!       bitmap_obstack_initialize (NULL);
!       gimple_register_cfg_hooks ();
!       record_all_accesses_in_func ();
!       htab_traverse (matrices_to_reorg, transform_access_sites, NULL);
!       cgraph_rebuild_references ();
!       free_dominance_info (CDI_DOMINATORS);
!       free_dominance_info (CDI_POST_DOMINATORS);
!       pop_cfun ();
!       current_function_decl = temp_fn;
!       bitmap_obstack_release (NULL);
!     }
    htab_traverse (matrices_to_reorg, dump_matrix_reorg_analysis, NULL);
  
    current_function_decl = NULL;
Index: tree-vectorizer.c
===================================================================
*** tree-vectorizer.c	(revision 186466)
--- tree-vectorizer.c	(working copy)
*************** increase_alignment (void)
*** 320,328 ****
    struct varpool_node *vnode;
  
    /* Increase the alignment of all global arrays for vectorization.  */
!   for (vnode = varpool_nodes_queue;
!        vnode;
!        vnode = vnode->next_needed)
      {
        tree vectype, decl = vnode->symbol.decl;
        tree t;
--- 320,326 ----
    struct varpool_node *vnode;
  
    /* Increase the alignment of all global arrays for vectorization.  */
!   FOR_EACH_DEFINED_VARIABLE (vnode)
      {
        tree vectype, decl = vnode->symbol.decl;
        tree t;
Index: ipa.c
===================================================================
*** ipa.c	(revision 186466)
--- ipa.c	(working copy)
*************** cgraph_remove_unreachable_nodes (bool be
*** 181,189 ****
    if (file)
      fprintf (file, "\nReclaiming functions:");
  #ifdef ENABLE_CHECKING
!   for (node = cgraph_nodes; node; node = node->next)
      gcc_assert (!node->symbol.aux);
!   for (vnode = varpool_nodes; vnode; vnode = vnode->next)
      gcc_assert (!vnode->symbol.aux);
  #endif
    varpool_reset_queue ();
--- 181,189 ----
    if (file)
      fprintf (file, "\nReclaiming functions:");
  #ifdef ENABLE_CHECKING
!   FOR_EACH_FUNCTION (node)
      gcc_assert (!node->symbol.aux);
!   FOR_EACH_VARIABLE (vnode)
      gcc_assert (!vnode->symbol.aux);
  #endif
    varpool_reset_queue ();
*************** cgraph_remove_unreachable_nodes (bool be
*** 191,197 ****
       This is mostly when they can be referenced externally.  Inline clones
       are special since their declarations are shared with master clone and thus
       cgraph_can_remove_if_no_direct_calls_and_refs_p should not be called on them.  */
!   for (node = cgraph_nodes; node; node = node->next)
      if (node->analyzed && !node->global.inlined_to
  	&& (!cgraph_can_remove_if_no_direct_calls_and_refs_p (node)
  	    /* Keep around virtual functions for possible devirtualization.  */
--- 191,197 ----
       This is mostly when they can be referenced externally.  Inline clones
       are special since their declarations are shared with master clone and thus
       cgraph_can_remove_if_no_direct_calls_and_refs_p should not be called on them.  */
!   FOR_EACH_FUNCTION (node)
      if (node->analyzed && !node->global.inlined_to
  	&& (!cgraph_can_remove_if_no_direct_calls_and_refs_p (node)
  	    /* Keep around virtual functions for possible devirtualization.  */
*************** cgraph_remove_unreachable_nodes (bool be
*** 210,216 ****
        }
  
    /* Mark variables that are obviously needed.  */
!   for (vnode = varpool_nodes; vnode; vnode = vnode->next)
      {
        vnode->next_needed = NULL;
        vnode->prev_needed = NULL;
--- 210,216 ----
        }
  
    /* Mark variables that are obviously needed.  */
!   FOR_EACH_VARIABLE (vnode)
      {
        vnode->next_needed = NULL;
        vnode->prev_needed = NULL;
*************** cgraph_remove_unreachable_nodes (bool be
*** 405,411 ****
  	    }
  	}
      }
!   for (node = cgraph_nodes; node; node = node->next)
      {
        /* Inline clones might be kept around so their materializing allows further
           cloning.  If the function the clone is inlined into is removed, we need
--- 405,411 ----
  	    }
  	}
      }
!   FOR_EACH_FUNCTION (node)
      {
        /* Inline clones might be kept around so their materializing allows further
           cloning.  If the function the clone is inlined into is removed, we need
*************** cgraph_remove_unreachable_nodes (bool be
*** 441,447 ****
  
    if (file)
      fprintf (file, "\nClearing address taken flags:");
!   for (node = cgraph_nodes; node; node = node->next)
      if (node->symbol.address_taken
  	&& !node->symbol.used_from_other_partition)
        {
--- 441,447 ----
  
    if (file)
      fprintf (file, "\nClearing address taken flags:");
!   FOR_EACH_DEFINED_FUNCTION (node)
      if (node->symbol.address_taken
  	&& !node->symbol.used_from_other_partition)
        {
*************** ipa_discover_readonly_nonaddressable_var
*** 492,498 ****
    struct varpool_node *vnode;
    if (dump_file)
      fprintf (dump_file, "Clearing variable flags:");
!   for (vnode = varpool_nodes; vnode; vnode = vnode->next)
      if (vnode->finalized && varpool_all_refs_explicit_p (vnode)
  	&& (TREE_ADDRESSABLE (vnode->symbol.decl)
  	    || !TREE_READONLY (vnode->symbol.decl)))
--- 492,498 ----
    struct varpool_node *vnode;
    if (dump_file)
      fprintf (dump_file, "Clearing variable flags:");
!   FOR_EACH_VARIABLE (vnode)
      if (vnode->finalized && varpool_all_refs_explicit_p (vnode)
  	&& (TREE_ADDRESSABLE (vnode->symbol.decl)
  	    || !TREE_READONLY (vnode->symbol.decl)))
*************** function_and_variable_visibility (bool w
*** 797,803 ****
         fprintf (dump_file, "\n");
      }
  
!   for (node = cgraph_nodes; node; node = node->next)
      {
        int flags = flags_from_decl_or_type (node->symbol.decl);
  
--- 797,803 ----
         fprintf (dump_file, "\n");
      }
  
!   FOR_EACH_FUNCTION (node)
      {
        int flags = flags_from_decl_or_type (node->symbol.decl);
  
*************** function_and_variable_visibility (bool w
*** 889,897 ****
  	    DECL_EXTERNAL (node->symbol.decl) = 1;
  	}
      }
!   for (node = cgraph_nodes; node; node = node->next)
      node->local.local = cgraph_local_node_p (node);
!   for (vnode = varpool_nodes; vnode; vnode = vnode->next)
      {
        /* weak flag makes no sense on local variables.  */
        gcc_assert (!DECL_WEAK (vnode->symbol.decl)
--- 889,897 ----
  	    DECL_EXTERNAL (node->symbol.decl) = 1;
  	}
      }
!   FOR_EACH_DEFINED_FUNCTION (node)
      node->local.local = cgraph_local_node_p (node);
!   FOR_EACH_VARIABLE (vnode)
      {
        /* weak flag makes no sense on local variables.  */
        gcc_assert (!DECL_WEAK (vnode->symbol.decl)
*************** function_and_variable_visibility (bool w
*** 921,927 ****
  		    (TYPE_ADDR_SPACE (TREE_TYPE (vnode->symbol.decl))))))
  	DECL_COMMON (vnode->symbol.decl) = 0;
      }
!   for (vnode = varpool_nodes_queue; vnode; vnode = vnode->next_needed)
      {
        if (!vnode->finalized)
          continue;
--- 921,927 ----
  		    (TYPE_ADDR_SPACE (TREE_TYPE (vnode->symbol.decl))))))
  	DECL_COMMON (vnode->symbol.decl) = 0;
      }
!   FOR_EACH_DEFINED_VARIABLE (vnode)
      {
        if (!vnode->finalized)
          continue;
*************** function_and_variable_visibility (bool w
*** 946,962 ****
    if (dump_file)
      {
        fprintf (dump_file, "\nMarking local functions:");
!       for (node = cgraph_nodes; node; node = node->next)
  	if (node->local.local)
  	  fprintf (dump_file, " %s", cgraph_node_name (node));
        fprintf (dump_file, "\n\n");
        fprintf (dump_file, "\nMarking externally visible functions:");
!       for (node = cgraph_nodes; node; node = node->next)
  	if (node->symbol.externally_visible)
  	  fprintf (dump_file, " %s", cgraph_node_name (node));
        fprintf (dump_file, "\n\n");
        fprintf (dump_file, "\nMarking externally visible variables:");
!       for (vnode = varpool_nodes_queue; vnode; vnode = vnode->next_needed)
  	if (vnode->symbol.externally_visible)
  	  fprintf (dump_file, " %s", varpool_node_name (vnode));
        fprintf (dump_file, "\n\n");
--- 946,962 ----
    if (dump_file)
      {
        fprintf (dump_file, "\nMarking local functions:");
!       FOR_EACH_DEFINED_FUNCTION (node)
  	if (node->local.local)
  	  fprintf (dump_file, " %s", cgraph_node_name (node));
        fprintf (dump_file, "\n\n");
        fprintf (dump_file, "\nMarking externally visible functions:");
!       FOR_EACH_DEFINED_FUNCTION (node)
  	if (node->symbol.externally_visible)
  	  fprintf (dump_file, " %s", cgraph_node_name (node));
        fprintf (dump_file, "\n\n");
        fprintf (dump_file, "\nMarking externally visible variables:");
!       FOR_EACH_DEFINED_VARIABLE (vnode)
  	if (vnode->symbol.externally_visible)
  	  fprintf (dump_file, " %s", varpool_node_name (vnode));
        fprintf (dump_file, "\n\n");
*************** whole_program_function_and_variable_visi
*** 1012,1028 ****
  
    function_and_variable_visibility (flag_whole_program);
  
!   for (node = cgraph_nodes; node; node = node->next)
      if ((node->symbol.externally_visible && !DECL_COMDAT (node->symbol.decl))
          && node->local.finalized)
        cgraph_mark_needed_node (node);
!   for (vnode = varpool_nodes_queue; vnode; vnode = vnode->next_needed)
      if (vnode->symbol.externally_visible && !DECL_COMDAT (vnode->symbol.decl))
        varpool_mark_needed_node (vnode);
    if (dump_file)
      {
        fprintf (dump_file, "\nNeeded variables:");
!       for (vnode = varpool_nodes_queue; vnode; vnode = vnode->next_needed)
  	if (vnode->needed)
  	  fprintf (dump_file, " %s", varpool_node_name (vnode));
        fprintf (dump_file, "\n\n");
--- 1012,1028 ----
  
    function_and_variable_visibility (flag_whole_program);
  
!   FOR_EACH_DEFINED_FUNCTION (node)
      if ((node->symbol.externally_visible && !DECL_COMDAT (node->symbol.decl))
          && node->local.finalized)
        cgraph_mark_needed_node (node);
!   FOR_EACH_DEFINED_VARIABLE (vnode)
      if (vnode->symbol.externally_visible && !DECL_COMDAT (vnode->symbol.decl))
        varpool_mark_needed_node (vnode);
    if (dump_file)
      {
        fprintf (dump_file, "\nNeeded variables:");
!       FOR_EACH_DEFINED_VARIABLE (vnode)
  	if (vnode->needed)
  	  fprintf (dump_file, " %s", varpool_node_name (vnode));
        fprintf (dump_file, "\n\n");
*************** static unsigned int
*** 1405,1414 ****
  ipa_cdtor_merge (void)
  {
    struct cgraph_node *node;
!   for (node = cgraph_nodes; node; node = node->next)
!     if (node->analyzed
! 	&& (DECL_STATIC_CONSTRUCTOR (node->symbol.decl)
! 	    || DECL_STATIC_DESTRUCTOR (node->symbol.decl)))
         record_cdtor_fn (node);
    build_cdtor_fns ();
    VEC_free (tree, heap, static_ctors);
--- 1405,1413 ----
  ipa_cdtor_merge (void)
  {
    struct cgraph_node *node;
!   FOR_EACH_DEFINED_FUNCTION (node)
!     if (DECL_STATIC_CONSTRUCTOR (node->symbol.decl)
! 	|| DECL_STATIC_DESTRUCTOR (node->symbol.decl))
         record_cdtor_fn (node);
    build_cdtor_fns ();
    VEC_free (tree, heap, static_ctors);
Index: trans-mem.c
===================================================================
*** trans-mem.c	(revision 186466)
--- trans-mem.c	(working copy)
*************** ipa_tm_execute (void)
*** 4769,4775 ****
    bitmap_obstack_initialize (&tm_obstack);
  
    /* For all local functions marked tm_callable, queue them.  */
!   for (node = cgraph_nodes; node; node = node->next)
      if (is_tm_callable (node->symbol.decl)
  	&& cgraph_function_body_availability (node) >= AVAIL_OVERWRITABLE)
        {
--- 4769,4775 ----
    bitmap_obstack_initialize (&tm_obstack);
  
    /* For all local functions marked tm_callable, queue them.  */
!   FOR_EACH_DEFINED_FUNCTION (node)
      if (is_tm_callable (node->symbol.decl)
  	&& cgraph_function_body_availability (node) >= AVAIL_OVERWRITABLE)
        {
*************** ipa_tm_execute (void)
*** 4778,4784 ****
        }
  
    /* For all local reachable functions...  */
!   for (node = cgraph_nodes; node; node = node->next)
      if (node->reachable && node->lowered
  	&& cgraph_function_body_availability (node) >= AVAIL_OVERWRITABLE)
        {
--- 4778,4784 ----
        }
  
    /* For all local reachable functions...  */
!   FOR_EACH_DEFINED_FUNCTION (node)
      if (node->reachable && node->lowered
  	&& cgraph_function_body_availability (node) >= AVAIL_OVERWRITABLE)
        {
*************** ipa_tm_execute (void)
*** 4946,4952 ****
  
    /* Now validate all tm_safe functions, and all atomic regions in
       other functions.  */
!   for (node = cgraph_nodes; node; node = node->next)
      if (node->reachable && node->lowered
  	&& cgraph_function_body_availability (node) >= AVAIL_OVERWRITABLE)
        {
--- 4946,4952 ----
  
    /* Now validate all tm_safe functions, and all atomic regions in
       other functions.  */
!   FOR_EACH_DEFINED_FUNCTION (node)
      if (node->reachable && node->lowered
  	&& cgraph_function_body_availability (node) >= AVAIL_OVERWRITABLE)
        {
*************** ipa_tm_execute (void)
*** 4994,5000 ****
  	    ipa_tm_transform_clone (node);
  	}
      }
!   for (node = cgraph_nodes; node; node = node->next)
      if (node->reachable && node->lowered
  	&& cgraph_function_body_availability (node) >= AVAIL_OVERWRITABLE)
        {
--- 4994,5000 ----
  	    ipa_tm_transform_clone (node);
  	}
      }
!   FOR_EACH_DEFINED_FUNCTION (node)
      if (node->reachable && node->lowered
  	&& cgraph_function_body_availability (node) >= AVAIL_OVERWRITABLE)
        {
*************** ipa_tm_execute (void)
*** 5008,5014 ****
    VEC_free (cgraph_node_p, heap, irr_worklist);
    bitmap_obstack_release (&tm_obstack);
  
!   for (node = cgraph_nodes; node; node = node->next)
      node->symbol.aux = NULL;
  
  #ifdef ENABLE_CHECKING
--- 5008,5014 ----
    VEC_free (cgraph_node_p, heap, irr_worklist);
    bitmap_obstack_release (&tm_obstack);
  
!   FOR_EACH_FUNCTION (node)
      node->symbol.aux = NULL;
  
  #ifdef ENABLE_CHECKING
Index: ipa-inline-analysis.c
===================================================================
*** ipa-inline-analysis.c	(revision 186466)
--- ipa-inline-analysis.c	(working copy)
*************** dump_inline_summaries (FILE *f)
*** 1226,1233 ****
  {
    struct cgraph_node *node;
  
!   for (node = cgraph_nodes; node; node = node->next)
!     if (node->analyzed && !node->global.inlined_to)
        dump_inline_summary (f, node);
  }
  
--- 1226,1233 ----
  {
    struct cgraph_node *node;
  
!   FOR_EACH_DEFINED_FUNCTION (node)
!     if (!node->global.inlined_to)
        dump_inline_summary (f, node);
  }
  
Index: lto/lto.c
===================================================================
*** lto/lto.c	(revision 186466)
--- lto/lto.c	(working copy)
*************** read_cgraph_and_symbols (unsigned nfiles
*** 1868,1885 ****
    lto_symtab_merge_cgraph_nodes ();
    ggc_collect ();
  
    if (flag_ltrans)
!     for (node = cgraph_nodes; node; node = node->next)
!       {
! 	/* FIXME: ipa_transforms_to_apply holds list of passes that have optimization
! 	   summaries computed and needs to apply changes.  At the moment WHOPR only
! 	   supports inlining, so we can push it here by hand.  In future we need to stream
! 	   this field into ltrans compilation.  */
! 	if (node->analyzed)
! 	  VEC_safe_push (ipa_opt_pass, heap,
! 			 node->ipa_transforms_to_apply,
! 			 (ipa_opt_pass)&pass_ipa_inline);
!       }
    lto_symtab_free ();
  
    timevar_pop (TV_IPA_LTO_CGRAPH_MERGE);
--- 1868,1882 ----
    lto_symtab_merge_cgraph_nodes ();
    ggc_collect ();
  
+   /* FIXME: ipa_transforms_to_apply holds list of passes that have optimization
+      summaries computed and needs to apply changes.  At the moment WHOPR only
+      supports inlining, so we can push it here by hand.  In future we need to stream
+      this field into ltrans compilation.  */
    if (flag_ltrans)
!     FOR_EACH_DEFINED_FUNCTION (node)
!       VEC_safe_push (ipa_opt_pass, heap,
! 		     node->ipa_transforms_to_apply,
! 		     (ipa_opt_pass)&pass_ipa_inline);
    lto_symtab_free ();
  
    timevar_pop (TV_IPA_LTO_CGRAPH_MERGE);
*************** materialize_cgraph (void)
*** 1923,1929 ****
       nodes and read the functions if we are not running in WPA mode.  */
    timevar_push (TV_IPA_LTO_GIMPLE_IN);
  
!   for (node = cgraph_nodes; node; node = node->next)
      {
        if (node->symbol.lto_file_data)
  	{
--- 1920,1926 ----
       nodes and read the functions if we are not running in WPA mode.  */
    timevar_push (TV_IPA_LTO_GIMPLE_IN);
  
!   FOR_EACH_FUNCTION (node)
      {
        if (node->symbol.lto_file_data)
  	{
Index: lto/lto-partition.c
===================================================================
*** lto/lto-partition.c	(revision 186466)
--- lto/lto-partition.c	(working copy)
*************** lto_1_to_1_map (void)
*** 313,319 ****
  
    pmap = pointer_map_create ();
  
!   for (node = cgraph_nodes; node; node = node->next)
      {
        if (!partition_cgraph_node_p (node)
  	  || node->symbol.aux)
--- 313,319 ----
  
    pmap = pointer_map_create ();
  
!   FOR_EACH_DEFINED_FUNCTION (node)
      {
        if (!partition_cgraph_node_p (node)
  	  || node->symbol.aux)
*************** lto_1_to_1_map (void)
*** 348,354 ****
        add_cgraph_node_to_partition (partition, node);
      }
  
!   for (vnode = varpool_nodes; vnode; vnode = vnode->next)
      {
        if (!partition_varpool_node_p (vnode)
  	  || vnode->symbol.aux)
--- 348,354 ----
        add_cgraph_node_to_partition (partition, node);
      }
  
!   FOR_EACH_VARIABLE (vnode)
      {
        if (!partition_varpool_node_p (vnode)
  	  || vnode->symbol.aux)
*************** lto_1_to_1_map (void)
*** 367,375 ****
  
        add_varpool_node_to_partition (partition, vnode);
      }
!   for (node = cgraph_nodes; node; node = node->next)
      node->symbol.aux = NULL;
!   for (vnode = varpool_nodes; vnode; vnode = vnode->next)
      vnode->symbol.aux = NULL;
  
    /* If the cgraph is empty, create one cgraph node set so that there is still
--- 367,375 ----
  
        add_varpool_node_to_partition (partition, vnode);
      }
!   FOR_EACH_FUNCTION (node)
      node->symbol.aux = NULL;
!   FOR_EACH_VARIABLE (vnode)
      vnode->symbol.aux = NULL;
  
    /* If the cgraph is empty, create one cgraph node set so that there is still
*************** lto_balanced_map (void)
*** 463,469 ****
    int npartitions;
    int current_order = -1;
  
!   for (vnode = varpool_nodes; vnode; vnode = vnode->next)
      gcc_assert (!vnode->symbol.aux);
    /* Until we have better ordering facility, use toplogical order.
       Include only nodes we will partition and compute estimate of program
--- 463,469 ----
    int npartitions;
    int current_order = -1;
  
!   FOR_EACH_VARIABLE (vnode)
      gcc_assert (!vnode->symbol.aux);
    /* Until we have better ordering facility, use toplogical order.
       Include only nodes we will partition and compute estimate of program
*************** lto_balanced_map (void)
*** 487,499 ****
      {
        qsort (order, n_nodes, sizeof (struct cgraph_node *), node_cmp);
  
!       for (vnode = varpool_nodes; vnode; vnode = vnode->next)
  	if (partition_varpool_node_p (vnode))
  	  n_varpool_nodes++;
        varpool_order = XNEWVEC (struct varpool_node *, n_varpool_nodes);
  
        n_varpool_nodes = 0;
!       for (vnode = varpool_nodes; vnode; vnode = vnode->next)
  	if (partition_varpool_node_p (vnode))
  	  varpool_order[n_varpool_nodes++] = vnode;
        qsort (varpool_order, n_varpool_nodes, sizeof (struct varpool_node *),
--- 487,499 ----
      {
        qsort (order, n_nodes, sizeof (struct cgraph_node *), node_cmp);
  
!       FOR_EACH_VARIABLE (vnode)
  	if (partition_varpool_node_p (vnode))
  	  n_varpool_nodes++;
        varpool_order = XNEWVEC (struct varpool_node *, n_varpool_nodes);
  
        n_varpool_nodes = 0;
!       FOR_EACH_VARIABLE (vnode)
  	if (partition_varpool_node_p (vnode))
  	  varpool_order[n_varpool_nodes++] = vnode;
        qsort (varpool_order, n_varpool_nodes, sizeof (struct varpool_node *),
*************** lto_balanced_map (void)
*** 742,748 ****
    /* Varables that are not reachable from the code go into last partition.  */
    if (flag_toplevel_reorder)
      {
!       for (vnode = varpool_nodes; vnode; vnode = vnode->next)
          if (partition_varpool_node_p (vnode) && !vnode->symbol.aux)
  	  add_varpool_node_to_partition (partition, vnode);
      }
--- 742,748 ----
    /* Varables that are not reachable from the code go into last partition.  */
    if (flag_toplevel_reorder)
      {
!       FOR_EACH_VARIABLE (vnode)
          if (partition_varpool_node_p (vnode) && !vnode->symbol.aux)
  	  add_varpool_node_to_partition (partition, vnode);
      }
*************** lto_promote_cross_file_statics (void)
*** 858,864 ****
  	 referenced from all initializers of read-only vars referenced
  	 from this partition that are not in this partition.  This needs
  	 to be done recursively.  */
!       for (vnode = varpool_nodes; vnode; vnode = vnode->next)
  	if (const_value_known_p (vnode->symbol.decl)
  	    && DECL_INITIAL (vnode->symbol.decl)
  	    && !varpool_node_in_set_p (vnode, vset)
--- 858,864 ----
  	 referenced from all initializers of read-only vars referenced
  	 from this partition that are not in this partition.  This needs
  	 to be done recursively.  */
!       FOR_EACH_VARIABLE (vnode)
  	if (const_value_known_p (vnode->symbol.decl)
  	    && DECL_INITIAL (vnode->symbol.decl)
  	    && !varpool_node_in_set_p (vnode, vset)
Index: ipa-prop.c
===================================================================
*** ipa-prop.c	(revision 186466)
--- ipa-prop.c	(working copy)
*************** ipa_print_all_jump_functions (FILE *f)
*** 260,266 ****
    struct cgraph_node *node;
  
    fprintf (f, "\nJump functions:\n");
!   for (node = cgraph_nodes; node; node = node->next)
      {
        ipa_print_node_jump_functions (f, node);
      }
--- 260,266 ----
    struct cgraph_node *node;
  
    fprintf (f, "\nJump functions:\n");
!   FOR_EACH_FUNCTION (node)
      {
        ipa_print_node_jump_functions (f, node);
      }
*************** ipa_print_all_params (FILE * f)
*** 2209,2215 ****
    struct cgraph_node *node;
  
    fprintf (f, "\nFunction parameters:\n");
!   for (node = cgraph_nodes; node; node = node->next)
      ipa_print_node_params (f, node);
  }
  
--- 2209,2215 ----
    struct cgraph_node *node;
  
    fprintf (f, "\nFunction parameters:\n");
!   FOR_EACH_FUNCTION (node)
      ipa_print_node_params (f, node);
  }
  
*************** ipa_update_after_lto_read (void)
*** 3087,3093 ****
    ipa_check_create_node_params ();
    ipa_check_create_edge_args ();
  
!   for (node = cgraph_nodes; node; node = node->next)
      if (node->analyzed)
        ipa_initialize_node_params (node);
  }
--- 3087,3093 ----
    ipa_check_create_node_params ();
    ipa_check_create_edge_args ();
  
!   FOR_EACH_DEFINED_FUNCTION (node)
      if (node->analyzed)
        ipa_initialize_node_params (node);
  }
Index: tree-profile.c
===================================================================
*** tree-profile.c	(revision 186466)
--- tree-profile.c	(working copy)
*************** tree_profiling (void)
*** 479,488 ****
  
    init_node_map();
  
!   for (node = cgraph_nodes; node; node = node->next)
      {
!       if (!node->analyzed
! 	  || !gimple_has_body_p (node->symbol.decl))
  	continue;
  
        /* Don't profile functions produced for builtin stuff.  */
--- 479,487 ----
  
    init_node_map();
  
!   FOR_EACH_DEFINED_FUNCTION (node)
      {
!       if (!gimple_has_body_p (node->symbol.decl))
  	continue;
  
        /* Don't profile functions produced for builtin stuff.  */
*************** tree_profiling (void)
*** 520,529 ****
      }
  
    /* Drop pure/const flags from instrumented functions.  */
!   for (node = cgraph_nodes; node; node = node->next)
      {
!       if (!node->analyzed
! 	  || !gimple_has_body_p (node->symbol.decl)
  	  || !(!node->clone_of
  	  || node->symbol.decl != node->clone_of->symbol.decl))
  	continue;
--- 519,527 ----
      }
  
    /* Drop pure/const flags from instrumented functions.  */
!   FOR_EACH_DEFINED_FUNCTION (node)
      {
!       if (!gimple_has_body_p (node->symbol.decl)
  	  || !(!node->clone_of
  	  || node->symbol.decl != node->clone_of->symbol.decl))
  	continue;
*************** tree_profiling (void)
*** 538,549 ****
      }
  
    /* Update call statements and rebuild the cgraph.  */
!   for (node = cgraph_nodes; node; node = node->next)
      {
        basic_block bb;
  
!       if (!node->analyzed
! 	  || !gimple_has_body_p (node->symbol.decl)
  	  || !(!node->clone_of
  	  || node->symbol.decl != node->clone_of->symbol.decl))
  	continue;
--- 536,546 ----
      }
  
    /* Update call statements and rebuild the cgraph.  */
!   FOR_EACH_DEFINED_FUNCTION (node)
      {
        basic_block bb;
  
!       if (!gimple_has_body_p (node->symbol.decl)
  	  || !(!node->clone_of
  	  || node->symbol.decl != node->clone_of->symbol.decl))
  	continue;
Index: tree-ssa-structalias.c
===================================================================
*** tree-ssa-structalias.c	(revision 186466)
--- tree-ssa-structalias.c	(working copy)
*************** ipa_pta_execute (void)
*** 6862,6868 ****
      }
  
    /* Build the constraints.  */
!   for (node = cgraph_nodes; node; node = node->next)
      {
        varinfo_t vi;
        /* Nodes without a body are not interesting.  Especially do not
--- 6862,6868 ----
      }
  
    /* Build the constraints.  */
!   FOR_EACH_DEFINED_FUNCTION (node)
      {
        varinfo_t vi;
        /* Nodes without a body are not interesting.  Especially do not
*************** ipa_pta_execute (void)
*** 6879,6885 ****
      }
  
    /* Create constraints for global variables and their initializers.  */
!   for (var = varpool_nodes; var; var = var->next)
      {
        if (var->alias)
  	continue;
--- 6879,6885 ----
      }
  
    /* Create constraints for global variables and their initializers.  */
!   FOR_EACH_VARIABLE (var)
      {
        if (var->alias)
  	continue;
*************** ipa_pta_execute (void)
*** 6896,6902 ****
      }
    from = VEC_length (constraint_t, constraints);
  
!   for (node = cgraph_nodes; node; node = node->next)
      {
        struct function *func;
        basic_block bb;
--- 6896,6902 ----
      }
    from = VEC_length (constraint_t, constraints);
  
!   FOR_EACH_DEFINED_FUNCTION (node)
      {
        struct function *func;
        basic_block bb;
*************** ipa_pta_execute (void)
*** 7004,7010 ****
    ipa_escaped_pt.ipa_escaped = 0;
  
    /* Assign the points-to sets to the SSA names in the unit.  */
!   for (node = cgraph_nodes; node; node = node->next)
      {
        tree ptr;
        struct function *fn;
--- 7004,7010 ----
    ipa_escaped_pt.ipa_escaped = 0;
  
    /* Assign the points-to sets to the SSA names in the unit.  */
!   FOR_EACH_DEFINED_FUNCTION (node)
      {
        tree ptr;
        struct function *fn;
Index: passes.c
===================================================================
*** passes.c	(revision 186466)
--- passes.c	(working copy)
*************** dump_passes (void)
*** 703,718 ****
  
    create_pass_tab();
  
!   n = cgraph_nodes;
!   while (n)
!     {
!       if (DECL_STRUCT_FUNCTION (n->symbol.decl))
!         {
!           node = n;
!           break;
!         }
!       n = n->next;
!     }
  
    if (!node)
      return;
--- 703,714 ----
  
    create_pass_tab();
  
!   FOR_EACH_DEFINED_FUNCTION (n)
!     if (DECL_STRUCT_FUNCTION (n->symbol.decl))
!       {
! 	node = n;
! 	break;
!       }
  
    if (!node)
      return;
*************** do_per_function (void (*callback) (void 
*** 1662,1669 ****
    else
      {
        struct cgraph_node *node;
!       for (node = cgraph_nodes; node; node = node->next)
! 	if (node->analyzed && gimple_has_body_p (node->symbol.decl)
  	    && (!node->clone_of || node->symbol.decl != node->clone_of->symbol.decl))
  	  {
  	    push_cfun (DECL_STRUCT_FUNCTION (node->symbol.decl));
--- 1658,1665 ----
    else
      {
        struct cgraph_node *node;
!       FOR_EACH_DEFINED_FUNCTION (node)
! 	if (gimple_has_body_p (node->symbol.decl)
  	    && (!node->clone_of || node->symbol.decl != node->clone_of->symbol.decl))
  	  {
  	    push_cfun (DECL_STRUCT_FUNCTION (node->symbol.decl));
*************** ipa_write_summaries (void)
*** 2346,2352 ****
      }
    vset = varpool_node_set_new ();
  
!   for (vnode = varpool_nodes; vnode; vnode = vnode->next)
      if (vnode->needed && (!vnode->alias || vnode->alias_of))
        varpool_node_set_add (vset, vnode);
  
--- 2342,2348 ----
      }
    vset = varpool_node_set_new ();
  
!   FOR_EACH_VARIABLE (vnode)
      if (vnode->needed && (!vnode->alias || vnode->alias_of))
        varpool_node_set_add (vset, vnode);
  
Index: varpool.c
===================================================================
*** varpool.c	(revision 186466)
--- varpool.c	(working copy)
*************** dump_varpool (FILE *f)
*** 254,260 ****
    struct varpool_node *node;
  
    fprintf (f, "variable pool:\n\n");
!   for (node = varpool_nodes; node; node = node->next)
      dump_varpool_node (f, node);
  }
  
--- 254,260 ----
    struct varpool_node *node;
  
    fprintf (f, "variable pool:\n\n");
!   FOR_EACH_VARIABLE (node)
      dump_varpool_node (f, node);
  }
  
*************** varpool_node_for_asm (tree asmname)
*** 272,278 ****
  {
    struct varpool_node *node;
  
!   for (node = varpool_nodes; node ; node = node->next)
      if (decl_assembler_name_equal (node->symbol.decl, asmname))
        return node;
  
--- 272,278 ----
  {
    struct varpool_node *node;
  
!   FOR_EACH_VARIABLE (node)
      if (decl_assembler_name_equal (node->symbol.decl, asmname))
        return node;
  
*************** varpool_assemble_pending_decls (void)
*** 652,658 ****
       elsewhere.  */
    varpool_analyze_pending_decls ();
  
!   for (node = varpool_nodes_queue; node; node = node->next_needed)
      varpool_finalize_named_section_flags (node);
  
    while (varpool_nodes_queue)
--- 652,658 ----
       elsewhere.  */
    varpool_analyze_pending_decls ();
  
!   FOR_EACH_DEFINED_VARIABLE (node)
      varpool_finalize_named_section_flags (node);
  
    while (varpool_nodes_queue)



More information about the Gcc-patches mailing list