@@ -529,7 +529,7 @@ class SampleProfileLoader final : public SampleProfileLoaderBaseImpl<Function> {
529
529
void generateMDProfMetadata (Function &F);
530
530
bool rejectHighStalenessProfile (Module &M, ProfileSummaryInfo *PSI,
531
531
const SampleProfileMap &Profiles);
532
- void removePseudoProbeInsts (Module &M);
532
+ void removePseudoProbeInstsDiscriminator (Module &M);
533
533
534
534
// / Map from function name to Function *. Used to find the function from
535
535
// / the function name. If the function name contains suffix, additional
@@ -2138,13 +2138,25 @@ bool SampleProfileLoader::rejectHighStalenessProfile(
2138
2138
return false ;
2139
2139
}
2140
2140
2141
- void SampleProfileLoader::removePseudoProbeInsts (Module &M) {
2141
+ void SampleProfileLoader::removePseudoProbeInstsDiscriminator (Module &M) {
2142
2142
for (auto &F : M) {
2143
2143
std::vector<Instruction *> InstsToDel;
2144
2144
for (auto &BB : F) {
2145
2145
for (auto &I : BB) {
2146
2146
if (isa<PseudoProbeInst>(&I))
2147
2147
InstsToDel.push_back (&I);
2148
+ else if (isa<CallBase>(&I))
2149
+ if (const DILocation *DIL = I.getDebugLoc ().get ()) {
2150
+ // Restore dwarf discriminator for call.
2151
+ unsigned Discriminator = DIL->getDiscriminator ();
2152
+ if (DILocation::isPseudoProbeDiscriminator (Discriminator)) {
2153
+ std::optional<uint32_t > DwarfDiscriminator =
2154
+ PseudoProbeDwarfDiscriminator::extractDwarfBaseDiscriminator (
2155
+ Discriminator);
2156
+ I.setDebugLoc (DIL->cloneWithDiscriminator (
2157
+ DwarfDiscriminator ? *DwarfDiscriminator : 0 ));
2158
+ }
2159
+ }
2148
2160
}
2149
2161
}
2150
2162
for (auto *I : InstsToDel)
@@ -2224,8 +2236,12 @@ bool SampleProfileLoader::runOnModule(Module &M, ModuleAnalysisManager *AM,
2224
2236
notInlinedCallInfo)
2225
2237
updateProfileCallee (pair.first , pair.second .entryCount );
2226
2238
2227
- if (RemoveProbeAfterProfileAnnotation && FunctionSamples::ProfileIsProbeBased)
2228
- removePseudoProbeInsts (M);
2239
+ if (RemoveProbeAfterProfileAnnotation &&
2240
+ FunctionSamples::ProfileIsProbeBased) {
2241
+ removePseudoProbeInstsDiscriminator (M);
2242
+ if (auto *FuncInfo = M.getNamedMetadata (PseudoProbeDescMetadataName))
2243
+ M.eraseNamedMetadata (FuncInfo);
2244
+ }
2229
2245
2230
2246
return retval;
2231
2247
}
0 commit comments