[42/50] sel-sched.c:count_occurrences_equiv
diff mbox

Message ID 87wqap63s8.fsf@googlemail.com
State New
Headers show

Commit Message

Richard Sandiford Aug. 3, 2014, 2:33 p.m. UTC
gcc/
	* sel-sched.c: Include rtl-iter.h
	(count_occurrences_1): Delete.
	(count_occurrences_equiv): Turn rtxes into const_rtxes.
	Use FOR_EACH_SUBRTX rather than for_each_rtx.

Comments

Jeff Law Aug. 5, 2014, 10:12 p.m. UTC | #1
On 08/03/14 08:33, Richard Sandiford wrote:
> gcc/
> 	* sel-sched.c: Include rtl-iter.h
> 	(count_occurrences_1): Delete.
> 	(count_occurrences_equiv): Turn rtxes into const_rtxes.
> 	Use FOR_EACH_SUBRTX rather than for_each_rtx.
OK.
Jeff

Patch
diff mbox

Index: gcc/sel-sched.c
===================================================================
--- gcc/sel-sched.c	2014-08-03 11:23:46.458129098 +0100
+++ gcc/sel-sched.c	2014-08-03 11:25:31.949172045 +0100
@@ -42,6 +42,7 @@  Software Foundation; either version 3, o
 #include "rtlhooks-def.h"
 #include "emit-rtl.h"
 #include "ira.h"
+#include "rtl-iter.h"
 
 #ifdef INSN_SCHEDULING
 #include "sel-sched-ir.h"
@@ -798,58 +799,35 @@  substitute_reg_in_expr (expr_t expr, ins
     return false;
 }
 
-/* Helper function for count_occurences_equiv.  */
-static int
-count_occurrences_1 (rtx *cur_rtx, void *arg)
-{
-  rtx_search_arg_p p = (rtx_search_arg_p) arg;
-
-  if (REG_P (*cur_rtx) && REGNO (*cur_rtx) == REGNO (p->x))
-    {
-      /* Bail out if mode is different or more than one register is used.  */
-      if (GET_MODE (*cur_rtx) != GET_MODE (p->x)
-          || (HARD_REGISTER_P (*cur_rtx)
-	      && hard_regno_nregs[REGNO (*cur_rtx)][GET_MODE (*cur_rtx)] > 1))
-        {
-          p->n = 0;
-          return 1;
-        }
-
-      p->n++;
-
-      /* Do not traverse subexprs.  */
-      return -1;
-    }
-
-  if (GET_CODE (*cur_rtx) == SUBREG
-      && (!REG_P (SUBREG_REG (*cur_rtx))
-	  || REGNO (SUBREG_REG (*cur_rtx)) == REGNO (p->x)))
-    {
-      /* ??? Do not support substituting regs inside subregs.  In that case,
-         simplify_subreg will be called by validate_replace_rtx, and
-         unsubstitution will fail later.  */
-      p->n = 0;
-      return 1;
-    }
-
-  /* Continue search.  */
-  return 0;
-}
-
 /* Return the number of places WHAT appears within WHERE.
    Bail out when we found a reference occupying several hard registers.  */
 static int
-count_occurrences_equiv (rtx what, rtx where)
+count_occurrences_equiv (const_rtx what, const_rtx where)
 {
-  struct rtx_search_arg arg;
-
-  gcc_assert (REG_P (what));
-  arg.x = what;
-  arg.n = 0;
-
-  for_each_rtx (&where, &count_occurrences_1, (void *) &arg);
-
-  return arg.n;
+  int count = 0;
+  subrtx_iterator::array_type array;
+  FOR_EACH_SUBRTX (iter, array, where, NONCONST)
+    {
+      const_rtx x = *iter;
+      if (REG_P (x) && REGNO (x) == REGNO (what))
+	{
+	  /* Bail out if mode is different or more than one register is
+	     used.  */
+	  if (GET_MODE (x) != GET_MODE (what)
+	      || (HARD_REGISTER_P (x)
+		  && hard_regno_nregs[REGNO (x)][GET_MODE (x)] > 1))
+	    return 0;
+	  count += 1;
+	}
+      else if (GET_CODE (x) == SUBREG
+	       && (!REG_P (SUBREG_REG (x))
+		   || REGNO (SUBREG_REG (x)) == REGNO (what)))
+	/* ??? Do not support substituting regs inside subregs.  In that case,
+	   simplify_subreg will be called by validate_replace_rtx, and
+	   unsubstitution will fail later.  */
+	return 0;
+    }
+  return count;
 }
 
 /* Returns TRUE if WHAT is found in WHERE rtx tree.  */