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]

Minor cleanups in predict.c


I did this about a week ago and haven't gotten a chance to check it in
until now.  This fixes a number of whitespace problems and also does a general
cleanup of code, making minor changes for clarity.  Not everything changes
here is in the coding standards, but it makes the code a bit more
consistent with the rest of GCC.

No functional changes are in this patch, but it was checked on
alphaev56-dec-osf4.0c wiht other changes just in case.

Sat Dec 22 08:59:50 2001  Richard Kenner  <kenner@vlsi1.ultra.nyu.edu>

	* predict.c: Reformatting and minor cleanups.

*** predict.c	2001/12/14 21:28:49	1.50
--- predict.c	2001/12/22 15:13:01
***************
*** 2,21 ****
     Copyright (C) 2000, 2001 Free Software Foundation, Inc.
  
!    This file is part of GCC.
  
!    GCC is free software; you can redistribute it and/or modify it
!    under the terms of the GNU General Public License as published by
!    the Free Software Foundation; either version 2, or (at your option)
!    any later version.
! 
!    GCC is distributed in the hope that it will be useful, but WITHOUT
!    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
!    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
!    License for more details.
! 
!    You should have received a copy of the GNU General Public License
!    along with GCC; see the file COPYING.  If not, write to the Free
!    Software Foundation, 59 Temple Place - Suite 330, Boston, MA
!    02111-1307, USA.  */
  
  /* References:
--- 2,21 ----
     Copyright (C) 2000, 2001 Free Software Foundation, Inc.
  
! This file is part of GCC.
  
! GCC is free software; you can redistribute it and/or modify it under
! the terms of the GNU General Public License as published by the Free
! Software Foundation; either version 2, or (at your option) any later
! version.
! 
! GCC is distributed in the hope that it will be useful, but WITHOUT ANY
! WARRANTY; without even the implied warranty of MERCHANTABILITY or
! FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
! for more details.
! 
! You should have received a copy of the GNU General Public License
! along with GCC; see the file COPYING.  If not, write to the Free
! Software Foundation, 59 Temple Place - Suite 330, Boston, MA
! 02111-1307, USA.  */
  
  /* References:
***************
*** 26,34 ****
         Wu and Larus; MICRO-27.
     [3] "Corpus-based Static Branch Prediction"
!        Calder, Grunwald, Lindsay, Martin, Mozer, and Zorn; PLDI '95.
  
- */
  
- 
  #include "config.h"
  #include "system.h"
--- 26,32 ----
         Wu and Larus; MICRO-27.
     [3] "Corpus-based Static Branch Prediction"
!        Calder, Grunwald, Lindsay, Martin, Mozer, and Zorn; PLDI '95.   */
  
  
  #include "config.h"
  #include "system.h"
