Commit 4df3629e by David Malcolm Committed by David Malcolm

Add "optinfo" framework

This patch implements a way to consolidate dump_* calls into
optinfo objects, as enabling work towards being able to write out
optimization records to a file.

The patch adds the support for building optinfo instances from dump_*
calls, but leaves implementing any *users* of them to followup patches.

gcc/ChangeLog:
	* Makefile.in (OBJS): Add optinfo.o.
	* coretypes.h (class symtab_node): New forward decl.
	(struct cgraph_node): New forward decl.
	(class varpool_node): New forward decl.
	* dump-context.h: New file.
	* dumpfile.c: Include "optinfo.h", "dump-context.h", "cgraph.h",
	"tree-pass.h".
	(refresh_dumps_are_enabled): Use optinfo_enabled_p.
	(set_dump_file): Call dumpfile_ensure_any_optinfo_are_flushed.
	(set_alt_dump_file): Likewise.
	(dump_context::~dump_context): New dtor.
	(dump_gimple_stmt): Move implementation to...
	(dump_context::dump_gimple_stmt): ...this new member function.
	Add the stmt to any pending optinfo, creating one if need be.
	(dump_gimple_stmt_loc): Move implementation to...
	(dump_context::dump_gimple_stmt_loc): ...this new member function.
	Start a new optinfo and add the stmt to it.
	(dump_gimple_expr): Move implementation to...
	(dump_context::dump_gimple_expr): ...this new member function.
	Add the stmt to any pending optinfo, creating one if need be.
	(dump_gimple_expr_loc): Move implementation to...
	(dump_context::dump_gimple_expr_loc): ...this new member function.
	Start a new optinfo and add the stmt to it.
	(dump_generic_expr): Move implementation to...
	(dump_context::dump_generic_expr): ...this new member function.
	Add the tree to any pending optinfo, creating one if need be.
	(dump_generic_expr_loc): Move implementation to...
	(dump_context::dump_generic_expr_loc): ...this new member
	function.  Add the tree to any pending optinfo, creating one if
	need be.
	(dump_printf): Move implementation to...
	(dump_context::dump_printf_va): ...this new member function.  Add
	the text to any pending optinfo, creating one if need be.
	(dump_printf_loc): Move implementation to...
	(dump_context::dump_printf_loc_va): ...this new member function.
	Start a new optinfo and add the stmt to it.
	(dump_dec): Move implementation to...
	(dump_context::dump_dec): ...this new member function.  Add the
	value to any pending optinfo, creating one if need be.
	(dump_context::dump_symtab_node): New member function.
	(dump_context::get_scope_depth): New member function.
	(dump_context::begin_scope): New member function.
	(dump_context::end_scope): New member function.
	(dump_context::ensure_pending_optinfo): New member function.
	(dump_context::begin_next_optinfo): New member function.
	(dump_context::end_any_optinfo): New member function.
	(dump_context::s_current): New global.
	(dump_context::s_default): New global.
	(dump_scope_depth): Delete global.
	(dumpfile_ensure_any_optinfo_are_flushed): New function.
	(dump_symtab_node): New function.
	(get_dump_scope_depth): Reimplement in terms of dump_context.
	(dump_begin_scope): Likewise.
	(dump_end_scope): Likewise.
	(selftest::temp_dump_context::temp_dump_context): New ctor.
	(selftest::temp_dump_context::~temp_dump_context): New dtor.
	(selftest::verify_item): New function.
	(ASSERT_IS_TEXT): New macro.
	(ASSERT_IS_TREE): New macro.
	(ASSERT_IS_GIMPLE): New macro.
	(selftest::test_capture_of_dump_calls): New test.
	(selftest::dumpfile_c_tests): Call it.
	* dumpfile.h (dump_printf, dump_printf_loc, dump_basic_block)
	(dump_generic_expr_loc, dump_generic_expr, dump_gimple_stmt_loc)
	(dump_gimple_stmt, dump_dec): Gather these related decls and add a
	descriptive comment.
	(dump_function, print_combine_total_stats, enable_rtl_dump_file)
	(dump_node, dump_bb): Move these unrelated decls.
	(class dump_manager): Add leading comment.
	* optinfo.cc: New file.
	* optinfo.h: New file.

