+2011-04-21 Xinliang David Li <davidxl@google.com>
+
+ * cgraph.h: Remove pid.
+ * cgraph.c: Remove pid.
+ * value-prof.c (init_node_map): New function.
+ (del_node_map): New function.
+ (find_func_by_funcdef_no): New function.
+ (gimple_ic_transform): Call new function.
+ * cgraphunit.c (cgraph_finalize_function): Remove pid.
+ * function.c (get_last_funcdef_no): New function.
+ * function.h (get_last_funcdef_no): New function.
+ * tree-profile.c (gimple_gen_ic_func_profiler): Pass funcdef_no
+ to libgcov function.
+ (tree-profiling): Call node map init and delete function.
+
2011-04-21 Ian Lance Taylor <iant@google.com>
* godump.c (go_format_type): Use exported Go name for anonymous
/* Maximal uid used in cgraph edges. */
int cgraph_edge_max_uid;
-/* Maximal pid used for profiling */
-int cgraph_max_pid;
-
/* Set when whole unit has been analyzed so we can access global info. */
bool cgraph_global_info_ready = false;
struct cgraph_node *node = cgraph_allocate_node ();
node->next = cgraph_nodes;
- node->pid = -1;
node->order = cgraph_order++;
if (cgraph_nodes)
cgraph_nodes->previous = node;
struct cgraph_edge *edge;
int indirect_calls_count = 0;
- fprintf (f, "%s/%i(%i)", cgraph_node_name (node), node->uid,
- node->pid);
+ fprintf (f, "%s/%i", cgraph_node_name (node), node->uid);
dump_addr (f, " @", (void *)node);
if (DECL_ASSEMBLER_NAME_SET_P (node->decl))
fprintf (f, " (asm: %s)", IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (node->decl)));
/* Ordering of all cgraph nodes. */
int order;
- /* unique id for profiling. pid is not suitable because of different
- number of cfg nodes with -fprofile-generate and -fprofile-use */
- int pid;
enum ld_plugin_symbol_resolution resolution;
/* Set when function must be output for some reason. The primary
extern GTY(()) int cgraph_n_nodes;
extern GTY(()) int cgraph_max_uid;
extern GTY(()) int cgraph_edge_max_uid;
-extern GTY(()) int cgraph_max_pid;
extern bool cgraph_global_info_ready;
enum cgraph_state
{
void compute_inline_parameters (struct cgraph_node *);
cgraph_inline_failed_t cgraph_edge_inlinable_p (struct cgraph_edge *);
-
/* Create a new static variable of type TYPE. */
tree add_new_static_var (tree type);
if (node->local.finalized)
cgraph_reset_node (node);
- node->pid = cgraph_max_pid ++;
notice_global_symbol (decl);
node->local.finalized = true;
node->lowered = DECL_STRUCT_FUNCTION (decl)->cfg != NULL;
return funcdef_no++;
}
+/* Return value of funcdef. */
+int
+get_last_funcdef_no (void)
+{
+ return funcdef_no;
+}
+
/* Allocate a function structure for FNDECL and set its contents
to the defaults. Set cfun to the newly-allocated object.
Some of the helper functions invoked during initialization assume
extern void used_types_insert (tree);
extern int get_next_funcdef_no (void);
+extern int get_last_funcdef_no (void);
/* In predict.c */
extern bool optimize_function_for_size_p (struct function *);
extern gcov_type sum_edge_counts (VEC (edge, gc) *edges);
+extern void init_node_map (void);
+extern void del_node_map (void);
+
#endif /* PROFILE_H */
#include "timevar.h"
#include "value-prof.h"
#include "cgraph.h"
+#include "profile.h"
static GTY(()) tree gcov_type_node;
static GTY(()) tree gcov_type_tmp_var;
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);
+ 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);
if (cgraph_state == CGRAPH_STATE_FINISHED)
return 0;
+ init_node_map();
+
for (node = cgraph_nodes; node; node = node->next)
{
if (!node->analyzed
pop_cfun ();
}
+ del_node_map();
return 0;
}
#include "timevar.h"
#include "tree-pass.h"
#include "pointer-set.h"
+#include "profile.h"
/* In this file value profile based optimizations are placed. Currently the
following optimizations are implemented (for more detailed descriptions
return true;
}
-static struct cgraph_node** pid_map = NULL;
+static VEC(cgraph_node_ptr, heap) *cgraph_node_map = NULL;
-/* Initialize map of pids (pid -> cgraph node) */
+/* Initialize map from FUNCDEF_NO to CGRAPH_NODE. */
-static void
-init_pid_map (void)
+void
+init_node_map (void)
{
struct cgraph_node *n;
- if (pid_map != NULL)
- return;
-
- pid_map = XCNEWVEC (struct cgraph_node*, cgraph_max_pid);
+ if (get_last_funcdef_no ())
+ VEC_safe_grow_cleared (cgraph_node_ptr, heap,
+ cgraph_node_map, get_last_funcdef_no ());
for (n = cgraph_nodes; n; n = n->next)
{
- if (n->pid != -1)
- pid_map [n->pid] = n;
+ if (DECL_STRUCT_FUNCTION (n->decl))
+ VEC_replace (cgraph_node_ptr, cgraph_node_map,
+ DECL_STRUCT_FUNCTION (n->decl)->funcdef_no, n);
}
}
+/* Delete the CGRAPH_NODE_MAP. */
+
+void
+del_node_map (void)
+{
+ VEC_free (cgraph_node_ptr, heap, cgraph_node_map);
+ cgraph_node_map = NULL;
+}
+
/* Return cgraph node for function with pid */
static inline struct cgraph_node*
-find_func_by_pid (int pid)
+find_func_by_funcdef_no (int func_id)
{
- init_pid_map ();
+ int max_id = get_last_funcdef_no ();
+ if (func_id >= max_id || VEC_index (cgraph_node_ptr,
+ cgraph_node_map,
+ func_id) == NULL)
+ {
+ if (flag_profile_correction)
+ inform (DECL_SOURCE_LOCATION (current_function_decl),
+ "Inconsistent profile: indirect call target (%d) does not exist", func_id);
+ else
+ error ("Inconsistent profile: indirect call target (%d) does not exist", func_id);
+
+ return NULL;
+ }
- return pid_map [pid];
+ return VEC_index (cgraph_node_ptr, cgraph_node_map, func_id);
}
/* Perform sanity check on the indirect call target. Due to race conditions,
prob = (count * REG_BR_PROB_BASE + all / 2) / all;
else
prob = 0;
- direct_call = find_func_by_pid ((int)val);
+ direct_call = find_func_by_funcdef_no ((int)val);
if (direct_call == NULL)
return false;