This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Add new functions to rtlanal.c and simplify-rtx.c


These will be used by my later changes, but I wanted to get them in first.

Tue Feb 13 15:42:05 2001  Richard Kenner  <kenner@vlsi1.ultra.nyu.edu>

	* rtlanal.c (find_reg_equal_equiv_note): New function.
	* simplify-rtx.c (simplify_gen_unary, simplify_gen_ternary): New fns.
	(simplify_gen_relational, simplify_replace_rtx): Likewise.
	* rtl.h: Add declarations for above functions.

*** rtlanal.c	2001/02/08 16:24:34	1.85
--- rtlanal.c	2001/02/13 20:37:36
*************** find_regno_note (insn, kind, regno)
*** 1486,1489 ****
--- 1486,1506 ----
  }
  
+ /* Return a REG_EQUIV or REG_EQUAL note if insn has only a single set and
+    has such a note.  */
+ 
+ rtx
+ find_reg_equal_equiv_note (insn)
+      rtx insn;
+ {
+   rtx note;
+ 
+   if (single_set (insn) == 0)
+     return 0;
+   else if ((note = find_reg_note (insn, REG_EQUIV, NULL_RTX)) != 0)
+     return note;
+   else
+     return find_reg_note (insn, REG_EQUAL, NULL_RTX);
+ }
+ 
  /* Return true if DATUM, or any overlap of DATUM, of kind CODE is found
     in the CALL_INSN_FUNCTION_USAGE information of INSN.  */
*** simplify-rtx.c	2001/02/12 23:15:38	1.42
--- simplify-rtx.c	2001/02/13 20:37:40
*************** simplify_gen_binary (code, mode, op0, op
*** 141,144 ****
--- 141,266 ----
  }
  
+ /* Make a unary operation by first seeing if it folds and otherwise making
+    the specified operation.  */
+ 
+ rtx
+ simplify_gen_unary (code, mode, op, op_mode)
+      enum rtx_code code;
+      enum machine_mode mode;
+      rtx op;
+      enum machine_mode op_mode;
+ {
+   rtx tem;
+ 
+   /* If this simplifies, use it.  */
+   if ((tem = simplify_unary_operation (code, mode, op, op_mode)) != 0)
+     return tem;
+ 
+   return gen_rtx_fmt_e (code, mode, op);
+ }
+ 
+ /* Likewise for ternary operations.  */
+ 
+ rtx
+ simplify_gen_ternary (code, mode, op0_mode, op0, op1, op2)
+      enum rtx_code code;
+      enum machine_mode mode, op0_mode;
+      rtx op0, op1, op2;
+ {
+   rtx tem;
+ 
+   /* If this simplifies, use it.  */
+   if (0 != (tem = simplify_ternary_operation (code, mode, op0_mode,
+ 					      op0, op1, op2)))
+     return tem;
+ 
+   return gen_rtx_fmt_eee (code, mode, op0, op1, op2);
+ }
+ 
+ /* Likewise, for relational operations.  */
+ 
+ rtx
+ simplify_gen_relational (code, mode, op0, op1)
+      enum rtx_code code;
+      enum machine_mode mode;
+      rtx op0, op1;
+ {
+   rtx tem;
+ 
+   if ((tem = simplify_relational_operation (code, mode, op0, op1)) != 0)
+     return tem;
+ 
+   /* Put complex operands first and constants second.  */
+   if ((CONSTANT_P (op0) && GET_CODE (op1) != CONST_INT)
+       || (GET_RTX_CLASS (GET_CODE (op0)) == 'o'
+ 	  && GET_RTX_CLASS (GET_CODE (op1)) != 'o')
+       || (GET_CODE (op0) == SUBREG
+ 	  && GET_RTX_CLASS (GET_CODE (SUBREG_REG (op0))) == 'o'
+ 	  && GET_RTX_CLASS (GET_CODE (op1)) != 'o'))
+     tem = op0, op0 = op1, op1 = tem, code = swap_condition (code);
+ 
+   return gen_rtx_fmt_ee (code, mode, op0, op1);
+ }
+ 
+ /* Replace all occurrences of OLD in X with NEW and try to simplify the
+    resulting RTX.  Return a new RTX which is as simplified as possible.  */
+ 
+ rtx
+ simplify_replace_rtx (x, old, new)
+      rtx x;
+      rtx old;
+      rtx new;
+ {
+   enum rtx_code code = GET_CODE (x);
+   enum machine_mode mode = GET_MODE (x);
+ 
+   /* If X is OLD, return NEW.  Otherwise, if this is an expression, try
+      to build a new expression substituting recursively.  If we can't do
+      anything, return our input.  */
+ 
+   if (x == old)
+     return new;
+ 
+   switch (GET_RTX_CLASS (code))
+     {
+     case '1':
+       {
+ 	enum machine_mode op_mode = GET_MODE (XEXP (x, 0));
+ 	rtx op = (XEXP (x, 0) == old
+ 		  ? new : simplify_replace_rtx (XEXP (x, 0), old, new));
+ 
+ 	return simplify_gen_unary (code, mode, op, op_mode);
+       }
+ 
+     case '2':
+     case 'c':
+       return
+ 	simplify_gen_binary (code, mode,
+ 			     simplify_replace_rtx (XEXP (x, 0), old, new),
+ 			     simplify_replace_rtx (XEXP (x, 1), old, new));
+ 
+     case '3':
+     case 'b':
+       return
+ 	simplify_gen_ternary (code, mode, GET_MODE (XEXP (x, 0)),
+ 			      simplify_replace_rtx (XEXP (x, 0), old, new),
+ 			      simplify_replace_rtx (XEXP (x, 1), old, new),
+ 			      simplify_replace_rtx (XEXP (x, 2), old, new));
+ 
+     case 'x':
+       /* The only case we try to handle is a lowpart SUBREG of a single-word
+ 	 CONST_INT.  */
+       if (code == SUBREG && subreg_lowpart_p (x) && old == SUBREG_REG (x)
+ 	  && GET_CODE (new) == CONST_INT
+ 	  && GET_MODE_SIZE (GET_MODE (old)) <= UNITS_PER_WORD)
+ 	return GEN_INT (INTVAL (new) & GET_MODE_MASK (mode));
+ 
+       return x;
+ 
+     default:
+       return x;
+     }
+ }
+ 
  /* Try to simplify a unary operation CODE whose output mode is to be
     MODE with input operand OP whose mode was originally OP_MODE.
*** rtl.h	2001/02/13 20:17:45	1.241
--- rtl.h	2001/02/13 20:37:33
*************** extern rtx split_insns			PARAMS ((rtx, r
*** 1312,1321 ****
  
  /* In simplify-rtx.c  */
! extern rtx simplify_unary_operation	PARAMS ((enum rtx_code, enum machine_mode, rtx, enum machine_mode));
! extern rtx simplify_binary_operation	PARAMS ((enum rtx_code, enum machine_mode, rtx, rtx));
! extern rtx simplify_ternary_operation	PARAMS ((enum rtx_code, enum machine_mode, enum machine_mode, rtx, rtx, rtx));
! extern rtx simplify_relational_operation PARAMS ((enum rtx_code, enum machine_mode, rtx, rtx));
! extern rtx simplify_gen_binary		PARAMS ((enum rtx_code, enum machine_mode,
! 					       rtx, rtx));
  extern rtx simplify_rtx			PARAMS ((rtx));
  
--- 1312,1342 ----
  
  /* In simplify-rtx.c  */
! extern rtx simplify_unary_operation	PARAMS ((enum rtx_code,
! 						 enum machine_mode, rtx,
! 						 enum machine_mode));
! extern rtx simplify_binary_operation	PARAMS ((enum rtx_code,
! 						 enum machine_mode, rtx,
! 						 rtx));
! extern rtx simplify_ternary_operation	PARAMS ((enum rtx_code,
! 						 enum machine_mode,
! 						 enum machine_mode, rtx, rtx,
! 						 rtx));
! extern rtx simplify_relational_operation PARAMS ((enum rtx_code,
! 						  enum machine_mode, rtx,
! 						  rtx));
! extern rtx simplify_gen_binary		PARAMS ((enum rtx_code,
! 						 enum machine_mode,
! 						 rtx, rtx));
! extern rtx simplify_gen_unary		PARAMS ((enum rtx_code,
! 						 enum machine_mode, rtx,
! 						 enum machine_mode));
! extern rtx simplify_gen_ternary		PARAMS ((enum rtx_code,
! 						 enum machine_mode,
! 						 enum machine_mode,
! 						 rtx, rtx, rtx));
! extern rtx simplify_gen_relational	PARAMS ((enum rtx_code,
! 						 enum machine_mode,
! 						 rtx, rtx));
! extern rtx simplify_replace_rtx		PARAMS ((rtx, rtx, rtx));
  extern rtx simplify_rtx			PARAMS ((rtx));
  
*************** extern rtx find_reg_note		PARAMS ((rtx, 
*** 1389,1392 ****
--- 1410,1414 ----
  extern rtx find_regno_note		PARAMS ((rtx, enum reg_note,
  						 unsigned int));
+ extern rtx find_reg_equal_equiv_note	PARAMS ((rtx));
  extern int find_reg_fusage		PARAMS ((rtx, enum rtx_code, rtx));
  extern int find_regno_fusage		PARAMS ((rtx, enum rtx_code,


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]