From-SVN: r262891
parent 30c46053
2018-07-19 David Malcolm <dmalcolm@redhat.com>
* Makefile.in (OBJS): Add optinfo.o.
* coretypes.h (class symtab_node): New forward decl.
(struct cgraph_node): New forward decl.
(class varpool_node): New forward decl.
* dump-context.h: New file.
* dumpfile.c: Include "optinfo.h", "dump-context.h", "cgraph.h",
"tree-pass.h".
(refresh_dumps_are_enabled): Use optinfo_enabled_p.
(set_dump_file): Call dumpfile_ensure_any_optinfo_are_flushed.
(set_alt_dump_file): Likewise.
(dump_context::~dump_context): New dtor.
(dump_gimple_stmt): Move implementation to...
(dump_context::dump_gimple_stmt): ...this new member function.
Add the stmt to any pending optinfo, creating one if need be.
(dump_gimple_stmt_loc): Move implementation to...
(dump_context::dump_gimple_stmt_loc): ...this new member function.
Start a new optinfo and add the stmt to it.
(dump_gimple_expr): Move implementation to...
(dump_context::dump_gimple_expr): ...this new member function.
Add the stmt to any pending optinfo, creating one if need be.
(dump_gimple_expr_loc): Move implementation to...
(dump_context::dump_gimple_expr_loc): ...this new member function.
Start a new optinfo and add the stmt to it.
(dump_generic_expr): Move implementation to...
(dump_context::dump_generic_expr): ...this new member function.
Add the tree to any pending optinfo, creating one if need be.
(dump_generic_expr_loc): Move implementation to...
(dump_context::dump_generic_expr_loc): ...this new member
function. Add the tree to any pending optinfo, creating one if
need be.
(dump_printf): Move implementation to...
(dump_context::dump_printf_va): ...this new member function. Add
the text to any pending optinfo, creating one if need be.
(dump_printf_loc): Move implementation to...
(dump_context::dump_printf_loc_va): ...this new member function.
Start a new optinfo and add the stmt to it.
(dump_dec): Move implementation to...
(dump_context::dump_dec): ...this new member function. Add the
value to any pending optinfo, creating one if need be.
(dump_context::dump_symtab_node): New member function.
(dump_context::get_scope_depth): New member function.
(dump_context::begin_scope): New member function.
(dump_context::end_scope): New member function.
(dump_context::ensure_pending_optinfo): New member function.
(dump_context::begin_next_optinfo): New member function.
(dump_context::end_any_optinfo): New member function.
(dump_context::s_current): New global.
(dump_context::s_default): New global.
(dump_scope_depth): Delete global.
(dumpfile_ensure_any_optinfo_are_flushed): New function.
(dump_symtab_node): New function.
(get_dump_scope_depth): Reimplement in terms of dump_context.
(dump_begin_scope): Likewise.
(dump_end_scope): Likewise.
(selftest::temp_dump_context::temp_dump_context): New ctor.
(selftest::temp_dump_context::~temp_dump_context): New dtor.
(selftest::verify_item): New function.
(ASSERT_IS_TEXT): New macro.
(ASSERT_IS_TREE): New macro.
(ASSERT_IS_GIMPLE): New macro.
(selftest::test_capture_of_dump_calls): New test.
(selftest::dumpfile_c_tests): Call it.
* dumpfile.h (dump_printf, dump_printf_loc, dump_basic_block)
(dump_generic_expr_loc, dump_generic_expr, dump_gimple_stmt_loc)
(dump_gimple_stmt, dump_dec): Gather these related decls and add a
descriptive comment.
(dump_function, print_combine_total_stats, enable_rtl_dump_file)
(dump_node, dump_bb): Move these unrelated decls.
(class dump_manager): Add leading comment.
* optinfo.cc: New file.
* optinfo.h: New file.
2018-07-19 Michael Collison <michael.collison@arm.com>
Richard Henderson <rth@redhat.com>
......
......@@ -1427,6 +1427,7 @@ OBJS = \
optabs-libfuncs.o \
optabs-query.o \
optabs-tree.o \
optinfo.o \
options-save.o \
opts-global.o \
passes.o \
......
......@@ -134,6 +134,13 @@ struct gomp_single;
struct gomp_target;
struct gomp_teams;
/* Subclasses of symtab_node, using indentation to show the class
hierarchy. */
class symtab_node;
struct cgraph_node;
class varpool_node;
union section;
typedef union section section;
struct gcc_options;
......
/* Support code for handling the various dump_* calls in dumpfile.h
Copyright (C) 2018 Free Software Foundation, Inc.
Contributed by David Malcolm <dmalcolm@redhat.com>.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GCC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
#ifndef GCC_DUMP_CONTEXT_H
#define GCC_DUMP_CONTEXT_H 1
/* A class for handling the various dump_* calls.
In particular, this class has responsibility for consolidating
the "dump_*" calls into optinfo instances (delimited by "dump_*_loc"
calls), and emitting them.
Putting this in a class (rather than as global state) allows
for selftesting of this code. */
class dump_context
{
friend class temp_dump_context;
public:
static dump_context &get () { return *s_current; }
~dump_context ();
void dump_gimple_stmt (dump_flags_t dump_kind, dump_flags_t extra_dump_flags,
gimple *gs, int spc);
void dump_gimple_stmt_loc (dump_flags_t dump_kind,
const dump_location_t &loc,
dump_flags_t extra_dump_flags,
gimple *gs, int spc);
void dump_gimple_expr (dump_flags_t dump_kind,
dump_flags_t extra_dump_flags,
gimple *gs, int spc);
void dump_gimple_expr_loc (dump_flags_t dump_kind,
const dump_location_t &loc,
dump_flags_t extra_dump_flags,
gimple *gs,
int spc);
void dump_generic_expr (dump_flags_t dump_kind,
dump_flags_t extra_dump_flags,
tree t);
void dump_generic_expr_loc (dump_flags_t dump_kind,
const dump_location_t &loc,
dump_flags_t extra_dump_flags,
tree t);
void dump_printf_va (dump_flags_t dump_kind, const char *format,
va_list ap) ATTRIBUTE_PRINTF (3, 0);
void dump_printf_loc_va (dump_flags_t dump_kind, const dump_location_t &loc,
const char *format, va_list ap)
ATTRIBUTE_PRINTF (4, 0);
template<unsigned int N, typename C>
void dump_dec (dump_flags_t dump_kind, const poly_int<N, C> &value);
void dump_symtab_node (dump_flags_t dump_kind, symtab_node *node);
/* Managing nested scopes. */
unsigned int get_scope_depth () const;
void begin_scope (const char *name, const dump_location_t &loc);
void end_scope ();
/* For use in selftests; if true then optinfo_enabled_p is true. */
bool forcibly_enable_optinfo_p () const
{
return m_forcibly_enable_optinfo;
}
void end_any_optinfo ();
private:
optinfo &ensure_pending_optinfo ();
optinfo &begin_next_optinfo (const dump_location_t &loc);
/* For use in selftests; if true then optinfo_enabled_p is true. */
bool m_forcibly_enable_optinfo;
/* The current nesting depth of dump scopes, for showing nesting
via indentation). */
unsigned int m_scope_depth;
/* The optinfo currently being accumulated since the last dump_*_loc call,
if any. */
optinfo *m_pending;
/* The currently active dump_context, for use by the dump_* API calls. */
static dump_context *s_current;
/* The default active context. */
static dump_context s_default;
};
#if CHECKING_P
/* An RAII-style class for use in selftests for temporarily using a different
dump_context. */
class temp_dump_context
{
public:
temp_dump_context (bool forcibly_enable_optinfo);
~temp_dump_context ();
/* Support for selftests. */
optinfo *get_pending_optinfo () const { return m_context.m_pending; }
private:
dump_context m_context;
dump_context *m_saved;
bool m_saved_flag_remarks;
};
#endif /* CHECKING_P */
#endif /* GCC_DUMP_CONTEXT_H */
......@@ -420,6 +420,48 @@ extern FILE *dump_begin (int, dump_flags_t *, int part=-1);
extern void dump_end (int, FILE *);
extern int opt_info_switch_p (const char *);
extern const char *dump_flag_name (int);
/* Global variables used to communicate with passes. */
extern FILE *dump_file;
extern dump_flags_t dump_flags;
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. */
static inline bool
dump_enabled_p (void)
{
return dumps_are_enabled;
}
/* The following API calls (which *don't* take a "FILE *")
write the output to zero or more locations:
(a) the active dump_file, if any
(b) the -fopt-info destination, if any
(c) to the "optinfo" destinations, if any:
dump_* (MSG_*) --> dumpfile.c --+--> (a) dump_file
|
+--> (b) alt_dump_file
|
`--> (c) optinfo
`---> optinfo destinations
For optinfos, the dump_*_loc mark the beginning of an optinfo
instance: all subsequent dump_* calls are consolidated into
that optinfo, until the next dump_*_loc call (or a change in
dump scope, or a call to dumpfile_ensure_any_optinfo_are_flushed).
A group of dump_* calls should be guarded by:
if (dump_enabled_p ())
to minimize the work done for the common case where dumps
are disabled. */
extern void dump_printf (dump_flags_t, const char *, ...) ATTRIBUTE_PRINTF_2;
extern void dump_printf_loc (dump_flags_t, const dump_location_t &,
const char *, ...) ATTRIBUTE_PRINTF_3;
......@@ -434,37 +476,14 @@ extern void dump_gimple_stmt (dump_flags_t, dump_flags_t, gimple *, int);
extern void dump_gimple_expr_loc (dump_flags_t, const dump_location_t &,
dump_flags_t, gimple *, int);
extern void dump_gimple_expr (dump_flags_t, dump_flags_t, gimple *, int);
extern void print_combine_total_stats (void);
extern bool enable_rtl_dump_file (void);
extern void dump_symtab_node (dump_flags_t, symtab_node *);
template<unsigned int N, typename C>
void dump_dec (dump_flags_t, const poly_int<N, C> &);
extern void dump_dec (dump_flags_t, const poly_wide_int &, signop);
extern void dump_hex (dump_flags_t, const poly_wide_int &);
/* In tree-dump.c */
extern void dump_node (const_tree, dump_flags_t, FILE *);
/* In combine.c */
extern void dump_combine_total_stats (FILE *);
/* In cfghooks.c */
extern void dump_bb (FILE *, basic_block, int, dump_flags_t);
/* Global variables used to communicate with passes. */
extern FILE *dump_file;
extern dump_flags_t dump_flags;
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. */
static inline bool
dump_enabled_p (void)
{
return dumps_are_enabled;
}
extern void dumpfile_ensure_any_optinfo_are_flushed ();
/* Managing nested scopes, so that dumps can express the call chain
leading to a dump message. */
......@@ -505,8 +524,23 @@ class auto_dump_scope
#define AUTO_DUMP_SCOPE(NAME, LOC) \
auto_dump_scope scope (NAME, LOC)
extern void dump_function (int phase, tree fn);
extern void print_combine_total_stats (void);
extern bool enable_rtl_dump_file (void);
/* In tree-dump.c */
extern void dump_node (const_tree, dump_flags_t, FILE *);
/* In combine.c */
extern void dump_combine_total_stats (FILE *);
/* In cfghooks.c */
extern void dump_bb (FILE *, basic_block, int, dump_flags_t);
namespace gcc {
/* A class for managing all of the various dump files used by the
optimization passes. */
class dump_manager
{
public:
......
/* Optimization information.
Copyright (C) 2018 Free Software Foundation, Inc.
Contributed by David Malcolm <dmalcolm@redhat.com>.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "backend.h"
#include "tree.h"
#include "gimple.h"
#include "optinfo.h"
#include "dump-context.h"
#include "pretty-print.h"
#include "gimple-pretty-print.h"
#include "cgraph.h"
#include "selftest.h"
/* optinfo_item's ctor. */
optinfo_item::optinfo_item (enum optinfo_item_kind kind, location_t location,
char *text, bool owned)
: m_kind (kind), m_location (location), m_text (text), m_owned (owned)
{
}
/* optinfo_item's dtor. */
optinfo_item::~optinfo_item ()
{
if (m_owned)
free (m_text);
}
/* Get a string from KIND. */
const char *
optinfo_kind_to_string (enum optinfo_kind kind)
{
switch (kind)
{
default:
gcc_unreachable ();
case OPTINFO_KIND_SUCCESS:
return "success";
case OPTINFO_KIND_FAILURE:
return "failure";
case OPTINFO_KIND_NOTE:
return "note";
case OPTINFO_KIND_SCOPE:
return "scope";
}
}
/* optinfo's dtor. */
optinfo::~optinfo ()
{
/* Cleanup. */
unsigned i;
optinfo_item *item;
FOR_EACH_VEC_ELT (m_items, i, item)
delete item;
}
/* Emit the optinfo to all of the active destinations. */
void
optinfo::emit ()
{
/* currently this is a no-op. */
}
/* Update the optinfo's kind based on DUMP_KIND. */
void
optinfo::handle_dump_file_kind (dump_flags_t dump_kind)
{
if (dump_kind & MSG_OPTIMIZED_LOCATIONS)
m_kind = OPTINFO_KIND_SUCCESS;
else if (dump_kind & MSG_MISSED_OPTIMIZATION)
m_kind = OPTINFO_KIND_FAILURE;
else if (dump_kind & MSG_NOTE)
m_kind = OPTINFO_KIND_NOTE;
}
/* Append a string literal to this optinfo. */
void
optinfo::add_string (const char *str)
{
optinfo_item *item
= new optinfo_item (OPTINFO_ITEM_KIND_TEXT, UNKNOWN_LOCATION,
const_cast <char *> (str), false);
m_items.safe_push (item);
}
/* Append printf-formatted text to this optinfo. */
void
optinfo::add_printf (const char *format, ...)
{
va_list ap;
va_start (ap, format);
add_printf_va (format, ap);
va_end (ap);
}
/* Append printf-formatted text to this optinfo. */
void
optinfo::add_printf_va (const char *format, va_list ap)
{
char *formatted_text = xvasprintf (format, ap);
optinfo_item *item
= new optinfo_item (OPTINFO_ITEM_KIND_TEXT, UNKNOWN_LOCATION,
formatted_text, true);
m_items.safe_push (item);
}
/* Append a gimple statement to this optinfo, equivalent to
print_gimple_stmt. */
void
optinfo::add_gimple_stmt (gimple *stmt, int spc, dump_flags_t dump_flags)
{
pretty_printer pp;
pp_needs_newline (&pp) = true;
pp_gimple_stmt_1 (&pp, stmt, spc, dump_flags);
pp_newline (&pp);
optinfo_item *item
= new optinfo_item (OPTINFO_ITEM_KIND_GIMPLE, gimple_location (stmt),
xstrdup (pp_formatted_text (&pp)), true);
m_items.safe_push (item);
}
/* Append a gimple statement to this optinfo, equivalent to
print_gimple_expr. */
void
optinfo::add_gimple_expr (gimple *stmt, int spc, dump_flags_t dump_flags)
{
dump_flags |= TDF_RHS_ONLY;
pretty_printer pp;
pp_needs_newline (&pp) = true;
pp_gimple_stmt_1 (&pp, stmt, spc, dump_flags);
optinfo_item *item
= new optinfo_item (OPTINFO_ITEM_KIND_GIMPLE, gimple_location (stmt),
xstrdup (pp_formatted_text (&pp)), true);
m_items.safe_push (item);
}
/* Append a tree node to this optinfo, equivalent to print_generic_expr. */
void
optinfo::add_tree (tree node, dump_flags_t dump_flags)
{
pretty_printer pp;
pp_needs_newline (&pp) = true;
pp_translate_identifiers (&pp) = false;
dump_generic_node (&pp, node, 0, dump_flags, false);
location_t loc = UNKNOWN_LOCATION;
if (EXPR_HAS_LOCATION (node))
loc = EXPR_LOCATION (node);
optinfo_item *item
= new optinfo_item (OPTINFO_ITEM_KIND_TREE, loc,
xstrdup (pp_formatted_text (&pp)), true);
m_items.safe_push (item);
}
/* Append a symbol table node to this optinfo. */
void
optinfo::add_symtab_node (symtab_node *node)
{
location_t loc = DECL_SOURCE_LOCATION (node->decl);
optinfo_item *item
= new optinfo_item (OPTINFO_ITEM_KIND_SYMTAB_NODE, loc,
xstrdup (node->dump_name ()), true);
m_items.safe_push (item);
}
/* Append the decimal represenation of a wide_int_ref to this
optinfo. */
void
optinfo::add_dec (const wide_int_ref &wi, signop sgn)
{
char buf[WIDE_INT_PRINT_BUFFER_SIZE];
print_dec (wi, buf, sgn);
optinfo_item *item
= new optinfo_item (OPTINFO_ITEM_KIND_TEXT, UNKNOWN_LOCATION,
xstrdup (buf), true);
m_items.safe_push (item);
}
/* Should optinfo instances be created?
All creation of optinfos should be guarded by this predicate.
Return true if any optinfo destinations are active. */
bool optinfo_enabled_p ()
{
/* Currently no destinations are implemented, just a hook for
selftests. */
return dump_context::get ().forcibly_enable_optinfo_p ();
}
/* Return true if any of the active optinfo destinations make use
of inlining information.
(if true, then the information is preserved). */
bool optinfo_wants_inlining_info_p ()
{
return false;
}
/* Optimization information.
Copyright (C) 2018 Free Software Foundation, Inc.
Contributed by David Malcolm <dmalcolm@redhat.com>.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
#ifndef GCC_OPTINFO_H
#define GCC_OPTINFO_H
/* An "optinfo" is a bundle of information describing part of an
optimization, which can be emitted to zero or more of several
destinations, such as:
* as a "remark" through the diagnostics subsystem
* saved to a file as an "optimization record"
Currently no such destinations are implemented.
They are generated in response to calls to the "dump_*" API in
dumpfile.h; repeated calls to the "dump_*" API are consolidated
into a pending optinfo instance, with a "dump_*_loc" starting a new
optinfo instance.
The data sent to the dump calls are captured within the pending optinfo
instance as a sequence of optinfo_items. For example, given:
if (dump_enabled_p ())
{
dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
"not vectorized: live stmt not supported: ");
dump_gimple_stmt (MSG_MISSED_OPTIMIZATION, TDF_SLIM, stmt, 0);
}
the "dump_printf_loc" call begins a new optinfo containing two items:
(1) a text item containing "not vectorized: live stmt not supported: "
(2) a gimple item for "stmt"
Dump destinations are thus able to access rich metadata about the
items when the optinfo is emitted to them, rather than just having plain
text. For example, when saving the above optinfo to a file as an
"optimization record", the record could capture the source location of
"stmt" above, rather than just its textual form.
The currently pending optinfo is emitted and deleted:
* each time a "dump_*_loc" call occurs (which starts the next optinfo), or
* when the dump files are changed (at the end of a pass)
Dumping to an optinfo instance is non-trivial (due to building optinfo_item
instances), so all usage should be guarded by
if (optinfo_enabled_p ())
which is off by default. */
/* Forward decls. */
struct opt_pass;
class optinfo_item;
/* Should optinfo instances be created?
All creation of optinfos should be guarded by this predicate.
Return true if any optinfo destinations are active. */
extern bool optinfo_enabled_p ();
/* Return true if any of the active optinfo destinations make use
of inlining information.
(if true, then the information is preserved). */
extern bool optinfo_wants_inlining_info_p ();
/* The various kinds of optinfo. */
enum optinfo_kind
{
OPTINFO_KIND_SUCCESS,
OPTINFO_KIND_FAILURE,
OPTINFO_KIND_NOTE,
OPTINFO_KIND_SCOPE
};
extern const char *optinfo_kind_to_string (enum optinfo_kind kind);
/* A bundle of information describing part of an optimization. */
class optinfo
{
friend class dump_context;
public:
optinfo (const dump_location_t &loc,
enum optinfo_kind kind,
opt_pass *pass)
: m_loc (loc), m_kind (kind), m_pass (pass), m_items ()
{}
~optinfo ();
const dump_user_location_t &
get_user_location () const { return m_loc.get_user_location (); }
const dump_impl_location_t &
get_impl_location () const { return m_loc.get_impl_location (); }
enum optinfo_kind get_kind () const { return m_kind; }
opt_pass *get_pass () const { return m_pass; }
unsigned int num_items () const { return m_items.length (); }
const optinfo_item *get_item (unsigned int i) const { return m_items[i]; }
location_t get_location_t () const { return m_loc.get_location_t (); }
profile_count get_count () const { return m_loc.get_count (); }
private:
void emit ();
/* Pre-canned ways of manipulating the optinfo, for use by friend class
dump_context. */
void handle_dump_file_kind (dump_flags_t);
void add_string (const char *str);
void add_printf (const char *format, ...) ATTRIBUTE_PRINTF_2;
void add_printf_va (const char *format, va_list ap) ATTRIBUTE_PRINTF (2, 0);
void add_gimple_stmt (gimple *stmt, int spc, dump_flags_t dump_flags);
void add_gimple_expr (gimple *stmt, int spc, dump_flags_t dump_flags);
void add_tree (tree node, dump_flags_t dump_flags);
void add_symtab_node (symtab_node *node);
void add_dec (const wide_int_ref &wi, signop sgn);
template<unsigned int N, typename C>
void add_poly_int (const poly_int<N, C> &value)
{
/* Compare with dump_dec (MSG_NOTE, ). */
STATIC_ASSERT (poly_coeff_traits<C>::signedness >= 0);
signop sgn = poly_coeff_traits<C>::signedness ? SIGNED : UNSIGNED;
if (value.is_constant ())
add_dec (value.coeffs[0], sgn);
else
{
add_string ("[");
for (unsigned int i = 0; i < N; ++i)
{
add_dec (value.coeffs[i], sgn);
add_string (i == N - 1 ? "]" : ",");
}
}
}
private:
dump_location_t m_loc;
enum optinfo_kind m_kind;
opt_pass *m_pass;
auto_vec <optinfo_item *> m_items;
};
/* An enum for discriminating between different kinds of optinfo_item. */
enum optinfo_item_kind
{
OPTINFO_ITEM_KIND_TEXT,
OPTINFO_ITEM_KIND_TREE,
OPTINFO_ITEM_KIND_GIMPLE,
OPTINFO_ITEM_KIND_SYMTAB_NODE
};
/* An item within an optinfo. */
class optinfo_item
{
public:
optinfo_item (enum optinfo_item_kind kind, location_t location,
char *text, bool owned);
~optinfo_item ();
enum optinfo_item_kind get_kind () const { return m_kind; }
location_t get_location () const { return m_location; }
const char *get_text () const { return m_text; }
private:
/* Metadata (e.g. for optimization records). */
enum optinfo_item_kind m_kind;
location_t m_location;
/* The textual form of the item. */
char *m_text;
bool m_owned;
};
#endif /* #ifndef GCC_OPTINFO_H */
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