OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [gcc-4.5.1/] [gcc/] [statistics.c] - Diff between revs 816 and 826

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 816 Rev 826
/* Optimization statistics functions.
/* Optimization statistics functions.
   Copyright (C) 2008
   Copyright (C) 2008
   Free Software Foundation, Inc.
   Free Software Foundation, Inc.
   Contributed by Richard Guenther  <rguenther@suse.de>
   Contributed by Richard Guenther  <rguenther@suse.de>
 
 
This file is part of GCC.
This file is part of GCC.
 
 
GCC is free software; you can redistribute it and/or modify it under
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
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
Software Foundation; either version 3, or (at your option) any later
version.
version.
 
 
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.
for more details.
 
 
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3.  If not see
along with GCC; see the file COPYING3.  If not see
<http://www.gnu.org/licenses/>.  */
<http://www.gnu.org/licenses/>.  */
 
 
#include "config.h"
#include "config.h"
#include "system.h"
#include "system.h"
#include "coretypes.h"
#include "coretypes.h"
#include "tree-pass.h"
#include "tree-pass.h"
#include "tree-dump.h"
#include "tree-dump.h"
#include "statistics.h"
#include "statistics.h"
#include "hashtab.h"
#include "hashtab.h"
#include "tm.h"
#include "tm.h"
#include "function.h"
#include "function.h"
 
 
static int statistics_dump_nr;
static int statistics_dump_nr;
static int statistics_dump_flags;
static int statistics_dump_flags;
static FILE *statistics_dump_file;
static FILE *statistics_dump_file;
 
 
/* Statistics entry.  A integer counter associated to a string ID
/* Statistics entry.  A integer counter associated to a string ID
   and value.  */
   and value.  */
 
 
typedef struct statistics_counter_s {
typedef struct statistics_counter_s {
  const char *id;
  const char *id;
  int val;
  int val;
  bool histogram_p;
  bool histogram_p;
  unsigned HOST_WIDE_INT count;
  unsigned HOST_WIDE_INT count;
  unsigned HOST_WIDE_INT prev_dumped_count;
  unsigned HOST_WIDE_INT prev_dumped_count;
} statistics_counter_t;
} statistics_counter_t;
 
 
/* Array of statistic hashes, indexed by pass id.  */
/* Array of statistic hashes, indexed by pass id.  */
static htab_t *statistics_hashes;
static htab_t *statistics_hashes;
static unsigned nr_statistics_hashes;
static unsigned nr_statistics_hashes;
 
 
/* Hash a statistic counter by its string ID.  */
/* Hash a statistic counter by its string ID.  */
 
 
static hashval_t
static hashval_t
hash_statistics_hash (const void *p)
hash_statistics_hash (const void *p)
{
{
  const statistics_counter_t *const c = (const statistics_counter_t *)p;
  const statistics_counter_t *const c = (const statistics_counter_t *)p;
  return htab_hash_string (c->id) + c->val;
  return htab_hash_string (c->id) + c->val;
}
}
 
 
/* Compare two statistic counters by their string IDs.  */
/* Compare two statistic counters by their string IDs.  */
 
 
static int
static int
hash_statistics_eq (const void *p, const void *q)
hash_statistics_eq (const void *p, const void *q)
{
{
  const statistics_counter_t *const c1 = (const statistics_counter_t *)p;
  const statistics_counter_t *const c1 = (const statistics_counter_t *)p;
  const statistics_counter_t *const c2 = (const statistics_counter_t *)q;
  const statistics_counter_t *const c2 = (const statistics_counter_t *)q;
  return c1->val == c2->val && strcmp (c1->id, c2->id) == 0;
  return c1->val == c2->val && strcmp (c1->id, c2->id) == 0;
}
}
 
 
/* Free a statistics entry.  */
/* Free a statistics entry.  */
 
 
static void
static void
hash_statistics_free (void *p)
hash_statistics_free (void *p)
{
{
  free (CONST_CAST(char *, ((statistics_counter_t *)p)->id));
  free (CONST_CAST(char *, ((statistics_counter_t *)p)->id));
  free (p);
  free (p);
}
}
 
 
/* Return the current hashtable to be used for recording or printing
/* Return the current hashtable to be used for recording or printing
   statistics.  */
   statistics.  */
 
 
