From 5d98e5a6bc715cc865b9110ff0255572ac22570d Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Thu, 4 Oct 2018 14:33:47 +0000 Subject: Fix -fopt-info for plugin passes Attempts to dump via -fopt-info from a plugin pass fail, due to the dfi->alt_state for such passes never being set. This is because the -fopt-info options were being set up per-pass during option-parsing (via gcc::dump_manager::opt_info_enable_passes), but this data was not retained or used it for passes created later (for plugins and target-specific passes). This patch fixes the issue by storing the -fopt-info options into gcc::dump_manager, refactoring the dfi-setup code out of opt_info_enable_passes, and reusing it for such passes, fixing the issue. The patch adds a demo plugin to test that dumping from a plugin works. gcc/ChangeLog: * dumpfile.c (gcc::dump_manager::dump_manager): Initialize new fields. (gcc::dump_manager::~dump_manager): Free m_optinfo_filename. (gcc::dump_manager::register_pass): New member function, adapted from loop body in gcc::pass_manager::register_pass, adding a call to update_dfi_for_opt_info. (gcc::dump_manager::opt_info_enable_passes): Store the -fopt-info options into the new fields. Move the loop bodies into... (gcc::dump_manager::update_dfi_for_opt_info): ...this new member function. * dumpfile.h (struct opt_pass): New forward decl. (gcc::dump_manager::register_pass): New decl. (gcc::dump_manager::update_dfi_for_opt_info): New decl. (class gcc::dump_manager): Add fields "m_optgroup_flags", "m_optinfo_flags", and "m_optinfo_filename". * passes.c (gcc::pass_manager::register_pass): Move all of the dump-handling code to gcc::dump_manager::register_pass. gcc/testsuite/ChangeLog: * gcc.dg/plugin/dump-1.c: New test. * gcc.dg/plugin/dump_plugin.c: New test plugin. * gcc.dg/plugin/plugin.exp (plugin_test_list): Add the above. From-SVN: r264844 --- gcc/passes.c | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-) (limited to 'gcc/passes.c') diff --git a/gcc/passes.c b/gcc/passes.c index 832f0b3..d838d90 100644 --- a/gcc/passes.c +++ b/gcc/passes.c @@ -1404,7 +1404,6 @@ void pass_manager::register_pass (struct register_pass_info *pass_info) { bool all_instances, success; - gcc::dump_manager *dumps = m_ctxt->get_dumps (); /* The checks below could fail in buggy plugins. Existing GCC passes should never fail these checks, so we mention plugin in @@ -1442,33 +1441,16 @@ pass_manager::register_pass (struct register_pass_info *pass_info) /* OK, we have successfully inserted the new pass. We need to register the dump files for the newly added pass and its duplicates (if any). - Because the registration of plugin/backend passes happens after the - command-line options are parsed, the options that specify single - pass dumping (e.g. -fdump-tree-PASSNAME) cannot be used for new - passes. Therefore we currently can only enable dumping of - new passes when the 'dump-all' flags (e.g. -fdump-tree-all) - are specified. While doing so, we also delete the pass_list_node + While doing so, we also delete the pass_list_node objects created during pass positioning. */ + gcc::dump_manager *dumps = m_ctxt->get_dumps (); while (added_pass_nodes) { struct pass_list_node *next_node = added_pass_nodes->next; - enum tree_dump_index tdi; - register_one_dump_file (added_pass_nodes->pass); - if (added_pass_nodes->pass->type == SIMPLE_IPA_PASS - || added_pass_nodes->pass->type == IPA_PASS) - tdi = TDI_ipa_all; - else if (added_pass_nodes->pass->type == GIMPLE_PASS) - tdi = TDI_tree_all; - else - tdi = TDI_rtl_all; - /* Check if dump-all flag is specified. */ - if (dumps->get_dump_file_info (tdi)->pstate) - { - dumps->get_dump_file_info (added_pass_nodes->pass->static_pass_number) - ->pstate = dumps->get_dump_file_info (tdi)->pstate; - dumps->get_dump_file_info (added_pass_nodes->pass->static_pass_number) - ->pflags = dumps->get_dump_file_info (tdi)->pflags; - } + + /* Handle -fdump-* and -fopt-info. */ + dumps->register_pass (added_pass_nodes->pass); + XDELETE (added_pass_nodes); added_pass_nodes = next_node; } -- cgit v1.1