diff mbox

[cli] Add dump functions for CLI passes

Message ID 4C1B20A8.9070105@inria.fr
State New
Headers show

Commit Message

Erven Rohou June 18, 2010, 7:30 a.m. UTC
I just added dump functions for the CLI passes.

--
Erven.


2010-06-18  Erven Rohou <erven.rohou@inria.fr>

	* tree-pass.h: Add CIL property.
	* passes.c: Map CIL property to dump function.
	* config/cil32/cil-dump.c: Dump functions dump to FILE*.
	* config/cil32/gimple-to-cil.c: Provides property CIL.
	* config/cil32/missing-protos.c: Requires CIL property.
	* config/cil32/peephole.c: Likewise.
	* config/cil32/remove-temps.c: Likewise.
	* config/cil32/remove-convs.c: Likewise.
	* config/cil32/simp-cond.c: Likewise.
	* config/cil32/cil-lower.c: Likewise.
	* config/cil32/emit-cil.c: Likewise.
	* config/cil32/cil32.h: Declare dump functions.
diff mbox

Patch

Index: tree-pass.h
===================================================================
--- tree-pass.h	(revision 160959)
+++ tree-pass.h	(working copy)
@@ -210,6 +210,7 @@ 
  #define PROP_rtl		(1 << 7)
  #define PROP_alias		(1 << 8)
  #define PROP_gimple_lomp	(1 << 9)	/* lowered OpenMP directives */
+#define PROP_cil	        (1 << 10)	/* Common Intermediate Language 
representation */

  #define PROP_trees \
    (PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh | PROP_gimple_lomp)
Index: passes.c
===================================================================
--- passes.c	(revision 160959)
+++ passes.c	(working copy)
@@ -971,7 +971,9 @@ 

    if ((flags & TODO_dump_func) && dump_file && current_function_decl)
      {
-      if (cfun->curr_properties & PROP_trees)
+      if (cfun->curr_properties & PROP_cil)
+        dump_cil_function_to_file (current_function_decl, dump_file, dump_flags);
+      else if (cfun->curr_properties & PROP_trees)
          dump_function_to_file (current_function_decl, dump_file, dump_flags);
        else
  	{
Index: config/cil32/peephole.c
===================================================================
--- config/cil32/peephole.c	(revision 160959)
+++ config/cil32/peephole.c	(working copy)
@@ -137,11 +137,11 @@ 
    NULL,                                 /* next */
    0,                                    /* static_pass_number */
    TV_CIL_PEEPHOLE,                      /* tv_id */
-  PROP_cfg,                             /* properties_required */
+  PROP_cfg|PROP_cil,                    /* properties_required */
    0,                                    /* properties_provided */
    0,                                    /* properties_destroyed */
    0,                                    /* todo_flags_start */
-  TODO_ggc_collect                      /* todo_flags_finish */
+  TODO_ggc_collect|TODO_dump_func       /* todo_flags_finish */
   }
  };

Index: config/cil32/gimple-to-cil.c
===================================================================
--- config/cil32/gimple-to-cil.c	(revision 160959)
+++ config/cil32/gimple-to-cil.c	(working copy)
@@ -4561,10 +4561,10 @@ 
    0,                                    /* static_pass_number */
    TV_GIMPLE_TO_CIL,                     /* tv_id */
    PROP_cfg,                             /* properties_required */
-  0,                                    /* properties_provided */
+  PROP_cil,                             /* properties_provided */
    0,                                    /* properties_destroyed */
    0,                                    /* todo_flags_start */
-  TODO_ggc_collect                      /* todo_flags_finish */
+  TODO_ggc_collect|TODO_dump_func       /* todo_flags_finish */
   }
  };

Index: config/cil32/remove-temps.c
===================================================================
--- config/cil32/remove-temps.c	(revision 160959)
+++ config/cil32/remove-temps.c	(working copy)
@@ -825,11 +825,11 @@ 
    NULL,                                 /* next */
    0,                                    /* static_pass_number */
    TV_REMOVE_TEMPS,                      /* tv_id */
