diff options
author | marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4> | 2013-12-17 22:20:12 +0000 |
---|---|---|
committer | marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4> | 2013-12-17 22:20:12 +0000 |
commit | af48f0b184090da9bd5bd5f959e2387385f92b8c (patch) | |
tree | 3ad29a01dabd9e49f49f9ebdc04f7655721d6300 /gcc/cgraphunit.c | |
parent | cf4f5d5e5a8bffc5c58b5dc64ac035adf9c98e1d (diff) | |
download | gcc-af48f0b184090da9bd5bd5f959e2387385f92b8c.tar.gz |
Time profile-based function reordering (phase 2).
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@206070 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cgraphunit.c')
-rw-r--r-- | gcc/cgraphunit.c | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c index 44f3afd6e4a..28f51162bba 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 |