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]

[tuples] patch: Remove pointer magic


This patch removes some pointer magic that was causing problems, and
introduces macros to access gimple_stmt internals.  I've also removed
the prev/next fields from gimple_stmt which I forgot to do in yesterday's
patch.

Committed.

	* tree.c (expr_location): Use GIMPLE_STMT_LOCUS.
	(set_expr_location): Same.
	(expr_locus): Same.
	(set_expr_locus): Same.
	(expr_filename): Same.
	(expr_lineno): Same.
	(tree_block): Use GIMPLE_STMT_BLOCK.
	(protected_tree_operand): Use GIMPLE_STMT_OPERAND.
	* tree.h (struct gimple_stmt): Remove prev and next.
	(GIMPLE_STMT_OPERAND_CHECK): New.
	(TREE_TO_GIMPLE_STMT): Delete.
	(GIMPLE_STMT_TO_TREE): Delete.
	(GIMPLE_STMT_OPERAND): Use union, not cast.
	(GIMPLE_STMT_LOCUS): New.
	(GIMPLE_STMT_BLOCK): New.
	* gimplify.c (tree_to_gimple_tuple): Use union.  Do not cast
	to tree_base.
	* tree-cfg.c (verify_gimple_tuples_1): Call gcc_unreachable.

Index: tree.c
===================================================================
--- tree.c	(revision 117112)
+++ tree.c	(working copy)
@@ -3359,13 +3359,13 @@ location_t
 expr_location (tree node)
 {
 #ifdef USE_MAPPED_LOCATION
-  if (GIMPLE_TUPLE_HAS_LOCUS_P (node))
-    return TREE_TO_GIMPLE_STMT (node)->locus;
+  if (GIMPLE_STMT_P (node))
+    return GIMPLE_STMT_LOCUS (node);
   return EXPR_P (node) ? node->exp.locus : UNKNOWN_LOCATION;
 #else
-  if (GIMPLE_TUPLE_HAS_LOCUS_P (node))
+  if (GIMPLE_STMT_P (node))
     return EXPR_HAS_LOCATION (node)
-      ? *TREE_TO_GIMPLE_STMT (node)->locus : UNKNOWN_LOCATION;
+      ? *GIMPLE_STMT_LOCUS (node) : UNKNOWN_LOCATION;
   return EXPR_HAS_LOCATION (node) ? *node->exp.locus : UNKNOWN_LOCATION;
 #endif
 }
