profile.c (branch_prob): Split edges with goto locus on them to get proper line counts.
authorJan Hubicka <jh@suse.cz>
Wed, 3 Aug 2005 22:10:54 +0000 (00:10 +0200)
committerJan Hubicka <hubicka@gcc.gnu.org>
Wed, 3 Aug 2005 22:10:54 +0000 (22:10 +0000)
* profile.c (branch_prob): Split edges with goto locus on them
to get proper line counts.
* tree-cfg.c (make_cond_expr_edges): Record user goto locuses, if any.

* gcov-1.C: Fix switch counts.
* gcov-4b.c: Likewise.

From-SVN: r102717

gcc/ChangeLog
gcc/profile.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/gcov/gcov-1.C
gcc/testsuite/gcc.misc-tests/gcov-4b.c
gcc/tree-cfg.c

index e879f4d3a9d4c44a1cd877b9a3506e57a87fcc61..8a061aed2eed2fae1fbf9a4ffde3288ac0e00e96 100644 (file)
@@ -1,3 +1,9 @@
+2005-08-04  Jan Hubicka  <jh@suse.cz>
+
+       * profile.c (branch_prob): Split edges with goto locus on them
+       to get proper line counts.
+       * tree-cfg.c (make_cond_expr_edges): Record user goto locuses, if any.
+
 2005-08-03  Paul Brook  <paul@codesourcery.com>
 
        * function.c (assign_parms): Round current_function_args_size
index 95448f076ff3b160e36174ccf6c8b991124cdbf8..1fc8aa58d505f9b92019f010f5c35476c866fd78 100644 (file)
@@ -806,6 +806,27 @@ branch_prob (void)
 
       FOR_EACH_EDGE (e, ei, bb->succs)
        {
+         tree last = last_stmt (bb);
+         /* Edge with goto locus might get wrong coverage info unless
+            it is the only edge out of BB.   
+            Don't do that when the locuses match, so 
+            if (blah) goto something;
+            is not computed twice.  */
+         if (e->goto_locus && !single_succ_p (bb)
+#ifdef USE_MAPPED_LOCATION
+             && (LOCATION_FILE (e->goto_locus)
+                 != LOCATION_FILE (EXPR_LOCATION  (last))
+                 || (LOCATION_LINE (e->goto_locus)
+                     != LOCATION_LINE (EXPR_LOCATION  (last)))))
+#else
+             && (e->goto_locus->file != EXPR_LOCUS (last)->file
+                 || (e->goto_locus->line
+                     != EXPR_LOCUS (last)->line)))
+#endif
+           {
+             basic_block new = split_edge (e);
+             single_succ_edge (new)->goto_locus = e->goto_locus;
+           }
          if ((e->flags & (EDGE_ABNORMAL | EDGE_ABNORMAL_CALL))
               && e->dest != EXIT_BLOCK_PTR)
            need_exit_edge = 1;
index 800fc4151a70fed69e43bbe84de0600b90f5defd..acbe5eba8bcdc545d2ebe221bbdca7fc1706abb6 100644 (file)
@@ -1,3 +1,8 @@
+2005-08-04  Jan Hubicka  <jh@suse.cz>
+
+       * gcov-1.C: Fix switch counts.
+       * gcov-4b.c: Likewise.
+
 2005-08-03  Jeff Law  <law@redhat.com>
 
        * g++.dg/tree-ssa/pr14814.C: xfail test for &this count.
index 6089adac05b40f22776215850fdfb5955d1a5d4e..c279b1452fcdf39d68e23a75ed274bb94a6a186a 100644 (file)
@@ -253,7 +253,7 @@ test_switch (int i, int j)
 {
   int result = 0;                      /* count(5) */
 
-                                       /* branch(80 25) */
+                                       /* branch(20 0 60 20) */
   switch (i)                           /* count(5) */
                                        /* branch(end) */
     {
index 7653c5897ad7e18ad5b31a43277a5d4232d4f13d..da98749f719a868d9465391d90906332a4dbf785 100644 (file)
@@ -207,7 +207,7 @@ test_switch (int i, int j)
 {
   int result = 0;
 
-  switch (i)                           /* branch(80 25) */
+  switch (i)                           /* branch(20 0 60 20) */
                                        /* branch(end) */
     {
       case 1:
index bf25f837e766af1246df232164970b686587f4f7..096da092151bc883e76272d7ba274fb00b8e6279 100644 (file)
@@ -577,6 +577,7 @@ make_cond_expr_edges (basic_block bb)
   tree entry = last_stmt (bb);
   basic_block then_bb, else_bb;
   tree then_label, else_label;
+  edge e;
 
   gcc_assert (entry);
   gcc_assert (TREE_CODE (entry) == COND_EXPR);
@@ -587,8 +588,21 @@ make_cond_expr_edges (basic_block bb)
   then_bb = label_to_block (then_label);
   else_bb = label_to_block (else_label);
 
-  make_edge (bb, then_bb, EDGE_TRUE_VALUE);
-  make_edge (bb, else_bb, EDGE_FALSE_VALUE);
+  e = make_edge (bb, then_bb, EDGE_TRUE_VALUE);
+#ifdef USE_MAPPED_LOCATION
+  e->goto_locus = EXPR_LOCATION (COND_EXPR_THEN (entry));
+#else
+  e->goto_locus = EXPR_LOCUS (COND_EXPR_THEN (entry));
+#endif
+  e = make_edge (bb, else_bb, EDGE_FALSE_VALUE);
+  if (e)
+    {
+#ifdef USE_MAPPED_LOCATION
+      e->goto_locus = EXPR_LOCATION (COND_EXPR_ELSE (entry));
+#else
+      e->goto_locus = EXPR_LOCUS (COND_EXPR_ELSE (entry));
+#endif
+    }
 }
 
 /* Hashing routine for EDGE_TO_CASES.  */