-  PROP_cfg,                             /* properties_required */
+  PROP_cfg|PROP_cil,                    /* properties_required */
    0,                                    /* properties_provided */
    0,                                    /* properties_destroyed */
    0,                                    /* todo_flags_start */
-  TODO_ggc_collect                      /* todo_flags_finish */
+  TODO_ggc_collect|TODO_dump_func       /* todo_flags_finish */
   }
  };

Index: config/cil32/remove-convs.c
===================================================================
--- config/cil32/remove-convs.c	(revision 160959)
+++ config/cil32/remove-convs.c	(working copy)
@@ -320,11 +320,11 @@ 
    NULL,                                 /* next */
    0,                                    /* static_pass_number */
    TV_REMOVE_CONVS,                      /* tv_id */
-  PROP_cfg,                             /* properties_required */
+  PROP_cfg|PROP_cil,                    /* properties_required */
    0,                                    /* properties_provided */
    0,                                    /* properties_destroyed */
    0,                                    /* todo_flags_start */
-  TODO_ggc_collect                      /* todo_flags_finish */
+  TODO_ggc_collect|TODO_dump_func       /* todo_flags_finish */
   }
  };

Index: config/cil32/simp-cond.c
===================================================================
--- config/cil32/simp-cond.c	(revision 160959)
+++ config/cil32/simp-cond.c	(working copy)
@@ -225,11 +225,11 @@ 
    NULL,                                 /* next */
    0,                                    /* static_pass_number */
    TV_SIMP_COND,                         /* tv_id */
-  PROP_cfg,                             /* properties_required */
+  PROP_cfg|PROP_cil,                    /* properties_required */
    0,                                    /* properties_provided */
    0,                                    /* properties_destroyed */
    0,                                    /* todo_flags_start */
-  TODO_ggc_collect                      /* todo_flags_finish */
+  TODO_ggc_collect|TODO_dump_func       /* todo_flags_finish */
   }
  };

Index: config/cil32/missing-protos.c
===================================================================
--- config/cil32/missing-protos.c	(revision 160959)
+++ config/cil32/missing-protos.c	(working copy)
@@ -218,11 +218,11 @@ 
    NULL,                                 /* next */
    0,                                    /* static_pass_number */
    TV_MISSING_PROTOS,                    /* tv_id */
-  PROP_cfg,                             /* properties_required */
+  PROP_cfg|PROP_cil,                    /* properties_required */
    0,                                    /* properties_provided */
    0,                                    /* properties_destroyed */
    0,                                    /* todo_flags_start */
-  TODO_ggc_collect                      /* todo_flags_finish */
+  TODO_ggc_collect|TODO_dump_func       /* todo_flags_finish */
   }
  };

Index: config/cil32/cil-lower.c
===================================================================
--- config/cil32/cil-lower.c	(revision 160959)
+++ config/cil32/cil-lower.c	(working copy)
@@ -662,11 +662,11 @@ 
    NULL,                                 /* next */
    0,                                    /* static_pass_number */
    TV_LOWER_CIL,                         /* tv_id */
-  PROP_cfg,                             /* properties_required */
+  PROP_cfg|PROP_cil,                    /* properties_required */
    0,                                    /* properties_provided */
    0,                                    /* properties_destroyed */
    0,                                    /* todo_flags_start */
-  0                                     /* todo_flags_finish */
+  TODO_dump_func                        /* todo_flags_finish */
   }
  };

Index: config/cil32/emit-cil.c
===================================================================
--- config/cil32/emit-cil.c	(revision 160959)
+++ config/cil32/emit-cil.c	(working copy)
@@ -2068,11 +2068,11 @@ 
    NULL,                                 /* next */
    0,                                    /* static_pass_number */
    TV_EMIT_CIL,                          /* tv_id */
-  PROP_cfg,                             /* properties_required */
+  PROP_cfg|PROP_cil,                    /* properties_required */
    0,                                    /* properties_provided */
    0,                                    /* properties_destroyed */
    0,                                    /* todo_flags_start */
