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] |
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? Thanks, David
Attachment:
out
Description: Binary data
2011-05-31 David Li <davidxl@google.com> * passes.c (passr_eq): (register_pass_name): Change pass name table name. (get_pass_by_name): Ditto. (enable_disable_pass): Handle function assembler name. (is_pass_explicitly_enabled_or_disabled): Ditto. (execute_one_pass): Add pass dumping. (execute_pass_list): Track pass identation. (execute_ipa_pass_list): Ditto. (dump_one_pass): New function. (pass_traverse): Ditto. (enter_pass_list): Ditto. (exit_pass_list): Ditto. (is_valid_assembler_name): Ditto. 2011-05-31 David Li <davidxl@google.com> * testsuite/gcc.dg/inline_2.c (revision 0): * testsuite/gcc.dg/inline_6.c (revision 0): * testsuite/gcc.dg/unroll_2.c (revision 0): * testsuite/gcc.dg/inline_3.c (revision 0): * testsuite/gcc.dg/unroll_3.c (revision 0): * testsuite/gcc.dg/inline_4.c (revision 0): * testsuite/gcc.dg/unroll_4.c (revision 0): * testsuite/gcc.dg/inline_1.c (revision 0): * testsuite/gcc.dg/inline_5.c (revision 0): * testsuite/gcc.dg/unroll_1.c (revision 0): Index: doc/invoke.texi =================================================================== --- doc/invoke.texi (revision 174424) +++ 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 @@ -5056,11 +5057,12 @@ appended with a sequential number starti Disable rtl pass @var{pass}. @var{pass} is the pass name. If the same pass is statically invoked in the compiler multiple times, the pass name should be appended with a sequential number starting from 1. @var{range-list} is a comma -seperated list of function ranges. Each range is a number pair seperated by a colon. -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. +seperated list of function ranges or assembler names. Each range is a number +pair seperated by a colon. The range is inclusive in both ends. If the range +is trivial, the number pair can be simplified as 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. @item -fdisable-tree-@var{pass} @item -fdisable-tree-@var{pass}=@var{range-list} @@ -5090,7 +5092,8 @@ of option arguments. -fenable-tree-cunroll=1 # disable gcse2 for functions at the following ranges [1,1], # [300,400], and [400,1000] - -fdisable-rtl-gcse2=1:100,300,400:1000 +# disable gcse2 for functions foo and foo2 + -fdisable-rtl-gcse2=foo,foo2 # disable early inlining -fdisable-tree-einline # disable ipa inlining @@ -5483,6 +5486,11 @@ Dump after function inlining. @end table +@item -fdump-passes +@optindex 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: testsuite/gcc.dg/inline_2.c =================================================================== --- testsuite/gcc.dg/inline_2.c (revision 0) +++ testsuite/gcc.dg/inline_2.c (revision 0) @@ -0,0 +1,23 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized -fdisable-tree-einline=0:3 -fdisable-ipa-inline" } */ +int g; +__attribute__((always_inline)) void bar (void) +{ + g++; +} + +int foo (void) +{ + bar (); + return g; +} + +int foo2 (void) +{ + bar(); + return g + 1; +} + +/* { dg-final { scan-tree-dump-times "bar" 5 "optimized" } } */ +/* { dg-final { cleanup-tree-dump "optimized" } } */ +/* { dg-excess-errors "extra notes" } */ Index: testsuite/gcc.dg/inline_6.c =================================================================== --- testsuite/gcc.dg/inline_6.c (revision 0) +++ testsuite/gcc.dg/inline_6.c (revision 0) @@ -0,0 +1,23 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized -fdisable-tree-einline=foo2 -fdisable-ipa-inline" } */ +int g; +__attribute__((always_inline)) void bar (void) +{ + g++; +} + +int foo (void) +{ + bar (); + return g; +} + +int foo2 (void) +{ + bar(); + return g + 1; +} + +/* { dg-final { scan-tree-dump-times "bar" 4 "optimized" } } */ +/* { dg-final { cleanup-tree-dump "optimized" } } */ +/* { dg-excess-errors "extra notes" } */ Index: testsuite/gcc.dg/unroll_2.c =================================================================== --- testsuite/gcc.dg/unroll_2.c (revision 0) +++ testsuite/gcc.dg/unroll_2.c (revision 0) @@ -0,0 +1,33 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-rtl-loop2_unroll -fno-peel-loops -fdisable-tree-cunroll=1 -fdisable-tree-cunrolli=1 -fenable-rtl-loop2_unroll" } */ + +unsigned a[100], b[100]; +inline void bar() +{ + a[10] = b[10]; +} + +int foo(void) +{ + int i; + bar(); + for (i = 0; i < 2; i++) + { + a[i]= b[i] + 1; + } + return 1; +} + +int foo2(void) +{ + int i; + for (i = 0; i < 2; i++) + { + a[i]= b[i] + 1; + } + return 1; +} + +/* { dg-final { scan-rtl-dump-times "Decided to peel loop completely" 1 "loop2_unroll" } } */ +/* { dg-final { cleanup-rtl-dump "loop2_unroll" } } */ +/* { dg-excess-errors "extra notes" } */ Index: testsuite/gcc.dg/inline_3.c =================================================================== --- testsuite/gcc.dg/inline_3.c (revision 0) +++ testsuite/gcc.dg/inline_3.c (revision 0) @@ -0,0 +1,23 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized -fdisable-tree-einline=0:1,2,99:100 -fdisable-ipa-inline" } */ +int g; +__attribute__((always_inline)) void bar (void) +{ + g++; +} + +int foo (void) +{ + bar (); + return g; +} + +int foo2 (void) +{ + bar(); + return g + 1; +} + +/* { dg-final { scan-tree-dump-times "bar" 5 "optimized" } } */ +/* { dg-final { cleanup-tree-dump "optimized" } } */ +/* { dg-excess-errors "extra notes" } */ Index: testsuite/gcc.dg/unroll_3.c =================================================================== --- testsuite/gcc.dg/unroll_3.c (revision 0) +++ testsuite/gcc.dg/unroll_3.c (revision 0) @@ -0,0 +1,33 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-rtl-loop2_unroll -fno-peel-loops -fdisable-tree-cunroll -fdisable-tree-cunrolli -fenable-rtl-loop2_unroll=1" } */ + +unsigned a[100], b[100]; +inline void bar() +{ + a[10] = b[10]; +} + +int foo(void) +{ + int i; + bar(); + for (i = 0; i < 2; i++) + { + a[i]= b[i] + 1; + } + return 1; +} + +int foo2(void) +{ + int i; + for (i = 0; i < 2; i++) + { + a[i]= b[i] + 1; + } + return 1; +} + +/* { dg-final { scan-rtl-dump-times "Decided to peel loop completely" 1 "loop2_unroll" } } */ +/* { dg-final { cleanup-rtl-dump "loop2_unroll" } } */ +/* { dg-excess-errors "extra notes" } */ Index: testsuite/gcc.dg/inline_4.c =================================================================== --- testsuite/gcc.dg/inline_4.c (revision 0) +++ testsuite/gcc.dg/inline_4.c (revision 0) @@ -0,0 +1,23 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized -fdisable-tree-einline=1:1,3,4:100 -fdisable-ipa-inline" } */ +int g; +__attribute__((always_inline)) void bar (void) +{ + g++; +} + +int foo (void) +{ + bar (); + return g; +} + +int foo2 (void) +{ + bar(); + return g + 1; +} + +/* { dg-final { scan-tree-dump-times "bar" 4 "optimized" } } */ +/* { dg-final { cleanup-tree-dump "optimized" } } */ +/* { dg-excess-errors "extra notes" } */ Index: testsuite/gcc.dg/unroll_4.c =================================================================== --- testsuite/gcc.dg/unroll_4.c (revision 0) +++ testsuite/gcc.dg/unroll_4.c (revision 0) @@ -0,0 +1,33 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-rtl-loop2_unroll -fno-peel-loops -fdisable-tree-cunroll -fdisable-tree-cunrolli -fenable-rtl-loop2_unroll=foo2" } */ + +unsigned a[100], b[100]; +inline void bar() +{ + a[10] = b[10]; +} + +int foo(void) +{ + int i; + bar(); + for (i = 0; i < 2; i++) + { + a[i]= b[i] + 1; + } + return 1; +} + +int foo2(void) +{ + int i; + for (i = 0; i < 2; i++) + { + a[i]= b[i] + 1; + } + return 1; +} + +/* { dg-final { scan-rtl-dump-times "Decided to peel loop completely" 1 "loop2_unroll" } } */ +/* { dg-final { cleanup-rtl-dump "loop2_unroll" } } */ +/* { dg-excess-errors "extra notes" } */ Index: testsuite/gcc.dg/inline_1.c =================================================================== --- testsuite/gcc.dg/inline_1.c (revision 0) +++ testsuite/gcc.dg/inline_1.c (revision 0) @@ -0,0 +1,23 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized -fdisable-tree-einline -fdisable-ipa-inline" } */ +int g; +__attribute__((always_inline)) void bar (void) +{ + g++; +} + +int foo (void) +{ + bar (); + return g; +} + +int foo2 (void) +{ + bar(); + return g + 1; +} + +/* { dg-final { scan-tree-dump-times "bar" 5 "optimized" } } */ +/* { dg-final { cleanup-tree-dump "optimized" } } */ +/* { dg-excess-errors "extra notes" } */ Index: testsuite/gcc.dg/inline_5.c =================================================================== --- testsuite/gcc.dg/inline_5.c (revision 0) +++ testsuite/gcc.dg/inline_5.c (revision 0) @@ -0,0 +1,23 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized -fdisable-tree-einline=foo,foo2 -fdisable-ipa-inline" } */ +int g; +__attribute__((always_inline)) void bar (void) +{ + g++; +} + +int foo (void) +{ + bar (); + return g; +} + +int foo2 (void) +{ + bar(); + return g + 1; +} + +/* { dg-final { scan-tree-dump-times "bar" 5 "optimized" } } */ +/* { dg-final { cleanup-tree-dump "optimized" } } */ +/* { dg-excess-errors "extra notes" } */ Index: testsuite/gcc.dg/unroll_1.c =================================================================== --- testsuite/gcc.dg/unroll_1.c (revision 0) +++ testsuite/gcc.dg/unroll_1.c (revision 0) @@ -0,0 +1,33 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-rtl-loop2_unroll -fno-peel-loops -fdisable-tree-cunroll -fdisable-tree-cunrolli -fenable-rtl-loop2_unroll" } */ + +unsigned a[100], b[100]; +inline void bar() +{ + a[10] = b[10]; +} + +int foo(void) +{ + int i; + bar(); + for (i = 0; i < 2; i++) + { + a[i]= b[i] + 1; + } + return 1; +} + +int foo2(void) +{ + int i; + for (i = 0; i < 2; i++) + { + a[i]= b[i] + 1; + } + return 1; +} + +/* { dg-final { scan-rtl-dump-times "Decided to peel loop completely" 2 "loop2_unroll" } } */ +/* { dg-final { cleanup-rtl-dump "loop2_unroll" } } */ +/* { dg-excess-errors "extra notes" } */ Index: common.opt =================================================================== --- common.opt (revision 174424) +++ 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 174424) +++ passes.c (working copy) @@ -120,7 +120,7 @@ debug_pass (void) print_current_pass (stderr); } - +static void dump_one_pass (struct opt_pass *, bool); /* Global variables used to communicate with passes. */ int dump_flags; @@ -477,7 +477,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. */ @@ -487,11 +487,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; @@ -505,6 +505,61 @@ 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); +} + /* Returns the pass with NAME. */ static struct opt_pass * @@ -512,9 +567,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) @@ -530,6 +585,7 @@ struct uid_range { unsigned int start; unsigned int last; + const char *assem_name; struct uid_range *next; }; @@ -541,6 +597,35 @@ DEF_VEC_ALLOC_P(uid_range_p, heap); static VEC(uid_range_p, heap) *enabled_pass_uid_range_tab = NULL; static VEC(uid_range_p, heap) *disabled_pass_uid_range_tab = NULL; +/* A helper function to determine if an identifier is valid to + be an assembler name (better to use target specific hook). */ + +static bool +is_valid_assembler_name (const char *str) +{ + const char *p = str; + char c; + + c = *p; + if (!((c >= 'a' && c <= 'z') + || (c >= 'A' && c <= 'Z') + || *p == '_')) + return false; + + p++; + while ((c = *p)) + { + if (!((c >= 'a' && c <= 'z') + || (c >= 'A' && c <= 'Z') + || (c >= '0' && c <= '9') + || *p == '_')) + return false; + p++; + } + + return true; +} + /* Parse option string for -fdisable- and -fenable- The syntax of the options: @@ -627,6 +712,7 @@ enable_disable_pass (const char *arg, bo uid_range_p new_range; char *invalid = NULL; long start; + char *func_name = NULL; next_range = strchr (one_range, ','); if (next_range) @@ -644,17 +730,31 @@ enable_disable_pass (const char *arg, bo start = strtol (one_range, &invalid, 10); if (*invalid || start < 0) { - error ("Invalid range %s in option %s", - one_range, - is_enable ? "-fenable" : "-fdisable"); - free (argstr); - return; + if (end_val || !is_valid_assembler_name (one_range)) + { + error ("Invalid range %s in option %s", + one_range, + is_enable ? "-fenable" : "-fdisable"); + free (argstr); + return; + } + else + func_name = one_range; } if (!end_val) { new_range = XCNEW (struct uid_range); - new_range->start = (unsigned) start; - new_range->last = (unsigned) start; + if (!func_name) + { + new_range->start = (unsigned) start; + new_range->last = (unsigned) start; + } + else + { + new_range->start = (unsigned) -1; + new_range->last = (unsigned) -1; + new_range->assem_name = xstrdup (func_name); + } } else { @@ -678,13 +778,23 @@ enable_disable_pass (const char *arg, bo new_range); if (is_enable) - inform (UNKNOWN_LOCATION, - "enable pass %s for functions in the range of [%u, %u]", - phase_name, new_range->start, new_range->last); + if (new_range->assem_name) + inform (UNKNOWN_LOCATION, + "enable pass %s for function %s", + phase_name, new_range->assem_name); + else + inform (UNKNOWN_LOCATION, + "enable pass %s for functions in the range of [%u, %u]", + phase_name, new_range->start, new_range->last); else - inform (UNKNOWN_LOCATION, - "disable pass %s for functions in the range of [%u, %u]", - phase_name, new_range->start, new_range->last); + if (new_range->assem_name) + inform (UNKNOWN_LOCATION, + "disable pass %s for function %s", + phase_name, new_range->assem_name); + else + inform (UNKNOWN_LOCATION, + "disable pass %s for functions in the range of [%u, %u]", + phase_name, new_range->start, new_range->last); one_range = next_range; } while (next_range); @@ -718,6 +828,7 @@ is_pass_explicitly_enabled_or_disabled ( { uid_range_p slot, range; int cgraph_uid; + const char *aname = NULL; if (!tab || (unsigned) pass->static_pass_number >= VEC_length (uid_range_p, tab) @@ -729,6 +840,8 @@ is_pass_explicitly_enabled_or_disabled ( return false; cgraph_uid = func ? cgraph_get_node (func)->uid : 0; + if (func && DECL_ASSEMBLER_NAME_SET_P (func)) + aname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func)); range = slot; while (range) @@ -736,6 +849,9 @@ is_pass_explicitly_enabled_or_disabled ( if ((unsigned) cgraph_uid >= range->start && (unsigned) cgraph_uid <= range->last) return true; + if (range->assem_name && aname + && !strcmp (range->assem_name, aname)) + return true; range = range->next; } @@ -1836,6 +1952,9 @@ execute_one_pass (struct opt_pass *pass) gate_status = (pass->gate == NULL) ? true : pass->gate(); gate_status = override_gate_status (pass, current_function_decl, gate_status); + if (flag_dump_passes) + dump_one_pass (pass, gate_status); + /* Override gate with plugin. */ invoke_plugin_callbacks (PLUGIN_OVERRIDE_GATE, &gate_status); @@ -1920,9 +2039,63 @@ execute_one_pass (struct opt_pass *pass) return true; } + +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) +{ + 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%-30s%*s:%s\n", indent, " ", + pi->pass_name, + (10 - indent < 0 ? 0 : 10 - indent), " ", + is_on ? " ON" : " OFF"); + pi->dumped = true; +} + void execute_pass_list (struct opt_pass *pass) { + enter_pass_list (); do { gcc_assert (pass->type == GIMPLE_PASS @@ -1932,6 +2105,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 @@ -2234,6 +2408,7 @@ ipa_read_optimization_summaries (void) void execute_ipa_pass_list (struct opt_pass *pass) { + enter_pass_list (); do { gcc_assert (!current_function_decl); @@ -2259,6 +2434,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. */
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |