aboutsummaryrefslogtreecommitdiff
path: root/gcc/cgraphunit.c
diff options
context:
space:
mode:
authorMartin Liska <marxin.liska@gmail.com>2013-12-17 22:20:12 +0000
committerMartin Liska <marxin@gcc.gnu.org>2013-12-17 22:20:12 +0000
commit9cec31f43afbdb326fddbc144e9aea63986828e4 (patch)
tree3ad29a01dabd9e49f49f9ebdc04f7655721d6300 /gcc/cgraphunit.c
parent14407011d62da724e88ac0cb30390d3f8fda2b9f (diff)
downloadgcc-9cec31f43afbdb326fddbc144e9aea63986828e4.zip
gcc-9cec31f43afbdb326fddbc144e9aea63986828e4.tar.gz
gcc-9cec31f43afbdb326fddbc144e9aea63986828e4.tar.bz2
Time profile-based function reordering (phase 2).
Co-Authored-By: Jan Hubicka <jh@suse.cz> From-SVN: r206070
Diffstat (limited to 'gcc/cgraphunit.c')
-rw-r--r--gcc/cgraphunit.c40
1 files changed, 39 insertions, 1 deletions
diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c
index 44f3afd..28f5116 100644
--- a/gcc/cgraphunit.c
+++ b/gcc/cgraphunit.c
@@ -1831,6 +1831,23 @@ expand_function (struct cgraph_node *node)
ipa_remove_all_references (&node->ref_list);
}
+/* Node comparer that is responsible for the order that corresponds
+ to time when a function was launched for the first time. */
+
+static int
+node_cmp (const void *pa, const void *pb)
+{
+ const struct cgraph_node *a = *(const struct cgraph_node * const *) pa;
+ const struct cgraph_node *b = *(const struct cgraph_node * const *) pb;
+
+ /* Functions with time profile must be before these without profile. */
+ if (!a->tp_first_run || !b->tp_first_run)
+ return a->tp_first_run - b->tp_first_run;
+
+ return a->tp_first_run != b->tp_first_run
+ ? b->tp_first_run - a->tp_first_run
+ : b->order - a->order;
+}
/* Expand all functions that must be output.
@@ -1847,6 +1864,7 @@ expand_all_functions (void)
{
struct cgraph_node *node;
struct cgraph_node **order = XCNEWVEC (struct cgraph_node *, cgraph_n_nodes);
+ unsigned int expanded_func_count = 0, profiled_func_count = 0;
int order_pos, new_order_pos = 0;
int i;
@@ -1859,20 +1877,39 @@ expand_all_functions (void)
if (order[i]->process)
order[new_order_pos++] = order[i];
+ if (flag_profile_reorder_functions)
+ qsort (order, new_order_pos, sizeof (struct cgraph_node *), node_cmp);
+
for (i = new_order_pos - 1; i >= 0; i--)
{
node = order[i];
+
if (node->process)
{
+ expanded_func_count++;
+ if(node->tp_first_run)
+ profiled_func_count++;
+
+ if (cgraph_dump_file)
+ fprintf (cgraph_dump_file, "Time profile order in expand_all_functions:%s:%d\n", node->asm_name (), node->tp_first_run);
+
node->process = 0;
expand_function (node);
}
}
+
+ if (dump_file)
+ fprintf (dump_file, "Expanded functions with time profile (%s):%u/%u\n",
+ main_input_filename, profiled_func_count, expanded_func_count);
+
+ if (cgraph_dump_file && flag_profile_reorder_functions)
+ fprintf (cgraph_dump_file, "Expanded functions with time profile:%u/%u\n",
+ profiled_func_count, expanded_func_count);
+
cgraph_process_new_functions ();
free_gimplify_stack ();
free (order);
-
}
/* This is used to sort the node types by the cgraph order number. */
@@ -2194,6 +2231,7 @@ compile (void)
#endif
cgraph_state = CGRAPH_STATE_EXPANSION;
+
if (!flag_toplevel_reorder)
output_in_order ();
else