diff mbox

[RFC] : Next stage1, refactoring: propagating rtx subclasses

Message ID 55727B9D.2010306@gmail.com
State New
Headers show

Commit Message

Mikhail Maltsev June 6, 2015, 4:48 a.m. UTC
09.05.2015 1:54, Jeff Law wrote:
> On 05/04/2015 02:18 PM, Mikhail Maltsev wrote:
[snip]
>> I'm trying to continue and the next patch (peep_split.patch,
>> peep_split.cl) is addressing the same task in some of the generated code
>> (namely, gen_peephole2_* and gen_split_* series of functions).
> And that looks good.  If it's bootstrapping and regression testing then
> it's good to go too.
> 
>>
>>> If you're going to continue this work, you should probably get
>>> write-after-approval access so that you can commit your own approved
>>> changes.
>> Is it OK to mention you as a maintainer who can approve my request for
>> write access?
> Yes, absolutely.  If you haven't already done so, go ahead and get this
> going because...
> 
> Both patches are approved.  Please install onto the trunk.
> 
> jeff
> 

Though this patch was approved about a month ago and I spent some time
while fixing the first patch related to rtx class hierarchy, I suppose
that it is still OK to apply it without additional approval.

I rebased the patch, and it required ~1 line change (which is rather
obvious). I also performed the complete test (bootstrapped and regtested
on x86_64-linux multilib, checked build of targets in
contrib/config-list.mk and ran regtests on several simulators: sh, mips
and arm).

Commited to trunk as r224183.
diff mbox

Patch

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index c388eb5..5c8d6c4 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,21 @@ 
+2015-06-06  Mikhail Maltsev  <maltsevm@gmail.com>
+
+	* combine.c (combine_split_insns): Remove cast.
+	* config/bfin/bfin.c (hwloop_fail): Add cast in try_split call.
+	* config/sh/sh.c (sh_try_split_insn_simple): Remove cast.
+	* config/sh/sh_treg_combine.cc (sh_treg_combine::execute): Add cast.
+	* emit-rtl.c (try_split): Promote type of trial argument to rtx_insn.
+	* genemit.c (gen_split): Change return type of generated functions to
+	rtx_insn.
+	* genrecog.c (get_failure_return): Use NULL instead of NULL_RTX.
+	(print_subroutine_start): Promote rtx to rtx_insn in gen_split_* and
+	gen_peephole2_* functions.
+	(print_subroutine, main): Likewise.
+	* recog.c (peephole2_optimize): Remove cast.
+	(peep2_next_insn): Promote return type to rtx_insn.
+	* recog.h (peep2_next_insn): Fix prototype.
+	* rtl.h (try_split, split_insns): Likewise.
+
 2015-06-05  Kaz Kojima  <kkojima@gcc.gnu.org>
 
 	PR target/66410
diff --git a/gcc/combine.c b/gcc/combine.c
index 01f43b1..8a9ab7a 100644
--- a/gcc/combine.c
+++ b/gcc/combine.c
@@ -554,7 +554,7 @@  combine_split_insns (rtx pattern, rtx_insn *insn)
   rtx_insn *ret;
   unsigned int nregs;
 
-  ret = safe_as_a <rtx_insn *> (split_insns (pattern, insn));
+  ret = split_insns (pattern, insn);
   nregs = max_reg_num ();
   if (nregs > reg_stat.length ())
     reg_stat.safe_grow_cleared (nregs);
diff --git a/gcc/config/bfin/bfin.c b/gcc/config/bfin/bfin.c
index 914a024..7b570cd 100644
--- a/gcc/config/bfin/bfin.c
+++ b/gcc/config/bfin/bfin.c
@@ -3877,7 +3877,7 @@  hwloop_fail (hwloop_info loop)
   else
     {
       splitting_loops = 1;  
-      try_split (PATTERN (insn), insn, 1);
+      try_split (PATTERN (insn), safe_as_a <rtx_insn *> (insn), 1);
       splitting_loops = 0;
     }
 }