static htab_t
static htab_t
curr_statistics_hash (void)
curr_statistics_hash (void)
{
{
  unsigned idx;
  unsigned idx;
 
 
  gcc_assert (current_pass->static_pass_number >= 0);
  gcc_assert (current_pass->static_pass_number >= 0);
  idx = current_pass->static_pass_number;
  idx = current_pass->static_pass_number;
 
 
  if (idx < nr_statistics_hashes
  if (idx < nr_statistics_hashes
      && statistics_hashes[idx] != NULL)
      && statistics_hashes[idx] != NULL)
    return statistics_hashes[idx];
    return statistics_hashes[idx];
 
 
  if (idx >= nr_statistics_hashes)
  if (idx >= nr_statistics_hashes)
    {
    {
      statistics_hashes = XRESIZEVEC (struct htab *, statistics_hashes, idx+1);
      statistics_hashes = XRESIZEVEC (struct htab *, statistics_hashes, idx+1);
      memset (statistics_hashes + nr_statistics_hashes, 0,
      memset (statistics_hashes + nr_statistics_hashes, 0,
              (idx + 1 - nr_statistics_hashes) * sizeof (htab_t));
              (idx + 1 - nr_statistics_hashes) * sizeof (htab_t));
      nr_statistics_hashes = idx + 1;
      nr_statistics_hashes = idx + 1;
    }
    }
 
 
  statistics_hashes[idx] = htab_create (15, hash_statistics_hash,
  statistics_hashes[idx] = htab_create (15, hash_statistics_hash,
                                        hash_statistics_eq,
                                        hash_statistics_eq,
                                        hash_statistics_free);
                                        hash_statistics_free);
 
 
  return statistics_hashes[idx];
  return statistics_hashes[idx];
}
}
 
 
/* Helper for statistics_fini_pass.  Print the counter difference
/* Helper for statistics_fini_pass.  Print the counter difference
   since the last dump for the pass dump files.  */
   since the last dump for the pass dump files.  */
 
 
static int
static int
statistics_fini_pass_1 (void **slot, void *data ATTRIBUTE_UNUSED)
statistics_fini_pass_1 (void **slot, void *data ATTRIBUTE_UNUSED)
{
{
  statistics_counter_t *counter = (statistics_counter_t *)*slot;
  statistics_counter_t *counter = (statistics_counter_t *)*slot;
  unsigned HOST_WIDE_INT count = counter->count - counter->prev_dumped_count;
  unsigned HOST_WIDE_INT count = counter->count - counter->prev_dumped_count;
  if (count == 0)
  if (count == 0)
    return 1;
    return 1;
  if (counter->histogram_p)
  if (counter->histogram_p)
    fprintf (dump_file, "%s == %d: " HOST_WIDE_INT_PRINT_DEC "\n",
    fprintf (dump_file, "%s == %d: " HOST_WIDE_INT_PRINT_DEC "\n",
             counter->id, counter->val, count);
             counter->id, counter->val, count);
  else
  else
    fprintf (dump_file, "%s: " HOST_WIDE_INT_PRINT_DEC "\n",
    fprintf (dump_file, "%s: " HOST_WIDE_INT_PRINT_DEC "\n",
             counter->id, count);
             counter->id, count);
  counter->prev_dumped_count = counter->count;
  counter->prev_dumped_count = counter->count;
  return 1;
  return 1;
}
}
 
 
/* Helper for statistics_fini_pass.  Print the counter difference
/* Helper for statistics_fini_pass.  Print the counter difference
   since the last dump for the statistics dump.  */
   since the last dump for the statistics dump.  */
 
 
