aboutsummaryrefslogtreecommitdiff
path: root/gcc/predict.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/predict.c')
-rw-r--r--gcc/predict.c170
1 files changed, 84 insertions, 86 deletions
diff --git a/gcc/predict.c b/gcc/predict.c
index 068c187..a847ec6 100644
--- a/gcc/predict.c
+++ b/gcc/predict.c
@@ -1986,59 +1986,6 @@ expr_expected_value (tree expr, bitmap visited,
return expr_expected_value_1 (TREE_TYPE (expr),
op0, code, op1, visited, predictor);
}
-
-
-/* Get rid of all builtin_expect calls and GIMPLE_PREDICT statements
- we no longer need. */
-static unsigned int
-strip_predict_hints (void)
-{
- basic_block bb;
- gimple ass_stmt;
- tree var;
-
- FOR_EACH_BB_FN (bb, cfun)
- {
- gimple_stmt_iterator bi;
- for (bi = gsi_start_bb (bb); !gsi_end_p (bi);)
- {
- gimple stmt = gsi_stmt (bi);
-
- if (gimple_code (stmt) == GIMPLE_PREDICT)
- {
- gsi_remove (&bi, true);
- continue;
- }
- else if (is_gimple_call (stmt))
- {
- tree fndecl = gimple_call_fndecl (stmt);
-
- if ((fndecl
- && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL
- && DECL_FUNCTION_CODE (fndecl) == BUILT_IN_EXPECT
- && gimple_call_num_args (stmt) == 2)
- || (gimple_call_internal_p (stmt)
- && gimple_call_internal_fn (stmt) == IFN_BUILTIN_EXPECT))
- {
- var = gimple_call_lhs (stmt);
- if (var)
- {
- ass_stmt
- = gimple_build_assign (var, gimple_call_arg (stmt, 0));
- gsi_replace (&bi, ass_stmt, true);
- }
- else
- {
- gsi_remove (&bi, true);
- continue;
- }
- }
- }
- gsi_next (&bi);
- }
- }
- return 0;
-}
/* Predict using opcode of the last statement in basic block. */
static void
@@ -2468,37 +2415,6 @@ tree_estimate_probability (void)
free_dominance_info (CDI_POST_DOMINATORS);
remove_fake_exit_edges ();
}
-
-/* Predict branch probabilities and estimate profile of the tree CFG.
- This is the driver function for PASS_PROFILE. */
-
-static unsigned int
-tree_estimate_probability_driver (void)
-{
- unsigned nb_loops;
-
- loop_optimizer_init (LOOPS_NORMAL);
- if (dump_file && (dump_flags & TDF_DETAILS))
- flow_loops_dump (dump_file, NULL, 0);
-
- mark_irreducible_loops ();
-
- nb_loops = number_of_loops (cfun);
- if (nb_loops > 1)
- scev_initialize ();
-
- tree_estimate_probability ();
-
- if (nb_loops > 1)
- scev_finalize ();
-
- loop_optimizer_finalize ();
- if (dump_file && (dump_flags & TDF_DETAILS))
- gimple_dump_cfg (dump_file, dump_flags);
- if (profile_status_for_fn (cfun) == PROFILE_ABSENT)
- profile_status_for_fn (cfun) = PROFILE_GUESSED;
- return 0;
-}
/* Predict edges to successors of CUR whose sources are not postdominated by
BB by PRED and recurse to all postdominators. */
@@ -3147,6 +3063,8 @@ predictor_name (enum br_predictor predictor)
return predictor_info[predictor].name;
}
+/* Predict branch probabilities and estimate profile of the tree CFG. */
+
namespace {
const pass_data pass_data_profile =
@@ -3172,10 +3090,38 @@ public:
/* opt_pass methods: */
virtual bool gate (function *) { return flag_guess_branch_prob; }
- unsigned int execute () { return tree_estimate_probability_driver (); }
+ virtual unsigned int execute (function *);
}; // class pass_profile
+unsigned int
+pass_profile::execute (function *fun)
+{
+ unsigned nb_loops;
+
+ loop_optimizer_init (LOOPS_NORMAL);
+ if (dump_file && (dump_flags & TDF_DETAILS))
+ flow_loops_dump (dump_file, NULL, 0);
+
+ mark_irreducible_loops ();
+
+ nb_loops = number_of_loops (fun);
+ if (nb_loops > 1)
+ scev_initialize ();
+
+ tree_estimate_probability ();
+
+ if (nb_loops > 1)
+ scev_finalize ();
+
+ loop_optimizer_finalize ();
+ if (dump_file && (dump_flags & TDF_DETAILS))
+ gimple_dump_cfg (dump_file, dump_flags);
+ if (profile_status_for_fn (fun) == PROFILE_ABSENT)
+ profile_status_for_fn (fun) = PROFILE_GUESSED;
+ return 0;
+}
+
} // anon namespace
gimple_opt_pass *
@@ -3209,10 +3155,62 @@ public:
/* opt_pass methods: */
opt_pass * clone () { return new pass_strip_predict_hints (m_ctxt); }
- unsigned int execute () { return strip_predict_hints (); }
+ virtual unsigned int execute (function *);
}; // class pass_strip_predict_hints
+/* Get rid of all builtin_expect calls and GIMPLE_PREDICT statements
+ we no longer need. */
+unsigned int
+pass_strip_predict_hints::execute (function *fun)
+{
+ basic_block bb;
+ gimple ass_stmt;
+ tree var;
+
+ FOR_EACH_BB_FN (bb, fun)
+ {
+ gimple_stmt_iterator bi;
+ for (bi = gsi_start_bb (bb); !gsi_end_p (bi);)
+ {
+ gimple stmt = gsi_stmt (bi);
+
+ if (gimple_code (stmt) == GIMPLE_PREDICT)
+ {
+ gsi_remove (&bi, true);
+ continue;
+ }
+ else if (is_gimple_call (stmt))
+ {
+ tree fndecl = gimple_call_fndecl (stmt);
+
+ if ((fndecl
+ && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL
+ && DECL_FUNCTION_CODE (fndecl) == BUILT_IN_EXPECT
+ && gimple_call_num_args (stmt) == 2)
+ || (gimple_call_internal_p (stmt)
+ && gimple_call_internal_fn (stmt) == IFN_BUILTIN_EXPECT))
+ {
+ var = gimple_call_lhs (stmt);
+ if (var)
+ {
+ ass_stmt
+ = gimple_build_assign (var, gimple_call_arg (stmt, 0));
+ gsi_replace (&bi, ass_stmt, true);
+ }
+ else
+ {
+ gsi_remove (&bi, true);
+ continue;
+ }
+ }
+ }
+ gsi_next (&bi);
+ }
+ }
+ return 0;
+}
+
} // anon namespace
gimple_opt_pass *