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] Reorganize the conversion stripping macros


This is my patch to address Jakub's concerns from here:

  http://gcc.gnu.org/ml/gcc-patches/2009-06/msg00885.html

As I said in my response STRIP_USELESS_TYPE_CONVERSION suffers from the same
problem so I'd like to propose this incremental patch on top of my previous
patch to change all three macros.

I didn't remove the macros themselves mainly not to create problems for the
branches before the big merges; I can of course do that if people feel
strongly about it.

Bootstrapped and regtested on x86_64-linux.

OK to install after the previous patch is in?

Adam


	* tree.h (STRIP_NOPS, STRIP_SIGN_NOPS,
	STRIP_USELESS_TYPE_CONVERSION): Use tree_strip_nop_conversions,
	tree_strip_sign_nop_conversions and
	tree_ssa_strip_useless_type_conversions rather than stripping
	the operations here.
	(tree_nop_conversion, tree_sign_nop_conversion): Remove
	declarations.
	(tree_strip_nop_conversions, tree_strip_sign_nop_conversions):
	Declare them.
	* gimple.h (tree_ssa_strip_useless_type_conversions): Declare it.
	* tree-ssa.c (tree_ssa_strip_useless_type_conversions): New function.
	* tree.c (tree_strip_nop_conversions,
	tree_strip_sign_nop_conversions): New functions.
	(tree_nop_conversion): Make it static and inline.
	(tree_sign_nop_conversion): Make it static.

Index: gcc/tree.h
===================================================================
--- gcc.orig/tree.h	2009-06-11 10:35:57.000000000 -0700
+++ gcc/tree.h	2009-06-11 16:31:14.000000000 -0700
@@ -964,18 +964,17 @@ extern void omp_clause_range_check_faile
   case NOP_EXPR:						\
   case CONVERT_EXPR
 
-/* Given an expression as a tree, strip any conversion that generates no
-   instruction.  */
+/* Given an expression as a tree, strip any conversion that generates
+   no instruction.  Accepts both tree and const_tree arguments since
+   we are not modifying the tree itself.  */
 
-#define STRIP_NOPS(EXP)				\
-  while (tree_nop_conversion (EXP))		\
-    (EXP) = TREE_OPERAND (EXP, 0)
+#define STRIP_NOPS(EXP) \
+  (EXP) = tree_strip_nop_conversions (CONST_CAST_TREE (EXP))
 
 /* Like STRIP_NOPS, but don't let the signedness change either.  */
 
-#define STRIP_SIGN_NOPS(EXP)			 \
-  while (tree_sign_nop_conversion (EXP))	 \
-    (EXP) = TREE_OPERAND (EXP, 0)
+#define STRIP_SIGN_NOPS(EXP) \
+  (EXP) = tree_strip_sign_nop_conversions (CONST_CAST_TREE (EXP))
 
 /* Like STRIP_NOPS, but don't alter the TREE_TYPE either.  */
 
@@ -990,9 +989,8 @@ extern void omp_clause_range_check_faile
 /* Remove unnecessary type conversions according to
    tree_ssa_useless_type_conversion.  */
 
-#define STRIP_USELESS_TYPE_CONVERSION(EXP)				\
-      while (tree_ssa_useless_type_conversion (EXP))			\
-	EXP = TREE_OPERAND (EXP, 0)
+#define STRIP_USELESS_TYPE_CONVERSION(EXP) \
+  (EXP) = tree_ssa_strip_useless_type_conversions (EXP)
 
 /* Nonzero if TYPE represents an integral type.  Note that we do not
    include COMPLEX types here.  Keep these checks in ascending code
@@ -4616,8 +4614,8 @@ extern bool stdarg_p (tree);
 extern bool prototype_p (tree);
 extern bool auto_var_in_fn_p (const_tree, const_tree);
 extern tree build_low_bits_mask (tree, unsigned);
-extern bool tree_nop_conversion (const_tree);
-extern bool tree_sign_nop_conversion (const_tree);
+extern tree tree_strip_nop_conversions (tree);
+extern tree tree_strip_sign_nop_conversions (tree);
 
 /* In cgraph.c */
 extern void change_decl_assembler_name (tree, tree);
Index: gcc/gimple.h
===================================================================
--- gcc.orig/gimple.h	2009-06-11 10:41:34.000000000 -0700
+++ gcc/gimple.h	2009-06-11 16:15:58.000000000 -0700
@@ -997,6 +997,7 @@ extern bool validate_gimple_arglist (con
 
 /* In tree-ssa.c  */
 extern bool tree_ssa_useless_type_conversion (tree);
+extern tree tree_ssa_strip_useless_type_conversions (tree);
 extern bool useless_type_conversion_p (tree, tree);
 extern bool types_compatible_p (tree, tree);
 
Index: gcc/tree-ssa.c
===================================================================
--- gcc.orig/tree-ssa.c	2009-06-11 10:40:36.000000000 -0700
+++ gcc/tree-ssa.c	2009-06-11 16:20:58.000000000 -0700
@@ -1079,6 +1079,18 @@ tree_ssa_useless_type_conversion (tree e
   return false;
 }
 
+/* Strip conversions from EXP according to
+   tree_ssa_useless_type_conversion and return the resulting
+   expression.  */
+
+tree
+tree_ssa_strip_useless_type_conversions (tree exp)
+{
+  while (tree_ssa_useless_type_conversion (exp))
+    exp = TREE_OPERAND (exp, 0);
+  return exp;
+}
+
 
 /* Internal helper for walk_use_def_chains.  VAR, FN and DATA are as
    described in walk_use_def_chains.
Index: gcc/tree.c
===================================================================
--- gcc.orig/tree.c	2009-06-11 10:35:57.000000000 -0700
+++ gcc/tree.c	2009-06-11 17:00:48.000000000 -0700
@@ -9437,9 +9437,11 @@ list_equal_p (const_tree t1, const_tree 
   return !t1 && !t2;
 }
 
-/* Return true iff conversion in EXP generates no instruction.  */
+/* Return true iff conversion in EXP generates no instruction.  Mark
+   it inline so that we fully inline into the stripping functions even
+   though we have two uses of this function.  */
 
-bool
+static inline bool
 tree_nop_conversion (const_tree exp)
 {
   tree outer_type, inner_type;
@@ -9497,7 +9499,7 @@ tree_nop_conversion (const_tree exp)
 /* Return true iff conversion in EXP generates no instruction.  Don't
    consider conversions changing the signedness.  */
 
-bool
+static bool
 tree_sign_nop_conversion (const_tree exp)
 {
   tree outer_type, inner_type;
@@ -9512,5 +9514,27 @@ tree_sign_nop_conversion (const_tree exp
 	  && POINTER_TYPE_P (outer_type) == POINTER_TYPE_P (inner_type));
 }
 
+/* Strip conversions from EXP according to tree_nop_conversion and
+   return the resulting expression.  */
+
+tree
+tree_strip_nop_conversions (tree exp)
+{
+  while (tree_nop_conversion (exp))
+    exp = TREE_OPERAND (exp, 0);
+  return exp;
+}
+
+/* Strip conversions from EXP according to tree_sign_nop_conversion
+   and return the resulting expression.  */
+
+tree
+tree_strip_sign_nop_conversions (tree exp)
+{
+  while (tree_sign_nop_conversion (exp))
+    exp = TREE_OPERAND (exp, 0);
+  return exp;
+}
+
 
 #include "gt-tree.h"


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