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