This adds a dump modifier, -gimple (TDF_GIMPLE) and guards the dumping changes with it (in the case of dump_function_header simply not calling it). It also adjusts label dumping in another place (when dumping switch statements which btw do not yet parse correctly it seems).
Tested on x86_64-unknown-linux-gnu, will commit after bootstrap. Richard. 2016-10-26 Richard Biener <rguent...@suse.de> * dumpfile.h (TDF_GIMPLE): Add. * dumpfile.c (dump_options): Add gimple. * gimple-pretty-print.c: Guard changes with flags & TDF_GIMPLE. * passes.c (pass_init_dump_file): Do not dump function header for TDF_GIMPLE. * tree-cfg.c (dump_function_to_file): Guard changes. * tree-pretty-print.c (dump_decl_name): Likewise. (dump_generic_node): Dump labels in parseable form. (dump_function_header): Undo changes. diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index 542b83b..ad80b16 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -1467,7 +1467,7 @@ static void c_finish_oacc_routine (struct oacc_routine_data *, tree, bool); threadprivate-directive GIMPLE: - + gimple-function-definition: declaration-specifiers[opt] __GIMPLE (gimple-pass-list) declarator declaration-list[opt] compound-statement */ diff --git a/gcc/c/gimple-parser.c b/gcc/c/gimple-parser.c index c19f417..a1e8988 100644 --- a/gcc/c/gimple-parser.c +++ b/gcc/c/gimple-parser.c @@ -230,7 +230,7 @@ c_parser_gimple_compound_statement (c_parser *parser, gimple_seq *seq) } } c_parser_consume_token (parser); - return return_p; + return return_p; } /* Parse a gimple expression. diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c index b1812b2..e315a77 100644 --- a/gcc/cgraphunit.c +++ b/gcc/cgraphunit.c @@ -2052,7 +2052,6 @@ cgraph_node::expand (void) /* Make sure that BE didn't give up on compiling. */ gcc_assert (TREE_ASM_WRITTEN (decl)); - if (cfun) pop_cfun (); diff --git a/gcc/dumpfile.c b/gcc/dumpfile.c index 74522a6..e9483bc 100644 --- a/gcc/dumpfile.c +++ b/gcc/dumpfile.c @@ -108,13 +108,15 @@ static const struct dump_option_value_info dump_options[] = {"nouid", TDF_NOUID}, {"enumerate_locals", TDF_ENUMERATE_LOCALS}, {"scev", TDF_SCEV}, + {"gimple", TDF_GIMPLE}, {"optimized", MSG_OPTIMIZED_LOCATIONS}, {"missed", MSG_MISSED_OPTIMIZATION}, {"note", MSG_NOTE}, {"optall", MSG_ALL}, {"all", ~(TDF_RAW | TDF_SLIM | TDF_LINENO | TDF_TREE | TDF_RTL | TDF_IPA | TDF_STMTADDR | TDF_GRAPH | TDF_DIAGNOSTIC | TDF_VERBOSE - | TDF_RHS_ONLY | TDF_NOUID | TDF_ENUMERATE_LOCALS | TDF_SCEV)}, + | TDF_RHS_ONLY | TDF_NOUID | TDF_ENUMERATE_LOCALS | TDF_SCEV + | TDF_GIMPLE)}, {NULL, 0} }; diff --git a/gcc/dumpfile.h b/gcc/dumpfile.h index 3f08b16..b7d70f2 100644 --- a/gcc/dumpfile.h +++ b/gcc/dumpfile.h @@ -82,9 +82,10 @@ enum tree_dump_index #define TDF_CSELIB (1 << 23) /* Dump cselib details. */ #define TDF_SCEV (1 << 24) /* Dump SCEV details. */ #define TDF_COMMENT (1 << 25) /* Dump lines with prefix ";;" */ -#define MSG_OPTIMIZED_LOCATIONS (1 << 26) /* -fopt-info optimized sources */ -#define MSG_MISSED_OPTIMIZATION (1 << 27) /* missed opportunities */ -#define MSG_NOTE (1 << 28) /* general optimization info */ +#define TDF_GIMPLE (1 << 26) /* Dump in GIMPLE FE syntax */ +#define MSG_OPTIMIZED_LOCATIONS (1 << 27) /* -fopt-info optimized sources */ +#define MSG_MISSED_OPTIMIZATION (1 << 28) /* missed opportunities */ +#define MSG_NOTE (1 << 29) /* general optimization info */ #define MSG_ALL (MSG_OPTIMIZED_LOCATIONS | MSG_MISSED_OPTIMIZATION \ | MSG_NOTE) diff --git a/gcc/gimple-pretty-print.c b/gcc/gimple-pretty-print.c index 66cec25..9914adf 100644 --- a/gcc/gimple-pretty-print.c +++ b/gcc/gimple-pretty-print.c @@ -887,7 +887,10 @@ dump_gimple_switch (pretty_printer *buffer, gswitch *gs, int spc, { pp_string (buffer, "switch ("); dump_generic_node (buffer, gimple_switch_index (gs), spc, flags, true); - pp_string (buffer, ") {"); + if (flags & TDF_GIMPLE) + pp_string (buffer, ") {"); + else + pp_string (buffer, ") <"); } for (i = 0; i < gimple_switch_num_labels (gs); i++) @@ -898,9 +901,17 @@ dump_gimple_switch (pretty_printer *buffer, gswitch *gs, int spc, pp_space (buffer); dump_generic_node (buffer, CASE_LABEL (case_label), spc, flags, false); if (i < gimple_switch_num_labels (gs) - 1) - pp_string (buffer, "; "); + { + if (flags & TDF_GIMPLE) + pp_string (buffer, "; "); + else + pp_string (buffer, ", "); + } } - pp_string (buffer, "}"); + if (flags & TDF_GIMPLE) + pp_right_brace (buffer); + else + pp_greater (buffer); } @@ -956,11 +967,18 @@ dump_gimple_label (pretty_printer *buffer, glabel *gs, int spc, int flags) { tree label = gimple_label_label (gs); if (flags & TDF_RAW) - dump_gimple_fmt (buffer, spc, flags, "%T", label); + dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, label); else - dump_generic_node (buffer, label, spc, flags, false); - - pp_colon (buffer); + { + dump_generic_node (buffer, label, spc, flags, false); + pp_colon (buffer); + } + if (flags & TDF_GIMPLE) + return; + if (DECL_NONLOCAL (label)) + pp_string (buffer, " [non-local]"); + if ((flags & TDF_EH) && EH_LANDING_PAD_NR (label)) + pp_printf (buffer, " [LP %d]", EH_LANDING_PAD_NR (label)); } /* Dump a GIMPLE_GOTO tuple on the pretty_printer BUFFER, SPC @@ -2010,7 +2028,8 @@ dump_ssaname_info_to_file (FILE *file, tree node, int spc) pretty printer. If COMMENT is true, print this after #. */ static void -dump_gimple_phi (pretty_printer *buffer, gphi *phi, int spc, int flags) +dump_gimple_phi (pretty_printer *buffer, gphi *phi, int spc, bool comment, + int flags) { size_t i; tree lhs = gimple_phi_result (phi); @@ -2018,27 +2037,45 @@ dump_gimple_phi (pretty_printer *buffer, gphi *phi, int spc, int flags) if (flags & TDF_ALIAS) dump_ssaname_info (buffer, lhs, spc); + if (comment) + pp_string (buffer, "# "); + if (flags & TDF_RAW) dump_gimple_fmt (buffer, spc, flags, "%G <%T, ", phi, gimple_phi_result (phi)); else { dump_generic_node (buffer, lhs, spc, flags, false); - pp_string (buffer, " = __PHI ("); + if (flags & TDF_GIMPLE) + pp_string (buffer, " = __PHI ("); + else + pp_string (buffer, " = PHI <"); } for (i = 0; i < gimple_phi_num_args (phi); i++) { if ((flags & TDF_LINENO) && gimple_phi_arg_has_location (phi, i)) dump_location (buffer, gimple_phi_arg_location (phi, i)); - pp_string (buffer, "bb_"); - pp_decimal_int (buffer, gimple_phi_arg_edge (phi, i)->src->index); - pp_string (buffer, ": "); + if (flags & TDF_GIMPLE) + { + pp_string (buffer, "bb_"); + pp_decimal_int (buffer, gimple_phi_arg_edge (phi, i)->src->index); + pp_string (buffer, ": "); + } dump_generic_node (buffer, gimple_phi_arg_def (phi, i), spc, flags, false); + if (! (flags & TDF_GIMPLE)) + { + pp_left_paren (buffer); + pp_decimal_int (buffer, gimple_phi_arg_edge (phi, i)->src->index); + pp_right_paren (buffer); + } if (i < gimple_phi_num_args (phi) - 1) pp_string (buffer, ", "); } - pp_right_paren (buffer); + if (flags & TDF_GIMPLE) + pp_right_paren (buffer); + else + pp_greater (buffer); } @@ -2326,7 +2363,7 @@ pp_gimple_stmt_1 (pretty_printer *buffer, gimple *gs, int spc, int flags) break; case GIMPLE_PHI: - dump_gimple_phi (buffer, as_a <gphi *> (gs), spc, flags); + dump_gimple_phi (buffer, as_a <gphi *> (gs), spc, false, flags); break; case GIMPLE_OMP_PARALLEL: @@ -2487,7 +2524,12 @@ dump_gimple_bb_header (FILE *outf, basic_block bb, int indent, int flags) { gimple *stmt = first_stmt (bb); if (!stmt || gimple_code (stmt) != GIMPLE_LABEL) - fprintf (outf, "%*sbb_%d:\n", indent, "", bb->index); + { + if (flags & TDF_GIMPLE) + fprintf (outf, "%*sbb_%d:\n", indent, "", bb->index); + else + fprintf (outf, "%*s<bb %d>:\n", indent, "", bb->index); + } } } @@ -2520,7 +2562,8 @@ dump_phi_nodes (pretty_printer *buffer, basic_block bb, int indent, int flags) if (!virtual_operand_p (gimple_phi_result (phi)) || (flags & TDF_VOPS)) { INDENT (indent); - dump_gimple_phi (buffer, phi, indent, flags); + dump_gimple_phi (buffer, phi, indent, + (flags & TDF_GIMPLE) ? false : true, flags); pp_newline (buffer); } } @@ -2531,11 +2574,32 @@ dump_phi_nodes (pretty_printer *buffer, basic_block bb, int indent, int flags) to BUFFER. */ static void -pp_cfg_jump (pretty_printer *buffer, basic_block bb) +pp_cfg_jump (pretty_printer *buffer, basic_block bb, int flags) { - pp_string (buffer, "goto bb_"); - pp_decimal_int (buffer, bb->index); - pp_semicolon (buffer); + if (flags & TDF_GIMPLE) + { + pp_string (buffer, "goto bb_"); + pp_decimal_int (buffer, bb->index); + pp_semicolon (buffer); + } + else + { + gimple *stmt = first_stmt (bb); + pp_string (buffer, "goto <bb "); + pp_decimal_int (buffer, bb->index); + pp_greater (buffer); + if (stmt && gimple_code (stmt) == GIMPLE_LABEL) + { + pp_string (buffer, " ("); + dump_generic_node (buffer, + gimple_label_label (as_a <glabel *> (stmt)), + 0, 0, false); + pp_right_paren (buffer); + pp_semicolon (buffer); + } + else + pp_semicolon (buffer); + } } @@ -2563,11 +2627,11 @@ dump_implicit_edges (pretty_printer *buffer, basic_block bb, int indent, extract_true_false_edges_from_block (bb, &true_edge, &false_edge); INDENT (indent + 2); - pp_cfg_jump (buffer, true_edge->dest); + pp_cfg_jump (buffer, true_edge->dest, flags); newline_and_indent (buffer, indent); pp_string (buffer, "else"); newline_and_indent (buffer, indent + 2); - pp_cfg_jump (buffer, false_edge->dest); + pp_cfg_jump (buffer, false_edge->dest, flags); pp_newline (buffer); return; } @@ -2584,7 +2648,7 @@ dump_implicit_edges (pretty_printer *buffer, basic_block bb, int indent, && e->goto_locus != UNKNOWN_LOCATION) dump_location (buffer, e->goto_locus); - pp_cfg_jump (buffer, e->dest); + pp_cfg_jump (buffer, e->dest, flags); pp_newline (buffer); } } @@ -2652,7 +2716,7 @@ gimple_dump_bb (FILE *file, basic_block bb, int indent, int flags) void gimple_dump_bb_for_graph (pretty_printer *pp, basic_block bb) { - pp_printf (pp, "bb_%d:\n", bb->index); + pp_printf (pp, "<bb %d>:\n", bb->index); pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true); for (gphi_iterator gsi = gsi_start_phis (bb); !gsi_end_p (gsi); diff --git a/gcc/passes.c b/gcc/passes.c index 61eea90..51d0d84 100644 --- a/gcc/passes.c +++ b/gcc/passes.c @@ -2099,7 +2099,7 @@ pass_init_dump_file (opt_pass *pass) release_dump_file_name (); dump_file_name = dumps->get_dump_file_name (pass->static_pass_number); dumps->dump_start (pass->static_pass_number, &dump_flags); - if (dump_file && current_function_decl) + if (dump_file && current_function_decl && ! (dump_flags & TDF_GIMPLE)) dump_function_header (dump_file, current_function_decl, dump_flags); if (initializing_dump && dump_file && (dump_flags & TDF_GRAPH) diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c index b9e73c9..11bf6d6 100644 --- a/gcc/tree-cfg.c +++ b/gcc/tree-cfg.c @@ -7548,8 +7548,14 @@ dump_function_to_file (tree fndecl, FILE *file, int flags) } current_function_decl = fndecl; - print_generic_expr (file, TREE_TYPE (TREE_TYPE (fndecl)), dump_flags); - fprintf (file, "\n%s %s(", function_name (fun), tmclone ? "[tm-clone] " : ""); + if (flags & TDF_GIMPLE) + { + print_generic_expr (file, TREE_TYPE (TREE_TYPE (fndecl)), + dump_flags | TDF_SLIM); + fprintf (file, "\n%s (", function_name (fun)); + } + else + fprintf (file, "%s %s(", function_name (fun), tmclone ? "[tm-clone] " : ""); arg = DECL_ARGUMENTS (fndecl); while (arg) diff --git a/gcc/tree-pretty-print.c b/gcc/tree-pretty-print.c index d54252d..69c79d6 100644 --- a/gcc/tree-pretty-print.c +++ b/gcc/tree-pretty-print.c @@ -257,10 +257,11 @@ dump_decl_name (pretty_printer *pp, tree node, int flags) else pp_tree_identifier (pp, DECL_NAME (node)); } + char uid_sep = (flags & TDF_GIMPLE) ? '_' : '.'; if ((flags & TDF_UID) || DECL_NAME (node) == NULL_TREE) { if (TREE_CODE (node) == LABEL_DECL && LABEL_DECL_UID (node) != -1) - pp_printf (pp, "L_%d", (int) LABEL_DECL_UID (node)); + pp_printf (pp, "L%c%d", uid_sep, (int) LABEL_DECL_UID (node)); else if (TREE_CODE (node) == DEBUG_EXPR_DECL) { if (flags & TDF_NOUID) @@ -274,7 +275,7 @@ dump_decl_name (pretty_printer *pp, tree node, int flags) if (flags & TDF_NOUID) pp_printf (pp, "%c.xxxx", c); else - pp_printf (pp, "%c_%u", c, DECL_UID (node)); + pp_printf (pp, "%c%c%u", c, uid_sep, DECL_UID (node)); } } if ((flags & TDF_ALIAS) && DECL_PT_UID (node) != DECL_UID (node)) @@ -1762,13 +1763,23 @@ dump_generic_node (pretty_printer *pp, tree node, int spc, int flags, if (DECL_NAME (node)) dump_decl_name (pp, node, flags); else if (LABEL_DECL_UID (node) != -1) - pp_printf (pp, "<L%d>", (int) LABEL_DECL_UID (node)); + { + if (flags & TDF_GIMPLE) + pp_printf (pp, "L%d", (int) LABEL_DECL_UID (node)); + else + pp_printf (pp, "<L%d>", (int) LABEL_DECL_UID (node)); + } else { if (flags & TDF_NOUID) pp_string (pp, "<D.xxxx>"); else - pp_printf (pp, "<D.%u>", DECL_UID (node)); + { + if (flags & TDF_GIMPLE) + pp_printf (pp, "<D%u>", DECL_UID (node)); + else + pp_printf (pp, "<D.%u>", DECL_UID (node)); + } } break; @@ -3965,14 +3976,14 @@ dump_function_header (FILE *dump_file, tree fdecl, int flags) else aname = "<unset-asm-name>"; - fprintf (dump_file, "\n/* Function %s (%s, funcdef_no=%d", + fprintf (dump_file, "\n;; Function %s (%s, funcdef_no=%d", dname, aname, fun->funcdef_no); if (!(flags & TDF_NOUID)) fprintf (dump_file, ", decl_uid=%d", DECL_UID (fdecl)); if (node) { fprintf (dump_file, ", cgraph_uid=%d", node->uid); - fprintf (dump_file, ", symbol_order=%d)%s", node->order, + fprintf (dump_file, ", symbol_order=%d)%s\n\n", node->order, node->frequency == NODE_FREQUENCY_HOT ? " (hot)" : node->frequency == NODE_FREQUENCY_UNLIKELY_EXECUTED @@ -3982,8 +3993,7 @@ dump_function_header (FILE *dump_file, tree fdecl, int flags) : ""); } else - fprintf (dump_file, ")"); - fprintf (dump_file, "*/\n\n"); + fprintf (dump_file, ")\n\n"); } /* Dump double_int D to pretty_printer PP. UNS is true