- tree stmt = value->hvalue.stmt;
- block_stmt_iterator bsi = bsi_for_stmt (stmt);
- tree ref = tree_coverage_counter_ref (tag, base), ref_ptr;
- tree args, call, val;
-
- ref_ptr = force_gimple_operand_bsi (&bsi,
- build_addr (ref, current_function_decl),
- true, NULL_TREE);
- val = prepare_instrumented_value (&bsi, value);
- args = tree_cons (NULL_TREE, ref_ptr,
- tree_cons (NULL_TREE, val,
- NULL_TREE));
- call = build_function_call_expr (tree_one_value_profiler_fn, args);
- bsi_insert_before (&bsi, call, BSI_SAME_STMT);
+ gimple stmt = value->hvalue.stmt;
+ gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
+ tree ref_ptr = tree_coverage_counter_addr (tag, base);
+ gimple call;
+ tree val;
+
+ ref_ptr = force_gimple_operand_gsi (&gsi, ref_ptr,
+ true, NULL_TREE, true, GSI_SAME_STMT);
+ val = prepare_instrumented_value (&gsi, value);
+ call = gimple_build_call (tree_one_value_profiler_fn, 2, ref_ptr, val);
+ gsi_insert_before (&gsi, call, GSI_NEW_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. */
+
+void
+gimple_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_reg (ptr_void, "PROF");
+ stmt1 = gimple_build_assign (ic_gcov_type_ptr_var, ref_ptr);
+ stmt2 = gimple_build_assign (tmp1, unshare_expr (value->hvalue.value));
+ gimple_assign_set_lhs (stmt2, make_ssa_name (tmp1, stmt2));
+ stmt3 = gimple_build_assign (ic_void_ptr_var, gimple_assign_lhs (stmt2));
+
+ 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.
+ */
+
+void
+gimple_gen_ic_func_profiler (void)
+{
+ struct cgraph_node * c_node = cgraph_get_node (current_function_decl);
+ gimple_stmt_iterator gsi;
+ gimple stmt1, stmt2;
+ tree tree_uid, cur_func, counter_ptr, ptr_var, void0;
+
+ if (cgraph_only_called_directly_p (c_node))
+ return;
+
+ gimple_init_edge_profiler ();
+
+ gsi = gsi_after_labels (single_succ (ENTRY_BLOCK_PTR));
+
+ cur_func = force_gimple_operand_gsi (&gsi,
+ build_addr (current_function_decl,
+ current_function_decl),
+ true, NULL_TREE,
+ true, GSI_SAME_STMT);
+ 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);
+ tree_uid = build_int_cst (gcov_type_node, c_node->pid);
+ stmt1 = gimple_build_call (tree_indirect_call_profiler_fn, 4,
+ counter_ptr, tree_uid, cur_func, ptr_var);
+ gsi_insert_before (&gsi, stmt1, GSI_SAME_STMT);
+
+ /* 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_before (&gsi, stmt2, GSI_SAME_STMT);