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]

[rtlopt] use of alloc pools in var-tracking.c


Hi,

this patch changes the allocation to use alloc-pool.c
It also fixes a memory leak (variable_htab was not freed)
and some comments.

Bootstrapped i386.

Josef

2003-02-02  Josef Zlomek  <zlomekj@suse.cz>

	* Makefile.in (var-tracking.o): Added dependency on alloc-pool.h.
	* var-tracking.c: Fix some comments.
	(attrs_pool): New variable.
	(var_pool): New variable.
	(variable_htab_free): New function.
	(attrs_*_*): Use pool_alloc instead of xmalloc and pool_free instead of
	free.
	(set_location_part): Likewise.
	(var_tracking_initialize): Create alloc pools, del_f for variable_htab
	is variable_htab_free now.
	(var_tracking_finalize): Delete variable_htab and alloc pools.
	(variable_tracking_main): Remove debug dump.

Index: Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Makefile.in,v
retrieving revision 1.937.2.29
diff -c -3 -p -r1.937.2.29 Makefile.in
*** Makefile.in	25 Jan 2003 11:45:34 -0000	1.937.2.29
--- Makefile.in	2 Feb 2003 16:53:37 -0000
*************** df.o : df.c $(CONFIG_H) $(SYSTEM_H) core
*** 1585,1591 ****
     $(BASIC_BLOCK_H) df.h $(FIBHEAP_H)
  var-tracking.o : var-tracking.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
      $(RTL_H) hard-reg-set.h $(BASIC_BLOCK_H) $(TREE_H) output.h sbitmap.h \
!     $(FIBHEAP_H) $(HASHTAB_H)
  conflict.o : conflict.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(OBSTACK_H) \
     $(HASHTAB_H) $(RTL_H) hard-reg-set.h $(BASIC_BLOCK_H)
  profile.o : profile.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(RTL_H) $(TREE_H) \
--- 1585,1591 ----
     $(BASIC_BLOCK_H) df.h $(FIBHEAP_H)
  var-tracking.o : var-tracking.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
      $(RTL_H) hard-reg-set.h $(BASIC_BLOCK_H) $(TREE_H) output.h sbitmap.h \
!     alloc-pool.h $(FIBHEAP_H) $(HASHTAB_H)
  conflict.o : conflict.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(OBSTACK_H) \
     $(HASHTAB_H) $(RTL_H) hard-reg-set.h $(BASIC_BLOCK_H)
  profile.o : profile.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(RTL_H) $(TREE_H) \
Index: var-tracking.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/var-tracking.c,v
retrieving revision 1.1.4.12
diff -c -3 -p -r1.1.4.12 var-tracking.c
*** var-tracking.c	2 Feb 2003 12:24:16 -0000	1.1.4.12
--- var-tracking.c	2 Feb 2003 16:53:41 -0000
***************
*** 27,32 ****
--- 27,33 ----
  #include "basic-block.h"
  #include "output.h"
  #include "sbitmap.h"
+ #include "alloc-pool.h"
  #include "fibheap.h"
  #include "hashtab.h"
  
*************** enum scan_operation
*** 46,52 ****
    SO_SKIP	/* Skip current node, and scan and store its internals.  */
  };
  
! /* Where shall the note be emitted? BEFORE or AFTER the instruction.  */
  enum where_emit_note
  {
    EMIT_NOTE_BEFORE_INSN,
--- 47,53 ----
    SO_SKIP	/* Skip current node, and scan and store its internals.  */
  };
  
! /* Where shall the note be emitted?  BEFORE or AFTER the instruction.  */
  enum where_emit_note
  {
    EMIT_NOTE_BEFORE_INSN,
*************** static htab_t variable_htab;
*** 180,190 ****
--- 181,198 ----
  /* Get the pointer to the BB's information specific to var-tracking pass.  */
  #define VTI(BB) ((var_tracking_info) (BB)->aux)
  
+ /* Alloc pool for struct attrs_def.  */
+ static alloc_pool attrs_pool;
+ 
+ /* Alloc pool for struct variable_def.  */
+ static alloc_pool var_pool;
+ 
  /* Local function prototypes.  */
  static hashval_t mem_htab_hash		PARAMS ((const void *));
  static int mem_htab_eq			PARAMS ((const void *, const void *));
  static hashval_t variable_htab_hash	PARAMS ((const void *));
  static int variable_htab_eq		PARAMS ((const void *, const void *));
+ static void variable_htab_free		PARAMS ((void *));
  
  static void init_attrs_list_set		PARAMS ((attrs *));
  static void attrs_list_clear		PARAMS ((attrs *));
*************** variable_htab_eq (x, y)
*** 286,291 ****
--- 294,308 ----
    return (VARIABLE_HASH_VAL (v->decl) == VARIABLE_HASH_VAL (decl));
  }
  
+ /* Free the element of VARIABLE_HTAB (struct variable_def).  */
+ 
+ static void
+ variable_htab_free (var)
+      void *var;
+ {
+   pool_free (var_pool, var);
+ }
+ 
  /* Initialize the set (array) SET of attrs to empty lists.  */
  
  static void