static int
static int
statistics_fini_pass_2 (void **slot, void *data ATTRIBUTE_UNUSED)
statistics_fini_pass_2 (void **slot, void *data ATTRIBUTE_UNUSED)
{
{
  statistics_counter_t *counter = (statistics_counter_t *)*slot;
  statistics_counter_t *counter = (statistics_counter_t *)*slot;
  unsigned HOST_WIDE_INT count = counter->count - counter->prev_dumped_count;
  unsigned HOST_WIDE_INT count = counter->count - counter->prev_dumped_count;
  if (count == 0)
  if (count == 0)
    return 1;
    return 1;
  counter->prev_dumped_count = counter->count;
  counter->prev_dumped_count = counter->count;
  if (counter->histogram_p)
  if (counter->histogram_p)
    fprintf (statistics_dump_file,
    fprintf (statistics_dump_file,
             "%d %s \"%s == %d\" \"%s\" " HOST_WIDE_INT_PRINT_DEC "\n",
             "%d %s \"%s == %d\" \"%s\" " HOST_WIDE_INT_PRINT_DEC "\n",
             current_pass->static_pass_number,
             current_pass->static_pass_number,
             current_pass->name,
             current_pass->name,
             counter->id, counter->val,
             counter->id, counter->val,
             cfun ? IDENTIFIER_POINTER (DECL_NAME (cfun->decl)) : "(nofn)",
             cfun ? IDENTIFIER_POINTER (DECL_NAME (cfun->decl)) : "(nofn)",
             count);
             count);
  else
  else
    fprintf (statistics_dump_file,
    fprintf (statistics_dump_file,
             "%d %s \"%s\" \"%s\" " HOST_WIDE_INT_PRINT_DEC "\n",
             "%d %s \"%s\" \"%s\" " HOST_WIDE_INT_PRINT_DEC "\n",
             current_pass->static_pass_number,
             current_pass->static_pass_number,
             current_pass->name,
             current_pass->name,
             counter->id,
             counter->id,
             cfun ? IDENTIFIER_POINTER (DECL_NAME (cfun->decl)) : "(nofn)",
             cfun ? IDENTIFIER_POINTER (DECL_NAME (cfun->decl)) : "(nofn)",
             count);
             count);
  counter->prev_dumped_count = counter->count;
  counter->prev_dumped_count = counter->count;
  return 1;
  return 1;
}
}
 
 
/* Helper for statistics_fini_pass, reset the counters.  */
/* Helper for statistics_fini_pass, reset the counters.  */
 
 
static int
static int
statistics_fini_pass_3 (void **slot, void *data ATTRIBUTE_UNUSED)
statistics_fini_pass_3 (void **slot, void *data ATTRIBUTE_UNUSED)
{
{
  statistics_counter_t *counter = (statistics_counter_t *)*slot;
  statistics_counter_t *counter = (statistics_counter_t *)*slot;
  counter->prev_dumped_count = counter->count;
  counter->prev_dumped_count = counter->count;
  return 1;
  return 1;
}
}
 
 
/* Dump the current statistics incrementally.  */
/* Dump the current statistics incrementally.  */
 
 
void
void
statistics_fini_pass (void)
statistics_fini_pass (void)
{
{
  if (current_pass->static_pass_number == -1)
  if (current_pass->static_pass_number == -1)
    return;
    return;
 
 
  if (dump_file
  if (dump_file
      && dump_flags & TDF_STATS)
      && dump_flags & TDF_STATS)
    {
    {
      fprintf (dump_file, "\n");
      fprintf (dump_file, "\n");
      fprintf (dump_file, "Pass statistics:\n");
      fprintf (dump_file, "Pass statistics:\n");
      fprintf (dump_file, "----------------\n");
      fprintf (dump_file, "----------------\n");
      htab_traverse_noresize (curr_statistics_hash (),
      htab_traverse_noresize (curr_statistics_hash (),
                              statistics_fini_pass_1, NULL);
                              statistics_fini_pass_1, NULL);
      fprintf (dump_file, "\n");
      fprintf (dump_file, "\n");
    }
    }
  if (statistics_dump_file
  if (statistics_dump_file
      && !(statistics_dump_flags & TDF_STATS
      && !(statistics_dump_flags & TDF_STATS
           || statistics_dump_flags & TDF_DETAILS))
           || statistics_dump_flags & TDF_DETAILS))
    htab_traverse_noresize (curr_statistics_hash (),
    htab_traverse_noresize (curr_statistics_hash (),
                            statistics_fini_pass_2, NULL);
                            statistics_fini_pass_2, NULL);
  htab_traverse_noresize (curr_statistics_hash (),
  htab_traverse_noresize (curr_statistics_hash (),
                          statistics_fini_pass_3, NULL);
                          statistics_fini_pass_3, NULL);
}
}
 
 
/* Helper for printing summary information.  */
/* Helper for printing summary information.  */
 
 
static int
static int
statistics_fini_1 (void **slot, void *data)
statistics_fini_1 (void **slot, void *data)
{
{
  struct opt_pass *pass = (struct opt_pass *)data;
  struct opt_pass *pass = (struct opt_pass *)data;
  statistics_counter_t *counter = (statistics_counter_t *)*slot;
  statistics_counter_t *counter = (statistics_counter_t *)*slot;
  if (counter->count == 0)
  if (counter->count == 0)
    return 1;
    return 1;
  if (counter->histogram_p)
  if (counter->histogram_p)
    fprintf (statistics_dump_file,
    fprintf (statistics_dump_file,
             "%d %s \"%s == %d\" " HOST_WIDE_INT_PRINT_DEC "\n",
             "%d %s \"%s == %d\" " HOST_WIDE_INT_PRINT_DEC "\n",
             pass->static_pass_number,
             pass->static_pass_number,
             pass->name,
             pass->name,
             counter->id, counter->val,
             counter->id, counter->val,
             counter->count);
             counter->count);
  else
  else
    fprintf (statistics_dump_file,
    fprintf (statistics_dump_file,
             "%d %s \"%s\" " HOST_WIDE_INT_PRINT_DEC "\n",
             "%d %s \"%s\" " HOST_WIDE_INT_PRINT_DEC "\n",
             pass->static_pass_number,
             pass->static_pass_number,
             pass->name,
             pass->name,
             counter->id,
             counter->id,
             counter->count);
             counter->count);
  return 1;
  return 1;
}
}
 
 
/* Finish the statistics and dump summary information.  */
/* Finish the statistics and dump summary information.  */
 
 
void
void
statistics_fini (void)
statistics_fini (void)
{
{
  if (!statistics_dump_file)
  if (!statistics_dump_file)
    return;
    return;
 
 
  if (statistics_dump_flags & TDF_STATS)
  if (statistics_dump_flags & TDF_STATS)
    {
    {
      unsigned i;
      unsigned i;
      for (i = 0; i < nr_statistics_hashes; ++i)
      for (i = 0; i < nr_statistics_hashes; ++i)
        if (statistics_hashes[i] != NULL
        if (statistics_hashes[i] != NULL
            && get_pass_for_id (i) != NULL)
            && get_pass_for_id (i) != NULL)
          htab_traverse_noresize (statistics_hashes[i],
          htab_traverse_noresize (statistics_hashes[i],
                                  statistics_fini_1, get_pass_for_id (i));
                                  statistics_fini_1, get_pass_for_id (i));
    }
    }
 
 
  dump_end (statistics_dump_nr, statistics_dump_file);
  dump_end (statistics_dump_nr, statistics_dump_file);
}
}
 
 
/* Register the statistics dump file.  */
/* Register the statistics dump file.  */
 
 
void
void
statistics_early_init (void)
statistics_early_init (void)
{
{
  statistics_dump_nr = dump_register (".statistics", "statistics",
  statistics_dump_nr = dump_register (".statistics", "statistics",
                                      "statistics", TDF_TREE);
                                      "statistics", TDF_TREE);
}
}
 
 
/* Init the statistics.  */
/* Init the statistics.  */
 
 
void
void
statistics_init (void)
statistics_init (void)
{
{
  statistics_dump_file = dump_begin (statistics_dump_nr, NULL);
  statistics_dump_file = dump_begin (statistics_dump_nr, NULL);
  statistics_dump_flags = get_dump_file_info (statistics_dump_nr)->flags;
  statistics_dump_flags = get_dump_file_info (statistics_dump_nr)->flags;
}
}
 
 
/* Lookup or add a statistics counter in the hashtable HASH with ID, VAL
/* Lookup or add a statistics counter in the hashtable HASH with ID, VAL
   and HISTOGRAM_P.  */
   and HISTOGRAM_P.  */
 
 
static statistics_counter_t *
static statistics_counter_t *
lookup_or_add_counter (htab_t hash, const char *id, int val,
lookup_or_add_counter (htab_t hash, const char *id, int val,
                       bool histogram_p)
                       bool histogram_p)
{
{
  statistics_counter_t **counter;
  statistics_counter_t **counter;
  statistics_counter_t c;
  statistics_counter_t c;
  c.id = id;
  c.id = id;
  c.val = val;
  c.val = val;
  counter = (statistics_counter_t **) htab_find_slot (hash, &c, INSERT);
  counter = (statistics_counter_t **) htab_find_slot (hash, &c, INSERT);
  if (!*counter)
  if (!*counter)
    {
    {
      *counter = XNEW (struct statistics_counter_s);
      *counter = XNEW (struct statistics_counter_s);
      (*counter)->id = xstrdup (id);
      (*counter)->id = xstrdup (id);
      (*counter)->val = val;
      (*counter)->val = val;
      (*counter)->histogram_p = histogram_p;
      (*counter)->histogram_p = histogram_p;
      (*counter)->prev_dumped_count = 0;
      (*counter)->prev_dumped_count = 0;
      (*counter)->count = 0;
      (*counter)->count = 0;
    }
    }
  return *counter;
  return *counter;
}
}
 
 
/* Add statistics information about event ID in function FN.
/* Add statistics information about event ID in function FN.
   This will increment the counter associated with ID by INCR.
   This will increment the counter associated with ID by INCR.
   It will also dump the event to the global statistics file if requested.  */
   It will also dump the event to the global statistics file if requested.  */
 
 
