8 changes: 6 additions & 2 deletions llvm/test/tools/llvm-profdata/raw-two-profiles.test
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
RUN: printf '\201rforpl\377' > %t-foo.profraw
RUN: printf '\11\0\0\0\0\0\0\0' >> %t-foo.profraw
RUN: printf '\12\0\0\0\0\0\0\0' >> %t-foo.profraw
RUN: printf '\0\0\0\0\0\0\0\0' >> %t-foo.profraw
RUN: printf '\1\0\0\0\0\0\0\0' >> %t-foo.profraw
RUN: printf '\0\0\0\0\0\0\0\0' >> %t-foo.profraw
Expand All @@ -12,6 +12,8 @@ RUN: printf '\0\0\4\0\1\0\0\0' >> %t-foo.profraw
RUN: printf '\0\0\0\0\0\0\0\0' >> %t-foo.profraw
RUN: printf '\0\0\4\0\2\0\0\0' >> %t-foo.profraw
RUN: printf '\0\0\0\0\0\0\0\0' >> %t-foo.profraw
RUN: printf '\0\0\0\0\0\0\0\0' >> %t-foo.profraw
RUN: printf '\0\0\0\0\0\0\0\0' >> %t-foo.profraw

RUN: printf '\254\275\030\333\114\302\370\134' >> %t-foo.profraw
RUN: printf '\1\0\0\0\0\0\0\0' >> %t-foo.profraw
Expand All @@ -26,7 +28,7 @@ RUN: printf '\023\0\0\0\0\0\0\0' >> %t-foo.profraw
RUN: printf '\3\0foo\0\0\0' >> %t-foo.profraw

RUN: printf '\201rforpl\377' > %t-bar.profraw
RUN: printf '\11\0\0\0\0\0\0\0' >> %t-bar.profraw
RUN: printf '\12\0\0\0\0\0\0\0' >> %t-bar.profraw
RUN: printf '\0\0\0\0\0\0\0\0' >> %t-bar.profraw
RUN: printf '\1\0\0\0\0\0\0\0' >> %t-bar.profraw
RUN: printf '\0\0\0\0\0\0\0\0' >> %t-bar.profraw
Expand All @@ -39,6 +41,8 @@ RUN: printf '\0\0\6\0\1\0\0\0' >> %t-bar.profraw
RUN: printf '\0\0\0\0\0\0\0\0' >> %t-bar.profraw
RUN: printf '\0\0\6\0\2\0\0\0' >> %t-bar.profraw
RUN: printf '\0\0\0\0\0\0\0\0' >> %t-bar.profraw
RUN: printf '\0\0\0\0\0\0\0\0' >> %t-bar.profraw
RUN: printf '\0\0\0\0\0\0\0\0' >> %t-bar.profraw

RUN: printf '\067\265\035\031\112\165\023\344' >> %t-bar.profraw
RUN: printf '\02\0\0\0\0\0\0\0' >> %t-bar.profraw
Expand Down
124 changes: 124 additions & 0 deletions llvm/test/tools/llvm-profdata/vtable-value-prof-basic.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
To update the inputs used below, run
Inputs/update_vtable_value_prof_inputs.sh /path/to/updated/clang++

; Raw profiles stores zlib-compressed vtable names. Raw profile reader needs
; to decompress them.
; REQUIRES: zlib

; RUN: rm -rf %t && mkdir %t && cd %t

Show profile data from raw profiles.
RUN: llvm-profdata show --function=main --ic-targets --show-vtables %p/Inputs/vtable-value-prof-basic.profraw | FileCheck %s --check-prefix=RAW

Generate indexed profile from raw profile and show the data.
RUN: llvm-profdata merge %p/Inputs/vtable-value-prof-basic.profraw -o indexed.profdata
RUN: llvm-profdata show --function=main --ic-targets --show-vtables indexed.profdata | FileCheck %s --check-prefix=INDEXED

