+
+/* Output instructions as GIMPLE trees for code to find the most
+ common called function in indirect call.
+ VALUE is the call expression whose indirect callee is profiled.
+ TAG is the tag of the section for counters, BASE is offset of the
+ counter position. */
+
+static void
+tree_gen_ic_profiler (histogram_value value, unsigned tag, unsigned base)
+{
+ tree tmp1;
+ gimple stmt1, stmt2, stmt3;
+ gimple stmt = value->hvalue.stmt;
+ gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
+ tree ref_ptr = tree_coverage_counter_addr (tag, base);
+
+ ref_ptr = force_gimple_operand_gsi (&gsi, ref_ptr,
+ true, NULL_TREE, true, GSI_SAME_STMT);
+
+ /* Insert code:
+
+ __gcov_indirect_call_counters = get_relevant_counter_ptr ();
+ __gcov_indirect_call_callee = (void *) indirect call argument;
+ */
+
+ tmp1 = create_tmp_var (ptr_void, "PROF");
+ stmt1 = gimple_build_assign (ic_gcov_type_ptr_var, ref_ptr);
+ stmt2 = gimple_build_assign (tmp1, unshare_expr (value->hvalue.value));
+ stmt3 = gimple_build_assign (ic_void_ptr_var, tmp1);
+
+ gsi_insert_before (&gsi, stmt1, GSI_SAME_STMT);
+ gsi_insert_before (&gsi, stmt2, GSI_SAME_STMT);
+ gsi_insert_before (&gsi, stmt3, GSI_SAME_STMT);
+}
+
+
+/* Output instructions as GIMPLE trees for code to find the most
+ common called function in indirect call. Insert instructions at the
+ beginning of every possible called function.
+ */
+
+static void
+tree_gen_ic_func_profiler (void)
+{
+ struct cgraph_node * c_node = cgraph_node (current_function_decl);
+ gimple_stmt_iterator gsi;
+ edge e;
+ basic_block bb;
+ edge_iterator ei;
+ gimple stmt1, stmt2;
+ tree tree_uid, cur_func;
+
+ if (!c_node->needed)
+ return;
+
+ tree_init_edge_profiler ();
+
+ FOR_EACH_EDGE (e, ei, ENTRY_BLOCK_PTR->succs)
+ {
+ tree void0;
+
+ bb = split_edge (e);
+ gsi = gsi_start_bb (bb);
+
+ cur_func = force_gimple_operand_gsi (&gsi,
+ build_addr (current_function_decl,
+ current_function_decl),
+ true, NULL_TREE,
+ true, GSI_SAME_STMT);
+ tree_uid = build_int_cst (gcov_type_node, c_node->pid);
+ stmt1 = gimple_build_call (tree_indirect_call_profiler_fn, 4,
+ ic_gcov_type_ptr_var,
+ tree_uid,
+ cur_func,
+ ic_void_ptr_var);
+ gsi_insert_after (&gsi, stmt1, GSI_NEW_STMT);
+ gcc_assert (EDGE_COUNT (bb->succs) == 1);
+ bb = split_edge (EDGE_I (bb->succs, 0));
+ add_abnormal_goto_call_edges (gsi);
+
+ gsi = gsi_start_bb (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 = gimple_build_assign (ic_void_ptr_var, void0);
+ gsi_insert_after (&gsi, stmt2, GSI_NEW_STMT);
+ }
+}
+
+/* Output instructions as GIMPLE trees for code to find the most common value