PATCH: Fix regset memory leaks.

Michael Hayes m.hayes@elec.canterbury.ac.nz
Fri Jan 11 18:07:00 GMT 2002


This patch fixes a couple of small memory leaks due to regsets that are
not freed.  I found them with my new bitset code.

I've bootstrapped GCC with the patch and noticed no new regressions.

Michael.


2002-01-12  Michael Hayes  <m.hayes@elec.canterbury.ac.nz>

	* conflict.c (conflict_graph_compute): Free regsets when finished.
	* ssa.c (compute_coalesced_reg_partition): Likewise.

Index: conflict.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/conflict.c,v
retrieving revision 1.10
diff -c -3 -p -r1.10 conflict.c
*** conflict.c	2001/11/11 11:25:16	1.10
--- conflict.c	2001/12/31 00:06:57
*************** conflict_graph_compute (regs, p)
*** 449,468 ****
  {
    int b;
    conflict_graph graph = conflict_graph_new (max_reg_num ());
  
    for (b = n_basic_blocks; --b >= 0; )
      {
        basic_block bb = BASIC_BLOCK (b);
-       regset_head live_head;
-       regset live = &live_head;
-       regset_head born_head;
-       regset born = &born_head;
        rtx insn;
        rtx head;
  
-       INIT_REG_SET (live);
-       INIT_REG_SET (born);
- 
        /* Start with the regs that are live on exit, limited to those
  	 we're interested in.  */
        COPY_REG_SET (live, bb->global_live_at_end);
--- 449,468 ----
  {
    int b;
    conflict_graph graph = conflict_graph_new (max_reg_num ());
+   regset_head live_head;
+   regset live = &live_head;
+   regset_head born_head;
+   regset born = &born_head;
  
+   INIT_REG_SET (live);
+   INIT_REG_SET (born);
+ 
    for (b = n_basic_blocks; --b >= 0; )
      {
        basic_block bb = BASIC_BLOCK (b);
        rtx insn;
        rtx head;
  
        /* Start with the regs that are live on exit, limited to those
  	 we're interested in.  */
        COPY_REG_SET (live, bb->global_live_at_end);
*************** conflict_graph_compute (regs, p)
*** 523,528 ****
--- 523,531 ----
  	    }
  	}
      }
+ 
+   FREE_REG_SET (live);
+   FREE_REG_SET (born);
  
    return graph;
  }
Index: ssa.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/ssa.c,v
retrieving revision 1.41
diff -c -3 -p -r1.41 ssa.c
*** ssa.c	2001/10/28 20:09:16	1.41
--- ssa.c	2001/12/31 00:07:25
*************** compute_coalesced_reg_partition ()
*** 1850,1855 ****
--- 1850,1857 ----
  {
    int bb;
    int changed = 0;
+   regset_head phi_set_head;
+   regset phi_set = &phi_set_head;
  
    partition p = 
      partition_new (ssa_definition->num_elements);
*************** compute_coalesced_reg_partition ()
*** 1861,1880 ****
    for (bb = n_basic_blocks; --bb >= 0; )
      make_regs_equivalent_over_bad_edges (bb, p);
  
    do
      {
-       regset_head phi_set;
        conflict_graph conflicts;
  
        changed = 0;
  
        /* Build the set of registers involved in phi nodes, either as
  	 arguments to the phi function or as the target of a set.  */
!       INITIALIZE_REG_SET (phi_set);
!       mark_phi_and_copy_regs (&phi_set);
  
        /* Compute conflicts.  */
!       conflicts = conflict_graph_compute (&phi_set, p);
  
        /* FIXME: Better would be to process most frequently executed
  	 blocks first, so that most frequently executed copies would
--- 1863,1883 ----
    for (bb = n_basic_blocks; --bb >= 0; )
      make_regs_equivalent_over_bad_edges (bb, p);
  
+   INIT_REG_SET (phi_set);
+ 
    do
      {
        conflict_graph conflicts;
  
        changed = 0;
  
        /* Build the set of registers involved in phi nodes, either as
  	 arguments to the phi function or as the target of a set.  */
!       CLEAR_REG_SET (phi_set);
!       mark_phi_and_copy_regs (phi_set);
  
        /* Compute conflicts.  */
!       conflicts = conflict_graph_compute (phi_set, p);
  
        /* FIXME: Better would be to process most frequently executed
  	 blocks first, so that most frequently executed copies would
*************** compute_coalesced_reg_partition ()
*** 1891,1896 ****
--- 1894,1901 ----
        conflict_graph_delete (conflicts);
      }
    while (changed > 0);
+ 
+   FREE_REG_SET (phi_set);
  
    return p;
  }



More information about the Gcc-patches mailing list