IPA merge part 2: operand-cache privatization

Jan Hubicka jh@suse.cz
Thu Nov 30 09:15:00 GMT 2006


Hi,
this privatizes the operand cache in a way we discussed earlier (by
introducing structure for ssa_operands local and common accessor).  This
ought to be last basic SSA datastructure that needs privatizing.  This
time I hope I got even the Makefile stuff right ;)

Bootstrapped/regtested i686-linux, OK?

Honza

	* tree-ssa-operands.h (struct ssa_operands): New.
	* tree-flow-inline.h (gimple_ssa_operands): New function.
	* tree-flow.h: (struct gimple_df): Add ssa_operands.
	* Makefile.in: Remove gt-tree-ssa-operands.h
	* tree-ssa-operands.c: Do not include gt-tree-ssa-operands.h
	(free_defs, free_uses, free_vuses, free_maydefs, free_mustdefs,
	operand_memory, operand_memory_index, ops_active): Remove statics.
	(ALLOC_OPTYPE): Update.
	(operand_build_sort_virtual): Update.
	(ssa_operands_active): Update.
	(init_ssa_operands): Update.
	(fini_ssa_operands): Update.
	(ssa_operand_alloc): Update.
	(INITIALIZE_USE): Update.
	(finalize_ssa_use_ops): Update.
	(finalize_ssa_v_may_def_ops): Update.
	(finalize_ssa_vuse_ops): Update.
	(finalize_ssa_v_must_def_ops): Update.
Index: tree-ssa-operands.h
===================================================================
*** tree-ssa-operands.h	(revision 119291)
--- tree-ssa-operands.h	(working copy)
*************** struct ssa_operand_memory_d GTY((chain_n
*** 88,93 ****
--- 88,107 ----
    char mem[SSA_OPERAND_MEMORY_SIZE];
  };
  
+ /* Per-function operand caches.  */
+ struct ssa_operands GTY(()) {
+    /* These arrays are the cached operand vectors for call clobbered calls.  */
+    bool ops_active;
+ 
+    struct ssa_operand_memory_d *operand_memory;
+    unsigned operand_memory_index;
+ 
+    struct def_optype_d * GTY ((skip (""))) free_defs;
+    struct use_optype_d * GTY ((skip (""))) free_uses;
+    struct vuse_optype_d * GTY ((skip (""))) free_vuses;
+    struct maydef_optype_d * GTY ((skip (""))) free_maydefs;
+    struct mustdef_optype_d * GTY ((skip (""))) free_mustdefs;
+ };
  
  /* This represents the operand cache for a stmt.  */
  struct stmt_operands_d
Index: tree-flow-inline.h
===================================================================
*** tree-flow-inline.h	(revision 119294)
--- tree-flow-inline.h	(working copy)
*************** get_value_handle (tree expr)
*** 1726,1729 ****
--- 1726,1735 ----
      gcc_unreachable ();
  }
  
+ /* Accessor to tree-ssa-operands.c caches.  */
+ static inline struct ssa_operands *
+ gimple_ssa_operands (struct function *fun)
+ {
+   return &fun->gimple_df->ssa_operands;
+ }
  #endif /* _TREE_FLOW_INLINE_H  */
