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]

Make tree-ssa-operands even more IPA-SSA ready


Hi,
this patch fixes two friendly memory corruptions in tree-ssa-operands that
appears after enabing SSA inliner.  One problem is that for some permanent
datastructures now bitmaps are used that are freed by tree-optimize.c.
Other problem is that ssa_operand_mem_size needs to be localized.

Bootstrapped/regtested together with other changes, separate testing in
progress (i686-linux).  Ok if it passes?

Honza

2006-12-21  Jan Hubicka  <jh@suse.cz>
	* tree-ssa-operands.h (struct ssa_operand_memory_d):
	add ssa_operand_mem_size.
	* tree-ssa-operands.c (operands_bitmap_obstack): New.
	(ssa_operand_mem_size): Remove.
	(init_ssa_operands): Initialize obstack; use it.
	(fini_ssa_operands): Release obstack.
	(ssa_operand_alloc): Update.
	(finalize_ssa_vdefs, finalize_ssa_vuse_ops, copy_virtual_operands,
	get_mpt_for): Use obstack.
Index: tree-ssa-operands.h
===================================================================
*** tree-ssa-operands.h	(revision 120083)
--- tree-ssa-operands.h	(working copy)
*************** struct ssa_operand_memory_d GTY((chain_n
*** 124,129 ****
--- 124,131 ----
  struct ssa_operands GTY(()) {
     struct ssa_operand_memory_d *operand_memory;
     unsigned operand_memory_index;
+    /* Current size of the operand memory buffer.  */
+    unsigned int ssa_operand_mem_size;
  
     bool ops_active;
  
Index: tree-ssa-operands.c
===================================================================
*** tree-ssa-operands.c	(revision 120083)
--- tree-ssa-operands.c	(working copy)
*************** static VEC(tree,heap) *build_vdefs;
*** 139,144 ****
--- 139,147 ----
  /* Set for building all the VUSE operands.  */
  static VEC(tree,heap) *build_vuses;
  
+ /* Bitmap obstack for our datastructures that needs to survive across	
+    compilations of multiple funcitons.  */
+ static bitmap_obstack operands_bitmap_obstack;
  /* Set for building all the loaded symbols.  */
  static bitmap build_loads;
  
*************** add_vop_to_freelist (voptype_p ptr)
*** 351,359 ****
  #define OP_SIZE_2	110
  #define OP_SIZE_3	511
  
- /* Current size of the operand memory buffer.  */
- static unsigned int ssa_operand_mem_size;
- 
  /* Initialize the operand cache routines.  */
  
  void
--- 354,359 ----
*************** init_ssa_operands (void)
*** 365,382 ****
        build_uses = VEC_alloc (tree, heap, 10);
        build_vuses = VEC_alloc (tree, heap, 25);
        build_vdefs = VEC_alloc (tree, heap, 25);
!       build_loads = BITMAP_ALLOC (NULL);
!       build_stores = BITMAP_ALLOC (NULL);
        scb_stack = VEC_alloc (scb_t, heap, 20);
      }
  
    gcc_assert (gimple_ssa_operands (cfun)->operand_memory == NULL);
    gcc_assert (gimple_ssa_operands (cfun)->mpt_table == NULL);
!   gimple_ssa_operands (cfun)->operand_memory_index = ssa_operand_mem_size;
    gimple_ssa_operands (cfun)->ops_active = true;
    memset (&clobber_stats, 0, sizeof (clobber_stats));
    init_vop_buckets ();
!   ssa_operand_mem_size = OP_SIZE_INIT;
  }
  
  
--- 365,384 ----
        build_uses = VEC_alloc (tree, heap, 10);
        build_vuses = VEC_alloc (tree, heap, 25);
        build_vdefs = VEC_alloc (tree, heap, 25);
!       bitmap_obstack_initialize (&operands_bitmap_obstack);
!       build_loads = BITMAP_ALLOC (&operands_bitmap_obstack);
!       build_stores = BITMAP_ALLOC (&operands_bitmap_obstack);
        scb_stack = VEC_alloc (scb_t, heap, 20);
      }
  
    gcc_assert (gimple_ssa_operands (cfun)->operand_memory == NULL);
    gcc_assert (gimple_ssa_operands (cfun)->mpt_table == NULL);
