aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Li <davidxl@google.com>2013-02-06 06:39:27 +0000
committerDavid Li <davidxl@google.com>2013-02-06 06:39:27 +0000
commitb068dbdbac6a4017e6f664f819a2cbd2bd842a8a (patch)
tree67d56cbb97e0bc2490287e3b09fc5db962c350a4
parentc6b0e3e6bd6fe01bc8a8e6ae194a8cd813665a11 (diff)
Implement two parameters to control lipo profile-gen
runtime behavior: 1. --param=lipo-propagate-sccale=<scale_factor> 2. --param=lipo-dump-cgraph=<1|2> git-svn-id: https://gcc.gnu.org/svn/gcc/branches/google/gcc-4_7@195782 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/params.def14
-rw-r--r--gcc/tree-profile.c18
-rw-r--r--libgcc/dyn-ipa.c51
3 files changed, 72 insertions, 11 deletions
diff --git a/gcc/params.def b/gcc/params.def
index 2ea0a555961..436d51e06d8 100644
--- a/gcc/params.def
+++ b/gcc/params.def
@@ -990,6 +990,20 @@ DEFPARAM (PARAM_LIPO_RANDOM_GROUP_SIZE,
" no random grouping.",
0, 0, 300)
+/* In LIPO profile-gen, use this parameter to specify the scale factor to propagate
+ callee module groups to caller. */
+DEFPARAM (PARAM_LIPO_PROPAGATE_SCALE,
+ "lipo-propagate-scale",
+ "The scale factor to propagate callee module group's weight to the caller.",
+ 100, 0, 100)
+
+/* In LIPO profile-gen, use this parameter to enable cgraph dumping. */
+DEFPARAM (PARAM_LIPO_DUMP_CGRAPH,
+ "lipo-dump-cgraph",
+ "Default is 0. If the value is 1, text dump is used. If the value "
+ "is 2, .dot dump is enabled. ",
+ 0, 0, 2)
+
DEFPARAM (PARAM_PROFILE_GENERATE_SAMPLING_PERIOD,
"profile-generate-sampling-period",
"sampling rate with -fprofile-generate-sampling",
diff --git a/gcc/tree-profile.c b/gcc/tree-profile.c
index 5f637ec3e94..57957c57b1f 100644
--- a/gcc/tree-profile.c
+++ b/gcc/tree-profile.c
@@ -180,6 +180,12 @@ static tree GTY(()) gcov_lipo_random_seed_decl = NULL_TREE;
/* extern gcov_unsigned_t __gcov_lipo_random_group_size */
static tree GTY(()) gcov_lipo_random_group_size_decl = NULL_TREE;
+/* extern gcov_unsigned_t __gcov_lipo_propagate_scale */
+static tree GTY(()) gcov_lipo_propagate_scale_decl = NULL_TREE;
+
+/* extern gcov_unsigned_t __gcov_lipo_dump_cgraph */
+static tree GTY(()) gcov_lipo_dump_cgraph_decl = NULL_TREE;
+
/* Insert STMT_IF around given sequence of consecutive statements in the
same basic block starting with STMT_START, ending with STMT_END. */
@@ -336,6 +342,18 @@ tree_init_dyn_ipa_parameters (void)
get_identifier ("__gcov_lipo_random_group_size"),
get_gcov_unsigned_t ());
init_comdat_decl (gcov_lipo_random_group_size_decl, PARAM_LIPO_RANDOM_GROUP_SIZE);
+ gcov_lipo_propagate_scale_decl = build_decl (
+ UNKNOWN_LOCATION,
+ VAR_DECL,
+ get_identifier ("__gcov_lipo_propagate_scale"),
+ get_gcov_unsigned_t ());
+ init_comdat_decl (gcov_lipo_propagate_scale_decl, PARAM_LIPO_PROPAGATE_SCALE);
+ gcov_lipo_dump_cgraph_decl = build_decl (
+ UNKNOWN_LOCATION,
+ VAR_DECL,
+ get_identifier ("__gcov_lipo_dump_cgraph"),
+ get_gcov_unsigned_t ());
+ init_comdat_decl (gcov_lipo_dump_cgraph_decl, PARAM_LIPO_DUMP_CGRAPH);
}
}
diff --git a/libgcc/dyn-ipa.c b/libgcc/dyn-ipa.c
index 8d909529ff8..996b5958f28 100644
--- a/libgcc/dyn-ipa.c
+++ b/libgcc/dyn-ipa.c
@@ -98,6 +98,8 @@ struct dyn_pointer_set
extern gcov_unsigned_t __gcov_lipo_cutoff;
extern gcov_unsigned_t __gcov_lipo_random_seed;
extern gcov_unsigned_t __gcov_lipo_random_group_size;
+extern gcov_unsigned_t __gcov_lipo_propagate_scale;
+extern gcov_unsigned_t __gcov_lipo_dump_cgraph;
#if defined(inhibit_libc)
__gcov_build_callgraph (void) {}
@@ -109,6 +111,8 @@ static void gcov_dump_callgraph (gcov_type);
static void gcov_dump_cgraph_node_short (struct dyn_cgraph_node *node);
static void gcov_dump_cgraph_node (struct dyn_cgraph_node *node,
unsigned m, unsigned f);
+static int do_cgraph_dump (void);
+
static void
gcov_dump_cgraph_node_dot (struct dyn_cgraph_node *node,
unsigned m, unsigned f,
@@ -124,6 +128,30 @@ static struct dyn_cgraph the_dyn_call_graph;
static int total_zero_count = 0;
static int total_insane_count = 0;
+/* Returns 0 if no dump is enabled. Returns 1 if text form graph
+ dump is enabled. Returns 2 if .dot form dump is enabled. */
+
+static int
+do_cgraph_dump (void)
+{
+ const char *dyn_cgraph_dump = 0;
+
+ if (__gcov_lipo_dump_cgraph)
+ return __gcov_lipo_dump_cgraph;
+
+ dyn_cgraph_dump = getenv ("GCOV_DYN_CGRAPH_DUMP");
+
+ if (!dyn_cgraph_dump || !strlen (dyn_cgraph_dump))
+ return 0;
+
+ if (dyn_cgraph_dump[0] == '1')
+ return 1;
+ if (dyn_cgraph_dump[0] == '2')
+ return 2;
+
+ return 0;
+}
+
static void
init_dyn_cgraph_node (struct dyn_cgraph_node *node, gcov_type guid)
{
@@ -745,7 +773,7 @@ gcov_compute_cutoff_count (void)
total += edges[i]->count;
cum_cutoff = (total * cutoff_perc)/100;
- do_dump = (getenv ("GCOV_DYN_CGRAPH_DUMP") != 0);
+ do_dump = (do_cgraph_dump () != 0);
for (i = 0; i < num_edges; i++)
{
cum += edges[i]->count;
@@ -1029,15 +1057,16 @@ gcov_process_cgraph_node (struct dyn_cgraph_node *node,
/* Compute module grouping using CUTOFF_COUNT as the hot edge
threshold. */
-#define DEFAULT_IMPORT_SCALE 100
static void
gcov_compute_module_groups (gcov_type cutoff_count)
{
unsigned m_ix;
struct gcov_info *gi_ptr;
const char *import_scale_str;
- unsigned import_scale = DEFAULT_IMPORT_SCALE;
+ unsigned import_scale = __gcov_lipo_propagate_scale;
+ /* Different from __gcov_lipo_cutoff handling, the
+ environment variable here takes precedance */
import_scale_str = getenv ("GCOV_DYN_IMPORT_SCALE");
if (import_scale_str && strlen (import_scale_str))
import_scale = atoi (import_scale_str);
@@ -1261,7 +1290,7 @@ __gcov_compute_module_groups (void)
srandom (__gcov_lipo_random_seed);
init_dyn_call_graph ();
gcov_compute_random_module_groups (__gcov_lipo_random_group_size);
- if (getenv ("GCOV_DYN_CGRAPH_DUMP") != 0)
+ if (do_cgraph_dump () != 0)
{
fprintf (stderr, " Creating random grouping with %u:%u\n",
__gcov_lipo_random_seed, __gcov_lipo_random_group_size);
@@ -1275,7 +1304,7 @@ __gcov_compute_module_groups (void)
srandom (atoi (seed));
init_dyn_call_graph ();
gcov_compute_random_module_groups (atoi (max_group_size));
- if (getenv ("GCOV_DYN_CGRAPH_DUMP") != 0)
+ if (do_cgraph_dump () != 0)
{
fprintf (stderr, " Creating random grouping with %s:%s\n",
seed, max_group_size);
@@ -1407,12 +1436,12 @@ gcov_dump_callgraph (gcov_type cutoff_count)
{
struct gcov_info *gi_ptr;
unsigned m_ix;
- const char *dyn_cgraph_dump = 0;
-
- dyn_cgraph_dump = getenv ("GCOV_DYN_CGRAPH_DUMP");
+ int do_dump;
+
+ do_dump = do_cgraph_dump ();
- if (!dyn_cgraph_dump || !strlen (dyn_cgraph_dump))
- return;
+ if (do_dump == 0)
+ return;
fprintf (stderr,"digraph dyn_call_graph {\n");
fprintf (stderr,"node[shape=box]\nsize=\"11,8.5\"\n");
@@ -1437,7 +1466,7 @@ gcov_dump_callgraph (gcov_type cutoff_count)
if (!node->callees && !node->callers)
continue;
- if (dyn_cgraph_dump[0] == '1')
+ if (do_dump == 1)
gcov_dump_cgraph_node (node, m_ix, fi_ptr->ident);
else
gcov_dump_cgraph_node_dot (node, m_ix, fi_ptr->ident,