On 09/08/2016 06:30 PM, David Malcolm wrote:
This patch generalizes the RTL-reading capabilities so that they
can be run on the host as well as the build machine.
The available rtx in rtl.def changes dramatically between these
two configurations, so a fair amount of #ifdef GENERATOR_FILE is
required to express this.

This patch introduces a function_reader subclass of rtx_reader,
capable of reading an RTL function dump (or part of one),
reconstructing a cfun with a CFG and basic blocks containing insns.

gcc/ChangeLog:
        * Makefile.in (OBJS): Add errors.o, read-md.o, read-rtl.o,
        read-rtl-function.o, and selftest-rtl.o.

        * cfgexpand.c (pass_expand::execute): Move stack initializations
        to rtl_data::init_stack_alignment and call it.  Pass "true"
        for new "emit_insns" param of expand_function_start.
        * emit-rtl.c (gen_reg_rtx): Move regno_pointer_align and
        regno_reg_rtx resizing logic to...
        (emit_status::ensure_regno_capacity): ...this new method.
        (init_emit): Allocate regno_reg_rtx using ggc_cleared_vec_alloc
        rather than ggc_vec_alloc.
        (rtl_data::init_stack_alignment): New method.
        (get_insn_by_uid): New function.
        * emit-rtl.h (rtl_data::init_stack_alignment): New method.
        * errors.c: Use consistent pattern for bconfig.h vs config.h
        includes.
        (progname): Wrap with #ifdef GENERATOR_FILE.
        (error): Likewise.  Add "error: " to message.
        (fatal): Likewise.
        (internal_error): Likewise.
        (trim_filename): Likewise.
        (fancy_abort): Likewise.
        * errors.h (struct file_location): Move here from read-md.h.
        (file_location::file_location): Likewise.
        (error_at): New decl.
        * function-tests.c (selftest::verify_three_block_rtl_cfg): Remove
        "static".
        * function.c (instantiate_decls): Guard call to
        instantiate_decls_1 with if (DECL_INITIAL (fndecl)).
        (expand_function_start): Add param "emit_insns", and use it to
        guard the various gen/emit calls.
        * function.h (emit_status::ensure_regno_capacity): New method.
        (expand_function_start): Add bool param to decl.
        * gensupport.c (gen_reader::gen_reader): Add NULL for new policy
        param of rtx_reader ctor.
        * print-rtl.c (print_rtx): Print "(nil)" rather than an empty
        string for NULL strings.  Print "(nil)" for NULL basic blocks.
        * read-md.c (read_skip_construct): Provide forward decl.
        (read_skip_spaces): Support '/'.
        (require_char): New function.
        (require_word_ws): New function.
        (peek_char): New function.
        (read_name): Rename to...
        (read_name_1): ...this new static function, adding "out_loc" param,
        and converting "missing name or number" to returning false, rather
        than failing.
        (read_name): Reimplement in terms of read_name_1.
        (read_name_or_nil): New function.
        (read_string): Handle "(nil)" by returning NULL.  */
        (rtx_reader::rtx_reader): Add rtl_reader_policy * param, using
        it to initialize m_policy.
        (rtx_reader::~rtx_reader): Free m_base_dir.  Clean up global data.
        * read-md.h (struct file_location): Move to errors.h.
        (file_location::file_location): Likewise.
        Include errors.h.
        (class regno_remapper): New class.
        (struct rtl_reader_policy): New struct.
        (rtx_reader::rtx_reader): Add rtl_reader_policy * param.
        (rtx_reader::add_fixup_insn_uid): New vfunc.
        (rtx_reader::add_fixup_bb): New vfunc.
        (rtx_reader::add_fixup_note_insn_basic_block): New vfunc.
        (rtx_reader::add_fixup_source_location): New vfunc.
        (rtx_reader::add_fixup_jump_label): New vfunc.
        (rtx_reader::add_fixup_expr): New vfunc.
        (rtx_reader::remap_regno): New method.
        (rtx_reader::m_policy): New field.
        (noop_reader::noop_reader): Add NULL for new policy param of
        rtx_reader ctor.
        (peek_char): New decl.
        (require_char): New decl.
        (require_word_ws): New decl.
        (read_name): Convert return type from void to file_location.
        (read_name_or_nil): New decl.
        * read-rtl-function.c: New file.
        * read-rtl-function.h: New file.
        * read-rtl.c: Potentially include config.h rather than bconfig.h.
        For host, include function.h and emit-rtl.h.
        (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.
        (read_mapping): Likewise.
        (add_define_attr_for_define_subst): Likewise.
        (add_define_subst_attr): Likewise.
        (read_subst_mapping): Likewise.
        (check_code_iterator): Likewise.
        (read_rtx): Likewise.  Move one-time initialization logic to...
        (one_time_initialization): New function.
        (parse_reg_note_name): New function.
        (parse_note_insn_name): New function.
        (maybe_read_location): New function.
        (read_until): New function.
        (strip_trailing_whitespace): New function.
        (read_flags): New function.
        (regno_remapper::get_effective_regno): New method.
        (rtx_reader::remap_regno): New method.
        (read_rtx_code): Remove "static".  Initialize "iterator" to NULL.
        Call one_time_initialization.  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 SYMBOL_REF data, REG_NOTE names,
        INSN_UID values, note-specific data, basic block IDs,
        jump labels, hexdump values of wide ints, REG_EXPR, MEM_EXPR,
        skipping recognized insn names, remapping register numbers.
        When on host, reallocate XSTR and XTMPL fields in the GC-managed
        heap.
        (lookup_global_register): New function.
        (consolidate_reg): New function.
        (consolidate_singletons): New function.
        (read_nested_rtx): Call consolidate_singletons.
        * rtl.h (read_rtx): Wrap decl with #ifdef GENERATOR_FILE.
        (read_rtx_code): New decl.
        * selftest-rtl.c: New file.
        * selftest-rtl.h: New file.
        * selftest-run-tests.c (selftest::run_tests): Run
        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.
So I see a couple conceptual things going on here.

First is initialization/finalization/state handling and various fallout items. Essentially it encompasses all changes that we can make a case are useful cleanups and should be handled independently.

Second is all the grunt work necessary to suck in a RTL reader into the target's cc1. The Makefile.in changes, all the GENERATOR_FILE stuff, and of course the new rtx_reader class, regno_mapper and the like.

I think that'll allow us to spend more time looking at the raw mechanics of how to pull in an RTL reader into cc1.

Jeff

Reply via email to