Commit d8838217 by Martin Liska Committed by Martin Liska

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
parent 1ee77fbd
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.
2017-06-09 Segher Boessenkool <segher@kernel.crashing.org>
PR target/80966
......
......@@ -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. */
......@@ -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 ();
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment