Skip to content

Commit 9423e45

Browse files
committed
[ProfileData] Copy CallTargetMaps a bit less. NFCI
1 parent 1e710cf commit 9423e45

File tree

5 files changed

+15
-18
lines changed

5 files changed

+15
-18
lines changed

llvm/include/llvm/ProfileData/SampleProf.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ class FunctionSamples {
883883
/// Returns the call target map collected at a given location.
884884
/// Each location is specified by \p LineOffset and \p Discriminator.
885885
/// If the location is not found in profile, return error.
886-
ErrorOr<SampleRecord::CallTargetMap>
886+
ErrorOr<const SampleRecord::CallTargetMap &>
887887
findCallTargetMapAt(uint32_t LineOffset, uint32_t Discriminator) const {
888888
const auto &ret = BodySamples.find(
889889
mapIRLocToProfileLoc(LineLocation(LineOffset, Discriminator)));
@@ -894,7 +894,7 @@ class FunctionSamples {
894894

895895
/// Returns the call target map collected at a given location specified by \p
896896
/// CallSite. If the location is not found in profile, return error.
897-
ErrorOr<SampleRecord::CallTargetMap>
897+
ErrorOr<const SampleRecord::CallTargetMap &>
898898
findCallTargetMapAt(const LineLocation &CallSite) const {
899899
const auto &Ret = BodySamples.find(mapIRLocToProfileLoc(CallSite));
900900
if (Ret == BodySamples.end())

llvm/include/llvm/Transforms/IPO/ProfiledCallGraph.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,8 @@ class ProfiledCallGraph {
114114
uint64_t CallsiteCount = 0;
115115
LineLocation Callsite = Callee->getCallSiteLoc();
116116
if (auto CallTargets = CallerSamples->findCallTargetMapAt(Callsite)) {
117-
SampleRecord::CallTargetMap &TargetCounts = CallTargets.get();
118-
auto It = TargetCounts.find(CalleeSamples->getFunction());
119-
if (It != TargetCounts.end())
117+
auto It = CallTargets->find(CalleeSamples->getFunction());
118+
if (It != CallTargets->end())
120119
CallsiteCount = It->second;
121120
}
122121
Weight = std::max(CallsiteCount, CalleeEntryCount);

llvm/lib/Target/X86/X86InsertPrefetch.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ using PrefetchHints = SampleRecord::CallTargetMap;
6969

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

126-
const ErrorOr<PrefetchHints> T = getPrefetchHints(TopSamples, MI);
126+
auto T = getPrefetchHints(TopSamples, MI);
127127
if (!T)
128128
return false;
129129
int16_t max_index = -1;

llvm/lib/Transforms/IPO/SampleProfile.cpp

+6-7
Original file line numberDiff line numberDiff line change
@@ -794,10 +794,9 @@ SampleProfileLoader::findIndirectCallFunctionSamples(
794794
return R;
795795

796796
auto CallSite = FunctionSamples::getCallSiteIdentifier(DIL);
797-
auto T = FS->findCallTargetMapAt(CallSite);
798797
Sum = 0;
799-
if (T)
800-
for (const auto &T_C : T.get())
798+
if (auto T = FS->findCallTargetMapAt(CallSite))
799+
for (const auto &T_C : *T)
801800
Sum += T_C.second;
802801
if (const FunctionSamplesMap *M = FS->findFunctionSamplesMapAt(CallSite)) {
803802
if (M->empty())
@@ -1679,7 +1678,8 @@ void SampleProfileLoader::generateMDProfMetadata(Function &F) {
16791678
if (!FS)
16801679
continue;
16811680
auto CallSite = FunctionSamples::getCallSiteIdentifier(DIL);
1682-
auto T = FS->findCallTargetMapAt(CallSite);
1681+
ErrorOr<SampleRecord::CallTargetMap> T =
1682+
FS->findCallTargetMapAt(CallSite);
16831683
if (!T || T.get().empty())
16841684
continue;
16851685
if (FunctionSamples::ProfileIsProbeBased) {
@@ -2261,9 +2261,8 @@ void SampleProfileMatcher::countProfileCallsiteMismatches(
22612261

22622262
// Compute number of samples in the original profile.
22632263
uint64_t CallsiteSamples = 0;
2264-
auto CTM = FS.findCallTargetMapAt(Loc);
2265-
if (CTM) {
2266-
for (const auto &I : CTM.get())
2264+
if (auto CTM = FS.findCallTargetMapAt(Loc)) {
2265+
for (const auto &I : *CTM)
22672266
CallsiteSamples += I.second;
22682267
}
22692268
const auto *FSMap = FS.findFunctionSamplesMapAt(Loc);

llvm/tools/llvm-profgen/CSPreInliner.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,8 @@ bool CSPreInliner::getInlineCandidates(ProfiledCandidateQueue &CQueue,
128128
uint64_t CallsiteCount = 0;
129129
LineLocation Callsite = CalleeNode->getCallSiteLoc();
130130
if (auto CallTargets = CallerSamples->findCallTargetMapAt(Callsite)) {
131-
SampleRecord::CallTargetMap &TargetCounts = CallTargets.get();
132-
auto It = TargetCounts.find(CalleeSamples->getFunction());
133-
if (It != TargetCounts.end())
131+
auto It = CallTargets->find(CalleeSamples->getFunction());
132+
if (It != CallTargets->end())
134133
CallsiteCount = It->second;
135134
}
136135

0 commit comments

Comments
 (0)