diff --git a/gcc/config/sh/sh.c b/gcc/config/sh/sh.c
index d77154c..3b63014 100644
--- a/gcc/config/sh/sh.c
+++ b/gcc/config/sh/sh.c
@@ -14236,7 +14236,7 @@  sh_try_split_insn_simple (rtx_insn* i, rtx_insn* curr_insn, int n = 0)
       fprintf (dump_file, "\n");
     }
 
-  rtx_insn* seq = safe_as_a<rtx_insn*> (split_insns (PATTERN (i), curr_insn));
+  rtx_insn* seq = split_insns (PATTERN (i), curr_insn);
 
   if (seq == NULL)
     return std::make_pair (i, i);
diff --git a/gcc/config/sh/sh_treg_combine.cc b/gcc/config/sh/sh_treg_combine.cc
index 02e13e8..c09a4c3 100644
--- a/gcc/config/sh/sh_treg_combine.cc
+++ b/gcc/config/sh/sh_treg_combine.cc
@@ -1612,7 +1612,7 @@  sh_treg_combine::execute (function *fun)
 	log_msg ("trying to split insn:\n");
 	log_insn (*i);
 	log_msg ("\n");
-	try_split (PATTERN (*i), *i, 0);
+	try_split (PATTERN (*i), safe_as_a <rtx_insn *> (*i), 0);
       }
 
   m_touched_insns.clear ();
diff --git a/gcc/emit-rtl.c b/gcc/emit-rtl.c
index e632710..7bb2c77 100644
--- a/gcc/emit-rtl.c
+++ b/gcc/emit-rtl.c
@@ -3653,9 +3653,8 @@  mark_label_nuses (rtx x)
    returns TRIAL.  If the insn to be returned can be split, it will be.  */
 
 rtx_insn *