-  0                                    /* todo_flags_finish */
+  TODO_dump_func                        /* todo_flags_finish */
   }
  };

@@ -2176,11 +2176,11 @@ 
    NULL,                                 /* next */
    0,                                    /* static_pass_number */
    TV_EMIT_CIL_VCG,                      /* tv_id */
-  PROP_cfg,                             /* properties_required */
+  PROP_cfg|PROP_cil,                    /* properties_required */
    0,                                    /* properties_provided */
    0,                                    /* properties_destroyed */
    0,                                    /* todo_flags_start */
-  0                                     /* todo_flags_finish */
+  TODO_dump_func                        /* todo_flags_finish */
   }
  };

Index: config/cil32/cil-dump.c
===================================================================
--- config/cil32/cil-dump.c	(revision 160959)
+++ config/cil32/cil-dump.c	(working copy)
@@ -44,15 +44,16 @@ 
  #include "cil-stack.h"


-void dump_cil (void);
-static void dump_cil_stmt (const_cil_stmt stmt, cil_stack stack);
-static void dump_label_name (const_tree);
-static void dump_decl_name (const_tree);
-static void dump_valuetype_name (const_tree);
-static void dump_fun (const_tree);
-static void dump_type (const_tree type);
+void dump_cil_function_to_file (tree fn, FILE *file, int flags);

+void dump_cil_stmt (FILE * file, const_cil_stmt stmt, cil_stack stack);
+void dump_cil_label_name (FILE *, const_tree);
+void dump_cil_decl_name (FILE *, const_tree);
+void dump_cil_valuetype_name (FILE *, const_tree);
+void dump_cil_fun_signature (FILE *, const_tree);
+void dump_cil_type (FILE *, const_tree type);

+
  static const char* const cil_names[] = {
  #define CIL_INSTRDEF(A,B,C,D) D,
  #include "cil-instr.def"
@@ -67,29 +68,29 @@ 

  /* Dump the name of a label.  */

-static void
-dump_label_name (const_tree label)
+void
+dump_cil_label_name (FILE * file, const_tree label)
  {
-  printf ("?L" HOST_WIDE_INT_PRINT_DEC, (HOST_WIDE_INT) LABEL_DECL_UID (label));
+  fprintf (file, "?L" HOST_WIDE_INT_PRINT_DEC, (HOST_WIDE_INT) LABEL_DECL_UID 
(label));
  }

  /* Dump the name of a _DECL node pointed by NODE.  */

-static void
-dump_decl_name (const_tree node)
+void
+dump_cil_decl_name (FILE * file, const_tree node)
  {
    if (DECL_ASSEMBLER_NAME_SET_P (node) || DECL_NAME (node))
-    printf ("'%s'",IDENTIFIER_POINTER (DECL_NAME (node)));
+    fprintf (file, "'%s'",IDENTIFIER_POINTER (DECL_NAME (node)));
    else
-    printf ("'?UNNAMED%d'", DECL_UID (node));
+    fprintf (file, "'?UNNAMED%d'", DECL_UID (node));
  }

  /* Dump the name of a valuetype.
     T must be an aggregate type or an enumeral type, since these are
     the types emitted as CIL valuetypes.  */

-static void
-dump_valuetype_name (const_tree t)
+void
+dump_cil_valuetype_name (FILE * file, const_tree t)
  {
    tree name = TYPE_NAME (t);
    const char *str = NULL;
@@ -101,17 +102,17 @@ 
      str = IDENTIFIER_POINTER (DECL_NAME (name));

    if (str)
-    printf ("'%s'", str);
+    fprintf (file, "'%s'", str);
    else
-    printf ("'?UNNAMED%d'", DECL_UID (name));
+    fprintf (file, "'?UNNAMED%d'", DECL_UID (name));
  }

  /* Dump the signature of function type FUN_TYPE.
     The function name that is dumped is taken from function_decl FUN.
     FUN must be a FUNCTION_DECL.   */

-static void
-dump_fun (const_tree fun)
+void
+dump_cil_fun_signature (FILE * file, const_tree fun)
  {
    tree fun_type = TREE_TYPE (fun);
    tree args_type;
@@ -128,50 +129,50 @@ 
        varargs = true;
      }

-  printf ("%s", varargs ? "vararg " : "");
-  dump_type (TREE_TYPE (fun_type));
-  printf (" '%s'(", IDENTIFIER_POINTER (DECL_NAME (fun)));
+  fprintf (file, "%s", varargs ? "vararg " : "");
+  dump_cil_type (file, TREE_TYPE (fun_type));
+  fprintf (file, " '%s'(", IDENTIFIER_POINTER (DECL_NAME (fun)));


    while (args_type != last_arg_type)
      {
-      dump_type (TREE_VALUE (args_type));
+      dump_cil_type (file, TREE_VALUE (args_type));
        args_type = TREE_CHAIN (args_type);

        if (args_type != last_arg_type)
-	printf (", ");
+	fprintf (file, ", ");
      }

-  printf (")");
+  fprintf (file, ")");
  }

  /* Dump type TYPE.
     NODE must be a type node.   */

