This is an archive of the discontinued LLVM Phabricator instance.

[PGO] Don't reference functions unless value profiling is enabled
ClosedPublic

Authored by rnk on May 19 2021, 6:18 PM.

Details

Summary

This reduces the size of chrome.dll.pdb built with optimizations,
coverage, and line table info from 4,690,210,816 to 2,181,128,192, which
makes it possible to fit under the 4GB limit.

This change can greatly reduce binary size in coverage builds, which do
not need value profiling. IR PGO builds are unaffected. There is a minor
behavior change for frontend PGO.

PGO and coverage both use InstrProfiling to create profile data with
counters. PGO records the address of each function in the __profd_
global. It is used later to map runtime function pointer values back to
source-level function names. Coverage does not appear to use this
information.

Recording the address of every function with code coverage drastically
increases code size. Consider this program:

void foo();
void bar();
inline void inlineMe(int x) {
  if (x > 0)
    foo();
  else
    bar();
}
int getVal();
int main() { inlineMe(getVal()); }

With code coverage, the InstrProfiling pass runs before inlining, and it
captures the address of inlineMe in the __profd_ global. This greatly
increases code size, because now the compiler can no longer delete
trivial code.

One downside to this approach is that users of frontend PGO must apply
the -mllvm -enable-value-profiling flag globally in TUs that enable PGO.
Otherwise, some inline virtual method addresses may not be recorded and
will not be able to be promoted. My assumption is that this mllvm flag
is not popular, and most frontend PGO users don't enable it.

Diff Detail

Unit TestsFailed

Event Timeline

rnk created this revision.May 19 2021, 6:18 PM
rnk requested review of this revision.May 19 2021, 6:18 PM
Herald added projects: Restricted Project, Restricted Project, Restricted Project. · View Herald TranscriptMay 19 2021, 6:18 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript
davidxl accepted this revision.May 19 2021, 9:24 PM

lgtm (value profiling is off by default for FE PGO anyway)

This revision is now accepted and ready to land.May 19 2021, 9:24 PM

Thanks! I'll wait to see if I can get an ack from the Apple folks who indicated that they are using frontend PGO.

vsk accepted this revision.May 20 2021, 9:53 AM

Thanks, lgtm as well. On Darwin, the __llvm_prf_data section is marked with S_ATTR_LIVE_SUPPORT to allow the linker to dead strip functions even if they are pointed-to by a profd global. Removing the reference altogether should yield even better size benefits.

This revision was landed with ongoing or failed builds.May 20 2021, 11:09 AM
This revision was automatically updated to reflect the committed changes.