@@ -3374,8 +3374,8 @@ void
 set_expr_location (tree node, location_t locus)
 {
 #ifdef USE_MAPPED_LOCATION
-  if (GIMPLE_TUPLE_HAS_LOCUS_P (node))
-    TREE_TO_GIMPLE_STMT (node)->locus = locus;
+  if (GIMPLE_STMT_P (node))
+    GIMPLE_STMT_LOCUS (node) = locus;
   else
     EXPR_CHECK (node)->exp.locus = locus;
 #else
@@ -3401,12 +3401,12 @@ source_locus
 expr_locus (tree node)
 {
 #ifdef USE_MAPPED_LOCATION
-  if (GIMPLE_TUPLE_HAS_LOCUS_P (node))
-    return &TREE_TO_GIMPLE_STMT (node)->locus;
+  if (GIMPLE_STMT_P (node))
+    return &GIMPLE_STMT_LOCUS (node);
   return EXPR_P (node) ? &node->exp.locus : (location_t *) NULL;
 #else
-  if (GIMPLE_TUPLE_HAS_LOCUS_P (node))
-    return TREE_TO_GIMPLE_STMT (node)->locus;
+  if (GIMPLE_STMT_P (node))
+    return GIMPLE_STMT_LOCUS (node);
   /* ?? The cast below was originally "(location_t *)" in the macro,
      but that makes no sense.  ?? */
   return EXPR_P (node) ? node->exp.locus : (source_locus) NULL;
@@ -3425,21 +3425,21 @@ set_expr_locus (tree node,
 #ifdef USE_MAPPED_LOCATION
   if (loc == NULL)
     {
-      if (GIMPLE_TUPLE_HAS_LOCUS_P (node))
-	TREE_TO_GIMPLE_STMT (node)->locus = UNKNOWN_LOCATION;
+      if (GIMPLE_STMT_P (node))
+	GIMPLE_STMT_LOCUS (node) = UNKNOWN_LOCATION;
       else
 	EXPR_CHECK (node)->exp.locus = UNKNOWN_LOCATION;
     }
   else
     {
-      if (GIMPLE_TUPLE_HAS_LOCUS_P (node))
-	TREE_TO_GIMPLE_STMT (node)->locus = *loc;
+      if (GIMPLE_STMT_P (node))
+	GIMPLE_STMT_LOCUS (node) = *loc;
       else
 	EXPR_CHECK (node)->exp.locus = *loc;
     }
 #else
-  if (GIMPLE_TUPLE_HAS_LOCUS_P (node))
-    TREE_TO_GIMPLE_STMT (node)->locus = loc;
+  if (GIMPLE_STMT_P (node))
+    GIMPLE_STMT_LOCUS (node) = loc;
   else
     EXPR_CHECK (node)->exp.locus = loc;
 #endif
@@ -3449,12 +3449,12 @@ const char **
 expr_filename (tree node)
 {
 #ifdef USE_MAPPED_LOCATION
-  if (GIMPLE_TUPLE_HAS_LOCUS_P (node))
-    return &LOCATION_FILE (TREE_TO_GIMPLE_STMT (node)->locus);
+  if (GIMPLE_STMT_P (node))
+    return &LOCATION_FILE (GIMPLE_STMT_LOCUS (node));
   return &LOCATION_FILE (EXPR_CHECK (node)->exp.locus);
 #else
-  if (GIMPLE_TUPLE_HAS_LOCUS_P (node))
-    return &(TREE_TO_GIMPLE_STMT (node)->locus->file);
+  if (GIMPLE_STMT_P (node))
+    return &GIMPLE_STMT_LOCUS (node)->file;
   return &(EXPR_CHECK (node)->exp.locus->file);
 #endif
 }
@@ -3463,12 +3463,12 @@ int *
 expr_lineno (tree node)
 {
 #ifdef USE_MAPPED_LOCATION
-  if (GIMPLE_TUPLE_HAS_LOCUS_P (node))
-    return &LOCATION_LINE (TREE_TO_GIMPLE_STMT (node)->locus);
+  if (GIMPLE_STMT_P (node))
+    return &LOCATION_LINE (GIMPLE_STMT_LOCUS (node));
   return &LOCATION_LINE (EXPR_CHECK (node)->exp.locus);
 #else
-  if (GIMPLE_TUPLE_HAS_LOCUS_P (node))
-    return &TREE_TO_GIMPLE_STMT (node)->locus->line;
+  if (GIMPLE_STMT_P (node))
+    return &GIMPLE_STMT_LOCUS (node)->line;
   return &EXPR_CHECK (node)->exp.locus->line;
 #endif
 }
@@ -7932,7 +7932,7 @@ tree_block (tree t)
   if (IS_EXPR_CODE_CLASS (c))
     return &t->exp.block;
   else if (IS_GIMPLE_STMT_CODE_CLASS (c))
-    return &TREE_TO_GIMPLE_STMT (t)->block;
+    return &GIMPLE_STMT_BLOCK (t);
   gcc_unreachable ();
   return NULL;
 }
@@ -7941,7 +7941,7 @@ tree *
 protected_tree_operand (tree node, int i)
 {
   if (GIMPLE_STMT_P (node))
-    return (tree *)(&TREE_TO_GIMPLE_STMT (node)->operands[i]);
+    return &GIMPLE_STMT_OPERAND (node, i);
   return &TREE_OPERAND (node, i);
 }
 
Index: tree.h
===================================================================
--- tree.h	(revision 117112)
+++ tree.h	(working copy)
@@ -401,8 +401,6 @@ struct gimple_stmt GTY(())
   struct tree_base base;
   source_locus locus;
   tree block;
-  struct gimple_stmt *prev;
-  struct gimple_stmt *next;
   /* FIXME tuples: Eventually this should be of type ``struct gimple_expr''.  */
   tree GTY ((length ("TREE_CODE_LENGTH (TREE_CODE (&%h))"))) operands[1];
 };
@@ -797,6 +795,15 @@ enum tree_node_structure_enum {
 				 __FILE__, __LINE__, __FUNCTION__);	\
     &__t->exp.operands[__i]; }))
 
