Commit 29b54a9d by David Malcolm Committed by David Malcolm

Hide alt_dump_file within dumpfile.c

This patch removes alt_dump_file from dumpfile.h, making it static
within dumpfile.c.  This allows for changing how -fopt-info is
implemented, and potentially adding other kinds of dump target, such
as remarks or optimization records.

Doing so requires changing the implementation of dump_enabled_p, so
the patch changes this to a simple lookup of a boolean global, which
is updated any time dump_file or alt_dump_file change.

gcc/ChangeLog:
	* cgraph.c (cgraph_node::get_body): Replace assignments to
	"dump_file" with calls to set_dump_file.
	* dumpfile.c (alt_dump_file): Make static, and group with...
	(alt_flags): ...this definition.
	(dumps_are_enabled): New variable.
	(refresh_dumps_are_enabled): New function.
	(set_dump_file): New function.
	(set_alt_dump_file): New function.
	(gcc::dump_manager::dump_start): Replace assignments to
	"dump_file" and "alt_dump_file" with calls to set_dump_file and
	set_alt_dump_file.
	(gcc::dump_manager::dump_finish): Likewise.
	* dumpfile.h (alt_dump_file): Delete decl.
	(dumps_are_enabled): New variable decl.
	(set_dump_file): New function decl.
	(dump_enabled_p): Rewrite in terms of new "dumps_are_enabled"
	global.
	* tree-nested.c (lower_nested_functions): Replace assignments to
	"dump_file" with calls to set_dump_file.

