re PR debug/66691 (ICE on valid code at -O3 with -g enabled in simplify_subreg, at...
[gcc.git] / gcc / tree-profile.c
index 73844e81d16c8f99be9f58eb225f5d0bc6684b54..bcb5cb9953f3bed31c7a390d6d1655ea4287bbac 100644 (file)
@@ -1,5 +1,5 @@
 /* Calculate branch probabilities, and basic block execution counts.
-   Copyright (C) 1990-2014 Free Software Foundation, Inc.
+   Copyright (C) 1990-2015 Free Software Foundation, Inc.
    Contributed by James E. Wilson, UC Berkeley/Cygnus Support;
    based on some ideas from Dain Samples of UC Berkeley.
    Further mangling by Bob Manson, Cygnus Support.
@@ -29,12 +29,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "coretypes.h"
 #include "tm.h"
 #include "flags.h"
-#include "hashtab.h"
-#include "hash-set.h"
-#include "vec.h"
-#include "machmode.h"
 #include "hard-reg-set.h"
-#include "input.h"
 #include "function.h"
 #include "predict.h"
 #include "dominance.h"
@@ -42,11 +37,13 @@ along with GCC; see the file COPYING3.  If not see
 #include "basic-block.h"
 #include "diagnostic-core.h"
 #include "coverage.h"
+#include "alias.h"
+#include "symtab.h"
 #include "tree.h"
+#include "fold-const.h"
 #include "tree-ssa-alias.h"
 #include "internal-fn.h"
 #include "gimple-expr.h"
-#include "is-a.h"
 #include "gimple.h"
 #include "varasm.h"
 #include "tree-nested.h"
@@ -54,9 +51,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "gimple-iterator.h"
 #include "gimplify-me.h"
 #include "gimple-ssa.h"
-#include "hash-map.h"
-#include "plugin-api.h"
-#include "ipa-ref.h"
 #include "cgraph.h"
 #include "tree-cfg.h"
 #include "stringpool.h"
@@ -98,30 +92,15 @@ init_ic_make_global_vars (void)
 
   ptr_void = build_pointer_type (void_type_node);
 
-  /* Workaround for binutils bug 14342.  Once it is fixed, remove lto path.  */
-  if (flag_lto)
-    {
-      ic_void_ptr_var
-       = build_decl (UNKNOWN_LOCATION, VAR_DECL,
-                     get_identifier ("__gcov_indirect_call_callee_ltopriv"),
-                     ptr_void);
-      TREE_PUBLIC (ic_void_ptr_var) = 1;
-      DECL_COMMON (ic_void_ptr_var) = 1;
-      DECL_VISIBILITY (ic_void_ptr_var) = VISIBILITY_HIDDEN;
-      DECL_VISIBILITY_SPECIFIED (ic_void_ptr_var) = true;
-    }
-  else
-    {
-      ic_void_ptr_var
-       = build_decl (UNKNOWN_LOCATION, VAR_DECL,
-                     get_identifier (
-                             (PARAM_VALUE (PARAM_INDIR_CALL_TOPN_PROFILE) ?
-                              "__gcov_indirect_call_topn_callee" :
-                              "__gcov_indirect_call_callee")),
-                     ptr_void);
-      TREE_PUBLIC (ic_void_ptr_var) = 1;
-      DECL_EXTERNAL (ic_void_ptr_var) = 1;
-    }
+  ic_void_ptr_var
+    = build_decl (UNKNOWN_LOCATION, VAR_DECL,
+                 get_identifier (
+                         (PARAM_VALUE (PARAM_INDIR_CALL_TOPN_PROFILE) ?
+                          "__gcov_indirect_call_topn_callee" :
+                          "__gcov_indirect_call_callee")),
+                 ptr_void);
+  TREE_PUBLIC (ic_void_ptr_var) = 1;
+  DECL_EXTERNAL (ic_void_ptr_var) = 1;
   TREE_STATIC (ic_void_ptr_var) = 1;
   DECL_ARTIFICIAL (ic_void_ptr_var) = 1;
   DECL_INITIAL (ic_void_ptr_var) = NULL;
@@ -131,30 +110,16 @@ init_ic_make_global_vars (void)
   varpool_node::finalize_decl (ic_void_ptr_var);
 
   gcov_type_ptr = build_pointer_type (get_gcov_type ());
-  /* Workaround for binutils bug 14342.  Once it is fixed, remove lto path.  */
-  if (flag_lto)
-    {
-      ic_gcov_type_ptr_var
-       = build_decl (UNKNOWN_LOCATION, VAR_DECL,
-                     get_identifier ("__gcov_indirect_call_counters_ltopriv"),
-                     gcov_type_ptr);
-      TREE_PUBLIC (ic_gcov_type_ptr_var) = 1;
-      DECL_COMMON (ic_gcov_type_ptr_var) = 1;
-      DECL_VISIBILITY (ic_gcov_type_ptr_var) = VISIBILITY_HIDDEN;
-      DECL_VISIBILITY_SPECIFIED (ic_gcov_type_ptr_var) = true;
-    }
-  else
-    {
-      ic_gcov_type_ptr_var
-       = build_decl (UNKNOWN_LOCATION, VAR_DECL,
-                     get_identifier (
-                             (PARAM_VALUE (PARAM_INDIR_CALL_TOPN_PROFILE) ?
-                              "__gcov_indirect_call_topn_counters" :
-                              "__gcov_indirect_call_counters")),
-                     gcov_type_ptr);
-      TREE_PUBLIC (ic_gcov_type_ptr_var) = 1;
-      DECL_EXTERNAL (ic_gcov_type_ptr_var) = 1;
-    }
+
+  ic_gcov_type_ptr_var
+    = build_decl (UNKNOWN_LOCATION, VAR_DECL,
+                 get_identifier (
+                         (PARAM_VALUE (PARAM_INDIR_CALL_TOPN_PROFILE) ?
+                          "__gcov_indirect_call_topn_counters" :
+                          "__gcov_indirect_call_counters")),
+                 gcov_type_ptr);
+  TREE_PUBLIC (ic_gcov_type_ptr_var) = 1;
+  DECL_EXTERNAL (ic_gcov_type_ptr_var) = 1;
   TREE_STATIC (ic_gcov_type_ptr_var) = 1;
   DECL_ARTIFICIAL (ic_gcov_type_ptr_var) = 1;
   DECL_INITIAL (ic_gcov_type_ptr_var) = NULL;
@@ -223,33 +188,18 @@ gimple_init_edge_profiler (void)
 
       init_ic_make_global_vars ();
 
-      /* Workaround for binutils bug 14342.  Once it is fixed, remove lto path.  */
-      if (flag_lto)
-        {
-         /* void (*) (gcov_type, void *)  */
-         ic_profiler_fn_type
-                  = build_function_type_list (void_type_node,
-                                             gcov_type_ptr, gcov_type_node,
-                                             ptr_void, ptr_void,
-                                             NULL_TREE);
-         tree_indirect_call_profiler_fn
-                 = build_fn_decl ("__gcov_indirect_call_profiler",
-                                        ic_profiler_fn_type);
-        }
-      else
-        {
-         /* void (*) (gcov_type, void *)  */
-         ic_profiler_fn_type
-                  = build_function_type_list (void_type_node,
-                                             gcov_type_node,
-                                             ptr_void,
-                                             NULL_TREE);
-         tree_indirect_call_profiler_fn
-                 = build_fn_decl ( (PARAM_VALUE (PARAM_INDIR_CALL_TOPN_PROFILE) ?
-                                    "__gcov_indirect_call_topn_profiler":
-                                    "__gcov_indirect_call_profiler_v2"),
-                                  ic_profiler_fn_type);
-        }
+      /* void (*) (gcov_type, void *)  */
+      ic_profiler_fn_type
+              = build_function_type_list (void_type_node,
+                                         gcov_type_node,
+                                         ptr_void,
+                                         NULL_TREE);
+      tree_indirect_call_profiler_fn
+             = build_fn_decl ( (PARAM_VALUE (PARAM_INDIR_CALL_TOPN_PROFILE) ?
+                                "__gcov_indirect_call_topn_profiler":
+                                "__gcov_indirect_call_profiler_v2"),
+                              ic_profiler_fn_type);
+
       TREE_NOTHROW (tree_indirect_call_profiler_fn) = 1;
       DECL_ATTRIBUTES (tree_indirect_call_profiler_fn)
        = tree_cons (get_identifier ("leaf"), NULL,
@@ -315,8 +265,8 @@ gimple_gen_edge_profiler (int edgeno, edge e)
   stmt1 = gimple_build_assign (gcov_type_tmp_var, ref);
   gcov_type_tmp_var = make_temp_ssa_name (gcov_type_node,
                                          NULL, "PROF_edge_counter");
-  stmt2 = gimple_build_assign_with_ops (PLUS_EXPR, gcov_type_tmp_var,
-                                       gimple_assign_lhs (stmt1), one);
+  stmt2 = gimple_build_assign (gcov_type_tmp_var, PLUS_EXPR,
+                              gimple_assign_lhs (stmt1), one);
   stmt3 = gimple_build_assign (unshare_expr (ref), gimple_assign_lhs (stmt2));
   gsi_insert_on_edge (e, stmt1);
   gsi_insert_on_edge (e, stmt2);
@@ -470,7 +420,8 @@ gimple_gen_ic_func_profiler (void)
     stmt1: __gcov_indirect_call_profiler_v2 (profile_id,
                                             &current_function_decl)
    */
-  gsi = gsi_after_labels (split_edge (single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun))));
+  gsi = gsi_after_labels (split_edge (single_succ_edge
+                                        (ENTRY_BLOCK_PTR_FOR_FN (cfun))));
 
   cur_func = force_gimple_operand_gsi (&gsi,
                                       build_addr (current_function_decl,
@@ -478,26 +429,10 @@ gimple_gen_ic_func_profiler (void)
                                       true, NULL_TREE,
                                       true, GSI_SAME_STMT);
   tree_uid = build_int_cst
-             (gcov_type_node, cgraph_node::get (current_function_decl)->profile_id);
-  /* Workaround for binutils bug 14342.  Once it is fixed, remove lto path.  */
-  if (flag_lto)
-    {
-      tree counter_ptr, ptr_var;
-      counter_ptr = force_gimple_operand_gsi (&gsi, ic_gcov_type_ptr_var,
-                                             true, NULL_TREE, true,
-                                             GSI_SAME_STMT);
-      ptr_var = force_gimple_operand_gsi (&gsi, ic_void_ptr_var,
-                                         true, NULL_TREE, true,
-                                         GSI_SAME_STMT);
-
-      stmt1 = gimple_build_call (tree_indirect_call_profiler_fn, 4,
-                                counter_ptr, tree_uid, cur_func, ptr_var);
-    }
-  else
-    {
-      stmt1 = gimple_build_call (tree_indirect_call_profiler_fn, 2,
-                                tree_uid, cur_func);
-    }
+             (gcov_type_node,
+              cgraph_node::get (current_function_decl)->profile_id);
+  stmt1 = gimple_build_call (tree_indirect_call_profiler_fn, 2,
+                            tree_uid, cur_func);
   gsi_insert_before (&gsi, stmt1, GSI_SAME_STMT);
 
   /* Set __gcov_indirect_call_callee to 0,