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"
19 char *(*GetEnvHook)(const char *) = 0;
21 COMPILER_RT_WEAK uint64_t __llvm_profile_raw_version = INSTR_PROF_RAW_VERSION;
23 COMPILER_RT_VISIBILITY uint64_t __llvm_profile_get_magic(void) {
24 return sizeof(void *) == sizeof(uint64_t) ? (INSTR_PROF_RAW_MAGIC_64)
25 : (INSTR_PROF_RAW_MAGIC_32);
28 /* Return the number of bytes needed to add to SizeInBytes to make it
29 * the result a multiple of 8.
31 COMPILER_RT_VISIBILITY uint8_t
32 __llvm_profile_get_num_padding_bytes(uint64_t SizeInBytes) {
33 return 7 & (sizeof(uint64_t) - SizeInBytes % sizeof(uint64_t));
36 COMPILER_RT_VISIBILITY uint64_t __llvm_profile_get_version(void) {
37 return __llvm_profile_raw_version;
40 COMPILER_RT_VISIBILITY void __llvm_profile_reset_counters(void) {
41 uint64_t *I = __llvm_profile_begin_counters();
42 uint64_t *E = __llvm_profile_end_counters();
44 memset(I, 0, sizeof(uint64_t) * (E - I));
46 const __llvm_profile_data *DataBegin = __llvm_profile_begin_data();
47 const __llvm_profile_data *DataEnd = __llvm_profile_end_data();
48 const __llvm_profile_data *DI;
49 for (DI = DataBegin; DI != DataEnd; ++DI) {
50 uint64_t CurrentVSiteCount = 0;
55 ValueProfNode **ValueCounters = (ValueProfNode **)DI->Values;
57 for (VKI = IPVK_First; VKI <= IPVK_Last; ++VKI)
58 CurrentVSiteCount += DI->NumValueSites[VKI];
60 for (i = 0; i < CurrentVSiteCount; ++i) {
61 ValueProfNode *CurrentVNode = ValueCounters[i];
63 while (CurrentVNode) {
64 CurrentVNode->VData.Count = 0;
65 CurrentVNode = CurrentVNode->Next;