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]
Other format: [Raw text]

[PATCH]: cleanup for conversion exprs code patterns (5/16)


 Hi,

 this series of patches is doing small cleanup in using conversion
 expressions code patterns. There is a lot of duplicate code patterns
 for conversion expressions (CONVERT_EXPR, NOP_EXPR, NON_LVALUE_EXPR)
 that can be substituted by macro. Patterns are:
 
 (TREE_CODE (EXP) == NOP_EXPR || TREE_CODE (EXP) == CONVERT_EXPR) 
 -> TEST_CONVERT_NOPS_P(EXP)

 (TREE_CODE (EXP) == NOP_EXPR || TREE_CODE (EXP) == CONVERT_EXPR
  || TREE_CODE (EXP) == NON_LVALUE_EXPR)
 -> TEST_NOPS_P(EXP)

 case NOP_EXPR: case CONVERT_EXPR
 -> CASE_CONVERT_NOPS

 case NOP_EXPR: case CONVERT_EXPR: case NON_LVALUE_EXPR
 -> CASE_NOPS

 while (TREE_CODE (EXP) == NOP_EXPR 
        || TREE_CODE (EXP) == CONVERT_EXPR
        || TREE_CODE (EXP) == NON_LVALUE_EXPR)
    (EXP) = TREE_OPERAND (EXP, 0)
 -> STRIP_NOPS_UNSAFE(EXP)

 -> means replaced by

 Patch 1: Add new macros (TEST_CONVERT_NOPS_P(EXP), TEST_NOPS_P(EXP),
          CASE_CONVERT_NOPS, CASE_NOPS, STRIP_NOPS_UNSAFE(EXP)).
 Patch 2-4: Add support of TEST_CONVERT_NOPS_P.
 Patch 5-8: Add support of TEST_NOPS_P.
 Patch 9-11: Add support of CASE_CONVERT_NOPS.
 Patch 12-13: Add support of CASE_NOPS.
 Patch 14-16: Add support of STRIP_NOPS_UNSAFE.

 Bootstraped and tested on x86_64 x86_64 GNU/Linux.

 Ok?

 Greetings 
 Tomas


 Patch 5

 Changelog:

2008-03-13  Tomas Bily  <tbily@suse.cz>

	* tree-ssa.c (tree_ssa_useless_type_conversion): Use TEST_NOPS_P.

	* varasm.c (initializer_constant_valid_p, output_constant): Likewise.

	* emit-rtl.c (component_ref_for_mem_expr)
	(set_mem_attributes_minus_bitpos): Likewise.

	* gimplify.c (goa_lhs_expr_p): Likewise.

	* c-typeck.c (default_function_array_conversion, c_finish_return):
	Likewise.
	
	* dojump.c (do_jump): Likewise.

	* fold-const.c (decode_field_reference): Likewise.

	* builtins.c (get_memory_rtx, fold_builtin_next_arg): Likewise.

	* tree-vrp.c (register_edge_assert_for_1): Likewise.



Index: gcc/tree-vrp.c
===================================================================
--- gcc/tree-vrp.c	(revision 132974)
+++ gcc/tree-vrp.c	(working copy)
@@ -3679,9 +3679,7 @@ register_edge_assert_for_1 (tree op, enu
       /* Recurse through the copy.  */
       retval |= register_edge_assert_for_1 (rhs, code, e, bsi);
     }
