aboutsummaryrefslogtreecommitdiff
path: root/test/profile/instrprof-value-prof-2.c
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2015-12-30 11:52:19 +0000
committerDimitry Andric <dim@FreeBSD.org>2015-12-30 11:52:19 +0000
commit5c909fa013fc285f010a95e8d387e0ef3412da9c (patch)
tree1059d068ad281f4776ff44cd414574f99a460023 /test/profile/instrprof-value-prof-2.c
parentf31bcc68c72371a2bf63aead9f3373a1ff2053b6 (diff)
downloadsrc-5c909fa013fc285f010a95e8d387e0ef3412da9c.tar.gz
src-5c909fa013fc285f010a95e8d387e0ef3412da9c.zip
Vendor import of compiler-rt trunk r256633:vendor/compiler-rt/compiler-rt-trunk-r256633
Notes
Notes: svn path=/vendor/compiler-rt/dist/; revision=292925 svn path=/vendor/compiler-rt/compiler-rt-trunk-r256633/; revision=292926; tag=vendor/compiler-rt/compiler-rt-trunk-r256633
Diffstat (limited to 'test/profile/instrprof-value-prof-2.c')
-rw-r--r--test/profile/instrprof-value-prof-2.c135
1 files changed, 135 insertions, 0 deletions
diff --git a/test/profile/instrprof-value-prof-2.c b/test/profile/instrprof-value-prof-2.c
new file mode 100644
index 000000000000..989353e1f53e
--- /dev/null
+++ b/test/profile/instrprof-value-prof-2.c
@@ -0,0 +1,135 @@
+// RUN: %clang_profgen -O2 -o %t %s
+// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t
+// RUN: llvm-profdata merge -o %t.profdata %t.profraw
+// RUN: llvm-profdata show --all-functions -ic-targets %t.profdata | FileCheck %s
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+typedef struct __llvm_profile_data __llvm_profile_data;
+const __llvm_profile_data *__llvm_profile_begin_data(void);
+const __llvm_profile_data *__llvm_profile_end_data(void);
+void __llvm_profile_set_num_value_sites(__llvm_profile_data *Data,
+ uint32_t ValueKind,
+ uint16_t NumValueSites);
+__llvm_profile_data *
+__llvm_profile_iterate_data(const __llvm_profile_data *Data);
+void *__llvm_get_function_addr(const __llvm_profile_data *Data);
+void __llvm_profile_instrument_target(uint64_t TargetValue, void *Data,
+ uint32_t CounterIndex);
+void callee1() {}
+void callee2() {}
+
+void caller_without_value_site1() {}
+void caller_with_value_site_never_called1() {}
+void caller_with_vp1() {}
+void caller_with_value_site_never_called2() {}
+void caller_without_value_site2() {}
+void caller_with_vp2() {}
+
+int main(int argc, const char *argv[]) {
+ unsigned S, NS = 10, V;
+ const __llvm_profile_data *Data, *DataEnd;
+
+ Data = __llvm_profile_begin_data();
+ DataEnd = __llvm_profile_end_data();
+ for (; Data < DataEnd; Data = __llvm_profile_iterate_data(Data)) {
+ void *func = __llvm_get_function_addr(Data);
+ if (func == caller_without_value_site1 ||
+ func == caller_without_value_site2 ||
+ func == callee1 || func == callee2 || func == main)
+ continue;
+
+ __llvm_profile_set_num_value_sites((__llvm_profile_data *)Data,
+ 0 /*IPVK_IndirectCallTarget */, 10);
+
+ if (func == caller_with_value_site_never_called1 ||
+ func == caller_with_value_site_never_called2)
+ continue;
+ for (S = 0; S < NS; S++) {
+ unsigned C;
+ for (C = 0; C < S + 1; C++) {
+ __llvm_profile_instrument_target((uint64_t)&callee1, (void *)Data, S);
+ if (C % 2 == 0)
+ __llvm_profile_instrument_target((uint64_t)&callee2, (void *)Data, S);
+ }
+ }
+ }
+}
+
+// CHECK-LABEL: caller_with_value_site_never_called2:
+// CHECK-NEXT: Hash: 0x0000000000000000
+// CHECK-NEXT: Counters:
+// CHECK-NEXT: Function count
+// CHECK-NEXT: Indirect Call Site Count: 10
+// CHECK-NEXT: Indirect Target Results:
+// CHECK-LABEL: caller_with_vp2:
+// CHECK-NEXT: Hash: 0x0000000000000000
+// CHECK-NEXT: Counters:
+// CHECK-NEXT: Function count:
+// CHECK-NEXT: Indirect Call Site Count: 10
+// CHECK-NEXT: Indirect Target Results:
+// CHECK-NEXT: [ 0, callee1, 1 ]
+// CHECK-NEXT: [ 0, callee2, 1 ]
+// CHECK-NEXT: [ 1, callee1, 2 ]
+// CHECK-NEXT: [ 1, callee2, 1 ]
+// CHECK-NEXT: [ 2, callee1, 3 ]
+// CHECK-NEXT: [ 2, callee2, 2 ]
+// CHECK-NEXT: [ 3, callee1, 4 ]
+// CHECK-NEXT: [ 3, callee2, 2 ]
+// CHECK-NEXT: [ 4, callee1, 5 ]
+// CHECK-NEXT: [ 4, callee2, 3 ]
+// CHECK-NEXT: [ 5, callee1, 6 ]
+// CHECK-NEXT: [ 5, callee2, 3 ]
+// CHECK-NEXT: [ 6, callee1, 7 ]
+// CHECK-NEXT: [ 6, callee2, 4 ]
+// CHECK-NEXT: [ 7, callee1, 8 ]
+// CHECK-NEXT: [ 7, callee2, 4 ]
+// CHECK-NEXT: [ 8, callee1, 9 ]
+// CHECK-NEXT: [ 8, callee2, 5 ]
+// CHECK-NEXT: [ 9, callee1, 10 ]
+// CHECK-NEXT: [ 9, callee2, 5 ]
+// CHECK-LABEL: caller_with_vp1:
+// CHECK-NEXT: Hash: 0x0000000000000000
+// CHECK-NEXT: Counters:
+// CHECK-NEXT: Function count
+// CHECK-NEXT: Indirect Call Site Count: 10
+// CHECK-NEXT: Indirect Target Results:
+// CHECK-NEXT: [ 0, callee1, 1 ]
+// CHECK-NEXT: [ 0, callee2, 1 ]
+// CHECK-NEXT: [ 1, callee1, 2 ]
+// CHECK-NEXT: [ 1, callee2, 1 ]
+// CHECK-NEXT: [ 2, callee1, 3 ]
+// CHECK-NEXT: [ 2, callee2, 2 ]
+// CHECK-NEXT: [ 3, callee1, 4 ]
+// CHECK-NEXT: [ 3, callee2, 2 ]
+// CHECK-NEXT: [ 4, callee1, 5 ]
+// CHECK-NEXT: [ 4, callee2, 3 ]
+// CHECK-NEXT: [ 5, callee1, 6 ]
+// CHECK-NEXT: [ 5, callee2, 3 ]
+// CHECK-NEXT: [ 6, callee1, 7 ]
+// CHECK-NEXT: [ 6, callee2, 4 ]
+// CHECK-NEXT: [ 7, callee1, 8 ]
+// CHECK-NEXT: [ 7, callee2, 4 ]
+// CHECK-NEXT: [ 8, callee1, 9 ]
+// CHECK-NEXT: [ 8, callee2, 5 ]
+// CHECK-NEXT: [ 9, callee1, 10 ]
+// CHECK-NEXT: [ 9, callee2, 5 ]
+// CHECK-LABEL: caller_with_value_site_never_called1:
+// CHECK-NEXT: Hash: 0x0000000000000000
+// CHECK-NEXT: Counters:
+// CHECK-NEXT: Function count:
+// CHECK-NEXT: Indirect Call Site Count: 10
+// CHECK-NEXT: Indirect Target Results:
+// CHECK-LABEL: caller_without_value_site2:
+// CHECK-NEXT: Hash: 0x0000000000000000
+// CHECK-NEXT: Counters:
+// CHECK-NEXT: Function count:
+// CHECK-NEXT: Indirect Call Site Count: 0
+// CHECK-NEXT: Indirect Target Results:
+// CHECK-LABEL: caller_without_value_site1:
+// CHECK-NEXT: Hash: 0x0000000000000000
+// CHECK-NEXT: Counters:
+// CHECK-NEXT: Function count:
+// CHECK-NEXT: Indirect Call Site Count: 0
+// CHECK-NEXT: Indirect Target Results: