@@ -527,7 +527,7 @@ class SampleProfileLoader final : public SampleProfileLoaderBaseImpl<Function> {
527
527
void generateMDProfMetadata (Function &F);
528
528
bool rejectHighStalenessProfile (Module &M, ProfileSummaryInfo *PSI,
529
529
const SampleProfileMap &Profiles);
530
- void removePseudoProbeInsts (Module &M);
530
+ void removePseudoProbeInstsDiscriminator (Module &M);
531
531
532
532
// / Map from function name to Function *. Used to find the function from
533
533
// / the function name. If the function name contains suffix, additional
@@ -2125,13 +2125,25 @@ bool SampleProfileLoader::rejectHighStalenessProfile(
2125
2125
return false ;
2126
2126
}
2127
2127
2128
- void SampleProfileLoader::removePseudoProbeInsts (Module &M) {
2128
+ void SampleProfileLoader::removePseudoProbeInstsDiscriminator (Module &M) {
2129
2129
for (auto &F : M) {
2130
2130
std::vector<Instruction *> InstsToDel;
2131
2131
for (auto &BB : F) {
2132
2132
for (auto &I : BB) {
2133
2133
if (isa<PseudoProbeInst>(&I))
2134
2134
InstsToDel.push_back (&I);
2135
+ else if (isa<CallBase>(&I))
2136
+ if (const DILocation *DIL = I.getDebugLoc ().get ()) {
2137
+ // Restore dwarf discriminator for call.
2138
+ unsigned Discriminator = DIL->getDiscriminator ();
2139
+ if (DILocation::isPseudoProbeDiscriminator (Discriminator)) {
2140
+ std::optional<uint32_t > DwarfDiscriminator =
2141
+ PseudoProbeDwarfDiscriminator::extractDwarfBaseDiscriminator (
2142
+ Discriminator);
2143
+ I.setDebugLoc (DIL->cloneWithDiscriminator (
2144
+ DwarfDiscriminator ? *DwarfDiscriminator : 0 ));
2145
+ }
2146
+ }
2135
2147
}
2136
2148
}
2137
2149
for (auto *I : InstsToDel)
@@ -2211,8 +2223,12 @@ bool SampleProfileLoader::runOnModule(Module &M, ModuleAnalysisManager *AM,
2211
2223
notInlinedCallInfo)
2212
2224
updateProfileCallee (pair.first , pair.second .entryCount );
2213
2225
2214
- if (RemoveProbeAfterProfileAnnotation && FunctionSamples::ProfileIsProbeBased)
2215
- removePseudoProbeInsts (M);
2226
+ if (RemoveProbeAfterProfileAnnotation &&
2227
+ FunctionSamples::ProfileIsProbeBased) {
2228
+ removePseudoProbeInstsDiscriminator (M);
2229
+ if (auto *FuncInfo = M.getNamedMetadata (PseudoProbeDescMetadataName))
2230
+ M.eraseNamedMetadata (FuncInfo);
2231
+ }
2216
2232
2217
2233
return retval;
2218
2234
}
0 commit comments