-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[PseudoProbe] Fix cleanup for pseudo probe after annotation #119660
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -529,7 +529,7 @@ class SampleProfileLoader final : public SampleProfileLoaderBaseImpl<Function> { | |
void generateMDProfMetadata(Function &F); | ||
bool rejectHighStalenessProfile(Module &M, ProfileSummaryInfo *PSI, | ||
const SampleProfileMap &Profiles); | ||
void removePseudoProbeInsts(Module &M); | ||
void removePseudoProbeInstsDiscriminator(Module &M); | ||
|
||
/// Map from function name to Function *. Used to find the function from | ||
/// the function name. If the function name contains suffix, additional | ||
|
@@ -2138,13 +2138,25 @@ bool SampleProfileLoader::rejectHighStalenessProfile( | |
return false; | ||
} | ||
|
||
void SampleProfileLoader::removePseudoProbeInsts(Module &M) { | ||
void SampleProfileLoader::removePseudoProbeInstsDiscriminator(Module &M) { | ||
for (auto &F : M) { | ||
std::vector<Instruction *> InstsToDel; | ||
for (auto &BB : F) { | ||
for (auto &I : BB) { | ||
if (isa<PseudoProbeInst>(&I)) | ||
InstsToDel.push_back(&I); | ||
else if (isa<CallBase>(&I)) | ||
if (const DILocation *DIL = I.getDebugLoc().get()) { | ||
// Restore dwarf discriminator for call. | ||
unsigned Discriminator = DIL->getDiscriminator(); | ||
if (DILocation::isPseudoProbeDiscriminator(Discriminator)) { | ||
std::optional<uint32_t> DwarfDiscriminator = | ||
PseudoProbeDwarfDiscriminator::extractDwarfBaseDiscriminator( | ||
Discriminator); | ||
I.setDebugLoc(DIL->cloneWithDiscriminator( | ||
DwarfDiscriminator ? *DwarfDiscriminator : 0)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is zero discriminator same effect as no discriminator in DILexicalBlockFile? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think so, looks the encoding https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/IR/DebugInfoMetadata.h#L2101 0 means all the components are empty. |
||
} | ||
} | ||
} | ||
} | ||
for (auto *I : InstsToDel) | ||
|
@@ -2224,8 +2236,12 @@ bool SampleProfileLoader::runOnModule(Module &M, ModuleAnalysisManager *AM, | |
notInlinedCallInfo) | ||
updateProfileCallee(pair.first, pair.second.entryCount); | ||
|
||
if (RemoveProbeAfterProfileAnnotation && FunctionSamples::ProfileIsProbeBased) | ||
removePseudoProbeInsts(M); | ||
if (RemoveProbeAfterProfileAnnotation && | ||
FunctionSamples::ProfileIsProbeBased) { | ||
removePseudoProbeInstsDiscriminator(M); | ||
if (auto *FuncInfo = M.getNamedMetadata(PseudoProbeDescMetadataName)) | ||
M.eraseNamedMetadata(FuncInfo); | ||
} | ||
|
||
return retval; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A friendly caveat: this is still not the original DwarfBaseDiscriminator, it's only keep 3 bits(#94506), though it can cover most of the cases(95%+), just not the exact same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I noticed it.