From: Jan Hubicka Date: Tue, 14 Sep 2004 00:52:41 +0000 (+0200) Subject: Makefile.in (predict.o): Depend on tree-scalar-evolution.h X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b6acab32f182074d7253fc215d3639227fc4f624;p=gcc.git Makefile.in (predict.o): Depend on tree-scalar-evolution.h * 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 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 60d76f6c5a1..8e52c7569bf 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2004-09-14 Jan Hubicka + + * 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 PR 17408 diff --git a/gcc/Makefile.in b/gcc/Makefile.in index e30d8132b14..aa45b739796 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -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) \ diff --git a/gcc/predict.c b/gcc/predict.c index fbbc1579b39..c19ccbe59eb 100644 --- a/gcc/predict.c +++ b/gcc/predict.c @@ -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