Dump probability for edges a frequency for BBs
authorMartin Liska <mliska@suse.cz>
Thu, 24 Nov 2016 12:58:45 +0000 (13:58 +0100)
committerMartin Liska <marxin@gcc.gnu.org>
Thu, 24 Nov 2016 12:58:45 +0000 (12:58 +0000)
* gimple-pretty-print.c (dump_edge_probability): New function.
(dump_gimple_switch): Dump label edge probabilities.
(dump_gimple_cond): Likewise.
(dump_gimple_label): Dump
(dump_gimple_bb_header): Dump basic block frequency.
(pp_cfg_jump): Replace e->dest argument with e.
(dump_implicit_edges): Likewise.
* tree-ssa-loop-ivopts.c (get_scaled_computation_cost_at):
Use gimple_bb (at) instead of at->bb.
* gcc.dg/builtin-unreachable-6.c: Update test to not to scan
parts for frequencies/probabilities.
* gcc.dg/pr34027-1.c: Likewise.
* gcc.dg/strict-overflow-2.c: Likewise.
* gcc.dg/tree-ssa/20040703-1.c: Likewise.
* gcc.dg/tree-ssa/builtin-sprintf-2.c: Likewise.
* gcc.dg/tree-ssa/pr32044.c: Likewise.
* gcc.dg/tree-ssa/vector-3.c: Likewise.
* gcc.dg/tree-ssa/vrp101.c: Likewise.
* gcc.dg/tree-ssa/dump-2.c: New test.

From-SVN: r242837

13 files changed:
gcc/ChangeLog
gcc/gimple-pretty-print.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/builtin-unreachable-6.c
gcc/testsuite/gcc.dg/pr34027-1.c
gcc/testsuite/gcc.dg/strict-overflow-2.c
gcc/testsuite/gcc.dg/tree-ssa/20040703-1.c
gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-2.c
gcc/testsuite/gcc.dg/tree-ssa/dump-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/pr32044.c
gcc/testsuite/gcc.dg/tree-ssa/vector-3.c
gcc/testsuite/gcc.dg/tree-ssa/vrp101.c
gcc/tree-ssa-loop-ivopts.c

index 92c2c9e00155c53f539fb6b8d3e5a0d914c3e400..e11426babcf67e81877909c923dcb0476ed236fc 100644 (file)
@@ -1,3 +1,15 @@
+2016-11-24  Martin Liska  <mliska@suse.cz>
+
+       * gimple-pretty-print.c (dump_edge_probability): New function.
+       (dump_gimple_switch): Dump label edge probabilities.
+       (dump_gimple_cond): Likewise.
+       (dump_gimple_label): Dump
+       (dump_gimple_bb_header): Dump basic block frequency.
+       (pp_cfg_jump): Replace e->dest argument with e.
+       (dump_implicit_edges): Likewise.
+       * tree-ssa-loop-ivopts.c (get_scaled_computation_cost_at):
+       Use gimple_bb (at) instead of at->bb.
+
 2016-11-24  Bernd Schmidt  <bschmidt@redhat.com>
 
        * common.opt (flimit-function-alignment): New.
index 82863260ac3afa53903453b535c26eb63a678943..b5e866d36fabeb3cd354d9f98f690522f166e833 100644 (file)
@@ -36,6 +36,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "dumpfile.h"  /* for dump_flags */
 #include "value-prof.h"
 #include "trans-mem.h"
+#include "cfganal.h"
 
 #define INDENT(SPACE)                                                  \
   do { int i; for (i = 0; i < SPACE; i++) pp_space (buffer); } while (0)
@@ -71,6 +72,14 @@ debug_gimple_stmt (gimple *gs)
   print_gimple_stmt (stderr, gs, 0, TDF_VOPS|TDF_MEMSYMS);
 }
 
+/* Dump E probability to BUFFER.  */
+
+static void
+dump_edge_probability (pretty_printer *buffer, edge e)
+{
+  pp_scalar (buffer, " [%.1f%%]",
+            e->probability * 100.0 / REG_BR_PROB_BASE);
+}
 
 /* Print GIMPLE statement G to FILE using SPC indentation spaces and
    FLAGS as in pp_gimple_stmt_1.  */
