Re: [PATCH 5/9] Introduce class function_reader

2016-09-19 Thread Jeff Law

On 09/16/2016 03:42 PM, David Malcolm wrote:

On Fri, 2016-09-16 at 15:28 -0600, Jeff Law wrote:

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.

Re: [PATCH 5/9] Introduce class function_reader

2016-09-16 Thread David Malcolm
On Fri, 2016-09-16 at 15:28 -0600, Jeff Law wrote:
> 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 

Re: [PATCH 5/9] Introduce class function_reader

2016-09-16 Thread Jeff Law

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.