+ tree stmt = value->hvalue.stmt;
+ block_stmt_iterator bsi = bsi_for_stmt (stmt);
+ tree ref = tree_coverage_counter_ref (tag, base), ref_ptr;
+ tree call, val;
+
+ ref_ptr = force_gimple_operand_bsi (&bsi,
+ build_addr (ref, current_function_decl),
+ true, NULL_TREE, true, BSI_SAME_STMT);
+ val = prepare_instrumented_value (&bsi, value);
+ call = build_call_expr (tree_one_value_profiler_fn, 2, ref_ptr, val);
+ bsi_insert_before (&bsi, call, BSI_SAME_STMT);
+}
+
+
+/* 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, stmt1, stmt2, stmt3;
+ tree stmt = value->hvalue.stmt;
+ block_stmt_iterator bsi = bsi_for_stmt (stmt);
+ tree ref = tree_coverage_counter_ref (tag, base), ref_ptr;
+
+ ref_ptr = force_gimple_operand_bsi (&bsi,
+ build_addr (ref, current_function_decl),
+ true, NULL_TREE, true, BSI_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 = build_gimple_modify_stmt (ic_gcov_type_ptr_var, ref_ptr);
+ stmt2 = build_gimple_modify_stmt (tmp1, unshare_expr (value->hvalue.value));
+ stmt3 = build_gimple_modify_stmt (ic_void_ptr_var, tmp1);
+
+ bsi_insert_before (&bsi, stmt1, BSI_SAME_STMT);
+ bsi_insert_before (&bsi, stmt2, BSI_SAME_STMT);
+ bsi_insert_before (&bsi, stmt3, BSI_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);
+ block_stmt_iterator bsi;
+ edge e;
+ basic_block bb;
+ edge_iterator ei;
+ tree stmt1;
+ tree tree_uid, cur_func;
+
+ if (flag_unit_at_a_time)
+ {
+ if (!c_node->needed)
+ return;
+ }
+
+ tree_init_edge_profiler ();
+
+ FOR_EACH_EDGE (e, ei, ENTRY_BLOCK_PTR->succs)
+ {
+ bb = split_edge (e);
+ bsi = bsi_start (bb);
+ cur_func = force_gimple_operand_bsi (&bsi,
+ build_addr (current_function_decl,
+ current_function_decl),
+ true, NULL_TREE,
+ true, BSI_SAME_STMT);
+ tree_uid = build_int_cst (gcov_type_node, c_node->pid);
+ stmt1 = build_call_expr (tree_indirect_call_profiler_fn, 4,
+ ic_gcov_type_ptr_var,
+ tree_uid,
+ cur_func,
+ ic_void_ptr_var);
+ bsi_insert_after (&bsi, stmt1, BSI_NEW_STMT);
+ }