#ifndef INSTR_PROF_VISIBILITY
#define INSTR_PROF_VISIBILITY
#endif
#ifndef INSTR_PROF_DATA
#define INSTR_PROF_DATA …
#else
#define INSTR_PROF_DATA_DEFINED
#endif
INSTR_PROF_DATA
INSTR_PROF_DATA
INSTR_PROF_DATA
INSTR_PROF_DATA
INSTR_PROF_DATA
INSTR_PROF_DATA
INSTR_PROF_DATA
INSTR_PROF_DATA \
INSTR_PROF_DATA
#undef INSTR_PROF_DATA
#ifndef INSTR_PROF_VTABLE_DATA
#define INSTR_PROF_VTABLE_DATA …
#else
#define INSTR_PROF_VTABLE_DATA_DEFINED
#endif
INSTR_PROF_VTABLE_DATA
INSTR_PROF_VTABLE_DATA
INSTR_PROF_VTABLE_DATA
#undef INSTR_PROF_VTABLE_DATA
#ifndef INSTR_PROF_VALUE_NODE
#define INSTR_PROF_VALUE_NODE …
#else
#define INSTR_PROF_DATA_DEFINED
#endif
INSTR_PROF_VALUE_NODE
INSTR_PROF_VALUE_NODE
INSTR_PROF_VALUE_NODE
#undef INSTR_PROF_VALUE_NODE
#ifndef INSTR_PROF_RAW_HEADER
#define INSTR_PROF_RAW_HEADER …
#else
#define INSTR_PROF_DATA_DEFINED
#endif
INSTR_PROF_RAW_HEADER
INSTR_PROF_RAW_HEADER
INSTR_PROF_RAW_HEADER
INSTR_PROF_RAW_HEADER
INSTR_PROF_RAW_HEADER
INSTR_PROF_RAW_HEADER
INSTR_PROF_RAW_HEADER
INSTR_PROF_RAW_HEADER
INSTR_PROF_RAW_HEADER
INSTR_PROF_RAW_HEADER
INSTR_PROF_RAW_HEADER
INSTR_PROF_RAW_HEADER
INSTR_PROF_RAW_HEADER
INSTR_PROF_RAW_HEADER
INSTR_PROF_RAW_HEADER
INSTR_PROF_RAW_HEADER
#undef INSTR_PROF_RAW_HEADER
#ifndef VALUE_PROF_FUNC_PARAM
#define VALUE_PROF_FUNC_PARAM …
#define INSTR_PROF_COMMA
#else
#define INSTR_PROF_DATA_DEFINED
#define INSTR_PROF_COMMA …
#endif
VALUE_PROF_FUNC_PARAM \
INSTR_PROF_COMMA
VALUE_PROF_FUNC_PARAM INSTR_PROF_COMMA
VALUE_PROF_FUNC_PARAM
#undef VALUE_PROF_FUNC_PARAM
#undef INSTR_PROF_COMMA
#ifndef VALUE_PROF_KIND
#define VALUE_PROF_KIND …
#else
#define INSTR_PROF_DATA_DEFINED
#endif
VALUE_PROF_KIND
VALUE_PROF_KIND
VALUE_PROF_KIND
VALUE_PROF_KIND
VALUE_PROF_KIND
#undef VALUE_PROF_KIND
#undef COVMAP_V2_OR_V3
#ifdef COVMAP_V2
#define COVMAP_V2_OR_V3
#endif
#ifdef COVMAP_V3
#define COVMAP_V2_OR_V3
#endif
#ifndef COVMAP_FUNC_RECORD
#define COVMAP_FUNC_RECORD …
#else
#define INSTR_PROF_DATA_DEFINED
#endif
#ifdef COVMAP_V1
COVMAP_FUNC_RECORD(const IntPtrT, llvm::PointerType::getUnqual(Ctx), \
NamePtr, llvm::ConstantExpr::getBitCast(NamePtr, \
llvm::PointerType::getUnqual(Ctx)))
COVMAP_FUNC_RECORD(const uint32_t, llvm::Type::getInt32Ty(Ctx), NameSize, \
llvm::ConstantInt::get(llvm::Type::getInt32Ty(Ctx), \
NameValue.size()))
#endif
#ifdef COVMAP_V2_OR_V3
COVMAP_FUNC_RECORD(const int64_t, llvm::Type::getInt64Ty(Ctx), NameRef, \
llvm::ConstantInt::get( \
llvm::Type::getInt64Ty(Ctx), NameHash))
#endif
COVMAP_FUNC_RECORD
COVMAP_FUNC_RECORD
#ifdef COVMAP_V3
COVMAP_FUNC_RECORD(const uint64_t, llvm::Type::getInt64Ty(Ctx), FilenamesRef, \
llvm::ConstantInt::get( \
llvm::Type::getInt64Ty(Ctx), FilenamesRef))
COVMAP_FUNC_RECORD(const char, \
llvm::ArrayType::get(llvm::Type::getInt8Ty(Ctx), \
CoverageMapping.size()), \
CoverageMapping,
llvm::ConstantDataArray::getRaw( \
CoverageMapping, CoverageMapping.size(), \
llvm::Type::getInt8Ty(Ctx)))
#endif
#undef COVMAP_FUNC_RECORD
#ifndef COVMAP_HEADER
#define COVMAP_HEADER …
#else
#define INSTR_PROF_DATA_DEFINED
#endif
COVMAP_HEADER
COVMAP_HEADER
COVMAP_HEADER
COVMAP_HEADER
#undef COVMAP_HEADER
#ifdef INSTR_PROF_SECT_ENTRY
#define INSTR_PROF_DATA_DEFINED
INSTR_PROF_SECT_ENTRY(IPSK_data, \
INSTR_PROF_QUOTE(INSTR_PROF_DATA_COMMON), \
INSTR_PROF_DATA_COFF, "__DATA,")
INSTR_PROF_SECT_ENTRY(IPSK_cnts, \
INSTR_PROF_QUOTE(INSTR_PROF_CNTS_COMMON), \
INSTR_PROF_CNTS_COFF, "__DATA,")
INSTR_PROF_SECT_ENTRY(IPSK_bitmap, \
INSTR_PROF_QUOTE(INSTR_PROF_BITS_COMMON), \
INSTR_PROF_BITS_COFF, "__DATA,")
INSTR_PROF_SECT_ENTRY(IPSK_name, \
INSTR_PROF_QUOTE(INSTR_PROF_NAME_COMMON), \
INSTR_PROF_NAME_COFF, "__DATA,")
INSTR_PROF_SECT_ENTRY(IPSK_vname, \
INSTR_PROF_QUOTE(INSTR_PROF_VNAME_COMMON), \
INSTR_PROF_VNAME_COFF, "__DATA,")
INSTR_PROF_SECT_ENTRY(IPSK_vals, \
INSTR_PROF_QUOTE(INSTR_PROF_VALS_COMMON), \
INSTR_PROF_VALS_COFF, "__DATA,")
INSTR_PROF_SECT_ENTRY(IPSK_vnodes, \
INSTR_PROF_QUOTE(INSTR_PROF_VNODES_COMMON), \
INSTR_PROF_VNODES_COFF, "__DATA,")
INSTR_PROF_SECT_ENTRY(IPSK_vtab, \
INSTR_PROF_QUOTE(INSTR_PROF_VTAB_COMMON), \
INSTR_PROF_VTAB_COFF, "__DATA,")
INSTR_PROF_SECT_ENTRY(IPSK_covmap, \
INSTR_PROF_QUOTE(INSTR_PROF_COVMAP_COMMON), \
INSTR_PROF_COVMAP_COFF, "__LLVM_COV,")
INSTR_PROF_SECT_ENTRY(IPSK_covfun, \
INSTR_PROF_QUOTE(INSTR_PROF_COVFUN_COMMON), \
INSTR_PROF_COVFUN_COFF, "__LLVM_COV,")
INSTR_PROF_SECT_ENTRY(IPSK_orderfile, \
INSTR_PROF_QUOTE(INSTR_PROF_ORDERFILE_COMMON), \
INSTR_PROF_QUOTE(INSTR_PROF_ORDERFILE_COFF), "__DATA,")
INSTR_PROF_SECT_ENTRY(IPSK_covdata, \
INSTR_PROF_QUOTE(INSTR_PROF_COVDATA_COMMON), \
INSTR_PROF_COVDATA_COFF, "__LLVM_COV,")
INSTR_PROF_SECT_ENTRY(IPSK_covname, \
INSTR_PROF_QUOTE(INSTR_PROF_COVNAME_COMMON), \
INSTR_PROF_COVNAME_COFF, "__LLVM_COV,")
#undef INSTR_PROF_SECT_ENTRY
#endif
#ifdef INSTR_PROF_VALUE_PROF_DATA
#define INSTR_PROF_DATA_DEFINED
#define INSTR_PROF_MAX_NUM_VAL_PER_SITE …
typedef struct ValueProfRecord {
uint32_t Kind;
uint32_t NumValueSites;
uint8_t SiteCountArray[1];
#ifdef __cplusplus
uint32_t getNumValueSites() const { return NumValueSites; }
void deserializeTo(InstrProfRecord &Record,
InstrProfSymtab *SymTab);
void swapBytes(llvm::endianness Old, llvm::endianness New);
#endif
} ValueProfRecord;
typedef struct ValueProfData {
uint32_t TotalSize;
uint32_t NumValueKinds;
#if __cplusplus
static uint32_t getSize(const InstrProfRecord &Record);
static std::unique_ptr<ValueProfData>
serializeFrom(const InstrProfRecord &Record);
Error checkIntegrity();
static Expected<std::unique_ptr<ValueProfData>>
getValueProfData(const unsigned char *SrcBuffer,
const unsigned char *const SrcBufferEnd,
llvm::endianness SrcDataEndianness);
void swapBytesToHost(llvm::endianness Endianness);
void swapBytesFromHost(llvm::endianness Endianness);
uint32_t getSize() const { return TotalSize; }
void deserializeTo(InstrProfRecord &Record,
InstrProfSymtab *SymTab);
void operator delete(void *ptr) { ::operator delete(ptr); }
#endif
} ValueProfData;
typedef struct ValueProfRecordClosure {
const void *Record;
uint32_t (*GetNumValueKinds)(const void *Record);
uint32_t (*GetNumValueSites)(const void *Record, uint32_t VKind);
uint32_t (*GetNumValueData)(const void *Record, uint32_t VKind);
uint32_t (*GetNumValueDataForSite)(const void *R, uint32_t VK, uint32_t S);
uint64_t (*RemapValueData)(uint32_t, uint64_t Value);
void (*GetValueForSite)(const void *R, InstrProfValueData *Dst, uint32_t K,
uint32_t S);
ValueProfData *(*AllocValueProfData)(size_t TotalSizeInBytes);
} ValueProfRecordClosure;
INSTR_PROF_VISIBILITY ValueProfRecord *
getFirstValueProfRecord(ValueProfData *VPD);
INSTR_PROF_VISIBILITY ValueProfRecord *
getValueProfRecordNext(ValueProfRecord *VPR);
INSTR_PROF_VISIBILITY InstrProfValueData *
getValueProfRecordValueData(ValueProfRecord *VPR);
INSTR_PROF_VISIBILITY uint32_t
getValueProfRecordHeaderSize(uint32_t NumValueSites);
#undef INSTR_PROF_VALUE_PROF_DATA
#endif
#ifdef INSTR_PROF_COMMON_API_IMPL
#define INSTR_PROF_DATA_DEFINED
#ifdef __cplusplus
#define INSTR_PROF_INLINE …
#define INSTR_PROF_NULLPTR …
#else
#define INSTR_PROF_INLINE
#define INSTR_PROF_NULLPTR …
#endif
#ifndef offsetof
#define offsetof …
#endif
INSTR_PROF_VISIBILITY INSTR_PROF_INLINE uint32_t
getValueProfRecordHeaderSize(uint32_t NumValueSites) {
uint32_t Size = offsetof(ValueProfRecord, SiteCountArray) +
sizeof(uint8_t) * NumValueSites;
Size = (Size + 7) & ~7;
return Size;
}
INSTR_PROF_VISIBILITY INSTR_PROF_INLINE uint32_t
getValueProfRecordSize(uint32_t NumValueSites, uint32_t NumValueData) {
return getValueProfRecordHeaderSize(NumValueSites) +
sizeof(InstrProfValueData) * NumValueData;
}
INSTR_PROF_VISIBILITY INSTR_PROF_INLINE InstrProfValueData *
getValueProfRecordValueData(ValueProfRecord *This) {
return (InstrProfValueData *)((char *)This + getValueProfRecordHeaderSize(
This->NumValueSites));
}
INSTR_PROF_VISIBILITY INSTR_PROF_INLINE uint32_t
getValueProfRecordNumValueData(ValueProfRecord *This) {
uint32_t NumValueData = 0;
uint32_t I;
for (I = 0; I < This->NumValueSites; I++)
NumValueData += This->SiteCountArray[I];
return NumValueData;
}
INSTR_PROF_VISIBILITY INSTR_PROF_INLINE ValueProfRecord *
getValueProfRecordNext(ValueProfRecord *This) {
uint32_t NumValueData = getValueProfRecordNumValueData(This);
return (ValueProfRecord *)((char *)This +
getValueProfRecordSize(This->NumValueSites,
NumValueData));
}
INSTR_PROF_VISIBILITY INSTR_PROF_INLINE ValueProfRecord *
getFirstValueProfRecord(ValueProfData *This) {
return (ValueProfRecord *)((char *)This + sizeof(ValueProfData));
}
INSTR_PROF_VISIBILITY uint32_t
getValueProfDataSize(ValueProfRecordClosure *Closure) {
uint32_t Kind;
uint32_t TotalSize = sizeof(ValueProfData);
const void *Record = Closure->Record;
for (Kind = IPVK_First; Kind <= IPVK_Last; Kind++) {
uint32_t NumValueSites = Closure->GetNumValueSites(Record, Kind);
if (!NumValueSites)
continue;
TotalSize += getValueProfRecordSize(NumValueSites,
Closure->GetNumValueData(Record, Kind));
}
return TotalSize;
}
INSTR_PROF_VISIBILITY void
serializeValueProfRecordFrom(ValueProfRecord *This,
ValueProfRecordClosure *Closure,
uint32_t ValueKind, uint32_t NumValueSites) {
uint32_t S;
const void *Record = Closure->Record;
This->Kind = ValueKind;
This->NumValueSites = NumValueSites;
InstrProfValueData *DstVD = getValueProfRecordValueData(This);
for (S = 0; S < NumValueSites; S++) {
uint32_t ND = Closure->GetNumValueDataForSite(Record, ValueKind, S);
This->SiteCountArray[S] = ND;
Closure->GetValueForSite(Record, DstVD, ValueKind, S);
DstVD += ND;
}
}
INSTR_PROF_VISIBILITY ValueProfData *
serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
ValueProfData *DstData) {
uint32_t Kind;
uint32_t TotalSize =
DstData ? DstData->TotalSize : getValueProfDataSize(Closure);
ValueProfData *VPD =
DstData ? DstData : Closure->AllocValueProfData(TotalSize);
VPD->TotalSize = TotalSize;
VPD->NumValueKinds = Closure->GetNumValueKinds(Closure->Record);
ValueProfRecord *VR = getFirstValueProfRecord(VPD);
for (Kind = IPVK_First; Kind <= IPVK_Last; Kind++) {
uint32_t NumValueSites = Closure->GetNumValueSites(Closure->Record, Kind);
if (!NumValueSites)
continue;
serializeValueProfRecordFrom(VR, Closure, Kind, NumValueSites);
VR = getValueProfRecordNext(VR);
}
return VPD;
}
#undef INSTR_PROF_COMMON_API_IMPL
#endif
#ifndef INSTR_PROF_DATA_DEFINED
#ifndef INSTR_PROF_DATA_INC
#define INSTR_PROF_DATA_INC
#define INSTR_PROF_SIMPLE_QUOTE(x) …
#define INSTR_PROF_QUOTE(x) …
#define INSTR_PROF_SIMPLE_CONCAT(x,y) …
#define INSTR_PROF_CONCAT(x,y) …
#define INSTR_PROF_RAW_MAGIC_64 …
#define INSTR_PROF_RAW_MAGIC_32 …
#define INSTR_PROF_RAW_VERSION …
#define INSTR_PROF_INDEX_VERSION …
#define INSTR_PROF_COVMAP_VERSION …
#define VARIANT_MASKS_ALL …
#define GET_VERSION(V) …
#define VARIANT_MASK_IR_PROF …
#define VARIANT_MASK_CSIR_PROF …
#define VARIANT_MASK_INSTR_ENTRY …
#define VARIANT_MASK_DBG_CORRELATE …
#define VARIANT_MASK_BYTE_COVERAGE …
#define VARIANT_MASK_FUNCTION_ENTRY_ONLY …
#define VARIANT_MASK_MEMPROF …
#define VARIANT_MASK_TEMPORAL_PROF …
#define INSTR_PROF_RAW_VERSION_VAR …
#define INSTR_PROF_PROFILE_RUNTIME_VAR …
#define INSTR_PROF_PROFILE_COUNTER_BIAS_VAR …
#define INSTR_PROF_PROFILE_BITMAP_BIAS_VAR …
#define INSTR_PROF_PROFILE_SET_TIMESTAMP …
#define INSTR_PROF_PROFILE_SAMPLING_VAR …
#define INSTR_PROF_PROFILE_NAME_VAR …
#define INSTR_PROF_DATA_COMMON …
#define INSTR_PROF_NAME_COMMON …
#define INSTR_PROF_VNAME_COMMON …
#define INSTR_PROF_CNTS_COMMON …
#define INSTR_PROF_BITS_COMMON …
#define INSTR_PROF_VALS_COMMON …
#define INSTR_PROF_VNODES_COMMON …
#define INSTR_PROF_VTAB_COMMON …
#define INSTR_PROF_COVMAP_COMMON …
#define INSTR_PROF_COVFUN_COMMON …
#define INSTR_PROF_COVDATA_COMMON …
#define INSTR_PROF_COVNAME_COMMON …
#define INSTR_PROF_ORDERFILE_COMMON …
#define INSTR_PROF_DATA_COFF …
#define INSTR_PROF_NAME_COFF …
#define INSTR_PROF_VNAME_COFF …
#define INSTR_PROF_CNTS_COFF …
#define INSTR_PROF_BITS_COFF …
#define INSTR_PROF_VALS_COFF …
#define INSTR_PROF_VNODES_COFF …
#define INSTR_PROF_VTAB_COFF …
#define INSTR_PROF_COVMAP_COFF …
#define INSTR_PROF_COVFUN_COFF …
#define INSTR_PROF_COVDATA_COFF …
#define INSTR_PROF_COVNAME_COFF …
#define INSTR_PROF_ORDERFILE_COFF …
#ifdef _WIN32
#define INSTR_PROF_DATA_SECT_NAME …
#define INSTR_PROF_NAME_SECT_NAME …
#define INSTR_PROF_CNTS_SECT_NAME …
#define INSTR_PROF_BITS_SECT_NAME …
#define INSTR_PROF_VTAB_SECT_NAME …
#define INSTR_PROF_VNAME_SECT_NAME …
#define INSTR_PROF_VALS_SECT_NAME …
#define INSTR_PROF_VNODES_SECT_NAME …
#define INSTR_PROF_COVMAP_SECT_NAME …
#define INSTR_PROF_COVFUN_SECT_NAME …
#define INSTR_PROF_COVDATA_SECT_NAME …
#define INSTR_PROF_COVNAME_SECT_NAME …
#define INSTR_PROF_ORDERFILE_SECT_NAME …
#else
#define INSTR_PROF_DATA_SECT_NAME …
#define INSTR_PROF_NAME_SECT_NAME …
#define INSTR_PROF_CNTS_SECT_NAME …
#define INSTR_PROF_BITS_SECT_NAME …
#define INSTR_PROF_VTAB_SECT_NAME …
#define INSTR_PROF_VNAME_SECT_NAME …
#define INSTR_PROF_VALS_SECT_NAME …
#define INSTR_PROF_VNODES_SECT_NAME …
#define INSTR_PROF_COVMAP_SECT_NAME …
#define INSTR_PROF_COVFUN_SECT_NAME …
#define INSTR_PROF_COVDATA_SECT_NAME …
#define INSTR_PROF_COVNAME_SECT_NAME …
#define INSTR_PROF_ORDERFILE_SECT_NAME …
#endif
#define INSTR_PROF_ORDERFILE_BUFFER_NAME …
#define INSTR_PROF_ORDERFILE_BUFFER_NAME_STR …
#define INSTR_PROF_ORDERFILE_BUFFER_IDX_NAME …
#define INSTR_PROF_ORDERFILE_BUFFER_IDX_NAME_STR …
#define INSTR_PROF_SECT_START(Sect) …
#define INSTR_PROF_SECT_STOP(Sect) …
#define INSTR_PROF_VALUE_PROF_FUNC …
#define INSTR_PROF_VALUE_PROF_FUNC_STR …
#define INSTR_PROF_VALUE_PROF_MEMOP_FUNC …
#define INSTR_PROF_VALUE_PROF_MEMOP_FUNC_STR …
#define INSTR_PROF_DATA_ALIGNMENT …
InstrProfValueData;
#endif
#ifndef INSTR_ORDER_FILE_INC
#define INSTR_ORDER_FILE_BUFFER_SIZE …
#define INSTR_ORDER_FILE_BUFFER_BITS …
#define INSTR_ORDER_FILE_BUFFER_MASK …
#endif
#else
#undef INSTR_PROF_DATA_DEFINED
#endif
#undef COVMAP_V2_OR_V3
#ifdef INSTR_PROF_VALUE_PROF_MEMOP_API
#ifdef __cplusplus
#define INSTR_PROF_INLINE …
#else
#define INSTR_PROF_INLINE
#endif
#define INSTR_PROF_NUM_BUCKETS …
#if defined(_MSC_VER) && !defined(__clang__)
#include <intrin.h>
INSTR_PROF_VISIBILITY INSTR_PROF_INLINE
int InstProfClzll(unsigned long long X) {
unsigned long LeadZeroIdx = 0;
#if !defined(_M_ARM64) && !defined(_M_X64)
if (_BitScanReverse(&LeadZeroIdx, (unsigned long)(X >> 32)))
return (int)(63 - (LeadZeroIdx + 32));
if (_BitScanReverse(&LeadZeroIdx, (unsigned long)(X)))
return (int)(63 - LeadZeroIdx);
#else
if (_BitScanReverse64(&LeadZeroIdx, X)) return 63 - LeadZeroIdx;
#endif
return 64;
}
INSTR_PROF_VISIBILITY INSTR_PROF_INLINE
int InstProfPopcountll(unsigned long long X) {
unsigned long long v = X;
v = v - ((v >> 1) & 0x5555555555555555ULL);
v = (v & 0x3333333333333333ULL) + ((v >> 2) & 0x3333333333333333ULL);
v = (v + (v >> 4)) & 0x0F0F0F0F0F0F0F0FULL;
return (int)((unsigned long long)(v * 0x0101010101010101ULL) >> 56);
}
#else
INSTR_PROF_VISIBILITY INSTR_PROF_INLINE
int InstProfClzll(unsigned long long X) { return __builtin_clzll(X); }
INSTR_PROF_VISIBILITY INSTR_PROF_INLINE
int InstProfPopcountll(unsigned long long X) { return __builtin_popcountll(X); }
#endif
INSTR_PROF_VISIBILITY INSTR_PROF_INLINE uint64_t
InstrProfGetRangeRepValue(uint64_t Value) {
if (Value <= 8)
return Value;
else if (Value >= 513)
return 513;
else if (InstProfPopcountll(Value) == 1)
return Value;
else
return (UINT64_C(1) << (64 - InstProfClzll(Value) - 1)) + 1;
}
INSTR_PROF_VISIBILITY INSTR_PROF_INLINE unsigned
InstrProfIsSingleValRange(uint64_t Value) {
if (Value <= 8)
return 1;
else if (InstProfPopcountll(Value) == 1)
return 1;
else
return 0;
}
#endif