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]

RFA: estimate probabilities if profile information not available


As discussed here:
http://gcc.gnu.org/ml/gcc-patches/2004-01/msg02867.html
there are cases when you specifiy -fbranch-probabilities, but no
profile information is available for the file currently being compiled.
This patch uses the probability estimation as a fallback when all the
execution counts are zero.
We could get false positives, of sorts, when a module is completely
unused in the training run.  I think using estimates is still the right
thing then, since the code being compiled might be a module that is
well used in different circumstances.
If the fallback is not desired in special cases, people can switch
it off with -fno-guess-branch-probability.

I've verified that this enables proper branch target load migration for
sh64-elf.
Bootstrapping on i686-pc-linux-gnu.

2004-01-26  J"orn Rennecke <joern.rennecke@superh.com>

	* coverage.c (get_coverage_counts): Give a different message
	if flag_guess_branch_prob is set.
	* predict.c (counts_to_freqs): Return an int.
	(estimate_bb_frequencies): If counts_to_freqs returns zero,
	calculate estimates.

Index: coverage.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/coverage.c,v
retrieving revision 1.28
diff -p -r1.28 coverage.c
*** coverage.c	18 Jan 2004 15:10:23 -0000	1.28
--- coverage.c	26 Jan 2004 15:44:56 -0000
*************** get_coverage_counts (unsigned counter, u
*** 316,322 ****
        static int warned = 0;
  
        if (!warned++)
! 	inform ("file %s not found, execution counts assumed to be zero",
  		da_file_name);
        return NULL;
      }
--- 316,324 ----
        static int warned = 0;
  
        if (!warned++)
! 	inform ((flag_guess_branch_prob
! 		 ? "file %s not found, execution counts estimated"
! 		 : "file %s not found, execution counts assumed to be zero"),
  		da_file_name);
        return NULL;
      }
Index: predict.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/predict.c,v
retrieving revision 1.98
diff -p -r1.98 predict.c
*** predict.c	16 Jan 2004 01:44:06 -0000	1.98
--- predict.c	26 Jan 2004 15:44:56 -0000
*************** static void dump_prediction (enum br_pre
*** 71,77 ****
  static void estimate_loops_at_level (struct loop *loop);
  static void propagate_freq (struct loop *);
  static void estimate_bb_frequencies (struct loops *);
! static void counts_to_freqs (void);
  static void process_note_predictions (basic_block, int *);
  static void process_note_prediction (basic_block, int *, int, int);
  static bool last_basic_block_p (basic_block);
--- 71,77 ----
  static void estimate_loops_at_level (struct loop *loop);
  static void propagate_freq (struct loop *);
  static void estimate_bb_frequencies (struct loops *);
! static int counts_to_freqs (void);
  static void process_note_predictions (basic_block, int *);
  static void process_note_prediction (basic_block, int *, int, int);
  static bool last_basic_block_p (basic_block);
*************** estimate_loops_at_level (struct loop *fi
*** 1048,1066 ****
      }
  }
  
! /* Convert counts measured by profile driven feedback to frequencies.  */
  
! static void
  counts_to_freqs (void)
  {
!   gcov_type count_max = 1;
    basic_block bb;
  
    FOR_EACH_BB (bb)
!     count_max = MAX (bb->count, count_max);
  
    FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, NULL, next_bb)
      bb->frequency = (bb->count * BB_FREQ_MAX + count_max / 2) / count_max;
  }
  
  /* Return true if function is likely to be expensive, so there is no point to
--- 1048,1069 ----
      }
  }
  
! /* Convert counts measured by profile driven feedback to frequencies.
!    Return nonzero iff there was any nonzero execution count.  */
  
! static int
  counts_to_freqs (void)
  {
!   gcov_type count_max, true_count_max = 0;
    basic_block bb;
  
    FOR_EACH_BB (bb)
!     count_max = MAX (bb->count, true_count_max);
  
+   count_max = MAX (true_count_max, 1);
    FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, NULL, next_bb)
      bb->frequency = (bb->count * BB_FREQ_MAX + count_max / 2) / count_max;
+   return true_count_max;
  }
  
  /* Return true if function is likely to be expensive, so there is no point to
*************** estimate_bb_frequencies (struct loops *l
*** 1113,1121 ****
    basic_block bb;
    sreal freq_max;
  
!   if (flag_branch_probabilities)
!     counts_to_freqs ();
!   else
      {
        static int real_values_initialized = 0;
  
--- 1116,1122 ----
    basic_block bb;
    sreal freq_max;
  
!   if (! flag_branch_probabilities || ! counts_to_freqs ())
      {
        static int real_values_initialized = 0;
  


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]