!   gimple_ssa_operands (cfun)->operand_memory_index
!      = gimple_ssa_operands (cfun)->ssa_operand_mem_size;
    gimple_ssa_operands (cfun)->ops_active = true;
    memset (&clobber_stats, 0, sizeof (clobber_stats));
    init_vop_buckets ();
!   gimple_ssa_operands (cfun)->ssa_operand_mem_size = OP_SIZE_INIT;
  }
  
  
*************** fini_ssa_operands (void)
*** 402,407 ****
--- 404,410 ----
        gcc_assert (VEC_length (scb_t, scb_stack) == 0);
        VEC_free (scb_t, heap, scb_stack);
        scb_stack = NULL;
+       bitmap_obstack_release (&operands_bitmap_obstack);
      }
  
    gimple_ssa_operands (cfun)->free_defs = NULL;
*************** ssa_operand_alloc (unsigned size)
*** 452,482 ****
    char *ptr;
  
    if (gimple_ssa_operands (cfun)->operand_memory_index + size
!       >= ssa_operand_mem_size)
      {
        struct ssa_operand_memory_d *ptr;
  
!       if (ssa_operand_mem_size == OP_SIZE_INIT)
! 	ssa_operand_mem_size = OP_SIZE_1 * sizeof (struct voptype_d);
        else
! 	if (ssa_operand_mem_size == OP_SIZE_1 * sizeof (struct voptype_d))
! 	  ssa_operand_mem_size = OP_SIZE_2 * sizeof (struct voptype_d);
  	else
! 	  ssa_operand_mem_size = OP_SIZE_3 * sizeof (struct voptype_d);
  
        /* Go right to the maximum size if the request is too large.  */
!       if (size > ssa_operand_mem_size)
!         ssa_operand_mem_size = OP_SIZE_3 * sizeof (struct voptype_d);
  
        /* Fail if there is not enough space.  If thre are this many operands
  	 required, first make sure there isn't a different probem causing this
  	 many operands.  If the decision is that this is OK, then we can 
  	 specially allocate a buffer just for this request.  */
!       gcc_assert (size <= ssa_operand_mem_size);
  
        ptr = (struct ssa_operand_memory_d *) 
  	      ggc_alloc (sizeof (struct ssa_operand_memory_d) 
! 			 + ssa_operand_mem_size - 1);
        ptr->next = gimple_ssa_operands (cfun)->operand_memory;
        gimple_ssa_operands (cfun)->operand_memory = ptr;
        gimple_ssa_operands (cfun)->operand_memory_index = 0;
--- 455,490 ----
    char *ptr;
  
    if (gimple_ssa_operands (cfun)->operand_memory_index + size
!       >= gimple_ssa_operands (cfun)->ssa_operand_mem_size)
      {
        struct ssa_operand_memory_d *ptr;
  
!       if (gimple_ssa_operands (cfun)->ssa_operand_mem_size == OP_SIZE_INIT)
! 	gimple_ssa_operands (cfun)->ssa_operand_mem_size
! 	   = OP_SIZE_1 * sizeof (struct voptype_d);
        else
! 	if (gimple_ssa_operands (cfun)->ssa_operand_mem_size
! 	    == OP_SIZE_1 * sizeof (struct voptype_d))
! 	  gimple_ssa_operands (cfun)->ssa_operand_mem_size
! 	     = OP_SIZE_2 * sizeof (struct voptype_d);
  	else
! 	  gimple_ssa_operands (cfun)->ssa_operand_mem_size
! 	     = OP_SIZE_3 * sizeof (struct voptype_d);
  
        /* Go right to the maximum size if the request is too large.  */
!       if (size > gimple_ssa_operands (cfun)->ssa_operand_mem_size)
!         gimple_ssa_operands (cfun)->ssa_operand_mem_size
! 	  = OP_SIZE_3 * sizeof (struct voptype_d);
  
        /* Fail if there is not enough space.  If thre are this many operands
  	 required, first make sure there isn't a different probem causing this
  	 many operands.  If the decision is that this is OK, then we can 
  	 specially allocate a buffer just for this request.  */
!       gcc_assert (size <= gimple_ssa_operands (cfun)->ssa_operand_mem_size);
  
        ptr = (struct ssa_operand_memory_d *) 
  	      ggc_alloc (sizeof (struct ssa_operand_memory_d) 
! 			 + gimple_ssa_operands (cfun)->ssa_operand_mem_size - 1);
        ptr->next = gimple_ssa_operands (cfun)->operand_memory;
        gimple_ssa_operands (cfun)->operand_memory = ptr;
        gimple_ssa_operands (cfun)->operand_memory_index = 0;
*************** finalize_ssa_vdefs (tree stmt)
*** 876,882 ****
    if (!bitmap_empty_p (build_stores))
      {
        if (ann->operands.stores == NULL)
! 	ann->operands.stores = BITMAP_ALLOC (NULL);
  
        bitmap_copy (ann->operands.stores, build_stores);
      }
--- 884,890 ----
    if (!bitmap_empty_p (build_stores))
      {
        if (ann->operands.stores == NULL)
! 	ann->operands.stores = BITMAP_ALLOC (&operands_bitmap_obstack);
  
        bitmap_copy (ann->operands.stores, build_stores);
      }
*************** finalize_ssa_vuse_ops (tree stmt)
*** 982,988 ****
    if (!bitmap_empty_p (build_loads))
      {
        if (ann->operands.loads == NULL)
! 	ann->operands.loads = BITMAP_ALLOC (NULL);
  
        bitmap_copy (ann->operands.loads, build_loads);
      }
--- 990,996 ----
    if (!bitmap_empty_p (build_loads))
      {
        if (ann->operands.loads == NULL)
! 	ann->operands.loads = BITMAP_ALLOC (&operands_bitmap_obstack);
  
        bitmap_copy (ann->operands.loads, build_loads);
      }
*************** copy_virtual_operands (tree dest, tree s
*** 2403,2415 ****
  
    if (LOADED_SYMS (src))
      {
!       dest_ann->operands.loads = BITMAP_ALLOC (NULL);
        bitmap_copy (dest_ann->operands.loads, LOADED_SYMS (src));
      }
  
    if (STORED_SYMS (src))
      {
!       dest_ann->operands.stores = BITMAP_ALLOC (NULL);
        bitmap_copy (dest_ann->operands.stores, STORED_SYMS (src));
      }
  
--- 2411,2423 ----
  
    if (LOADED_SYMS (src))
      {
!       dest_ann->operands.loads = BITMAP_ALLOC (&operands_bitmap_obstack);
        bitmap_copy (dest_ann->operands.loads, LOADED_SYMS (src));
      }
  
    if (STORED_SYMS (src))
      {
!       dest_ann->operands.stores = BITMAP_ALLOC (&operands_bitmap_obstack);
        bitmap_copy (dest_ann->operands.stores, STORED_SYMS (src));
      }
  
*************** get_mpt_for (tree sym)
*** 2969,2975 ****
        MTAG_GLOBAL (mpt) = 1;
        add_referenced_var (mpt);
        VEC_safe_push (tree, heap, gimple_ssa_operands (cfun)->mpt_table, mpt);
!       MPT_SYMBOLS (mpt) = BITMAP_ALLOC (NULL);
        set_memory_partition (sym, mpt);
      }
  
--- 2977,2983 ----
        MTAG_GLOBAL (mpt) = 1;
        add_referenced_var (mpt);
        VEC_safe_push (tree, heap, gimple_ssa_operands (cfun)->mpt_table, mpt);
!       MPT_SYMBOLS (mpt) = BITMAP_ALLOC (&operands_bitmap_obstack);
        set_memory_partition (sym, mpt);
      }
  


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