Commit 47e0da37 by David Malcolm Committed by David Malcolm

Introduce gcc::dump_manager class

gcc/
	* dumpfile.h (gcc::dump_manager): New class, to hold state
	relating to dumpfile management.
	(get_dump_file_name): Remove in favor of method of dump_manager.
	(dump_initialized_p): Likewise.
	(dump_start): Likewise.
	(dump_finish): Likewise.
	(dump_switch_p): Likewise.
	(dump_register): Likewise.
	(get_dump_file_info): Likewise.
	* context.c (gcc::context::context): Construct the dump_manager
	instance.
	* context.h (gcc::context::get_dumps): New.
	(gcc::context::m_dumps): New.
	* coverage.c (coverage_init): Port to dump_manager API.
	* dumpfile.c (extra_dump_files): Convert to field of
	gcc::dump_manager.
	(extra_dump_files_in_use): Likewise.
	(extra_dump_files_alloced): Likewise.
	(gcc::dump_manager::dump_manager): New.
	(dump_register): Convert to...
	(gcc::dump_manager::dump_register): ...method, replacing
	function-static next_dump with m_next_dump field.
	(get_dump_file_info): Convert to...
	(gcc::dump_manager::get_dump_file_info): ...method.
	(get_dump_file_name): Convert to...
	(gcc::dump_manager::get_dump_file_name): ...method.
	(dump_start): Convert to...
	(gcc::dump_manager::dump_start): ...method.
	(dump_finish): Convert to...
	(gcc::dump_manager::dump_finish): ...method.
	(dump_begin): Replace body with...
	(gcc::dump_manager::dump_begin): ...new method.
	(dump_phase_enabled_p): Convert to...
	(gcc::dump_manager::dump_phase_enabled_p): ...method.
	(dump_phase_enabled_p): Convert to...
	(gcc::dump_manager::dump_phase_enabled_p): ...method.
	(dump_initialized_p):  Convert to...
	(gcc::dump_manager::dump_initialized_p): ...method.
	(dump_flag_name): Replace body with...
	(gcc::dump_manager::dump_flag_name): ...new method.
	(dump_enable_all): Convert to...
	(gcc::dump_manager::dump_enable_all): ...new method.
	(opt_info_enable_passes): Convert to...
	(gcc::dump_manager::opt_info_enable_passes): ...new method.
	(dump_switch_p_1): Convert to...
	(gcc::dump_manager::dump_switch_p_1): ...new method.
	(dump_switch_p):  Convert to...
	(gcc::dump_manager::dump_switch_p): ...new method.
	(opt_info_switch_p): Port to dump_manager API.
	(enable_rtl_dump_file): Likewise.
	* opts-global.c (handle_common_deferred_options): Port to new
	dump_manager API.
	* passes.c (pass_manager::finish_optimization_passes): Likewise.
	(pass_manager::register_one_dump_file): Likewise.
	(pass_manager::register_pass): Likewise.
	(pass_init_dump_file): Likewise.
	(pass_fini_dump_file): Likewise.
	* statistics.c (statistics_early_init): Likewise.

gcc/java/

	* lang.c (java_handle_option): Update for introduction of
	gcc::dump_manager.

From-SVN: r203569
parent 811189d9
2013-10-14 David Malcolm <dmalcolm@redhat.com>
* dumpfile.h (gcc::dump_manager): New class, to hold state
relating to dumpfile management.
(get_dump_file_name): Remove in favor of method of dump_manager.
(dump_initialized_p): Likewise.
(dump_start): Likewise.
(dump_finish): Likewise.
(dump_switch_p): Likewise.
(dump_register): Likewise.
(get_dump_file_info): Likewise.
* context.c (gcc::context::context): Construct the dump_manager
instance.
* context.h (gcc::context::get_dumps): New.
(gcc::context::m_dumps): New.
* coverage.c (coverage_init): Port to dump_manager API.
* dumpfile.c (extra_dump_files): Convert to field of
gcc::dump_manager.
(extra_dump_files_in_use): Likewise.
(extra_dump_files_alloced): Likewise.
(gcc::dump_manager::dump_manager): New.
(dump_register): Convert to...
(gcc::dump_manager::dump_register): ...method, replacing
function-static next_dump with m_next_dump field.
(get_dump_file_info): Convert to...
(gcc::dump_manager::get_dump_file_info): ...method.
(get_dump_file_name): Convert to...
(gcc::dump_manager::get_dump_file_name): ...method.
(dump_start): Convert to...
(gcc::dump_manager::dump_start): ...method.
(dump_finish): Convert to...
(gcc::dump_manager::dump_finish): ...method.
(dump_begin): Replace body with...
(gcc::dump_manager::dump_begin): ...new method.
(dump_phase_enabled_p): Convert to...
(gcc::dump_manager::dump_phase_enabled_p): ...method.
(dump_phase_enabled_p): Convert to...
(gcc::dump_manager::dump_phase_enabled_p): ...method.
(dump_initialized_p): Convert to...
(gcc::dump_manager::dump_initialized_p): ...method.
(dump_flag_name): Replace body with...
(gcc::dump_manager::dump_flag_name): ...new method.
(dump_enable_all): Convert to...
(gcc::dump_manager::dump_enable_all): ...new method.
(opt_info_enable_passes): Convert to...
(gcc::dump_manager::opt_info_enable_passes): ...new method.
(dump_switch_p_1): Convert to...
(gcc::dump_manager::dump_switch_p_1): ...new method.
(dump_switch_p): Convert to...
(gcc::dump_manager::dump_switch_p): ...new method.
(opt_info_switch_p): Port to dump_manager API.
(enable_rtl_dump_file): Likewise.
* opts-global.c (handle_common_deferred_options): Port to new
dump_manager API.
* passes.c (pass_manager::finish_optimization_passes): Likewise.
(pass_manager::register_one_dump_file): Likewise.
(pass_manager::register_pass): Likewise.
(pass_init_dump_file): Likewise.
(pass_fini_dump_file): Likewise.
* statistics.c (statistics_early_init): Likewise.
2013-10-14 Richard Biener <rguenther@suse.de>
* gimple.c (gimple_canonical_types, canonical_type_hash_cache,
......
......@@ -23,11 +23,16 @@ along with GCC; see the file COPYING3. If not see
#include "ggc.h"
#include "context.h"
#include "pass_manager.h"
#include "dumpfile.h"
/* The singleton holder of global state: */
gcc::context *g;
gcc::context::context ()
{
/* The pass manager's constructor uses the dump manager (to set up
dumps for the various passes), so the dump manager must be set up
before the pass manager. */
m_dumps = new gcc::dump_manager ();
m_passes = new gcc::pass_manager (this);
}
......@@ -23,6 +23,7 @@ along with GCC; see the file COPYING3. If not see
namespace gcc {
class pass_manager;
class dump_manager;
/* GCC's internal state can be divided into zero or more
"parallel universe" of state; an instance of this class is one such
......@@ -36,10 +37,17 @@ public:
pass_manager *get_passes () { gcc_assert (m_passes); return m_passes; }
/* Handling dump files. */
dump_manager *get_dumps () {gcc_assert (m_dumps); return m_dumps; }
private:
/* Pass-management. */
pass_manager *m_passes;
/* Dump files. */
dump_manager *m_dumps;
}; // class context
} // namespace gcc
......
......@@ -1137,7 +1137,9 @@ coverage_init (const char *filename)
/* Since coverage_init is invoked very early, before the pass
manager, we need to set up the dumping explicitly. This is
similar to the handling in finish_optimization_passes. */
dump_start (g->get_passes ()->get_pass_profile ()->static_pass_number, NULL);
int profile_pass_num =
g->get_passes ()->get_pass_profile ()->static_pass_number;
g->get_dumps ()->dump_start (profile_pass_num, NULL);
if (!profile_data_prefix && !IS_ABSOLUTE_PATH (filename))
profile_data_prefix = getpwd ();
......@@ -1182,7 +1184,7 @@ coverage_init (const char *filename)
}
}
dump_finish (g->get_passes ()->get_pass_profile ()->static_pass_number);
g->get_dumps ()->dump_finish (profile_pass_num);
}
/* Performs file-level cleanup. Close notes file, generate coverage
......
......@@ -121,13 +121,8 @@ struct dump_file_info
};
/* In dumpfile.c */
extern char *get_dump_file_name (int);
extern int dump_initialized_p (int);
extern FILE *dump_begin (int, int *);
extern void dump_end (int, FILE *);
extern int dump_start (int, int *);
extern void dump_finish (int);
extern int dump_switch_p (const char *);
extern int opt_info_switch_p (const char *);
extern const char *dump_flag_name (int);
extern void dump_printf (int, const char *, ...) ATTRIBUTE_PRINTF_2;
......@@ -139,8 +134,6 @@ extern void dump_generic_expr (int, int, tree);
extern void dump_gimple_stmt_loc (int, source_location, int, gimple, int);
extern void dump_gimple_stmt (int, int, gimple, int);
extern void print_combine_total_stats (void);
extern unsigned int dump_register (const char *, const char *, const char *,
int, int);
extern bool enable_rtl_dump_file (void);
/* In tree-dump.c */
......@@ -157,9 +150,6 @@ extern FILE *alt_dump_file;
extern int dump_flags;
extern const char *dump_file_name;
/* Return the dump_file_info for the given phase. */
extern struct dump_file_info *get_dump_file_info (int);
/* Return true if any of the dumps is enabled, false otherwise. */
static inline bool
dump_enabled_p (void)
......@@ -167,4 +157,84 @@ dump_enabled_p (void)
return (dump_file || alt_dump_file);
}
namespace gcc {
class dump_manager
{
public:
dump_manager ();
unsigned int
dump_register (const char *suffix, const char *swtch, const char *glob,
int flags, int optgroup_flags);
/* Return the dump_file_info for the given phase. */
struct dump_file_info *
get_dump_file_info (int phase) const;
/* Return the name of the dump file for the given phase.
If the dump is not enabled, returns NULL. */
char *
get_dump_file_name (int phase) const;
int
dump_switch_p (const char *arg);
/* Start a dump for PHASE. Store user-supplied dump flags in
*FLAG_PTR. Return the number of streams opened. Set globals
DUMP_FILE, and ALT_DUMP_FILE to point to the opened streams, and
set dump_flags appropriately for both pass dump stream and
-fopt-info stream. */
int
dump_start (int phase, int *flag_ptr);
/* Finish a tree dump for PHASE and close associated dump streams. Also
reset the globals DUMP_FILE, ALT_DUMP_FILE, and DUMP_FLAGS. */
void
dump_finish (int phase);
FILE *
dump_begin (int phase, int *flag_ptr);
/* Returns nonzero if tree dump PHASE has been initialized. */
int
dump_initialized_p (int phase) const;
/* Returns the switch name of PHASE. */
const char *
dump_flag_name (int phase) const;
private:
int
dump_phase_enabled_p (int phase) const;
int
dump_switch_p_1 (const char *arg, struct dump_file_info *dfi, bool doglob);
int
dump_enable_all (int flags, const char *filename);
int
opt_info_enable_passes (int optgroup_flags, int flags, const char *filename);
private:
/* Dynamically registered dump files and switches. */
int m_next_dump;
struct dump_file_info *m_extra_dump_files;
size_t m_extra_dump_files_in_use;
size_t m_extra_dump_files_alloced;
/* Grant access to dump_enable_all. */
friend bool ::enable_rtl_dump_file (void);
/* Grant access to opt_info_enable_passes. */
friend int ::opt_info_switch_p (const char *arg);
}; // class dump_manager
} // namespace gcc
#endif /* GCC_DUMPFILE_H */
2013-10-14 David Malcolm <dmalcolm@redhat.com>
* lang.c (java_handle_option): Update for introduction of
gcc::dump_manager.
2013-09-25 Tom Tromey <tromey@redhat.com>
* Make-lang.in (jvspec.o): Remove.
......
......@@ -42,6 +42,7 @@ The Free Software Foundation is independent of Sun Microsystems, Inc. */
#include "opts.h"
#include "options.h"
#include "target.h"
#include "context.h"
static bool java_init (void);
static void java_finish (void);
......@@ -271,7 +272,7 @@ java_handle_option (size_t scode, const char *arg, int value,
break;
case OPT_fdump_:
if (!dump_switch_p (arg))
if (!g->get_dumps ()->dump_switch_p (arg))
return false;
break;
......
......@@ -36,6 +36,7 @@ along with GCC; see the file COPYING3. If not see
#include "plugin.h"
#include "toplev.h"
#include "tree-pass.h"
#include "context.h"
typedef const char *const_char_p; /* For DEF_VEC_P. */
......@@ -385,7 +386,7 @@ handle_common_deferred_options (void)
break;
case OPT_fdump_:
if (!dump_switch_p (opt->arg))
if (!g->get_dumps ()->dump_switch_p (opt->arg))
error ("unrecognized command line option %<-fdump-%s%>", opt->arg);
break;
......
......@@ -279,27 +279,28 @@ finish_optimization_passes (void)
int i;
struct dump_file_info *dfi;
char *name;
gcc::dump_manager *dumps = m_ctxt->get_dumps ();
timevar_push (TV_DUMP);
if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
{
dump_start (pass_profile_1->static_pass_number, NULL);
dumps->dump_start (pass_profile_1->static_pass_number, NULL);
end_branch_prob ();
dump_finish (pass_profile_1->static_pass_number);
dumps->dump_finish (pass_profile_1->static_pass_number);
}
if (optimize > 0)
{
dump_start (pass_profile_1->static_pass_number, NULL);
dumps->dump_start (pass_profile_1->static_pass_number, NULL);
print_combine_total_stats ();
dump_finish (pass_profile_1->static_pass_number);
dumps->dump_finish (pass_profile_1->static_pass_number);
}
/* Do whatever is necessary to finish printing the graphs. */
for (i = TDI_end; (dfi = get_dump_file_info (i)) != NULL; ++i)
if (dump_initialized_p (i)
for (i = TDI_end; (dfi = dumps->get_dump_file_info (i)) != NULL; ++i)
if (dumps->dump_initialized_p (i)
&& (dfi->pflags & TDF_GRAPH) != 0
&& (name = get_dump_file_name (i)) != NULL)
&& (name = dumps->get_dump_file_name (i)) != NULL)
{
finish_graph_dump_file (name);
free (name);
......@@ -642,6 +643,7 @@ pass_manager::register_one_dump_file (struct opt_pass *pass)
char num[10];
int flags, id;
int optgroup_flags = OPTGROUP_NONE;
gcc::dump_manager *dumps = m_ctxt->get_dumps ();
/* See below in next_pass_1. */
num[0] = '\0';
......@@ -682,7 +684,8 @@ pass_manager::register_one_dump_file (struct opt_pass *pass)
any dump messages are emitted properly under -fopt-info(-optall). */
if (optgroup_flags == OPTGROUP_NONE)
optgroup_flags = OPTGROUP_OTHER;
id = dump_register (dot_name, flag_name, glob_name, flags, optgroup_flags);
id = dumps->dump_register (dot_name, flag_name, glob_name, flags,
optgroup_flags);
set_pass_for_id (id, pass);
full_name = concat (prefix, pass->name, num, NULL);
register_pass_name (pass, full_name);
......@@ -1390,6 +1393,7 @@ 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
......@@ -1447,9 +1451,9 @@ pass_manager::register_pass (struct register_pass_info *pass_info)
else
tdi = TDI_rtl_all;
/* Check if dump-all flag is specified. */
if (get_dump_file_info (tdi)->pstate)
get_dump_file_info (added_pass_nodes->pass->static_pass_number)
->pstate = get_dump_file_info (tdi)->pstate;
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;
XDELETE (added_pass_nodes);
added_pass_nodes = next_node;
}
......@@ -1932,9 +1936,11 @@ pass_init_dump_file (struct opt_pass *pass)
if (pass->static_pass_number != -1)
{
timevar_push (TV_DUMP);
bool initializing_dump = !dump_initialized_p (pass->static_pass_number);
dump_file_name = get_dump_file_name (pass->static_pass_number);
dump_start (pass->static_pass_number, &dump_flags);
gcc::dump_manager *dumps = g->get_dumps ();
bool initializing_dump =
!dumps->dump_initialized_p (pass->static_pass_number);
dump_file_name = dumps->get_dump_file_name (pass->static_pass_number);
dumps->dump_start (pass->static_pass_number, &dump_flags);
if (dump_file && current_function_decl)
dump_function_header (dump_file, current_function_decl, dump_flags);
if (initializing_dump
......@@ -1963,7 +1969,7 @@ pass_fini_dump_file (struct opt_pass *pass)
dump_file_name = NULL;
}
dump_finish (pass->static_pass_number);
g->get_dumps ()->dump_finish (pass->static_pass_number);
timevar_pop (TV_DUMP);
}
......
......@@ -260,8 +260,10 @@ statistics_fini (void)
void
statistics_early_init (void)
{
statistics_dump_nr = dump_register (".statistics", "statistics",
"statistics", TDF_TREE, OPTGROUP_NONE);
gcc::dump_manager *dumps = g->get_dumps ();
statistics_dump_nr = dumps->dump_register (".statistics", "statistics",
"statistics", TDF_TREE,
OPTGROUP_NONE);
}
/* Init the statistics. */
......@@ -269,8 +271,9 @@ statistics_early_init (void)
void
statistics_init (void)
{
gcc::dump_manager *dumps = g->get_dumps ();
statistics_dump_file = dump_begin (statistics_dump_nr, NULL);
statistics_dump_flags = get_dump_file_info (statistics_dump_nr)->pflags;
statistics_dump_flags = dumps->get_dump_file_info (statistics_dump_nr)->pflags;
}
/* Lookup or add a statistics counter in the hashtable HASH with ID, VAL
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment