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

Tomas Bily tomby@atrey.karlin.mff.cuni.cz
Mon Mar 31 14:50:00 GMT 2008


 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 1

 Changelog:

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

	* tree.h (TEST_CONVERT_NOPS_P): Define.
	(TEST_NOPS_P): Likewise.
	(CASE_CONVERT_NOPS): Likewise.
	(CASE_NOPS): Likewise.
	(STRIP_NOPS_UNSAFE): Likewise.
	(STRIP_NOPS): Use TEST_NOPS_P.
	(STRIP_SIGN_NOPS): Likewise.
	(STRIP_TYPE_NOPS): Likewise.


Index: gcc/tree.h
===================================================================
--- gcc/tree.h	(revision 132974)
+++ gcc/tree.h	(working copy)
@@ -1000,13 +1000,41 @@ extern void omp_clause_range_check_faile
   (TREE_CODE (NODE) == PHI_NODE ? PHI_CHAIN (NODE) :		\
      GIMPLE_STMT_P (NODE) ? NULL_TREE : TREE_CHAIN (NODE))
 
+/* Tests if expression is conversion nop (NOP_EXPRs or CONVERT_EXPRs) */
+
+#define TEST_CONVERT_NOPS_P(EXP)				\
+  (TREE_CODE (EXP) == NOP_EXPR					\
+   || TREE_CODE (EXP) == CONVERT_EXPR)
+
+/* Tests if expression is a nop (NOP_EXPRs, CONVERT_EXPRs or NON_LVALUE_EXPRs) */
+
+#define TEST_NOPS_P(EXP)					\
+  (TEST_CONVERT_NOPS_P(EXP)					\
+   || TREE_CODE (EXP) == NON_LVALUE_EXPR)
+
+/* Generate case for NOP_EXPR and CONVERT_EXPR */
+
+#define CASE_CONVERT_NOPS					\
+  case NOP_EXPR:						\
+  case CONVERT_EXPR
+
+/* Generate case fot NOP_EXPR, CONVERT_EXPR and NON_LVALUE_EXPR */
+
+#define CASE_NOPS						\
+  CASE_CONVERT_NOPS:						\
+  case NON_LVALUE_EXPR
+
+/* Given an expression as a tree, strip any NON_LVALUE_EXPRs and NOP_EXPRs. */
+
+#define STRIP_NOPS_UNSAFE(EXP)					\
+  while (TEST_NOPS_P (EXP))					\
+    (EXP) = TREE_OPERAND (EXP, 0)
+
 /* Given an expression as a tree, strip any NON_LVALUE_EXPRs and NOP_EXPRs
    that don't change the machine mode.  */
 
 #define STRIP_NOPS(EXP)						\
-  while ((TREE_CODE (EXP) == NOP_EXPR				\
-	  || TREE_CODE (EXP) == CONVERT_EXPR			\
-	  || TREE_CODE (EXP) == NON_LVALUE_EXPR)		\
+  while (TEST_NOPS_P (EXP)					\
 	 && TREE_OPERAND (EXP, 0) != error_mark_node		\
 	 && (TYPE_MODE (TREE_TYPE (EXP))			\
 	     == TYPE_MODE (GENERIC_TREE_TYPE (TREE_OPERAND (EXP, 0))))) \
@@ -1014,10 +1042,8 @@ extern void omp_clause_range_check_faile
 
 /* Like STRIP_NOPS, but don't let the signedness change either.  */
 
-#define STRIP_SIGN_NOPS(EXP) \
-  while ((TREE_CODE (EXP) == NOP_EXPR				\
-	  || TREE_CODE (EXP) == CONVERT_EXPR			\
-	  || TREE_CODE (EXP) == NON_LVALUE_EXPR)		\
+#define STRIP_SIGN_NOPS(EXP)					\
+  while (TEST_NOPS_P (EXP)					\
 	 && TREE_OPERAND (EXP, 0) != error_mark_node		\
 	 && (TYPE_MODE (TREE_TYPE (EXP))			\
 	     == TYPE_MODE (TREE_TYPE (TREE_OPERAND (EXP, 0))))	\
@@ -1029,10 +1055,8 @@ extern void omp_clause_range_check_faile
 
 /* Like STRIP_NOPS, but don't alter the TREE_TYPE either.  */
 
-#define STRIP_TYPE_NOPS(EXP) \
-  while ((TREE_CODE (EXP) == NOP_EXPR				\
-	  || TREE_CODE (EXP) == CONVERT_EXPR			\
-	  || TREE_CODE (EXP) == NON_LVALUE_EXPR)		\
+#define STRIP_TYPE_NOPS(EXP)					\
+  while (TEST_NOPS_P (EXP)					\
 	 && TREE_OPERAND (EXP, 0) != error_mark_node		\
 	 && (TREE_TYPE (EXP)					\
 	     == TREE_TYPE (TREE_OPERAND (EXP, 0))))		\



More information about the Gcc-patches mailing list