1 // RUN: %clang_profgen -mllvm --enable-value-profiling=true -mllvm -vp-static-alloc=true -mllvm -vp-counters-per-site=3 -O2 -o %t %s
2 // RUN: %run %t %t.profraw
3 // RUN: llvm-profdata merge -o %t.profdata %t.profraw
4 // RUN: llvm-profdata show --all-functions --counts --ic-targets %t.profdata > %t.profdump
5 // RUN: FileCheck --input-file %t.profdump %s --check-prefix=FOO
6 // RUN: FileCheck --input-file %t.profdump %s --check-prefix=BAR
11 #include <sys/types.h>
14 int __llvm_profile_runtime
= 0;
15 int __llvm_profile_write_file();
16 void __llvm_profile_reset_counters(void);
17 int __llvm_profile_merge_from_buffer(const char *, uint64_t);
18 void __llvm_profile_set_filename(const char *);
19 struct __llvm_profile_data
;
21 void lprofMergeValueProfData(struct ValueProfData
*, struct __llvm_profile_data
*);
22 /* Force the vp merger module to be linked in. */
23 void *Dummy
= &lprofMergeValueProfData
;
29 typedef void (*FP
)(void);
30 FP Fps
[3] = {callee1
, callee2
, callee3
};
34 for (I
= 0; I
< 3; I
++)
35 for (J
= 0; J
< I
* 2 + 1; J
++)
41 for (I
= 0; I
< 3; I
++)
42 for (J
= 0; J
< I
* 2 + 1; J
++)
46 /* This function is not profiled */
49 for (I
= 0; I
< 20; I
++)
53 int main(int argc
, const char *argv
[]) {
58 const char *FileN
= argv
[1];
59 __llvm_profile_set_filename(FileN
);
60 /* Start profiling. */
61 __llvm_profile_reset_counters();
63 /* End profiling by freezing counters and
64 * dump them to the file. */
65 if (__llvm_profile_write_file())
68 /* Read profile data into buffer. */
69 FILE *File
= fopen(FileN
, "r");
72 fseek(File
, 0, SEEK_END
);
73 uint64_t Size
= ftell(File
);
74 fseek(File
, 0, SEEK_SET
);
75 char *Buffer
= (char *)malloc(Size
);
76 if (Size
!= fread(Buffer
, 1, Size
, File
))
80 /* Its profile will be discarded. */
81 for (i
= 0; i
< 10; i
++)
84 /* Start profiling again and merge in previously
85 saved counters in buffer. */
86 __llvm_profile_reset_counters();
87 __llvm_profile_merge_from_buffer(Buffer
, Size
);
91 if (__llvm_profile_write_file())
94 /* Its profile will be discarded. */
101 // FOO: Indirect Target Results:
102 // FOO-NEXT: [ 0, callee3, 10 ]
103 // FOO-NEXT: [ 0, callee2, 6 ]
104 // FOO-NEXT: [ 0, callee1, 2 ]
105 // FOO-NEXT: [ 1, callee1, 5 ]
106 // FOO-NEXT: [ 1, callee2, 3 ]
107 // FOO-NEXT: [ 1, callee3, 1 ]
110 // BAR: [ 0, callee1, 0 ]
111 // BAR-NEXT: [ 0, callee2, 0 ]
112 // BAR-NEXT: [ 0, callee3, 0 ]