1*7c3d14c8STreehugger Robot /*===- InstrProfiling.c - Support library for PGO instrumentation ---------===*\ 2*7c3d14c8STreehugger Robot |* 3*7c3d14c8STreehugger Robot |* The LLVM Compiler Infrastructure 4*7c3d14c8STreehugger Robot |* 5*7c3d14c8STreehugger Robot |* This file is distributed under the University of Illinois Open Source 6*7c3d14c8STreehugger Robot |* License. See LICENSE.TXT for details. 7*7c3d14c8STreehugger Robot |* 8*7c3d14c8STreehugger Robot \*===----------------------------------------------------------------------===*/ 9*7c3d14c8STreehugger Robot 10*7c3d14c8STreehugger Robot #include "InstrProfiling.h" 11*7c3d14c8STreehugger Robot #include "InstrProfilingInternal.h" 12*7c3d14c8STreehugger Robot #include <limits.h> 13*7c3d14c8STreehugger Robot #include <stdio.h> 14*7c3d14c8STreehugger Robot #include <stdlib.h> 15*7c3d14c8STreehugger Robot #include <string.h> 16*7c3d14c8STreehugger Robot #define INSTR_PROF_VALUE_PROF_DATA 17*7c3d14c8STreehugger Robot #include "InstrProfData.inc" 18*7c3d14c8STreehugger Robot 19*7c3d14c8STreehugger Robot COMPILER_RT_VISIBILITY char *(*GetEnvHook)(const char *) = 0; 20*7c3d14c8STreehugger Robot 21*7c3d14c8STreehugger Robot COMPILER_RT_WEAK uint64_t __llvm_profile_raw_version = INSTR_PROF_RAW_VERSION; 22*7c3d14c8STreehugger Robot __llvm_profile_get_magic(void)23*7c3d14c8STreehugger RobotCOMPILER_RT_VISIBILITY uint64_t __llvm_profile_get_magic(void) { 24*7c3d14c8STreehugger Robot return sizeof(void *) == sizeof(uint64_t) ? (INSTR_PROF_RAW_MAGIC_64) 25*7c3d14c8STreehugger Robot : (INSTR_PROF_RAW_MAGIC_32); 26*7c3d14c8STreehugger Robot } 27*7c3d14c8STreehugger Robot 28*7c3d14c8STreehugger Robot /* Return the number of bytes needed to add to SizeInBytes to make it 29*7c3d14c8STreehugger Robot * the result a multiple of 8. 30*7c3d14c8STreehugger Robot */ 31*7c3d14c8STreehugger Robot COMPILER_RT_VISIBILITY uint8_t __llvm_profile_get_num_padding_bytes(uint64_t SizeInBytes)32*7c3d14c8STreehugger Robot__llvm_profile_get_num_padding_bytes(uint64_t SizeInBytes) { 33*7c3d14c8STreehugger Robot return 7 & (sizeof(uint64_t) - SizeInBytes % sizeof(uint64_t)); 34*7c3d14c8STreehugger Robot } 35*7c3d14c8STreehugger Robot __llvm_profile_get_version(void)36*7c3d14c8STreehugger RobotCOMPILER_RT_VISIBILITY uint64_t __llvm_profile_get_version(void) { 37*7c3d14c8STreehugger Robot return __llvm_profile_raw_version; 38*7c3d14c8STreehugger Robot } 39*7c3d14c8STreehugger Robot __llvm_profile_reset_counters(void)40*7c3d14c8STreehugger RobotCOMPILER_RT_VISIBILITY void __llvm_profile_reset_counters(void) { 41*7c3d14c8STreehugger Robot uint64_t *I = __llvm_profile_begin_counters(); 42*7c3d14c8STreehugger Robot uint64_t *E = __llvm_profile_end_counters(); 43*7c3d14c8STreehugger Robot 44*7c3d14c8STreehugger Robot memset(I, 0, sizeof(uint64_t) * (E - I)); 45*7c3d14c8STreehugger Robot 46*7c3d14c8STreehugger Robot const __llvm_profile_data *DataBegin = __llvm_profile_begin_data(); 47*7c3d14c8STreehugger Robot const __llvm_profile_data *DataEnd = __llvm_profile_end_data(); 48*7c3d14c8STreehugger Robot const __llvm_profile_data *DI; 49*7c3d14c8STreehugger Robot for (DI = DataBegin; DI < DataEnd; ++DI) { 50*7c3d14c8STreehugger Robot uint64_t CurrentVSiteCount = 0; 51*7c3d14c8STreehugger Robot uint32_t VKI, i; 52*7c3d14c8STreehugger Robot if (!DI->Values) 53*7c3d14c8STreehugger Robot continue; 54*7c3d14c8STreehugger Robot 55*7c3d14c8STreehugger Robot ValueProfNode **ValueCounters = (ValueProfNode **)DI->Values; 56*7c3d14c8STreehugger Robot 57*7c3d14c8STreehugger Robot for (VKI = IPVK_First; VKI <= IPVK_Last; ++VKI) 58*7c3d14c8STreehugger Robot CurrentVSiteCount += DI->NumValueSites[VKI]; 59*7c3d14c8STreehugger Robot 60*7c3d14c8STreehugger Robot for (i = 0; i < CurrentVSiteCount; ++i) { 61*7c3d14c8STreehugger Robot ValueProfNode *CurrentVNode = ValueCounters[i]; 62*7c3d14c8STreehugger Robot 63*7c3d14c8STreehugger Robot while (CurrentVNode) { 64*7c3d14c8STreehugger Robot CurrentVNode->Count = 0; 65*7c3d14c8STreehugger Robot CurrentVNode = CurrentVNode->Next; 66*7c3d14c8STreehugger Robot } 67*7c3d14c8STreehugger Robot } 68*7c3d14c8STreehugger Robot } 69*7c3d14c8STreehugger Robot } 70