This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: New varpool walking API


Jan,

Just a couple of comments

--- Jan Hubicka <jh@suse.cz> wrote:

> Hi,
> this patch adds FOR_EACH_STATIC_VAIRABLE and FOR_EACH_STATIC_INITIALIZER
> macros to walk varpool without having to care about implementation
> details.  I will commit the patch tomorrow if there will be no complains
> and will follow with similar stuff for functions.
> 
> Honza
> 
> 	* cgraph.h (FOR_EACH_STATIC_VARIABLE, FOR_EACH_STATIC_INITIALIZER): New
> 	macros.
> 	(varpool_first_static_initializer, varpol_next_static_initializer): New
> 	inline functions.
> 	* ipa-reference.c (analyze_variable): Simplify.
> 	(static_execute): Use FOR_EACH_STATIC_INITIALIZER.
> 	* ipa-type-escape.c (type_escape_execute): Use FOR_EACH_STATIC_VARIABLE.
> Index: cgraph.h
> ===================================================================
> *** cgraph.h	(revision 120017)
> --- cgraph.h	(working copy)
> *************** bool varpool_analyze_pending_decls (void
> *** 342,347 ****
> --- 342,383 ----
>   void varpool_output_debug_info (void);
>   void varpool_remove_unreferenced_decls (void);
>   
> + /* Walk all reachable static variables.  */
> + #define FOR_EACH_STATIC_VARIABLE(node) \
> +    for ((node) = varpool_nodes_queue; (node); (node) = (node)->next_needed)
> + 
> + /* Return first reachable static variable with initializer.  */
> + static inline struct varpool_node *
> + varpool_first_static_initializer (void)
> + {
> +   struct varpool_node *node;
> +   for (node = varpool_nodes_queue; node; node = node->next_needed)
Any reason not to use the FOR_EACH_STATIC_VARIABLE macro here?
> +     {
> +       gcc_assert (TREE_CODE (node->decl) == VAR_DECL);
> +       if (DECL_INITIAL (node->decl))
> + 	return node;
> +     }
> +   return NULL;
> + }
> + 
> + /* Return next reachable static variable with initializer after NODE.  */
> + static inline struct varpool_node *
> + varpool_next_static_initializer (struct varpool_node *node)
> + {
> +   for (node = node->next_needed; node; node = node->next_needed)
Likewise here?
> +     {
> +       gcc_assert (TREE_CODE (node->decl) == VAR_DECL);
> +       if (DECL_INITIAL (node->decl))
> + 	return node;
> +     }
> +   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))
> + 
>   /* In ipa-inline.c  */
>   bool cgraph_decide_inlining_incrementally (struct cgraph_node *, bool);
>   void cgraph_clone_inlined_nodes (struct cgraph_edge *, bool, bool);
> Index: ipa-reference.c
> ===================================================================
> *** ipa-reference.c	(revision 120017)
> --- ipa-reference.c	(working copy)
> *************** static void 
> *** 774,786 ****
>   analyze_variable (struct varpool_node *vnode)
>   {
>     tree global = vnode->decl;
> !   if (TREE_CODE (global) == VAR_DECL)
> !     {
> !       if (DECL_INITIAL (global)) 
> ! 	walk_tree (&DECL_INITIAL (global), scan_for_static_refs, 
> ! 		   NULL, visited_nodes);
> !     } 
> !   else gcc_unreachable ();
>   }
>   
>   /* This is the main routine for finding the reference patterns for
> --- 774,781 ----
>   analyze_variable (struct varpool_node *vnode)
>   {
>     tree global = vnode->decl;
> !   walk_tree (&DECL_INITIAL (global), scan_for_static_refs, 
> !              NULL, visited_nodes);
>   }
>   
>   /* This is the main routine for finding the reference patterns for
> *************** static_execute (void)
> *** 903,909 ****
>     ipa_init ();
>   
>     /* Process all of the variables first.  */
> !   for (vnode = varpool_nodes_queue; vnode; vnode = vnode->next_needed)
>       analyze_variable (vnode);
>   
>     /* Process all of the functions next. 
> --- 898,904 ----
>     ipa_init ();
>   
>     /* Process all of the variables first.  */
> !   FOR_EACH_STATIC_INITIALIZER (vnode)
Uhm this looks wrong, shouldn't this for FOR_EACH_STATIC_VARIABLE?
>       analyze_variable (vnode);
>   
>     /* Process all of the functions next. 
> Index: ipa-type-escape.c
> ===================================================================
> *** ipa-type-escape.c	(revision 120017)
> --- ipa-type-escape.c	(working copy)
> *************** type_escape_execute (void)
> *** 1682,1688 ****
>     ipa_init ();
>   
>     /* Process all of the variables first.  */
> !   for (vnode = varpool_nodes_queue; vnode; vnode = vnode->next_needed)
>       analyze_variable (vnode);
>   
>     /* Process all of the functions. next
> --- 1682,1688 ----
>     ipa_init ();
>   
>     /* Process all of the variables first.  */
> !   FOR_EACH_STATIC_VARIABLE (vnode)
>       analyze_variable (vnode);
>   
>     /* Process all of the functions. next
> 

Cheers
Graham


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]