PATCH: Plug some memory leaks
Mark Mitchell
mark@codesourcery.com
Wed Apr 5 19:31:00 GMT 2000
This patch kills some memory leaks in the back-end. Pretty much any
use of `oballoc' is a memory leak now, since front-ends are no longer
required so switch about from obstack to obstack all the time.
Fortunately, there's no reason to `oballoc' these things; they can
easily be handled in other ways.
Together with a similar patch for the C++ front-end (coming next),
these changes saved 35MB on file that took 289MB to compile.
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com
2000-04-05 Mark Mitchell <mark@codesourcery.com>
* final.c (final): Use xcalloc to allocate line_note_exists.
* function.c (free_after_compilation): Free the temp_slots.
(assign_stack_temp_for_type): Use xmalloc to allocate temp_slots.
(combine_temp_slot): Free temp_slots when they get combined.
(purge_addressof): Fix typo in comment.
* stmt.c (mark_goto_fixup): Mark the fixup itself.
(expand_fixup): Allocate the fixup with ggc_alloc_obj.
Index: final.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/final.c,v
retrieving revision 1.120
diff -c -p -r1.120 final.c
*** final.c 2000/03/29 13:10:41 1.120
--- final.c 2000/04/06 00:36:47
*************** final (first, file, optimize, prescan)
*** 1974,1981 ****
max_line = NOTE_LINE_NUMBER (insn);
}
! line_note_exists = (char *) oballoc (max_line + 1);
! bzero (line_note_exists, max_line + 1);
for (insn = first; insn; insn = NEXT_INSN (insn))
{
--- 1974,1980 ----
max_line = NOTE_LINE_NUMBER (insn);
}
! line_note_exists = (char *) xcalloc (max_line + 1, sizeof (char));
for (insn = first; insn; insn = NEXT_INSN (insn))
{
*************** final (first, file, optimize, prescan)
*** 2020,2025 ****
--- 2019,2026 ----
add_bb (file);
free_insn_eh_region ();
+ free (line_note_exists);
+ line_note_exists = NULL;
}
const char *
Index: function.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/function.c,v
retrieving revision 1.187
diff -c -p -r1.187 function.c
*** function.c 2000/03/30 20:32:31 1.187
--- function.c 2000/04/06 00:36:51
*************** void
*** 445,450 ****
--- 445,453 ----
free_after_compilation (f)
struct function *f;
{
+ struct temp_slot *ts;
+ struct temp_slot *next;
+
free_eh_status (f);
free_expr_status (f);
free_emit_status (f);
*************** free_after_compilation (f)
*** 456,461 ****
--- 459,471 ----
if (f->x_parm_reg_stack_loc)
free (f->x_parm_reg_stack_loc);
+ for (ts = f->x_temp_slots; ts; ts = next)
+ {
+ next = ts->next;
+ free (ts);
+ }
+ f->x_temp_slots = NULL;
+
f->arg_offset_rtx = NULL;
f->return_rtx = NULL;
f->internal_arg_pointer = NULL;
*************** free_after_compilation (f)
*** 476,482 ****
f->x_parm_birth_insn = NULL;
f->x_last_parm_insn = NULL;
f->x_parm_reg_stack_loc = NULL;
- f->x_temp_slots = NULL;
f->fixup_var_refs_queue = NULL;
f->original_arg_vector = NULL;
f->original_decl_initial = NULL;
--- 486,491 ----
*************** assign_stack_temp_for_type (mode, size,
*** 714,720 ****
if (best_p->size - rounded_size >= alignment)
{
! p = (struct temp_slot *) oballoc (sizeof (struct temp_slot));
p->in_use = p->addr_taken = 0;
p->size = best_p->size - rounded_size;
p->base_offset = best_p->base_offset + rounded_size;
--- 723,729 ----
if (best_p->size - rounded_size >= alignment)
{
! p = (struct temp_slot *) xmalloc (sizeof (struct temp_slot));
p->in_use = p->addr_taken = 0;
p->size = best_p->size - rounded_size;
p->base_offset = best_p->base_offset + rounded_size;
*************** assign_stack_temp_for_type (mode, size,
*** 744,750 ****
{
HOST_WIDE_INT frame_offset_old = frame_offset;
! p = (struct temp_slot *) oballoc (sizeof (struct temp_slot));
/* We are passing an explicit alignment request to assign_stack_local.
One side effect of that is assign_stack_local will not round SIZE
--- 753,759 ----
{
HOST_WIDE_INT frame_offset_old = frame_offset;
! p = (struct temp_slot *) xmalloc (sizeof (struct temp_slot));
/* We are passing an explicit alignment request to assign_stack_local.
One side effect of that is assign_stack_local will not round SIZE
*************** combine_temp_slots ()
*** 935,941 ****
}
/* Either delete Q or advance past it. */
if (delete_q)
! prev_q->next = q->next;
else
prev_q = q;
}
--- 944,953 ----
}
/* Either delete Q or advance past it. */
if (delete_q)
! {
! prev_q->next = q->next;
! free (q);
! }
else
prev_q = q;
}
*************** purge_addressof (insns)
*** 3274,3280 ****
/* When we actually purge ADDRESSOFs, we turn REGs into MEMs. That
requires a fixup pass over the instruction stream to correct
INSNs that depended on the REG being a REG, and not a MEM. But,
! these fixup passes are slow. Furthermore, more MEMs are not
mentioned in very many instructions. So, we speed up the process
by pre-calculating which REGs occur in which INSNs; that allows
us to perform the fixup passes much more quickly. */
--- 3286,3292 ----
/* When we actually purge ADDRESSOFs, we turn REGs into MEMs. That
requires a fixup pass over the instruction stream to correct
INSNs that depended on the REG being a REG, and not a MEM. But,
! these fixup passes are slow. Furthermore, most MEMs are not
mentioned in very many instructions. So, we speed up the process
by pre-calculating which REGs occur in which INSNs; that allows
us to perform the fixup passes much more quickly. */
Index: stmt.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/stmt.c,v
retrieving revision 1.139
diff -c -p -r1.139 stmt.c
*** stmt.c 2000/03/30 13:46:04 1.139
--- stmt.c 2000/04/06 00:36:58
*************** mark_goto_fixup (g)
*** 539,544 ****
--- 539,545 ----
{
while (g)
{
+ ggc_mark (g);
ggc_mark_rtx (g->before_jump);
ggc_mark_tree (g->target);
ggc_mark_tree (g->context);
*************** expand_fixup (tree_label, rtl_label, las
*** 1002,1008 ****
{
/* Ok, a fixup is needed. Add a fixup to the list of such. */
struct goto_fixup *fixup
! = (struct goto_fixup *) oballoc (sizeof (struct goto_fixup));
/* In case an old stack level is restored, make sure that comes
after any pending stack adjust. */
/* ?? If the fixup isn't to come at the present position,
--- 1003,1009 ----
{
/* Ok, a fixup is needed. Add a fixup to the list of such. */
struct goto_fixup *fixup
! = (struct goto_fixup *) ggc_alloc_obj (sizeof (struct goto_fixup), 0);
/* In case an old stack level is restored, make sure that comes
after any pending stack adjust. */
/* ?? If the fixup isn't to come at the present position,
More information about the Gcc-patches
mailing list