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] New accessors and pretty printer improvements


This patch adds a few accessors for gimple_flags().  Since this field
is used with different meanings for different GIMPLE codes, it's
cleaner if we provide wrappers instead of having each caller cast the
call to gimple_flags() to the type they're expecting.

So, given a GIMPLE_ASSIGN, instead of calling gimple_flags() and type
casting the flag into an enum tree_code, we call
gimple_assign_rhs_code() which does that and checks that it's being
used on a GIMPLE_ASSIGN.

The patch also improves the pretty printing of unary RHS for GIMPLE_ASSIGN.
2007-08-30  Diego Novillo  <dnovillo@google.com>

	* gimple-low.c (gimple_try_catch_may_fallthru): Call
	gimple_code instead of gimple_flags.
	* gimple.c (set_gimple_body): Use gimple_seq instead of gimple
	when accessing vector gimple_bodies_vec.
	(gimple_body): Likewise.
	(gimple_assign_copy_p): New.
	* gimple.h (enum gimple_try_kind): New.
	(GIMPLE_TRY_CATCH): Move inside enum gimple_try_kind.
	(GIMPLE_TRY_FINALLY): Likewise.
	(gimple_assign_copy_p): Declare.
	(gimple_assign_rhs_code): New.
	Update callers that used to call gimple_flags.
	(gimple_cond_code): New.
	Update callers that used to call gimple_flags.
	(gimple_try_kind): New.
	(gimple_nop_p): Tidy comment.
	* gimple-pretty-print.c (dump_unary_rhs): New.
	(dump_gimple_assign): Call it.


