Skip to content

Commit 730d934

Browse files
committed
[PGO] Profile interface cleanup
- Remove unused valuemapper parameter - add totalcount optional parameter git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@259756 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent fb3aa17 commit 730d934

File tree

4 files changed

+38
-25
lines changed

4 files changed

+38
-25
lines changed

include/llvm/ProfileData/InstrProf.h

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "llvm/Support/ErrorHandling.h"
2626
#include "llvm/Support/ErrorOr.h"
2727
#include "llvm/Support/MD5.h"
28+
#include "llvm/Support/MathExtras.h"
2829
#include <cstdint>
2930
#include <list>
3031
#include <map>
@@ -410,13 +411,17 @@ struct InstrProfRecord {
410411
/// site: Site.
411412
inline uint32_t getNumValueDataForSite(uint32_t ValueKind,
412413
uint32_t Site) const;
413-
/// Return the array of profiled values at \p Site.
414+
/// Return the array of profiled values at \p Site. If \p TotalC
415+
/// is not null, the total count of all target values at this site
416+
/// will be stored in \c *TotalC.
414417
inline std::unique_ptr<InstrProfValueData[]>
415418
getValueForSite(uint32_t ValueKind, uint32_t Site,
416-
uint64_t (*ValueMapper)(uint32_t, uint64_t) = nullptr) const;
417-
inline void
418-
getValueForSite(InstrProfValueData Dest[], uint32_t ValueKind, uint32_t Site,
419-
uint64_t (*ValueMapper)(uint32_t, uint64_t) = nullptr) const;
419+
uint64_t *TotalC = 0) const;
420+
/// Get the target value/counts of kind \p ValueKind collected at site
421+
/// \p Site and store the result in array \p Dest. Return the total
422+
/// counts of all target values at this site.
423+
inline uint64_t getValueForSite(InstrProfValueData Dest[], uint32_t ValueKind,
424+
uint32_t Site) const;
420425
/// Reserve space for NumValueSites sites.
421426
inline void reserveSites(uint32_t ValueKind, uint32_t NumValueSites);
422427
/// Add ValueData for ValueKind at value Site.
@@ -505,29 +510,35 @@ uint32_t InstrProfRecord::getNumValueDataForSite(uint32_t ValueKind,
505510
return getValueSitesForKind(ValueKind)[Site].ValueData.size();
506511
}
507512