Index: tree-flow.h
===================================================================
*** tree-flow.h	(revision 119294)
--- tree-flow.h	(working copy)
*************** struct gimple_df GTY(()) {
*** 88,93 ****
--- 89,96 ----
  
    /* True if the code is in ssa form.  */
    unsigned int in_ssa_p : 1;
+ 
+   struct ssa_operands ssa_operands;
  };
  
  /* Accessors for internal use only.  Generic code should use abstraction
Index: Makefile.in
===================================================================
*** Makefile.in	(revision 119291)
--- Makefile.in	(working copy)
*************** tree-dfa.o : tree-dfa.c $(TREE_FLOW_H) $
*** 1972,1978 ****
  tree-ssa-operands.o : tree-ssa-operands.c $(TREE_FLOW_H) $(CONFIG_H) \
     $(SYSTEM_H) $(TREE_H) $(GGC_H) $(DIAGNOSTIC_H) errors.h $(TREE_INLINE_H) \
     $(FLAGS_H) $(FUNCTION_H) $(TM_H) $(TIMEVAR_H) tree-pass.h toplev.h \
!    gt-tree-ssa-operands.h coretypes.h langhooks.h $(IPA_REFERENCE_H)
  tree-eh.o : tree-eh.c $(TREE_FLOW_H) $(CONFIG_H) $(SYSTEM_H) \
     $(RTL_H) $(TREE_H) $(TM_H) $(FLAGS_H) $(FUNCTION_H) except.h langhooks.h \
     $(GGC_H) tree-pass.h coretypes.h $(TIMEVAR_H) $(TM_P_H) \
--- 1972,1978 ----
  tree-ssa-operands.o : tree-ssa-operands.c $(TREE_FLOW_H) $(CONFIG_H) \
     $(SYSTEM_H) $(TREE_H) $(GGC_H) $(DIAGNOSTIC_H) errors.h $(TREE_INLINE_H) \
     $(FLAGS_H) $(FUNCTION_H) $(TM_H) $(TIMEVAR_H) tree-pass.h toplev.h \
!    coretypes.h langhooks.h $(IPA_REFERENCE_H)
  tree-eh.o : tree-eh.c $(TREE_FLOW_H) $(CONFIG_H) $(SYSTEM_H) \
     $(RTL_H) $(TREE_H) $(TM_H) $(FLAGS_H) $(FUNCTION_H) except.h langhooks.h \
     $(GGC_H) tree-pass.h coretypes.h $(TIMEVAR_H) $(TM_P_H) \
*************** GTFILES = $(srcdir)/input.h $(srcdir)/co
*** 2868,2874 ****
    $(srcdir)/tree-dfa.c $(srcdir)/tree-ssa-propagate.c \
    $(srcdir)/tree-iterator.c $(srcdir)/gimplify.c \
    $(srcdir)/tree-chrec.h $(srcdir)/tree-vect-generic.c \
!   $(srcdir)/tree-ssa-operands.h $(srcdir)/tree-ssa-operands.c \
    $(srcdir)/tree-profile.c $(srcdir)/tree-nested.c \
    $(srcdir)/ipa-reference.c $(srcdir)/tree-ssa-structalias.h \
    $(srcdir)/tree-ssa-structalias.c \
--- 2868,2874 ----
    $(srcdir)/tree-dfa.c $(srcdir)/tree-ssa-propagate.c \
    $(srcdir)/tree-iterator.c $(srcdir)/gimplify.c \
    $(srcdir)/tree-chrec.h $(srcdir)/tree-vect-generic.c \
!   $(srcdir)/tree-ssa-operands.h \
    $(srcdir)/tree-profile.c $(srcdir)/tree-nested.c \
    $(srcdir)/ipa-reference.c $(srcdir)/tree-ssa-structalias.h \
    $(srcdir)/tree-ssa-structalias.c \
*************** gt-tree-mudflap.h gt-tree-vect-generic.h
*** 2903,2909 ****
  gt-tree-profile.h gt-tree-ssa-address.h \
  gt-tree-ssanames.h gt-tree-iterator.h gt-gimplify.h \
  gt-tree-phinodes.h gt-tree-nested.h \
! gt-tree-ssa-operands.h gt-tree-ssa-propagate.h \
  gt-tree-ssa-structalias.h gt-ipa-inline.h gt-cgraphunit.h \
  gt-stringpool.h gt-targhooks.h gt-omp-low.h : s-gtype ; @true
  
--- 2903,2909 ----
  gt-tree-profile.h gt-tree-ssa-address.h \
  gt-tree-ssanames.h gt-tree-iterator.h gt-gimplify.h \
  gt-tree-phinodes.h gt-tree-nested.h \
! gt-tree-ssa-propagate.h \
  gt-tree-ssa-structalias.h gt-ipa-inline.h gt-cgraphunit.h \
  gt-stringpool.h gt-targhooks.h gt-omp-low.h : s-gtype ; @true
  
Index: tree-ssa-operands.c
===================================================================
*** tree-ssa-operands.c	(revision 119294)
--- tree-ssa-operands.c	(working copy)
*************** static VEC(tree,heap) *build_vuses;
*** 116,134 ****
  /* Array for building all the V_MUST_DEF operands.  */
  static VEC(tree,heap) *build_v_must_defs;
  
- /* These arrays are the cached operand vectors for call clobbered calls.  */
- static bool ops_active = false;
- 
- static GTY (()) struct ssa_operand_memory_d *operand_memory = NULL;
- static unsigned operand_memory_index;
- 
  static void get_expr_operands (tree, tree *, int);
  
! static def_optype_p free_defs = NULL;
! static use_optype_p free_uses = NULL;
! static vuse_optype_p free_vuses = NULL;
! static maydef_optype_p free_maydefs = NULL;
! static mustdef_optype_p free_mustdefs = NULL;
  
  /* Allocates operand OP of given TYPE from the appropriate free list,
     or of the new value if the list is empty.  */
--- 116,125 ----
  /* Array for building all the V_MUST_DEF operands.  */
  static VEC(tree,heap) *build_v_must_defs;
  
  static void get_expr_operands (tree, tree *, int);
  
! /* Number of functions with initialized ssa_operands.  */
! static int n_initialized = 0;
  
  /* Allocates operand OP of given TYPE from the appropriate free list,
     or of the new value if the list is empty.  */
*************** static mustdef_optype_p free_mustdefs = 
*** 136,144 ****
  #define ALLOC_OPTYPE(OP, TYPE)				\
    do							\
      {							\
!       TYPE##_optype_p ret = free_##TYPE##s;		\
        if (ret)						\
! 	free_##TYPE##s = ret->next;			\
        else						\
  	ret = ssa_operand_alloc (sizeof (*ret));	\
        (OP) = ret;					\
--- 127,137 ----
  #define ALLOC_OPTYPE(OP, TYPE)				\
    do							\
      {							\
!       TYPE##_optype_p ret				\
! 	 = gimple_ssa_operands (cfun)->free_##TYPE##s;	\
        if (ret)						\
! 	gimple_ssa_operands (cfun)->free_##TYPE##s 	\
! 	 = ret->next;					\
        else						\
  	ret = ssa_operand_alloc (sizeof (*ret));	\
        (OP) = ret;					\
*************** operand_build_sort_virtual (VEC(tree,hea
*** 212,218 ****
  bool
  ssa_operands_active (void)
  {
!   return ops_active;
  }
  
  
--- 205,211 ----
  bool
  ssa_operands_active (void)
  {
!   return cfun->gimple_df && gimple_ssa_operands (cfun)->ops_active;
  }
  
  
*************** static struct 
*** 250,264 ****
  void
  init_ssa_operands (void)
  {
!   build_defs = VEC_alloc (tree, heap, 5);
!   build_uses = VEC_alloc (tree, heap, 10);
!   build_vuses = VEC_alloc (tree, heap, 25);
!   build_v_may_defs = VEC_alloc (tree, heap, 25);
!   build_v_must_defs = VEC_alloc (tree, heap, 25);
! 
!   gcc_assert (operand_memory == NULL);
!   operand_memory_index = SSA_OPERAND_MEMORY_SIZE;
!   ops_active = true;
    memset (&clobber_stats, 0, sizeof (clobber_stats));
  }
  
--- 243,260 ----
  void
  init_ssa_operands (void)
  {
!   if (!n_initialized++)
!     {
!       build_defs = VEC_alloc (tree, heap, 5);
!       build_uses = VEC_alloc (tree, heap, 10);
!       build_vuses = VEC_alloc (tree, heap, 25);
!       build_v_may_defs = VEC_alloc (tree, heap, 25);
!       build_v_must_defs = VEC_alloc (tree, heap, 25);
!     }
! 
!   gcc_assert (gimple_ssa_operands (cfun)->operand_memory == NULL);
!   gimple_ssa_operands (cfun)->operand_memory_index = SSA_OPERAND_MEMORY_SIZE;
!   gimple_ssa_operands (cfun)->ops_active = true;
    memset (&clobber_stats, 0, sizeof (clobber_stats));
  }
  
*************** void
*** 269,291 ****
  fini_ssa_operands (void)
  {
    struct ssa_operand_memory_d *ptr;
!   VEC_free (tree, heap, build_defs);
!   VEC_free (tree, heap, build_uses);
!   VEC_free (tree, heap, build_v_must_defs);
!   VEC_free (tree, heap, build_v_may_defs);
!   VEC_free (tree, heap, build_vuses);
!   free_defs = NULL;
!   free_uses = NULL;
!   free_vuses = NULL;
!   free_maydefs = NULL;
!   free_mustdefs = NULL;
!   while ((ptr = operand_memory) != NULL)
      {
!       operand_memory = operand_memory->next;
        ggc_free (ptr);
      }
  
!   ops_active = false;
    
    if (dump_file && (dump_flags & TDF_STATS))
      {
--- 265,291 ----
  fini_ssa_operands (void)
  {
    struct ssa_operand_memory_d *ptr;
!   if (!--n_initialized)
!     {
!       VEC_free (tree, heap, build_defs);
!       VEC_free (tree, heap, build_uses);
!       VEC_free (tree, heap, build_v_must_defs);
!       VEC_free (tree, heap, build_v_may_defs);
!       VEC_free (tree, heap, build_vuses);
!     }
!   gimple_ssa_operands (cfun)->free_defs = NULL;
!   gimple_ssa_operands (cfun)->free_uses = NULL;
!   gimple_ssa_operands (cfun)->free_vuses = NULL;
!   gimple_ssa_operands (cfun)->free_maydefs = NULL;
!   gimple_ssa_operands (cfun)->free_mustdefs = NULL;
!   while ((ptr = gimple_ssa_operands (cfun)->operand_memory) != NULL)
      {
!       gimple_ssa_operands (cfun)->operand_memory
! 	= gimple_ssa_operands (cfun)->operand_memory->next;
        ggc_free (ptr);
      }
  
!   gimple_ssa_operands (cfun)->ops_active = false;
    
    if (dump_file && (dump_flags & TDF_STATS))
      {
*************** static inline void *
*** 311,326 ****
  ssa_operand_alloc (unsigned size)
  {
    char *ptr;
!   if (operand_memory_index + size >= SSA_OPERAND_MEMORY_SIZE)
      {
        struct ssa_operand_memory_d *ptr;
        ptr = GGC_NEW (struct ssa_operand_memory_d);
!       ptr->next = operand_memory;
!       operand_memory = ptr;
!       operand_memory_index = 0;
!     }
!   ptr = &(operand_memory->mem[operand_memory_index]);
!   operand_memory_index += size;
    return ptr;
  }
  
--- 311,328 ----
  ssa_operand_alloc (unsigned size)
  {
    char *ptr;
!   if (gimple_ssa_operands (cfun)->operand_memory_index + size
!         >= SSA_OPERAND_MEMORY_SIZE)
      {
        struct ssa_operand_memory_d *ptr;
        ptr = GGC_NEW (struct ssa_operand_memory_d);
!       ptr->next = gimple_ssa_operands (cfun)->operand_memory;
!       gimple_ssa_operands (cfun)->operand_memory = ptr;
!       gimple_ssa_operands (cfun)->operand_memory_index = 0;
!     }
!   ptr = &(gimple_ssa_operands (cfun)->operand_memory
! 	  ->mem[gimple_ssa_operands (cfun)->operand_memory_index]);
!   gimple_ssa_operands (cfun)->operand_memory_index += size;
    return ptr;
  }
  
*************** set_virtual_use_link (use_operand_p ptr,
*** 366,373 ****
    do							\
      {							\
        TYPE##_optype_p next = (OP)->next;		\
!       (OP)->next = free_##TYPE##s;			\
!       free_##TYPE##s = (OP);				\
        (OP) = next;					\
      } while (0)
  
--- 368,376 ----
    do							\
      {							\
        TYPE##_optype_p next = (OP)->next;		\
!       (OP)->next					\
! 	 = gimple_ssa_operands (cfun)->free_##TYPE##s;	\
!       gimple_ssa_operands (cfun)->free_##TYPE##s = (OP);\
        (OP) = next;					\
      } while (0)
  
*************** finalize_ssa_def_ops (tree stmt)
*** 503,510 ****
    /* If there is anything in the old list, free it.  */
    if (old_ops)
      {
!       old_ops->next = free_defs;
!       free_defs = old_ops;
      }
  
    /* Now set the stmt's operands.  */
--- 506,513 ----
    /* If there is anything in the old list, free it.  */
    if (old_ops)
      {
!       old_ops->next = gimple_ssa_operands (cfun)->free_defs;
!       gimple_ssa_operands (cfun)->free_defs = old_ops;
      }
  
    /* Now set the stmt's operands.  */
*************** finalize_ssa_use_ops (tree stmt)
*** 558,565 ****
      {
        for (ptr = old_ops; ptr; ptr = ptr->next)
  	delink_imm_use (USE_OP_PTR (ptr));
!       old_ops->next = free_uses;
!       free_uses = old_ops;
      }
  
    /* Now create nodes for all the new nodes.  */
--- 561,568 ----
      {
        for (ptr = old_ops; ptr; ptr = ptr->next)
  	delink_imm_use (USE_OP_PTR (ptr));
!       old_ops->next = gimple_ssa_operands (cfun)->free_uses;
!       gimple_ssa_operands (cfun)->free_uses = old_ops;
      }
  
    /* Now create nodes for all the new nodes.  */
*************** finalize_ssa_v_may_def_ops (tree stmt)
*** 661,668 ****
      {
        for (ptr = old_ops; ptr; ptr = ptr->next)
  	delink_imm_use (MAYDEF_OP_PTR (ptr));
!       old_ops->next = free_maydefs;
!       free_maydefs = old_ops;
      }
  
    /* Now set the stmt's operands.  */
--- 664,671 ----
      {
        for (ptr = old_ops; ptr; ptr = ptr->next)
  	delink_imm_use (MAYDEF_OP_PTR (ptr));
!       old_ops->next = gimple_ssa_operands (cfun)->free_maydefs;
!       gimple_ssa_operands (cfun)->free_maydefs = old_ops;
      }
  
    /* Now set the stmt's operands.  */
*************** finalize_ssa_vuse_ops (tree stmt)
*** 763,770 ****
      {
        for (ptr = old_ops; ptr; ptr = ptr->next)
  	delink_imm_use (VUSE_OP_PTR (ptr));
!       old_ops->next = free_vuses;
!       free_vuses = old_ops;
      }
  
    /* Now set the stmt's operands.  */
--- 766,773 ----
      {
        for (ptr = old_ops; ptr; ptr = ptr->next)
  	delink_imm_use (VUSE_OP_PTR (ptr));
!       old_ops->next = gimple_ssa_operands (cfun)->free_vuses;
!       gimple_ssa_operands (cfun)->free_vuses = old_ops;
      }
  
    /* Now set the stmt's operands.  */
*************** finalize_ssa_v_must_def_ops (tree stmt)
*** 904,911 ****
      {
        for (ptr = old_ops; ptr; ptr = ptr->next)
  	delink_imm_use (MUSTDEF_KILL_PTR (ptr));
!       old_ops->next = free_mustdefs;
!       free_mustdefs = old_ops;
      }
  
    /* Now set the stmt's operands.  */
--- 907,914 ----
      {
        for (ptr = old_ops; ptr; ptr = ptr->next)
  	delink_imm_use (MUSTDEF_KILL_PTR (ptr));
!       old_ops->next = gimple_ssa_operands (cfun)->free_mustdefs;
!       gimple_ssa_operands (cfun)->free_mustdefs = old_ops;
      }
  
    /* Now set the stmt's operands.  */
*************** debug_immediate_uses_for (tree var)
*** 2582,2586 ****
  {
    dump_immediate_uses_for (stderr, var);
  }
- 
- #include "gt-tree-ssa-operands.h"
--- 2585,2587 ----



More information about the Gcc-patches mailing list