1 /*===- InstrProfiling.c - Support library for PGO instrumentation ---------===*\
3 |* The LLVM Compiler Infrastructure
5 |* This file is distributed under the University of Illinois Open Source
6 |* License. See LICENSE.TXT for details.
8 \*===----------------------------------------------------------------------===*/
10 #include "InstrProfiling.h"
11 #include "InstrProfilingInternal.h"
16 #define INSTR_PROF_VALUE_PROF_DATA
17 #include "InstrProfData.inc"
20 COMPILER_RT_WEAK
uint64_t INSTR_PROF_RAW_VERSION_VAR
= INSTR_PROF_RAW_VERSION
;
22 COMPILER_RT_WEAK
char INSTR_PROF_PROFILE_NAME_VAR
[1] = {0};
24 COMPILER_RT_VISIBILITY
uint64_t __llvm_profile_get_magic(void) {
25 return sizeof(void *) == sizeof(uint64_t) ? (INSTR_PROF_RAW_MAGIC_64
)
26 : (INSTR_PROF_RAW_MAGIC_32
);
29 static unsigned ProfileDumped
= 0;
31 COMPILER_RT_VISIBILITY
unsigned lprofProfileDumped() {
35 COMPILER_RT_VISIBILITY
void lprofSetProfileDumped() {
39 /* Return the number of bytes needed to add to SizeInBytes to make it
40 * the result a multiple of 8.
42 COMPILER_RT_VISIBILITY
uint8_t
43 __llvm_profile_get_num_padding_bytes(uint64_t SizeInBytes
) {
44 return 7 & (sizeof(uint64_t) - SizeInBytes
% sizeof(uint64_t));
47 COMPILER_RT_VISIBILITY
uint64_t __llvm_profile_get_version(void) {
48 return __llvm_profile_raw_version
;
51 COMPILER_RT_VISIBILITY
void __llvm_profile_reset_counters(void) {
52 uint64_t *I
= __llvm_profile_begin_counters();
53 uint64_t *E
= __llvm_profile_end_counters();
55 memset(I
, 0, sizeof(uint64_t) * (E
- I
));
57 const __llvm_profile_data
*DataBegin
= __llvm_profile_begin_data();
58 const __llvm_profile_data
*DataEnd
= __llvm_profile_end_data();
59 const __llvm_profile_data
*DI
;
60 for (DI
= DataBegin
; DI
< DataEnd
; ++DI
) {
61 uint64_t CurrentVSiteCount
= 0;
66 ValueProfNode
**ValueCounters
= (ValueProfNode
**)DI
->Values
;
68 for (VKI
= IPVK_First
; VKI
<= IPVK_Last
; ++VKI
)
69 CurrentVSiteCount
+= DI
->NumValueSites
[VKI
];
71 for (i
= 0; i
< CurrentVSiteCount
; ++i
) {
72 ValueProfNode
*CurrentVNode
= ValueCounters
[i
];
74 while (CurrentVNode
) {
75 CurrentVNode
->Count
= 0;
76 CurrentVNode
= CurrentVNode
->Next
;