Skip to content

Commit 8927a27

Browse files
committed
Fixup GuidFilter && Pseudo probe callee mismatch
1 parent b1cbdd0 commit 8927a27

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

llvm/tools/llvm-profgen/ProfileGenerator.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ void ProfileGenerator::populateBodySamplesForAllFunctions(
723723
}
724724

725725
StringRef
726-
ProfileGeneratorBase::getCalleeNameForAddress(uint64_t TargetAddress) {
726+
ProfileGeneratorBase::getCalleeNameForAddress(uint64_t TargetAddress, bool RestoreSymbolName) {
727727
// Get the function range by branch target if it's a call branch.
728728
auto *FRange = Binary->findFuncRangeForStartAddr(TargetAddress);
729729

@@ -732,6 +732,16 @@ ProfileGeneratorBase::getCalleeNameForAddress(uint64_t TargetAddress) {
732732
if (!FRange || !FRange->IsFuncEntry)
733733
return StringRef();
734734

735+
if (RestoreSymbolName && FRange->Func->FromSymtab) {
736+
const AddressProbesMap &Address2ProbesMap =
737+
Binary->getAddress2ProbesMap();
738+
for (const MCDecodedPseudoProbe &Probe :
739+
Address2ProbesMap.find(TargetAddress)) {
740+
if (const auto *ProbeDesc = Binary->getFuncDescForGUID(Probe.getGuid()))
741+
return FunctionSamples::getCanonicalFnName(ProbeDesc->FuncName);
742+
}
743+
}
744+
735745
return FunctionSamples::getCanonicalFnName(FRange->getFuncName());
736746
}
737747

@@ -1352,7 +1362,7 @@ void CSProfileGenerator::populateBoundarySamplesWithProbes(
13521362
getFunctionProfileForLeafProbe(CtxKey, CallProbe);
13531363
FunctionProfile.addBodySamples(CallProbe->getIndex(), 0, Count);
13541364
FunctionProfile.addTotalSamples(Count);
1355-
StringRef CalleeName = getCalleeNameForAddress(TargetAddress);
1365+
StringRef CalleeName = getCalleeNameForAddress(TargetAddress, true);
13561366
if (CalleeName.size() == 0)
13571367
continue;
13581368
FunctionProfile.addCalledTargetSamples(CallProbe->getIndex(),

llvm/tools/llvm-profgen/ProfileGenerator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class ProfileGeneratorBase {
109109

110110
bool filterAmbiguousProfile(FunctionSamples &FS);
111111

112-
StringRef getCalleeNameForAddress(uint64_t TargetAddress);
112+
StringRef getCalleeNameForAddress(uint64_t TargetAddress, bool RestoreSymbolName = false);
113113

114114
void computeSummaryAndThreshold(SampleProfileMap &ProfileMap);
115115

llvm/tools/llvm-profgen/ProfiledBinary.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,12 @@ void ProfiledBinary::decodePseudoProbe(const ObjectFile *Obj) {
473473
GuidFilter.insert(Function::getGUIDAssumingExternalLinkage(F->FuncName));
474474
for (auto &Range : F->Ranges) {
475475
auto GUIDs = StartAddrToSymMap.equal_range(Range.first);
476-
for (const auto &[StartAddr, Func] : make_range(GUIDs))
476+
for (const auto &[StartAddr, Func] : make_range(GUIDs)) {
477477
FuncStartAddresses[Func] = StartAddr;
478+
// Function name may be changed when symbol table is loaded. Adding
479+
// back the original GUID if possible
480+
GuidFilter.insert(Func);
481+
}
478482
}
479483
}
480484
}
@@ -865,9 +869,11 @@ void ProfiledBinary::loadSymbolsFromSymtab(const ObjectFile *Obj) {
865869
const uint64_t EndAddr = StartAddr + Size;
866870
const StringRef SymName =
867871
FunctionSamples::getCanonicalFnName(Name, Suffixes);
872+
assert(StartAddr < EndAddr && StartAddr >= getPreferredBaseAddress());
868873

869874
auto Range = findFuncRange(StartAddr);
870875
if (!Range) {
876+
assert(findFuncRange(EndAddr - 1) == nullptr);
871877
// Function from symbol table not found previously in DWARF, store ranges.
872878
auto Ret = BinaryFunctions.emplace(SymName, BinaryFunction());
873879
auto &Func = Ret.first->second;

0 commit comments

Comments
 (0)