This is an archive of the discontinued LLVM Phabricator instance.

[llvm] Intoduce llvm-orderfile
Needs ReviewPublic

Authored by serge-sans-paille on Jun 12 2023, 9:13 AM.

Details

Reviewers
davidxl
ellis
Summary

This tool is solely meant to decypher the output of

clang -forder-file-instrumentation -mllvm -orderfile-write-mapping=mapping

Which is meant to be used to generate order file but used an
undocumented (yet simple!) format.

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptJun 12 2023, 9:13 AM
serge-sans-paille requested review of this revision.Jun 12 2023, 9:13 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 12 2023, 9:13 AM

@reviewers: I plan to add documentation once the core is validated :-)

serge-sans-paille retitled this revision from [llvm] Intoduce llvm-orderfil to [llvm] Intoduce llvm-orderfile.Jun 13 2023, 1:43 AM

With the new ordering feature in place, do we need further development on this?

ellis added a comment.Jun 13 2023, 9:14 PM

I'm happy to see that there is interest in order files! Recently, I've been developing order file generation within IRPGO that is understood by the llvm-profdata tool. In short, you can instrument a binary to get function traces, merge them into a profile, and then use the llvm-profdata tool to compute a function order which you can pass to the linker using -symbol-ordering-file.

$ clang -fprofile-generate -mllvm -pgo-temporal-instrumentation main.cpp
$ ./a.out
$ llvm-profdata merge default.profraw -o default.profdata
$ llvm-profdata order default.profdata -o order.txt

Please see https://discourse.llvm.org/t/rfc-temporal-profiling-extension-for-irpgo/68068 for details on that.

When combined with Lightweight Instrumentation, this is more lightweight (at runtime), has better infra support, has more features, and should give better performance than -forder-file-instrumentation. In fact, I plan to deprecate -forder-file-instrumentation now that the initial work on temporal instrumentation is done.

Please don't hesitate to reach out on discord or discourse if you have questions :)

I'm happy to see that there is interest in order files! Recently, I've been developing order file generation within IRPGO that is understood by the llvm-profdata tool. In short, you can instrument a binary to get function traces, merge them into a profile, and then use the llvm-profdata tool to compute a function order which you can pass to the linker using -symbol-ordering-file.

$ clang -fprofile-generate -mllvm -pgo-temporal-instrumentation main.cpp
$ ./a.out
$ llvm-profdata merge default.profraw -o default.profdata
$ llvm-profdata order default.profdata -o order.txt

Please see https://discourse.llvm.org/t/rfc-temporal-profiling-extension-for-irpgo/68068 for details on that.

When combined with Lightweight Instrumentation, this is more lightweight (at runtime), has better infra support, has more features, and should give better performance than -forder-file-instrumentation. In fact, I plan to deprecate -forder-file-instrumentation now that the initial work on temporal instrumentation is done.

Please don't hesitate to reach out on discord or discourse if you have questions :)

Great news! Easier integration is a big plus for me, I definitively don't mind moving to this approach if we plan to obsolete -forder-file-instrumentation. One question though: from a user perspective, it would be great to have the ordering be transparent for the user so that any PGO build (with temporal instrumentation) would benefit from it. Does that make sense to you?

ellis added a comment.Jun 15 2023, 8:08 AM

I'm happy to see that there is interest in order files! Recently, I've been developing order file generation within IRPGO that is understood by the llvm-profdata tool. In short, you can instrument a binary to get function traces, merge them into a profile, and then use the llvm-profdata tool to compute a function order which you can pass to the linker using -symbol-ordering-file.

$ clang -fprofile-generate -mllvm -pgo-temporal-instrumentation main.cpp
$ ./a.out
$ llvm-profdata merge default.profraw -o default.profdata
$ llvm-profdata order default.profdata -o order.txt

Please see https://discourse.llvm.org/t/rfc-temporal-profiling-extension-for-irpgo/68068 for details on that.

When combined with Lightweight Instrumentation, this is more lightweight (at runtime), has better infra support, has more features, and should give better performance than -forder-file-instrumentation. In fact, I plan to deprecate -forder-file-instrumentation now that the initial work on temporal instrumentation is done.

Please don't hesitate to reach out on discord or discourse if you have questions :)

Great news! Easier integration is a big plus for me, I definitively don't mind moving to this approach if we plan to obsolete -forder-file-instrumentation. One question though: from a user perspective, it would be great to have the ordering be transparent for the user so that any PGO build (with temporal instrumentation) would benefit from it. Does that make sense to you?

I'm not exactly sure what you mean. Right now we need to manually pass the order file to the linker via -symbol-ordering-file, but eventually I'd like this to happen automatically when you pass the profile to the compiler via -fprofile-use=default.profdata.