Daily bump.
[gcc.git] / libgcc / libgcov-merge.c
index 45cd48cc4c4e290e9e8ebc8450bc167135248744..1acdaa0403e60b7ab47d700218fc6c5eb9a32355 100644 (file)
@@ -1,6 +1,6 @@
 /* Routines required for instrumenting a program.  */
 /* Compile this one with gcc.  */
-/* Copyright (C) 1989-2013 Free Software Foundation, Inc.
+/* Copyright (C) 1989-2020 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -23,19 +23,7 @@ a copy of the GCC Runtime Library Exception along with this program;
 see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 <http://www.gnu.org/licenses/>.  */
 
-#include "tconfig.h"
-#include "tsystem.h"
-#include "coretypes.h"
-#include "tm.h"
-#include "libgcc_tm.h"
-
-#if defined(inhibit_libc)
-#define IN_LIBGCOV (-1)
-#else
-#define IN_LIBGCOV 1
-#endif
-
-#include "gcov-io.h"
+#include "libgcov.h"
 
 #if defined(inhibit_libc)
 /* If libc and its header files are not available, provide dummy functions.  */
@@ -45,14 +33,9 @@ void __gcov_merge_add (gcov_type *counters  __attribute__ ((unused)),
                        unsigned n_counters __attribute__ ((unused))) {}
 #endif
 
-#ifdef L_gcov_merge_single
-void __gcov_merge_single (gcov_type *counters  __attribute__ ((unused)),
-                          unsigned n_counters __attribute__ ((unused))) {}
-#endif
-
-#ifdef L_gcov_merge_delta
-void __gcov_merge_delta (gcov_type *counters  __attribute__ ((unused)),
-                         unsigned n_counters __attribute__ ((unused))) {}
+#ifdef L_gcov_merge_topn
+void __gcov_merge_topn (gcov_type *counters  __attribute__ ((unused)),
+                       unsigned n_counters __attribute__ ((unused))) {}
 #endif
 
 #else
@@ -65,7 +48,7 @@ void
 __gcov_merge_add (gcov_type *counters, unsigned n_counters)
 {
   for (; n_counters; counters++, n_counters--)
-    *counters += gcov_read_counter ();
+    *counters += gcov_get_counter ();
 }
 #endif /* L_gcov_merge_add */
 
@@ -77,7 +60,7 @@ void
 __gcov_merge_ior (gcov_type *counters, unsigned n_counters)
 {
   for (; n_counters; counters++, n_counters--)
-    *counters |= gcov_read_counter ();
+    *counters |= gcov_get_counter_target ();
 }
 #endif
 
@@ -93,7 +76,7 @@ __gcov_merge_time_profile (gcov_type *counters, unsigned n_counters)
 
   for (i = 0; i < n_counters; i++)
     {
-      value = gcov_read_counter ();
+      value = gcov_get_counter_target ();
 
       if (value && (!counters[i] || value < counters[i]))
         counters[i] = value;
@@ -101,81 +84,42 @@ __gcov_merge_time_profile (gcov_type *counters, unsigned n_counters)
 }
 #endif /* L_gcov_merge_time_profile */
 
-#ifdef L_gcov_merge_single
+#ifdef L_gcov_merge_topn
+
 /* The profile merging function for choosing the most common value.
    It is given an array COUNTERS of N_COUNTERS old counters and it
    reads the same number of counters from the gcov file.  The counters
-   are split into 3-tuples where the members of the tuple have
+   are split into pairs where the members of the tuple have
    meanings:
 
    -- the stored candidate on the most common value of the measured entity
    -- counter
-   -- total number of evaluations of the value  */
+   */
+
 void
-__gcov_merge_single (gcov_type *counters, unsigned n_counters)
+__gcov_merge_topn (gcov_type *counters, unsigned n_counters)
 {
-  unsigned i, n_measures;
-  gcov_type value, counter, all;
+  gcc_assert (!(n_counters % GCOV_TOPN_MEM_COUNTERS));
 
-  gcc_assert (!(n_counters % 3));
-  n_measures = n_counters / 3;
-  for (i = 0; i < n_measures; i++, counters += 3)
+  for (unsigned i = 0; i < (n_counters / GCOV_TOPN_MEM_COUNTERS); i++)
     {
-      value = gcov_read_counter ();
-      counter = gcov_read_counter ();
-      all = gcov_read_counter ();
-
-      if (counters[0] == value)
-        counters[1] += counter;
-      else if (counter > counters[1])
-        {
-          counters[0] = value;
-          counters[1] = counter - counters[1];
-        }
-      else
-        counters[1] -= counter;
-      counters[2] += all;
-    }
-}
-#endif /* L_gcov_merge_single */
+      /* First value is number of total executions of the profiler.  */
+      gcov_type all = gcov_get_counter_ignore_scaling (-1);
+      gcov_type n = gcov_get_counter_ignore_scaling (-1);
 
-#ifdef L_gcov_merge_delta
-/* The profile merging function for choosing the most common
-   difference between two consecutive evaluations of the value.  It is
-   given an array COUNTERS of N_COUNTERS old counters and it reads the
-   same number of counters from the gcov file.  The counters are split
-   into 4-tuples where the members of the tuple have meanings:
+      counters[GCOV_TOPN_MEM_COUNTERS * i] += all;
 
-   -- the last value of the measured entity
-   -- the stored candidate on the most common difference
-   -- counter
-   -- total number of evaluations of the value  */
-void
-__gcov_merge_delta (gcov_type *counters, unsigned n_counters)
-{
-  unsigned i, n_measures;
-  gcov_type value, counter, all;
+      for (unsigned j = 0; j < n; j++)
+       {
+         gcov_type value = gcov_get_counter_target ();
+         gcov_type count = gcov_get_counter_ignore_scaling (-1);
 
-  gcc_assert (!(n_counters % 4));
-  n_measures = n_counters / 4;
-  for (i = 0; i < n_measures; i++, counters += 4)
-    {
-      /* last = */ gcov_read_counter ();
-      value = gcov_read_counter ();
-      counter = gcov_read_counter ();
-      all = gcov_read_counter ();
-
-      if (counters[1] == value)
-        counters[2] += counter;
-      else if (counter > counters[2])
-        {
-          counters[1] = value;
-          counters[2] = counter - counters[2];
-        }
-      else
-        counters[2] -= counter;
-      counters[3] += all;
+         // TODO: we should use atomic here
+         gcov_topn_add_value (counters + GCOV_TOPN_MEM_COUNTERS * i, value,
+                              count, 0, 0);
+       }
     }
 }
-#endif /* L_gcov_merge_delta */
+#endif /* L_gcov_merge_topn */
+
 #endif /* inhibit_libc */