This is an archive of the discontinued LLVM Phabricator instance.

[SamplePGO] Fix callsite sample lookup to use dwarf names when dwarf linkage name isn't available.
ClosedPublic

Authored by hoy on Nov 1 2021, 12:24 PM.

Details

Summary

When linkage name isn't available in dwarf (ususally the case of C code), looking up callee samples should be based on the dwarf name instead of using an empty string.

Also fixing a test issue where using empty string to look up callee samples accidentally returns the correct samples because it is treated as indirect call.

Diff Detail

Event Timeline

hoy created this revision.Nov 1 2021, 12:24 PM
hoy requested review of this revision.Nov 1 2021, 12:24 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 1 2021, 12:24 PM
wenlei added inline comments.Nov 1 2021, 6:23 PM
llvm/lib/ProfileData/SampleProf.cpp
233–234

This is not NFC change because getCallSiteIdentifier has other call sites too other than the one from findFunctionSamples. Can we avoid this change and stick to linkage name fix only?

hoy added inline comments.Nov 1 2021, 6:26 PM
llvm/lib/ProfileData/SampleProf.cpp
233–234

I can make this a separate change. Still need the pseudo probe path in order for a probe-based nested profile to work.

wenlei added inline comments.Nov 1 2021, 6:40 PM
llvm/lib/ProfileData/SampleProf.cpp
233–234

Not sure if I understand, see the other comment.

253–254

What I meant is - can we just do this for now and avoid changes in getCallSiteIdentifier? If we want to fix FSAFDO, we can do it in a separate patch.

// Use C++ linkage name if possible.
StringRef Name = PrevDIL->getScope()->getSubprogram()->getLinkageName();
if (Name.empty())
    Name = PrevDIL->getScope()->getSubprogram()->getName();

S.push_back(
        std::make_pair(LineLocation(getOffset(DIL), Discriminator), Name));
hoy added inline comments.Nov 1 2021, 6:43 PM
llvm/lib/ProfileData/SampleProf.cpp
253–254

This looks good for this change. I was saying the getCallSiteIdentifier change is still needed to make probe-based nested profile work since the currently it only deals with line numbers in this function.

wenlei added inline comments.Nov 1 2021, 6:52 PM
llvm/lib/ProfileData/SampleProf.cpp
253–254

Are you saying change for getCallSiteIdentifier is needed for the linkage name issue with nested probe profile? But isn't there no change for FunctionSamples::ProfileIsProbeBased anyways inside getCallSiteIdentifier? Sorry I'm confused - I thought this patch is just for fixing linkage name issue as the description says, which is unrelated to nested probe profile.

hoy added inline comments.Nov 1 2021, 6:54 PM
llvm/lib/ProfileData/SampleProf.cpp
253–254

It's not needed for the linkage name issue. I'll make it a separate change to target probe-based nested profile. Sorry for the confusion.

hoy updated this revision to Diff 383941.Nov 1 2021, 6:55 PM

Dropping the getCallSiteIdentifier change.

wenlei accepted this revision.Nov 1 2021, 8:05 PM

lgtm, thanks.

This revision is now accepted and ready to land.Nov 1 2021, 8:05 PM
This revision was landed with ongoing or failed builds.Nov 1 2021, 9:24 PM
This revision was automatically updated to reflect the committed changes.