Generate text profile from raw profile and show the data.
RUN: llvm-profdata merge --text %p/Inputs/vtable-value-prof-basic.profraw -o vtable-value-prof-basic.proftext
RUN: llvm-profdata show --function=main --ic-targets --show-vtables --text vtable-value-prof-basic.proftext | FileCheck %s --check-prefix=ICTEXT

RAW: Counters:
RAW-NEXT: main:
RAW-NEXT: Hash: 0x0f9a16fe6d398548
RAW-NEXT: Counters: 2
RAW-NEXT: Indirect Call Site Count: 2
RAW-NEXT: Number of instrumented vtables: 2
RAW-NEXT: Indirect Target Results:
RAW-NEXT: [ 0, _ZN8Derived15func1Eii, 250 ] (25.00%)
RAW-NEXT: [ 0, {{.*}}vtable_prof.cc;_ZN12_GLOBAL__N_18Derived25func1Eii, 750 ] (75.00%)
RAW-NEXT: [ 1, _ZN8Derived15func2Eii, 250 ] (25.00%)
RAW-NEXT: [ 1, {{.*}}vtable_prof.cc;_ZN12_GLOBAL__N_18Derived25func2Eii, 750 ] (75.00%)
RAW-NEXT: VTable Results:
RAW-NEXT: [ 0, _ZTV8Derived1, 250 ] (25.00%)
RAW-NEXT: [ 0, {{.*}}vtable_prof.cc;_ZTVN12_GLOBAL__N_18Derived2E, 750 ] (75.00%)
RAW-NEXT: [ 1, _ZTV8Derived1, 250 ] (25.00%)
RAW-NEXT: [ 1, {{.*}}vtable_prof.cc;_ZTVN12_GLOBAL__N_18Derived2E, 750 ] (75.00%)
RAW-NEXT: Instrumentation level: IR entry_first = 0
RAW-NEXT: Functions shown: 1
RAW-NEXT: Total functions: 6
RAW-NEXT: Maximum function count: 1000
RAW-NEXT: Maximum internal block count: 250
RAW-NEXT: Statistics for indirect call sites profile:
RAW-NEXT: Total number of sites: 2
RAW-NEXT: Total number of sites with values: 2
RAW-NEXT: Total number of profiled values: 4
RAW-NEXT: Value sites histogram:
RAW-NEXT: NumTargets, SiteCount
RAW-NEXT: 2, 2
RAW-NEXT: Statistics for vtable profile:
RAW-NEXT: Total number of sites: 2
RAW-NEXT: Total number of sites with values: 2
RAW-NEXT: Total number of profiled values: 4
RAW-NEXT: Value sites histogram:
RAW-NEXT: NumTargets, SiteCount
RAW-NEXT: 2, 2


