]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR middle-end/10060 (ICE (stack overflow) on huge file (300k lines) due to recursi...
authorAndrew Pinski <pinskia@physics.uc.edu>
Mon, 8 Dec 2003 17:36:59 +0000 (17:36 +0000)
committerAndrew Pinski <pinskia@gcc.gnu.org>
Mon, 8 Dec 2003 17:36:59 +0000 (09:36 -0800)
2003-12-08  Andrew Pinski  <pinskia@physics.uc.edu>

        PR middle-end/10060
        * emit-rtl.c (copy_rtx_if_shared): Split out into ...
        (copy_rtx_if_shared_1): here and optimize the last one
        in the sequence into tail-recursion.
        (reset_used_flags): Optimize the last one
        in the sequence into tail-recursion.

From-SVN: r74425

gcc/ChangeLog
gcc/emit-rtl.c

index c8cb81245eaa049a81a03ef9e2072dec2c3b978d..266ca5e7480df455af72af8e1382b0b2866e5d30 100644 (file)
@@ -1,3 +1,12 @@
+2003-12-08  Andrew Pinski  <pinskia@physics.uc.edu>
+
+       PR middle-end/10060
+       * emit-rtl.c (copy_rtx_if_shared): Split out into ...
+       (copy_rtx_if_shared_1): here and optimize the last one
+       in the sequence into tail-recursion.
+       (reset_used_flags): Optimize the last one
+       in the sequence into tail-recursion.
+
 2003-12-07  Alan Modra  <amodra@bigpond.net.au>
 
        * config/rs6000/rs6000.c (rs6000_elf_section_type_flags): Don't
index 172a82d3b4b1ca4ce72388c1bc555aa564bef455..ef0e1569305138563f91ccf37c3aa9e6a28fa39f 100644 (file)
@@ -190,6 +190,7 @@ static mem_attrs *get_mem_attrs             PARAMS ((HOST_WIDE_INT, tree, rtx,
                                                 enum machine_mode));
 static tree component_ref_for_mem_expr PARAMS ((tree));
 static rtx gen_const_vector_0          PARAMS ((enum machine_mode));
+static void copy_rtx_if_shared_1       PARAMS ((rtx *orig));
 
 /* Probability of the conditional branch currently proceeded by try_split.
    Set to -1 otherwise.  */
@@ -2572,14 +2573,28 @@ rtx
 copy_rtx_if_shared (orig)
      rtx orig;
 {
-  rtx x = orig;
+  copy_rtx_if_shared_1 (&orig);
+  return orig;
+}
+
+static void
+copy_rtx_if_shared_1 (orig1)
+     rtx *orig1;
+{
+  rtx x;
   int i;
   enum rtx_code code;
+  rtx *last_ptr;
   const char *format_ptr;
   int copied = 0;
+  int length;
+
+  /* Repeat is used to turn tail-recursion into iteration.  */
+repeat:
+  x = *orig1;
 
   if (x == 0)
-    return 0;
+    return;
 
   code = GET_CODE (x);
 
@@ -2598,7 +2613,7 @@ copy_rtx_if_shared (orig)
     case CC0:
     case SCRATCH:
       /* SCRATCH must be shared because they represent distinct values.  */
-      return x;
+      return;
 
     case CONST:
       /* CONST can be shared if it contains a SYMBOL_REF.  If it contains
@@ -2606,7 +2621,7 @@ copy_rtx_if_shared (orig)
       if (GET_CODE (XEXP (x, 0)) == PLUS
          && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
          && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT)
-       return x;
+       return;
       break;
 
     case INSN:
@@ -2615,7 +2630,7 @@ copy_rtx_if_shared (orig)
     case NOTE:
     case BARRIER:
       /* The chain of insns is not being copied.  */
-      return x;
+      return;
 
     case MEM:
       /* A MEM is allowed to be shared if its address is constant.
@@ -2657,13 +2672,17 @@ copy_rtx_if_shared (orig)
      must be copied if X was copied.  */
 
   format_ptr = GET_RTX_FORMAT (code);
-
-  for (i = 0; i < GET_RTX_LENGTH (code); i++)
+  length = GET_RTX_LENGTH (code);
+  last_ptr = NULL;
+  
+  for (i = 0; i < length; i++)
     {
       switch (*format_ptr++)
        {
        case 'e':
-         XEXP (x, i) = copy_rtx_if_shared (XEXP (x, i));
+          if (last_ptr)
+            copy_rtx_if_shared_1 (last_ptr);
+         last_ptr = &XEXP (x, i);
          break;
 
        case 'E':
@@ -2671,16 +2690,29 @@ copy_rtx_if_shared (orig)
            {
              int j;
              int len = XVECLEN (x, i);
-
+              
+              /* Copy the vector iff I copied the rtx and the length is nonzero. */
              if (copied && len > 0)
                XVEC (x, i) = gen_rtvec_v (len, XVEC (x, i)->elem);
+              
+              /* Call recsusively on all inside the vector. */
              for (j = 0; j < len; j++)
-               XVECEXP (x, i, j) = copy_rtx_if_shared (XVECEXP (x, i, j));
+                {
+                 if (last_ptr)
+                   copy_rtx_if_shared_1 (last_ptr);
+                  last_ptr = &XVECEXP (x, i, j);
+                }
            }
          break;
        }
     }
-  return x;
+  *orig1 = x;
+  if (last_ptr)
+    {
+      orig1 = last_ptr;
+      goto repeat;
+    }
+  return;
 }
 
 /* Clear all the USED bits in X to allow copy_rtx_if_shared to be used
@@ -2693,7 +2725,10 @@ reset_used_flags (x)
   int i, j;
   enum rtx_code code;
   const char *format_ptr;
+  int length;
 
+  /* Repeat is used to turn tail-recursion into iteration.  */
+repeat:
   if (x == 0)
     return;
 
@@ -2731,11 +2766,18 @@ reset_used_flags (x)
   RTX_FLAG (x, used) = 0;
 
   format_ptr = GET_RTX_FORMAT (code);
-  for (i = 0; i < GET_RTX_LENGTH (code); i++)
+  length = GET_RTX_LENGTH (code);
+  
+  for (i = 0; i < length; i++)
     {
       switch (*format_ptr++)
        {
        case 'e':
+          if (i == length-1)
+            {
+              x = XEXP (x, i);
+             goto repeat;
+            }
          reset_used_flags (XEXP (x, i));
          break;