]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
value-prof.c: New.
authorZdenek Dvorak <rakdver@gcc.gnu.org>
Thu, 26 Jun 2003 09:38:34 +0000 (09:38 +0000)
committerZdenek Dvorak <rakdver@gcc.gnu.org>
Thu, 26 Jun 2003 09:38:34 +0000 (09:38 +0000)
* value-prof.c: New.
* value-prof.h: New.

From-SVN: r68521

gcc/value-prof.c [new file with mode: 0644]
gcc/value-prof.h [new file with mode: 0644]

diff --git a/gcc/value-prof.c b/gcc/value-prof.c
new file mode 100644 (file)
index 0000000..1c8ff4e
--- /dev/null
@@ -0,0 +1,106 @@
+/* Transformations based on profile information for values.
+   Copyright (C) 2003 Free Software Foundation, Inc.
+
+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 2, 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 COPYING.  If not, write to the Free
+Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+02111-1307, USA.  */
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "rtl.h"
+#include "expr.h"
+#include "hard-reg-set.h"
+#include "basic-block.h"
+#include "value-prof.h"
+#include "output.h"
+#include "flags.h"
+#include "insn-config.h"
+#include "recog.h"
+#include "optabs.h"
+
+/* In this file value profile based optimizations will be placed (none are
+   here just now, but they are hopefully coming soon).
+
+   Every such optimization should add its requirements for profiled values to
+   insn_values_to_profile function.  This function is called from branch_prob
+   in profile.c and the requested values are instrumented by it in the first
+   compilation with -fprofile-arcs.  The optimization may then read the
+   gathered data in the second compilation with -fbranch-probablities (the
+   description of an exact way how to do it will be added here once the
+   code responsible for reading of the data is merged).  */
+
+static void insn_values_to_profile (rtx, unsigned *, struct histogram_value **);
+\f
+/* Release the list of VALUES of length N_VALUES for that we want to measure
+   histograms.  */
+void
+free_profiled_values (unsigned n_values ATTRIBUTE_UNUSED,
+                     struct histogram_value *values)
+{
+  free (values);
+}
+
+/* Find values inside INSN for that we want to measure histograms and adds
+   them to list VALUES (increasing the record of its length in N_VALUES).  */
+static void
+insn_values_to_profile (rtx insn ATTRIBUTE_UNUSED,
+                       unsigned *n_values ATTRIBUTE_UNUSED,
+                       struct histogram_value **values ATTRIBUTE_UNUSED)
+{
+}
+
+/* Find list of values for that we want to measure histograms.  */
+void
+find_values_to_profile (unsigned *n_values, struct histogram_value **values)
+{
+  rtx insn;
+  unsigned i;
+
+  *n_values = 0;
+  *values = NULL;
+  for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
+    insn_values_to_profile (insn, n_values, values);
+
+  for (i = 0; i < *n_values; i++)
+    {
+      switch ((*values)[i].type)
+       {
+       case HIST_TYPE_INTERVAL:
+         (*values)[i].n_counters = (*values)[i].hdata.intvl.steps +
+                 ((*values)[i].hdata.intvl.may_be_less ? 1 : 0) +
+                 ((*values)[i].hdata.intvl.may_be_more ? 1 : 0);
+         break;
+
+       case HIST_TYPE_POW2:
+         (*values)[i].n_counters = GET_MODE_BITSIZE ((*values)[i].mode) +
+                 ((*values)[i].hdata.pow2.may_be_other ? 1 : 0);
+         break;
+
+       case HIST_TYPE_SINGLE_VALUE:
+         (*values)[i].n_counters = 3;
+         break;
+
+       case HIST_TYPE_CONST_DELTA:
+         (*values)[i].n_counters = 4;
+         break;
+
+       default:
+         abort ();
+       }
+    }
+}
diff --git a/gcc/value-prof.h b/gcc/value-prof.h
new file mode 100644 (file)
index 0000000..ddb2028
--- /dev/null
@@ -0,0 +1,59 @@
+/* Definitions for transformations based on profile information for values.
+   Copyright (C) 2003 Free Software Foundation, Inc.
+
+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 2, 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 COPYING.  If not, write to the Free
+Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+02111-1307, USA.  */
+
+/* Supported histogram types.  */
+enum hist_type
+{
+  HIST_TYPE_INTERVAL,  /* Measures histogram of values inside a specified
+                          interval.  */
+  HIST_TYPE_POW2,      /* Histogram of power of 2 values.  */
+  HIST_TYPE_SINGLE_VALUE, /* Tries to identify the value that is (almost)
+                          always constant.  */
+  HIST_TYPE_CONST_DELTA        /* Tries to identify the (almost) always constant
+                          difference between two evaluations of a value.  */
+};
+
+/* The value to measure.  */
+struct histogram_value
+{
+  rtx value;           /* The value to profile.  */
+  enum machine_mode mode; /* And its mode.  */
+  rtx seq;             /* Insns requiered to count the profiled value.  */
+  rtx insn;            /* Insn before that to measure.  */
+  enum hist_type type; /* Type of information to measure.  */
+  unsigned n_counters; /* Number of requiered counters.  */
+  union
+    {
+      struct
+       {
+         int int_start;        /* First value in interval.  */
+         int steps;            /* Number of values in it.  */
+         int may_be_less;      /* May the value be below?  */
+         int may_be_more;      /* Or above.  */
+       } intvl;        /* Interval histogram data.  */
+      struct
+       {
+         int may_be_other;     /* If the value may be non-positive or not 2^k.  */
+       } pow2;         /* Power of 2 histogram data.  */
+    } hdata;           /* Profiled information specific data.  */
+};
+
+extern void find_values_to_profile (unsigned *, struct histogram_value **);
+extern void free_profiled_values (unsigned, struct histogram_value *);