Makefile.in (predict.o): Depend on tree-scalar-evolution.h
authorJan Hubicka <jh@suse.cz>
Tue, 14 Sep 2004 00:52:41 +0000 (02:52 +0200)
committerJan Hubicka <hubicka@gcc.gnu.org>
Tue, 14 Sep 2004 00:52:41 +0000 (00:52 +0000)
* Makefile.in (predict.o): Depend on tree-scalar-evolution.h
* predict.c: Include tree-scalar-evolution.h and cfgloop.h
(predict_loops): Use number_of_iterations_exit to predict
number of iterations on trees.

From-SVN: r87473

gcc/ChangeLog
gcc/Makefile.in
gcc/predict.c

index 60d76f6c5a1c71e7a2a728f5f1d8949705d0462b..8e52c7569bf65bfcd8f632e191c8fe4e401a1450 100644 (file)
@@ -1,3 +1,10 @@
+2004-09-14  Jan Hubicka  <jh@suse.cz>
+
+       * Makefile.in (predict.o): Depend on tree-scalar-evolution.h
+       * predict.c: Include tree-scalar-evolution.h and cfgloop.h
+       (predict_loops): Use number_of_iterations_exit to predict
+       number of iterations on trees.
+
 2004-09-13  Dale Johannesen  <dalej@apple.com>
 
        PR 17408
index e30d8132b14736949b0239d75902a8e4b20609e9..aa45b739796417d61201c42413a336fe8366595f 100644 (file)
@@ -2139,7 +2139,7 @@ sreal.o: sreal.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) sreal.h
 predict.o: predict.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(RTL_H) $(TREE_H) \
    $(FLAGS_H) insn-config.h $(BASIC_BLOCK_H) $(REGS_H) hard-reg-set.h output.h toplev.h \
    $(RECOG_H) function.h except.h $(EXPR_H) $(TM_P_H) $(PREDICT_H) sreal.h \
-   $(PARAMS_H) $(TARGET_H) $(CFGLOOP_H) $(COVERAGE_H)
+   $(PARAMS_H) $(TARGET_H) $(CFGLOOP_H) $(COVERAGE_H) tree-scalar-evolution.h
 lists.o: lists.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) toplev.h $(RTL_H) $(GGC_H)
 bb-reorder.o : bb-reorder.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
    $(RTL_H) $(BASIC_BLOCK_H) $(FLAGS_H) $(TIMEVAR_H) output.h $(CFGLAYOUT_H) $(FIBHEAP_H) \
index fbbc1579b39349fe6ee06f33fa9c61423eb3b068..c19ccbe59ebcfa8ffc4e8e757a9cfcbf05edda1b 100644 (file)
@@ -58,6 +58,8 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include "tree-dump.h"
 #include "tree-pass.h"
 #include "timevar.h"
+#include "tree-scalar-evolution.h"
+#include "cfgloop.h"
 
 /* real constants: 0, 1, 1-1/REG_BR_PROB_BASE, REG_BR_PROB_BASE,
                   1/REG_BR_PROB_BASE, 0.5, BB_FREQ_MAX.  */
@@ -552,13 +554,16 @@ combine_predictions_for_bb (FILE *file, basic_block bb)
 }
 
 /* Predict edge probabilities by exploiting loop structure.
-   When SIMPLELOOPS is set, attempt to count number of iterations by analyzing
-   RTL.  */
+   When RTLSIMPLELOOPS is set, attempt to count number of iterations by analyzing
+   RTL otherwise use tree based approach.  */
 static void
-predict_loops (struct loops *loops_info, bool simpleloops)
+predict_loops (struct loops *loops_info, bool rtlsimpleloops)
 {
   unsigned i;
 
+  if (!rtlsimpleloops)
+    scev_initialize (loops_info);
+
   /* Try to predict out blocks in a loop that are not part of a
      natural loop.  */
   for (i = 1; i < loops_info->num; i++)
@@ -573,7 +578,7 @@ predict_loops (struct loops *loops_info, bool simpleloops)
       flow_loop_scan (loop, LOOP_EXIT_EDGES);
       exits = loop->num_exits;
 
-      if (simpleloops)
+      if (rtlsimpleloops)
        {
          iv_analysis_loop_init (loop);
          find_simple_exit (loop, &desc);
@@ -595,6 +600,42 @@ predict_loops (struct loops *loops_info, bool simpleloops)
                            prob);
            }
        }
+      else
+       {
+         edge *exits;
+         unsigned j, n_exits;
+         struct tree_niter_desc niter_desc;
+
+         exits = get_loop_exit_edges (loop, &n_exits);
+         for (j = 0; j < n_exits; j++)
+           {
+             tree niter = NULL;
+
+             if (number_of_iterations_exit (loop, exits[j], &niter_desc))
+               niter = niter_desc.niter;
+             if (!niter || TREE_CODE (niter_desc.niter) != INTEGER_CST)
+               niter = loop_niter_by_eval (loop, exits[j]);
+
+             if (TREE_CODE (niter) == INTEGER_CST)
+               {
+                 int probability;
+                 if (host_integerp (niter, 1)
+                     && tree_int_cst_lt (niter,
+                                         build_int_cstu (NULL_TREE,
+                                                      REG_BR_PROB_BASE - 1)))
+                   {
+                     HOST_WIDE_INT nitercst = tree_low_cst (niter, 1) + 1;
+                     probability = (REG_BR_PROB_BASE + nitercst / 2) / nitercst;
+                   }
+                 else
+                   probability = 1;
+
+                 predict_edge (exits[j], PRED_LOOP_ITERATIONS, probability);
+               }
+           }
+
+         free (exits);
+       }
 
       bbs = get_loop_body (loop);
 
@@ -609,7 +650,7 @@ predict_loops (struct loops *loops_info, bool simpleloops)
             statements construct loops via "non-loop" constructs
             in the source language and are better to be handled
             separately.  */
-         if ((simpleloops && !can_predict_insn_p (BB_END (bb)))
+         if ((rtlsimpleloops && !can_predict_insn_p (BB_END (bb)))
              || predicted_by_p (bb, PRED_CONTINUE))
            continue;
 
@@ -639,6 +680,9 @@ predict_loops (struct loops *loops_info, bool simpleloops)
       /* Free basic blocks from get_loop_body.  */
       free (bbs);
     }
+
+  if (!rtlsimpleloops)
+    scev_reset ();
 }
 
 /* Attempt to predict probabilities of BB outgoing edges using local