[LTO][AutoFDO] Can split ThinLTO and AutoFDO in two steps?

I can use ThinLTO and AutoFDO like this:
clang++ a.cpp -c -o a.o -flto=thin -fprofile-sample-use=a.prof
This can make a.o have the summary about import function and function coming from profile information.
My question is how to split this in two steps? It need llvm to write summary two times. Likes:
1.clang++ a.cpp -c -o a.o -flto=thin
2.clang++ a.o -c a.o.2 -flto=thin -fprofile-sample-use=a.prof

This should work but it looks like you have a couple issues on your second command line. It should be:

clang++ -x ir a.o -c -o a.o.2 -flto=thin -fprofile-sample-use=a.prof

Note the addition of the -o in front of a.o.2, and importantly, the “-x ir” in front of the IR input object. Otherwise clang thinks you are trying to do a link of the input object, and the “-x ir” tells it that the input type is LLVM IR and it will then run through the compilation pipeline.

You can try with “-Xclang -fdebug-pass-manager” to confirm that you get the ThinLTOBitcodeWriterPass as the last non-analysis pass in both compiles. I confirmed that this works (without -fprofile-sample use though on the second command line), and llvm-dis also shows the summary in both output IR objects.

Thank you, I used this command at start. Now I found it works when I use llvm13. But llvm12 will report error: fatal error: error in backend: Broken module found, compilation aborted!

Ah ok, no idea what the issue was on that older version of clang/llvm. I would recommend using newer versions if at all possible.