This is an archive of the discontinued LLVM Phabricator instance.

[InstrProf] Add option to avoid instrumenting small functions
ClosedPublic

Authored by ellis on Aug 12 2022, 4:06 PM.

Details

Summary

If a function only has a few instructions, instrumentation can significantly increase the size and performance overhead of that function. Add the -pgo-function-size-threshold option to select a size threshold so these small functions are not instrumented.

A similar option -fxray-instruction-threshold=<N> is used for XRay to reduce binary size overhead [1].

[1] https://www.llvm.org/docs/XRay.html

Diff Detail

Event Timeline

ellis created this revision.Aug 12 2022, 4:06 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 12 2022, 4:06 PM
ellis edited the summary of this revision. (Show Details)Aug 12 2022, 4:24 PM
ellis added reviewers: phosek, davidxl, MaskRay.
ellis published this revision for review.Aug 12 2022, 4:34 PM

I originally wanted to check this threshold in clang and add the skipprofile attribute for small functions. Unfortunately, clang doesn't have a good idea of how small functions are, i.e., how many instructions they have, before codegen and before optimizations. Of course, the number of IR instructions does not map directly to the size of the assembly function, but this is the best we can do since this is when we are injecting instrumentation.

Herald added a project: Restricted Project. · View Herald TranscriptAug 12 2022, 4:34 PM
MaskRay accepted this revision.Aug 13 2022, 6:24 PM

LGTM. Please wait a bit for others' opinions.

llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
297

The convention is to omit the period for help messages. Just ignore a few options in this file which do not stick with the convention.

llvm/test/Transforms/PGOProfile/function_size_threshold.ll
8

CHECK-LABEL

15

CHECK-LABEL

This revision is now accepted and ready to land.Aug 13 2022, 6:24 PM
ellis added inline comments.Aug 15 2022, 8:48 AM
llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
297

Thanks!

I think you’ve helped me with opt<> before, e.g., to omit cl::init(0). Is there some guide that describes the defaults and the conversions for this? Maybe we could add it to the programmers manual?

https://www.llvm.org/docs/ProgrammersManual.html

ellis updated this revision to Diff 453273.Aug 17 2022, 6:45 AM

Resolve comments

This revision was landed with ongoing or failed builds.Aug 17 2022, 6:47 AM
This revision was automatically updated to reflect the committed changes.