@@ -905,7 +914,20 @@ dump_gimple_switch (pretty_printer *buffer, gswitch *gs, int spc,
       gcc_checking_assert (case_label != NULL_TREE);
       dump_generic_node (buffer, case_label, spc, flags, false);
       pp_space (buffer);
-      dump_generic_node (buffer, CASE_LABEL (case_label), spc, flags, false);
+      tree label = CASE_LABEL (case_label);
+      dump_generic_node (buffer, label, spc, flags, false);
+
+      if (cfun && cfun->cfg)
+       {
+         basic_block dest = label_to_block (label);
+         if (dest)
+           {
+             edge label_edge = find_edge (gimple_bb (gs), dest);
+             if (label_edge && !(flags & TDF_GIMPLE))
+               dump_edge_probability (buffer, label_edge);
+           }
+       }
+
       if (i < gimple_switch_num_labels (gs) - 1)
        {
          if (flags & TDF_GIMPLE)
@@ -943,6 +965,23 @@ dump_gimple_cond (pretty_printer *buffer, gcond *gs, int spc, int flags)
       dump_generic_node (buffer, gimple_cond_rhs (gs), spc, flags, false);
       if (!(flags & TDF_RHS_ONLY))
        {
+         edge_iterator ei;
+         edge e, true_edge = NULL, false_edge = NULL;
+         basic_block bb = gimple_bb (gs);
+
+         if (bb)
+           {
+             FOR_EACH_EDGE (e, ei, bb->succs)
+               {
+                 if (e->flags & EDGE_TRUE_VALUE)
+                   true_edge = e;
+                 else if (e->flags & EDGE_FALSE_VALUE)
+                   false_edge = e;
+               }
+           }
+
+         bool has_edge_info = true_edge != NULL && false_edge != NULL;
+
          pp_right_paren (buffer);
 
          if (gimple_cond_true_label (gs))
@@ -950,6 +989,8 @@ dump_gimple_cond (pretty_printer *buffer, gcond *gs, int spc, int flags)
              pp_string (buffer, " goto ");
              dump_generic_node (buffer, gimple_cond_true_label (gs),
                                 spc, flags, false);
+             if (has_edge_info && !(flags & TDF_GIMPLE))
+               dump_edge_probability (buffer, true_edge);
              pp_semicolon (buffer);
            }
          if (gimple_cond_false_label (gs))
@@ -957,6 +998,9 @@ dump_gimple_cond (pretty_printer *buffer, gcond *gs, int spc, int flags)
              pp_string (buffer, " else goto ");
              dump_generic_node (buffer, gimple_cond_false_label (gs),
                                 spc, flags, false);
+             if (has_edge_info && !(flags & TDF_GIMPLE))
+               dump_edge_probability (buffer, false_edge);
+
              pp_semicolon (buffer);
            }
        }
@@ -977,6 +1021,10 @@ dump_gimple_label (pretty_printer *buffer, glabel *gs, int spc, int flags)
   else
     {
       dump_generic_node (buffer, label, spc, flags, false);
+      basic_block bb = gimple_bb (gs);
+      if (bb && !(flags & TDF_GIMPLE))
+       pp_scalar (buffer, " [%.1f%%]",
+                  bb->frequency * 100.0 / REG_BR_PROB_BASE);
       pp_colon (buffer);
     }
   if (flags & TDF_GIMPLE)
@@ -2542,7 +2590,8 @@ dump_gimple_bb_header (FILE *outf, basic_block bb, int indent, int flags)
          if (flags & TDF_GIMPLE)
            fprintf (outf, "%*sbb_%d:\n", indent, "", bb->index);
          else
-           fprintf (outf, "%*s<bb %d>:\n", indent, "", bb->index);
+           fprintf (outf, "%*s<bb %d> [%.1f%%]:\n", indent, "", bb->index,
+                    bb->frequency * 100.0 / REG_BR_PROB_BASE);
        }
     }
 }
@@ -2588,19 +2637,20 @@ dump_phi_nodes (pretty_printer *buffer, basic_block bb, int indent, int flags)
    to BUFFER.  */
 
 static void
