61 #ifndef INSTR_PROF_VISIBILITY 62 #define INSTR_PROF_VISIBILITY 67 #ifndef INSTR_PROF_DATA 68 #define INSTR_PROF_DATA(Type, LLVMType, Name, Initializer) 70 #define INSTR_PROF_DATA_DEFINED 76 ConstantInt::get(
llvm::
Type::getInt64Ty(Ctx), \
77 Inc->getHash()->getZExtValue()))
79 ConstantExpr::getBitCast(CounterPtr, \
90 ConstantInt::get(
llvm::
Type::getInt32Ty(Ctx), NumCounters))
92 ConstantArray::get(Int16ArrayTy, Int16ArrayVals))
93 #undef INSTR_PROF_DATA 109 #ifndef INSTR_PROF_VALUE_NODE 110 #define INSTR_PROF_VALUE_NODE(Type, LLVMType, Name, Initializer) 112 #define INSTR_PROF_DATA_DEFINED 115 ConstantInt::get(llvm::Type::GetInt64Ty(Ctx), 0))
117 ConstantInt::get(
llvm::
Type::GetInt64Ty(Ctx), 0))
119 ConstantInt::get(
llvm::
Type::GetInt8PtrTy(Ctx), 0))
120 #undef INSTR_PROF_VALUE_NODE 125 #ifndef INSTR_PROF_RAW_HEADER 126 #define INSTR_PROF_RAW_HEADER(Type, Name, Initializer) 128 #define INSTR_PROF_DATA_DEFINED 140 #undef INSTR_PROF_RAW_HEADER 147 #ifndef VALUE_PROF_FUNC_PARAM 148 #define VALUE_PROF_FUNC_PARAM(ArgType, ArgName, ArgLLVMType) 149 #define INSTR_PROF_COMMA 151 #define INSTR_PROF_DATA_DEFINED 152 #define INSTR_PROF_COMMA , 157 #ifndef VALUE_RANGE_PROF 168 #undef VALUE_PROF_FUNC_PARAM 169 #undef INSTR_PROF_COMMA 173 #ifndef VALUE_PROF_KIND 174 #define VALUE_PROF_KIND(Enumerator, Value, Descr) 176 #define INSTR_PROF_DATA_DEFINED 198 #undef VALUE_PROF_KIND 205 #ifndef COVMAP_FUNC_RECORD 206 #define COVMAP_FUNC_RECORD(Type, LLVMType, Name, Initializer) 208 #define INSTR_PROF_DATA_DEFINED 224 CoverageMapping.size()))
226 llvm::ConstantInt::get(
llvm::
Type::getInt64Ty(Ctx), FuncHash))
227 #undef COVMAP_FUNC_RECORD 233 #ifndef COVMAP_HEADER 234 #define COVMAP_HEADER(Type, LLVMType, Name, Initializer) 236 #define INSTR_PROF_DATA_DEFINED 241 llvm::ConstantInt::get(Int32Ty, FilenamesSize))
243 llvm::ConstantInt::get(Int32Ty, CoverageMappingSize))
250 #ifdef INSTR_PROF_SECT_ENTRY 251 #define INSTR_PROF_DATA_DEFINED 253 INSTR_PROF_QUOTE(INSTR_PROF_DATA_COMMON), \
254 INSTR_PROF_DATA_COFF,
"__DATA,")
256 INSTR_PROF_QUOTE(INSTR_PROF_CNTS_COMMON), \
257 INSTR_PROF_CNTS_COFF, "__DATA,")
259 INSTR_PROF_QUOTE(INSTR_PROF_NAME_COMMON), \
260 INSTR_PROF_NAME_COFF, "__DATA,")
262 INSTR_PROF_QUOTE(INSTR_PROF_VALS_COMMON), \
263 INSTR_PROF_VALS_COFF, "__DATA,")
265 INSTR_PROF_QUOTE(INSTR_PROF_VNODES_COMMON), \
266 INSTR_PROF_VNODES_COFF, "__DATA,")
268 INSTR_PROF_QUOTE(INSTR_PROF_COVMAP_COMMON), \
269 INSTR_PROF_COVMAP_COFF, "__LLVM_COV,")
271 INSTR_PROF_QUOTE(INSTR_PROF_ORDERFILE_COMMON), \
272 INSTR_PROF_QUOTE(INSTR_PROF_ORDERFILE_COFF), "__DATA,")
274 #undef INSTR_PROF_SECT_ENTRY 278 #ifdef INSTR_PROF_VALUE_PROF_DATA 279 #define INSTR_PROF_DATA_DEFINED 281 #define INSTR_PROF_MAX_NUM_VAL_PER_SITE 255 286 typedef struct ValueProfRecord {
293 uint32_t NumValueSites;
300 uint8_t SiteCountArray[1];
317 uint32_t getNumValueSites()
const {
return NumValueSites; }
321 void deserializeTo(InstrProfRecord &Record,
322 InstrProfSymtab *SymTab);
336 typedef struct ValueProfData {
350 uint32_t NumValueKinds;
365 static uint32_t getSize(
const InstrProfRecord &Record);
369 static std::unique_ptr<ValueProfData>
370 serializeFrom(
const InstrProfRecord &Record);
374 Error checkIntegrity();
380 static Expected<std::unique_ptr<ValueProfData>>
381 getValueProfData(
const unsigned char *SrcBuffer,
382 const unsigned char *
const SrcBufferEnd,
395 uint32_t getSize()
const {
return TotalSize; }
399 void deserializeTo(InstrProfRecord &Record,
400 InstrProfSymtab *SymTab);
401 void operator delete(
void *ptr) { ::operator
delete(ptr); }
419 typedef struct ValueProfRecordClosure {
421 uint32_t (*GetNumValueKinds)(
const void *Record);
422 uint32_t (*GetNumValueSites)(
const void *Record, uint32_t VKind);
423 uint32_t (*GetNumValueData)(
const void *Record, uint32_t VKind);
424 uint32_t (*GetNumValueDataForSite)(
const void *
R, uint32_t VK, uint32_t S);
431 uint64_t (*RemapValueData)(uint32_t, uint64_t
Value);
432 void (*GetValueForSite)(
const void *
R, InstrProfValueData *Dst, uint32_t K,
434 ValueProfData *(*AllocValueProfData)(
size_t TotalSizeInBytes);
435 } ValueProfRecordClosure;
437 INSTR_PROF_VISIBILITY ValueProfRecord *
438 getFirstValueProfRecord(ValueProfData *VPD);
439 INSTR_PROF_VISIBILITY ValueProfRecord *
440 getValueProfRecordNext(ValueProfRecord *VPR);
441 INSTR_PROF_VISIBILITY InstrProfValueData *
442 getValueProfRecordValueData(ValueProfRecord *VPR);
443 INSTR_PROF_VISIBILITY uint32_t
444 getValueProfRecordHeaderSize(uint32_t NumValueSites);
446 #undef INSTR_PROF_VALUE_PROF_DATA 450 #ifdef INSTR_PROF_COMMON_API_IMPL 451 #define INSTR_PROF_DATA_DEFINED 453 #define INSTR_PROF_INLINE inline 454 #define INSTR_PROF_NULLPTR nullptr 456 #define INSTR_PROF_INLINE 457 #define INSTR_PROF_NULLPTR NULL 461 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) 468 INSTR_PROF_VISIBILITY INSTR_PROF_INLINE
469 uint32_t getValueProfRecordHeaderSize(uint32_t NumValueSites) {
470 uint32_t
Size =
offsetof(ValueProfRecord, SiteCountArray) +
471 sizeof(uint8_t) * NumValueSites;
473 Size = (Size + 7) & ~7;
481 INSTR_PROF_VISIBILITY INSTR_PROF_INLINE
482 uint32_t getValueProfRecordSize(uint32_t NumValueSites,
483 uint32_t NumValueData) {
484 return getValueProfRecordHeaderSize(NumValueSites) +
485 sizeof(InstrProfValueData) * NumValueData;
491 INSTR_PROF_VISIBILITY INSTR_PROF_INLINE
492 InstrProfValueData *getValueProfRecordValueData(ValueProfRecord *This) {
493 return (InstrProfValueData *)((
char *)This + getValueProfRecordHeaderSize(
494 This->NumValueSites));
500 INSTR_PROF_VISIBILITY INSTR_PROF_INLINE
501 uint32_t getValueProfRecordNumValueData(ValueProfRecord *This) {
502 uint32_t NumValueData = 0;
504 for (I = 0; I < This->NumValueSites; I++)
505 NumValueData += This->SiteCountArray[I];
512 INSTR_PROF_VISIBILITY INSTR_PROF_INLINE
513 ValueProfRecord *getValueProfRecordNext(ValueProfRecord *This) {
514 uint32_t NumValueData = getValueProfRecordNumValueData(This);
515 return (ValueProfRecord *)((
char *)This +
516 getValueProfRecordSize(This->NumValueSites,
523 INSTR_PROF_VISIBILITY INSTR_PROF_INLINE
524 ValueProfRecord *getFirstValueProfRecord(ValueProfData *This) {
525 return (ValueProfRecord *)((
char *)This +
sizeof(ValueProfData));
534 INSTR_PROF_VISIBILITY uint32_t
535 getValueProfDataSize(ValueProfRecordClosure *Closure) {
537 uint32_t TotalSize =
sizeof(ValueProfData);
538 const void *Record = Closure->Record;
540 for (Kind = IPVK_First; Kind <= IPVK_Last; Kind++) {
541 uint32_t NumValueSites = Closure->GetNumValueSites(Record, Kind);
544 TotalSize += getValueProfRecordSize(NumValueSites,
545 Closure->GetNumValueData(Record, Kind));
554 INSTR_PROF_VISIBILITY
void 555 serializeValueProfRecordFrom(ValueProfRecord *This,
556 ValueProfRecordClosure *Closure,
557 uint32_t
ValueKind, uint32_t NumValueSites) {
559 const void *Record = Closure->Record;
561 This->NumValueSites = NumValueSites;
562 InstrProfValueData *DstVD = getValueProfRecordValueData(This);
564 for (S = 0; S < NumValueSites; S++) {
565 uint32_t ND = Closure->GetNumValueDataForSite(Record, ValueKind, S);
566 This->SiteCountArray[S] = ND;
567 Closure->GetValueForSite(Record, DstVD, ValueKind, S);
579 INSTR_PROF_VISIBILITY ValueProfData *
580 serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
581 ValueProfData *DstData) {
584 DstData ? DstData->TotalSize : getValueProfDataSize(Closure);
587 DstData ? DstData : Closure->AllocValueProfData(TotalSize);
589 VPD->TotalSize = TotalSize;
590 VPD->NumValueKinds = Closure->GetNumValueKinds(Closure->Record);
591 ValueProfRecord *VR = getFirstValueProfRecord(VPD);
592 for (Kind = IPVK_First; Kind <= IPVK_Last; Kind++) {
593 uint32_t NumValueSites = Closure->GetNumValueSites(Closure->Record, Kind);
596 serializeValueProfRecordFrom(VR, Closure, Kind, NumValueSites);
597 VR = getValueProfRecordNext(VR);
602 #undef INSTR_PROF_COMMON_API_IMPL 607 #ifndef INSTR_PROF_DATA_DEFINED 609 #ifndef INSTR_PROF_DATA_INC 610 #define INSTR_PROF_DATA_INC 613 #define INSTR_PROF_SIMPLE_QUOTE(x) #x 614 #define INSTR_PROF_QUOTE(x) INSTR_PROF_SIMPLE_QUOTE(x) 615 #define INSTR_PROF_SIMPLE_CONCAT(x,y) x ## y 616 #define INSTR_PROF_CONCAT(x,y) INSTR_PROF_SIMPLE_CONCAT(x,y) 625 #define INSTR_PROF_RAW_MAGIC_64 (uint64_t)255 << 56 | (uint64_t)'l' << 48 | \ 626 (uint64_t)'p' << 40 | (uint64_t)'r' << 32 | (uint64_t)'o' << 24 | \ 627 (uint64_t)'f' << 16 | (uint64_t)'r' << 8 | (uint64_t)129 628 #define INSTR_PROF_RAW_MAGIC_32 (uint64_t)255 << 56 | (uint64_t)'l' << 48 | \ 629 (uint64_t)'p' << 40 | (uint64_t)'r' << 32 | (uint64_t)'o' << 24 | \ 630 (uint64_t)'f' << 16 | (uint64_t)'R' << 8 | (uint64_t)129 633 #define INSTR_PROF_RAW_VERSION 5 635 #define INSTR_PROF_INDEX_VERSION 5 637 #define INSTR_PROF_COVMAP_VERSION 2 645 #define VARIANT_MASKS_ALL 0xff00000000000000ULL 646 #define GET_VERSION(V) ((V) & ~VARIANT_MASKS_ALL) 647 #define VARIANT_MASK_IR_PROF (0x1ULL << 56) 648 #define VARIANT_MASK_CSIR_PROF (0x1ULL << 57) 649 #define INSTR_PROF_RAW_VERSION_VAR __llvm_profile_raw_version 650 #define INSTR_PROF_PROFILE_RUNTIME_VAR __llvm_profile_runtime 654 #define INSTR_PROF_PROFILE_NAME_VAR __llvm_profile_filename 658 #define INSTR_PROF_DATA_COMMON __llvm_prf_data 659 #define INSTR_PROF_NAME_COMMON __llvm_prf_names 660 #define INSTR_PROF_CNTS_COMMON __llvm_prf_cnts 661 #define INSTR_PROF_VALS_COMMON __llvm_prf_vals 662 #define INSTR_PROF_VNODES_COMMON __llvm_prf_vnds 663 #define INSTR_PROF_COVMAP_COMMON __llvm_covmap 664 #define INSTR_PROF_ORDERFILE_COMMON __llvm_orderfile 668 #define INSTR_PROF_DATA_COFF ".lprfd$M" 669 #define INSTR_PROF_NAME_COFF ".lprfn$M" 670 #define INSTR_PROF_CNTS_COFF ".lprfc$M" 671 #define INSTR_PROF_VALS_COFF ".lprfv$M" 672 #define INSTR_PROF_VNODES_COFF ".lprfnd$M" 673 #define INSTR_PROF_COVMAP_COFF ".lcovmap$M" 674 #define INSTR_PROF_ORDERFILE_COFF ".lorderfile$M" 678 #define INSTR_PROF_DATA_SECT_NAME INSTR_PROF_DATA_COFF 679 #define INSTR_PROF_NAME_SECT_NAME INSTR_PROF_NAME_COFF 680 #define INSTR_PROF_CNTS_SECT_NAME INSTR_PROF_CNTS_COFF 684 #define INSTR_PROF_VALS_SECT_NAME INSTR_PROF_VALS_COFF 686 #define INSTR_PROF_VNODES_SECT_NAME INSTR_PROF_VNODES_COFF 687 #define INSTR_PROF_COVMAP_SECT_NAME INSTR_PROF_COVMAP_COFF 688 #define INSTR_PROF_ORDERFILE_SECT_NAME INSTR_PROF_ORDERFILE_COFF 691 #define INSTR_PROF_DATA_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_DATA_COMMON) 692 #define INSTR_PROF_NAME_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_NAME_COMMON) 693 #define INSTR_PROF_CNTS_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_CNTS_COMMON) 697 #define INSTR_PROF_VALS_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_VALS_COMMON) 699 #define INSTR_PROF_VNODES_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_VNODES_COMMON) 700 #define INSTR_PROF_COVMAP_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_COVMAP_COMMON) 702 #define INSTR_PROF_ORDERFILE_SECT_NAME \ 703 INSTR_PROF_QUOTE(INSTR_PROF_ORDERFILE_COMMON) 706 #define INSTR_PROF_ORDERFILE_BUFFER_NAME _llvm_order_file_buffer 707 #define INSTR_PROF_ORDERFILE_BUFFER_NAME_STR \ 708 INSTR_PROF_QUOTE(INSTR_PROF_ORDERFILE_BUFFER_NAME) 709 #define INSTR_PROF_ORDERFILE_BUFFER_IDX_NAME _llvm_order_file_buffer_idx 710 #define INSTR_PROF_ORDERFILE_BUFFER_IDX_NAME_STR \ 711 INSTR_PROF_QUOTE(INSTR_PROF_ORDERFILE_BUFFER_IDX_NAME) 718 #define INSTR_PROF_SECT_START(Sect) \ 719 INSTR_PROF_CONCAT(__start_,Sect) 720 #define INSTR_PROF_SECT_STOP(Sect) \ 721 INSTR_PROF_CONCAT(__stop_,Sect) 724 #define INSTR_PROF_VALUE_PROF_FUNC __llvm_profile_instrument_target 725 #define INSTR_PROF_VALUE_PROF_FUNC_STR \ 726 INSTR_PROF_QUOTE(INSTR_PROF_VALUE_PROF_FUNC) 727 #define INSTR_PROF_VALUE_RANGE_PROF_FUNC __llvm_profile_instrument_range 728 #define INSTR_PROF_VALUE_RANGE_PROF_FUNC_STR \ 729 INSTR_PROF_QUOTE(INSTR_PROF_VALUE_RANGE_PROF_FUNC) 732 #define INSTR_PROF_DATA_ALIGNMENT 8 737 typedef struct InstrProfValueData {
742 } InstrProfValueData;
746 #ifndef INSTR_ORDER_FILE_INC 748 #define INSTR_ORDER_FILE_BUFFER_SIZE 131072 749 #define INSTR_ORDER_FILE_BUFFER_BITS 17 750 #define INSTR_ORDER_FILE_BUFFER_MASK 0x1ffff 753 #undef INSTR_PROF_DATA_DEFINED Type
MessagePack types as defined in the standard, with the exception of Integer being divided into a sign...
This class represents lattice values for constants.
constexpr support::endianness Endianness
The endianness of all multi-byte encoded values in MessagePack.
#define VALUE_PROF_FUNC_PARAM(ParamType, ParamName, ParamLLVMType)
static IntegerType * getInt64Ty(LLVMContext &C)
llvm::support::endianness endianness
#define INSTR_PROF_DATA(Type, LLVMType, Name, Init)
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
#define offsetof(TYPE, MEMBER)
amdgpu propagate attributes Late propagate attributes from kernels to functions
#define VALUE_PROF_KIND(Enumerator, Value, Descr)
uint64_t ComputeHash(StringRef K)
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
static const char *const Magic
auto size(R &&Range, typename std::enable_if< std::is_same< typename std::iterator_traits< decltype(Range.begin())>::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr) -> decltype(std::distance(Range.begin(), Range.end()))
Get the size of a range.
#define INSTR_PROF_VALUE_NODE(Type, LLVMType, Name, Init)
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
#define INSTR_PROF_SECT_ENTRY(Kind, SectNameCommon, SectNameCoff, Prefix)
#define COVMAP_FUNC_RECORD(Type, LLVMType, Name, Init)
static IntegerType * getInt32Ty(LLVMContext &C)
#define INSTR_PROF_RAW_HEADER(Type, Name, Init)
#define COVMAP_HEADER(Type, LLVMType, Name, Init)
StringRef getPGOFuncNameVarInitializer(GlobalVariable *NameVar)
Return the initializer in string of the PGO name var NameVar.