-static void
-dump_type (const_tree type)
+void
+dump_cil_type (FILE * file, const_tree type)
  {
    if (cil_value_type_p (type))
      {
-      printf ("value_type ");
-      dump_valuetype_name (TYPE_MAIN_VARIANT (type));
+      fprintf (file, "value_type ");
+      dump_cil_valuetype_name (file, TYPE_MAIN_VARIANT (type));
      }
    else if (cil_pointer_type_p (type))
      {
        if (TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
          {
-          printf ("method_pointer");
+          fprintf (file, "method_pointer");
          }
        else
          {
-          dump_type (TREE_TYPE (type));
-          printf (" *");
+          dump_cil_type (file, TREE_TYPE (type));
+          fprintf (file, " *");
          }
      }
    else
      {
        cil_type_t cil_type = type_to_cil (type);
-      printf ("%s", cil_type_names [cil_type]);
+      fprintf (file, "%s", cil_type_names [cil_type]);
      }
  }

@@ -179,8 +180,8 @@ 
     the stack depth and the type of the top-of-stack BEFORE the statement is
     executed.  */

-static void
-dump_cil_stmt (const_cil_stmt stmt, cil_stack stack)
+void
+dump_cil_stmt (FILE * file, const_cil_stmt stmt, cil_stack stack)
  {
    enum cil_opcode opcode = cil_opcode (stmt);

@@ -193,29 +194,29 @@ 
        else
  	top_type = "<empty>";

-      printf ("\n[%d] %-11s   %s", depth, top_type, cil_names[opcode]);
+      fprintf (file, "\n[%d] %-11s   %s", depth, top_type, cil_names[opcode]);
      }
    else
      {
-      printf ("\n\t%s", cil_names[opcode]);
+      fprintf (file, "\n\t%s", cil_names[opcode]);
      }

    if (cil_prefix_volatile (stmt))
-      printf (" volatile");
+      fprintf (file, " volatile");
    if (cil_prefix_unaligned (stmt) != 0)
-      printf (" unaligned %d", cil_prefix_unaligned (stmt));
+      fprintf (file, " unaligned %d", cil_prefix_unaligned (stmt));
    if ((opcode == CIL_VEC_CTOR) && cil_short_ctor (stmt))
-    printf (" short ctor");
+    fprintf (file, " short ctor");

    switch (opcode_arg_type (opcode))
      {
      case CIL_VAR:
-      printf ("\t");
-      dump_decl_name (cil_var (stmt));
+      fprintf (file, "\t");
+      dump_cil_decl_name (file, cil_var (stmt));
        break;

      case CIL_TYPE:
-      dump_type (cil_type (stmt));
+      dump_cil_type (file, cil_type (stmt));
        break;

      case CIL_FIELD:
@@ -227,38 +228,38 @@ 
  	    tree domain = TYPE_DOMAIN (TREE_TYPE (field));
  	    tree max = TYPE_MAX_VALUE (domain);
  	    HOST_WIDE_INT fsize = tree_low_cst (max, 1) + 1;
-	    printf ("string_type"HOST_WIDE_INT_PRINT_UNSIGNED" '?string%u'",
+	    fprintf (file, "string_type"HOST_WIDE_INT_PRINT_UNSIGNED" '?string%u'",
  		    fsize, get_string_cst_id (field));
  	  }
  	else
  	  {
-	    printf(" ");
+	    fprintf (file, " ");

  	    if (COMPLETE_TYPE_P (TREE_TYPE (field)))
-	      dump_type (TREE_TYPE (field));
+	      dump_cil_type (file, TREE_TYPE (field));
  	    else
-	      printf ("%s(incomplete_type)", cil_type_names [CIL_NATIVE_INT]);
-	    printf (" ");
+	      fprintf (file, "%s(incomplete_type)", cil_type_names [CIL_NATIVE_INT]);
+	    fprintf (file, " ");

  	    switch (opcode)
  	      {
  	      case CIL_LDFLD:
  	      case CIL_LDFLDA:
  	      case CIL_STFLD:
-		dump_valuetype_name (DECL_FIELD_CONTEXT (field));
-		printf ("::");
+		dump_cil_valuetype_name (file, DECL_FIELD_CONTEXT (field));
+		fprintf (file, "::");
  		break;
  	      default:
  		break;
  	      }

-	    dump_decl_name (field);
+	    dump_cil_decl_name (file, field);
  	  }
        }
        break;

      case CIL_LABEL:
-      dump_label_name (cil_label (stmt));
+      dump_cil_label_name (file, cil_label (stmt));
        break;

      case CIL_LABELS:
@@ -267,48 +268,48 @@ 
  	unsigned int n_cases = cil_switch_ncases (stmt);
  	unsigned HOST_WIDE_INT i;

-	printf ("\t(\n");
-	printf ("\t\tdefault: ");
-	dump_label_name (CASE_LABEL (cil_switch_default (stmt)));
-	printf ("\n");
+	fprintf (file, "\t(\n");
+	fprintf (file, "\t\tdefault: ");
+	dump_cil_label_name (file, CASE_LABEL (cil_switch_default (stmt)));
+	fprintf (file, "\n");

  	for (i = 0; i < n_cases - 1; i++)
  	  {
  	    HOST_WIDE_INT lo = cil_switch_case_low (stmt, i);
  	    HOST_WIDE_INT hi = cil_switch_case_high (stmt, i);

-	    printf 
("\t\t["HOST_WIDE_INT_PRINT_UNSIGNED"-"HOST_WIDE_INT_PRINT_UNSIGNED"]: ",
+	    fprintf (file, 
"\t\t["HOST_WIDE_INT_PRINT_UNSIGNED"-"HOST_WIDE_INT_PRINT_UNSIGNED"]: ",
  		    lo, hi);
-	    dump_label_name (cil_switch_case_label (stmt, i));
-	    printf ("\n");
+	    dump_cil_label_name (file, cil_switch_case_label (stmt, i));
+	    fprintf (file, "\n");
  	  }
-	printf ("\t\t)");
+	fprintf (file, "\t\t)");
        }
        break;

      case CIL_FUNC:
-      dump_fun (cil_func (stmt));
+      dump_cil_fun_signature (file, cil_func (stmt));
        break;

      case CIL_FCALL:
        {
  	tree fdecl = cil_call_fdecl (stmt);

-	printf("\t");
+	fprintf (file, "\t");

  	if (cil_prefix_tail (stmt))
-	  printf ("tailcall");
+	  fprintf (file, "tailcall");

  	if (DECL_BUILT_IN (fdecl))
-	  printf ("builtin ");
+	  fprintf (file, "builtin ");

  	if (cil_call_vararg_p (stmt))
-	  printf("vararg ");
+	  fprintf (file, "vararg ");

  	if (DECL_BUILT_IN (fdecl) && DECL_BUILT_IN_CLASS (fdecl) == BUILT_IN_MD)
-	  printf ("%s", IDENTIFIER_POINTER (DECL_NAME (fdecl)));
+	  fprintf (file, "%s", IDENTIFIER_POINTER (DECL_NAME (fdecl)));
  	else
-	  dump_decl_name (fdecl);
+	  dump_cil_decl_name (file, fdecl);
        }
        break;

@@ -317,8 +318,8 @@ 
  	{
  	case CIL_LDC_I4:
  	case CIL_LDC_I8:
-	  printf ("\t");
-	  dump_double_int (stdout, TREE_INT_CST (cil_cst (stmt)), false);
+	  fprintf (file, "\t");
+	  dump_double_int (file, TREE_INT_CST (cil_cst (stmt)), false);
  	  break;

  	case CIL_LDC_R4:
@@ -331,7 +332,7 @@ 

  	    real_to_target (buf, &d, TYPE_MODE (type));
  	    real_to_decimal (string, &d, sizeof (string), 0, 1);
-	    printf ("\t(%#08lx%08lx)\t/* %s */", buf[1], buf[0], string);
+	    fprintf (file, "\t(%#08lx%08lx)\t/* %s */", buf[1], buf[0], string);
  	  }
  	  break;

@@ -342,7 +343,7 @@ 

      case CIL_STRING:
        gcc_assert (opcode == CIL_ASM);
-      printf ("\n\t// BEGIN ASM"
+      fprintf (file, "\n\t// BEGIN ASM"
  	      "\n\t%s"
  	      "\n\t// END ASM",
  	      TREE_STRING_POINTER (cil_string (stmt)));
@@ -360,8 +361,8 @@ 
  /* Dump the IR for a given basic block.  The state of the stack is updated
     after each statement.  */

-static void
-dump_cil_bb (basic_block bb, cil_stack stack)
+void
+dump_cil_bb (FILE * file, basic_block bb, cil_stack stack)
  {
    cil_stmt_iterator csi;
    cil_stmt stmt = NULL;
@@ -369,14 +370,14 @@ 

    /* Dump this block label */
    label = gimple_block_label (bb);
-  printf ("\n");
-  dump_label_name (label);
-  printf (":\n");
+  fprintf (file, "\n");
+  dump_cil_label_name (file, label);
+  fprintf (file, ":\n");

    for (csi = csi_start_bb (bb); !csi_end_p (csi); csi_next (&csi))
      {
        stmt = csi_stmt (csi);
-      dump_cil_stmt (stmt, stack);
+      dump_cil_stmt (file, stmt, stack);
        cil_stack_after_stmt (stack, stmt);
      }
  }
@@ -385,7 +386,7 @@ 
  /* Dump the IR for the current function.  */

  void
-dump_cil (void)
+dump_cil_function_to_file (tree fn, FILE *file, int flags __attribute__((unused)))
  {
    basic_block bb;
    cil_bb_stacks bbs;
@@ -393,14 +394,14 @@ 

    bbs = cil_bb_stacks_create ();

-  printf ("%s:", lang_hooks.decl_printable_name (current_function_decl, 1));
+  fprintf (file, "%s:", lang_hooks.decl_printable_name (fn, 1));

    FOR_EACH_BB (bb)
      {
        stack = cil_stack_for_bb (bbs, bb);
-      dump_cil_bb (bb, stack);
+      dump_cil_bb (file, bb, stack);
      }
-  printf ("\n");
+  fprintf (file, "\n");
  }

  /*
Index: config/cil32/cil32.h
===================================================================
--- config/cil32/cil32.h	(revision 160959)
+++ config/cil32/cil32.h	(working copy)
@@ -564,6 +564,9 @@ 
  extern struct gimple_opt_pass pass_emit_cil_vcg;
  extern struct gimple_opt_pass pass_emit_cil;

+/* In cil-dump.c: */
+extern void dump_cil_function_to_file (tree, FILE *, int);
+
  /*
   * Local variables:
   * eval: (c-set-style "gnu")