aboutsummaryrefslogtreecommitdiff
path: root/gcc/predict.c
diff options
context:
space:
mode:
authorMartin Liska <mliska@suse.cz>2017-06-09 09:38:52 +0200
committerMartin Liska <marxin@gcc.gnu.org>2017-06-09 07:38:52 +0000
commitd88382176e53eca7552e29b7bb88ae4efd72a39d (patch)
treee7548f278250e87e028751c87a71c1597f22efae /gcc/predict.c
parent1ee77fbdea58944b047de8ff88901aea4e93ed7d (diff)
downloadgcc-d88382176e53eca7552e29b7bb88ae4efd72a39d.zip
gcc-d88382176e53eca7552e29b7bb88ae4efd72a39d.tar.gz
gcc-d88382176e53eca7552e29b7bb88ae4efd72a39d.tar.bz2
Come up with selftests for predict.c.
2017-06-09 Martin Liska <mliska@suse.cz> * 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
Diffstat (limited to 'gcc/predict.c')
-rw-r--r--gcc/predict.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/gcc/predict.c b/gcc/predict.c
index bf93230..ca40068 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. */