summaryrefslogtreecommitdiff
path: root/test/profile/instrprof-write-file-only.c
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2014-05-09 23:14:58 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2014-05-09 23:14:58 +0000
commit18d66b3c136a821b8aadabcd666f578da97a545b (patch)
tree8a76a917ad1f6b94c9c9d5121572e81e83769e17 /test/profile/instrprof-write-file-only.c
parent2e8e44123a1af21beacf1190fc9f9c8104088c5f (diff)
InstrProf: Test the functions in the runtime
Check that the profile runtime works as expected. This tests the functions that are meant to be available to advanced users. In particular, check that the `atexit()` hook can be disabled by defining a custom `__llvm_profile_runtime` variable, that the libc dependencies are optional, and that the various functions for writing out files work for basic cases. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@208460 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/profile/instrprof-write-file-only.c')
-rw-r--r--test/profile/instrprof-write-file-only.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/test/profile/instrprof-write-file-only.c b/test/profile/instrprof-write-file-only.c
new file mode 100644
index 000000000..b9a1be4c0
--- /dev/null
+++ b/test/profile/instrprof-write-file-only.c
@@ -0,0 +1,30 @@
+// RUN: %clang_profgen -o %t -O3 %s
+// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t
+// RUN: llvm-profdata merge -o %t.profdata %t.profraw
+// RUN: %clang_profuse=%t.profdata -o - -S -emit-llvm %s | FileCheck %s
+
+int __llvm_profile_runtime = 0;
+int __llvm_profile_write_file(void);
+void __llvm_profile_set_filename(const char *);
+int foo(int);
+int main(int argc, const char *argv[]) {
+ // CHECK-LABEL: define i32 @main
+ // CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !prof !1
+ if (argc > 1)
+ return 1;
+
+ // Write out the profile.
+ __llvm_profile_write_file();
+
+ // Change the profile.
+ return foo(0);
+}
+int foo(int X) {
+ // There should be no profiling information for @foo, since it was called
+ // after the profile was written (and the atexit was supressed by defining
+ // profile_runtime).
+ // CHECK-LABEL: define i32 @foo
+ // CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{[^,]+$}}
+ return X <= 0 ? -X : X;
+}
+// CHECK: !1 = metadata !{metadata !"branch_weights", i32 1, i32 2}