62 #ifndef INSTR_PROF_VISIBILITY
63 #define INSTR_PROF_VISIBILITY
68 #ifndef INSTR_PROF_DATA
69 #define INSTR_PROF_DATA(Type, LLVMType, Name, Initializer)
71 #define INSTR_PROF_DATA_DEFINED
77 ConstantInt::get(llvm::
Type::getInt64Ty(Ctx), \
78 Inc->getHash()->getZExtValue()))
80 ConstantExpr::getBitCast(CounterPtr, \
81 llvm::
Type::getInt64PtrTy(Ctx)))
91 ConstantInt::get(llvm::
Type::getInt32Ty(Ctx), NumCounters))
93 ConstantArray::get(Int16ArrayTy, Int16ArrayVals))
94 #undef INSTR_PROF_DATA
110 #ifndef INSTR_PROF_VALUE_NODE
111 #define INSTR_PROF_VALUE_NODE(Type, LLVMType, Name, Initializer)
113 #define INSTR_PROF_DATA_DEFINED
116 ConstantInt::get(llvm::Type::GetInt64Ty(Ctx), 0))
118 ConstantInt::get(llvm::
Type::GetInt64Ty(Ctx), 0))
120 ConstantInt::get(llvm::
Type::GetInt8PtrTy(Ctx), 0))
121 #undef INSTR_PROF_VALUE_NODE
126 #ifndef INSTR_PROF_RAW_HEADER
127 #define INSTR_PROF_RAW_HEADER(Type, Name, Initializer)
129 #define INSTR_PROF_DATA_DEFINED
139 #undef INSTR_PROF_RAW_HEADER
146 #ifndef VALUE_PROF_FUNC_PARAM
147 #define VALUE_PROF_FUNC_PARAM(ArgType, ArgName, ArgLLVMType)
148 #define INSTR_PROF_COMMA
150 #define INSTR_PROF_DATA_DEFINED
151 #define INSTR_PROF_COMMA ,
156 #ifndef VALUE_RANGE_PROF
167 #undef VALUE_PROF_FUNC_PARAM
168 #undef INSTR_PROF_COMMA
172 #ifndef VALUE_PROF_KIND
173 #define VALUE_PROF_KIND(Enumerator, Value)
175 #define INSTR_PROF_DATA_DEFINED
197 #undef VALUE_PROF_KIND
204 #ifndef COVMAP_FUNC_RECORD
205 #define COVMAP_FUNC_RECORD(Type, LLVMType, Name, Initializer)
207 #define INSTR_PROF_DATA_DEFINED
214 llvm::ConstantInt::get(llvm::
Type::getInt32Ty(Ctx), \
223 CoverageMapping.size()))
225 llvm::ConstantInt::get(llvm::
Type::getInt64Ty(Ctx), FuncHash))
226 #undef COVMAP_FUNC_RECORD
232 #ifndef COVMAP_HEADER
233 #define COVMAP_HEADER(Type, LLVMType, Name, Initializer)
235 #define INSTR_PROF_DATA_DEFINED
240 llvm::ConstantInt::get(Int32Ty, FilenamesSize))
242 llvm::ConstantInt::get(Int32Ty, CoverageMappingSize))
249 #ifdef INSTR_PROF_SECT_ENTRY
250 #define INSTR_PROF_DATA_DEFINED
252 INSTR_PROF_QUOTE(INSTR_PROF_DATA_COMMON), \
253 INSTR_PROF_QUOTE(INSTR_PROF_DATA_COFF),
"__DATA,")
255 INSTR_PROF_QUOTE(INSTR_PROF_CNTS_COMMON), \
256 INSTR_PROF_QUOTE(INSTR_PROF_CNTS_COFF), "__DATA,")
258 INSTR_PROF_QUOTE(INSTR_PROF_NAME_COMMON), \
259 INSTR_PROF_QUOTE(INSTR_PROF_NAME_COFF), "__DATA,")
261 INSTR_PROF_QUOTE(INSTR_PROF_VALS_COMMON), \
262 INSTR_PROF_QUOTE(INSTR_PROF_VALS_COFF), "__DATA,")
264 INSTR_PROF_QUOTE(INSTR_PROF_VNODES_COMMON), \
265 INSTR_PROF_QUOTE(INSTR_PROF_VNODES_COFF), "__DATA,")
267 INSTR_PROF_QUOTE(INSTR_PROF_COVMAP_COMMON), \
268 INSTR_PROF_QUOTE(INSTR_PROF_COVMAP_COFF), "__LLVM_COV,")
270 #undef INSTR_PROF_SECT_ENTRY
274 #ifdef INSTR_PROF_VALUE_PROF_DATA
275 #define INSTR_PROF_DATA_DEFINED
277 #define INSTR_PROF_MAX_NUM_VAL_PER_SITE 255
282 typedef struct ValueProfRecord {
289 uint32_t NumValueSites;
296 uint8_t SiteCountArray[1];
313 uint32_t getNumValueSites()
const {
return NumValueSites; }
317 void deserializeTo(InstrProfRecord &Record,
318 InstrProfRecord::ValueMapType *VMap);
332 typedef struct ValueProfData {
346 uint32_t NumValueKinds;
361 static uint32_t getSize(
const InstrProfRecord &Record);
365 static std::unique_ptr<ValueProfData>
366 serializeFrom(
const InstrProfRecord &Record);
370 Error checkIntegrity();
376 static Expected<std::unique_ptr<ValueProfData>>
377 getValueProfData(
const unsigned char *SrcBuffer,
378 const unsigned char *
const SrcBufferEnd,
391 uint32_t getSize()
const {
return TotalSize; }
395 void deserializeTo(InstrProfRecord &Record,
396 InstrProfRecord::ValueMapType *VMap);
397 void operator delete(
void *ptr) { ::operator
delete(ptr); }
415 typedef struct ValueProfRecordClosure {
417 uint32_t (*GetNumValueKinds)(
const void *Record);
418 uint32_t (*GetNumValueSites)(
const void *Record, uint32_t VKind);
419 uint32_t (*GetNumValueData)(
const void *Record, uint32_t VKind);
420 uint32_t (*GetNumValueDataForSite)(
const void *R, uint32_t VK, uint32_t S);
427 uint64_t (*RemapValueData)(uint32_t, uint64_t Value);
428 void (*GetValueForSite)(
const void *R, InstrProfValueData *Dst, uint32_t K,
430 ValueProfData *(*AllocValueProfData)(
size_t TotalSizeInBytes);
431 } ValueProfRecordClosure;
433 INSTR_PROF_VISIBILITY ValueProfRecord *
434 getFirstValueProfRecord(ValueProfData *VPD);
435 INSTR_PROF_VISIBILITY ValueProfRecord *
436 getValueProfRecordNext(ValueProfRecord *VPR);
437 INSTR_PROF_VISIBILITY InstrProfValueData *
438 getValueProfRecordValueData(ValueProfRecord *VPR);
439 INSTR_PROF_VISIBILITY uint32_t
440 getValueProfRecordHeaderSize(uint32_t NumValueSites);
442 #undef INSTR_PROF_VALUE_PROF_DATA
446 #ifdef INSTR_PROF_COMMON_API_IMPL
447 #define INSTR_PROF_DATA_DEFINED
449 #define INSTR_PROF_INLINE inline
450 #define INSTR_PROF_NULLPTR nullptr
452 #define INSTR_PROF_INLINE
453 #define INSTR_PROF_NULLPTR NULL
457 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
464 INSTR_PROF_VISIBILITY INSTR_PROF_INLINE
465 uint32_t getValueProfRecordHeaderSize(uint32_t NumValueSites) {
466 uint32_t
Size = offsetof(ValueProfRecord, SiteCountArray) +
467 sizeof(uint8_t) * NumValueSites;
469 Size = (Size + 7) & ~7;
477 INSTR_PROF_VISIBILITY INSTR_PROF_INLINE
478 uint32_t getValueProfRecordSize(uint32_t NumValueSites,
479 uint32_t NumValueData) {
480 return getValueProfRecordHeaderSize(NumValueSites) +
481 sizeof(InstrProfValueData) * NumValueData;
487 INSTR_PROF_VISIBILITY INSTR_PROF_INLINE
488 InstrProfValueData *getValueProfRecordValueData(ValueProfRecord *This) {
489 return (InstrProfValueData *)((
char *)This + getValueProfRecordHeaderSize(
490 This->NumValueSites));
496 INSTR_PROF_VISIBILITY INSTR_PROF_INLINE
497 uint32_t getValueProfRecordNumValueData(ValueProfRecord *This) {
498 uint32_t NumValueData = 0;
500 for (I = 0; I < This->NumValueSites; I++)
501 NumValueData += This->SiteCountArray[I];
508 INSTR_PROF_VISIBILITY INSTR_PROF_INLINE
509 ValueProfRecord *getValueProfRecordNext(ValueProfRecord *This) {
510 uint32_t NumValueData = getValueProfRecordNumValueData(This);
511 return (ValueProfRecord *)((
char *)This +
512 getValueProfRecordSize(This->NumValueSites,
519 INSTR_PROF_VISIBILITY INSTR_PROF_INLINE
520 ValueProfRecord *getFirstValueProfRecord(ValueProfData *This) {
521 return (ValueProfRecord *)((
char *)This +
sizeof(ValueProfData));
530 INSTR_PROF_VISIBILITY uint32_t
531 getValueProfDataSize(ValueProfRecordClosure *Closure) {
533 uint32_t TotalSize =
sizeof(ValueProfData);
534 const void *Record = Closure->Record;
536 for (Kind = IPVK_First; Kind <= IPVK_Last; Kind++) {
537 uint32_t NumValueSites = Closure->GetNumValueSites(Record, Kind);
540 TotalSize += getValueProfRecordSize(NumValueSites,
541 Closure->GetNumValueData(Record, Kind));
550 INSTR_PROF_VISIBILITY
void
551 serializeValueProfRecordFrom(ValueProfRecord *This,
552 ValueProfRecordClosure *Closure,
553 uint32_t
ValueKind, uint32_t NumValueSites) {
555 const void *Record = Closure->Record;
557 This->NumValueSites = NumValueSites;
558 InstrProfValueData *DstVD = getValueProfRecordValueData(This);
560 for (S = 0; S < NumValueSites; S++) {
561 uint32_t ND = Closure->GetNumValueDataForSite(Record, ValueKind, S);
562 This->SiteCountArray[S] = ND;
563 Closure->GetValueForSite(Record, DstVD, ValueKind, S);
575 INSTR_PROF_VISIBILITY ValueProfData *
576 serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
577 ValueProfData *DstData) {
580 DstData ? DstData->TotalSize : getValueProfDataSize(Closure);
583 DstData ? DstData : Closure->AllocValueProfData(TotalSize);
585 VPD->TotalSize = TotalSize;
586 VPD->NumValueKinds = Closure->GetNumValueKinds(Closure->Record);
587 ValueProfRecord *VR = getFirstValueProfRecord(VPD);
588 for (Kind = IPVK_First; Kind <= IPVK_Last; Kind++) {
589 uint32_t NumValueSites = Closure->GetNumValueSites(Closure->Record, Kind);
592 serializeValueProfRecordFrom(VR, Closure, Kind, NumValueSites);
593 VR = getValueProfRecordNext(VR);
598 #undef INSTR_PROF_COMMON_API_IMPL
603 #ifndef INSTR_PROF_DATA_DEFINED
605 #ifndef INSTR_PROF_DATA_INC
606 #define INSTR_PROF_DATA_INC
609 #define INSTR_PROF_SIMPLE_QUOTE(x) #x
610 #define INSTR_PROF_QUOTE(x) INSTR_PROF_SIMPLE_QUOTE(x)
611 #define INSTR_PROF_SIMPLE_CONCAT(x,y) x ## y
612 #define INSTR_PROF_CONCAT(x,y) INSTR_PROF_SIMPLE_CONCAT(x,y)
621 #define INSTR_PROF_RAW_MAGIC_64 (uint64_t)255 << 56 | (uint64_t)'l' << 48 | \
622 (uint64_t)'p' << 40 | (uint64_t)'r' << 32 | (uint64_t)'o' << 24 | \
623 (uint64_t)'f' << 16 | (uint64_t)'r' << 8 | (uint64_t)129
624 #define INSTR_PROF_RAW_MAGIC_32 (uint64_t)255 << 56 | (uint64_t)'l' << 48 | \
625 (uint64_t)'p' << 40 | (uint64_t)'r' << 32 | (uint64_t)'o' << 24 | \
626 (uint64_t)'f' << 16 | (uint64_t)'R' << 8 | (uint64_t)129
629 #define INSTR_PROF_RAW_VERSION 4
631 #define INSTR_PROF_INDEX_VERSION 4
633 #define INSTR_PROF_COVMAP_VERSION 1
640 #define VARIANT_MASKS_ALL 0xff00000000000000ULL
641 #define GET_VERSION(V) ((V) & ~VARIANT_MASKS_ALL)
642 #define VARIANT_MASK_IR_PROF (0x1ULL << 56)
643 #define INSTR_PROF_RAW_VERSION_VAR __llvm_profile_raw_version
644 #define INSTR_PROF_PROFILE_RUNTIME_VAR __llvm_profile_runtime
648 #define INSTR_PROF_PROFILE_NAME_VAR __llvm_profile_filename
652 #define INSTR_PROF_DATA_COMMON __llvm_prf_data
653 #define INSTR_PROF_NAME_COMMON __llvm_prf_names
654 #define INSTR_PROF_CNTS_COMMON __llvm_prf_cnts
655 #define INSTR_PROF_VALS_COMMON __llvm_prf_vals
656 #define INSTR_PROF_VNODES_COMMON __llvm_prf_vnds
657 #define INSTR_PROF_COVMAP_COMMON __llvm_covmap
659 #define INSTR_PROF_DATA_COFF .lprfd
660 #define INSTR_PROF_NAME_COFF .lprfn
661 #define INSTR_PROF_CNTS_COFF .lprfc
662 #define INSTR_PROF_VALS_COFF .lprfv
663 #define INSTR_PROF_VNODES_COFF .lprfnd
664 #define INSTR_PROF_COVMAP_COFF .lcovmap
668 #define INSTR_PROF_DATA_SECT_NAME INSTR_PROF_DATA_COFF
669 #define INSTR_PROF_NAME_SECT_NAME INSTR_PROF_NAME_COFF
670 #define INSTR_PROF_CNTS_SECT_NAME INSTR_PROF_CNTS_COFF
674 #define INSTR_PROF_VALS_SECT_NAME INSTR_PROF_VALS_COFF
676 #define INSTR_PROF_VNODES_SECT_NAME INSTR_PROF_VNODES_COFF
677 #define INSTR_PROF_COVMAP_SECT_NAME INSTR_PROF_COVMAP_COFF
680 #define INSTR_PROF_DATA_SECT_NAME INSTR_PROF_DATA_COMMON
681 #define INSTR_PROF_NAME_SECT_NAME INSTR_PROF_NAME_COMMON
682 #define INSTR_PROF_CNTS_SECT_NAME INSTR_PROF_CNTS_COMMON
686 #define INSTR_PROF_VALS_SECT_NAME INSTR_PROF_VALS_COMMON
688 #define INSTR_PROF_VNODES_SECT_NAME INSTR_PROF_VNODES_COMMON
689 #define INSTR_PROF_COVMAP_SECT_NAME INSTR_PROF_COVMAP_COMMON
692 #define INSTR_PROF_DATA_SECT_NAME_STR \
693 INSTR_PROF_QUOTE(INSTR_PROF_DATA_SECT_NAME)
694 #define INSTR_PROF_NAME_SECT_NAME_STR \
695 INSTR_PROF_QUOTE(INSTR_PROF_NAME_SECT_NAME)
696 #define INSTR_PROF_CNTS_SECT_NAME_STR \
697 INSTR_PROF_QUOTE(INSTR_PROF_CNTS_SECT_NAME)
698 #define INSTR_PROF_COVMAP_SECT_NAME_STR \
699 INSTR_PROF_QUOTE(INSTR_PROF_COVMAP_SECT_NAME)
700 #define INSTR_PROF_VALS_SECT_NAME_STR \
701 INSTR_PROF_QUOTE(INSTR_PROF_VALS_SECT_NAME)
702 #define INSTR_PROF_VNODES_SECT_NAME_STR \
703 INSTR_PROF_QUOTE(INSTR_PROF_VNODES_SECT_NAME)
710 #define INSTR_PROF_SECT_START(Sect) \
711 INSTR_PROF_CONCAT(__start_,Sect)
712 #define INSTR_PROF_SECT_STOP(Sect) \
713 INSTR_PROF_CONCAT(__stop_,Sect)
716 #define INSTR_PROF_VALUE_PROF_FUNC __llvm_profile_instrument_target
717 #define INSTR_PROF_VALUE_PROF_FUNC_STR \
718 INSTR_PROF_QUOTE(INSTR_PROF_VALUE_PROF_FUNC)
719 #define INSTR_PROF_VALUE_RANGE_PROF_FUNC __llvm_profile_instrument_range
720 #define INSTR_PROF_VALUE_RANGE_PROF_FUNC_STR \
721 INSTR_PROF_QUOTE(INSTR_PROF_VALUE_RANGE_PROF_FUNC)
724 #define INSTR_PROF_DATA_ALIGNMENT 8
729 typedef struct InstrProfValueData {
734 } InstrProfValueData;
739 #undef INSTR_PROF_DATA_DEFINED
#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 VALUE_PROF_KIND(Enumerator, Value)
uint64_t ComputeHash(StringRef K)
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
static const char *const Magic
#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)
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
#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.