This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH 6/9] df selftests
- From: David Malcolm <dmalcolm at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: David Malcolm <dmalcolm at redhat dot com>
- Date: Thu, 8 Sep 2016 20:30:50 -0400
- Subject: [PATCH 6/9] df selftests
- Authentication-results: sourceware.org; auth=none
- References: <1473381053-18817-1-git-send-email-dmalcolm@redhat.com>
gcc/ChangeLog:
* df-core.c: Include selftest.h and selftest-rtl.h.
(selftest::dataflow_test::dataflow_test): New ctor.
(selftest::dataflow_test::~dataflow_test): New dtor.
(selftest::test_df_single_set): New function.
(selftest::df_core_c_tests): New function.
* selftest-run-tests.c (selftest::run_tests): Call it.
* selftest.h (selftest::df_core_c_tests): New decl.
---
gcc/df-core.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++
gcc/selftest-run-tests.c | 1 +
gcc/selftest.h | 1 +
3 files changed, 79 insertions(+)
diff --git a/gcc/df-core.c b/gcc/df-core.c
index e531d58..cb8e2f9 100644
--- a/gcc/df-core.c
+++ b/gcc/df-core.c
@@ -384,6 +384,8 @@ are write-only operations.
#include "cfganal.h"
#include "tree-pass.h"
#include "cfgloop.h"
+#include "selftest.h"
+#include "selftest-rtl.h"
static void *df_get_bb_info (struct dataflow *, unsigned int);
static void df_set_bb_info (struct dataflow *, unsigned int, void *);
@@ -2482,3 +2484,78 @@ debug_df_chain (struct df_link *link)
df_chain_dump (link, stderr);
fputc ('\n', stderr);
}
+
+#if CHECKING_P
+
+namespace selftest {
+
+/* dataflow_test's constructor. Initialize df. */
+
+dataflow_test::dataflow_test ()
+{
+ rest_of_handle_df_initialize ();
+}
+
+/* dataflow_test's destructor. Clean up df. */
+
+dataflow_test::~dataflow_test ()
+{
+ rest_of_handle_df_finish ();
+}
+
+/* Verify df_note on a trivial function. */
+
+void
+test_df_single_set ()
+{
+ const char *input_dump
+ = "(insn 1 0 0 2 (set (reg:SI 100) (reg:SI 101)) -1 (nil))\n";
+ rtl_dump_test t (input_dump, 100);
+ //print_rtl_with_bb (stdout, get_insns (), 1024);
+
+ dataflow_test dftest;
+
+ df_note_add_problem ();
+ df_analyze ();
+ //df_dump (stderr);
+ df_finish_pass (false);
+
+ rtx_insn *insn = get_insn_by_uid (1);
+
+ ASSERT_NE (NULL, REG_NOTES (insn));
+ rtx_expr_list *note0 = as_a <rtx_expr_list *> (REG_NOTES (insn));
+
+ rtx_expr_list *note1 = note0->next ();
+ ASSERT_NE (NULL, note1);
+
+ ASSERT_EQ (NULL, note1->next ());
+
+ ASSERT_EQ (SET_SRC (PATTERN (insn)), note0->element ());
+ ASSERT_EQ (REG_DEAD, REG_NOTE_KIND (note0));
+
+ ASSERT_EQ (SET_DEST (PATTERN (insn)), note1->element ());
+ ASSERT_EQ (REG_UNUSED, REG_NOTE_KIND (note1));
+
+ struct df_lr_bb_info *bb_info = df_lr_get_bb_info (2);
+ ASSERT_NE (NULL, bb_info);
+
+ /* "r100 = r101;" so we should have a use of r101. */
+ ASSERT_FALSE (bitmap_bit_p (&bb_info->use, t.effective_regno (100)));
+ ASSERT_TRUE (bitmap_bit_p (&bb_info->use, t.effective_regno (101)));
+
+ /* ...and a def of r100. */
+ ASSERT_TRUE (bitmap_bit_p (&bb_info->def, t.effective_regno (100)));
+ ASSERT_FALSE (bitmap_bit_p (&bb_info->def, t.effective_regno (101)));
+}
+
+/* Run all of the selftests within this file. */
+
+void
+df_core_c_tests ()
+{
+ test_df_single_set ();
+}
+
+} // namespace selftest
+
+#endif /* #if CHECKING_P */
diff --git a/gcc/selftest-run-tests.c b/gcc/selftest-run-tests.c
index c90037c..14e5828 100644
--- a/gcc/selftest-run-tests.c
+++ b/gcc/selftest-run-tests.c
@@ -64,6 +64,7 @@ selftest::run_tests ()
gimple_c_tests ();
rtl_tests_c_tests ();
read_rtl_function_c_tests ();
+ df_core_c_tests ();
/* Higher-level tests, or for components that other selftests don't
rely on. */
diff --git a/gcc/selftest.h b/gcc/selftest.h
index 75fea6f..037a5ee 100644
--- a/gcc/selftest.h
+++ b/gcc/selftest.h
@@ -190,6 +190,7 @@ extern void forcibly_ggc_collect ();
/* Declarations for specific families of tests (by source file), in
alphabetical order. */
extern void bitmap_c_tests ();
+extern void df_core_c_tests ();
extern void diagnostic_c_tests ();
extern void diagnostic_show_locus_c_tests ();
extern void edit_context_c_tests ();
--
1.8.5.3