[PATCH 11/16] df selftests (v3)

David Malcolm dmalcolm@redhat.com
Wed Oct 5 15:44:00 GMT 2016


Changes since v2:
* moved dump from a string literal to an external file
* update for addition of selftest::location to rtl_dump_test
* remove debug prints

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/testsuite/ChangeLog:
	* selftests/single-set.rtl: New file.
---
 gcc/df-core.c                          | 73 ++++++++++++++++++++++++++++++++++
 gcc/selftest-run-tests.c               |  1 +
 gcc/selftest.h                         |  1 +
 gcc/testsuite/selftests/single-set.rtl |  5 +++
 4 files changed, 80 insertions(+)
 create mode 100644 gcc/testsuite/selftests/single-set.rtl

diff --git a/gcc/df-core.c b/gcc/df-core.c
index e531d58..2c8ccba 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,74 @@ 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 ()
+{
+  rtl_dump_test t (SELFTEST_LOCATION, locate_file ("single-set.rtl"));
+
+  dataflow_test dftest;
+
+  df_note_add_problem ();
+  df_analyze ();
+  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 1dce665..5c95aaa 100644
--- a/gcc/selftest-run-tests.c
+++ b/gcc/selftest-run-tests.c
@@ -71,6 +71,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 ae39101..0033942 100644
--- a/gcc/selftest.h
+++ b/gcc/selftest.h
@@ -200,6 +200,7 @@ extern const char *path_to_src_gcc;
 /* 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 ();
diff --git a/gcc/testsuite/selftests/single-set.rtl b/gcc/testsuite/selftests/single-set.rtl
new file mode 100644
index 0000000..d72015f
--- /dev/null
+++ b/gcc/testsuite/selftests/single-set.rtl
@@ -0,0 +1,5 @@
+(function "test"
+  (insn-chain
+     (insn 1 0 0 2 (set (reg:SI 100) (reg:SI 101)) -1 (nil))
+  ) ;; insn-chain
+) ;; function
-- 
1.8.5.3



More information about the Gcc-patches mailing list