By default -finstrument-functions instruments all functions. To limit instrumentation to certain functions or files it is necessary to specify the complement using -finstrument-functions-exclude-file-list or -finstrument-functions-exclude-function-list.
The new options -finstrument-functions-include-file-list and -finstrument-functions-include-function-list make the specification of the complement unnecessary by allowing the user to limit instrumentation to a set of file names and functions. --- gcc/common.opt | 16 ++++++++++- gcc/doc/invoke.texi | 52 ++++++++++++++++++++++++++++++++++++ gcc/gimplify.c | 51 ++++++++++++++++++++++++----------- gcc/opts.c | 10 +++++++ gcc/testsuite/ChangeLog | 10 +++++++ gcc/testsuite/gcc.dg/instrument-10.c | 7 +++++ gcc/testsuite/gcc.dg/instrument-4.c | 7 +++++ gcc/testsuite/gcc.dg/instrument-5.c | 7 +++++ gcc/testsuite/gcc.dg/instrument-6.c | 7 +++++ gcc/testsuite/gcc.dg/instrument-7.c | 7 +++++ gcc/testsuite/gcc.dg/instrument-8.c | 7 +++++ gcc/testsuite/gcc.dg/instrument-9.c | 7 +++++ 12 files changed, 172 insertions(+), 16 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/instrument-10.c create mode 100644 gcc/testsuite/gcc.dg/instrument-4.c create mode 100644 gcc/testsuite/gcc.dg/instrument-5.c create mode 100644 gcc/testsuite/gcc.dg/instrument-6.c create mode 100644 gcc/testsuite/gcc.dg/instrument-7.c create mode 100644 gcc/testsuite/gcc.dg/instrument-8.c create mode 100644 gcc/testsuite/gcc.dg/instrument-9.c diff --git a/gcc/common.opt b/gcc/common.opt index 3eb520e..ac797b3 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -97,7 +97,7 @@ int flag_gen_aux_info = 0 Variable int flag_shlib -; These two are really VEC(char_p,heap) *. +; These are really VEC(char_p,heap) *. Variable void *flag_instrument_functions_exclude_functions @@ -105,6 +105,12 @@ void *flag_instrument_functions_exclude_functions Variable void *flag_instrument_functions_exclude_files +Variable +void *flag_instrument_functions_include_functions + +Variable +void *flag_instrument_functions_include_files + ; Generic structs (e.g. templates not explicitly specialized) ; may not have a compilation unit associated with them, and so ; may need to be treated differently from ordinary structs. @@ -1477,6 +1483,14 @@ finstrument-functions-exclude-file-list= Common RejectNegative Joined -finstrument-functions-exclude-file-list=filename,... Do not instrument functions listed in files. +finstrument-functions-include-function-list= +Common RejectNegative Joined +-finstrument-functions-include-function-list=name,... Only instrument listed functions. + +finstrument-functions-include-file-list= +Common RejectNegative Joined +-finstrument-functions-include-file-list=filename,... Only instrument functions listed in files. + fipa-cp Common Report Var(flag_ipa_cp) Optimization Perform interprocedural constant propagation. diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 53f1fe2..ba9a3bd 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -1150,6 +1150,8 @@ See S/390 and zSeries Options. -finhibit-size-directive -finstrument-functions @gol -finstrument-functions-exclude-function-list=@var{sym},@var{sym},@dots{} @gol -finstrument-functions-exclude-file-list=@var{file},@var{file},@dots{} @gol +-finstrument-functions-include-function-list=@var{sym},@var{sym},@dots{} @gol +-finstrument-functions-include-file-list=@var{file},@var{file},@dots{} @gol -fno-common -fno-ident @gol -fpcc-struct-return -fpic -fPIC -fpie -fPIE -fno-plt @gol -fno-jump-tables @gol @@ -24529,6 +24531,56 @@ of the function name, it is considered to be a match. For C99 and C++ extended identifiers, the function name must be given in UTF-8, not using universal character names. +@item -finstrument-functions-include-file-list=@var{file},@var{file},@dots{} +@opindex finstrument-functions-include-file-list + +Limit function instrumentation to functions from files specified in +the list. The matching of file names is identical to the matching of +@option{-finstrument-functions-exclude-file-list}. For example + +@smallexample +-finstrument-functions-include-file-list=/foo/bar,baz +@end smallexample + +@noindent +includes only functions defined in files whose pathnames contain +@file{/foo/bar} or @file{baz}. Additional functions can be added by +using the option +@option{-finstrument-functions-include-function-list}. For example + +@smallexample +-finstrument-functions-include-file-list=/foo/bar,baz +-finstrument-functions-include-function-list=fn1,fn2 +@end smallexample +includes functions defined in files whose pathnames contain +@file{/foo/bar} or @file{baz} as well as functions whose user-readable +names contain @code{fn1} or @code{fn2}. + +The option can also be combined with exclusions, where exclusions take +precedence. For example + +@smallexample +-finstrument-functions-include-file-list=/foo/bar,baz +-finstrument-functions-exclude-file-list=baz/qux +-finstrument-functions-exclude-function-list=fn1,fn2 +@end smallexample +includes only functions defined in files whose pathnames contain +@file{/foo/bar} or @file{baz}, whose names neither contain @code{fn1} +nor @code{fn2} and which are not defined in files whose pathnames +contain @file{baz/qux}. + +@item -finstrument-functions-include-function-list=@var{sym},@var{sym},@dots{} +@opindex finstrument-functions-include-function-list + +Limit function instrumentation to functions specified in the list. The +matching of function names is identical to the matching of +@option{-finstrument-functions-exclude-function-list}. For a +combination with @option{-finstrument-functions-include-file-list} or +with options for exclusion see the explanation for +@option{-finstrument-functions-include-file-list}. + +@noindent + @item -fstack-check @opindex fstack-check Generate code to verify that you do not go beyond the boundary of the diff --git a/gcc/gimplify.c b/gcc/gimplify.c index a3ed378..1015fa8 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -11102,34 +11102,55 @@ typedef char *char_p; /* For DEF_VEC_P. */ static bool flag_instrument_functions_exclude_p (tree fndecl) { - vec<char_p> *v; + vec<char_p> *v_efuns; + vec<char_p> *v_efiles; + vec<char_p> *v_ifuns; + vec<char_p> *v_ifiles; - v = (vec<char_p> *) flag_instrument_functions_exclude_functions; - if (v && v->length () > 0) - { - const char *name; - int i; - char *s; + const char *name; + int i; + char *s; + + v_efuns = (vec<char_p> *) flag_instrument_functions_exclude_functions; + if (v_efuns && v_efuns->length () > 0) + { name = lang_hooks.decl_printable_name (fndecl, 0); - FOR_EACH_VEC_ELT (*v, i, s) + FOR_EACH_VEC_ELT (*v_efuns, i, s) if (strstr (name, s) != NULL) return true; } - v = (vec<char_p> *) flag_instrument_functions_exclude_files; - if (v && v->length () > 0) + v_efiles = (vec<char_p> *) flag_instrument_functions_exclude_files; + if (v_efiles && v_efiles->length () > 0) { - const char *name; - int i; - char *s; - name = DECL_SOURCE_FILE (fndecl); - FOR_EACH_VEC_ELT (*v, i, s) + FOR_EACH_VEC_ELT (*v_efiles, i, s) if (strstr (name, s) != NULL) return true; } + v_ifuns = (vec<char_p> *) flag_instrument_functions_include_functions; + if (v_ifuns && v_ifuns->length () > 0) + { + name = lang_hooks.decl_printable_name (fndecl, 0); + FOR_EACH_VEC_ELT (*v_ifuns, i, s) + if (strstr (name, s) != NULL) + return false; + } + + v_ifiles = (vec<char_p> *) flag_instrument_functions_include_files; + if (v_ifiles && v_ifiles->length () > 0) + { + name = DECL_SOURCE_FILE (fndecl); + FOR_EACH_VEC_ELT (*v_ifiles, i, s) + if (strstr (name, s) != NULL) + return false; + } + + if(v_ifuns || v_ifiles) + return true; + return false; } diff --git a/gcc/opts.c b/gcc/opts.c index 874c84f..3c52d98 100644 --- a/gcc/opts.c +++ b/gcc/opts.c @@ -1895,6 +1895,16 @@ common_handle_option (struct gcc_options *opts, (&opts->x_flag_instrument_functions_exclude_files, arg); break; + case OPT_finstrument_functions_include_function_list_: + add_comma_separated_to_vector + (&opts->x_flag_instrument_functions_include_functions, arg); + break; + + case OPT_finstrument_functions_include_file_list_: + add_comma_separated_to_vector + (&opts->x_flag_instrument_functions_include_files, arg); + break; + case OPT_fmessage_length_: pp_set_line_maximum_length (dc->printer, value); diagnostic_set_caret_max_width (dc, value); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index dd7f96a..3601608 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,13 @@ +2015-12-03 Andi Drebes <a...@drebesium.org> + + * gcc.dg/instrument-4.c: New test. + * gcc.dg/instrument-5.c: New test. + * gcc.dg/instrument-6.c: New test. + * gcc.dg/instrument-7.c: New test. + * gcc.dg/instrument-8.c: New test. + * gcc.dg/instrument-9.c: New test. + * gcc.dg/instrument-10.c: New test. + 2015-11-23 Richard Biener <rguent...@suse.de> PR tree-optimization/68465 diff --git a/gcc/testsuite/gcc.dg/instrument-10.c b/gcc/testsuite/gcc.dg/instrument-10.c new file mode 100644 index 0000000..6d0ce69 --- /dev/null +++ b/gcc/testsuite/gcc.dg/instrument-10.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-options "-finstrument-functions -finstrument-functions-include-function-list=otherfile -finstrument-functions-include-function-list=fn" } */ + +__attribute__((no_instrument_function)) void fn () { } + +/* { dg-final { scan-assembler-not "__cyg_profile_func_enter" } } */ +/* { dg-final { scan-assembler-not "__cyg_profile_func_exit" } } */ diff --git a/gcc/testsuite/gcc.dg/instrument-4.c b/gcc/testsuite/gcc.dg/instrument-4.c new file mode 100644 index 0000000..256d207 --- /dev/null +++ b/gcc/testsuite/gcc.dg/instrument-4.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-options "-finstrument-functions -finstrument-functions-include-function-list=fn" } */ + +void fn () { } + +/* { dg-final { scan-assembler "__cyg_profile_func_enter" } } */ +/* { dg-final { scan-assembler "__cyg_profile_func_exit" } } */ diff --git a/gcc/testsuite/gcc.dg/instrument-5.c b/gcc/testsuite/gcc.dg/instrument-5.c new file mode 100644 index 0000000..47d97ae --- /dev/null +++ b/gcc/testsuite/gcc.dg/instrument-5.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-options "-finstrument-functions -finstrument-functions-include-file-list=instrument-5" } */ + +void fn () { } + +/* { dg-final { scan-assembler "__cyg_profile_func_enter" } } */ +/* { dg-final { scan-assembler "__cyg_profile_func_exit" } } */ diff --git a/gcc/testsuite/gcc.dg/instrument-6.c b/gcc/testsuite/gcc.dg/instrument-6.c new file mode 100644 index 0000000..2d29626 --- /dev/null +++ b/gcc/testsuite/gcc.dg/instrument-6.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-options "-finstrument-functions -finstrument-functions-include-function-list=otherfun" } */ + +void fn () { } + +/* { dg-final { scan-assembler-not "__cyg_profile_func_enter" } } */ +/* { dg-final { scan-assembler-not "__cyg_profile_func_exit" } } */ diff --git a/gcc/testsuite/gcc.dg/instrument-7.c b/gcc/testsuite/gcc.dg/instrument-7.c new file mode 100644 index 0000000..15659b8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/instrument-7.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-options "-finstrument-functions -finstrument-functions-include-function-list=fn -finstrument-functions-exclude-function-list=fn" } */ + +void fn () { } + +/* { dg-final { scan-assembler-not "__cyg_profile_func_enter" } } */ +/* { dg-final { scan-assembler-not "__cyg_profile_func_exit" } } */ diff --git a/gcc/testsuite/gcc.dg/instrument-8.c b/gcc/testsuite/gcc.dg/instrument-8.c new file mode 100644 index 0000000..bcc0e18 --- /dev/null +++ b/gcc/testsuite/gcc.dg/instrument-8.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-options "-finstrument-functions -finstrument-functions-include-function-list=fn -finstrument-functions-exclude-file-list=instrument-8" } */ + +void fn () { } + +/* { dg-final { scan-assembler-not "__cyg_profile_func_enter" } } */ +/* { dg-final { scan-assembler-not "__cyg_profile_func_exit" } } */ diff --git a/gcc/testsuite/gcc.dg/instrument-9.c b/gcc/testsuite/gcc.dg/instrument-9.c new file mode 100644 index 0000000..c87aed8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/instrument-9.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-options "-finstrument-functions -finstrument-functions-include-function-list=fn" } */ + +__attribute__((no_instrument_function)) void fn () { } + +/* { dg-final { scan-assembler-not "__cyg_profile_func_enter" } } */ +/* { dg-final { scan-assembler-not "__cyg_profile_func_exit" } } */ -- 2.1.4