-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[InstrFDO][TypeProf] Implement binary instrumentation and profile read/write #66825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 42 commits
361f8f6
cb0246f
3c6ca04
3780bd9
9255867
8d8a45a
82fac8e
d54d059
ebf4c1d
52143e9
2350d7f
af34929
fcf92af
f5d12b5
17d941c
c000e64
5b09e43
313eb10
abcbc6d
8c725ef
1050a6b
9f01a30
a9deaec
66efde8
9ec0784
0d9abe5
8240524
60cd296
a7633ad
a61c8a4
4dbe23e
000d818
c57422b
df6eadf
c30888c
4a9e6c9
61e8292
fc1d2be
d8967d2
27239f0
0158523
2abdfe3
7ea9217
0a0c364
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
// REQUIRES: lld-available | ||
|
||
// RUN: rm -rf %t && split-file %s %t && cd %t | ||
// | ||
// RUN: %clangxx_pgogen -fuse-ld=lld -O2 -g -fprofile-generate=. -mllvm -enable-vtable-value-profiling test.cpp -o test | ||
// RUN: env LLVM_PROFILE_FILE=test.profraw ./test | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [optional] If you prefix the test.profraw as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||
|
||
// Show vtable profiles from raw profile. | ||
// RUN: llvm-profdata show --function=main --ic-targets -show-vtables test.profraw | FileCheck %s --check-prefixes=COMMON,RAW | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: the show-vtables option has a single hyphen here as opposed to double elsewhere. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed it. |
||
|
||
// Generate indexed profile from raw profile and show the data. | ||
// RUN: llvm-profdata merge test.profraw -o test.profdata | ||
// RUN: llvm-profdata show --function=main --ic-targets --show-vtables test.profdata | FileCheck %s --check-prefixes=COMMON,INDEXED | ||
|
||
// Generate text profile from raw and indexed profiles respectively and show the data. | ||
// RUN: llvm-profdata merge --text test.profraw -o raw.proftext | ||
// RUN: llvm-profdata show --function=main --ic-targets --show-vtables --text raw.proftext | FileCheck %s --check-prefix=ICTEXT | ||
// RUN: llvm-profdata merge --text test.profdata -o indexed.proftext | ||
// RUN: llvm-profdata show --function=main --ic-targets --show-vtables --text indexed.proftext | FileCheck %s --check-prefix=ICTEXT | ||
|
||
// Generate indexed profile from text profiles and show the data | ||
// RUN: llvm-profdata merge --binary raw.proftext -o text.profraw | ||
// RUN: llvm-profdata show --function=main --ic-targets --show-vtables text.profraw | FileCheck %s --check-prefixes=COMMON,INDEXED | ||
// RUN: llvm-profdata merge --binary indexed.proftext -o text.profdata | ||
// RUN: llvm-profdata show --function=main --ic-targets --show-vtables text.profdata | FileCheck %s --check-prefixes=COMMON,INDEXED | ||
|
||
// COMMON: Counters: | ||
// COMMON-NEXT: main: | ||
// COMMON-NEXT: Hash: 0x0f9a16fe6d398548 | ||
// COMMON-NEXT: Counters: 2 | ||
// COMMON-NEXT: Indirect Call Site Count: 2 | ||
// COMMON-NEXT: Number of instrumented vtables: 2 | ||
// RAW: Indirect Target Results: | ||
// RAW-NEXT: [ 0, _ZN8Derived15func1Eii, 250 ] (25.00%) | ||
// RAW-NEXT: [ 0, test.cpp;_ZN12_GLOBAL__N_18Derived25func1Eii, 750 ] (75.00%) | ||
// RAW-NEXT: [ 1, _ZN8Derived15func2Eii, 250 ] (25.00%) | ||
// RAW-NEXT: [ 1, test.cpp;_ZN12_GLOBAL__N_18Derived25func2Eii, 750 ] (75.00%) | ||
// RAW-NEXT: VTable Results: | ||
// RAW-NEXT: [ 0, _ZTV8Derived1, 250 ] (25.00%) | ||
// RAW-NEXT: [ 0, test.cpp;_ZTVN12_GLOBAL__N_18Derived2E, 750 ] (75.00%) | ||
// RAW-NEXT: [ 1, _ZTV8Derived1, 250 ] (25.00%) | ||
// RAW-NEXT: [ 1, test.cpp;_ZTVN12_GLOBAL__N_18Derived2E, 750 ] (75.00%) | ||
// INDEXED: Indirect Target Results: | ||
// INDEXED-NEXT: [ 0, test.cpp;_ZN12_GLOBAL__N_18Derived25func1Eii, 750 ] (75.00%) | ||
// INDEXED-NEXT: [ 0, _ZN8Derived15func1Eii, 250 ] (25.00%) | ||
// INDEXED-NEXT: [ 1, test.cpp;_ZN12_GLOBAL__N_18Derived25func2Eii, 750 ] (75.00%) | ||
// INDEXED-NEXT: [ 1, _ZN8Derived15func2Eii, 250 ] (25.00%) | ||
// INDEXED-NEXT: VTable Results: | ||
// INDEXED-NEXT: [ 0, test.cpp;_ZTVN12_GLOBAL__N_18Derived2E, 750 ] (75.00%) | ||
// INDEXED-NEXT: [ 0, _ZTV8Derived1, 250 ] (25.00%) | ||
// INDEXED-NEXT: [ 1, test.cpp;_ZTVN12_GLOBAL__N_18Derived2E, 750 ] (75.00%) | ||
// INDEXED-NEXT: [ 1, _ZTV8Derived1, 250 ] (25.00%) | ||
// COMMON: Instrumentation level: IR entry_first = 0 | ||
// COMMON-NEXT: Functions shown: 1 | ||
// COMMON-NEXT: Total functions: 6 | ||
// COMMON-NEXT: Maximum function count: 1000 | ||
// COMMON-NEXT: Maximum internal block count: 250 | ||
// COMMON-NEXT: Statistics for indirect call sites profile: | ||
// COMMON-NEXT: Total number of sites: 2 | ||
// COMMON-NEXT: Total number of sites with values: 2 | ||
// COMMON-NEXT: Total number of profiled values: 4 | ||
// COMMON-NEXT: Value sites histogram: | ||
// COMMON-NEXT: NumTargets, SiteCount | ||
// COMMON-NEXT: 2, 2 | ||
// COMMON-NEXT: Statistics for vtable profile: | ||
// COMMON-NEXT: Total number of sites: 2 | ||
// COMMON-NEXT: Total number of sites with values: 2 | ||
// COMMON-NEXT: Total number of profiled values: 4 | ||
// COMMON-NEXT: Value sites histogram: | ||
// COMMON-NEXT: NumTargets, SiteCount | ||
// COMMON-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: test.cpp;_ZN12_GLOBAL__N_18Derived25func1Eii:750 | ||
// ICTEXT: _ZN8Derived15func1Eii:250 | ||
// ICTEXT: 2 | ||
// ICTEXT: test.cpp;_ZN12_GLOBAL__N_18Derived25func2Eii:750 | ||
// ICTEXT: _ZN8Derived15func2Eii:250 | ||
// ICTEXT: # ValueKind = IPVK_VTableTarget: | ||
// ICTEXT: 2 | ||
// ICTEXT: # NumValueSites: | ||
// ICTEXT: 2 | ||
// ICTEXT: 2 | ||
// ICTEXT: test.cpp;_ZTVN12_GLOBAL__N_18Derived2E:750 | ||
// ICTEXT: _ZTV8Derived1:250 | ||
// ICTEXT: 2 | ||
// ICTEXT: test.cpp;_ZTVN12_GLOBAL__N_18Derived2E:750 | ||
// ICTEXT: _ZTV8Derived1:250 | ||
|
||
//--- test.cpp | ||
mingmingl-llvm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#include <cstdio> | ||
#include <cstdlib> | ||
class Base { | ||
public: | ||
virtual int func1(int a, int b) = 0; | ||
virtual int func2(int a, int b) = 0; | ||
}; | ||
class Derived1 : public Base { | ||
public: | ||
int func1(int a, int b) override { return a + b; } | ||
|
||
int func2(int a, int b) override { return a * b; } | ||
}; | ||
namespace { | ||
class Derived2 : public Base { | ||
public: | ||
int func1(int a, int b) override { return a - b; } | ||
|
||
int func2(int a, int b) override { return a * (a - b); } | ||
}; | ||
} // namespace | ||
__attribute__((noinline)) Base *createType(int a) { | ||
Base *base = nullptr; | ||
if (a % 4 == 0) | ||
base = new Derived1(); | ||
else | ||
base = new Derived2(); | ||
return base; | ||
} | ||
int main(int argc, char **argv) { | ||
int sum = 0; | ||
for (int i = 0; i < 1000; i++) { | ||
int a = rand(); | ||
int b = rand(); | ||
Base *ptr = createType(i); | ||
sum += ptr->func1(a, b) + ptr->func2(b, a); | ||
} | ||
printf("sum is %d\n", sum); | ||
return 0; | ||
} |
Uh oh!
There was an error while loading. Please reload this page.