2014-10-16 Andrew MacLeod <amacleod@redhat.com> * function.h: Flatten file. Remove includes, adjust prototypes to reflect only what is in function.h. (enum direction, struct args_size, struct locate_and_pad_arg_data, ADD_PARM_SIZE, SUB_PARM_SIZE, ARGS_SIZE_TREE, ARGS_SIZE_RTX): Relocate from expr.h. (ASLK_REDUCE_ALIGN, ASLK_RECORD_PAD): Relocate from rtl.h. (optimize_function_for_size_p, optimize_function_for_speed_p): Move prototypes to predict.h. (init_varasm_status): Move prototype to varasm.h. * expr.h: Adjust include files. (enum direction, struct args_size, struct locate_and_pad_arg_data, ADD_PARM_SIZE, SUB_PARM_SIZE, ARGS_SIZE_TREE, ARGS_SIZE_RTX): Move to function.h. (locate_and_pad_parm): Move prototype to function.h. * rtl.h: (assign_stack_local, ASLK_REDUCE_ALIGN, ASLK_RECORD_PAD, assign_stack_local_1, assign_stack_temp, assign_stack_temp_for_type, assign_temp, reposition_prologue_and_epilogue_notes, prologue_epilogue_contains, sibcall_epilogue_contains, update_temp_slot_address, maybe_copy_prologue_epilogue_insn, set_return_jump_label): Move prototypes to function.h. * predict.h (optimize_function_for_size_p, optimize_function_for_speed_p): Relocate prototypes from function.h. * shrink-wrap.h (emit_return_into_block, active_insn_between, convert_jumps_to_returns, emit_return_for_exit): Move prototypes to function.h. * varasm.h (init_varasm_status): Relocate prototype from function.h. * genattrtab.c (write_header): Add predict.h to include list. * genconditions.c (write_header): Add predict.h to include list. * genemit.c (main): Adjust header file includes. * gengtype.c (ifiles): Add flattened function.h header files. * genoutput.c (output_prologue): Add predict.h to include list. * genpreds.c (write_insn_preds_c): Adjust header file includes. * genrecog.c (write_header): Add flattened function.h header files. * alias.c: Adjust include files. * auto-inc-dec.c: Likewise. * basic-block.h: Likewise. * bb-reorder.c: Likewise. * bt-load.c: Likewise. * builtins.c: Likewise. * caller-save.c: Likewise. * calls.c: Likewise. * cfgbuild.c: Likewise. * cfgcleanup.c: Likewise. * cfgexpand.c: Likewise. * cfgloop.c: Likewise. * cfgloop.h: Likewise. * cfgrtl.c: Likewise. * cgraph.h: Likewise. * cgraphclones.c: Likewise. * cgraphunit.c: Likewise. * combine-stack-adj.c: Likewise. * combine.c: Likewise. * coverage.c: Likewise. * cprop.c: Likewise. * cse.c: Likewise. * cselib.c: Likewise. * dbxout.c: Likewise. * ddg.c: Likewise. * df-core.c: Likewise. * df-problems.c: Likewise. * df-scan.c: Likewise. * dojump.c: Likewise. * dwarf2cfi.c: Likewise. * dwarf2out.c: Likewise. * emit-rtl.c: Likewise. * except.c: Likewise. * explow.c: Likewise. * expr.c: Likewise. * final.c: Likewise. * function.c: Likewise. * gcse.c: Likewise. * gimple-fold.c: Likewise. * gimple-low.c: Likewise. * gimple-streamer.h: Likewise. * haifa-sched.c: Likewise. * ifcvt.c: Likewise. * ira.c: Likewise. * jump.c: Likewise. * lcm.c: Likewise. * loop-invariant.c: Likewise. * lra-assigns.c: Likewise. * lra-coalesce.c: Likewise. * lra-constraints.c: Likewise. * lra-eliminations.c: Likewise. * lra-lives.c: Likewise. * lra-spills.c: Likewise. * lra.c: Likewise. * lto-cgraph.c: Likewise. * lto-section-in.c: Likewise. * lto-section-out.c: Likewise. * lto-streamer-in.c: Likewise. * lto-streamer-out.c: Likewise. * mode-switching.c: Likewise. * modulo-sched.c: Likewise. * omp-low.c: Likewise. * optabs.c: Likewise. * passes.c: Likewise. * postreload-gcse.c: Likewise. * postreload.c: Likewise. * predict.c: Likewise. * profile.c: Likewise. * recog.c: Likewise. * ree.c: Likewise. * reg-stack.c: Likewise. * regcprop.c: Likewise. * reginfo.c: Likewise. * regrename.c: Likewise. * reload.c: Likewise. * reload1.c: Likewise. * reorg.c: Likewise. * resource.c: Likewise. * rtlanal.c: Likewise. * sched-deps.c: Likewise. * sched-ebb.c: Likewise. * sched-rgn.c: Likewise. * sel-sched-dump.c: Likewise. * sel-sched-ir.c: Likewise. * sel-sched.c: Likewise. * shrink-wrap.c: Likewise. * simplify-rtx.c: Likewise. * statistics.c: Likewise. * stmt.c: Likewise. * stor-layout.c: Likewise. * store-motion.c: Likewise. * symtab.c: Likewise. * targhooks.c: Likewise. * toplev.c: Likewise. * trans-mem.c: Likewise. * tree-cfg.c: Likewise. * tree-cfgcleanup.c: Likewise. * tree-dfa.c: Likewise. * tree-eh.c: Likewise. * tree-inline.c: Likewise. * tree-into-ssa.c: Likewise. * tree-nested.c: Likewise. * tree-nrv.c: Likewise. * tree-profile.c: Likewise. * tree-ssa-alias.c: Likewise. * tree-ssa-ccp.c: Likewise. * tree-ssa-copy.c: Likewise. * tree-ssa-copyrename.c: Likewise. * tree-ssa-dom.c: Likewise. * tree-ssa-operands.c: Likewise. * tree-ssa-propagate.c: Likewise. * tree-ssa-structalias.c: Likewise. * tree-ssa-tail-merge.c: Likewise. * tree-ssa-threadedge.c: Likewise. * tree-ssa-threadupdate.c: Likewise. * tree-ssa-uncprop.c: Likewise. * tree-ssa-uninit.c: Likewise. * tree-ssa.c: Likewise. * tree-stdarg.c: Likewise. * tree-tailcall.c: Likewise. * tree.c: Likewise. * tsan.c: Likewise. * valtrack.c: Likewise. * varasm.c: Likewise. * vmsdbgout.c: Likewise. * web.c: Likewise. * testsuite/g++.dg/plugin/pragma_plugin.c: Adjust include files. * config/aarch64/aarch64.c: Add flattened includes from function.h. * config/alpha/alpha.c: Likewise. * config/arc/arc.c: Likewise. * config/arm/arm.c: Likewise. * config/avr/avr-log.c: Likewise. * config/avr/avr.c: Likewise. * config/bfin/bfin.c: Likewise. * config/c6x/c6x.c: Likewise. * config/cr16/cr16.c: Likewise. * config/cris/cris.c: Likewise. * config/darwin.c: Likewise. * config/epiphany/epiphany.c: Likewise. * config/epiphany/mode-switch-use.c: Likewise. * config/epiphany/resolve-sw-modes.c: Likewise. * config/fr30/fr30.c: Likewise. * config/frv/frv.c: Likewise. * config/h8300/h8300.c: Likewise. * config/i386/i386.c: Likewise. * config/ia64/ia64.c: Likewise. * config/iq2000/iq2000.c: Likewise. * config/lm32/lm32.c: Likewise. * config/m32c/m32c.c: Likewise. * config/m32r/m32r.c: Likewise. * config/m68k/m68k.c: Likewise. * config/mcore/mcore.c: Likewise. * config/mep/mep-pragma.c: Likewise. * config/mep/mep.c: Likewise. * config/microblaze/microblaze.c: Likewise. * config/mips/mips.c: Likewise. * config/mmix/mmix.c: Likewise. * config/mn10300/mn10300.c: Likewise. * config/moxie/moxie.c: Likewise. * config/msp430/msp430.c: Likewise. * config/nds32/nds32-cost.c: Likewise. * config/nds32/nds32-fp-as-gp.c: Likewise. * config/nds32/nds32-intrinsic.c: Likewise. * config/nds32/nds32-isr.c: Likewise. * config/nds32/nds32-md-auxiliary.c: Likewise. * config/nds32/nds32-memory-manipulation.c: Likewise. * config/nds32/nds32-pipelines-auxiliary.c: Likewise. * config/nds32/nds32-predicates.c: Likewise. * config/nds32/nds32.c: Likewise. * config/nios2/nios2.c: Likewise. * config/pa/pa.c: Likewise. * config/pdp11/pdp11.c: Likewise. * config/rl78/rl78.c: Likewise. * config/rs6000/rs6000.c: Likewise. * config/rx/rx.c: Likewise. * config/s390/s390.c: Likewise. * config/score/score.c: Likewise. * config/sh/sh.c: Likewise. * config/sparc/sparc.c: Likewise. * config/spu/spu.c: Likewise. * config/stormy16/stormy16.c: Likewise. * config/tilegx/tilegx.c: Likewise. * config/tilepro/tilepro.c: Likewise. * config/v850/v850.c: Likewise. * config/vax/vax.c: Likewise. * config/xtensa/xtensa.c: Likewise. 2014-10-16 Andrew MacLeod <amacleod@redhat.com> * ada/gcc-interface/misc.c: Adjust include files. 2014-10-16 Andrew MacLeod <amacleod@redhat.com> * c/c-decl.c: Adjust include files. 2014-10-16 Andrew MacLeod <amacleod@redhat.com> * c-family/c-pragma.c: Adjust include files. * c-family/c-semantics.c: Likewise. 2014-10-16 Andrew MacLeod <amacleod@redhat.com> * cp/cp-tree.h: Adjust include files. 2014-10-16 Andrew MacLeod <amacleod@redhat.com> * fortran/f95-lang.c: Adjust include files. * fortran/trans-decl.c: Likewise. 2014-10-16 Andrew MacLeod <amacleod@redhat.com> * java/class.c: Adjust include files. * java/resource.c: Likewise. 2014-10-16 Andrew MacLeod <amacleod@redhat.com> * objc/objc-act.c: Adjust include files. From-SVN: r216337
372 lines
9.8 KiB
C
372 lines
9.8 KiB
C
/* Optimization statistics functions.
|
|
Copyright (C) 2008-2014 Free Software Foundation, Inc.
|
|
Contributed by Richard Guenther <rguenther@suse.de>
|
|
|
|
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 "tree-pass.h"
|
|
#include "tree-dump.h"
|
|
#include "statistics.h"
|
|
#include "hash-table.h"
|
|
#include "hashtab.h"
|
|
#include "hash-set.h"
|
|
#include "vec.h"
|
|
#include "machmode.h"
|
|
#include "tm.h"
|
|
#include "hard-reg-set.h"
|
|
#include "input.h"
|
|
#include "function.h"
|
|
#include "context.h"
|
|
#include "pass_manager.h"
|
|
|
|
static int statistics_dump_nr;
|
|
static int statistics_dump_flags;
|
|
static FILE *statistics_dump_file;
|
|
|
|
/* Statistics entry. A integer counter associated to a string ID
|
|
and value. */
|
|
|
|
typedef struct statistics_counter_s {
|
|
const char *id;
|
|
int val;
|
|
bool histogram_p;
|
|
unsigned HOST_WIDE_INT count;
|
|
unsigned HOST_WIDE_INT prev_dumped_count;
|
|
} statistics_counter_t;
|
|
|
|
/* Hashtable helpers. */
|
|
|
|
struct stats_counter_hasher
|
|
{
|
|
typedef statistics_counter_t value_type;
|
|
typedef statistics_counter_t compare_type;
|
|
static inline hashval_t hash (const value_type *);
|
|
static inline bool equal (const value_type *, const compare_type *);
|
|
static inline void remove (value_type *);
|
|
};
|
|
|
|
/* Hash a statistic counter by its string ID. */
|
|
|
|
inline hashval_t
|
|
stats_counter_hasher::hash (const value_type *c)
|
|
{
|
|
return htab_hash_string (c->id) + c->val;
|
|
}
|
|
|
|
/* Compare two statistic counters by their string IDs. */
|
|
|
|
inline bool
|
|
stats_counter_hasher::equal (const value_type *c1, const compare_type *c2)
|
|
{
|
|
return c1->val == c2->val && strcmp (c1->id, c2->id) == 0;
|
|
}
|
|
|
|
/* Free a statistics entry. */
|
|
|
|
inline void
|
|
stats_counter_hasher::remove (value_type *v)
|
|
{
|
|
free (CONST_CAST (char *, v->id));
|
|
free (v);
|
|
}
|
|
|
|
typedef hash_table<stats_counter_hasher> stats_counter_table_type;
|
|
|
|
/* Array of statistic hashes, indexed by pass id. */
|
|
static stats_counter_table_type **statistics_hashes;
|
|
static unsigned nr_statistics_hashes;
|
|
|
|
/* Return the current hashtable to be used for recording or printing
|
|
statistics. */
|
|
|
|
static stats_counter_table_type *
|
|
curr_statistics_hash (void)
|
|
{
|
|
unsigned idx;
|
|
|
|
gcc_assert (current_pass->static_pass_number >= 0);
|
|
idx = current_pass->static_pass_number;
|
|
|
|
if (idx < nr_statistics_hashes
|
|
&& statistics_hashes[idx])
|
|
return statistics_hashes[idx];
|
|
|
|
if (idx >= nr_statistics_hashes)
|
|
{
|
|
statistics_hashes = XRESIZEVEC (stats_counter_table_type *,
|
|
statistics_hashes, idx+1);
|
|
memset (statistics_hashes + nr_statistics_hashes, 0,
|
|
(idx + 1 - nr_statistics_hashes)
|
|
* sizeof (stats_counter_table_type *));
|
|
nr_statistics_hashes = idx + 1;
|
|
}
|
|
|
|
statistics_hashes[idx] = new stats_counter_table_type (15);
|
|
|
|
return statistics_hashes[idx];
|
|
}
|
|
|
|
/* Helper for statistics_fini_pass. Print the counter difference
|
|
since the last dump for the pass dump files. */
|
|
|
|
int
|
|
statistics_fini_pass_1 (statistics_counter_t **slot,
|
|
void *data ATTRIBUTE_UNUSED)
|
|
{
|
|
statistics_counter_t *counter = *slot;
|
|
unsigned HOST_WIDE_INT count = counter->count - counter->prev_dumped_count;
|
|
if (count == 0)
|
|
return 1;
|
|
if (counter->histogram_p)
|
|
fprintf (dump_file, "%s == %d: " HOST_WIDE_INT_PRINT_DEC "\n",
|
|
counter->id, counter->val, count);
|
|
else
|
|
fprintf (dump_file, "%s: " HOST_WIDE_INT_PRINT_DEC "\n",
|
|
counter->id, count);
|
|
counter->prev_dumped_count = counter->count;
|
|
return 1;
|
|
}
|
|
|
|
/* Helper for statistics_fini_pass. Print the counter difference
|
|
since the last dump for the statistics dump. */
|
|
|
|
int
|
|
statistics_fini_pass_2 (statistics_counter_t **slot,
|
|
void *data ATTRIBUTE_UNUSED)
|
|
{
|
|
statistics_counter_t *counter = *slot;
|
|
unsigned HOST_WIDE_INT count = counter->count - counter->prev_dumped_count;
|
|
if (count == 0)
|
|
return 1;
|
|
counter->prev_dumped_count = counter->count;
|
|
if (counter->histogram_p)
|
|
fprintf (statistics_dump_file,
|
|
"%d %s \"%s == %d\" \"%s\" " HOST_WIDE_INT_PRINT_DEC "\n",
|
|
current_pass->static_pass_number,
|
|
current_pass->name,
|
|
counter->id, counter->val,
|
|
current_function_name (),
|
|
count);
|
|
else
|
|
fprintf (statistics_dump_file,
|
|
"%d %s \"%s\" \"%s\" " HOST_WIDE_INT_PRINT_DEC "\n",
|
|
current_pass->static_pass_number,
|
|
current_pass->name,
|
|
counter->id,
|
|
current_function_name (),
|
|
count);
|
|
counter->prev_dumped_count = counter->count;
|
|
return 1;
|
|
}
|
|
|
|
/* Helper for statistics_fini_pass, reset the counters. */
|
|
|
|
int
|
|
statistics_fini_pass_3 (statistics_counter_t **slot,
|
|
void *data ATTRIBUTE_UNUSED)
|
|
{
|
|
statistics_counter_t *counter = *slot;
|
|
counter->prev_dumped_count = counter->count;
|
|
return 1;
|
|
}
|
|
|
|
/* Dump the current statistics incrementally. */
|
|
|
|
void
|
|
statistics_fini_pass (void)
|
|
{
|
|
if (current_pass->static_pass_number == -1)
|
|
return;
|
|
|
|
if (dump_file
|
|
&& dump_flags & TDF_STATS)
|
|
{
|
|
fprintf (dump_file, "\n");
|
|
fprintf (dump_file, "Pass statistics:\n");
|
|
fprintf (dump_file, "----------------\n");
|
|
curr_statistics_hash ()
|
|
->traverse_noresize <void *, statistics_fini_pass_1> (NULL);
|
|
fprintf (dump_file, "\n");
|
|
}
|
|
if (statistics_dump_file
|
|
&& !(statistics_dump_flags & TDF_STATS
|
|
|| statistics_dump_flags & TDF_DETAILS))
|
|
curr_statistics_hash ()
|
|
->traverse_noresize <void *, statistics_fini_pass_2> (NULL);
|
|
curr_statistics_hash ()
|
|
->traverse_noresize <void *, statistics_fini_pass_3> (NULL);
|
|
}
|
|
|
|
/* Helper for printing summary information. */
|
|
|
|
int
|
|
statistics_fini_1 (statistics_counter_t **slot, opt_pass *pass)
|
|
{
|
|
statistics_counter_t *counter = *slot;
|
|
if (counter->count == 0)
|
|
return 1;
|
|
if (counter->histogram_p)
|
|
fprintf (statistics_dump_file,
|
|
"%d %s \"%s == %d\" " HOST_WIDE_INT_PRINT_DEC "\n",
|
|
pass->static_pass_number,
|
|
pass->name,
|
|
counter->id, counter->val,
|
|
counter->count);
|
|
else
|
|
fprintf (statistics_dump_file,
|
|
"%d %s \"%s\" " HOST_WIDE_INT_PRINT_DEC "\n",
|
|
pass->static_pass_number,
|
|
pass->name,
|
|
counter->id,
|
|
counter->count);
|
|
return 1;
|
|
}
|
|
|
|
/* Finish the statistics and dump summary information. */
|
|
|
|
void
|
|
statistics_fini (void)
|
|
{
|
|
gcc::pass_manager *passes = g->get_passes ();
|
|
if (!statistics_dump_file)
|
|
return;
|
|
|
|
if (statistics_dump_flags & TDF_STATS)
|
|
{
|
|
unsigned i;
|
|
for (i = 0; i < nr_statistics_hashes; ++i)
|
|
if (statistics_hashes[i]
|
|
&& passes->get_pass_for_id (i) != NULL)
|
|
statistics_hashes[i]
|
|
->traverse_noresize <opt_pass *, statistics_fini_1>
|
|
(passes->get_pass_for_id (i));
|
|
}
|
|
|
|
dump_end (statistics_dump_nr, statistics_dump_file);
|
|
}
|
|
|
|
/* Register the statistics dump file. */
|
|
|
|
void
|
|
statistics_early_init (void)
|
|
{
|
|
gcc::dump_manager *dumps = g->get_dumps ();
|
|
statistics_dump_nr = dumps->dump_register (".statistics", "statistics",
|
|
"statistics", TDF_TREE,
|
|
OPTGROUP_NONE);
|
|
}
|
|
|
|
/* Init the statistics. */
|
|
|
|
void
|
|
statistics_init (void)
|
|
{
|
|
gcc::dump_manager *dumps = g->get_dumps ();
|
|
statistics_dump_file = dump_begin (statistics_dump_nr, NULL);
|
|
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
|
|
and HISTOGRAM_P. */
|
|
|
|
static statistics_counter_t *
|
|
lookup_or_add_counter (stats_counter_table_type *hash, const char *id, int val,
|
|
bool histogram_p)
|
|
{
|
|
statistics_counter_t **counter;
|
|
statistics_counter_t c;
|
|
c.id = id;
|
|
c.val = val;
|
|
counter = hash->find_slot (&c, INSERT);
|
|
if (!*counter)
|
|
{
|
|
*counter = XNEW (struct statistics_counter_s);
|
|
(*counter)->id = xstrdup (id);
|
|
(*counter)->val = val;
|
|
(*counter)->histogram_p = histogram_p;
|
|
(*counter)->prev_dumped_count = 0;
|
|
(*counter)->count = 0;
|
|
}
|
|
return *counter;
|
|
}
|
|
|
|
/* Add statistics information about event ID in function FN.
|
|
This will increment the counter associated with ID by INCR.
|
|
It will also dump the event to the global statistics file if requested. */
|
|
|
|
void
|
|
statistics_counter_event (struct function *fn, const char *id, int incr)
|
|
{
|
|
statistics_counter_t *counter;
|
|
|
|
if ((!(dump_flags & TDF_STATS)
|
|
&& !statistics_dump_file)
|
|
|| incr == 0)
|
|
return;
|
|
|
|
if (current_pass->static_pass_number != -1)
|
|
{
|
|
counter = lookup_or_add_counter (curr_statistics_hash (), id, 0, false);
|
|
gcc_assert (!counter->histogram_p);
|
|
counter->count += incr;
|
|
}
|
|
|
|
if (!statistics_dump_file
|
|
|| !(statistics_dump_flags & TDF_DETAILS))
|
|
return;
|
|
|
|
fprintf (statistics_dump_file,
|
|
"%d %s \"%s\" \"%s\" %d\n",
|
|
current_pass->static_pass_number,
|
|
current_pass->name,
|
|
id,
|
|
function_name (fn),
|
|
incr);
|
|
}
|
|
|
|
/* Add statistics information about event ID in function FN with the
|
|
histogram value VAL.
|
|
It will dump the event to the global statistics file if requested. */
|
|
|
|
void
|
|
statistics_histogram_event (struct function *fn, const char *id, int val)
|
|
{
|
|
statistics_counter_t *counter;
|
|
|
|
if (!(dump_flags & TDF_STATS)
|
|
&& !statistics_dump_file)
|
|
return;
|
|
|
|
counter = lookup_or_add_counter (curr_statistics_hash (), id, val, true);
|
|
gcc_assert (counter->histogram_p);
|
|
counter->count += 1;
|
|
|
|
if (!statistics_dump_file
|
|
|| !(statistics_dump_flags & TDF_DETAILS))
|
|
return;
|
|
|
|
fprintf (statistics_dump_file,
|
|
"%d %s \"%s == %d\" \"%s\" 1\n",
|
|
current_pass->static_pass_number,
|
|
current_pass->name,
|
|
id, val,
|
|
function_name (fn));
|
|
}
|