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.
|
|
|
|
|*
|
|
|
|
\*===----------------------------------------------------------------------===*/
|
|
|
|
|
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>
|
2017-12-15 03:01:04 +08:00
|
|
|
|
|
|
|
#include "InstrProfiling.h"
|
|
|
|
#include "InstrProfilingInternal.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
|
|
|
|
2016-07-22 12:08:16 +08:00
|
|
|
COMPILER_RT_WEAK uint64_t INSTR_PROF_RAW_VERSION_VAR = INSTR_PROF_RAW_VERSION;
|
2016-01-09 07:31:57 +08:00
|
|
|
|
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
|
|
|
|
2016-08-09 12:21:14 +08:00
|
|
|
static unsigned ProfileDumped = 0;
|
|
|
|
|
|
|
|
COMPILER_RT_VISIBILITY unsigned lprofProfileDumped() {
|
|
|
|
return ProfileDumped;
|
|
|
|
}
|
|
|
|
|
|
|
|
COMPILER_RT_VISIBILITY void lprofSetProfileDumped() {
|
|
|
|
ProfileDumped = 1;
|
|
|
|
}
|
|
|
|
|
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;
|
2016-02-24 04:46:14 +08:00
|
|
|
for (DI = DataBegin; DI < DataEnd; ++DI) {
|
2015-11-19 04:20:15 +08:00
|
|
|
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) {
|
2016-05-17 04:33:30 +08:00
|
|
|
CurrentVNode->Count = 0;
|
2015-11-19 02:12:35 +08:00
|
|
|
CurrentVNode = CurrentVNode->Next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-08-09 12:21:14 +08:00
|
|
|
ProfileDumped = 0;
|
2015-11-19 02:12:35 +08:00
|
|
|
}
|