On 7/17/19 1:55 AM, Martin Liška wrote: > On 7/17/19 7:44 AM, luoxhu wrote: >> Hi Martin, >> Thanks for your review, v4 Changes as below: >> 1. Use decrease bubble sort. >> BTW, I have a question about hist->hvalue.counters[2], when will it become >> -1, please? Thanks. Currently, if it is -1, the function will return false. > Hi. > > Thanks for that. I made a minor changes to your patch, please see it in > attachment. > -1 is a value that we use for invalidated histogram. That happens when you > need > to fit in more values during instrumentation than you have counters in the > histogram. > It helps to make reproducible builds of a software. > > Martin > > > most-common-value.patch > > diff --git a/gcc/profile.c b/gcc/profile.c > index 441cb8eb183..1151b491848 100644 > --- a/gcc/profile.c > +++ b/gcc/profile.c > @@ -743,6 +743,44 @@ compute_branch_probabilities (unsigned cfg_checksum, > unsigned lineno_checksum) > free_aux_for_blocks (); > } > > +/* Sort the histogram value and count for TOPN and INDIR_CALL types. */ > + > +static void > +sort_hist_values (histogram_value hist) > +{ > + /* counters[2] equal to -1 means that all counters are invalidated. */ > + if (hist->hvalue.counters[2] == -1) > + return; > + > + gcc_assert (hist->type == HIST_TYPE_TOPN_VALUES > + || hist->type == HIST_TYPE_INDIR_CALL); > + > + gcc_assert (hist->n_counters == GCOV_TOPN_VALUES_COUNTERS); > + > + /* Hist value is organized as: > + [total_executions, value1, counter1, ..., value4, counter4] > + Use decrese bubble sort to rearrange it. The sort starts from <value1, s/decrese/decrease/
OK with that nit fixed. jeff