Patchwork merge {set,reset}_used_flags

login
register
mail settings
Submitter Nathan Froyd
Date Oct. 30, 2010, 3:06 a.m.
Message ID <20101030030657.GC6758@nightcrawler>
Download mbox | patch
Permalink /patch/69645/
State New
Headers show

Comments

Nathan Froyd - Oct. 30, 2010, 3:06 a.m.
set_used_flags and reset_used_flags in emit-rtl.c are essentially the
same function, except they set the used flag slightly differently.  This
patch introduces a common function, mark_used_flags, and makes them both
call it.  As a bonus, set_used_flags now gets to benefit from the small
tail recursion optimization that reset_used_flags employed.

Tested on x86_64-unknown-linux-gnu.  OK to commit?

-Nathan

	* emit-rtl.c (mark_used_flags): New function.
	(set_used_flags, reset_used_flags): Call it.
Richard Henderson - Oct. 31, 2010, 12:16 a.m.
On 10/29/2010 08:06 PM, Nathan Froyd wrote:
>  }
>  
> -/* Clear all the USED bits in X to allow copy_rtx_if_shared to be used
> -   to look for shared sub-parts.  */
> -
> -void
> -reset_used_flags (rtx x)
> +static void
> +mark_used_flags (rtx x, int flag)

Missing function block comment.

Otherwise ok.


r~

Patch

diff --git a/gcc/emit-rtl.c b/gcc/emit-rtl.c
index 19d290c..0aed7c0 100644
--- a/gcc/emit-rtl.c
+++ b/gcc/emit-rtl.c
@@ -2728,11 +2728,8 @@  repeat:
   return;
 }
 
-/* Clear all the USED bits in X to allow copy_rtx_if_shared to be used
-   to look for shared sub-parts.  */
-
-void
-reset_used_flags (rtx x)
+static void
+mark_used_flags (rtx x, int flag)
 {
   int i, j;
   enum rtx_code code;
@@ -2778,7 +2775,7 @@  repeat:
       break;
     }
 
-  RTX_FLAG (x, used) = 0;
+  RTX_FLAG (x, used) = flag;
 
   format_ptr = GET_RTX_FORMAT (code);
   length = GET_RTX_LENGTH (code);
@@ -2793,81 +2790,33 @@  repeat:
               x = XEXP (x, i);
 	      goto repeat;
             }
-	  reset_used_flags (XEXP (x, i));
+	  mark_used_flags (XEXP (x, i), flag);
 	  break;
 
 	case 'E':
 	  for (j = 0; j < XVECLEN (x, i); j++)
-	    reset_used_flags (XVECEXP (x, i, j));
+	    mark_used_flags (XVECEXP (x, i, j), flag);
 	  break;
 	}
     }
 }
 
-/* Set all the USED bits in X to allow copy_rtx_if_shared to be used
+/* Clear all the USED bits in X to allow copy_rtx_if_shared to be used
    to look for shared sub-parts.  */
 
 void
-set_used_flags (rtx x)
+reset_used_flags (rtx x)
 {
-  int i, j;
-  enum rtx_code code;
-  const char *format_ptr;
-
-  if (x == 0)
-    return;
-
-  code = GET_CODE (x);
-
-  /* These types may be freely shared so we needn't do any resetting
-     for them.  */
-
-  switch (code)
-    {
-    case REG:
-    case DEBUG_EXPR:
-    case VALUE:
-    case CONST_INT:
-    case CONST_DOUBLE:
-    case CONST_FIXED:
-    case CONST_VECTOR:
-    case SYMBOL_REF:
-    case CODE_LABEL:
-    case PC:
-    case CC0:
-      return;
-
-    case DEBUG_INSN:
-    case INSN:
-    case JUMP_INSN:
-    case CALL_INSN:
-    case NOTE:
-    case LABEL_REF:
-    case BARRIER:
-      /* The chain of insns is not being copied.  */
-      return;
-
-    default:
-      break;
-    }
-
-  RTX_FLAG (x, used) = 1;
+  mark_used_flags (x, 0);
+}
 
-  format_ptr = GET_RTX_FORMAT (code);
-  for (i = 0; i < GET_RTX_LENGTH (code); i++)
-    {
-      switch (*format_ptr++)
-	{
-	case 'e':
-	  set_used_flags (XEXP (x, i));
-	  break;
+/* Set all the USED bits in X to allow copy_rtx_if_shared to be used
+   to look for shared sub-parts.  */
 
-	case 'E':
-	  for (j = 0; j < XVECLEN (x, i); j++)
-	    set_used_flags (XVECEXP (x, i, j));
-	  break;
-	}
-    }
+void
+set_used_flags (rtx x)
+{
+  mark_used_flags (x, 1);
 }
 
 /* Copy X if necessary so that it won't be altered by changes in OTHER.