Clang++ PGO: empty .profraw

2k views Asked by At


I'm asking for help for a problem with Clang Profile Guided Optimization. I'm using clang++-3.7, but the problem is still present with clang++-3.6.
If I try to do the PGO with a dummy code, everything's fine:

  • I compile with -fprofile-instr-generate:
    clang++ -o test -fprofile-instr-generate dummy.cpp
  • The executable "test", when launched, generates a default.profraw file
  • I can merge the profiles with llvm-profdata merge
  • At the end I can compile with the profiles integration, with -fprofile-instr-use on the .profdata
  • But with a bigger project there are some problems. I use a makefile and a script to automate the process, but this is the operations flow:

  • I compile the sources containing the classes creating the object files:
    clang++ -c --std=c++0x -O3 -flto -fprofile-instr-generate src/foo1.cpp -o obj/foo1.o
    clang++ -c --std=c++0x -O3 -flto -fprofile-instr-generate src/foo2.cpp -o obj/foo2.o
    clang++ -c --std=c++0x -O3 -flto -fprofile-instr-generate src/foo3.cpp -o obj/foo3.o
  • Then I link the objects:
    clang++ -O3 -flto -fprofile-instr-generate obj/foo1.o obj/foo2.o obj/foo3.o -o foobar.out
  • At this point there is the problem: when I try to execute foobar.out with the training instances, the .profraw generated is always empty (and the execution speed is normal, not slower as during the pgo creation), and when I try to compile with the profiles integration (after the merge of the .profraw files), the compiler always gives me the warning "warning: no profile data available for file foo*.cpp" for each foo*.cpp file in my project.

    Could anyone help me trying to understand where is the problem? Thank you in advance!

  • 1

    There are 1 answers

    0
    Markigno On BEST ANSWER

    Solved. The problem was that the profiles are generated only in case of a normal exit (return or exit), while in my code the main ended with _exit.