Index: gimple-low.c
===================================================================
--- gimple-low.c	(revision 127911)
+++ gimple-low.c	(working copy)
@@ -458,7 +458,7 @@ gimple_try_catch_may_fallthru (gimple st
     return true;
 
   i = gsi_start (gimple_try_cleanup (stmt));
-  switch (gimple_flags (gsi_stmt (i)))
+  switch (gimple_code (gsi_stmt (i)))
     {
     case GIMPLE_CATCH:
       /* We expect to see a sequence of GIMPLE_CATCH stmts, each with a
Index: gimple.c
===================================================================
--- gimple.c	(revision 127911)
+++ gimple.c	(working copy)
@@ -1082,14 +1082,14 @@ set_gimple_body (tree fn, gimple_seq seq
   slot = pointer_map_insert (gimple_bodies_map, fn);
   if (*slot == NULL)
     {
-      VEC_safe_push (gimple, gc, gimple_bodies_vec, seq);
-      index = VEC_length (gimple, gimple_bodies_vec) - 1;
+      VEC_safe_push (gimple_seq, gc, gimple_bodies_vec, seq);
+      index = VEC_length (gimple_seq, gimple_bodies_vec) - 1;
       *slot = (void *) index;
     }
   else
     {
       index = (size_t) *slot;
-      VEC_replace (gimple, gimple_bodies_vec, index, seq);
+      VEC_replace (gimple_seq, gimple_bodies_vec, index, seq);
     }
 }
   
@@ -1105,7 +1105,7 @@ gimple_body (tree fn)
       && (slot = pointer_map_contains (gimple_bodies_map, fn)))
     {
       size_t ix = (size_t) *slot;
-      return VEC_index (gimple, gimple_bodies_vec, ix);
+      return VEC_index (gimple_seq, gimple_bodies_vec, ix);
     }
   
   return NULL;
@@ -1137,4 +1137,14 @@ gimple_call_flags (gimple stmt)
   return flags;
 }
 
+/* Return true if GS is a copy assignment.  */
+
+bool
+gimple_assign_copy_p (gimple gs)
+{
+  return (gimple_code (gs) == GIMPLE_ASSIGN
+          && gimple_num_ops (gs) == 2
+	  && is_gimple_val (gimple_op (gs, 1)));
+}
+
 #include "gt-gimple.h"
Index: gimple.h
===================================================================
--- gimple.h	(revision 127911)
+++ gimple.h	(working copy)
@@ -209,9 +209,11 @@ struct gimple_statement_try GTY(())
   struct gimple_sequence cleanup;
 };
 
-/* Flags stored in GIMPLE_TRY's subcode flags.  */
-#define GIMPLE_TRY_CATCH 1 << 0
-#define GIMPLE_TRY_FINALLY 1 << 1
+/* Kind of GIMPLE_TRY statements.  Either try/catch or try/finally.  */
+enum gimple_try_kind {
+  GIMPLE_TRY_CATCH = 1,
+  GIMPLE_TRY_FINALLY = 2
+};
 
 
 /* GIMPLE_ASM */
@@ -622,6 +624,7 @@ void set_gimple_body (tree, gimple_seq);
 gimple_seq gimple_body (tree);
 void gimple_seq_append (gimple_seq, gimple_seq);
 int gimple_call_flags (gimple);
+bool gimple_assign_copy_p (gimple);
 
 extern const char *const gimple_code_name[];
 
@@ -704,6 +707,13 @@ gimple_set_op (gimple gs, size_t i, tree
 
 /* GIMPLE_ASSIGN accessors.  */
 
+static inline enum tree_code
+gimple_assign_rhs_code (gimple gs)
+{
+  GIMPLE_CHECK (gs, GIMPLE_ASSIGN);
+  return (enum tree_code) gimple_flags (gs);
+}
+
 static inline tree
 gimple_assign_operand (gimple gs, size_t opno)
 {
@@ -866,6 +876,13 @@ gimple_call_set_arg (gimple gs, size_t i
 
 /* GIMPLE_COND accessors. */
 
+static inline enum tree_code
+gimple_cond_code (gimple gs)
+{
+  GIMPLE_CHECK (gs, GIMPLE_COND);
+  return (enum tree_code) gimple_flags (gs);
+}
+
 static inline tree
 gimple_cond_lhs (gimple gs)
 {
@@ -1171,6 +1188,13 @@ gimple_eh_filter_set_failure (gimple gs,
 
 /* GIMPLE_TRY accessors. */
 
+static inline enum gimple_try_kind
+gimple_try_kind (gimple gs)
+{
+  GIMPLE_CHECK (gs, GIMPLE_TRY);
+  return (enum gimple_try_kind) gimple_flags (gs);
+}
+
 static inline gimple_seq
 gimple_try_eval (gimple gs)
 {
Index: gimple-pretty-print.c
===================================================================
--- gimple-pretty-print.c	(revision 127911)
+++ gimple-pretty-print.c	(working copy)
@@ -139,13 +139,69 @@ debug_gimple_seq (gimple_seq seq)
 }
 
 
+/* Helper for dump_gimple_assign.  Print the unary RHS of the
+   assignment GS.  BUFFER, SPC and FLAGS are as in dump_gimple_stmt.  */
+
+static void
+dump_unary_rhs (pretty_printer *buffer, gimple gs, int spc, int flags)
+{
+  enum tree_code rhs_code = gimple_assign_rhs_code (gs);
+  tree lhs = gimple_assign_lhs (gs);
+  tree rhs = gimple_assign_rhs1 (gs);
+
+  switch (rhs_code)
+    {
+    case FIXED_CONVERT_EXPR:
+    case FIX_TRUNC_EXPR:
+    case FLOAT_EXPR:
+    case CONVERT_EXPR:
+      pp_string (buffer, tree_code_name [rhs_code]);
+      pp_string (buffer, " <");
+      dump_generic_node (buffer, TREE_TYPE (lhs), spc, flags, false);
+      pp_string (buffer, ", ");
+      dump_generic_node (buffer, rhs, spc, flags, false);
+      pp_string (buffer, ">");
+      break;
+
+    case NOP_EXPR:
+      pp_string (buffer, "(");
+      dump_generic_node (buffer, TREE_TYPE (lhs), spc, flags, false);
+      pp_string (buffer, ") ");
+      dump_generic_node (buffer, rhs, spc, flags, false);
+      break;
+
+    default:
+      if (TREE_CODE_CLASS (rhs_code) == tcc_declaration
+	  || TREE_CODE_CLASS (rhs_code) == tcc_constant
+	  || TREE_CODE_CLASS (rhs_code) == tcc_reference
+	  || rhs_code == SSA_NAME)
+	; /* do nothing.  */
+      else if (rhs_code == ADDR_EXPR)
+	pp_string (buffer, "&");
+      else if (rhs_code == BIT_NOT_EXPR)
+	pp_string (buffer, "~");
+      else if (rhs_code == TRUTH_NOT_EXPR)
+	pp_string (buffer, "!");
+      else
+	{
+	  pp_string (buffer, "[");
+	  pp_string (buffer, tree_code_name [rhs_code]);
+	  pp_string (buffer, "] ");
+	}
+
+      dump_generic_node (buffer, rhs, spc, flags, false);
+      break;
+    }
+}
+
+
 /* Helper for dump_gimple_assign.  Print the binary RHS of the
    assignment GS.  BUFFER, SPC and FLAGS are as in dump_gimple_stmt.  */
 
 static void
 dump_binary_rhs (pretty_printer *buffer, gimple gs, int spc, int flags)
 {
-  switch (gimple_flags (gs))
+  switch (gimple_assign_rhs_code (gs))
     {
     case COMPLEX_EXPR:
       pp_string (buffer, "COMPLEX_EXPR <");
@@ -158,7 +214,7 @@ dump_binary_rhs (pretty_printer *buffer,
     default:
       dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
       pp_space (buffer);
-      pp_string (buffer, op_symbol_code (gimple_flags (gs)));
+      pp_string (buffer, op_symbol_code (gimple_assign_rhs_code (gs)));
       pp_space (buffer);
       dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
     }
@@ -177,7 +233,7 @@ dump_gimple_assign (pretty_printer *buff
   pp_space (buffer);
 
   if (gimple_num_ops (gs) == 2)
-    dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
+    dump_unary_rhs (buffer, gs, spc, flags);
   else if (gimple_num_ops (gs) == 3)
     dump_binary_rhs (buffer, gs, spc, flags);
   else
@@ -285,7 +341,7 @@ dump_gimple_cond (pretty_printer *buffer
   pp_string (buffer, "if (");
   dump_generic_node (buffer, gimple_cond_lhs (gs), spc, flags, false);
   pp_space (buffer);
-  pp_string (buffer, op_gimple_cond (gimple_flags (gs)));
+  pp_string (buffer, op_gimple_cond (gimple_cond_code (gs)));
   pp_space (buffer);
   dump_generic_node (buffer, gimple_cond_rhs (gs), spc, flags, false);
   pp_character (buffer, ')');
@@ -371,10 +427,12 @@ dump_gimple_try (pretty_printer *buffer,
   newline_and_indent (buffer, spc + 2);
   dump_gimple_seq (buffer, gimple_try_eval (gs), spc + 2, flags);
   newline_and_indent (buffer, spc);
-  if (gimple_flags (gs) == GIMPLE_TRY_CATCH)
+  if (gimple_try_kind (gs) == GIMPLE_TRY_CATCH)
     pp_string (buffer, "} catch {");
-  else
+  else if (gimple_try_kind (gs) == GIMPLE_TRY_FINALLY)
     pp_string (buffer, "} finally {");
+  else
+    pp_string (buffer, "} <UNKNOWN GIMPLE_TRY> {");
   newline_and_indent (buffer, spc + 2);
   dump_gimple_seq (buffer, gimple_try_cleanup (gs), spc + 2, flags);
   newline_and_indent (buffer, spc);

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