void
void
statistics_counter_event (struct function *fn, const char *id, int incr)
statistics_counter_event (struct function *fn, const char *id, int incr)
{
{
  statistics_counter_t *counter;
  statistics_counter_t *counter;
 
 
  if ((!(dump_flags & TDF_STATS)
  if ((!(dump_flags & TDF_STATS)
       && !statistics_dump_file)
       && !statistics_dump_file)
      || incr == 0)
      || incr == 0)
    return;
    return;
 
 
  if (current_pass->static_pass_number != -1)
  if (current_pass->static_pass_number != -1)
    {
    {
      counter = lookup_or_add_counter (curr_statistics_hash (), id, 0, false);
      counter = lookup_or_add_counter (curr_statistics_hash (), id, 0, false);
      gcc_assert (!counter->histogram_p);
      gcc_assert (!counter->histogram_p);
      counter->count += incr;
      counter->count += incr;
    }
    }
 
 
  if (!statistics_dump_file
  if (!statistics_dump_file
      || !(statistics_dump_flags & TDF_DETAILS))
      || !(statistics_dump_flags & TDF_DETAILS))
    return;
    return;
 
 
  fprintf (statistics_dump_file,
  fprintf (statistics_dump_file,
           "%d %s \"%s\" \"%s\" %d\n",
           "%d %s \"%s\" \"%s\" %d\n",
           current_pass->static_pass_number,
           current_pass->static_pass_number,
           current_pass->name,
           current_pass->name,
           id,
           id,
           fn ? IDENTIFIER_POINTER (DECL_NAME (fn->decl)) : "(nofn)",
           fn ? IDENTIFIER_POINTER (DECL_NAME (fn->decl)) : "(nofn)",
           incr);
           incr);
}
}
 
 
/* Add statistics information about event ID in function FN with the
/* Add statistics information about event ID in function FN with the
   histogram value VAL.
   histogram value VAL.
   It will dump the event to the global statistics file if requested.  */
   It will dump the event to the global statistics file if requested.  */
 
 
void
void
statistics_histogram_event (struct function *fn, const char *id, int val)
statistics_histogram_event (struct function *fn, const char *id, int val)
{
{
  statistics_counter_t *counter;
  statistics_counter_t *counter;
 
 
  if (!(dump_flags & TDF_STATS)
  if (!(dump_flags & TDF_STATS)
      && !statistics_dump_file)
      && !statistics_dump_file)
    return;
    return;
 
 
  counter = lookup_or_add_counter (curr_statistics_hash (), id, val, true);
  counter = lookup_or_add_counter (curr_statistics_hash (), id, val, true);
  gcc_assert (counter->histogram_p);
  gcc_assert (counter->histogram_p);
  counter->count += 1;
  counter->count += 1;
 
 
  if (!statistics_dump_file
  if (!statistics_dump_file
      || !(statistics_dump_flags & TDF_DETAILS))
      || !(statistics_dump_flags & TDF_DETAILS))
    return;
    return;
 
 
  fprintf (statistics_dump_file,
  fprintf (statistics_dump_file,
           "%d %s \"%s == %d\" \"%s\" 1\n",
           "%d %s \"%s == %d\" \"%s\" 1\n",
           current_pass->static_pass_number,
           current_pass->static_pass_number,
           current_pass->name,
           current_pass->name,
           id, val,
           id, val,
           fn ? IDENTIFIER_POINTER (DECL_NAME (fn->decl)) : "(nofn)");
           fn ? IDENTIFIER_POINTER (DECL_NAME (fn->decl)) : "(nofn)");
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.