-pp_cfg_jump (pretty_printer *buffer, basic_block bb, int flags)
+pp_cfg_jump (pretty_printer *buffer, edge e, int flags)
 {
   if (flags & TDF_GIMPLE)
     {
       pp_string (buffer, "goto bb_");
-      pp_decimal_int (buffer, bb->index);
+      pp_decimal_int (buffer, e->dest->index);
       pp_semicolon (buffer);
     }
   else
     {
-      gimple *stmt = first_stmt (bb);
+      gimple *stmt = first_stmt (e->dest);
+
       pp_string (buffer, "goto <bb ");
-      pp_decimal_int (buffer, bb->index);
+      pp_decimal_int (buffer, e->dest->index);
       pp_greater (buffer);
       if (stmt && gimple_code (stmt) == GIMPLE_LABEL)
        {
@@ -2613,6 +2663,8 @@ pp_cfg_jump (pretty_printer *buffer, basic_block bb, int flags)
        }
       else
        pp_semicolon (buffer);
+
+      dump_edge_probability (buffer, e);
     }
 }
 
@@ -2641,11 +2693,11 @@ dump_implicit_edges (pretty_printer *buffer, basic_block bb, int indent,
       extract_true_false_edges_from_block (bb, &true_edge, &false_edge);
 
       INDENT (indent + 2);
-      pp_cfg_jump (buffer, true_edge->dest, flags);
+      pp_cfg_jump (buffer, true_edge, flags);
       newline_and_indent (buffer, indent);
       pp_string (buffer, "else");
       newline_and_indent (buffer, indent + 2);
-      pp_cfg_jump (buffer, false_edge->dest, flags);
+      pp_cfg_jump (buffer, false_edge, flags);
       pp_newline (buffer);
       return;
     }
@@ -2662,7 +2714,7 @@ dump_implicit_edges (pretty_printer *buffer, basic_block bb, int indent,
          && e->goto_locus != UNKNOWN_LOCATION)
        dump_location (buffer, e->goto_locus);
 
-      pp_cfg_jump (buffer, e->dest, flags);
+      pp_cfg_jump (buffer, e, flags);
       pp_newline (buffer);
     }
 }
index 694e59dfd0fa105b3e3e4780fb9bc543ba70872c..fa0c0e2c1f0a5cde25ffb092bee2288e69aa9239 100644 (file)
@@ -1,3 +1,16 @@
+2016-11-24  Martin Liska  <mliska@suse.cz>
+
+       * gcc.dg/builtin-unreachable-6.c: Update test to not to scan
+       parts for frequencies/probabilities.
+       * gcc.dg/pr34027-1.c: Likewise.
+       * gcc.dg/strict-overflow-2.c: Likewise.
+       * gcc.dg/tree-ssa/20040703-1.c: Likewise.
+       * gcc.dg/tree-ssa/builtin-sprintf-2.c: Likewise.
+       * gcc.dg/tree-ssa/pr32044.c: Likewise.
+       * gcc.dg/tree-ssa/vector-3.c: Likewise.
+       * gcc.dg/tree-ssa/vrp101.c: Likewise.
+       * gcc.dg/tree-ssa/dump-2.c: New test.
+
 2016-11-24  Bernd Schmidt  <bschmidt@redhat.com>
 
        * gcc.target/i386/align-limit.c: New test.
index 2f8ca3695463fc6780d51c7f8f8db98e04a741dd..d2596e95c3fc30a506cc09817a51535c7dd87a79 100644 (file)
@@ -16,5 +16,5 @@ lab2:
   goto *x;
 }
 
-/* { dg-final { scan-tree-dump-times "lab:" 1 "fab1" } } */
+/* { dg-final { scan-tree-dump-times "lab \\\[\[0-9.\]+%\\\]" 1 "fab1" } } */
 /* { dg-final { scan-tree-dump-times "__builtin_unreachable" 1 "fab1" } } */
index b1163ce77202af5c4458b0a9600497afaded7f70..0405e357a2f57d17d53fcfb097c38e8bb01a9315 100644 (file)
@@ -11,5 +11,5 @@ unsigned long foobar(unsigned long ns)
 /* This test was originally introduced to test that we transform
    to ns % 10000.  See the discussion of PR 32044 why we do not do
    that anymore.  */
-/* { dg-final { scan-tree-dump-times "%" 0 "optimized" } } */
-/* { dg-final { scan-tree-dump-times "/" 0 "optimized" } } */
+/* { dg-final { scan-tree-dump-times " % " 0 "optimized" } } */
+/* { dg-final { scan-tree-dump-times " / " 0 "optimized" } } */
index c39d8e8a3d32606a68ab893f1531664d3d2b7637..f23c43aa892791d8104290e7f93db03a912c30c3 100644 (file)
@@ -12,4 +12,4 @@ foo (int i)
   return (i * 100) / 10;
 }
 
