summaryrefslogtreecommitdiff
path: root/test/profile
diff options
context:
space:
mode:
authorXinliang David Li <davidxl@google.com>2016-08-09 04:21:14 +0000
committerXinliang David Li <davidxl@google.com>2016-08-09 04:21:14 +0000
commit662d5497c3a4fbcdbf125d109f4abe5a9385cc20 (patch)
tree75caffb22007df93d6a22f8424a6ee34ffe3e2d0 /test/profile
parent97809160002d2a275a04e62313e55f1607fde234 (diff)
[Profile] Implement new API __llvm_profile_dump
The API is intended to be used by user to do fine grained (per-region) control of profile dumping. Differential Revision: http://reviews.llvm.org/D23106 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@278092 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/profile')
-rw-r--r--test/profile/instrprof-dump.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/test/profile/instrprof-dump.c b/test/profile/instrprof-dump.c
new file mode 100644
index 000000000..93c3c46f6
--- /dev/null
+++ b/test/profile/instrprof-dump.c
@@ -0,0 +1,62 @@
+/*
+RUN: rm -fr %t.profdir
+RUN: %clang_profgen=%t.profdir/default_%m.profraw -o %t -O2 %s
+RUN: %run %t 2>&1 | FileCheck %s --check-prefix=NO_EXIT_WRITE
+RUN: llvm-profdata merge -o %t.profdata %t.profdir
+RUN: %clang_profuse=%t.profdata -o - -S -emit-llvm %s | FileCheck %s --check-prefix=PROF
+
+NO_EXIT_WRITE: Profile data not written to file: already written
+*/
+
+int __llvm_profile_dump(void);
+void __llvm_profile_reset_counters(void);
+int foo(int);
+int bar(int);
+int skip(int);
+
+int main(int argc, const char *argv[]) {
+ int Ret = foo(0); /* region 1 */
+ __llvm_profile_dump();
+
+ /* not profiled -- cleared later. */
+ skip(0); /* skipped region */
+
+ __llvm_profile_reset_counters();
+ Ret += bar(0); /* region 2 */
+ __llvm_profile_dump();
+
+ skip(1);
+
+ __llvm_profile_reset_counters();
+ /* foo's profile will be merged. */
+ foo(1); /* region 3 */
+ __llvm_profile_dump();
+
+ return Ret;
+}
+
+__attribute__((noinline)) int foo(int X) {
+ /* PROF: define {{.*}} @foo({{.*}}!prof ![[ENT:[0-9]+]]
+ PROF: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !prof ![[PD1:[0-9]+]]
+ */
+ return X <= 0 ? -X : X;
+}
+
+__attribute__((noinline)) int skip(int X) {
+ /* PROF: define {{.*}} @skip(
+ PROF: br i1 %{{.*}}, label %{{.*}}, label %{{[^,]+$}}
+ */
+ return X <= 0 ? -X : X;
+}
+
+__attribute__((noinline)) int bar(int X) {
+ /* PROF-LABEL: define {{.*}} @bar(
+ PROF: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !prof ![[PD2:[0-9]+]]
+ */
+ return X <= 0 ? -X : X;
+}
+
+/*
+PROF: ![[ENT]] = !{!"function_entry_count", i64 2}
+PROF: ![[PD1]] = !{!"branch_weights", i32 2, i32 2}
+*/