-try_split (rtx pat, rtx uncast_trial, int last)
+try_split (rtx pat, rtx_insn *trial, int last)
 {
-  rtx_insn *trial = as_a <rtx_insn *> (uncast_trial);
   rtx_insn *before = PREV_INSN (trial);
   rtx_insn *after = NEXT_INSN (trial);
   rtx note;
@@ -3674,7 +3673,7 @@  try_split (rtx pat, rtx uncast_trial, int last)
     split_branch_probability = XINT (note, 0);
   probability = split_branch_probability;
 
-  seq = safe_as_a <rtx_insn *> (split_insns (pat, trial));
+  seq = split_insns (pat, trial);
 
   split_branch_probability = -1;
 
diff --git a/gcc/genemit.c b/gcc/genemit.c
index 3f5dd82..e5b39fd 100644
--- a/gcc/genemit.c
+++ b/gcc/genemit.c
@@ -568,15 +568,17 @@  gen_split (rtx split)
   /* Output the prototype, function name and argument declarations.  */
   if (GET_CODE (split) == DEFINE_PEEPHOLE2)
     {
-      printf ("extern rtx gen_%s_%d (rtx_insn *, rtx *);\n",
+      printf ("extern rtx_insn *gen_%s_%d (rtx_insn *, rtx *);\n",
 	      name, insn_code_number);
-      printf ("rtx\ngen_%s_%d (rtx_insn *curr_insn ATTRIBUTE_UNUSED, rtx *operands%s)\n",
+      printf ("rtx_insn *\ngen_%s_%d (rtx_insn *curr_insn ATTRIBUTE_UNUSED, rtx *operands%s)\n",
 	      name, insn_code_number, unused);
     }
   else
     {
-      printf ("extern rtx gen_split_%d (rtx_insn *, rtx *);\n", insn_code_number);
-      printf ("rtx\ngen_split_%d (rtx_insn *curr_insn ATTRIBUTE_UNUSED, rtx *operands%s)\n",
+      printf ("extern rtx_insn *gen_split_%d (rtx_insn *, rtx *);\n",
+	      insn_code_number);
+      printf ("rtx_insn *\ngen_split_%d "
+	      "(rtx_insn *curr_insn ATTRIBUTE_UNUSED, rtx *operands%s)\n",
 	      insn_code_number, unused);
     }
   printf ("{\n");
@@ -584,7 +586,7 @@  gen_split (rtx split)
   /* Declare all local variables.  */
   for (i = 0; i < stats.num_operand_vars; i++)
     printf ("  rtx operand%d;\n", i);
-  printf ("  rtx _val = 0;\n");
+  printf ("  rtx_insn *_val = NULL;\n");
 
   if (GET_CODE (split) == DEFINE_PEEPHOLE2)
     output_peephole2_scratches (split);
diff --git a/gcc/genrecog.c b/gcc/genrecog.c
index 4b6dee6..217eb50 100644
--- a/gcc/genrecog.c
+++ b/gcc/genrecog.c
@@ -4307,7 +4307,7 @@  get_failure_return (routine_type type)
 
     case SPLIT:
     case PEEPHOLE2:
-      return "NULL_RTX";
+      return "NULL";
     }
   gcc_unreachable ();
 }
@@ -5061,7 +5061,7 @@  print_subroutine_start (output_state *os, state *s, position *root)
   if (os->type == SUBPATTERN || os->type == RECOG)
     printf ("  int res ATTRIBUTE_UNUSED;\n");
   else
-    printf ("  rtx res ATTRIBUTE_UNUSED;\n");
+    printf ("  rtx_insn *res ATTRIBUTE_UNUSED;\n");
 }
 
 /* Output the definition of pattern routine ROUTINE.  */
@@ -5111,7 +5111,7 @@  print_pattern (output_state *os, pattern_routine *routine)
 static void
 print_subroutine (output_state *os, state *s, int proc_id)
 {
-  /* For now, the top-level functions take a plain "rtx", and perform a
+  /* For now, the top-level "recog" takes a plain "rtx", and performs a
      checked cast to "rtx_insn *" for use throughout the rest of the
      function and the code it calls.  */
   const char *insn_param
@@ -5134,29 +5134,31 @@  print_subroutine (output_state *os, state *s, int proc_id)
 
     case SPLIT:
       if (proc_id)
-	printf ("static rtx\nsplit_%d", proc_id);
+	printf ("static rtx_insn *\nsplit_%d", proc_id);
       else
-	printf ("rtx\nsplit_insns");
-      printf (" (rtx x1 ATTRIBUTE_UNUSED, %s ATTRIBUTE_UNUSED)\n",
-	      insn_param);
+	printf ("rtx_insn *\nsplit_insns");
+      printf (" (rtx x1 ATTRIBUTE_UNUSED, rtx_insn *insn ATTRIBUTE_UNUSED)\n");
       break;
 
     case PEEPHOLE2:
       if (proc_id)
-	printf ("static rtx\npeephole2_%d", proc_id);
+	printf ("static rtx_insn *\npeephole2_%d", proc_id);
       else
-	printf ("rtx\npeephole2_insns");
+	printf ("rtx_insn *\npeephole2_insns");
       printf (" (rtx x1 ATTRIBUTE_UNUSED,\n"
-	      "\t%s ATTRIBUTE_UNUSED,\n"
-	      "\tint *pmatch_len_ ATTRIBUTE_UNUSED)\n", insn_param);
+	      "\trtx_insn *insn ATTRIBUTE_UNUSED,\n"
+	      "\tint *pmatch_len_ ATTRIBUTE_UNUSED)\n");
       break;
     }
   print_subroutine_start (os, s, &root_pos);
   if (proc_id == 0)
     {
       printf ("  recog_data.insn = NULL;\n");
-      printf ("  rtx_insn *insn ATTRIBUTE_UNUSED;\n");
-      printf ("  insn = safe_as_a <rtx_insn *> (uncast_insn);\n");
+      if (os->type == RECOG)
+	{
+	  printf ("  rtx_insn *insn ATTRIBUTE_UNUSED;\n");
+	  printf ("  insn = safe_as_a <rtx_insn *> (uncast_insn);\n");
+	}
     }
   print_state (os, s, 2, true);
   printf ("}\n");
@@ -5323,7 +5325,7 @@  main (int argc, char **argv)
 
 	  /* Declare the gen_split routine that we'll call if the
 	     pattern matches.  The definition comes from insn-emit.c.  */
-	  printf ("extern rtx gen_split_%d (rtx_insn *, rtx *);\n",
+	  printf ("extern rtx_insn *gen_split_%d (rtx_insn *, rtx *);\n",
 		  next_insn_code);
 	  break;
 
@@ -5335,7 +5337,7 @@  main (int argc, char **argv)
 
 	  /* Declare the gen_peephole2 routine that we'll call if the
 	     pattern matches.  The definition comes from insn-emit.c.  */
-	  printf ("extern rtx gen_peephole2_%d (rtx_insn *, rtx *);\n",
+	  printf ("extern rtx_insn *gen_peephole2_%d (rtx_insn *, rtx *);\n",
 		  next_insn_code);
 	  break;
 
diff --git a/gcc/recog.c b/gcc/recog.c
index ace0e9b..b1b9c22 100644
--- a/gcc/recog.c
+++ b/gcc/recog.c
@@ -3080,7 +3080,7 @@  peep2_buf_position (int n)
    does not exist.  Used by the recognizer to find the next insn to match
    in a multi-insn pattern.  */
 
-rtx
+rtx_insn *
 peep2_next_insn (int n)
 {
   gcc_assert (n <= peep2_current_count);
@@ -3653,8 +3653,7 @@  peephole2_optimize (void)
 
 	  /* Match the peephole.  */
 	  head = peep2_insn_data[peep2_current].insn;
-	  attempt = safe_as_a <rtx_insn *> (
-		      peephole2_insns (PATTERN (head), head, &match_len));
+	  attempt = peephole2_insns (PATTERN (head), head, &match_len);
 	  if (attempt != NULL)
 	    {
 	      rtx_insn *last = peep2_attempt (bb, head, match_len, attempt);
diff --git a/gcc/recog.h b/gcc/recog.h
index d97f4df..ce931eb 100644
--- a/gcc/recog.h
+++ b/gcc/recog.h
@@ -139,14 +139,14 @@  extern void preprocess_constraints (int, int, const char **,
 				    operand_alternative *);
 extern const operand_alternative *preprocess_insn_constraints (int);
 extern void preprocess_constraints (rtx_insn *);
-extern rtx peep2_next_insn (int);
+extern rtx_insn *peep2_next_insn (int);
 extern int peep2_regno_dead_p (int, int);
 extern int peep2_reg_dead_p (int, rtx);
 #ifdef CLEAR_HARD_REG_SET
 extern rtx peep2_find_free_register (int, int, const char *,
 				     machine_mode, HARD_REG_SET *);
 #endif
-extern rtx peephole2_insns (rtx, rtx, int *);
+extern rtx_insn *peephole2_insns (rtx, rtx_insn *, int *);
 
 extern int store_data_bypass_p (rtx_insn *, rtx_insn *);
 extern int if_test_bypass_p (rtx_insn *, rtx_insn *);
diff --git a/gcc/rtl.h b/gcc/rtl.h
index 863bfd4..2c190ec 100644
--- a/gcc/rtl.h
+++ b/gcc/rtl.h
@@ -2831,11 +2831,11 @@  extern rtx_insn *delete_related_insns (rtx);
 extern rtx *find_constant_term_loc (rtx *);
 
 /* In emit-rtl.c  */
-extern rtx_insn *try_split (rtx, rtx, int);
+extern rtx_insn *try_split (rtx, rtx_insn *, int);
 extern int split_branch_probability;
 
-/* In unknown file  */
-extern rtx split_insns (rtx, rtx);
+/* In insn-recog.c (generated by genrecog).  */
+extern rtx_insn *split_insns (rtx, rtx_insn *);
 
 /* In simplify-rtx.c  */
 extern rtx simplify_const_unary_operation (enum rtx_code, machine_mode,