508-
std::unique_ptr<InstrProfValueData[]> InstrProfRecord::getValueForSite(
509-
uint32_t ValueKind, uint32_t Site,
510-
uint64_t (*ValueMapper)(uint32_t, uint64_t)) const {
513+
std::unique_ptr<InstrProfValueData[]>
514+
InstrProfRecord::getValueForSite(uint32_t ValueKind, uint32_t Site,
515+
uint64_t *TotalC) const {
516+
uint64_t Dummy;
517+
uint64_t &TotalCount = (TotalC == 0 ? Dummy : *TotalC);
511518
uint32_t N = getNumValueDataForSite(ValueKind, Site);
512-
if (N == 0)
519+
if (N == 0) {
520+
TotalCount = 0;
513521
return std::unique_ptr<InstrProfValueData[]>(nullptr);
522+
}
514523

515524
auto VD = llvm::make_unique<InstrProfValueData[]>(N);
516-
getValueForSite(VD.get(), ValueKind, Site, ValueMapper);
525+
TotalCount = getValueForSite(VD.get(), ValueKind, Site);
517526

518527
return VD;
519528
}
520529

521-
void InstrProfRecord::getValueForSite(InstrProfValueData Dest[],
522-
uint32_t ValueKind, uint32_t Site,
523-
uint64_t (*ValueMapper)(uint32_t,
524-
uint64_t)) const {
530+
uint64_t InstrProfRecord::getValueForSite(InstrProfValueData Dest[],
531+
uint32_t ValueKind,
532+
uint32_t Site) const {
525533
uint32_t I = 0;
534+
uint64_t TotalCount = 0;
526535
for (auto V : getValueSitesForKind(ValueKind)[Site].ValueData) {
527-
Dest[I].Value = ValueMapper ? ValueMapper(ValueKind, V.Value) : V.Value;
536+
Dest[I].Value = V.Value;
528537
Dest[I].Count = V.Count;
538+
TotalCount = SaturatingAdd(TotalCount, V.Count);
529539
I++;
530540
}
541+
return TotalCount;
531542
}
532543

533544
void InstrProfRecord::reserveSites(uint32_t ValueKind, uint32_t NumValueSites) {

include/llvm/ProfileData/InstrProfData.inc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ typedef struct ValueProfRecordClosure {
343343
*/
344344
uint64_t (*RemapValueData)(uint32_t, uint64_t Value);
345345
void (*GetValueForSite)(const void *R, InstrProfValueData *Dst, uint32_t K,
346-
uint32_t S, uint64_t (*Mapper)(uint32_t, uint64_t));
346+
uint32_t S);
347347
ValueProfData *(*AllocValueProfData)(size_t TotalSizeInBytes);
348348
} ValueProfRecordClosure;
349349

@@ -506,8 +506,7 @@ void serializeValueProfRecordFrom(ValueProfRecord *This,
506506
for (S = 0; S < NumValueSites; S++) {
507507
uint32_t ND = Closure->GetNumValueDataForSite(Record, ValueKind, S);
508508
This->SiteCountArray[S] = ND;
509-
Closure->GetValueForSite(Record, DstVD, ValueKind, S,
510-
Closure->RemapValueData);
509+
Closure->GetValueForSite(Record, DstVD, ValueKind, S);
511510
DstVD += ND;
512511
}
513512
}
@@ -617,7 +616,7 @@ uint32_t getNumValueDataRT(const void *R, uint32_t VK) {
617616
}
618617

619618
void getValueForSiteRT(const void *R, InstrProfValueData *Dst, uint32_t VK,
620-
uint32_t S, uint64_t (*Mapper)(uint32_t, uint64_t)) {
619+
uint32_t S) {
621620
unsigned I, N = 0;
622621
const ValueProfRuntimeRecord *Record = (const ValueProfRuntimeRecord *)R;
623622
N = getNumValueDataForSiteRT(R, VK, S);

lib/ProfileData/InstrProf.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -430,10 +430,9 @@ uint32_t getNumValueDataForSiteInstrProf(const void *R, uint32_t VK,
430430
}
431431

432432
void getValueForSiteInstrProf(const void *R, InstrProfValueData *Dst,
433-
uint32_t K, uint32_t S,
434-
uint64_t (*Mapper)(uint32_t, uint64_t)) {
435-
return reinterpret_cast<const InstrProfRecord *>(R)->getValueForSite(
436-
Dst, K, S, Mapper);
433+
uint32_t K, uint32_t S) {
434+
reinterpret_cast<const InstrProfRecord *>(R)->getValueForSite(Dst, K, S);
435+
return;
437436
}
438437

439438
ValueProfData *allocValueProfDataInstrProf(size_t TotalSizeInBytes) {

unittests/ProfileData/InstrProfTest.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,14 @@ TEST_P(MaybeSparseInstrProfTest, get_icall_data_read_write) {
211211
ASSERT_EQ(2U, R.get().getNumValueDataForSite(IPVK_IndirectCallTarget, 2));
212212
ASSERT_EQ(1U, R.get().getNumValueDataForSite(IPVK_IndirectCallTarget, 3));
213213

214+
uint64_t TotalC;
214215
std::unique_ptr<InstrProfValueData[]> VD =
215-
R.get().getValueForSite(IPVK_IndirectCallTarget, 0);
216+
R.get().getValueForSite(IPVK_IndirectCallTarget, 0, &TotalC);
216217

217218
ASSERT_EQ(3U, VD[0].Count);
218219
ASSERT_EQ(2U, VD[1].Count);
219220
ASSERT_EQ(1U, VD[2].Count);
221+
ASSERT_EQ(6U, TotalC);
220222

221223
ASSERT_EQ(StringRef((const char *)VD[0].Value, 7), StringRef("callee3"));
222224
ASSERT_EQ(StringRef((const char *)VD[1].Value, 7), StringRef("callee2"));
@@ -258,11 +260,13 @@ TEST_P(MaybeSparseInstrProfTest, get_icall_data_read_write_with_weight) {
258260
ASSERT_EQ(2U, R.get().getNumValueDataForSite(IPVK_IndirectCallTarget, 2));
259261
ASSERT_EQ(1U, R.get().getNumValueDataForSite(IPVK_IndirectCallTarget, 3));
260262

263+
uint64_t TotalC;
261264
std::unique_ptr<InstrProfValueData[]> VD =
262-
R.get().getValueForSite(IPVK_IndirectCallTarget, 0);
265+
R.get().getValueForSite(IPVK_IndirectCallTarget, 0, &TotalC);
263266
ASSERT_EQ(30U, VD[0].Count);
264267
ASSERT_EQ(20U, VD[1].Count);
265268
ASSERT_EQ(10U, VD[2].Count);
269+
ASSERT_EQ(60U, TotalC);
266270

267271
ASSERT_EQ(StringRef((const char *)VD[0].Value, 7), StringRef("callee3"));
268272
ASSERT_EQ(StringRef((const char *)VD[1].Value, 7), StringRef("callee2"));

0 commit comments

Comments
 (0)