profile-driven optimization and the linker?

Dan Kegel dank@kegel.com
Fri Nov 26 05:08:00 GMT 2004


Jeffrey A Law wrote:
> On Thu, 2004-11-25 at 11:59 -0800, Dan 
>>>>http://gcc.gnu.org/news/profiledriven.html doesn't mention
>>>>having ld reorder sections to improve locality of reference
>>>>of frequently called functions.    Has that technique
>>>>been tried with gcc and binutils?
>>>
>>>Yes.  I had some success with it a while back.  ...
> 
> I believe we put all the code into gprof, though I haven't followed
> it over time and it may have been removed.
> 
> Basically there was two pieces to gprof.  The first within gprof
> itself to produce an ordering of functions.  That code will
> probably need to be rewritten (I never liked the way I did it
> and I never got the coalescing of information step done).
> 
> The second piece was a simple shell script which took the ordering
> produced by gprof and created a linker script.  Nothing too radical
> here.
> ...
> We were primarily measuring TLB effects with ours -- page locality
> for disk access falls out from the obvious algorithms.  Though IIRC
> we actually did better by first removing all the single call nodes
> from the graph and putting them into one contigious region, then
> applying the greedy algorithm on the rest of the call graph.

Hey, looks like it might still be there in current gprof.
(The grope paper describes your algorithm, btw.)

Here are the gprof options from the doc:

--function-ordering
     The `--function-ordering' option causes gprof to print a suggested function ordering for the program based on profiling data. This option suggests an ordering which may improve paging, tlb and cache behavior for the program on systems 
which support arbitrary ordering of functions in an executable. The exact details of how to force the linker to place functions in a particular order is system dependent and out of the scope of this manual.
--file-ordering map_file
     The `--file-ordering' option causes gprof to print a suggested .o link line ordering for the program based on profiling data. This option suggests an ordering which may improve paging, tlb and cache behavior for the program on systems 
which do not support arbitrary ordering of functions in an executable. Use of the `-a' argument is highly recommended with this option. The map_file argument is a pathname to a file which provides function name to object file mappings. The 
format of the file is similar to the output of the program nm.

c-parse.o:00000000 T yyparse
c-parse.o:00000004 C yyerrflag
c-lang.o:00000000 T maybe_objc_method_name
c-lang.o:00000000 T print_lang_statistics
c-lang.o:00000000 T recognize_objc_keyword
c-decl.o:00000000 T print_lang_identifier
c-decl.o:00000000 T print_lang_type
...
     GNU nm `--extern-only' `--defined-only' `-v' `--print-file-name' can be used to create map_file.

Sounds like it ought to be easy to try.

Thanks,
Dan

-- 
Trying to get a job as a c++ developer?  See http://kegel.com/academy/getting-hired.html



More information about the Gcc mailing list