aboutsummaryrefslogtreecommitdiff
path: root/gcc/read-md.c
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2017-01-05 19:32:09 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2017-01-05 19:32:09 +0000
commit51b861137ed73ae73e15a136949301fbaaf89202 (patch)
treefd9bdb64e3920b3c35272969864ac5576f4fdad5 /gcc/read-md.c
parent7f86d7de6b80f68a47fc48f82af1a3ec9dbda21a (diff)
downloadgcc-51b861137ed73ae73e15a136949301fbaaf89202.zip
gcc-51b861137ed73ae73e15a136949301fbaaf89202.tar.gz
gcc-51b861137ed73ae73e15a136949301fbaaf89202.tar.bz2
Introduce RTL function reader
This is the combination of these patches: - [8a/9] Introduce class function_reader (v8) - Add ASSERT_RTX_PTR_EQ - [8b/9] Add target-independent selftests of RTL function reader (v2) - [8c/9] Add aarch64-specific selftests for RTL function reader (v2) - [8d/9] Add x86_64-specific selftests for RTL function reader (v2) gcc/ChangeLog: * Makefile.in (OBJS): Add read-md.o, read-rtl.o, read-rtl-function.o, and selftest-rtl.o. * config/aarch64/aarch64.c: Include selftest.h and selftest-rtl.h. (selftest::aarch64_test_loading_full_dump): New function. (selftest::aarch64_run_selftests): New function. (TARGET_RUN_TARGET_SELFTESTS): Wire it up to selftest::aarch64_run_selftests. * config/i386/i386.c (selftest::ix86_test_loading_dump_fragment_1): New function. (selftest::ix86_test_loading_call_insn): New function. (selftest::ix86_test_loading_full_dump): New function. (selftest::ix86_test_loading_unspec): New function. (selftest::ix86_run_selftests): Call the new functions. * emit-rtl.c (maybe_set_max_label_num): New function. * emit-rtl.h (maybe_set_max_label_num): New decl. * function.c (instantiate_decls): Guard call to instantiate_decls_1 with if (DECL_INITIAL (fndecl)). * function-tests.c (selftest::verify_three_block_rtl_cfg): Remove "static". * gensupport.c (gen_reader::gen_reader): Pass "false" for new "compact" param of rtx_reader. * print-rtl.c (rtx_writer::print_rtx_operand): Print "(nil)" rather than an empty string for NULL strings. * read-md.c: Potentially include config.h rather than bconfig.h. Wrap include of errors.h with #ifdef GENERATOR_FILE. (have_error): New global, copied from errors.c. (md_reader::read_name): Rename to... (md_reader::read_name_1): ...this, adding "out_loc" param, and converting "missing name or number" to returning false, rather than failing. (md_reader::read_name): Reimplement in terms of read_name_1. (md_reader::read_name_or_nil): New function. (md_reader::read_string): Handle "(nil)" by returning NULL. (md_reader::md_reader): Add new param "compact". (md_reader::read_md_files): Wrap with #ifdef GENERATOR_FILE. (md_reader::read_file): New method. * read-md.h (md_reader::md_reader): Add new param "compact". (md_reader::read_file): New method. (md_reader::is_compact): New accessor. (md_reader::read_name): Convert return type from void to file_location. (md_reader::read_name_or_nil): New decl. (md_reader::read_name_1): New decl. (md_reader::m_compact): New field. (noop_reader::noop_reader): Pass "false" for new "compact" param of rtx_reader. (rtx_reader::rtx_reader): Add new "compact" param. (rtx_reader::read_rtx_operand): Make virtual and convert return type from void to rtx. (rtx_reader::read_until): New decl. (rtx_reader::handle_any_trailing_information): New virtual function. (rtx_reader::postprocess): New virtual function. (rtx_reader::finalize_string): New virtual function. (rtx_reader::m_in_call_function_usage): New field. (rtx_reader::m_reuse_rtx_by_id): New field. * read-rtl-function.c: New file. * selftest-rtl.c (selftest::assert_rtx_ptr_eq_at): New function. * selftest-rtl.h (ASSERT_RTX_PTR_EQ): New macro. (selftest::verify_three_block_rtl_cfg): New decl. * read-rtl-function.h: New file. * read-rtl.c: Potentially include config.h rather than bconfig.h. For host, include function.h, memmodel.h, and emit-rtl.h. (one_time_initialization): New function. (struct compact_insn_name): New struct. (compact_insn_names): New array. (find_code): Handle insn codes in compact dumps. (apply_subst_iterator): Wrap with #ifdef GENERATOR_FILE. (bind_subst_iter_and_attr): Likewise. (add_condition_to_string): Likewise. (add_condition_to_rtx): Likewise. (apply_attribute_uses): Likewise. (add_current_iterators): Likewise. (apply_iterators): Likewise. (initialize_iterators): Guard usage of apply_subst_iterator with #ifdef GENERATOR_FILE. (read_conditions): Wrap with #ifdef GENERATOR_FILE. (md_reader::read_mapping): Likewise. (add_define_attr_for_define_subst): Likewise. (add_define_subst_attr): Likewise. (read_subst_mapping): Likewise. (check_code_iterator): Likewise. (rtx_reader::read_rtx): Likewise. Move one-time initialization logic to... (one_time_initialization): New function. (rtx_reader::read_until): New method. (read_flags): New function. (parse_reg_note_name): New function. (rtx_reader::read_rtx_code): Initialize "iterator" to NULL. Handle reuse_rtx ids. Wrap iterator lookup within #ifdef GENERATOR_FILE. Add parsing support for RTL dumps, mirroring the special-cases in print_rtx, by calling read_flags, reading REG_NOTE names, INSN_UID values, and calling handle_any_trailing_information. (rtx_reader::read_rtx_operand): Convert return type from void to rtx, returning return_rtx. Handle case 'e'. Call finalize_string on XSTR and XTMPL fields. (rtx_reader::read_nested_rtx): Handle dumps in which trailing "(nil)" values were omitted. Call the postprocess vfunc on the return_rtx. (rtx_reader::rtx_reader): Add new "compact" param and pass to base class ctor. Initialize m_in_call_function_usage. Call one_time_initialization. * rtl-tests.c (selftest::test_uncond_jump): Call set_new_first_and_last_insn. * rtl.h (read_rtx): Wrap decl with #ifdef GENERATOR_FILE. * selftest-rtl.c: New file. * selftest-rtl.h (class selftest::rtl_dump_test): New class. (selftest::get_insn_by_uid): New decl. * selftest-run-tests.c (selftest::run_tests): Call read_rtl_function_c_tests. * selftest.h (selftest::read_rtl_function_c_tests): New decl. * tree-dfa.c (ssa_default_def): Return NULL_TREE for rtl function dumps. gcc/testsuite/ChangeLog: * selftests/asr_div1.rtl: New file. * selftests/aarch64: New subdirectory. * selftests/aarch64/times-two.rtl: New file. * selftests/bb-index.rtl: New file. * selftests/cfg-test.rtl: New file. * selftests/const-int.rtl: New file. * selftests/example-labels.rtl: New file. * selftests/insn-with-mode.rtl: New file. * selftests/jump-to-label-ref.rtl: New file. * selftests/jump-to-return.rtl: New file. * selftests/jump-to-simple-return.rtl: New file. * selftests/mem.rtl: New file. * selftests/note-insn-deleted.rtl: New file. * selftests/note_insn_basic_block.rtl: New file. * selftests/simple-cse.rtl: New file. * selftests/symbol-ref.rtl: New file. * selftests/x86_64: New subdirectory. * selftests/x86_64/call-insn.rtl: New file. * selftests/x86_64/copy-hard-reg-into-frame.rtl: New file. * selftests/x86_64/times-two.rtl: New file. * selftests/x86_64/unspec.rtl: New file. From-SVN: r244110
Diffstat (limited to 'gcc/read-md.c')
-rw-r--r--gcc/read-md.c89
1 files changed, 84 insertions, 5 deletions
diff --git a/gcc/read-md.c b/gcc/read-md.c
index 7b73361..ac28944 100644
--- a/gcc/read-md.c
+++ b/gcc/read-md.c
@@ -17,14 +17,32 @@ You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
+/* This file is compiled twice: once for the generator programs
+ once for the compiler. */
+#ifdef GENERATOR_FILE
#include "bconfig.h"
+#else
+#include "config.h"
+#endif
#include "system.h"
#include "coretypes.h"
+#ifdef GENERATOR_FILE
#include "errors.h"
+#endif /* #ifdef GENERATOR_FILE */
#include "statistics.h"
#include "vec.h"
#include "read-md.h"
+#ifndef GENERATOR_FILE
+
+/* Minimal reimplementation of errors.c for use by RTL frontend
+ within cc1. */
+
+int have_error = 0;
+
+#endif /* #ifndef GENERATOR_FILE */
+
+
/* Associates PTR (which can be a string, etc.) with the file location
specified by FILENAME and LINENO. */
struct ptr_loc {
@@ -424,8 +442,8 @@ md_reader::peek_char (void)
/* Read an rtx code name into NAME. It is terminated by any of the
punctuation chars of rtx printed syntax. */
-void
-md_reader::read_name (struct md_name *name)
+bool
+md_reader::read_name_1 (struct md_name *name, file_location *out_loc)
{
int c;
size_t i;
@@ -433,6 +451,8 @@ md_reader::read_name (struct md_name *name)
c = read_skip_spaces ();
+ *out_loc = get_current_location ();
+
i = 0;
angle_bracket_depth = 0;
while (1)
@@ -464,7 +484,7 @@ md_reader::read_name (struct md_name *name)
}
if (i == 0)
- fatal_with_file_and_line ("missing name or number");
+ return false;
name->buffer[i] = 0;
name->string = name->buffer;
@@ -485,6 +505,36 @@ md_reader::read_name (struct md_name *name)
}
while (def);
}
+
+ return true;
+}
+
+/* Read an rtx code name into NAME. It is terminated by any of the
+ punctuation chars of rtx printed syntax. */
+
+file_location
+md_reader::read_name (struct md_name *name)
+{
+ file_location loc;
+ if (!read_name_1 (name, &loc))
+ fatal_with_file_and_line ("missing name or number");
+ return loc;
+}
+
+file_location
+md_reader::read_name_or_nil (struct md_name *name)
+{
+ file_location loc;
+ if (!read_name_1 (name, &loc))
+ {
+ file_location loc = get_current_location ();
+ read_skip_construct (0, loc);
+ /* Skip the ')'. */
+ read_char ();
+ name->buffer[0] = 0;
+ name->string = name->buffer;
+ }
+ return loc;
}
/* Subroutine of the string readers. Handles backslash escapes.
@@ -630,6 +680,14 @@ md_reader::read_string (int star_if_braced)
obstack_1grow (&m_string_obstack, '*');
stringbuf = read_braced_string ();
}
+ else if (saw_paren && c == 'n')
+ {
+ /* Handle (nil) by returning NULL. */
+ require_char ('i');
+ require_char ('l');
+ require_char_ws (')');
+ return NULL;
+ }
else
fatal_with_file_and_line ("expected `\"' or `{', found `%c'", c);
@@ -924,8 +982,9 @@ md_reader::traverse_enum_types (htab_trav callback, void *info)
/* Constructor for md_reader. */
-md_reader::md_reader ()
-: m_toplevel_fname (NULL),
+md_reader::md_reader (bool compact)
+: m_compact (compact),
+ m_toplevel_fname (NULL),
m_base_dir (NULL),
m_read_md_file (NULL),
m_read_md_filename (NULL),
@@ -1129,6 +1188,8 @@ md_reader::add_include_path (const char *arg)
m_last_dir_md_include_ptr = &dirtmp->next;
}
+#ifdef GENERATOR_FILE
+
/* The main routine for reading .md files. Try to process all the .md
files specified on the command line and return true if no error occurred.
@@ -1235,6 +1296,24 @@ md_reader::read_md_files (int argc, const char **argv,
return !have_error;
}
+#endif /* #ifdef GENERATOR_FILE */
+
+/* Read FILENAME. */
+
+bool
+md_reader::read_file (const char *filename)
+{
+ m_read_md_filename = filename;
+ m_read_md_file = fopen (m_read_md_filename, "r");
+ if (m_read_md_file == 0)
+ {
+ perror (m_read_md_filename);
+ return false;
+ }
+ handle_toplevel_file ();
+ return !have_error;
+}
+
/* class noop_reader : public md_reader */
/* A dummy implementation which skips unknown directives. */