diff options
author | David Malcolm <dmalcolm@redhat.com> | 2013-08-05 20:01:43 +0000 |
---|---|---|
committer | David Malcolm <dmalcolm@gcc.gnu.org> | 2013-08-05 20:01:43 +0000 |
commit | f7695dbf402847104b2330126a3c61fae199cc1a (patch) | |
tree | cdd5686bbad14a7a9b7c4e8de621c8b7b8826c56 /gcc/tree-pass.h | |
parent | d0b2f8311e5e1917464aa4f65d506fbe4e580eb1 (diff) | |
download | gcc-f7695dbf402847104b2330126a3c61fae199cc1a.zip gcc-f7695dbf402847104b2330126a3c61fae199cc1a.tar.gz gcc-f7695dbf402847104b2330126a3c61fae199cc1a.tar.bz2 |
Handwritten part of conversion of passes to C++ classes
gcc/
* Makefile.in (PASS_MANAGER_H): Add dep on pass-instances.def.
(toplev.o): Add dep on PASS_MANAGER_H.
* cgraphunit.c (cgraph_process_new_functions): Rework invocation
of early local pases to reflect this moving from a global to a
member of gcc::pass_manager.
(cgraph_add_new_function): Likewise.
* lto-cgraph.c (lto_output_node): Update for conversion of
struct ipa_opt_pass_d to a C++ subclass of opt_pass.
* passes.c (opt_pass::clone): New.
(opt_pass::gate): New.
(opt_pass::execute): New.
(opt_pass::opt_pass): New.
(pass_manager::execute_early_local_passes): New.
(pass_manager::execute_pass_mode_switching): new.
(finish_optimization_passes): Convert to...
(pass_manager::finish_optimization_passes): ...this.
(finish_optimization_passes): Update for conversion of passes to
C++ classes.
(register_dump_files_1): Use has_gate since we cannot portably
check a vtable entry against NULL.
(dump_one_pass): Likewise.
(ipa_write_summaries_2): Likewise.
(ipa_write_optimization_summaries_1): Likewise.
(ipa_read_summaries_1): Likewise.
(ipa_read_optimization_summaries_1): Likewise.
(execute_ipa_stmt_fixups): Likewise.
(pass_manager::pass_manager): Rewrite pass-creation, invoking
pass-creation functions rather than wiring up globals, and
storing the results in fields of pass_manager generated using
pass-instances.def.
(pass_manager::dump_profile_report): Update for conversion of
passes to C++ classes.
(pass_manager::execute_ipa_summary_passes): Likewise.
(execute_one_ipa_transform_pass): Likewise.
(execute_one_pass): Use has_gate and has_execute since we cannot
portably check a vtable entry against NULL.
* pass_manager.h (pass_manager::finish_optimization_passes): New.
(pass_manager): Use pass-instances.def to add fields for the
various pass instances.
* toplev.c (finalize): Update for move of
finish_optimization_passes to a method of gcc::pass_manager.
* toplev.h (finish_optimization_passes): Move to method of class
pass_manager.
* tree-pass.h (struct pass_data): New.
(opt_pass): Convert to C++ class, make it a subclass of
pass_data.
(opt_pass::gate): Convert to virtual function.
(opt_pass::~opt_pass): New.
(opt_pass::clone): New.
(opt_pass::execute): Convert to virtual function.
(opt_pass::opt_pass): New.
(opt_pass::ctxt_): new.
(gimple_opt_pass): Convert to subclass of opt_pass.
(gimple_opt_pass::gimple_opt_pass): New.
(rtl_opt_pass): Convert to subclass of opt_pass.
(rtl_opt_pass::rtl_opt_pass): New.
(ipa_opt_pass_d): Convert to subclass of opt_pass.
(ipa_opt_pass_d::ipa_opt_pass_d): New.
(simple_ipa_opt_pass): Convert to subclass of opt_pass.
(simple_ipa_opt_pass::simple_ipa_opt_pass): New.
* config/i386/i386.c (rest_of_handle_insert_vzeroupper): Rework
invocation of pass_mode_switching to reflect this moving from a
global to a member of gcc::pass_manager.
(ix86_option_override): Rework how pass_insert_vzeroupper is
added to the pass_manager to reflect autogenerated changes.
* config/i386/t-i386 (i386.o) Add deps on CONTEXT_H and
PASS_MANAGER_H.
gcc/testsuite/
* g++.dg/plugin/dumb_plugin.c (plugin_init): Rework how the pass
is created and added to the pass_manager to reflect
autogenerated changes.
* g++.dg/plugin/selfassign.c (plugin_init): Likewise.
* gcc.dg/plugin/one_time_plugin.c (plugin_init): Likewise.
* gcc.dg/plugin/selfassign.c (plugin_init): Likewise.
From-SVN: r201505
Diffstat (limited to 'gcc/tree-pass.h')
-rw-r--r-- | gcc/tree-pass.h | 129 |
1 files changed, 101 insertions, 28 deletions
diff --git a/gcc/tree-pass.h b/gcc/tree-pass.h index 16442ed..41f7d17 100644 --- a/gcc/tree-pass.h +++ b/gcc/tree-pass.h @@ -34,9 +34,8 @@ enum opt_pass_type IPA_PASS }; -/* Describe one pass; this is the common part shared across different pass - types. */ -struct opt_pass +/* Metadata for a pass, non-varying across all instances of a pass. */ +struct pass_data { /* Optimization pass type. */ enum opt_pass_type type; @@ -48,23 +47,13 @@ struct opt_pass /* The -fopt-info optimization group flags as defined in dumpfile.h. */ unsigned int optinfo_flags; - /* If non-null, this pass and all sub-passes are executed only if - the function returns true. */ - bool (*gate) (void); + /* If true, this pass has its own implementation of the opt_pass::gate + method. */ + bool has_gate; - /* This is the code to run. If null, then there should be sub-passes - otherwise this pass does nothing. The return value contains - TODOs to execute in addition to those in TODO_flags_finish. */ - unsigned int (*execute) (void); - - /* A list of sub-passes to run, dependent on gate predicate. */ - struct opt_pass *sub; - - /* Next in the list of passes to run, independent of gate predicate. */ - struct opt_pass *next; - - /* Static pass number, used as a fragment of the dump file name. */ - int static_pass_number; + /* If true, this pass has its own implementation of the opt_pass::execute + method. */ + bool has_execute; /* The timevar id associated with this pass. */ /* ??? Ideally would be dynamically assigned. */ @@ -80,16 +69,72 @@ struct opt_pass unsigned int todo_flags_finish; }; +namespace gcc +{ + class context; +} // namespace gcc + +/* An instance of a pass. This is also "pass_data" to minimize the + changes in existing code. */ +class opt_pass : public pass_data +{ +public: + virtual ~opt_pass () { } + + /* Create a copy of this pass. + + Passes that can have multiple instances must provide their own + implementation of this, to ensure that any sharing of state between + this instance and the copy is "wired up" correctly. + + The default implementation prints an error message and aborts. */ + virtual opt_pass *clone (); + + /* If has_gate is set, this pass and all sub-passes are executed only if + the function returns true. */ + virtual bool gate (); + + /* This is the code to run. If has_execute is false, then there should + be sub-passes otherwise this pass does nothing. + The return value contains TODOs to execute in addition to those in + TODO_flags_finish. */ + virtual unsigned int execute (); + +protected: + opt_pass(const pass_data&, gcc::context *); + +public: + /* A list of sub-passes to run, dependent on gate predicate. */ + struct opt_pass *sub; + + /* Next in the list of passes to run, independent of gate predicate. */ + struct opt_pass *next; + + /* Static pass number, used as a fragment of the dump file name. */ + int static_pass_number; + +protected: + gcc::context *ctxt_; +}; + /* Description of GIMPLE pass. */ -struct gimple_opt_pass +class gimple_opt_pass : public opt_pass { - struct opt_pass pass; +protected: + gimple_opt_pass(const pass_data& data, gcc::context *ctxt) + : opt_pass(data, ctxt) + { + } }; /* Description of RTL pass. */ -struct rtl_opt_pass +class rtl_opt_pass : public opt_pass { - struct opt_pass pass; +protected: + rtl_opt_pass(const pass_data& data, gcc::context *ctxt) + : opt_pass(data, ctxt) + { + } }; struct varpool_node; @@ -98,10 +143,9 @@ struct lto_symtab_encoder_d; /* Description of IPA pass with generate summary, write, execute, read and transform stages. */ -struct ipa_opt_pass_d +class ipa_opt_pass_d : public opt_pass { - struct opt_pass pass; - +public: /* IPA passes can analyze function body and variable initializers using this hook and produce summary. */ void (*generate_summary) (void); @@ -127,13 +171,42 @@ struct ipa_opt_pass_d unsigned int function_transform_todo_flags_start; unsigned int (*function_transform) (struct cgraph_node *); void (*variable_transform) (struct varpool_node *); + +protected: + ipa_opt_pass_d(const pass_data& data, gcc::context *ctxt, + void (*generate_summary) (void), + void (*write_summary) (void), + void (*read_summary) (void), + void (*write_optimization_summary) (void), + void (*read_optimization_summary) (void), + void (*stmt_fixup) (struct cgraph_node *, gimple *), + unsigned int function_transform_todo_flags_start, + unsigned int (*function_transform) (struct cgraph_node *), + void (*variable_transform) (struct varpool_node *)) + : opt_pass(data, ctxt), + generate_summary(generate_summary), + write_summary(write_summary), + read_summary(read_summary), + write_optimization_summary(write_optimization_summary), + read_optimization_summary(read_optimization_summary), + stmt_fixup(stmt_fixup), + function_transform_todo_flags_start( + function_transform_todo_flags_start), + function_transform(function_transform), + variable_transform(variable_transform) + { + } }; /* Description of simple IPA pass. Simple IPA passes have just one execute hook. */ -struct simple_ipa_opt_pass +class simple_ipa_opt_pass : public opt_pass { - struct opt_pass pass; +protected: + simple_ipa_opt_pass(const pass_data& data, gcc::context *ctxt) + : opt_pass(data, ctxt) + { + } }; /* Pass properties. */ |