diff mbox

[2/2] tree-flow.h restructuring

Message ID 522F728E.4090907@redhat.com
State New
Headers show

Commit Message

Andrew MacLeod Sept. 10, 2013, 7:27 p.m. UTC
This splits out tree-ssaname related things to tree-ssanames.h. This is 
then included from tree-ssa.h

similar treatment can  be given to tree-phinodes.c

I notice a number of the other ssa passes only export a couple of 
functions, and thats it.. no structs or anything like that.  (like 
tree-ssa-uninit.c which exports ssa_undefined_value_p but that cant be 
easily relocated since it depends on static objects in the file which 
are constructed earlier by the pass)

I was thinking that rather than create tree-ssa-passxyz.h in these cases 
would could simply put those prototypes into tree-ssa.h since they are 
SSA related... but I'm ok creating those pass headers if that is the 
direction we want to go....  then we have 1:1 correspondences rather 
than recreating the /* In file.c */ setup again in tree-ssa.h :-)

It looks like there is a bunch of tree-ssa-loop stuff in there as well, 
I would think all of that would be good to put into a tree-ssa-loop.h, 
and then any non-loop files won't need to see these structs and 
functions unless they want to include that file.  (ie tree-ssa.h 
wouldn't include tree-ssa-loop.h, but all the tree-ssa-loop*.c files would)

after that, tree-flow.h will end up with some gimple flow and other 
miscellaneous things which can be looked at, as well as the SSA 
immediate use code which should go somewhere else... perhaps  in 
tree-ssa-operands.h...  Sometimes its hard to tell until you try moving 
it :-)

then I'd go tackle the stuff in gimple.h and tree.h that doesn't belong 
there.

Andrew

Comments

Richard Biener Sept. 11, 2013, 8:55 a.m. UTC | #1
On Tue, Sep 10, 2013 at 9:27 PM, Andrew MacLeod <amacleod@redhat.com> wrote:
> This splits out tree-ssaname related things to tree-ssanames.h. This is then
> included from tree-ssa.h

This patch is ok as-is.

> similar treatment can  be given to tree-phinodes.c
>
> I notice a number of the other ssa passes only export a couple of functions,
> and thats it.. no structs or anything like that.  (like tree-ssa-uninit.c
> which exports ssa_undefined_value_p but that cant be easily relocated since
> it depends on static objects in the file which are constructed earlier by
> the pass)

Well - usually the reason is a bad design choice.  There should have been
a ssa_undefined_value_p predicate without the special
possibly_undefined_names pointer-set handling available in generic code
and tree-ssa-uninit.c wrapping that adding it's own special handling.

Most of the awkwardness here is because the generic uninit warning
machinery resides in tree-ssa.c.  Consider moving that (the
early uninit pass and its helpers) to tree-ssa-uninit.c.

> I was thinking that rather than create tree-ssa-passxyz.h in these cases
> would could simply put those prototypes into tree-ssa.h since they are SSA
> related... but I'm ok creating those pass headers if that is the direction
> we want to go....  then we have 1:1 correspondences rather than recreating
> the /* In file.c */ setup again in tree-ssa.h :-)

Please not ;)  Just keep the existing mess rather than changing it to a
different one.  Or go the full way of restructuring things like outlined above
for this special case so no mess is required.

> It looks like there is a bunch of tree-ssa-loop stuff in there as well, I
> would think all of that would be good to put into a tree-ssa-loop.h, and
> then any non-loop files won't need to see these structs and functions unless
> they want to include that file.  (ie tree-ssa.h wouldn't include
> tree-ssa-loop.h, but all the tree-ssa-loop*.c files would)

Sure.  Note that for generic loop stuff we have the IL agnostic cfgloop*
files.

> after that, tree-flow.h will end up with some gimple flow and other
> miscellaneous things which can be looked at, as well as the SSA immediate
> use code which should go somewhere else... perhaps  in
> tree-ssa-operands.h...  Sometimes its hard to tell until you try moving it
> :-)

Immediate use stuff indeed looks like belonging to tree-ssa-operands.[ch].

> then I'd go tackle the stuff in gimple.h and tree.h that doesn't belong
> there.

Keep in mind the tree (GENERIC) vs. GIMPLE (non-SSA specific) and
SSA (SSA-on-GIMPLE specific) distinction.

Richard.

> Andrew
Andrew MacLeod Sept. 11, 2013, 12:39 p.m. UTC | #2
On 09/11/2013 04:55 AM, Richard Biener wrote:
> On Tue, Sep 10, 2013 at 9:27 PM, Andrew MacLeod <amacleod@redhat.com> wrote:
>> This splits out tree-ssaname related things to tree-ssanames.h. This is then
>> included from tree-ssa.h
> This patch is ok as-is.
>
>> similar treatment can  be given to tree-phinodes.c
>>
>> I notice a number of the other ssa passes only export a couple of functions,
>> and thats it.. no structs or anything like that.  (like tree-ssa-uninit.c
>> which exports ssa_undefined_value_p but that cant be easily relocated since
>> it depends on static objects in the file which are constructed earlier by
>> the pass)
> Well - usually the reason is a bad design choice.  There should have been
> a ssa_undefined_value_p predicate without the special
> possibly_undefined_names pointer-set handling available in generic code
> and tree-ssa-uninit.c wrapping that adding it's own special handling.
>
> Most of the awkwardness here is because the generic uninit warning
> machinery resides in tree-ssa.c.  Consider moving that (the
> early uninit pass and its helpers) to tree-ssa-uninit.c.
I oringinally did try moving that one function to tree-ssa.c, and 
discovered the static pointer-set bits... and toyed with seeing what 
else would need to be moved, but didn't spend any real effort on it.  
I'll put a little more effort into it  :-)

>
> Keep in mind the tree (GENERIC) vs. GIMPLE (non-SSA specific) and
> SSA (SSA-on-GIMPLE specific) distinction.
>
>
Someday it will be more obvious :-)    yes, I will keep that in mind, 
and you can catch what I miss, like types_compatible_p  :-)

Andrew
diff mbox

Patch


	* tree-flow.h (FREE_SSANAMES): Move to tree-ssanames.c
	(SSANAMES, MODIFIED_NORETURN_CALLS, DEFAULT_DEFS, ptr_info_def,
	num_ssa_names, ssa_name): Move to tree-ssanames.h + prototypes.
	* tree-flow-inline.h (make_ssa_name, copy_ssa_name, duplicate_ssa_name,
	make_temp_ssa_name): move to tree-ssanames.h
	* tree-ssa-alias.h: Move prototype.
	* tree-ssa.h: Include tree-ssanames.h.
	* tree-ssanames.c (FREE_SSANAMES): Move to here.
	* tree-ssanames.h: New.  Move items from tree-flow*.h
	* Makefile.in (tree-ssanames.h): Add to tree-ssanames.o and GTFILES.

diff -rcp r1/tree-flow.h ./tree-flow.h
*** r1/tree-flow.h	2013-09-10 13:06:06.568300474 -0400
--- ./tree-flow.h	2013-09-10 13:16:27.697748702 -0400
*************** struct GTY(()) gimple_df {
*** 92,103 ****
    htab_t GTY ((param_is (struct tm_restart_node))) tm_restart;
  };
  
- /* Accessors for internal use only.  Generic code should use abstraction
-    provided by tree-flow-inline.h or specific modules.  */
- #define FREE_SSANAMES(fun) (fun)->gimple_df->free_ssanames
- #define SSANAMES(fun) (fun)->gimple_df->ssa_names
- #define MODIFIED_NORETURN_CALLS(fun) (fun)->gimple_df->modified_noreturn_calls
- #define DEFAULT_DEFS(fun) (fun)->gimple_df->default_defs
  
  typedef struct
  {
--- 92,97 ----
*************** typedef struct
*** 113,153 ****
  	!end_htab_p (&(ITER)); \
  	RESULT = (TYPE) next_htab_element (&(ITER)))
  
- /*---------------------------------------------------------------------------
- 		      Attributes for SSA_NAMEs.
- 
-   NOTE: These structures are stored in struct tree_ssa_name
-   but are only used by the tree optimizers, so it makes better sense
-   to declare them here to avoid recompiling unrelated files when
-   making changes.
- ---------------------------------------------------------------------------*/
- 
- /* Aliasing information for SSA_NAMEs representing pointer variables.  */
- 
- struct GTY(()) ptr_info_def
- {
-   /* The points-to solution.  */
-   struct pt_solution pt;
- 
-   /* Alignment and misalignment of the pointer in bytes.  Together
-      align and misalign specify low known bits of the pointer.
-      ptr & (align - 1) == misalign.  */
- 
-   /* When known, this is the power-of-two byte alignment of the object this
-      pointer points into.  This is usually DECL_ALIGN_UNIT for decls and
-      MALLOC_ABI_ALIGNMENT for allocated storage.  When the alignment is not
-      known, it is zero.  Do not access directly but use functions
-      get_ptr_info_alignment, set_ptr_info_alignment,
-      mark_ptr_info_alignment_unknown and similar.  */
-   unsigned int align;
- 
-   /* When alignment is known, the byte offset this pointer differs from the
-      above alignment.  Access only through the same helper functions as align
-      above.  */
-   unsigned int misalign;
- };
- 
- 
  /* It is advantageous to avoid things like life analysis for variables which
     do not need PHI nodes.  This enum describes whether or not a particular
     variable may need a PHI node.  */
