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