*************** static void counts_to_freqs		 PARAMS ((v
*** 68,71 ****
--- 66,70 ----
  /* Information we hold about each branch predictor.
     Filled using information from predict.def.  */
+ 
  struct predictor_info
  {
*************** struct predictor_info
*** 82,89 ****
  /* Recompute hitrate in percent to our representation.  */
  
! #define HITRATE(VAL) ((int)((VAL) * REG_BR_PROB_BASE + 50) / 100)
  
  #define DEF_PREDICTOR(ENUM, NAME, HITRATE, FLAGS) {NAME, HITRATE, FLAGS},
! static const struct predictor_info predictor_info[] = {
  #include "predict.def"
  
--- 81,88 ----
  /* Recompute hitrate in percent to our representation.  */
  
! #define HITRATE(VAL) ((int) ((VAL) * REG_BR_PROB_BASE + 50) / 100)
  
  #define DEF_PREDICTOR(ENUM, NAME, HITRATE, FLAGS) {NAME, HITRATE, FLAGS},
! static const struct predictor_info predictor_info[]= {
  #include "predict.def"
  
*************** predict_insn (insn, predictor, probabili
*** 101,104 ****
--- 100,104 ----
    if (!any_condjump_p (insn))
      abort ();
+ 
    REG_NOTES (insn)
      = gen_rtx_EXPR_LIST (REG_BR_PRED,
*************** predict_insn (insn, predictor, probabili
*** 110,113 ****
--- 110,114 ----
  
  /* Predict insn by given predictor.  */
+ 
  void
  predict_insn_def (insn, predictor, taken)
*************** predict_insn_def (insn, predictor, taken
*** 117,126 ****
--- 118,130 ----
  {
     int probability = predictor_info[(int) predictor].hitrate;
+ 
     if (taken != TAKEN)
       probability = REG_BR_PROB_BASE - probability;
+ 
     predict_insn (insn, predictor, probability);
  }
  
  /* Predict edge E with given probability if possible.  */
+ 
  void
  predict_edge (e, predictor, probability)
*************** predict_edge (e, predictor, probability)
*** 145,148 ****
--- 149,153 ----
  
  /* Predict edge E by given predictor if possible.  */
+ 
  void
  predict_edge_def (e, predictor, taken)
*************** predict_edge_def (e, predictor, taken)
*** 155,158 ****
--- 160,164 ----
     if (taken != TAKEN)
       probability = REG_BR_PROB_BASE - probability;
+ 
     predict_edge (e, predictor, probability);
  }
*************** predict_edge_def (e, predictor, taken)
*** 160,181 ****
  /* Invert all branch predictions or probability notes in the INSN.  This needs
     to be done each time we invert the condition used by the jump.  */
  void
  invert_br_probabilities (insn)
       rtx insn;
  {
!   rtx note = REG_NOTES (insn);
  
!   while (note)
!     {
!       if (REG_NOTE_KIND (note) == REG_BR_PROB)
! 	XEXP (note, 0) = GEN_INT (REG_BR_PROB_BASE - INTVAL (XEXP (note, 0)));
!       else if (REG_NOTE_KIND (note) == REG_BR_PRED)
! 	XEXP (XEXP (note, 0), 1)
! 	  = GEN_INT (REG_BR_PROB_BASE - INTVAL (XEXP (XEXP (note, 0), 1)));
!       note = XEXP (note, 1);
!     }
  }
  
  /* Dump information about the branch prediction to the output file.  */
  static void
  dump_prediction (predictor, probability, bb, used)
--- 166,186 ----
  /* Invert all branch predictions or probability notes in the INSN.  This needs
     to be done each time we invert the condition used by the jump.  */
+ 
  void
  invert_br_probabilities (insn)
       rtx insn;
  {
!   rtx note;
  
!   for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
!     if (REG_NOTE_KIND (note) == REG_BR_PROB)
!       XEXP (note, 0) = GEN_INT (REG_BR_PROB_BASE - INTVAL (XEXP (note, 0)));
!     else if (REG_NOTE_KIND (note) == REG_BR_PRED)
!       XEXP (XEXP (note, 0), 1)
! 	= GEN_INT (REG_BR_PROB_BASE - INTVAL (XEXP (XEXP (note, 0), 1)));
  }
  
  /* Dump information about the branch prediction to the output file.  */
+ 
  static void
  dump_prediction (predictor, probability, bb, used)
*************** dump_prediction (predictor, probability,
*** 195,212 ****
    fprintf (rtl_dump_file, "  %s heuristics%s: %.1f%%",
  	   predictor_info[predictor].name,
! 	   used ? "" : " (ignored)",
! 	   probability * 100.0 / REG_BR_PROB_BASE);
  
    if (bb->count)
      {
        fprintf (rtl_dump_file, "  exec ");
!       fprintf (rtl_dump_file, HOST_WIDEST_INT_PRINT_DEC,
! 	       (HOST_WIDEST_INT) bb->count);
        fprintf (rtl_dump_file, " hit ");
!       fprintf (rtl_dump_file, HOST_WIDEST_INT_PRINT_DEC,
! 	       (HOST_WIDEST_INT) e->count);
!       fprintf (rtl_dump_file, " (%.1f%%)",
! 	       e->count * 100.0 / bb->count);
      }
    fprintf (rtl_dump_file, "\n");
  }
--- 200,214 ----
    fprintf (rtl_dump_file, "  %s heuristics%s: %.1f%%",
  	   predictor_info[predictor].name,
! 	   used ? "" : " (ignored)", probability * 100.0 / REG_BR_PROB_BASE);
  
    if (bb->count)
      {
        fprintf (rtl_dump_file, "  exec ");
!       fprintf (rtl_dump_file, HOST_WIDEST_INT_PRINT_DEC, bb->count);
        fprintf (rtl_dump_file, " hit ");
!       fprintf (rtl_dump_file, HOST_WIDEST_INT_PRINT_DEC, e->count);
!       fprintf (rtl_dump_file, " (%.1f%%)", e->count * 100.0 / bb->count);
      }
+ 
    fprintf (rtl_dump_file, "\n");
  }
*************** dump_prediction (predictor, probability,
*** 214,217 ****
--- 216,220 ----
  /* Combine all REG_BR_PRED notes into single probability and attach REG_BR_PROB
     note if not already present.  Remove now useless REG_BR_PRED notes.  */
+ 
  static void
  combine_predictions_for_insn (insn, bb)
*************** combine_predictions_for_insn (insn, bb)
*** 221,225 ****
    rtx prob_note = find_reg_note (insn, REG_BR_PROB, 0);
    rtx *pnote = &REG_NOTES (insn);
!   rtx note = REG_NOTES (insn);
    int best_probability = PROB_EVEN;
    int best_predictor = END_PREDICTORS;
--- 224,228 ----
    rtx prob_note = find_reg_note (insn, REG_BR_PROB, 0);
    rtx *pnote = &REG_NOTES (insn);
!   rtx note;
    int best_probability = PROB_EVEN;
    int best_predictor = END_PREDICTORS;
*************** combine_predictions_for_insn (insn, bb)
*** 236,262 ****
       by predictor with smallest index.  In the future we will use better
       probability combination techniques.  */
!   while (note)
!     {
!       if (REG_NOTE_KIND (note) == REG_BR_PRED)
! 	{
! 	  int predictor = INTVAL (XEXP (XEXP (note, 0), 0));
! 	  int probability = INTVAL (XEXP (XEXP (note, 0), 1));
! 
! 	  found = true;
! 	  if (best_predictor > predictor)
! 	    best_probability = probability, best_predictor = predictor;
  
! 	  d = (combined_probability * probability
! 	       + (REG_BR_PROB_BASE - combined_probability)
! 	       * (REG_BR_PROB_BASE - probability));
! 	  /* An FP math to avoid overflows of 32bit integers.  */
! 	  combined_probability = (((double)combined_probability) * probability
! 				  * REG_BR_PROB_BASE / d + 0.5);
! 	}
!       note = XEXP (note, 1);
!     }
! 
!   /* Decide heuristic to use.  In case we didn't match anything, use
!      no_prediction heuristic, in case we did match, use either
       first match or Dempster-Shaffer theory depending on the flags.  */
  
--- 239,263 ----
       by predictor with smallest index.  In the future we will use better
       probability combination techniques.  */
!   for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
!     if (REG_NOTE_KIND (note) == REG_BR_PRED)
!       {
! 	int predictor = INTVAL (XEXP (XEXP (note, 0), 0));
! 	int probability = INTVAL (XEXP (XEXP (note, 0), 1));
! 
! 	found = true;
! 	if (best_predictor > predictor)
! 	  best_probability = probability, best_predictor = predictor;
! 
! 	d = (combined_probability * probability
! 	     + (REG_BR_PROB_BASE - combined_probability)
! 	     * (REG_BR_PROB_BASE - probability));
! 
! 	/* Use FP math to avoid overflows of 32bit integers.  */
! 	combined_probability = (((double) combined_probability) * probability
! 				* REG_BR_PROB_BASE / d + 0.5);
!       }
  
!   /* Decide which heuristic to use.  In case we didn't match anything,
!      use no_prediction heuristic, in case we did match, use either
       first match or Dempster-Shaffer theory depending on the flags.  */
  
*************** combine_predictions_for_insn (insn, bb)
*** 268,273 ****
    else
      {
!       dump_prediction (PRED_DS_THEORY, combined_probability, bb,
! 		       !first_match);
        dump_prediction (PRED_FIRST_MATCH, best_probability, bb, first_match);
      }
--- 269,273 ----
    else
      {
!       dump_prediction (PRED_DS_THEORY, combined_probability, bb, !first_match);
        dump_prediction (PRED_FIRST_MATCH, best_probability, bb, first_match);
      }
*************** combine_predictions_for_insn (insn, bb)
*** 291,294 ****
--- 291,295 ----
          pnote = &XEXP (*pnote, 1);
      }
+ 
    if (!prob_note)
      {
*************** combine_predictions_for_insn (insn, bb)
*** 296,299 ****
--- 297,301 ----
  	= gen_rtx_EXPR_LIST (REG_BR_PROB,
  			     GEN_INT (combined_probability), REG_NOTES (insn));
+ 
        /* Save the prediction into CFG in case we are seeing non-degenerated
  	 conditional jump.  */
*************** combine_predictions_for_insn (insn, bb)
*** 301,305 ****
  	{
  	  BRANCH_EDGE (bb)->probability = combined_probability;
! 	  FALLTHRU_EDGE (bb)->probability = REG_BR_PROB_BASE - combined_probability;
  	}
      }
--- 303,308 ----
  	{
  	  BRANCH_EDGE (bb)->probability = combined_probability;
! 	  FALLTHRU_EDGE (bb)->probability
! 	    = REG_BR_PROB_BASE - combined_probability;
  	}
      }
*************** estimate_probability (loops_info)
*** 336,370 ****
        exits = loop->num_exits;
  
!       for (j = loop->first->index;
! 	   j <= loop->last->index;
! 	   ++j)
! 	{
! 	  if (TEST_BIT (loop->nodes, j))
! 	    {
! 	      int header_found = 0;
! 	      edge e;
  
! 	      /* Loop branch heuristics - predict as taken an edge back to
! 	         a loop's head.  */
  	      for (e = BASIC_BLOCK(j)->succ; e; e = e->succ_next)
! 		if (e->dest == loop->header
! 		    && e->src == loop->latch)
! 		  {
! 		    header_found = 1;
! 		    predict_edge_def (e, PRED_LOOP_BRANCH, TAKEN);
! 		  }
! 	      /* Loop exit heuristics - predict as not taken an edge
! 	         exiting the loop if the conditinal has no loop header
! 	         successors.  */
! 	      if (!header_found)
! 		for (e = BASIC_BLOCK(j)->succ; e; e = e->succ_next)
! 		  if (e->dest->index < 0
! 		      || !TEST_BIT (loop->nodes, e->dest->index))
! 		    predict_edge (e, PRED_LOOP_EXIT,
! 				  (REG_BR_PROB_BASE
! 				   - predictor_info [(int)PRED_LOOP_EXIT].hitrate)
! 				  / exits);
! 	    }
! 	}
      }
  
--- 339,370 ----
        exits = loop->num_exits;
  
!       for (j = loop->first->index; j <= loop->last->index; ++j)
! 	if (TEST_BIT (loop->nodes, j))
! 	  {
! 	    int header_found = 0;
! 	    edge e;
  
! 	    /* Loop branch heuristics - predict an edge back to a
! 	       loop's head as taken.  */
! 	    for (e = BASIC_BLOCK(j)->succ; e; e = e->succ_next)
! 	      if (e->dest == loop->header
! 		  && e->src == loop->latch)
! 		{
! 		  header_found = 1;
! 		  predict_edge_def (e, PRED_LOOP_BRANCH, TAKEN);
! 		}
! 
! 	    /* Loop exit heuristics - predict an edge exiting the loop if the
! 	       conditinal has no loop header successors as not taken.  */
! 	    if (!header_found)
  	      for (e = BASIC_BLOCK(j)->succ; e; e = e->succ_next)
! 		if (e->dest->index < 0
! 		    || !TEST_BIT (loop->nodes, e->dest->index))
! 		  predict_edge
! 		    (e, PRED_LOOP_EXIT,
! 		     (REG_BR_PROB_BASE
! 		      - predictor_info [(int)PRED_LOOP_EXIT].hitrate)
! 		     / exits);
! 	  }
      }
  
*************** estimate_probability (loops_info)
*** 377,383 ****
        edge e;
  
!       /* If block has no successor, predict all possible paths to
!          it as improbable, as the block contains a call to a noreturn
! 	 function and thus can be executed only once.  */
        if (bb->succ == NULL && !found_noreturn)
  	{
--- 377,383 ----
        edge e;
  
!       /* If block has no successor, predict all possible paths to it as
!          improbable, as the block contains a call to a noreturn function and
!          thus can be executed only once.  */
        if (bb->succ == NULL && !found_noreturn)
  	{
*************** estimate_probability (loops_info)
*** 386,404 ****
  	  /* ??? Postdominator claims each noreturn block to be postdominated
  	     by each, so we need to run only once.  This needs to be changed
! 	     once postdominace algorithm is updated to say something more sane.
! 	     */
  	  found_noreturn = 1;
  	  for (y = 0; y < n_basic_blocks; y++)
  	    if (!TEST_BIT (post_dominators[y], i))
! 	      {
! 		for (e = BASIC_BLOCK (y)->succ; e; e = e->succ_next)
  		if (e->dest->index >= 0
  		    && TEST_BIT (post_dominators[e->dest->index], i))
  		  predict_edge_def (e, PRED_NORETURN, NOT_TAKEN);
- 	      }
  	}
  
!       if (GET_CODE (last_insn) != JUMP_INSN
! 	  || ! any_condjump_p (last_insn))
  	continue;
  
--- 386,401 ----
  	  /* ??? Postdominator claims each noreturn block to be postdominated
  	     by each, so we need to run only once.  This needs to be changed
! 	     once postdominace algorithm is updated to say something more
! 	     sane. */
  	  found_noreturn = 1;
  	  for (y = 0; y < n_basic_blocks; y++)
  	    if (!TEST_BIT (post_dominators[y], i))
! 	      for (e = BASIC_BLOCK (y)->succ; e; e = e->succ_next)
  		if (e->dest->index >= 0
  		    && TEST_BIT (post_dominators[e->dest->index], i))
  		  predict_edge_def (e, PRED_NORETURN, NOT_TAKEN);
  	}
  
!       if (GET_CODE (last_insn) != JUMP_INSN || ! any_condjump_p (last_insn))
  	continue;
  
*************** estimate_probability (loops_info)
*** 414,423 ****
  	  /* Look for block we are guarding (ie we dominate it,
  	     but it doesn't postdominate us).  */
! 	  if (e->dest != EXIT_BLOCK_PTR
! 	      && e->dest != bb
  	      && TEST_BIT (dominators[e->dest->index], e->src->index)
  	      && !TEST_BIT (post_dominators[e->src->index], e->dest->index))
  	    {
  	      rtx insn;
  	      /* The call heuristic claims that a guarded function call
  		 is improbable.  This is because such calls are often used
--- 411,420 ----
  	  /* Look for block we are guarding (ie we dominate it,
  	     but it doesn't postdominate us).  */
! 	  if (e->dest != EXIT_BLOCK_PTR && e->dest != bb
  	      && TEST_BIT (dominators[e->dest->index], e->src->index)
  	      && !TEST_BIT (post_dominators[e->src->index], e->dest->index))
  	    {
  	      rtx insn;
+ 
  	      /* The call heuristic claims that a guarded function call
  		 is improbable.  This is because such calls are often used
*************** estimate_probability (loops_info)
*** 447,462 ****
  	  && ((REG_P (XEXP (cond, 0)) && REG_POINTER (XEXP (cond, 0)))
  	      || (REG_P (XEXP (cond, 1)) && REG_POINTER (XEXP (cond, 1)))))
! 	switch (GET_CODE (cond))
! 	  {
! 	  case EQ:
  	    predict_insn_def (last_insn, PRED_POINTER, NOT_TAKEN);
! 	    break;
! 	  case NE:
  	    predict_insn_def (last_insn, PRED_POINTER, TAKEN);
! 	    break;
! 	  default:
! 	    break;
! 	  }
        else
        /* Try "opcode heuristic."
  	 EQ tests are usually false and NE tests are usually true. Also,
--- 444,455 ----
  	  && ((REG_P (XEXP (cond, 0)) && REG_POINTER (XEXP (cond, 0)))
  	      || (REG_P (XEXP (cond, 1)) && REG_POINTER (XEXP (cond, 1)))))
! 	{
! 	  if (GET_CODE (cond) == EQ)
  	    predict_insn_def (last_insn, PRED_POINTER, NOT_TAKEN);
! 	  else if (GET_CODE (cond) == NE)
  	    predict_insn_def (last_insn, PRED_POINTER, TAKEN);
! 	}
        else
+ 
        /* Try "opcode heuristic."
  	 EQ tests are usually false and NE tests are usually true. Also,
*************** estimate_probability (loops_info)
*** 480,488 ****
  	    /* Comparisons with 0 are often used for booleans and there is
  	       nothing usefull to predict about them.  */
! 	    else if (XEXP (cond, 1) == const0_rtx || XEXP (cond, 0) == const0_rtx)
  	      ;
  	    else
  	      predict_insn_def (last_insn, PRED_OPCODE_NONEQUAL, NOT_TAKEN);
  	    break;
  	  case NE:
  	  case LTGT:
--- 473,483 ----
  	    /* Comparisons with 0 are often used for booleans and there is
  	       nothing usefull to predict about them.  */
! 	    else if (XEXP (cond, 1) == const0_rtx
! 		     || XEXP (cond, 0) == const0_rtx)
  	      ;
  	    else
  	      predict_insn_def (last_insn, PRED_OPCODE_NONEQUAL, NOT_TAKEN);
  	    break;
+ 
  	  case NE:
  	  case LTGT:
*************** estimate_probability (loops_info)
*** 494,508 ****
  	    /* Comparisons with 0 are often used for booleans and there is
  	       nothing usefull to predict about them.  */
! 	    else if (XEXP (cond, 1) == const0_rtx || XEXP (cond, 0) == const0_rtx)
  	      ;
  	    else
  	      predict_insn_def (last_insn, PRED_OPCODE_NONEQUAL, TAKEN);
  	    break;
  	  case ORDERED:
  	    predict_insn_def (last_insn, PRED_FPOPCODE, TAKEN);
  	    break;
  	  case UNORDERED:
  	    predict_insn_def (last_insn, PRED_FPOPCODE, NOT_TAKEN);
  	    break;
  	  case LE:
  	  case LT:
--- 489,507 ----
  	    /* Comparisons with 0 are often used for booleans and there is
  	       nothing usefull to predict about them.  */
! 	    else if (XEXP (cond, 1) == const0_rtx
! 		     || XEXP (cond, 0) == const0_rtx)
  	      ;
  	    else
  	      predict_insn_def (last_insn, PRED_OPCODE_NONEQUAL, TAKEN);
  	    break;
+ 
  	  case ORDERED:
  	    predict_insn_def (last_insn, PRED_FPOPCODE, TAKEN);
  	    break;
+ 
  	  case UNORDERED:
  	    predict_insn_def (last_insn, PRED_FPOPCODE, NOT_TAKEN);
  	    break;
+ 
  	  case LE:
  	  case LT:
*************** estimate_probability (loops_info)
*** 511,514 ****
--- 510,514 ----
  	      predict_insn_def (last_insn, PRED_OPCODE_POSITIVE, NOT_TAKEN);
  	    break;
+ 
  	  case GE:
  	  case GT:
*************** estimate_probability (loops_info)
*** 525,536 ****
    /* Attach the combined probability to each conditional jump.  */
    for (i = 0; i < n_basic_blocks; i++)
!     {
!       rtx last_insn = BLOCK_END (i);
  
-       if (GET_CODE (last_insn) != JUMP_INSN
- 	  || ! any_condjump_p (last_insn))
- 	continue;
-       combine_predictions_for_insn (last_insn, BASIC_BLOCK (i));
-     }
    sbitmap_vector_free (post_dominators);
    sbitmap_vector_free (dominators);
--- 525,532 ----
    /* Attach the combined probability to each conditional jump.  */
    for (i = 0; i < n_basic_blocks; i++)
!     if (GET_CODE (BLOCK_END (i)) == JUMP_INSN
! 	&& any_condjump_p (BLOCK_END (i)))
!       combine_predictions_for_insn (BLOCK_END (i), BASIC_BLOCK (i));
  
    sbitmap_vector_free (post_dominators);
    sbitmap_vector_free (dominators);
*************** estimate_probability (loops_info)
*** 539,545 ****
  }
  
! /* __builtin_expect dropped tokens into the insn stream describing
!    expected values of registers.  Generate branch probabilities
!    based off these values.  */
  
  void
--- 535,541 ----
  }
  
! /* __builtin_expect dropped tokens into the insn stream describing expected
!    values of registers.  Generate branch probabilities based off these
!    values.  */
  
  void
*************** expected_value_to_br_prob ()
*** 567,584 ****
  	  continue;
  
- 	default:
- 	  /* Look for insns that clobber the EV register.  */
- 	  if (ev && reg_set_p (ev_reg, insn))
- 	    ev = NULL_RTX;
- 	  continue;
- 
  	case JUMP_INSN:
  	  /* Look for simple conditional branches.  If we haven't got an
  	     expected value yet, no point going further.  */
! 	  if (GET_CODE (insn) != JUMP_INSN || ev == NULL_RTX)
! 	    continue;
! 	  if (! any_condjump_p (insn))
  	    continue;
  	  break;
  	}
  
--- 563,579 ----
  	  continue;
  
  	case JUMP_INSN:
  	  /* Look for simple conditional branches.  If we haven't got an
  	     expected value yet, no point going further.  */
! 	  if (GET_CODE (insn) != JUMP_INSN || ev == NULL_RTX
! 	      || ! any_condjump_p (insn))
  	    continue;
  	  break;
+ 
+ 	default:
+ 	  /* Look for insns that clobber the EV register.  */
+ 	  if (ev && reg_set_p (ev_reg, insn))
+ 	    ev = NULL_RTX;
+ 	  continue;
  	}
  
*************** expected_value_to_br_prob ()
*** 594,599 ****
        cond = XEXP (SET_SRC (pc_set (insn)), 0);
        cond = canonicalize_condition (insn, cond, 0, NULL, ev_reg);
!       if (! cond
! 	  || XEXP (cond, 0) != ev_reg
  	  || GET_CODE (XEXP (cond, 1)) != CONST_INT)
  	continue;
--- 589,593 ----
        cond = XEXP (SET_SRC (pc_set (insn)), 0);
        cond = canonicalize_condition (insn, cond, 0, NULL, ev_reg);
!       if (! cond || XEXP (cond, 0) != ev_reg
  	  || GET_CODE (XEXP (cond, 1)) != CONST_INT)
  	continue;
*************** typedef struct edge_info_def
*** 651,654 ****
--- 645,649 ----
  /* Helper function for estimate_bb_frequencies.
     Propagate the frequencies for loops headed by HEAD.  */
+ 
  static void
  propagate_freq (head)
*************** propagate_freq (head)
*** 669,672 ****
--- 664,668 ----
  	{
  	  int count = 0;
+ 
  	  for (e = bb->pred; e; e = e->pred_next)
  	    if (BLOCK_INFO (e->src)->tovisit && !(e->flags & EDGE_DFS_BACK))
*************** propagate_freq (head)
*** 684,688 ****
    for (; bb; bb = nextbb)
      {
!       volatile double cyclic_probability = 0, frequency = 0;
  
        nextbb = BLOCK_INFO (bb)->next;
--- 680,684 ----
    for (; bb; bb = nextbb)
      {
!       double cyclic_probability = 0, frequency = 0;
  
        nextbb = BLOCK_INFO (bb)->next;
*************** propagate_freq (head)
*** 717,723 ****
        for (e = bb->succ; e; e = e->succ_next)
  	if (e->dest == head)
! 	  EDGE_INFO (e)->back_edge_prob = (e->probability
! 					   * BLOCK_INFO (bb)->frequency
! 					   / REG_BR_PROB_BASE);
  
        /* Propagate to successor blocks.  */
--- 713,719 ----
        for (e = bb->succ; e; e = e->succ_next)
  	if (e->dest == head)
! 	  EDGE_INFO (e)->back_edge_prob
! 	    = ((e->probability * BLOCK_INFO (bb)->frequency)
! 	       / REG_BR_PROB_BASE);
  
        /* Propagate to successor blocks.  */
*************** propagate_freq (head)
*** 733,736 ****
--- 729,733 ----
  		else
  		  BLOCK_INFO (last)->next = e->dest;
+ 
  		last = e->dest;
  	      }
*************** propagate_freq (head)
*** 740,743 ****
--- 737,741 ----
  
  /* Estimate probabilities of loopback edges in loops at same nest level.  */
+ 
  static void
  estimate_loops_at_level (first_loop)
*************** estimate_loops_at_level (first_loop)
*** 754,758 ****
  
        /* Find current loop back edge and mark it.  */
!       for (e = loop->latch->succ; e->dest != loop->header; e = e->succ_next);
  
        EDGE_INFO (e)->back_edge = 1;
--- 752,757 ----
  
        /* Find current loop back edge and mark it.  */
!       for (e = loop->latch->succ; e->dest != loop->header; e = e->succ_next)
! 	;
  
        EDGE_INFO (e)->back_edge = 1;
*************** estimate_loops_at_level (first_loop)
*** 765,768 ****
--- 764,768 ----
  	    if (l->header == loop->header)
  	      break;
+ 
  	  if (l)
  	    continue;
*************** estimate_loops_at_level (first_loop)
*** 775,778 ****
--- 775,779 ----
  				     BLOCK_INFO (BASIC_BLOCK (n))->tovisit = 1
  				     );
+ 
        propagate_freq (loop->header);
      }
*************** estimate_loops_at_level (first_loop)
*** 780,783 ****
--- 781,785 ----
  
  /* Convert counts measured by profile driven feedback to frequencies.  */
+ 
  static void
  counts_to_freqs ()
*************** counts_to_freqs ()
*** 787,796 ****
  
    for (i = 0; i < n_basic_blocks; i++)
!     if (BASIC_BLOCK (i)->count > count_max)
!       count_max = BASIC_BLOCK (i)->count;
  
    for (i = -2; i < n_basic_blocks; i++)
      {
        basic_block bb;
        if (i == -2)
  	bb = ENTRY_BLOCK_PTR;
--- 789,798 ----
  
    for (i = 0; i < n_basic_blocks; i++)
!     count_max = MAX (BASIC_BLOCK (i)->count, count_max);
  
    for (i = -2; i < n_basic_blocks; i++)
      {
        basic_block bb;
+ 
        if (i == -2)
  	bb = ENTRY_BLOCK_PTR;
*************** counts_to_freqs ()
*** 799,812 ****
        else
  	bb = BASIC_BLOCK (i);
!       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 optimizer performance of prologue, epilogue or do inlining at the
!    expense of code size growth.  THRESHOLD is the limit of number
!    of isntructions function can execute at average to be still considered
!    not expensive.  */
  bool
  expensive_function_p (threshold)
--- 801,814 ----
        else
  	bb = BASIC_BLOCK (i);
! 
!       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
!    optimize performance of prologue, epilogue or do inlining at the expense
!    of code size growth.  THRESHOLD is the limit of number of isntructions
!    function can execute at average to be still considered not expensive.  */
! 
  bool
  expensive_function_p (threshold)
*************** expensive_function_p (threshold)
*** 837,853 ****
        for (insn = bb->head; insn != NEXT_INSN (bb->end);
  	   insn = NEXT_INSN (insn))
! 	{
! 	  if (active_insn_p (insn))
! 	    {
! 	      sum += bb->frequency;
! 	      if (sum > limit)
! 		return true;
! 	    }
  	}
      }
    return false;
  }
  
  /* Estimate basic blocks frequency by given branch probabilities.  */
  static void
  estimate_bb_frequencies (loops)
--- 839,855 ----
        for (insn = bb->head; insn != NEXT_INSN (bb->end);
  	   insn = NEXT_INSN (insn))
! 	if (active_insn_p (insn))
! 	  {
! 	    sum += bb->frequency;
! 	    if (sum > limit)
! 	      return true;
  	}
      }
+ 
    return false;
  }
  
  /* Estimate basic blocks frequency by given branch probabilities.  */
