This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Loop clean up fixes
On Jan 21, 2000, Michael Hayes <m.hayes@elec.canterbury.ac.nz> wrote:
> Alexandre Oliva writes:
>> BTW, I can't see where loops->array is freed; does it remain allocated
>> forever? In this case, you might prefer to allocate the loop_info
>> array as I do, but within loop_optimize.
> No, this is an inadvertent memory leak I've introduced by the
> splitting up of my loop clean up patches.
How 'bout this temporary fix, then? This patch renders the other
patches I've posted on this thread obsolete. Ok to install?
Index: gcc/ChangeLog
from Alexandre Oliva <oliva@lsd.ic.unicamp.br>
* basic_block.h (struct loop_info): Forward-declare.
(struct loop): Make info a struct loop_info*.
* loop.c (loop_optimize): Allocate loops->array and loop_info
array.
(find_and_verify_loops): Do not allocate loops->array.
Index: gcc/loop.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/loop.c,v
retrieving revision 1.221
diff -u -p -r1.221 loop.c
--- gcc/loop.c 2000/01/19 20:10:00 1.221
+++ gcc/loop.c 2000/01/21 11:40:30
@@ -445,6 +445,15 @@ loop_optimize (f, dumpfile, unroll_p, bc
loops->num = max_loop_num;
+ loops->array = (struct loop *)
+ xcalloc (max_loop_num, sizeof (struct loop));
+
+ loops->array[0].info = (struct loop_info *)
+ xcalloc (max_loop_num, sizeof (struct loop_info));
+
+ for (i = max_loop_num - 1; i >= 0; i--)
+ loops->array[i].info = &loops->array[0].info[i];
+
moved_once = (char *) xcalloc (max_reg_before_loop, sizeof (char));
/* Get size to use for tables indexed by uids.
@@ -510,15 +519,6 @@ loop_optimize (f, dumpfile, unroll_p, bc
this prevents low overhead loop instructions from being used. */
indirect_jump_in_function = indirect_jump_in_function_p (f);
- /* Allocate and initialize auxiliary loop information. */
- for (i = max_loop_num - 1; i >= 0; i--)
- {
- struct loop *loop = &loops->array[i];
-
- loop->info = (struct loop_info *) alloca (sizeof (struct loop_info));
- memset (loop->info, 0, sizeof (struct loop_info));
- }
-
/* Now scan the loops, last ones first, since this means inner ones are done
before outer ones. */
for (i = max_loop_num - 1; i >= 0; i--)
@@ -536,6 +536,8 @@ loop_optimize (f, dumpfile, unroll_p, bc
end_alias_analysis ();
/* Clean up. */
+ free (loops->array[0].info);
+ free (loops->array);
free (moved_once);
free (uid_luid);
free (uid_loop);
@@ -2596,10 +2598,6 @@ find_and_verify_loops (f, loops)
This also avoids writing past end of tables when there are no loops. */
uid_loop[0] = NULL;
- loops->array = (struct loop *)
- xmalloc (num_loops * sizeof (struct loop));
- bzero ((char *)loops->array, num_loops * sizeof (struct loop));
-
/* Find boundaries of loops, mark which loops are contained within
loops, and invalidate loops that have setjmp. */
--
Alexandre Oliva http://www.ic.unicamp.br/~oliva IC-Unicamp, Bra[sz]il
oliva@{lsd.ic.unicamp.br,guarana.{org,com}} aoliva@{acm,computer}.org
oliva@{gnu.org,kaffe.org,{egcs,sourceware}.cygnus.com,samba.org}
** I may forward mail about projects to mailing lists; please use them