Profile-guided optimization (PGO)

Johan Engelen via digitalmars-d-ldc digitalmars-d-ldc at puremagic.com
Sun Dec 13 05:59:03 PST 2015


On Sunday, 13 December 2015 at 13:21:33 UTC, David Nadlinger 
wrote:
>
> What is left to do before we can merge a first version into the 
> main repository? A partial list:
>
>  - Deal with the remaining FIXME comments (at least open 
> separate GitHub issues for them), as well as with commented-out 
> fragments from the Clang implementation.

Yep :-)  That's what the FIXME comments are there for: so I don't 
forget :-)
The plan is to deal with all FIXME's, and remove the unused 
commented-out Clang fragments.

>  - Find some way to avoid ICE-type regressions on real-world D 
> code, for example by building the druntime/Phobos unit tests 
> with instrumentation on.

I just fixed two more ICEs, and now the dmd-testsuite succeeds 
with -fprofile-instr-generate. Running the druntime/Phobos 
unittests now with -fprofile-instr-generate.

Also, I added a pragma(LDC_profile_instr, true|false) to 
enable/disable instrumentation codegen for specific functions. My 
main reason for this is to help people speed up instrumented 
binaries, and it also helps circumventing ICEs.
See tests/ir/profile/pragma.d.
(perhaps you think of a better name for the pragma)

>  - Decide on a name for the command line switches. The 
> GCC-style "-f" prefix isn't currently used for most of the 
> options, but that's not necessarily much of an argument.

I have absolutely no preference here. I think we should do what 
the world is already familiar with. Iirc, 
-fprofile-instr-generate is a Clang option, and that Clang is 
moving towards / will support GCC's option naming 
(-fprofile-generate, -fprofile-use).
DMD has a -profile option, but I have not read up on what that 
will do.
I guess we will not add any option for PGO to ldmd2?

> On a rather unrelated note, did you try whether the profile 
> data also gives sensible results with llvm-cov? If yes, that 
> might be something nice to mention in that upcoming 
> announcement, even though we also have DMD-style -cov support, 
> of course.

Did not look into this at all yet. Clang's PGOGen code has some 
extra functions for gcov support and more. It's all commented out 
for now, but it looks like we can support more tools relatively 
easily with the current implementation. I also see hints of 
sampling-based PGO in the code, for example.

Another important TODO item: remove the profiling runtime from 
druntime, and instead add a separate runtime-profiling lib 
(suggestions for a name?  ldc-profile.lib?).


More information about the digitalmars-d-ldc mailing list