+ 
  static void
  estimate_bb_frequencies (loops)
*************** estimate_bb_frequencies (loops)
*** 907,910 ****
--- 909,913 ----
  	}
      }
+ 
    ENTRY_BLOCK_PTR->succ->probability = REG_BR_PROB_BASE;
  
*************** estimate_bb_frequencies (loops)
*** 923,926 ****
--- 926,930 ----
        else
  	bb = BASIC_BLOCK (i);
+ 
        BLOCK_INFO (bb)->tovisit = 0;
        for (e = bb->succ; e; e = e->succ_next)
*************** estimate_bb_frequencies (loops)
*** 928,931 ****
--- 932,936 ----
  					 / REG_BR_PROB_BASE);
      }
+ 
    /* First compute probabilities locally for each loop from innermost
       to outermost to examine probabilities for back edges.  */
*************** estimate_bb_frequencies (loops)
*** 935,938 ****
--- 940,944 ----
    for (i = 0; i < n_basic_blocks; i++)
      BLOCK_INFO (BASIC_BLOCK (i))->tovisit = 1;
+ 
    BLOCK_INFO (ENTRY_BLOCK_PTR)->tovisit = 1;
    BLOCK_INFO (EXIT_BLOCK_PTR)->tovisit = 1;
*************** estimate_bb_frequencies (loops)
*** 942,948 ****
--- 948,956 ----
      if (BLOCK_INFO (BASIC_BLOCK (i))->frequency > freq_max)
        freq_max = BLOCK_INFO (BASIC_BLOCK (i))->frequency;
+ 
    for (i = -2; i < n_basic_blocks; i++)
      {
        basic_block bb;
+ 
        if (i == -2)
  	bb = ENTRY_BLOCK_PTR;
*************** estimate_bb_frequencies (loops)
*** 951,956 ****
        else
  	bb = BASIC_BLOCK (i);
!       bb->frequency = (BLOCK_INFO (bb)->frequency * BB_FREQ_MAX / freq_max
! 		       + 0.5);
      }
  
--- 959,964 ----
        else
  	bb = BASIC_BLOCK (i);
!       bb->frequency
! 	= BLOCK_INFO (bb)->frequency * BB_FREQ_MAX / freq_max + 0.5;
      }
  


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