The attached is patch-2 (-fdump-passes) and a sample output: Ok for trunk?
David On Wed, Jun 1, 2011 at 9:16 AM, Xinliang David Li <[email protected]> wrote: > On Wed, Jun 1, 2011 at 1:51 AM, Richard Guenther > <[email protected]> wrote: >> On Wed, Jun 1, 2011 at 1:34 AM, Xinliang David Li <[email protected]> wrote: >>> The following patch implements the a new option that dumps gcc PASS >>> configuration. The sample output is attached. There is one >>> limitation: some placeholder passes that are named with '*xxx' are >>> note registered thus they are not listed. They are not important as >>> they can not be turned on/off anyway. >>> >>> The patch also enhanced -fenable-xxx and -fdisable-xx to allow a list >>> of function assembler names to be specified. >>> >>> Ok for trunk? >> >> Please split the patch. >> >> I'm not too happy how you dump the pass configuration. Why not simply, >> at a _single_ place, walk the pass tree? Instead of doing pieces of it >> at pass execution time when it's not already dumped - that really looks >> gross. > > Yes, that was the original plan -- but it has problems > 1) the dumper needs to know the root pass lists -- which can change > frequently -- it can be a long term maintanance burden; > 2) the centralized dumper needs to be done after option processing > 3) not sure if gate functions have any side effects or have dependencies on > cfun > > The proposed solutions IMHO is not that intrusive -- just three hooks > to do the dumping and tracking indentation. > >> >> The documentation should also link this option to the -fenable/disable >> options as obviously the pass names in that dump are those to be >> used for those flags (and not readily available anywhere else). > > Ok. > >> >> I also think that it would be way more useful to note in the individual >> dump files the functions (at the place they would usually appear) that >> have the pass explicitly enabled/disabled. > > Ok -- for ipa passes or tree/rtl passes where all functions are > explicitly disabled. > > Thanks, > > David > >> >> Richard. >> >>> Thanks, >>> >>> David >>> >> >
Index: doc/invoke.texi
===================================================================
--- doc/invoke.texi (revision 174535)
+++ doc/invoke.texi (working copy)
@@ -291,6 +291,7 @@ Objective-C and Objective-C++ Dialects}.
-fdump-translation-unit@r{[}-@var{n}@r{]} @gol
-fdump-class-hierarchy@r{[}-@var{n}@r{]} @gol
-fdump-ipa-all -fdump-ipa-cgraph -fdump-ipa-inline @gol
+-fdump-passes @gol
-fdump-statistics @gol
-fdump-tree-all @gol
-fdump-tree-original@r{[}-@var{n}@r{]} @gol
@@ -5060,7 +5061,8 @@ seperated list of function ranges. Each
The range is inclusive in both ends. If the range is trivial, the number pair can be
simplified a a single number. If the function's cgraph node's @var{uid} is falling
within one of the specified ranges, the @var{pass} is disabled for that function.
-The @var{uid} is shown in the function header of a dump file.
+The @var{uid} is shown in the function header of a dump file, and pass names can be
+dumped by using option @option{-fdump-passes}.
@item -fdisable-tree-@var{pass}
@item -fdisable-tree-@var{pass}=@var{range-list}
@@ -5483,6 +5485,11 @@ Dump after function inlining.
@end table
+@item -fdump-passes
+@opindex fdump-passes
+Dump the list of optimization passes that are turned on and off by
+the current command line options.
+
@item -fdump-statistics-@var{option}
@opindex fdump-statistics
Enable and control dumping of pass statistics in a separate file. The
Index: common.opt
===================================================================
--- common.opt (revision 174535)
+++ common.opt (working copy)
@@ -1012,6 +1012,10 @@ fdump-noaddr
Common Report Var(flag_dump_noaddr)
Suppress output of addresses in debugging dumps
+fdump-passes
+Common Var(flag_dump_passes) Init(0)
+Dump optimization passes
+
fdump-unnumbered
Common Report Var(flag_dump_unnumbered)
Suppress output of instruction numbers, line number notes and addresses in debugging dumps
Index: passes.c
===================================================================
--- passes.c (revision 174536)
+++ passes.c (working copy)
@@ -478,7 +478,7 @@ passr_eq (const void *p1, const void *p2
return !strcmp (s1->unique_name, s2->unique_name);
}
-static htab_t pass_name_tab = NULL;
+static htab_t name_to_pass_map = NULL;
/* Register PASS with NAME. */
@@ -488,11 +488,11 @@ register_pass_name (struct opt_pass *pas
struct pass_registry **slot;
struct pass_registry pr;
- if (!pass_name_tab)
- pass_name_tab = htab_create (256, passr_hash, passr_eq, NULL);
+ if (!name_to_pass_map)
+ name_to_pass_map = htab_create (256, passr_hash, passr_eq, NULL);
pr.unique_name = name;
- slot = (struct pass_registry **) htab_find_slot (pass_name_tab, &pr, INSERT);
+ slot = (struct pass_registry **) htab_find_slot (name_to_pass_map, &pr, INSERT);
if (!*slot)
{
struct pass_registry *new_pr;
@@ -506,6 +506,117 @@ register_pass_name (struct opt_pass *pas
return; /* Ignore plugin passes. */
}
+typedef struct {
+ /* Pass name with kind prefix and instance number suffix. */
+ const char *pass_name;
+ /* Flag indicating if the pass info has been dumped. */
+ bool dumped;
+} pass_info;
+
+DEF_VEC_O(pass_info);
+DEF_VEC_ALLOC_O(pass_info, heap);
+static VEC(pass_info, heap) *pass_tab = NULL;
+
+/* Callback function for traversing NAME_TO_PASS_MAP. */
+
+static int
+pass_traverse (void **slot, void *data)
+{
+ int* tab_size = (int *)data;
+ struct pass_registry **p = (struct pass_registry **)slot;
+ struct opt_pass *pass = (*p)->pass;
+ pass_info *pd;
+
+ gcc_assert (pass->static_pass_number > 0);
+ if (tab_size)
+ {
+ if (pass->static_pass_number > *tab_size)
+ *tab_size = pass->static_pass_number;
+
+ return 1;
+ }
+
+ gcc_assert (pass_tab);
+ pd = VEC_index (pass_info, pass_tab, pass->static_pass_number);
+ pd->pass_name = (*p)->unique_name;
+ pd->dumped = false;
+
+ return 1;
+}
+
+/* The function traverses NAME_TO_PASS_MAP and creates a pass info
+ table for dumping purpose. */
+
+static void
+create_pass_tab (void)
+{
+ int tab_size = 0;
+
+ if (!flag_dump_passes || pass_tab)
+ return;
+
+ htab_traverse (name_to_pass_map, pass_traverse, &tab_size);
+ VEC_safe_grow_cleared (pass_info, heap,
+ pass_tab, tab_size + 1);
+ htab_traverse (name_to_pass_map, pass_traverse, NULL);
+}
+
+
+static int pass_indent = 0;
+
+/* Tracks pass dumping indentation. */
+
+static inline void
+enter_pass_list (void)
+{
+ pass_indent++;
+}
+
+/* Tracks pass dumping indentation. */
+
+static inline void
+exit_pass_list (void)
+{
+ pass_indent--;
+}
+
+/* Dump the instantiated name for PASS. IS_ON indicates if PASS
+ is turned on or not. */
+
+static void
+dump_one_pass (struct opt_pass *pass, bool is_on, bool is_really_on)
+{
+ pass_info *pi;
+ int indent = 3 * pass_indent;
+ static int uid_range_dumped = false;
+
+ if (!uid_range_dumped)
+ {
+ fprintf (stderr, "MAX_UID = %d\n", cgraph_max_uid);
+ uid_range_dumped = true;
+ }
+
+ create_pass_tab();
+ gcc_assert (pass_tab);
+
+ if (pass->static_pass_number <= 0)
+ return;
+
+ pi = VEC_index (pass_info, pass_tab,
+ pass->static_pass_number);
+ if (pi->dumped)
+ return;
+
+ fprintf (stderr, "%*s%-35s%*s:%s%s\n", indent, " ",
+ pi->pass_name,
+ (10 - indent < 0 ? 0 : 10 - indent), " ",
+ is_on ? " ON" : " OFF",
+ ((!is_on) == (!is_really_on) ? ""
+ : (is_really_on ? " (FORCED_ON)" : " (FORCED_OFF)")));
+ pi->dumped = true;
+}
+
+
/* Returns the pass with NAME. */
static struct opt_pass *
@@ -513,9 +624,9 @@ get_pass_by_name (const char *name)
{
struct pass_registry **slot, pr;
- gcc_assert (pass_name_tab);
+ gcc_assert (name_to_pass_map);
pr.unique_name = name;
- slot = (struct pass_registry **) htab_find_slot (pass_name_tab,
+ slot = (struct pass_registry **) htab_find_slot (name_to_pass_map,
&pr, NO_INSERT);
if (!slot || !*slot)
@@ -1807,7 +1918,7 @@ execute_one_pass (struct opt_pass *pass)
bool initializing_dump;
unsigned int todo_after = 0;
- bool gate_status;
+ bool gate_status0, gate_status;
/* IPA passes are executed on whole program, so cfun should be NULL.
Other passes need function context set. */
@@ -1820,8 +1931,11 @@ execute_one_pass (struct opt_pass *pass)
/* Check whether gate check should be avoided.
User controls the value of the gate through the parameter "gate_status". */
- gate_status = (pass->gate == NULL) ? true : pass->gate();
- gate_status = override_gate_status (pass, current_function_decl, gate_status);
+ gate_status0 = (pass->gate == NULL) ? true : pass->gate();
+ gate_status = override_gate_status (pass, current_function_decl, gate_status0);
+
+ if (flag_dump_passes)
+ dump_one_pass (pass, gate_status0, gate_status);
/* Override gate with plugin. */
invoke_plugin_callbacks (PLUGIN_OVERRIDE_GATE, &gate_status);
@@ -1910,6 +2024,7 @@ execute_one_pass (struct opt_pass *pass)
void
execute_pass_list (struct opt_pass *pass)
{
+ enter_pass_list ();
do
{
gcc_assert (pass->type == GIMPLE_PASS
@@ -1919,6 +2034,7 @@ execute_pass_list (struct opt_pass *pass
pass = pass->next;
}
while (pass);
+ exit_pass_list ();
}
/* Same as execute_pass_list but assume that subpasses of IPA passes
@@ -2221,6 +2337,7 @@ ipa_read_optimization_summaries (void)
void
execute_ipa_pass_list (struct opt_pass *pass)
{
+ enter_pass_list ();
do
{
gcc_assert (!current_function_decl);
@@ -2246,6 +2363,7 @@ execute_ipa_pass_list (struct opt_pass *
pass = pass->next;
}
while (pass);
+ exit_pass_list ();
}
/* Execute stmt fixup hooks of all passes in PASS for NODE and STMTS. */
out
Description: Binary data