From-SVN: r262220
parent f601629c
2018-06-28 David Malcolm <dmalcolm@redhat.com>
* cgraph.c (cgraph_node::get_body): Replace assignments to
"dump_file" with calls to set_dump_file.
* dumpfile.c (alt_dump_file): Make static, and group with...
(alt_flags): ...this definition.
(dumps_are_enabled): New variable.
(refresh_dumps_are_enabled): New function.
(set_dump_file): New function.
(set_alt_dump_file): New function.
(gcc::dump_manager::dump_start): Replace assignments to
"dump_file" and "alt_dump_file" with calls to set_dump_file and
set_alt_dump_file.
(gcc::dump_manager::dump_finish): Likewise.
* dumpfile.h (alt_dump_file): Delete decl.
(dumps_are_enabled): New variable decl.
(set_dump_file): New function decl.
(dump_enabled_p): Rewrite in terms of new "dumps_are_enabled"
global.
* tree-nested.c (lower_nested_functions): Replace assignments to
"dump_file" with calls to set_dump_file.
2018-06-28 Eric Botcazou <ebotcazou@adacore.com> 2018-06-28 Eric Botcazou <ebotcazou@adacore.com>
* tree-cfg.c (verify_gimple_in_cfg): Call verify_location on the * tree-cfg.c (verify_gimple_in_cfg): Call verify_location on the
......
...@@ -3582,7 +3582,7 @@ cgraph_node::get_body (void) ...@@ -3582,7 +3582,7 @@ cgraph_node::get_body (void)
const char *saved_dump_file_name = dump_file_name; const char *saved_dump_file_name = dump_file_name;
dump_flags_t saved_dump_flags = dump_flags; dump_flags_t saved_dump_flags = dump_flags;
dump_file_name = NULL; dump_file_name = NULL;
dump_file = NULL; set_dump_file (NULL);
push_cfun (DECL_STRUCT_FUNCTION (decl)); push_cfun (DECL_STRUCT_FUNCTION (decl));
execute_all_ipa_transforms (); execute_all_ipa_transforms ();
...@@ -3593,7 +3593,7 @@ cgraph_node::get_body (void) ...@@ -3593,7 +3593,7 @@ cgraph_node::get_body (void)
updated = true; updated = true;
current_pass = saved_current_pass; current_pass = saved_current_pass;
dump_file = saved_dump_file; set_dump_file (saved_dump_file);
dump_file_name = saved_dump_file_name; dump_file_name = saved_dump_file_name;
dump_flags = saved_dump_flags; dump_flags = saved_dump_flags;
} }
......
...@@ -40,18 +40,52 @@ along with GCC; see the file COPYING3. If not see ...@@ -40,18 +40,52 @@ along with GCC; see the file COPYING3. If not see
(strncmp (whole, part, strlen (part)) ? NULL : whole + strlen (part)) (strncmp (whole, part, strlen (part)) ? NULL : whole + strlen (part))
static dump_flags_t pflags; /* current dump_flags */ static dump_flags_t pflags; /* current dump_flags */
static dump_flags_t alt_flags; /* current opt_info flags */
static void dump_loc (dump_flags_t, FILE *, source_location); static void dump_loc (dump_flags_t, FILE *, source_location);
/* Current -fopt-info output stream, if any, and flags. */
static FILE *alt_dump_file = NULL;
static dump_flags_t alt_flags;
static FILE *dump_open_alternate_stream (struct dump_file_info *); static FILE *dump_open_alternate_stream (struct dump_file_info *);
/* These are currently used for communicating between passes. /* These are currently used for communicating between passes.
However, instead of accessing them directly, the passes can use However, instead of accessing them directly, the passes can use
dump_printf () for dumps. */ dump_printf () for dumps. */
FILE *dump_file = NULL; FILE *dump_file = NULL;
FILE *alt_dump_file = NULL;
const char *dump_file_name; const char *dump_file_name;
dump_flags_t dump_flags; dump_flags_t dump_flags;
bool dumps_are_enabled = false;
/* Update the "dumps_are_enabled" global; to be called whenever dump_file
or alt_dump_file change. */
static void
refresh_dumps_are_enabled ()
{
dumps_are_enabled = (dump_file || alt_dump_file);
}
/* Set global "dump_file" to NEW_DUMP_FILE, refreshing the "dumps_are_enabled"
global. */
void
set_dump_file (FILE *new_dump_file)
{
dump_file = new_dump_file;
refresh_dumps_are_enabled ();
}
/* Set "alt_dump_file" to NEW_ALT_DUMP_FILE, refreshing the "dumps_are_enabled"
global. */
static void
set_alt_dump_file (FILE *new_alt_dump_file)
{
alt_dump_file = new_alt_dump_file;
refresh_dumps_are_enabled ();
}
#define DUMP_FILE_INFO(suffix, swtch, dkind, num) \ #define DUMP_FILE_INFO(suffix, swtch, dkind, num) \
{suffix, swtch, NULL, NULL, NULL, NULL, NULL, dkind, TDF_NONE, TDF_NONE, \ {suffix, swtch, NULL, NULL, NULL, NULL, NULL, dkind, TDF_NONE, TDF_NONE, \
...@@ -568,7 +602,7 @@ dump_start (int phase, dump_flags_t *flag_ptr) ...@@ -568,7 +602,7 @@ dump_start (int phase, dump_flags_t *flag_ptr)
} }
free (name); free (name);
dfi->pstream = stream; dfi->pstream = stream;
dump_file = dfi->pstream; set_dump_file (dfi->pstream);
/* Initialize current dump flags. */ /* Initialize current dump flags. */
pflags = dfi->pflags; pflags = dfi->pflags;
} }
...@@ -578,7 +612,7 @@ dump_start (int phase, dump_flags_t *flag_ptr) ...@@ -578,7 +612,7 @@ dump_start (int phase, dump_flags_t *flag_ptr)
{ {
dfi->alt_stream = stream; dfi->alt_stream = stream;
count++; count++;
alt_dump_file = dfi->alt_stream; set_alt_dump_file (dfi->alt_stream);
/* Initialize current -fopt-info flags. */ /* Initialize current -fopt-info flags. */
alt_flags = dfi->alt_flags; alt_flags = dfi->alt_flags;
} }
...@@ -609,8 +643,8 @@ dump_finish (int phase) ...@@ -609,8 +643,8 @@ dump_finish (int phase)
dfi->alt_stream = NULL; dfi->alt_stream = NULL;
dfi->pstream = NULL; dfi->pstream = NULL;
dump_file = NULL; set_dump_file (NULL);
alt_dump_file = NULL; set_alt_dump_file (NULL);
dump_flags = TDF_NONE; dump_flags = TDF_NONE;
alt_flags = TDF_NONE; alt_flags = TDF_NONE;
pflags = TDF_NONE; pflags = TDF_NONE;
......
...@@ -445,15 +445,18 @@ extern void dump_bb (FILE *, basic_block, int, dump_flags_t); ...@@ -445,15 +445,18 @@ extern void dump_bb (FILE *, basic_block, int, dump_flags_t);
/* Global variables used to communicate with passes. */ /* Global variables used to communicate with passes. */
extern FILE *dump_file; extern FILE *dump_file;
extern FILE *alt_dump_file;
extern dump_flags_t dump_flags; extern dump_flags_t dump_flags;
extern const char *dump_file_name; extern const char *dump_file_name;
extern bool dumps_are_enabled;
extern void set_dump_file (FILE *new_dump_file);
/* Return true if any of the dumps is enabled, false otherwise. */ /* Return true if any of the dumps is enabled, false otherwise. */
static inline bool static inline bool
dump_enabled_p (void) dump_enabled_p (void)
{ {
return (dump_file || alt_dump_file); return dumps_are_enabled;
} }
namespace gcc { namespace gcc {
......
...@@ -3399,7 +3399,7 @@ lower_nested_functions (tree fndecl) ...@@ -3399,7 +3399,7 @@ lower_nested_functions (tree fndecl)
gimplify_all_functions (cgn); gimplify_all_functions (cgn);
dump_file = dump_begin (TDI_nested, &dump_flags); set_dump_file (dump_begin (TDI_nested, &dump_flags));
if (dump_file) if (dump_file)
fprintf (dump_file, "\n;; Function %s\n\n", fprintf (dump_file, "\n;; Function %s\n\n",
lang_hooks.decl_printable_name (fndecl, 2)); lang_hooks.decl_printable_name (fndecl, 2));
...@@ -3426,7 +3426,7 @@ lower_nested_functions (tree fndecl) ...@@ -3426,7 +3426,7 @@ lower_nested_functions (tree fndecl)
if (dump_file) if (dump_file)
{ {
dump_end (TDI_nested, dump_file); dump_end (TDI_nested, dump_file);
dump_file = NULL; set_dump_file (NULL);
} }
} }
......
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