diff mbox

[6/9] Pass REG changes through a new function

Message ID 87wq05sq2a.fsf@e105548-lin.cambridge.arm.com
State New
Headers show

Commit Message

Richard Sandiford May 18, 2015, 6:23 p.m. UTC
This patch adds a new function to set both the mode and regno
of a REG.  It makes sure that all REG PUT_MODE and SET_REGNO changes
go through this function.  There's a new PUT_MODE_RAW (analogous
to SET_REGNO_RAW) for the cases where the caller doesn't want that.

There's a small consistency fix: gen_rtx_REG was declared with
"unsigned" and defined with "unsigned int".  The latter is usual
GCC style.


gcc/
	* rtl.h (PUT_MODE_RAW): New macro.
	(PUT_REG_NOTE_KIND): Use it.
	(set_mode_and_regno): Declare.
	(gen_raw_REG): Change regno to "unsigned int".
	(gen_rtx_REG): Change "unsigned" to "unsigned int".
	(PUT_MODE): Forward to PUT_MODE_RAW for generators, otherwise
	use set_mode_and_regno to change the mode of registers.
	* gengenrtl.c (gendef): Use PUT_MODE_RAW.
	* emit-rtl.c (set_mode_and_regno): New function.
	(gen_raw_REG): Change regno to unsigned int.  Use set_mode_and_regno.
	* caller-save.c (reg_save_code): Use set_mode_and_regno.
	* expr.c (init_expr_target): Likewise.
	* ira.c (setup_prohibited_mode_move_regs): Likewise.
	* postreload.c (reload_cse_simplify_operands): Likewise.

Comments

Jeff Law May 18, 2015, 9:30 p.m. UTC | #1
On 05/18/2015 12:23 PM, Richard Sandiford wrote:
> This patch adds a new function to set both the mode and regno
> of a REG.  It makes sure that all REG PUT_MODE and SET_REGNO changes
> go through this function.  There's a new PUT_MODE_RAW (analogous
> to SET_REGNO_RAW) for the cases where the caller doesn't want that.
>
> There's a small consistency fix: gen_rtx_REG was declared with
> "unsigned" and defined with "unsigned int".  The latter is usual
> GCC style.
>
>
> gcc/
> 	* rtl.h (PUT_MODE_RAW): New macro.
> 	(PUT_REG_NOTE_KIND): Use it.
> 	(set_mode_and_regno): Declare.
> 	(gen_raw_REG): Change regno to "unsigned int".
> 	(gen_rtx_REG): Change "unsigned" to "unsigned int".
> 	(PUT_MODE): Forward to PUT_MODE_RAW for generators, otherwise
> 	use set_mode_and_regno to change the mode of registers.
> 	* gengenrtl.c (gendef): Use PUT_MODE_RAW.
> 	* emit-rtl.c (set_mode_and_regno): New function.
> 	(gen_raw_REG): Change regno to unsigned int.  Use set_mode_and_regno.
> 	* caller-save.c (reg_save_code): Use set_mode_and_regno.
> 	* expr.c (init_expr_target): Likewise.
> 	* ira.c (setup_prohibited_mode_move_regs): Likewise.
> 	* postreload.c (reload_cse_simplify_operands): Likewise.
OK.
jeff
diff mbox

Patch

Index: gcc/rtl.h
===================================================================
--- gcc/rtl.h	2015-05-17 21:26:44.375213705 +0100
+++ gcc/rtl.h	2015-05-17 21:29:52.068986873 +0100
@@ -668,8 +668,8 @@  #define RTX_PREV(X) ((INSN_P (X)
 #define GET_CODE(RTX)	    ((enum rtx_code) (RTX)->code)
 #define PUT_CODE(RTX, CODE) ((RTX)->code = (CODE))
 
-#define GET_MODE(RTX)	    ((machine_mode) (RTX)->mode)
-#define PUT_MODE(RTX, MODE) ((RTX)->mode = (MODE))
+#define GET_MODE(RTX)		((machine_mode) (RTX)->mode)
+#define PUT_MODE_RAW(RTX, MODE)	((RTX)->mode = (MODE))
 
 /* RTL vector.  These appear inside RTX's when there is a need
    for a variable number of things.  The principle use is inside
@@ -1509,7 +1509,7 @@  #define DEF_REG_NOTE(NAME) NAME,
 /* Define macros to extract and insert the reg-note kind in an EXPR_LIST.  */
 #define REG_NOTE_KIND(LINK) ((enum reg_note) GET_MODE (LINK))
 #define PUT_REG_NOTE_KIND(LINK, KIND) \
-  PUT_MODE (LINK, (machine_mode) (KIND))
+  PUT_MODE_RAW (LINK, (machine_mode) (KIND))
 
 /* Names for REG_NOTE's in EXPR_LIST insn's.  */
 
@@ -3216,13 +3216,27 @@  gen_rtx_INSN (machine_mode mode, rtx_ins
 	      rtx reg_notes);
 extern rtx gen_rtx_CONST_INT (machine_mode, HOST_WIDE_INT);
 extern rtx gen_rtx_CONST_VECTOR (machine_mode, rtvec);
-extern rtx gen_raw_REG (machine_mode, int);
-extern rtx gen_rtx_REG (machine_mode, unsigned);
+extern void set_mode_and_regno (rtx, machine_mode, unsigned int);
+extern rtx gen_raw_REG (machine_mode, unsigned int);
+extern rtx gen_rtx_REG (machine_mode, unsigned int);
 extern rtx gen_rtx_SUBREG (machine_mode, rtx, int);
 extern rtx gen_rtx_MEM (machine_mode, rtx);
 extern rtx gen_rtx_VAR_LOCATION (machine_mode, tree, rtx,
 				 enum var_init_status);
 
+#ifdef GENERATOR_FILE
+#define PUT_MODE(RTX, MODE) PUT_MODE_RAW (RTX, MODE)
+#else
+static inline void
+PUT_MODE (rtx x, machine_mode mode)
+{
+  if (REG_P (x))
+    set_mode_and_regno (x, mode, REGNO (x));
+  else
+    PUT_MODE_RAW (x, mode);
+}
+#endif
+
 #define GEN_INT(N)  gen_rtx_CONST_INT (VOIDmode, (N))
 
 /* Virtual registers are used during RTL generation to refer to locations into
Index: gcc/gengenrtl.c
===================================================================
--- gcc/gengenrtl.c	2015-05-15 21:12:56.172234508 +0100
+++ gcc/gengenrtl.c	2015-05-17 21:31:16.143988041 +0100
@@ -252,7 +252,7 @@  gendef (const char *format)
   puts ("  rtx rt;");
   puts ("  rt = rtx_alloc_stat (code PASS_MEM_STAT);\n");
 
-  puts ("  PUT_MODE (rt, mode);");
+  puts ("  PUT_MODE_RAW (rt, mode);");
 
   for (p = format, i = j = 0; *p ; ++p, ++i)
     if (*p != '0')
Index: gcc/emit-rtl.c
===================================================================
--- gcc/emit-rtl.c	2015-05-17 21:26:44.375213705 +0100
+++ gcc/emit-rtl.c	2015-05-17 21:30:18.484672892 +0100
@@ -430,16 +430,24 @@  gen_blockage (void)
 #endif
 
 
+/* Set the mode and register number of X to MODE and REGNO.  */
+
+void
+set_mode_and_regno (rtx x, machine_mode mode, unsigned int regno)
+{
+  PUT_MODE_RAW (x, mode);
+  SET_REGNO_RAW (x, regno);
+}
+
 /* Generate a new REG rtx.  Make sure ORIGINAL_REGNO is set properly, and
    don't attempt to share with the various global pieces of rtl (such as
    frame_pointer_rtx).  */
 
 rtx
-gen_raw_REG (machine_mode mode, int regno)
+gen_raw_REG (machine_mode mode, unsigned int regno)
 {
   rtx x = rtx_alloc_stat (REG PASS_MEM_STAT);
-  PUT_MODE (x, mode);
-  SET_REGNO_RAW (x, regno);
+  set_mode_and_regno (x, mode, regno);
   REG_ATTRS (x) = NULL;
   ORIGINAL_REGNO (x) = regno;
   return x;
Index: gcc/caller-save.c
===================================================================
--- gcc/caller-save.c	2015-05-17 21:26:44.375213705 +0100
+++ gcc/caller-save.c	2015-05-17 21:26:44.363212664 +0100
@@ -150,8 +150,7 @@  reg_save_code (int reg, machine_mode mod
 
   /* Update the register number and modes of the register
      and memory operand.  */
-  SET_REGNO_RAW (test_reg, reg);
-  PUT_MODE (test_reg, mode);
+  set_mode_and_regno (test_reg, mode, reg);
   PUT_MODE (test_mem, mode);
 
   /* Force re-recognition of the modified insns.  */
Index: gcc/expr.c
===================================================================
--- gcc/expr.c	2015-05-17 21:26:44.375213705 +0100
+++ gcc/expr.c	2015-05-17 21:26:44.371213229 +0100
@@ -221,7 +221,6 @@  init_expr_target (void)
       direct_load[(int) mode] = direct_store[(int) mode] = 0;
       PUT_MODE (mem, mode);
       PUT_MODE (mem1, mode);
-      PUT_MODE (reg, mode);
 
       /* See if there is some register that can be used in this mode and
 	 directly loaded or stored from memory.  */
@@ -234,7 +233,7 @@  init_expr_target (void)
 	    if (! HARD_REGNO_MODE_OK (regno, mode))
 	      continue;
 
-	    SET_REGNO (reg, regno);
+	    set_mode_and_regno (reg, mode, regno);
 
 	    SET_SRC (pat) = mem;
 	    SET_DEST (pat) = reg;
Index: gcc/ira.c
===================================================================
--- gcc/ira.c	2015-05-17 21:26:44.375213705 +0100
+++ gcc/ira.c	2015-05-17 21:26:44.363212664 +0100
@@ -1778,10 +1778,8 @@  setup_prohibited_mode_move_regs (void)
 	{
 	  if (! HARD_REGNO_MODE_OK (j, (machine_mode) i))
 	    continue;
-	  SET_REGNO_RAW (test_reg1, j);
-	  PUT_MODE (test_reg1, (machine_mode) i);
-	  SET_REGNO_RAW (test_reg2, j);
-	  PUT_MODE (test_reg2, (machine_mode) i);
+	  set_mode_and_regno (test_reg1, (machine_mode) i, j);
+	  set_mode_and_regno (test_reg2, (machine_mode) i, j);
 	  INSN_CODE (move_insn) = -1;
 	  recog_memoized (move_insn);
 	  if (INSN_CODE (move_insn) < 0)
Index: gcc/postreload.c
===================================================================
--- gcc/postreload.c	2015-05-17 21:26:44.375213705 +0100
+++ gcc/postreload.c	2015-05-17 21:26:44.367212817 +0100
@@ -562,8 +562,7 @@  reload_cse_simplify_operands (rtx_insn *
 	  if (! TEST_HARD_REG_BIT (equiv_regs[i], regno))
 	    continue;
 
-	  SET_REGNO_RAW (testreg, regno);
-	  PUT_MODE (testreg, mode);
+	  set_mode_and_regno (testreg, mode, regno);
 
 	  /* We found a register equal to this operand.  Now look for all
 	     alternatives that can accept this register and have not been