*************** attrs_list_clear (listp)
*** 309,315 ****
    for (list = *listp; list; list = next)
      {
        next = list->next;
!       free (list);
      }
    *listp = NULL;
  }
--- 326,332 ----
    for (list = *listp; list; list = next)
      {
        next = list->next;
!       pool_free (attrs_pool, list);
      }
    *listp = NULL;
  }
*************** attrs_list_insert (listp, decl, offset, 
*** 339,345 ****
  {
    attrs list;
  
!   list = xmalloc (sizeof (*list));
    list->loc = loc;
    list->decl = decl;
    list->offset = offset;
--- 356,362 ----
  {
    attrs list;
  
!   list = pool_alloc (attrs_pool);
    list->loc = loc;
    list->decl = decl;
    list->offset = offset;
*************** attrs_list_delete (listp, decl, offset)
*** 366,372 ****
  	    prev->next = next;
  	  else
  	    *listp = next;
! 	  free (list);
  	}
        else
  	prev = list;
--- 383,389 ----
  	    prev->next = next;
  	  else
  	    *listp = next;
! 	  pool_free (attrs_pool, list);
  	}
        else
  	prev = list;
*************** attrs_list_copy (dstp, src)
*** 385,391 ****
    attrs_list_clear (dstp);
    for (; src; src = src->next)
      {
!       n = xmalloc (sizeof (*n));
        n->loc = src->loc;
        n->decl = src->decl;
        n->offset = src->offset;
--- 402,408 ----
    attrs_list_clear (dstp);
    for (; src; src = src->next)
      {
!       n = pool_alloc (attrs_pool);
        n->loc = src->loc;
        n->decl = src->decl;
        n->offset = src->offset;
*************** attrs_htab_insert (htab, mem)
*** 446,452 ****
  						  MEM_HASH_VAL (mem), INSERT);
      }
  
!   list = xmalloc (sizeof (*list));
    list->loc = mem;
    list->decl = MEM_EXPR (mem);
    list->offset = MEM_OFFSET (mem) ? INTVAL (MEM_OFFSET (mem)) : 0;
--- 463,469 ----
  						  MEM_HASH_VAL (mem), INSERT);
      }
  
!   list = pool_alloc (attrs_pool);
    list->loc = mem;
    list->decl = MEM_EXPR (mem);
    list->offset = MEM_OFFSET (mem) ? INTVAL (MEM_OFFSET (mem)) : 0;
*************** attrs_htab_delete (htab, mem)
*** 490,496 ****
  		prev->next = next;
  	      else
  		*listp = next;
! 	      free (list);
  	    }
  	  else
  	    prev = list;
--- 507,513 ----
  		prev->next = next;
  	      else
  		*listp = next;
! 	      pool_free (attrs_pool, list);
  	    }
  	  else
  	    prev = list;
*************** attrs_htab_copy_1 (slot, data)
*** 566,572 ****
  					     MEM_HASH_VAL (src->loc), INSERT);
    for (; src; src = src->next)
      {
!       list = xmalloc (sizeof (*list));
        list->loc = src->loc;
        list->decl = src->decl;
        list->offset = src->offset;
--- 583,589 ----
  					     MEM_HASH_VAL (src->loc), INSERT);
    for (; src; src = src->next)
      {
!       list = pool_alloc (attrs_pool);
        list->loc = src->loc;
        list->decl = src->decl;
        list->offset = src->offset;
*************** attrs_htab_union_1 (slot, data)
*** 614,620 ****
  	  break;
        if (!list)
  	{
! 	  list = xmalloc (sizeof (*list));
  	  list->loc = src->loc;
  	  list->decl = src->decl;
  	  list->offset = src->offset;
--- 631,637 ----
  	  break;
        if (!list)
  	{
! 	  list = pool_alloc (attrs_pool);
  	  list->loc = src->loc;
  	  list->decl = src->decl;
  	  list->offset = src->offset;
*************** attrs_htab_cleanup (slot)
*** 655,661 ****
    for (list = (attrs) slot; list; list = next)
      {
        next = list->next;
!       free (list);
      }
  }
  
--- 672,678 ----
    for (list = (attrs) slot; list; list = next)
      {
        next = list->next;
!       pool_free (attrs_pool, list);
      }
  }
  
*************** track_expr_p (expr)
*** 691,697 ****
    return 1;
  }
  
! /* Scan rtx X for registers and memory references. Other parameters are
     in struct scan_for_locations_data passed in DATA.  */
  
  static int
--- 708,714 ----
    return 1;
  }
  
! /* Scan rtx X for registers and memory references.  Other parameters are
     in struct scan_for_locations_data passed in DATA.  */
  
  static int
*************** dump_attrs ()
*** 1060,1066 ****
      }
  }
  
! /* Emit the NOTE_INSN_VAR_LOCATION for variable VAR. WHERE specifies
     whether the note shall be emitted before of after instruction INSN.  */
  
  static void
--- 1077,1083 ----
      }
  }
  
! /* Emit the NOTE_INSN_VAR_LOCATION for variable VAR.  WHERE specifies
     whether the note shall be emitted before of after instruction INSN.  */
  
  static void
*************** note_insn_var_location_emit (insn, where
*** 1110,1118 ****
      abort ();
  }
  
! /* Set the part of variable's location. The variable part is specified
     by variable's declaration DECL and offset OFFSET and the part's location
!    by LOC. The INSN and WHERE parameters specify where the note will be emitted
     (see note_insn_var_location_emit).  */
  
  static void
--- 1127,1135 ----
      abort ();
  }
  
! /* Set the part of variable's location.  The variable part is specified
     by variable's declaration DECL and offset OFFSET and the part's location
!    by LOC.  The INSN and WHERE parameters specify where the note will be emitted
     (see note_insn_var_location_emit).  */
  
  static void
*************** set_location_part (decl, offset, loc, in
*** 1130,1136 ****
      {
        void **slot;
        /* Create new variable information.  */
!       var = xmalloc (sizeof (*var));
        var->decl = decl;
        var->n_location_parts = 0;
  
--- 1147,1153 ----
      {
        void **slot;
        /* Create new variable information.  */
!       var = pool_alloc (var_pool);
        var->decl = decl;
        var->n_location_parts = 0;
  
*************** set_location_part (decl, offset, loc, in
*** 1177,1183 ****
      }
  }
  
! /* Delete the part of variable's location. The variable part is specified
     by variable's declaration DECL and offset OFFSET.
     The INSN and WHERE parameters specify where the note will be emitted
     (see note_insn_var_location_emit).  */
--- 1194,1200 ----
      }
  }
  
! /* Delete the part of variable's location.  The variable part is specified
     by variable's declaration DECL and offset OFFSET.
     The INSN and WHERE parameters specify where the note will be emitted
     (see note_insn_var_location_emit).  */
*************** emit_note_if_var_changed (slot, aux)
*** 1263,1269 ****
  
  /* Delete the location part of variable corresponding to LOC from all
     register locations (in LISTS) and memory locations (in HTAB) and emit
!    notes before/after (parameter WHERE) INSN. The location part which
     has the same decl and offset as LOC is deleted from HTAB only when
     DELETE_LOC_FROM_HTAB is true.  */
  
--- 1280,1286 ----
  
  /* Delete the location part of variable corresponding to LOC from all
     register locations (in LISTS) and memory locations (in HTAB) and emit
!    notes before/after (parameter WHERE) INSN.  The location part which
     has the same decl and offset as LOC is deleted from HTAB only when
     DELETE_LOC_FROM_HTAB is true.  */
  
*************** var_tracking_initialize ()
*** 1570,1576 ****
  				       attrs_htab_cleanup);
      }
  
!   variable_htab = htab_create (37, variable_htab_hash, variable_htab_eq, free);
  }
  
  /* Free the data structures needed for variable tracking.  */
--- 1587,1599 ----
  				       attrs_htab_cleanup);
      }
  
!   attrs_pool = create_alloc_pool ("attrs_def pool",
! 				  sizeof (struct attrs_def), 1024);
!   var_pool = create_alloc_pool ("variable_def pool",
! 				sizeof (struct variable_def), 64);
!   variable_htab = htab_create (37, variable_htab_hash, variable_htab_eq,
! 			       variable_htab_free);
! 
  }
  
  /* Free the data structures needed for variable tracking.  */
*************** var_tracking_finalize ()
*** 1594,1599 ****
--- 1617,1625 ----
        htab_delete (VTI (bb)->mem_out);
      }
    free_aux_for_blocks ();
+   htab_delete (variable_htab);
+   free_alloc_pool (attrs_pool);
+   free_alloc_pool (var_pool);
  }
  
  /* The entry point to variable tracking pass.  */
*************** variable_tracking_main ()
*** 1614,1627 ****
    flow_depth_first_order_compute (NULL, rc_order);
    for (i = 0; i < n_basic_blocks; i++)
      bb_order[rc_order[i]] = i;
! 
!   if (rtl_dump_file)
!     {
!       fprintf (rtl_dump_file, "RC order: \n");
!       for (i = 0; i < n_basic_blocks; i++)
! 	fprintf (rtl_dump_file, "%d ", rc_order[i]);
!       fprintf (rtl_dump_file, "\n");
!     }
  
    iterative_dataflow (bb_order);
    var_tracking_emit_notes ();
--- 1640,1646 ----
    flow_depth_first_order_compute (NULL, rc_order);
    for (i = 0; i < n_basic_blocks; i++)
      bb_order[rc_order[i]] = i;
!   free (rc_order);
  
    iterative_dataflow (bb_order);
    var_tracking_emit_notes ();
*************** variable_tracking_main ()
*** 1632,1638 ****
        dump_flow_info (rtl_dump_file);
      }
  
-   free (rc_order);
    free (bb_order);
    var_tracking_finalize ();
  }
--- 1651,1656 ----


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