diff --git a/gcc/common.opt b/gcc/common.opt index ebc3ef4..d93ddca 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -811,6 +811,10 @@ Wcoverage-mismatch Common Var(warn_coverage_mismatch) Init(1) Warning Warn in case profiles in -fprofile-use do not match. +Wmissing-profile +Common Var(warn_missing_profile) Init(1) Warning +Warn in case profiles in -fprofile-use do not exist. + Wvector-operation-performance Common Var(warn_vector_operation_performance) Warning Warn when a vector operation is compiled outside the SIMD. diff --git a/gcc/coverage.c b/gcc/coverage.c index bae6f5c..df031df 100644 --- a/gcc/coverage.c +++ b/gcc/coverage.c @@ -341,16 +341,24 @@ get_coverage_counts (unsigned counter, unsigned expected, { static int warned = 0; - if (!warned++ && dump_enabled_p ()) + if (!warned++) { - dump_user_location_t loc - = dump_user_location_t::from_location_t (input_location); - dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, loc, + warning (OPT_Wmissing_profile, + "%qs profile count data file not found," + " regenerating profiles may help", + da_file_name); + if (dump_enabled_p ()) + { + dump_user_location_t loc + = dump_user_location_t::from_location_t (input_location); + dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, loc, + "file %s not found\n", + da_file_name); + dump_printf (MSG_OPTIMIZED_LOCATIONS, (flag_guess_branch_prob - ? "file %s not found, execution counts estimated\n" - : "file %s not found, execution counts assumed to " - "be zero\n"), - da_file_name); + ? "execution counts estimated\n" + : "execution counts assumed to be zero\n")); + } } return NULL; } diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index ca92028..e62bcae 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -314,7 +314,7 @@ Objective-C and Objective-C++ Dialects}. -Wlogical-op -Wlogical-not-parentheses -Wlong-long @gol -Wmain -Wmaybe-uninitialized -Wmemset-elt-size -Wmemset-transposed-args @gol -Wmisleading-indentation -Wmissing-attributes -Wmissing-braces @gol --Wmissing-field-initializers -Wmissing-include-dirs @gol +-Wmissing-field-initializers -Wmissing-include-dirs -Wmissing-profile @gol -Wno-multichar -Wmultistatement-macros -Wnonnull -Wnonnull-compare @gol -Wnormalized=@r{[}none@r{|}id@r{|}nfc@r{|}nfkc@r{]} @gol -Wnull-dereference -Wodr -Wno-overflow -Wopenmp-simd @gol @@ -4816,6 +4816,25 @@ This warning is enabled by @option{-Wall}. @opindex Wno-missing-include-dirs Warn if a user-supplied include directory does not exist. +@item -Wmissing-profile +@opindex Wmissing-profile +@opindex Wno-missing-profile +Warn if feedback profiles are missing when using the +@option{-fprofile-use} option. +If a new function or a new file is added to the user code between compiling +with @option{-fprofile-gen} and with @option{-fprofile-use} without +regenerating the profiles, the profile feedback data files do not contain any +profile feedback information for the newly +added function or file respectively. Also, in the case when profile count data +(.gcda) files are wiped out, GCC cannot use any profile feedback +information. In all these cases, warnings are issued to inform the user that a +profile generation step is due. By default, this warning is enabled and is +treated as an error. @option{-Wno-missing-profile} can be used to disable the +warning or @option{-Wno-error=missing-profile} can be used to disable the +error. Disabling the error for this warning can result in poorly optimized +code and is useful only in the cases when non-existent profile data is +justified. Completely disabling the warning is not recommended. + @item -Wmultistatement-macros @opindex Wmultistatement-macros @opindex Wno-multistatement-macros @@ -9899,8 +9918,10 @@ Before you can use this option, you must first generate profiling information. By default, GCC emits an error message if the feedback profiles do not match the source code. This error can be turned into a warning by using -@option{-Wcoverage-mismatch}. Note this may result in poorly optimized -code. +@option{-Wno-error=coverage-mismatch}. Note this may result in poorly +optimized code. Additionally, by default, GCC also emits an error message if +the feedback profiles do not exist. The latter error can be turned into a +warning by using @option{-Wno-error=missing-profile}. If @var{path} is specified, GCC looks at the @var{path} to find the profile feedback data files. See @option{-fprofile-dir}. diff --git a/gcc/profile.c b/gcc/profile.c index cb51e0d..40f9763 100644 --- a/gcc/profile.c +++ b/gcc/profile.c @@ -286,7 +286,13 @@ get_exec_counts (unsigned cfg_checksum, unsigned lineno_checksum) counts = get_coverage_counts (GCOV_COUNTER_ARCS, num_edges, cfg_checksum, lineno_checksum, &profile_info); if (!counts) - return NULL; + { + warning (OPT_Wmissing_profile, + "profile for function %qE not found in profile data," + " regenerating profiles may help", + DECL_ASSEMBLER_NAME (current_function_decl)); + return NULL; + } get_working_sets (); diff --git a/gcc/toplev.c b/gcc/toplev.c index 9fb83d4..5891554 100644 --- a/gcc/toplev.c +++ b/gcc/toplev.c @@ -1782,14 +1782,24 @@ process_options (void) || !targetm.have_prologue () || !targetm.have_epilogue ()) flag_ipa_ra = 0; - /* Enable -Werror=coverage-mismatch when -Werror and -Wno-error - have not been set. */ - if (!global_options_set.x_warnings_are_errors - && warn_coverage_mismatch - && (global_dc->classify_diagnostic[OPT_Wcoverage_mismatch] == - DK_UNSPECIFIED)) - diagnostic_classify_diagnostic (global_dc, OPT_Wcoverage_mismatch, - DK_ERROR, UNKNOWN_LOCATION); + if (!global_options_set.x_warnings_are_errors) + { + /* Enable -Werror=coverage-mismatch when -Werror and -Wno-error + have not been set. */ + if (warn_coverage_mismatch + && (global_dc->classify_diagnostic[OPT_Wcoverage_mismatch] == + DK_UNSPECIFIED)) + diagnostic_classify_diagnostic (global_dc, OPT_Wcoverage_mismatch, + DK_ERROR, UNKNOWN_LOCATION); + + /* Enable -Werror=missing-profile when -Werror and -Wno-error + have not been set. */ + if (warn_missing_profile + && (global_dc->classify_diagnostic[OPT_Wmissing_profile] == + DK_UNSPECIFIED)) + diagnostic_classify_diagnostic (global_dc, OPT_Wmissing_profile, + DK_ERROR, UNKNOWN_LOCATION); + } /* Save the current optimization options. */ optimization_default_node = build_optimization_node (&global_options);