--- 107,112 ----
*************** struct int_tree_map {
*** 282,290 ****
    tree to;
  };
  
- #define num_ssa_names (vec_safe_length (cfun->gimple_df->ssa_names))
- #define ssa_name(i) ((*cfun->gimple_df->ssa_names)[(i)])
- 
  /* Macros for showing usage statistics.  */
  #define SCALE(x) ((unsigned long) ((x) < 1024*10	\
  		  ? (x)					\
--- 241,246 ----
*************** void mark_virtual_operands_for_renaming
*** 479,504 ****
  tree get_current_def (tree);
  void set_current_def (tree, tree);
  
- /* In tree-ssanames.c  */
- extern void init_ssanames (struct function *, int);
- extern void fini_ssanames (void);
- extern tree make_ssa_name_fn (struct function *, tree, gimple);
- extern tree copy_ssa_name_fn (struct function *, tree, gimple);
- extern tree duplicate_ssa_name_fn (struct function *, tree, gimple);
- extern void duplicate_ssa_name_ptr_info (tree, struct ptr_info_def *);
- extern void release_ssa_name (tree);
- extern void release_defs (gimple);
- extern void replace_ssa_name_symbol (tree, tree);
- extern bool get_ptr_info_alignment (struct ptr_info_def *, unsigned int *,
- 				    unsigned int *);
- extern void mark_ptr_info_alignment_unknown (struct ptr_info_def *);
- extern void set_ptr_info_alignment (struct ptr_info_def *, unsigned int,
- 				    unsigned int);
- extern void adjust_ptr_info_misalignment (struct ptr_info_def *,
- 					  unsigned int);
- 
- extern void ssanames_print_statistics (void);
- 
  /* In tree-ssa-ccp.c  */
  tree fold_const_aggregate_ref (tree);
  tree gimple_fold_stmt_to_constant (gimple, tree (*)(tree));
--- 435,440 ----
diff -rcp r1/tree-flow-inline.h ./tree-flow-inline.h
*** r1/tree-flow-inline.h	2013-09-10 13:06:06.568300474 -0400
--- ./tree-flow-inline.h	2013-09-10 13:17:48.507534463 -0400
*************** gimple_ssa_operands (const struct functi
*** 1159,1204 ****
  }
  
  
- /* Return an SSA_NAME node for variable VAR defined in statement STMT
-    in function cfun.  */
- 
- static inline tree
- make_ssa_name (tree var, gimple stmt)
- {
-   return make_ssa_name_fn (cfun, var, stmt);
- }
- 
- /* Return an SSA_NAME node using the template SSA name NAME defined in
-    statement STMT in function cfun.  */
- 
- static inline tree
- copy_ssa_name (tree var, gimple stmt)
- {
-   return copy_ssa_name_fn (cfun, var, stmt);
- }
- 
- /*  Creates a duplicate of a SSA name NAME tobe defined by statement STMT
-     in function cfun.  */
- 
- static inline tree
- duplicate_ssa_name (tree var, gimple stmt)
- {
-   return duplicate_ssa_name_fn (cfun, var, stmt);
- }
- 
- /* Return an anonymous SSA_NAME node for type TYPE defined in statement STMT
-    in function cfun.  Arrange so that it uses NAME in dumps.  */
- 
- static inline tree
- make_temp_ssa_name (tree type, gimple stmt, const char *name)
- {
-   tree ssa_name;
-   gcc_checking_assert (TYPE_P (type));
-   ssa_name = make_ssa_name_fn (cfun, type, stmt);
-   SET_SSA_NAME_VAR_OR_IDENTIFIER (ssa_name, get_identifier (name));
-   return ssa_name;
- }
- 
  /* Returns the base object and a constant BITS_PER_UNIT offset in *POFFSET that
     denotes the starting address of the memory access EXP.
     Returns NULL_TREE if the offset is not constant or any component
--- 1159,1164 ----
diff -rcp r1/tree-ssa-alias.h ./tree-ssa-alias.h
*** r1/tree-ssa-alias.h	2013-09-10 13:06:06.572300471 -0400
--- ./tree-ssa-alias.h	2013-09-10 13:22:47.578955641 -0400
*************** extern void *walk_non_aliased_vuses (ao_
*** 116,122 ****
  extern unsigned int walk_aliased_vdefs (ao_ref *, tree,
  					bool (*)(ao_ref *, tree, void *),
  					void *, bitmap *);
- extern struct ptr_info_def *get_ptr_info (tree);
  extern void dump_alias_info (FILE *);
  extern void debug_alias_info (void);
  extern void dump_points_to_solution (FILE *, struct pt_solution *);
--- 116,121 ----
diff -rcp r1/tree-ssa.h ./tree-ssa.h
*** r1/tree-ssa.h	2013-09-10 13:06:06.574300470 -0400
--- ./tree-ssa.h	2013-09-10 13:10:01.063168160 -0400
*************** along with GCC; see the file COPYING3.
*** 21,26 ****
--- 21,27 ----
  #define GCC_TREE_SSA_H
  
  #include "tree-flow.h"
+ #include "tree-ssanames.h"
  
  /* Mapping for redirected edges.  */
  struct _edge_var_map {
diff -rcp r1/tree-ssanames.c ./tree-ssanames.c
*** r1/tree-ssanames.c	2013-09-10 13:06:06.575300469 -0400
--- ./tree-ssanames.c	2013-09-10 13:22:39.300968112 -0400
*************** along with GCC; see the file COPYING3.
*** 60,65 ****
--- 60,68 ----
  unsigned int ssa_name_nodes_reused;
  unsigned int ssa_name_nodes_created;
  
+ #define FREE_SSANAMES(fun) (fun)->gimple_df->free_ssanames
+ 
+ 
  /* Initialize management of SSA_NAMEs to default SIZE.  If SIZE is
     zero use default.  */
  
diff -rcp r1/tree-ssanames.h ./tree-ssanames.h
*** r1/tree-ssanames.h	2013-09-10 13:42:23.670820666 -0400
--- ./tree-ssanames.h	2013-09-10 13:22:42.102963872 -0400
***************
*** 0 ****
--- 1,119 ----
+ /* SSA name expresssons routines
+    Copyright (C) 2013 Free Software Foundation, Inc.
+ 
+ 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/>.  */
+ 
+ #ifndef GCC_TREE_SSANAMES_H
+ #define GCC_TREE_SSANAMES_H
+ 
+ /* Aliasing information for SSA_NAMEs representing pointer variables.  */
+ 
+ struct GTY(()) ptr_info_def
+ {
+   /* The points-to solution.  */
+   struct pt_solution pt;
+ 
+   /* Alignment and misalignment of the pointer in bytes.  Together
+      align and misalign specify low known bits of the pointer.
+      ptr & (align - 1) == misalign.  */
+ 
+   /* When known, this is the power-of-two byte alignment of the object this
+      pointer points into.  This is usually DECL_ALIGN_UNIT for decls and
+      MALLOC_ABI_ALIGNMENT for allocated storage.  When the alignment is not
+      known, it is zero.  Do not access directly but use functions
+      get_ptr_info_alignment, set_ptr_info_alignment,
+      mark_ptr_info_alignment_unknown and similar.  */
+   unsigned int align;
+ 
+   /* When alignment is known, the byte offset this pointer differs from the
+      above alignment.  Access only through the same helper functions as align
+      above.  */
+   unsigned int misalign;
+ };
+ 
+ 
+ #define SSANAMES(fun) (fun)->gimple_df->ssa_names
+ #define MODIFIED_NORETURN_CALLS(fun) (fun)->gimple_df->modified_noreturn_calls
+ #define DEFAULT_DEFS(fun) (fun)->gimple_df->default_defs
+ 
+ #define num_ssa_names (vec_safe_length (cfun->gimple_df->ssa_names))
+ #define ssa_name(i) ((*cfun->gimple_df->ssa_names)[(i)])
+ 
+ 
+ extern void init_ssanames (struct function *, int);
+ extern void fini_ssanames (void);
+ extern void ssanames_print_statistics (void);
+ extern tree make_ssa_name_fn (struct function *, tree, gimple);
+ extern void release_ssa_name (tree);
+ extern bool get_ptr_info_alignment (struct ptr_info_def *, unsigned int *,
+ 				    unsigned int *);
+ extern void mark_ptr_info_alignment_unknown (struct ptr_info_def *);
+ extern void set_ptr_info_alignment (struct ptr_info_def *, unsigned int,
+ 				    unsigned int);
+ extern void adjust_ptr_info_misalignment (struct ptr_info_def *,
+ 					  unsigned int);
+ extern struct ptr_info_def *get_ptr_info (tree);
+ 
+ extern tree copy_ssa_name_fn (struct function *, tree, gimple);
+ extern void duplicate_ssa_name_ptr_info (tree, struct ptr_info_def *);
+ extern tree duplicate_ssa_name_fn (struct function *, tree, gimple);
+ extern void release_defs (gimple);
+ extern void replace_ssa_name_symbol (tree, tree);
+ 
+ 
+ /* Return an SSA_NAME node for variable VAR defined in statement STMT
+    in function cfun.  */
+ 
+ static inline tree
+ make_ssa_name (tree var, gimple stmt)
+ {
+   return make_ssa_name_fn (cfun, var, stmt);
+ }
+ 
+ /* Return an SSA_NAME node using the template SSA name NAME defined in
+    statement STMT in function cfun.  */
+ 
+ static inline tree
+ copy_ssa_name (tree var, gimple stmt)
+ {
+   return copy_ssa_name_fn (cfun, var, stmt);
+ }
+ 
+ /*  Creates a duplicate of a SSA name NAME tobe defined by statement STMT
+     in function cfun.  */
+ 
+ static inline tree
+ duplicate_ssa_name (tree var, gimple stmt)
+ {
+   return duplicate_ssa_name_fn (cfun, var, stmt);
+ }
+ 
+ /* Return an anonymous SSA_NAME node for type TYPE defined in statement STMT
+    in function cfun.  Arrange so that it uses NAME in dumps.  */
+ 
+ static inline tree
+ make_temp_ssa_name (tree type, gimple stmt, const char *name)
+ {
+   tree ssa_name;
+   gcc_checking_assert (TYPE_P (type));
+   ssa_name = make_ssa_name_fn (cfun, type, stmt);
+   SET_SSA_NAME_VAR_OR_IDENTIFIER (ssa_name, get_identifier (name));
+   return ssa_name;
+ }
+ 
+ 
+ #endif /* GCC_TREE_SSANAMES_H */
diff -rcp r1/Makefile.in ./Makefile.in
*** r1/Makefile.in	2013-09-10 13:06:06.546300487 -0400
--- ./Makefile.in	2013-09-10 13:33:15.770063212 -0400
*************** tree-ssa-threadupdate.o : tree-ssa-threa
*** 2379,2385 ****
     $(DIAGNOSTIC_H) $(FUNCTION_H) $(TM_H) coretypes.h $(DUMPFILE_H) \
     $(BASIC_BLOCK_H) $(FLAGS_H) $(CFGLOOP_H)
  tree-ssanames.o : tree-ssanames.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
!    $(TM_H) $(TREE_H) $(TREE_SSA_H) $(TREE_PASS_H)
  tree-phinodes.o : tree-phinodes.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
     $(TM_H) $(TREE_H) $(GGC_H) $(BASIC_BLOCK_H) $(TREE_SSA_H) \
     gt-tree-phinodes.h $(DIAGNOSTIC_CORE_H) $(GIMPLE_H)
--- 2379,2385 ----
     $(DIAGNOSTIC_H) $(FUNCTION_H) $(TM_H) coretypes.h $(DUMPFILE_H) \
     $(BASIC_BLOCK_H) $(FLAGS_H) $(CFGLOOP_H)
  tree-ssanames.o : tree-ssanames.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
!    $(TM_H) $(TREE_H) $(TREE_SSA_H) $(TREE_PASS_H) tree-ssanames.h
  tree-phinodes.o : tree-phinodes.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
     $(TM_H) $(TREE_H) $(GGC_H) $(BASIC_BLOCK_H) $(TREE_SSA_H) \
     gt-tree-phinodes.h $(DIAGNOSTIC_CORE_H) $(GIMPLE_H)
*************** GTFILES = $(CPP_ID_DATA_H) $(srcdir)/inp
*** 3837,3842 ****
--- 3837,3843 ----
    $(srcdir)/tree-ssa-propagate.c \
    $(srcdir)/tree-phinodes.c \
    $(srcdir)/tree-ssa-alias.h \
+   $(srcdir)/tree-ssanames.h \
    $(srcdir)/ipa-prop.h \
    $(srcdir)/trans-mem.c \
    $(srcdir)/lto-streamer.h \