value-prof.c (tree_ic_transform): Print counts.
authorSeongbae Park <seongbae.park@gmail.com>
Wed, 28 May 2008 18:14:32 +0000 (18:14 +0000)
committerSeongbae Park <spark@gcc.gnu.org>
Wed, 28 May 2008 18:14:32 +0000 (18:14 +0000)
gcc/ChangeLog:
2008-05-28  Seongbae Park <seongbae.park@gmail.com>

* value-prof.c (tree_ic_transform): Print counts.
* tree-profile.c (tree_gen_ic_func_profiler):
Clear __gcov_indreict_call_callee variable
to avoid misattribution of the profile.

gcc/testsuite/ChangeLog:
2008-05-28  Seongbae Park <seongbae.park@gmail.com>

* gcc.dg/tree-prof/ic-misattribution-1.c: New test.
* gcc.dg/tree-prof/ic-misattribution-1a.c: New test.
* lib/profopt.exp (profopt-get-options): Support
dg-additional-sources.
(profopt-execute): Handle additional sources.

From-SVN: r136118

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-prof/ic-misattribution-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-prof/ic-misattribution-1a.c [new file with mode: 0644]
gcc/testsuite/lib/profopt.exp
gcc/tree-profile.c
gcc/value-prof.c

index fe82a48d1bddcea8ed1a91c5cd8aa3ce6213f644..7bffba370762619bc6517accecaa917a295e1d8f 100644 (file)
@@ -1,3 +1,10 @@
+2008-05-28  Seongbae Park <seongbae.park@gmail.com>
+
+       * value-prof.c (tree_ic_transform): Print counts.
+       * tree-profile.c (tree_gen_ic_func_profiler):
+       Clear __gcov_indreict_call_callee variable
+       to avoid misattribution of the profile.
+
 2008-05-28  Rafael Espindola  <espindola@google.com>
 
        * see.c (see_def_extension_not_merged): Use copy_rtx_if_shared to avoid
index c548a7d182876df528ef25da9c6de7e0eb26cb76..b715c2d00ca238d3cf8202e70cf77dafd3853673 100644 (file)
@@ -1,3 +1,11 @@
+2008-05-28  Seongbae Park <seongbae.park@gmail.com>
+
+       * gcc.dg/tree-prof/ic-misattribution-1.c: New test.
+       * gcc.dg/tree-prof/ic-misattribution-1a.c: New test.
+       * lib/profopt.exp (profopt-get-options): Support
+       dg-additional-sources.
+       (profopt-execute): Handle additional sources.
+
 2008-05-28  Rafael Espindola  <espindola@google.com>
 
        * gcc.dg/20080528-1.c: New test.
diff --git a/gcc/testsuite/gcc.dg/tree-prof/ic-misattribution-1.c b/gcc/testsuite/gcc.dg/tree-prof/ic-misattribution-1.c
new file mode 100644 (file)
index 0000000..c36dd8d
--- /dev/null
@@ -0,0 +1,19 @@
+/* { dg-options "-O2 -fdump-tree-tree_profile" } */
+/* { dg-additional-sources "ic-misattribution-1a.c" } */
+
+extern void other_caller (void);
+
+void
+callee (void)
+{
+  return;
+}
+
+void
+caller(void (*func) (void))
+{
+  func ();
+}
+
+/* { dg-final-use { scan-tree-dump "hist->count 1 hist->all 1" "tree_profile" } } */
+/* { dg-final-use { cleanup-tree-dump "tree_profile" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-prof/ic-misattribution-1a.c b/gcc/testsuite/gcc.dg/tree-prof/ic-misattribution-1a.c
new file mode 100644 (file)
index 0000000..ac54ab1
--- /dev/null
@@ -0,0 +1,20 @@
+/* { dg-options "-DEMPTY" } */
+/* This file is only needed in combination with ic-misattribution-1.c
+   but there's no easy way to make this file ignored. */
+extern void callee (void);
+extern void caller (void (*func) (void));
+
+typedef void (*func_t) (void);
+func_t func;
+
+int
+main ()
+{
+#ifdef EMPTY
+#else
+  func = callee;
+  caller (callee);
+  func ();
+#endif
+  return 0;
+}
index 92e6660b756b1568de7272fcac8a308ede5b2fee..967b7906f0ea87de20cf329ccdc6af5aea370d34 100644 (file)
@@ -184,6 +184,7 @@ proc profopt-get-options { src } {
             || ![string compare "dg-skip-if" $cmd] \
             || ![string compare "dg-final-generate" $cmd] \
             || ![string compare "dg-final-use" $cmd] \
+             || ![string compare "dg-additional-sources" $cmd] \
             || [string match "dg-require-*" $cmd]  } {
            set status [catch "$op" errmsg]
            if { $status != 0 } {
@@ -266,9 +267,11 @@ proc profopt-execute { src } {
            return
        }
 
+        set extra_options [dg-additional-files-options "" "$src"]
+
        # Compile for profiling.
 
-       set options ""
+       set options "$extra_options"
        lappend options "additional_flags=$option $extra_flags $profile_option"
        set optstr "$option $profile_option"
        set comp_output [${tool}_target_compile "$src" "$execname1" executable $options]
@@ -317,7 +320,7 @@ proc profopt-execute { src } {
 
        # Compile with feedback-directed optimizations.
 
-       set options ""
+       set options "$extra_options"
        lappend options "additional_flags=$option $extra_flags $feedback_option"
        set optstr "$option $feedback_option"
        set comp_output [${tool}_target_compile "$src" "$execname2" "executable" $options]
@@ -364,7 +367,7 @@ proc profopt-execute { src } {
 
        # Compile with normal optimizations.
 
-       set options ""
+       set options "$extra_options"
        lappend options "additional_flags=$option"
        set optstr "$option"
        set comp_output [${tool}_target_compile "$src" "$execname3" "executable" $options]
index 7a70cefad19d4d7a39155df587bb2c242d4e4da3..6121837e49628a1fc5bd385db1c7674efaab7101 100644 (file)
@@ -308,7 +308,7 @@ tree_gen_ic_func_profiler (void)
   edge e;
   basic_block bb;
   edge_iterator ei;
-  tree stmt1;
+  tree stmt1, stmt2;
   tree tree_uid, cur_func;
 
   if (flag_unit_at_a_time)
@@ -321,8 +321,11 @@ tree_gen_ic_func_profiler (void)
   
   FOR_EACH_EDGE (e, ei, ENTRY_BLOCK_PTR->succs)
     {
+      tree void0;
+
       bb = split_edge (e);
       bsi = bsi_start (bb);
+
       cur_func = force_gimple_operand_bsi (&bsi,
                                           build_addr (current_function_decl, 
                                                       current_function_decl),
@@ -335,6 +338,16 @@ tree_gen_ic_func_profiler (void)
                               cur_func,
                               ic_void_ptr_var);
       bsi_insert_after (&bsi, stmt1, BSI_NEW_STMT);
+
+      gcc_assert (EDGE_COUNT (bb->succs) == 1);
+      bb = split_edge (EDGE_I (bb->succs, 0));
+      bsi = bsi_start (bb);
+      /* Set __gcov_indirect_call_callee to 0,
+         so that calls from other modules won't get misattributed
+        to the last caller of the current callee. */
+      void0 = build_int_cst (build_pointer_type (void_type_node), 0);
+      stmt2 = build_gimple_modify_stmt (ic_void_ptr_var, void0);
+      bsi_insert_after (&bsi, stmt2, BSI_NEW_STMT);
     }
 }
 
index 33ecded88c39f7a52fe6d5844309fc1a90987ae6..8b0087a850f8fe593a197d56c4b75998c84c4d0b 100644 (file)
@@ -1198,6 +1198,7 @@ tree_ic_transform (tree stmt)
       print_generic_stmt (dump_file, stmt, TDF_SLIM);
       fprintf (dump_file, " to ");
       print_generic_stmt (dump_file, modify, TDF_SLIM);
+      fprintf (dump_file, "hist->count %llu hist->all %llu\n", count, all);
     }
 
   return true;