Skip to content

Commit

Permalink
[ProfileData] Copy CallTargetMaps a bit less. NFCI
Browse files Browse the repository at this point in the history
  • Loading branch information
d0k committed Dec 24, 2023
1 parent 1e710cf commit 9423e45
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 18 deletions.
4 changes: 2 additions & 2 deletions llvm/include/llvm/ProfileData/SampleProf.h
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ class FunctionSamples {
/// Returns the call target map collected at a given location.
/// Each location is specified by \p LineOffset and \p Discriminator.
/// If the location is not found in profile, return error.
ErrorOr<SampleRecord::CallTargetMap>
ErrorOr<const SampleRecord::CallTargetMap &>
findCallTargetMapAt(uint32_t LineOffset, uint32_t Discriminator) const {
const auto &ret = BodySamples.find(
mapIRLocToProfileLoc(LineLocation(LineOffset, Discriminator)));
Expand All @@ -894,7 +894,7 @@ class FunctionSamples {

/// Returns the call target map collected at a given location specified by \p
/// CallSite. If the location is not found in profile, return error.
ErrorOr<SampleRecord::CallTargetMap>
ErrorOr<const SampleRecord::CallTargetMap &>
findCallTargetMapAt(const LineLocation &CallSite) const {
const auto &Ret = BodySamples.find(mapIRLocToProfileLoc(CallSite));
if (Ret == BodySamples.end())
Expand Down
5 changes: 2 additions & 3 deletions llvm/include/llvm/Transforms/IPO/ProfiledCallGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,8 @@ class ProfiledCallGraph {
uint64_t CallsiteCount = 0;
LineLocation Callsite = Callee->getCallSiteLoc();
if (auto CallTargets = CallerSamples->findCallTargetMapAt(Callsite)) {
SampleRecord::CallTargetMap &TargetCounts = CallTargets.get();
auto It = TargetCounts.find(CalleeSamples->getFunction());
if (It != TargetCounts.end())
auto It = CallTargets->find(CalleeSamples->getFunction());
if (It != CallTargets->end())
CallsiteCount = It->second;
}
Weight = std::max(CallsiteCount, CalleeEntryCount);
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Target/X86/X86InsertPrefetch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ using PrefetchHints = SampleRecord::CallTargetMap;

// Return any prefetching hints for the specified MachineInstruction. The hints
// are returned as pairs (name, delta).
ErrorOr<PrefetchHints> getPrefetchHints(const FunctionSamples *TopSamples,
const MachineInstr &MI) {
ErrorOr<const PrefetchHints &>
getPrefetchHints(const FunctionSamples *TopSamples, const MachineInstr &MI) {
if (const auto &Loc = MI.getDebugLoc())
if (const auto *Samples = TopSamples->findFunctionSamples(Loc))
return Samples->findCallTargetMapAt(FunctionSamples::getOffset(Loc),
Expand Down Expand Up @@ -123,7 +123,7 @@ bool X86InsertPrefetch::findPrefetchInfo(const FunctionSamples *TopSamples,
};
static const char *SerializedPrefetchPrefix = "__prefetch";

const ErrorOr<PrefetchHints> T = getPrefetchHints(TopSamples, MI);
auto T = getPrefetchHints(TopSamples, MI);
if (!T)
return false;
int16_t max_index = -1;
Expand Down
13 changes: 6 additions & 7 deletions llvm/lib/Transforms/IPO/SampleProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -794,10 +794,9 @@ SampleProfileLoader::findIndirectCallFunctionSamples(
return R;

auto CallSite = FunctionSamples::getCallSiteIdentifier(DIL);
auto T = FS->findCallTargetMapAt(CallSite);
Sum = 0;
if (T)
for (const auto &T_C : T.get())
if (auto T = FS->findCallTargetMapAt(CallSite))
for (const auto &T_C : *T)
Sum += T_C.second;
if (const FunctionSamplesMap *M = FS->findFunctionSamplesMapAt(CallSite)) {
if (M->empty())
Expand Down Expand Up @@ -1679,7 +1678,8 @@ void SampleProfileLoader::generateMDProfMetadata(Function &F) {
if (!FS)
continue;
auto CallSite = FunctionSamples::getCallSiteIdentifier(DIL);
auto T = FS->findCallTargetMapAt(CallSite);
ErrorOr<SampleRecord::CallTargetMap> T =
FS->findCallTargetMapAt(CallSite);
if (!T || T.get().empty())
continue;
if (FunctionSamples::ProfileIsProbeBased) {
Expand Down Expand Up @@ -2261,9 +2261,8 @@ void SampleProfileMatcher::countProfileCallsiteMismatches(

// Compute number of samples in the original profile.
uint64_t CallsiteSamples = 0;
auto CTM = FS.findCallTargetMapAt(Loc);
if (CTM) {
for (const auto &I : CTM.get())
if (auto CTM = FS.findCallTargetMapAt(Loc)) {
for (const auto &I : *CTM)
CallsiteSamples += I.second;
}
const auto *FSMap = FS.findFunctionSamplesMapAt(Loc);
Expand Down
5 changes: 2 additions & 3 deletions llvm/tools/llvm-profgen/CSPreInliner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,8 @@ bool CSPreInliner::getInlineCandidates(ProfiledCandidateQueue &CQueue,
uint64_t CallsiteCount = 0;
LineLocation Callsite = CalleeNode->getCallSiteLoc();
if (auto CallTargets = CallerSamples->findCallTargetMapAt(Callsite)) {
SampleRecord::CallTargetMap &TargetCounts = CallTargets.get();
auto It = TargetCounts.find(CalleeSamples->getFunction());
if (It != TargetCounts.end())
auto It = CallTargets->find(CalleeSamples->getFunction());
if (It != CallTargets->end())
CallsiteCount = It->second;
}

Expand Down

0 comments on commit 9423e45

Please sign in to comment.