This is an archive of the discontinued LLVM Phabricator instance.

[FS-AFDO][llvm-profgen] Generate profile with FS-AFDO discriminator
ClosedPublic

Authored by wlei on Nov 5 2021, 10:12 AM.

Details

Summary

In order to support generating profile with FS discriminator, three kind of changes are done in llvm-profgen:

  1. Dissassemble .rodata section to check if FS discriminator var ('"llvm_fs_discriminator"') exists and set the corresponding flag in the binary.
  1. Change the discriminator decoding in getBaseDiscriminator and getDuplicationFactor.
  1. set true for FunctionSamples::ProfileIsFS to enable FS functionality in ProfileData.

Diff Detail

Event Timeline

wlei created this revision.Nov 5 2021, 10:12 AM
wlei requested review of this revision.Nov 5 2021, 10:12 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 5 2021, 10:12 AM
wlei edited the summary of this revision. (Show Details)Nov 5 2021, 10:27 AM
wlei added reviewers: xur, hoy, wenlei.
xur accepted this revision.Nov 23 2021, 11:27 AM

This looks good to me.

This revision is now accepted and ready to land.Nov 23 2021, 11:27 AM
wenlei added inline comments.Nov 23 2021, 5:04 PM
llvm/tools/llvm-profgen/ProfileGenerator.cpp
104–106

We don't support CS+FS right now, how about error out for now to prevent misuse?

llvm/tools/llvm-profgen/ProfileGenerator.h
41–55

In what scenario would use a IsFSD parameter different from the ProfileGeneratorBase::IsFSDiscriminator? Wondering if we could just omit the parameter and use IsFSDiscriminator directly inside.

57

nit: UseFSDiscriminator

wlei updated this revision to Diff 390413.Nov 29 2021, 10:47 AM
wlei edited the summary of this revision. (Show Details)

Addressing Wenlei's feedback.

wlei added a comment.Nov 29 2021, 10:48 AM

This looks good to me.

Thanks for reviewing this patch!

llvm/tools/llvm-profgen/ProfileGenerator.cpp
104–106

Good point!

llvm/tools/llvm-profgen/ProfileGenerator.h
41–55

Yeah, there is only one exception that calling getBaseDiscriminator to decode the discriminator for callsite in ProfiledBinary::getExpandedContext. It happens during unwinding where ProfileGeneratorBase::IsFSDiscriminator is not set yet.

57

Changed!

wenlei accepted this revision.Nov 29 2021, 7:39 PM

lgtm, thanks.

hoy added inline comments.Nov 29 2021, 8:52 PM
llvm/tools/llvm-profgen/ProfileGenerator.h
42

nit: please use full name ProfileGeneratorBase::UseFSDiscriminator for static fields.

Also, can we check Binary->useFSDiscriminator() instead of parsing in an parameter?

wlei updated this revision to Diff 390840.Nov 30 2021, 3:34 PM

addressing Hongtao's feedback

llvm/tools/llvm-profgen/ProfileGenerator.h
42

nit: please use full name ProfileGeneratorBase::UseFSDiscriminator for static fields.

Fixed, thanks!

Also, can we check Binary->useFSDiscriminator() instead of parsing in an parameter?

There is one exception that calling getBaseDiscriminator in ProfiledBinary::getExpandedContext where we don't have the ProfileGenerator instance, so that needs to make it static.

see the below code:

Frame.Location.Discriminator = ProfileGeneratorBase::getBaseDiscriminator(
    Frame.Location.Discriminator, UseFSDiscriminator);
hoy accepted this revision.Nov 30 2021, 3:40 PM
hoy added inline comments.
llvm/tools/llvm-profgen/ProfileGenerator.h
42

I see. Thanks for pointing it out.

This revision was landed with ongoing or failed builds.Nov 30 2021, 3:59 PM
This revision was automatically updated to reflect the committed changes.