-/* { dg-final { scan-tree-dump-not "100" "optimized" } } */
+/* { dg-final { scan-tree-dump-not "\\\* 100" "optimized" } } */
index 25e470a59b6a6c3fb8601635e63671b1572fa55b..2980047685218042bf0ef72913844df6d5389edf 100644 (file)
@@ -9,4 +9,4 @@ float foo(float x)
 }
 
 /* We should *not* fold the arithmetic.  */
-/* { dg-final { scan-tree-dump-times "0\\.0" 0 "dom2"} } */
+/* { dg-final { scan-tree-dump-times "0\\.0\[^%\]" 0 "dom2"} } */
index 1996665e2b3487dd13aca67cc2674837a13a4347..6279956c411fc0e0d3d63eb428a9c2d1950063e7 100644 (file)
@@ -252,5 +252,5 @@ RNG (0,  6,   8, "%s%ls", "1", L"2");
 
 */
 
-/* { dg-final { scan-tree-dump-times ">:\n *__builtin_abort" 114 "optimized" { target { ilp32 || lp64 } } } } */
-/* { dg-final { scan-tree-dump-times ">:\n *__builtin_abort" 83 "optimized" { target { { ! ilp32 } && { ! lp64 } } } } } */
+/* { dg-final { scan-tree-dump-times "> \\\[\[0-9.\]+%\\\]:\n *__builtin_abort" 114 "optimized" { target { ilp32 || lp64 } } } } */
+/* { dg-final { scan-tree-dump-times "> \\\[\[0-9.\]+%\\\]:\n *__builtin_abort" 83 "optimized" { target { { ! ilp32 } && { ! lp64 } } } } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/dump-2.c b/gcc/testsuite/gcc.dg/tree-ssa/dump-2.c
new file mode 100644 (file)
index 0000000..11cde92
--- /dev/null
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-O1 -fdump-tree-optimized" } */
+
+int f(void)
+{
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump "<bb \[0-9\]> \\\[100\\\.0%\\\]:" "optimized" } } */
index 745a5e4db01076101788891ae146541246db2dab..8a8977a7a6846ff9bc1c7628042e594518ef1180 100644 (file)
@@ -48,6 +48,6 @@ int baz (int n)
 
 /* There should be no division/modulo in the final dump (division and modulo
    by 64 are done using bit operations).  */
-/* { dg-final { scan-tree-dump-times "/" 0 "optimized" } } */
-/* { dg-final { scan-tree-dump-times "%" 0 "optimized" } } */
+/* { dg-final { scan-tree-dump-times " / " 0 "optimized" } } */
+/* { dg-final { scan-tree-dump-times " % " 0 "optimized" } } */
 
index ecdebf643c098cbae4378dfe6010595c835b3a09..589ee7e8616a9bdcd9285f489ecc159f466b1287 100644 (file)
@@ -14,6 +14,6 @@ float f(float b)
 
 /* We should be able to optimize this to just "return 0.0;" */
 /* { dg-final { scan-tree-dump-times "BIT_FIELD_REF" 0 "optimized"} } */
-/* { dg-final { scan-tree-dump-times "0\\\.0" 1 "optimized"} } */
+/* { dg-final { scan-tree-dump-times " 0\\\.0" 1 "optimized"} } */
 
 
index cfca5396e636ff4c0ace1033e47217e6cec8e2d2..bf4109f7156c47d9c78e83e93034e910fc45dba2 100644 (file)
@@ -10,4 +10,4 @@ int main ()
   return 0;
 }
 
-/* { dg-final { scan-tree-dump "<bb 2>:\[\n\r \]*return 0;" "optimized" } } */
+/* { dg-final { scan-tree-dump "<bb 2> \\\[\[0-9.\]+%\\\]:\[\n\r \]*return 0;" "optimized" } } */
index 2655c2346cc3ae2e7a66a7a77ecb32ec1f411c87..5c667a201a78f6b1e7eaaaef3029b21135bf6ceb 100644 (file)
@@ -4807,7 +4807,7 @@ get_scaled_computation_cost_at (ivopts_data *data, gimple *at, iv_cand *cand,
                                comp_cost cost)
 {
    int loop_freq = data->current_loop->header->frequency;
-   int bb_freq = at->bb->frequency;
+   int bb_freq = gimple_bb (at)->frequency;
    if (loop_freq != 0)
      {
        gcc_assert (cost.scratch <= cost.cost);