2014-03-20 06:10:27 +08:00
|
|
|
/*===- InstrProfiling.c - Support library for PGO instrumentation ---------===*\
|
|
|
|
|*
|
|
|
|
|* The LLVM Compiler Infrastructure
|
|
|
|
|*
|
|
|
|
|* This file is distributed under the University of Illinois Open Source
|
|
|
|
|* License. See LICENSE.TXT for details.
|
|
|
|
|*
|
|
|
|
\*===----------------------------------------------------------------------===*/
|
|
|
|
|
|
|
|
#include "InstrProfiling.h"
|
2015-12-11 03:50:04 +08:00
|
|
|
#include "InstrProfilingInternal.h"
|
2015-11-19 02:12:35 +08:00
|
|
|
#include <limits.h>
|
2015-12-04 09:02:24 +08:00
|
|
|
#include <stdio.h>
|
2015-11-19 02:12:35 +08:00
|
|
|
#include <stdlib.h>
|
2014-03-21 03:44:31 +08:00
|
|
|
#include <string.h>
|
2015-12-04 09:02:24 +08:00
|
|
|
#define INSTR_PROF_VALUE_PROF_DATA
|
|
|
|
#include "InstrProfData.inc"
|
|
|
|
|
2015-12-08 05:18:16 +08:00
|
|
|
char *(*GetEnvHook)(const char *) = 0;
|
|
|
|
|
2016-01-09 07:31:57 +08:00
|
|
|
COMPILER_RT_WEAK uint64_t __llvm_profile_raw_version = INSTR_PROF_RAW_VERSION;
|
|
|
|
|
2015-12-16 11:29:15 +08:00
|
|
|
COMPILER_RT_VISIBILITY uint64_t __llvm_profile_get_magic(void) {
|
2015-11-24 01:26:53 +08:00
|
|
|
return sizeof(void *) == sizeof(uint64_t) ? (INSTR_PROF_RAW_MAGIC_64)
|
|
|
|
: (INSTR_PROF_RAW_MAGIC_32);
|
2014-03-22 02:25:56 +08:00
|
|
|
}
|
2014-03-21 08:27:50 +08:00
|
|
|
|
2015-11-19 05:54:40 +08:00
|
|
|
/* Return the number of bytes needed to add to SizeInBytes to make it
|
2015-11-19 06:09:41 +08:00
|
|
|
* the result a multiple of 8.
|
|
|
|
*/
|
2015-12-16 11:29:15 +08:00
|
|
|
COMPILER_RT_VISIBILITY uint8_t
|
2015-11-19 05:54:40 +08:00
|
|
|
__llvm_profile_get_num_padding_bytes(uint64_t SizeInBytes) {
|
2015-11-19 02:12:35 +08:00
|
|
|
return 7 & (sizeof(uint64_t) - SizeInBytes % sizeof(uint64_t));
|
|
|
|
}
|
|
|
|
|
2015-12-16 11:29:15 +08:00
|
|
|
COMPILER_RT_VISIBILITY uint64_t __llvm_profile_get_version(void) {
|
2016-01-09 07:31:57 +08:00
|
|
|
return __llvm_profile_raw_version;
|
2014-03-20 06:10:27 +08:00
|
|
|
}
|
|
|
|
|
2015-12-16 11:29:15 +08:00
|
|
|
COMPILER_RT_VISIBILITY void __llvm_profile_reset_counters(void) {
|
2014-09-04 23:45:31 +08:00
|
|
|
uint64_t *I = __llvm_profile_begin_counters();
|
|
|
|
uint64_t *E = __llvm_profile_end_counters();
|
2014-03-21 03:44:31 +08:00
|
|
|
|
2015-11-19 05:54:40 +08:00
|
|
|
memset(I, 0, sizeof(uint64_t) * (E - I));
|
2015-11-19 02:12:35 +08:00
|
|
|
|
|
|
|
const __llvm_profile_data *DataBegin = __llvm_profile_begin_data();
|
|
|
|
const __llvm_profile_data *DataEnd = __llvm_profile_end_data();
|
2015-11-19 04:20:15 +08:00
|
|
|
const __llvm_profile_data *DI;
|
|
|
|
for (DI = DataBegin; DI != DataEnd; ++DI) {
|
|
|
|
uint64_t CurrentVSiteCount = 0;
|
|
|
|
uint32_t VKI, i;
|
2015-11-21 03:41:02 +08:00
|
|
|
if (!DI->Values)
|
2015-11-19 02:12:35 +08:00
|
|
|
continue;
|
|
|
|
|
2015-11-21 03:41:02 +08:00
|
|
|
ValueProfNode **ValueCounters = (ValueProfNode **)DI->Values;
|
|
|
|
|
|
|
|
for (VKI = IPVK_First; VKI <= IPVK_Last; ++VKI)
|
2015-11-19 02:12:35 +08:00
|
|
|
CurrentVSiteCount += DI->NumValueSites[VKI];
|
|
|
|
|
2015-11-19 04:20:15 +08:00
|
|
|
for (i = 0; i < CurrentVSiteCount; ++i) {
|
2015-11-21 03:41:02 +08:00
|
|
|
ValueProfNode *CurrentVNode = ValueCounters[i];
|
2015-11-19 02:12:35 +08:00
|
|
|
|
|
|
|
while (CurrentVNode) {
|
2015-11-24 01:09:40 +08:00
|
|
|
CurrentVNode->VData.Count = 0;
|
2015-11-19 02:12:35 +08:00
|
|
|
CurrentVNode = CurrentVNode->Next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|