From d88382176e53eca7552e29b7bb88ae4efd72a39d Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Fri, 9 Jun 2017 09:38:52 +0200 Subject: [PATCH] Come up with selftests for predict.c. 2017-06-09 Martin Liska * predict.c (struct branch_predictor): New struct. (test_prediction_value_range): New test. (predict_c_tests): New function. * selftest-run-tests.c (selftest::run_tests): Run the function. * selftest.h: Declare new tests. From-SVN: r249048 --- gcc/ChangeLog | 8 ++++++++ gcc/predict.c | 44 ++++++++++++++++++++++++++++++++++++++++ gcc/selftest-run-tests.c | 1 + gcc/selftest.h | 1 + 4 files changed, 54 insertions(+) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 285d56af280..ded979703ad 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2017-06-09 Martin Liska + + * predict.c (struct branch_predictor): New struct. + (test_prediction_value_range): New test. + (predict_c_tests): New function. + * selftest-run-tests.c (selftest::run_tests): Run the function. + * selftest.h: Declare new tests. + 2017-06-09 Segher Boessenkool PR target/80966 diff --git a/gcc/predict.c b/gcc/predict.c index bf932305cc9..ca40068c150 100644 --- a/gcc/predict.c +++ b/gcc/predict.c @@ -57,6 +57,7 @@ along with GCC; see the file COPYING3. If not see #include "tree-scalar-evolution.h" #include "ipa-utils.h" #include "gimple-pretty-print.h" +#include "selftest.h" /* Enum with reasons why a predictor is ignored. */ @@ -4016,3 +4017,46 @@ force_edge_cold (edge e, bool impossible) impossible ? "impossible" : "cold"); } } + +#if CHECKING_P + +namespace selftest { + +/* Test that value range of predictor values defined in predict.def is + within range (50, 100]. */ + +struct branch_predictor +{ + const char *name; + unsigned probability; +}; + +#define DEF_PREDICTOR(ENUM, NAME, HITRATE, FLAGS) { NAME, HITRATE }, + +static void +test_prediction_value_range () +{ + branch_predictor predictors[] = { +#include "predict.def" + {NULL, -1} + }; + + for (unsigned i = 0; predictors[i].name != NULL; i++) + { + unsigned p = 100 * predictors[i].probability / REG_BR_PROB_BASE; + ASSERT_TRUE (p > 50 && p <= 100); + } +} + +#undef DEF_PREDICTOR + +/* Run all of the selfests within this file. */ + +void +predict_c_tests () +{ + test_prediction_value_range (); +} + +} // namespace selftest +#endif /* CHECKING_P. */ diff --git a/gcc/selftest-run-tests.c b/gcc/selftest-run-tests.c index f62bc72b072..30e476d14c5 100644 --- a/gcc/selftest-run-tests.c +++ b/gcc/selftest-run-tests.c @@ -92,6 +92,7 @@ selftest::run_tests () targetm.run_target_selftests (); store_merging_c_tests (); + predict_c_tests (); /* Run any lang-specific selftests. */ lang_hooks.run_lang_selftests (); diff --git a/gcc/selftest.h b/gcc/selftest.h index dad53e9fe09..0572fefd281 100644 --- a/gcc/selftest.h +++ b/gcc/selftest.h @@ -196,6 +196,7 @@ extern void tree_c_tests (); extern void tree_cfg_c_tests (); extern void vec_c_tests (); extern void wide_int_cc_tests (); +extern void predict_c_tests (); extern int num_passes; -- 2.30.2