INDEXED: Counters:
INDEXED-NEXT: main:
INDEXED-NEXT: Hash: 0x0f9a16fe6d398548
INDEXED-NEXT: Counters: 2
INDEXED-NEXT: Indirect Call Site Count: 2
INDEXED-NEXT: Number of instrumented vtables: 2
INDEXED-NEXT: Indirect Target Results:
INDEXED-NEXT: [ 0, {{.*}}vtable_prof.cc;_ZN12_GLOBAL__N_18Derived25func1Eii, 750 ] (75.00%)
INDEXED-NEXT: [ 0, _ZN8Derived15func1Eii, 250 ] (25.00%)
INDEXED-NEXT: [ 1, {{.*}}vtable_prof.cc;_ZN12_GLOBAL__N_18Derived25func2Eii, 750 ] (75.00%)
INDEXED-NEXT: [ 1, _ZN8Derived15func2Eii, 250 ] (25.00%)
INDEXED-NEXT: VTable Results:
INDEXED-NEXT: [ 0, {{.*}}vtable_prof.cc;_ZTVN12_GLOBAL__N_18Derived2E, 750 ] (75.00%)
INDEXED-NEXT: [ 0, _ZTV8Derived1, 250 ] (25.00%)
INDEXED-NEXT: [ 1, {{.*}}vtable_prof.cc;_ZTVN12_GLOBAL__N_18Derived2E, 750 ] (75.00%)
INDEXED-NEXT: [ 1, _ZTV8Derived1, 250 ] (25.00%)
INDEXED-NEXT: Instrumentation level: IR entry_first = 0
INDEXED-NEXT: Functions shown: 1
INDEXED-NEXT: Total functions: 6
INDEXED-NEXT: Maximum function count: 1000
INDEXED-NEXT: Maximum internal block count: 250
INDEXED-NEXT: Statistics for indirect call sites profile:
INDEXED-NEXT: Total number of sites: 2
INDEXED-NEXT: Total number of sites with values: 2
INDEXED-NEXT: Total number of profiled values: 4
INDEXED-NEXT: Value sites histogram:
INDEXED-NEXT: NumTargets, SiteCount
INDEXED-NEXT: 2, 2
INDEXED-NEXT: Statistics for vtable profile:
INDEXED-NEXT: Total number of sites: 2
INDEXED-NEXT: Total number of sites with values: 2
INDEXED-NEXT: Total number of profiled values: 4
INDEXED-NEXT: Value sites histogram:
INDEXED-NEXT: NumTargets, SiteCount
INDEXED-NEXT: 2, 2

ICTEXT: :ir
ICTEXT: main
ICTEXT: # Func Hash:
ICTEXT: 1124236338992350536
ICTEXT: # Num Counters:
ICTEXT: 2
ICTEXT: # Counter Values:
ICTEXT: 1000
ICTEXT: 1
ICTEXT: # Num Value Kinds:
ICTEXT: 2
ICTEXT: # ValueKind = IPVK_IndirectCallTarget:
ICTEXT: 0
ICTEXT: # NumValueSites:
ICTEXT: 2
ICTEXT: 2
ICTEXT: {{.*}}vtable_prof.cc;_ZN12_GLOBAL__N_18Derived25func1Eii:750
ICTEXT: _ZN8Derived15func1Eii:250
ICTEXT: 2
ICTEXT: {{.*}}vtable_prof.cc;_ZN12_GLOBAL__N_18Derived25func2Eii:750
ICTEXT: _ZN8Derived15func2Eii:250
ICTEXT: # ValueKind = IPVK_VTableTarget:
ICTEXT: 2
ICTEXT: # NumValueSites:
ICTEXT: 2
ICTEXT: 2
ICTEXT: {{.*}}vtable_prof.cc;_ZTVN12_GLOBAL__N_18Derived2E:750
ICTEXT: _ZTV8Derived1:250
ICTEXT: 2
ICTEXT: {{.*}}vtable_prof.cc;_ZTVN12_GLOBAL__N_18Derived2E:750
ICTEXT: _ZTV8Derived1:250
16 changes: 16 additions & 0 deletions llvm/test/tools/llvm-profdata/vtable-value-prof.proftext
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# RUN: llvm-profdata show --function=main --show-vtables %p/Inputs/vtable-value-prof.proftext | FileCheck %s

# CHECK: Counters:
# CHECK: main:
# CHECK: Hash: 0x0f9a16fe6d398548
# CHECK: Counters: 2
# CHECK: VTable Results:
# CHECK: [ 0, /path/to/vtable_prof.cc;_ZTVN12_GLOBAL__N_18Derived2E, 750 ] (75.00%)
# CHECK: [ 0, _ZTV8Derived1, 250 ] (25.00%)
# CHECK: [ 1, /path/to/vtable_prof.cc;_ZTVN12_GLOBAL__N_18Derived2E, 750 ] (75.00%)
# CHECK: [ 1, _ZTV8Derived1, 250 ] (25.00%)
# CHECK: Instrumentation level: IR entry_first = 0
# CHECK: Functions shown: 1
# CHECK: Total functions: 6
# CHECK: Maximum function count: 1000
# CHECK: Maximum internal block count: 250
30 changes: 28 additions & 2 deletions llvm/tools/llvm-profdata/llvm-profdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,9 @@ cl::opt<bool> ShowIndirectCallTargets(
"ic-targets", cl::init(false),
cl::desc("Show indirect call site target values for shown functions"),
cl::sub(ShowSubcommand));
cl::opt<bool> ShowVTables("show-vtables", cl::init(false),
cl::desc("Show vtable names for shown functions"),
cl::sub(ShowSubcommand));
cl::opt<bool> ShowMemOPSizes(
"memop-sizes", cl::init(false),
cl::desc("Show the profiled sizes of the memory intrinsic calls "
Expand Down Expand Up @@ -722,6 +725,13 @@ static void loadInput(const WeightedFile &Input, SymbolRemapper *Remapper,
});
}

const InstrProfSymtab &symtab = Reader->getSymtab();
const auto &VTableNames = symtab.getVTableNames();

for (const auto &kv : VTableNames) {
WC->Writer.addVTableName(kv.getKey());
}

if (Reader->hasTemporalProfile()) {
auto &Traces = Reader->getTemporalProfTraces(Input.Weight);
if (!Traces.empty())
Expand Down Expand Up @@ -1353,8 +1363,8 @@ remapSamples(const sampleprof::FunctionSamples &Samples,
BodySample.second.getSamples());
for (const auto &Target : BodySample.second.getCallTargets()) {
Result.addCalledTargetSamples(BodySample.first.LineOffset,
MaskedDiscriminator,
Remapper(Target.first), Target.second);
MaskedDiscriminator, Remapper(Target.first),
Target.second);
}
}
for (const auto &CallsiteSamples : Samples.getCallsiteSamples()) {
Expand Down Expand Up @@ -2817,6 +2827,10 @@ static int showInstrProfile(ShowFormat SFormat, raw_fd_ostream &OS) {
OS << " Indirect Call Site Count: "
<< Func.getNumValueSites(IPVK_IndirectCallTarget) << "\n";

if (ShowVTables)
OS << " Number of instrumented vtables: "
<< Func.getNumValueSites(IPVK_VTableTarget) << "\n";

uint32_t NumMemOPCalls = Func.getNumValueSites(IPVK_MemOPSize);
if (ShowMemOPSizes && NumMemOPCalls > 0)
OS << " Number of Memory Intrinsics Calls: " << NumMemOPCalls
Expand All @@ -2838,6 +2852,13 @@ static int showInstrProfile(ShowFormat SFormat, raw_fd_ostream &OS) {
&(Reader->getSymtab()));
}

if (ShowVTables) {
OS << " VTable Results:\n";
traverseAllValueSites(Func, IPVK_VTableTarget,
VPStats[IPVK_VTableTarget], OS,
&(Reader->getSymtab()));
}

if (ShowMemOPSizes && NumMemOPCalls > 0) {
OS << " Memory Intrinsic Size Results:\n";
traverseAllValueSites(Func, IPVK_MemOPSize, VPStats[IPVK_MemOPSize], OS,
Expand Down Expand Up @@ -2886,6 +2907,11 @@ static int showInstrProfile(ShowFormat SFormat, raw_fd_ostream &OS) {
VPStats[IPVK_IndirectCallTarget]);
}

if (ShownFunctions && ShowVTables) {
OS << "Statistics for vtable profile:\n";
showValueSitesStats(OS, IPVK_VTableTarget, VPStats[IPVK_VTableTarget]);
}

if (ShownFunctions && ShowMemOPSizes) {
OS << "Statistics for memory intrinsic calls sizes profile:\n";
showValueSitesStats(OS, IPVK_MemOPSize, VPStats[IPVK_MemOPSize]);
Expand Down
604 changes: 472 additions & 132 deletions llvm/unittests/ProfileData/InstrProfTest.cpp

Large diffs are not rendered by default.