Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[InstrProfiling] Place __llvm_prf_vnodes and __llvm_prf_names in llvm…
….used on ELF `__llvm_prf_vnodes` and `__llvm_prf_names` are used by runtime but not referenced via relocation in the translation unit. With `-z start-stop-gc` (D96914 https://sourceware.org/bugzilla/show_bug.cgi?id=27451), the linker no longer lets `__start_/__stop_` references retain them. Place `__llvm_prf_vnodes` and `__llvm_prf_names` in `llvm.used` to make them retained by the linker. This patch changes most existing `UsedVars` cases to `CompilerUsedVars` to reflect the ideal state - if the binary format properly supports section based GC (dead stripping), `llvm.compiler.used` should be sufficient. `__llvm_prf_vnodes` and `__llvm_prf_names` are switched to `UsedVars` since we want them to be unconditionally retained by both compiler and linker. Behaviors on other COFF/Mach-O are not affected. Differential Revision: https://reviews.llvm.org/D97649
- Loading branch information
Showing
6 changed files
with
123 additions
and
75 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
compiler-rt/test/profile/Linux/Inputs/instrprof-value-merge.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#include <string.h> | ||
|
||
void (*f0)(); | ||
void (*f1)(); | ||
void (*f2)(); | ||
|
||
char dst[200]; | ||
char src[200]; | ||
volatile int n; | ||
|
||
__attribute__((noinline)) void foo() {} | ||
|
||
__attribute__((noinline)) void bar() { | ||
f0 = foo; | ||
f1 = foo; | ||
f2 = foo; | ||
n = 4; | ||
} | ||
int main(int argc, char *argv[]) { | ||
int i; | ||
bar(); | ||
if (argc == 1) { | ||
f0(); | ||
for (i = 0; i < 9; i++) | ||
f1(); | ||
for (i = 0; i < 99; i++) | ||
f2(); | ||
} else { | ||
memcpy((void *)dst, (void *)src, n); | ||
for (i = 0; i < 6; i++) | ||
memcpy((void *)(dst + 2), (void *)src, n + 1); | ||
for (i = 0; i < 66; i++) | ||
memcpy((void *)(dst + 9), (void *)src, n + 2); | ||
} | ||
} | ||
|
||
// CHECK: Counters: | ||
// CHECK: main: | ||
// CHECK: Hash: 0x0a9bd81e87ab6e87 | ||
// CHECK: Counters: 6 | ||
// CHECK: Indirect Call Site Count: 3 | ||
// CHECK: Number of Memory Intrinsics Calls: 3 | ||
// CHECK: Block counts: [27, 297, 12, 132, 3, 2] | ||
// CHECK: Indirect Target Results: | ||
// CHECK: [ 0, foo, 3 ] | ||
// CHECK: [ 1, foo, 27 ] | ||
// CHECK: [ 2, foo, 297 ] | ||
// CHECK: Memory Intrinsic Size Results: | ||
// CHECK: [ 0, 4, 2 ] | ||
// CHECK: [ 1, 5, 12 ] | ||
// CHECK: [ 2, 6, 132 ] | ||
// CHECK: Instrumentation level: IR | ||
// CHECK: Functions shown: 1 | ||
// CHECK: Total functions: 3 | ||
// CHECK: Maximum function count: 327 | ||
// CHECK: Maximum internal block count: 297 | ||
// CHECK: Statistics for indirect call sites profile: | ||
// CHECK: Total number of sites: 3 | ||
// CHECK: Total number of sites with values: 3 | ||
// CHECK: Total number of profiled values: 3 | ||
// CHECK: Value sites histogram: | ||
// CHECK: NumTargets, SiteCount | ||
// CHECK: 1, 3 | ||
// CHECK: Statistics for memory intrinsic calls sizes profile: | ||
// CHECK: Total number of sites: 3 | ||
// CHECK: Total number of sites with values: 3 | ||
// CHECK: Total number of profiled values: 3 | ||
// CHECK: Value sites histogram: | ||
// CHECK: NumTargets, SiteCount | ||
// CHECK: 1, 3 |
10 changes: 10 additions & 0 deletions
10
compiler-rt/test/profile/Linux/instrprof-value-merge-lld.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// REQUIRES: lld-available | ||
|
||
// RUN: %clang_pgogen -o %t -O3 %S/Inputs/instrprof-value-merge.c -fuse-ld=lld -ffunction-sections -fdata-sections -Wl,--gc-sections -z start-stop-gc | ||
// RUN: rm -rf %t.profdir | ||
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t | ||
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t | ||
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t | ||
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t 1 | ||
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t 1 | ||
// RUN: llvm-profdata show -counts -function=main -ic-targets -memop-sizes %t.profdir/default_*.profraw | FileCheck %S/Inputs/instrprof-value-merge.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,27 @@ | ||
// RUN: %clang_pgogen -o %t -O3 %s | ||
// RUN: %clang_pgogen -o %t -O3 %S/Inputs/instrprof-value-merge.c | ||
// RUN: rm -rf %t.profdir | ||
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t | ||
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t | ||
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t | ||
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t 1 | ||
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t 1 | ||
// RUN: llvm-profdata show -counts -function=main -ic-targets -memop-sizes %t.profdir/default_*.profraw | FileCheck %s | ||
// RUN: llvm-profdata show -counts -function=main -ic-targets -memop-sizes %t.profdir/default_*.profraw | FileCheck %S/Inputs/instrprof-value-merge.c | ||
|
||
#include <string.h> | ||
|
||
void (*f0)(); | ||
void (*f1)(); | ||
void (*f2)(); | ||
|
||
char dst[200]; | ||
char src[200]; | ||
volatile int n; | ||
|
||
__attribute__((noinline)) void foo() {} | ||
|
||
__attribute__((noinline)) void bar() { | ||
f0 = foo; | ||
f1 = foo; | ||
f2 = foo; | ||
n = 4; | ||
} | ||
int main(int argc, char *argv[]) { | ||
int i; | ||
bar(); | ||
if (argc == 1) { | ||
f0(); | ||
for (i = 0; i < 9; i++) | ||
f1(); | ||
for (i = 0; i < 99; i++) | ||
f2(); | ||
} else { | ||
memcpy((void *)dst, (void *)src, n); | ||
for (i = 0; i < 6; i++) | ||
memcpy((void *)(dst + 2), (void *)src, n + 1); | ||
for (i = 0; i < 66; i++) | ||
memcpy((void *)(dst + 9), (void *)src, n + 2); | ||
} | ||
} | ||
/// -z start-stop-gc requires binutils 2.37. | ||
// RUN: %clang_pgogen -o %t -O3 %S/Inputs/instrprof-value-merge.c -fuse-ld=bfd -ffunction-sections -fdata-sections -Wl,--gc-sections | ||
// RUN: rm -rf %t.profdir | ||
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t | ||
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t | ||
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t | ||
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t 1 | ||
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t 1 | ||
// RUN: llvm-profdata show -counts -function=main -ic-targets -memop-sizes %t.profdir/default_*.profraw | FileCheck %S/Inputs/instrprof-value-merge.c | ||
|
||
// CHECK: Counters: | ||
// CHECK: main: | ||
// CHECK: Hash: 0x0a9bd81e87ab6e87 | ||
// CHECK: Counters: 6 | ||
// CHECK: Indirect Call Site Count: 3 | ||
// CHECK: Number of Memory Intrinsics Calls: 3 | ||
// CHECK: Block counts: [27, 297, 12, 132, 3, 2] | ||
// CHECK: Indirect Target Results: | ||
// CHECK: [ 0, foo, 3 ] | ||
// CHECK: [ 1, foo, 27 ] | ||
// CHECK: [ 2, foo, 297 ] | ||
// CHECK: Memory Intrinsic Size Results: | ||
// CHECK: [ 0, 4, 2 ] | ||
// CHECK: [ 1, 5, 12 ] | ||
// CHECK: [ 2, 6, 132 ] | ||
// CHECK: Instrumentation level: IR | ||
// CHECK: Functions shown: 1 | ||
// CHECK: Total functions: 3 | ||
// CHECK: Maximum function count: 327 | ||
// CHECK: Maximum internal block count: 297 | ||
// CHECK: Statistics for indirect call sites profile: | ||
// CHECK: Total number of sites: 3 | ||
// CHECK: Total number of sites with values: 3 | ||
// CHECK: Total number of profiled values: 3 | ||
// CHECK: Value sites histogram: | ||
// CHECK: NumTargets, SiteCount | ||
// CHECK: 1, 3 | ||
// CHECK: Statistics for memory intrinsic calls sizes profile: | ||
// CHECK: Total number of sites: 3 | ||
// CHECK: Total number of sites with values: 3 | ||
// CHECK: Total number of profiled values: 3 | ||
// CHECK: Value sites histogram: | ||
// CHECK: NumTargets, SiteCount | ||
// CHECK: 1, 3 | ||
// RUN: %clang_pgogen -o %t -O3 %S/Inputs/instrprof-value-merge.c -fuse-ld=gold -ffunction-sections -fdata-sections -Wl,--gc-sections | ||
// RUN: rm -rf %t.profdir | ||
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t | ||
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t | ||
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t | ||
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t 1 | ||
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t 1 | ||
// RUN: llvm-profdata show -counts -function=main -ic-targets -memop-sizes %t.profdir/default_*.profraw | FileCheck %S/Inputs/instrprof-value-merge.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters