> This patch adds support to linker driven function reordering by creating 
> function sections with a prefix '.text.sorted' which are then sorted using 
> SORT in by the linker. Appropriate support for this is already present in 
> binutils.
> 
> Bootstrapped and regtested on aarch64-linux-gnu. Ok for mainline?
> 
> Thanks,
> Prachi
> 
> Signed-off-by: Prachi Godbole [email protected]
> 
> gcc/ChangeLog:
> 
>       * cgraph.cc (cgraph_node::dump): Dump value of text_locality_order.
>       * cgraph.h (struct cgraph_node): New variable text_locality_order.
>       * cgraphclones.cc (cgraph_node::create_clone): Initialize
>       text_locality_order.
>       * cgraphunit.cc (expand_all_functions): Update text_locality_order.
>       * ipa-locality-cloning.cc (get_default_locality_order): New function.
>       (add_node_to_partition): Update text_locality_order.
>       * lto-cgraph.cc (lto_output_node): Write text_locality_order to file.
>       (input_node): Read text_locality_order.
>       * varasm.cc (default_function_section): Create function sections based
>       on text_locality_order.
> 

> diff --git a/gcc/lto-cgraph.cc b/gcc/lto-cgraph.cc
> index 0af2e889af8..ecac2bb7c4a 100644
> --- a/gcc/lto-cgraph.cc
> +++ b/gcc/lto-cgraph.cc
> @@ -515,6 +515,7 @@ lto_output_node (struct lto_simple_output_block *ob, 
> struct cgraph_node *node,
> +  /* Unordered nodes have locality order of 0 and go to the appropriate text
> +     section the usual way.  */
> +  cgraph_node *node = cgraph_node::get (decl);
> +  if (node->text_locality_order != 0)
> +    {
> +      char section_name[64];
> +      if (node->text_locality_order > 0)
> +     sprintf (section_name, ".text.sorted.%010d", node->text_locality_order);
> +      else
> +     sprintf (section_name, ".text.unlikely");
Why do you have .text.unlikely here?  I do not see where locality_order
should be negative.
> +      return get_named_text_section (decl, section_name, NULL);
> +    }

We planned similar feature (using .text.sorted) already for time
profiling before LTO, so I thik you can use to_first_run and make it
output sorted sections.  This will help non-LTO builds with profile
feedback.

However with LTO we already make sure to output functions in right
order, so this will only break up bigger text section into multiple
.text.sorted.xxx which is ineffective by requiring more padding and
longer jumps.

If you use tp_first_run then functions will be output in order and you
should not need .text.sorted with LTO. Without LTO you can also check if
the two functions are consecutive and keep them in one sorted
subsection.

Honza

Reply via email to