+/* Special checks for GIMPLE_STMT_OPERANDs.  */
+#define GIMPLE_STMT_OPERAND_CHECK(T, I) __extension__			\
+(*({const tree __t = GIMPLE_STMT_CHECK (T);				\
+    const int __i = (I);						\
+    if (__i < 0 || __i >= TREE_CODE_LENGTH (TREE_CODE (__t)))		\
+      tree_operand_check_failed (__i, TREE_CODE (__t),			\
+				 __FILE__, __LINE__, __FUNCTION__);	\
+    &__t->gstmt.operands[__i]; }))
+
 #define TREE_RTL_OPERAND_CHECK(T, CODE, I) __extension__		\
 (*(rtx *)								\
  ({const tree __t = (T);						\
@@ -868,6 +875,7 @@ extern void omp_clause_range_check_faile
 #define TREE_VEC_ELT_CHECK(T, I)		((T)->vec.a[I])
 #define TREE_OPERAND_CHECK(T, I)		((T)->exp.operands[I])
 #define TREE_OPERAND_CHECK_CODE(T, CODE, I)	((T)->exp.operands[I])
+#define GIMPLE_STMT_OPERAND_CHECK(T, I)		((T)->gstmt.operands[I])
 #define TREE_RTL_OPERAND_CHECK(T, CODE, I)  (*(rtx *) &((T)->exp.operands[I]))
 #define PHI_NODE_ELT_CHECK(T, i)	((T)->phi.a[i])
 #define OMP_CLAUSE_ELT_CHECK(T, i)	        ((T)->omp_clause.ops[i])
@@ -907,16 +915,6 @@ extern void omp_clause_range_check_faile
 /* Nonzero if NODE is a GIMPLE tuple.  */
 #define GIMPLE_TUPLE_P(NODE) (GIMPLE_STMT_P (NODE))
 
-/* Convert a TREE into a GIMPLE_STMT.  */
-#define TREE_TO_GIMPLE_STMT(T) ((struct gimple_stmt *)(GIMPLE_STMT_CHECK (T)))
-
-/* Convert a GIMPLE_STMT into a TREE.  */
-#define GIMPLE_STMT_TO_TREE(T) ((tree)(T))
-
-/* Given a TREE, return its operand number I.  */
-#define GIMPLE_STMT_OPERAND(T, I) \
-  (*((tree *)(&TREE_TO_GIMPLE_STMT (T)->operands[(I)])))
-
 /* A GIMPLE tuple that has a ``locus'' field.  */
 #define GIMPLE_TUPLE_HAS_LOCUS_P(NODE) GIMPLE_STMT_P ((NODE))
 
@@ -1503,6 +1501,11 @@ struct tree_constructor GTY(())
 #define TREE_OPERAND(NODE, I) TREE_OPERAND_CHECK (NODE, I)
 #define TREE_COMPLEXITY(NODE) (EXPR_CHECK (NODE)->exp.complexity)
 
+/* In gimple statements.  */
+#define GIMPLE_STMT_OPERAND(NODE, I) GIMPLE_STMT_OPERAND_CHECK (NODE, I)
+#define GIMPLE_STMT_LOCUS(NODE) (GIMPLE_STMT_CHECK (NODE)->gstmt.locus)
+#define GIMPLE_STMT_BLOCK(NODE) (GIMPLE_STMT_CHECK (NODE)->gstmt.block)
+
 /* In a LOOP_EXPR node.  */
 #define LOOP_EXPR_BODY(NODE) TREE_OPERAND_CHECK_CODE (NODE, LOOP_EXPR, 0)
 
Index: gimplify.c
===================================================================
--- gimplify.c	(revision 117112)
+++ gimplify.c	(working copy)
@@ -3520,14 +3520,14 @@ tree_to_gimple_tuple (tree *tp)
 	      debug_tree (*tp);
 	  }
 
-        gs = TREE_TO_GIMPLE_STMT (make_node (GIMPLE_MODIFY_STMT));
+        gs = &make_node (GIMPLE_MODIFY_STMT)->gstmt;
         gs->base = (*tp)->base;
         /* The set to base above overwrites the CODE.  */
         TREE_SET_CODE ((tree) gs, GIMPLE_MODIFY_STMT);
 
         gs->locus = EXPR_LOCUS (*tp);
-        gs->operands[0] = (struct tree_base *) TREE_OPERAND (*tp, 0);
-        gs->operands[1] = (struct tree_base *) TREE_OPERAND (*tp, 1);
+        gs->operands[0] = TREE_OPERAND (*tp, 0);
+        gs->operands[1] = TREE_OPERAND (*tp, 1);
         gs->block = save_tree_block;
         *tp = (tree)gs;
 
Index: tree-cfg.c
===================================================================
--- tree-cfg.c	(revision 116725)
+++ tree-cfg.c	(working copy)
@@ -3563,7 +3563,8 @@ verify_gimple_tuples_1 (tree *tp, int *w
     case MODIFY_EXPR:
       error ("unexpected non-tuple");
       debug_tree (*tp);
-      return true;
+      gcc_unreachable ();
+      return NULL_TREE;
 
     default:
       return NULL_TREE;


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