summaryrefslogtreecommitdiff
path: root/test/profile
diff options
context:
space:
mode:
authorVedant Kumar <vsk@apple.com>2016-10-11 21:48:48 +0000
committerVedant Kumar <vsk@apple.com>2016-10-11 21:48:48 +0000
commitab31f66db3be38eac83671a23b60d61fdc9ee51f (patch)
treee8ef1777a7fba24f8bd1300296bd2f6c06965eda /test/profile
parent2232cef62de7658bc0356ea1de79c2fe3226ad82 (diff)
[profile] Add test for dead_strip+live_support functionality
Differential Revision: https://reviews.llvm.org/D25457 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@283948 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/profile')
-rw-r--r--test/profile/instrprof-darwin-dead-strip.c60
-rw-r--r--test/profile/lit.cfg11
2 files changed, 69 insertions, 2 deletions
diff --git a/test/profile/instrprof-darwin-dead-strip.c b/test/profile/instrprof-darwin-dead-strip.c
new file mode 100644
index 000000000..64a4895a9
--- /dev/null
+++ b/test/profile/instrprof-darwin-dead-strip.c
@@ -0,0 +1,60 @@
+// REQUIRES: osx-ld64-live_support
+// REQUIRES: lto
+
+// RUN: %clang_profgen=%t.profraw -fcoverage-mapping -mllvm -enable-name-compression=false -Wl,-dead_strip -o %t %s
+// RUN: %run %t
+// RUN: llvm-profdata merge -o %t.profdata %t.profraw
+// RUN: llvm-profdata show --all-functions %t.profdata | FileCheck %s -check-prefix=PROF
+// RUN: llvm-cov show %t -instr-profile %t.profdata | FileCheck %s -check-prefix=COV
+// RUN: nm %t | FileCheck %s -check-prefix=NM
+// RUN: otool -s __DATA __llvm_prf_names %t | FileCheck %s -check-prefix=PRF_NAMES
+// RUN: otool -s __DATA __llvm_prf_cnts %t | FileCheck %s -check-prefix=PRF_CNTS
+
+// RUN: %clang_lto_profgen=%t.lto.profraw -fcoverage-mapping -mllvm -enable-name-compression=false -Wl,-dead_strip -flto -o %t.lto %s
+// RUN: %run %t.lto
+// RUN: llvm-profdata merge -o %t.lto.profdata %t.lto.profraw
+// RUN: llvm-profdata show --all-functions %t.lto.profdata | FileCheck %s -check-prefix=PROF
+// RUN: llvm-cov show %t.lto -instr-profile %t.lto.profdata | FileCheck %s -check-prefix=COV
+// RUN: nm %t.lto | FileCheck %s -check-prefix=NM
+// RUN: otool -s __DATA __llvm_prf_names %t.lto | FileCheck %s -check-prefix=PRF_NAMES
+// RUN: otool -s __DATA __llvm_prf_cnts %t.lto | FileCheck %s -check-prefix=PRF_CNTS
+
+// Note: We expect foo() and some of the profiling data associated with it to
+// be dead-stripped.
+
+// COV: [[@LINE+1]]{{ *}}|{{ *}}0|void foo()
+void foo() {}
+
+// COV: [[@LINE+1]]{{ *}}|{{ *}}1|int main
+int main() { return 0; }
+
+// NM-NOT: foo
+
+// PROF: Counters:
+// PROF-NEXT: main:
+// PROF-NEXT: Hash:
+// PROF-NEXT: Counters: 1
+// PROF-NEXT: Function count: 1
+// PROF-NEXT: Functions shown: 1
+// PROF-NEXT: Total functions: 1
+// PROF-NEXT: Maximum function count: 1
+// PROF-NEXT: Maximum internal block count: 0
+
+// Note: We don't expect the names of dead-stripped functions to disappear from
+// __llvm_prf_names, because collectPGOFuncNameStrings() glues the names
+// together.
+
+// PRF_NAMES: Contents of (__DATA,__llvm_prf_names) section
+// PRF_NAMES-NEXT: {{.*}} 08 00 66 6f 6f 01 6d 61 69 6e{{ +$}}
+// | | f o o # m a i n
+// | |___________|
+// | |
+// UncompressedLen = 8 |
+// |
+// CompressedLen = 0
+
+// Note: We expect the profile counters for dead-stripped functions to also be
+// dead-stripped.
+
+// PRF_CNTS: Contents of (__DATA,__llvm_prf_cnts) section
+// PRF_CNTS-NEXT: {{.*}} 00 00 00 00 00 00 00 00{{ +$}}
diff --git a/test/profile/lit.cfg b/test/profile/lit.cfg
index b8968c448..a6e6ef81c 100644
--- a/test/profile/lit.cfg
+++ b/test/profile/lit.cfg
@@ -49,8 +49,13 @@ target_cflags=[get_required_attr(config, "target_cflags")]
clang_cflags = target_cflags + extra_linkflags
clang_cxxflags = config.cxx_mode_flags + clang_cflags
-def build_invocation(compile_flags):
- return " " + " ".join([config.clang] + compile_flags) + " "
+def build_invocation(compile_flags, with_lto = False):
+ lto_flags = []
+ lto_prefix = []
+ if with_lto and config.lto_supported:
+ lto_flags += config.lto_flags
+ lto_prefix += config.lto_launch
+ return " " + " ".join(lto_prefix + [config.clang] + lto_flags + compile_flags) + " "
# Add clang substitutions.
config.substitutions.append( ("%clang ", build_invocation(clang_cflags)) )
@@ -71,6 +76,8 @@ config.substitutions.append( ("%clang_profuse_gcc=", build_invocation(clang_cfla
config.substitutions.append( ("%clang_profuse=", build_invocation(clang_cflags) + " -fprofile-instr-use=") )
config.substitutions.append( ("%clangxx_profuse=", build_invocation(clang_cxxflags) + " -fprofile-instr-use=") )
+config.substitutions.append( ("%clang_lto_profgen=", build_invocation(clang_cflags, True) + " -fprofile-instr-generate=") )
+
if config.host_os not in ['Darwin', 'FreeBSD', 'Linux']:
config.unsupported = True