This is an archive of the discontinued LLVM Phabricator instance.

[llvm-profdata] Handle internal linkage functions in profile supplementation
ClosedPublic

Authored by xur on Aug 24 2022, 1:36 PM.

Details

Summary

This patch has the following changes:
(1) Handling of internal linkage functions (static functions)
Static functions in FDO have a prefix of source file name, while they do not
have one in SampleFDO. Current implementation does not handle this and we are
not updating the profile for static functions. This patch fixes this.

(2) Handling of -funique-internal-linakge-symbols
Again this is for the internal linkage functions. Option
-funique-internal-linakge-symbols can now be applied to both FDO and SampleFDO
compilation. When it is used, it demangles internal linkage function names and
adds a hash value as the postfix.

When both SampleFDO and FDO profiles use this option, or both
not use this option, changes in (1) should handle this.

Here we also handle when the SampleFDO profile using this option while FDO
profile not using this option, or vice versa.

There is one case where this patch won't work: If one of the profiles used
mangled name and the other does not. For example, if the SampleFDO profile
uses clang c-compiler and without -funique-internal-linakge-symbols, while
the FDO profile uses -funique-internal-linakge-symbols. The SampleFDO profile
contains unmangled names while the FDO profile contains mangled names. If
both profiles use c++ compiler, this won't happen. We think this use case
is rare and does not justify the effort to fix.

Diff Detail

Event Timeline

xur created this revision.Aug 24 2022, 1:36 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 24 2022, 1:36 PM
Herald added a subscriber: wenlei. · View Herald Transcript
xur requested review of this revision.Aug 24 2022, 1:36 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 24 2022, 1:36 PM
davidxl added inline comments.Aug 24 2022, 9:25 PM
llvm/tools/llvm-profdata/llvm-profdata.cpp
612

define a macro for the marker string.

663

Skip to the next (using continue) when FS is not interesting (cold etc)

674

continue when Itr == end or when Itr is not cold

xur added inline comments.Aug 25 2022, 10:05 AM
llvm/tools/llvm-profdata/llvm-profdata.cpp
612

Will do.

663

OK.

674

Will change.

xur updated this revision to Diff 455640.Aug 25 2022, 10:29 AM

Integrated David's review commends.

davidxl added inline comments.Aug 25 2022, 10:50 AM
llvm/tools/llvm-profdata/llvm-profdata.cpp
566

no need for & for StringRef

xur updated this revision to Diff 455682.Aug 25 2022, 12:03 PM

Fixed unneeded &

davidxl accepted this revision.Aug 25 2022, 2:33 PM

lgtm

This revision is now accepted and ready to land.Aug 25 2022, 2:33 PM
tmsriram accepted this revision.Aug 25 2022, 2:49 PM
tmsriram added inline comments.
llvm/tools/llvm-profdata/llvm-profdata.cpp
591

Maybe rewrite this slightly as:

// If Sample Profile and Instrumented Profile do not agree on symbol uniqification.
if (SampleProfileHasFunique != ProfileHasFUnique) {

if (ProfileHasFUnique) {
   // trim
} else {
   // Build Map
}

}

xur added inline comments.Aug 26 2022, 12:26 AM
llvm/tools/llvm-profdata/llvm-profdata.cpp
591

Good point. I will change to this form.

xur updated this revision to Diff 455816.Aug 26 2022, 12:31 AM

Integrated Sriraman's suggestion.

This revision was landed with ongoing or failed builds.Aug 29 2022, 4:21 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptAug 29 2022, 4:21 PM