cfgloopanal.c: Include sreal.h
authorJan Hubicka <hubicka@ucw.cz>
Thu, 16 Nov 2017 10:36:04 +0000 (11:36 +0100)
committerJan Hubicka <hubicka@gcc.gnu.org>
Thu, 16 Nov 2017 10:36:04 +0000 (10:36 +0000)
* cfgloopanal.c: Include sreal.h
(average_num_loop_insns): Use counts and sreal for accounting.

From-SVN: r254807

gcc/ChangeLog
gcc/cfgloopanal.c

index 452a9a4..e3bf8ee 100644 (file)
@@ -1,5 +1,10 @@
 2017-11-14  Jan Hubicka  <hubicka@ucw.cz>
 
+       * cfgloopanal.c: Include sreal.h
+       (average_num_loop_insns): Use counts and sreal for accounting.
+
+2017-11-14  Jan Hubicka  <hubicka@ucw.cz>
+
        * cfgloopmanip.c (duplicate_loop_to_header_edge): Cleanup profile
        manipulation.
 
index 78a3c93..63f7eab 100644 (file)
@@ -31,6 +31,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "expr.h"
 #include "graphds.h"
 #include "params.h"
+#include "sreal.h"
 
 struct target_cfgloop default_target_cfgloop;
 #if SWITCHABLE_TARGET
@@ -199,7 +200,8 @@ int
 average_num_loop_insns (const struct loop *loop)
 {
   basic_block *bbs, bb;
-  unsigned i, binsns, ninsns, ratio;
+  unsigned i, binsns;
+  sreal ninsns;
   rtx_insn *insn;
 
   ninsns = 0;
@@ -213,19 +215,18 @@ average_num_loop_insns (const struct loop *loop)
        if (NONDEBUG_INSN_P (insn))
          binsns++;
 
-      ratio = loop->header->count.to_frequency (cfun) == 0
-             ? BB_FREQ_MAX
-             : (bb->count.to_frequency (cfun) * BB_FREQ_MAX)
-                / loop->header->count.to_frequency (cfun);
-      ninsns += binsns * ratio;
+      ninsns += (sreal)binsns * bb->count.to_sreal_scale (loop->header->count);
+      /* Avoid overflows.   */
+      if (ninsns > 1000000)
+       return 100000;
     }
   free (bbs);
 
-  ninsns /= BB_FREQ_MAX;
-  if (!ninsns)
-    ninsns = 1; /* To avoid division by zero.  */
+  int64_t ret = ninsns.to_int ();
+  if (!ret)
+    ret = 1; /* To avoid division by zero.  */
 
-  return ninsns;
+  return ret;
 }
 
 /* Returns expected number of iterations of LOOP, according to