- 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);
- }
+ 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 ();
+
+ /* Insert code:
+
+ stmt1: __gcov_indirect_call_profiler (__gcov_indirect_call_counters,
+ current_function_funcdef_no,
+ ¤t_function_decl,
+ __gcov_indirect_call_callee);
+ */
+ 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, current_function_funcdef_no);
+ 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);