-  else if (TREE_CODE (rhs) == NOP_EXPR
-	   || TREE_CODE (rhs) == CONVERT_EXPR
-	   || TREE_CODE (rhs) == NON_LVALUE_EXPR)
+  else if (TEST_NOPS_P (rhs))
     { 
       /* Recurse through the type conversion.  */
       retval |= register_edge_assert_for_1 (TREE_OPERAND (rhs, 0),
Index: gcc/builtins.c
===================================================================
--- gcc/builtins.c	(revision 132974)
+++ gcc/builtins.c	(working copy)
@@ -1073,8 +1071,7 @@ get_memory_rtx (tree exp, tree len)
   /* Get an expression we can use to find the attributes to assign to MEM.
      If it is an ADDR_EXPR, use the operand.  Otherwise, dereference it if
      we can.  First remove any nops.  */
-  while ((TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
-	  || TREE_CODE (exp) == NON_LVALUE_EXPR)
+  while (TEST_NOPS_P (exp)
 	 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (exp, 0))))
     exp = TREE_OPERAND (exp, 0);
 
@@ -1104,9 +1101,7 @@ get_memory_rtx (tree exp, tree len)
 	  tree inner = exp;
 
 	  while (TREE_CODE (inner) == ARRAY_REF
-		 || TREE_CODE (inner) == NOP_EXPR
-		 || TREE_CODE (inner) == CONVERT_EXPR
-		 || TREE_CODE (inner) == NON_LVALUE_EXPR
+		 || TEST_NOPS_P (inner)
 		 || TREE_CODE (inner) == VIEW_CONVERT_EXPR
 		 || TREE_CODE (inner) == SAVE_EXPR)
 	    inner = TREE_OPERAND (inner, 0);
@@ -11417,9 +11412,7 @@ fold_builtin_next_arg (tree exp, bool va
 	 is not quite the same as STRIP_NOPS.  It does more.
 	 We must also strip off INDIRECT_EXPR for C++ reference
 	 parameters.  */
-      while (TREE_CODE (arg) == NOP_EXPR
-	     || TREE_CODE (arg) == CONVERT_EXPR
-	     || TREE_CODE (arg) == NON_LVALUE_EXPR
+      while (TEST_NOPS_P (arg)
 	     || TREE_CODE (arg) == INDIRECT_REF)
 	arg = TREE_OPERAND (arg, 0);
       if (arg != last_parm)
Index: gcc/fold-const.c
===================================================================
--- gcc/fold-const.c	(revision 132974)
+++ gcc/fold-const.c	(working copy)
@@ -3896,9 +3895,7 @@ decode_field_reference (tree exp, HOST_W
   /* We are interested in the bare arrangement of bits, so strip everything
      that doesn't affect the machine mode.  However, record the type of the
      outermost expression if it may matter below.  */
-  if (TREE_CODE (exp) == NOP_EXPR
-      || TREE_CODE (exp) == CONVERT_EXPR
-      || TREE_CODE (exp) == NON_LVALUE_EXPR)
+  if (TEST_NOPS_P (exp))
     outer_type = TREE_TYPE (exp);
   STRIP_NOPS (exp);
 
Index: gcc/dojump.c
===================================================================
--- gcc/dojump.c	(revision 132974)
+++ gcc/dojump.c	(working copy)
@@ -218,9 +218,7 @@ do_jump (tree exp, rtx if_false_label, r
 	  rtx set_label, clr_label;
 
 	  /* Strip narrowing integral type conversions.  */
-	  while ((TREE_CODE (exp0) == NOP_EXPR
-		  || TREE_CODE (exp0) == CONVERT_EXPR
-		  || TREE_CODE (exp0) == NON_LVALUE_EXPR)
+	  while (TEST_NOPS_P (exp0)
 		 && TREE_OPERAND (exp0, 0) != error_mark_node
 		 && TYPE_PRECISION (TREE_TYPE (exp0))
 		    <= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (exp0, 0))))
Index: gcc/c-typeck.c
===================================================================
--- gcc/c-typeck.c	(revision 132974)
+++ gcc/c-typeck.c	(working copy)
@@ -1656,9 +1656,7 @@ default_function_array_conversion (struc
 	bool not_lvalue = false;
 	bool lvalue_array_p;
 
-	while ((TREE_CODE (exp.value) == NON_LVALUE_EXPR
-		|| TREE_CODE (exp.value) == NOP_EXPR
-		|| TREE_CODE (exp.value) == CONVERT_EXPR)
+	while (TEST_NOPS_P (exp.value)
 	       && TREE_TYPE (TREE_OPERAND (exp.value, 0)) == type)
 	  {
 	    if (TREE_CODE (exp.value) == NON_LVALUE_EXPR)
@@ -7133,9 +7127,7 @@ c_finish_return (tree retval)
 		tree op1 = TREE_OPERAND (inner, 1);
 
 		while (!POINTER_TYPE_P (TREE_TYPE (op1))
-		       && (TREE_CODE (op1) == NOP_EXPR
-			   || TREE_CODE (op1) == NON_LVALUE_EXPR
-			   || TREE_CODE (op1) == CONVERT_EXPR))
+		       && TEST_NOPS_P (op1))
 		  op1 = TREE_OPERAND (op1, 0);
 
 		if (POINTER_TYPE_P (TREE_TYPE (op1)))
Index: gcc/gimplify.c
===================================================================
--- gcc/gimplify.c	(revision 132974)
+++ gcc/gimplify.c	(working copy)
@@ -5442,9 +5441,7 @@ goa_lhs_expr_p (tree expr, tree addr)
   /* Also include casts to other type variants.  The C front end is fond
      of adding these for e.g. volatile variables.  This is like 
      STRIP_TYPE_NOPS but includes the main variant lookup.  */
-  while ((TREE_CODE (expr) == NOP_EXPR
-          || TREE_CODE (expr) == CONVERT_EXPR
-          || TREE_CODE (expr) == NON_LVALUE_EXPR)
+  while (TEST_NOPS_P (expr)
          && TREE_OPERAND (expr, 0) != error_mark_node
          && (TYPE_MAIN_VARIANT (TREE_TYPE (expr))
              == TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (expr, 0)))))
@@ -5454,9 +5451,7 @@ goa_lhs_expr_p (tree expr, tree addr)
     {
       expr = TREE_OPERAND (expr, 0);
       while (expr != addr
-	     && (TREE_CODE (expr) == NOP_EXPR
-		 || TREE_CODE (expr) == CONVERT_EXPR
-		 || TREE_CODE (expr) == NON_LVALUE_EXPR)
+	     && TEST_NOPS_P (expr)
 	     && TREE_CODE (expr) == TREE_CODE (addr)
 	     && TYPE_MAIN_VARIANT (TREE_TYPE (expr))
 		== TYPE_MAIN_VARIANT (TREE_TYPE (addr)))
Index: gcc/emit-rtl.c
===================================================================
--- gcc/emit-rtl.c	(revision 132974)
+++ gcc/emit-rtl.c	(working copy)
@@ -1407,8 +1407,7 @@ component_ref_for_mem_expr (tree ref)
     {
       /* Now remove any conversions: they don't change what the underlying
 	 object is.  Likewise for SAVE_EXPR.  */
-      while (TREE_CODE (inner) == NOP_EXPR || TREE_CODE (inner) == CONVERT_EXPR
-	     || TREE_CODE (inner) == NON_LVALUE_EXPR
+      while (TEST_NOPS_P (inner)
 	     || TREE_CODE (inner) == VIEW_CONVERT_EXPR
 	     || TREE_CODE (inner) == SAVE_EXPR)
 	inner = TREE_OPERAND (inner, 0);
@@ -1538,8 +1537,7 @@ set_mem_attributes_minus_bitpos (rtx ref
 
       /* Now remove any conversions: they don't change what the underlying
 	 object is.  Likewise for SAVE_EXPR.  */
-      while (TREE_CODE (t) == NOP_EXPR || TREE_CODE (t) == CONVERT_EXPR
-	     || TREE_CODE (t) == NON_LVALUE_EXPR
+      while (TEST_NOPS_P (t)
 	     || TREE_CODE (t) == VIEW_CONVERT_EXPR
 	     || TREE_CODE (t) == SAVE_EXPR)
 	t = TREE_OPERAND (t, 0);
Index: gcc/varasm.c
===================================================================
--- gcc/varasm.c	(revision 132974)
+++ gcc/varasm.c	(working copy)
@@ -4211,9 +4200,7 @@ initializer_constant_valid_p (tree value
 	     (int)(p1 - p2) to ((int)p1 - (int)p2) under the theory
 	     that the narrower operation is cheaper.  */
 
-	  while (TREE_CODE (op0) == NOP_EXPR
-		 || TREE_CODE (op0) == CONVERT_EXPR
-		 || TREE_CODE (op0) == NON_LVALUE_EXPR)
+	  while (TEST_NOPS_P (op0))
 	    {
 	      tree inner = TREE_OPERAND (op0, 0);
 	      if (inner == error_mark_node
@@ -4224,9 +4211,7 @@ initializer_constant_valid_p (tree value
 	      op0 = inner;
 	    }
 
-	  while (TREE_CODE (op1) == NOP_EXPR
-		 || TREE_CODE (op1) == CONVERT_EXPR
-		 || TREE_CODE (op1) == NON_LVALUE_EXPR)
+	  while (TEST_NOPS_P (op1))
 	    {
 	      tree inner = TREE_OPERAND (op1, 0);
 	      if (inner == error_mark_node
@@ -4326,8 +4311,7 @@ output_constant (tree exp, unsigned HOST
 
   /* Eliminate any conversions since we'll be outputting the underlying
      constant.  */
-  while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
-	 || TREE_CODE (exp) == NON_LVALUE_EXPR
+  while (TEST_NOPS_P (exp)
 	 || TREE_CODE (exp) == VIEW_CONVERT_EXPR)
     {
       HOST_WIDE_INT type_size = int_size_in_bytes (TREE_TYPE (exp));
Index: gcc/tree-ssa.c
===================================================================
--- gcc/tree-ssa.c	(revision 132974)
+++ gcc/tree-ssa.c	(working copy)
@@ -1227,9 +1227,8 @@ tree_ssa_useless_type_conversion (tree e
      the top of the RHS to the type of the LHS and the type conversion
      is "safe", then strip away the type conversion so that we can
      enter LHS = RHS into the const_and_copies table.  */
-  if (TREE_CODE (expr) == NOP_EXPR || TREE_CODE (expr) == CONVERT_EXPR
-      || TREE_CODE (expr) == VIEW_CONVERT_EXPR
-      || TREE_CODE (expr) == NON_LVALUE_EXPR)
+  if (TEST_NOPS_P (expr)
+      || TREE_CODE (expr) == VIEW_CONVERT_EXPR)
     /* FIXME: Use of GENERIC_TREE_TYPE here is a temporary measure to work
        around known bugs with GIMPLE_MODIFY_STMTs appearing in places
        they shouldn't.  See PR 30391.  */


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