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 ,
157 #undef VALUE_PROF_FUNC_PARAM
158 #undef INSTR_PROF_COMMA
162 #ifndef VALUE_PROF_KIND
163 #define VALUE_PROF_KIND(Enumerator, Value)
165 #define INSTR_PROF_DATA_DEFINED
185 #undef VALUE_PROF_KIND
192 #ifndef COVMAP_FUNC_RECORD
193 #define COVMAP_FUNC_RECORD(Type, LLVMType, Name, Initializer)
195 #define INSTR_PROF_DATA_DEFINED
202 llvm::ConstantInt::get(llvm::
Type::getInt32Ty(Ctx), \
211 CoverageMapping.size()))
213 llvm::ConstantInt::get(llvm::
Type::getInt64Ty(Ctx), FuncHash))
214 #undef COVMAP_FUNC_RECORD
220 #ifndef COVMAP_HEADER
221 #define COVMAP_HEADER(Type, LLVMType, Name, Initializer)
223 #define INSTR_PROF_DATA_DEFINED
228 llvm::ConstantInt::get(Int32Ty, FilenamesSize))
230 llvm::ConstantInt::get(Int32Ty, CoverageMappingSize))
237 #ifdef INSTR_PROF_VALUE_PROF_DATA
238 #define INSTR_PROF_DATA_DEFINED
240 #define INSTR_PROF_MAX_NUM_VAL_PER_SITE 255
245 typedef struct ValueProfRecord {
252 uint32_t NumValueSites;
259 uint8_t SiteCountArray[1];
276 uint32_t getNumValueSites()
const {
return NumValueSites; }
280 void deserializeTo(InstrProfRecord &Record,
281 InstrProfRecord::ValueMapType *VMap);
295 typedef struct ValueProfData {
309 uint32_t NumValueKinds;
324 static uint32_t getSize(
const InstrProfRecord &Record);
328 static std::unique_ptr<ValueProfData>
329 serializeFrom(
const InstrProfRecord &Record);
333 Error checkIntegrity();
339 static Expected<std::unique_ptr<ValueProfData>>
340 getValueProfData(
const unsigned char *SrcBuffer,
341 const unsigned char *
const SrcBufferEnd,
354 uint32_t getSize()
const {
return TotalSize; }
358 void deserializeTo(InstrProfRecord &Record,
359 InstrProfRecord::ValueMapType *VMap);
360 void operator delete(
void *ptr) { ::operator
delete(ptr); }
378 typedef struct ValueProfRecordClosure {
380 uint32_t (*GetNumValueKinds)(
const void *Record);
381 uint32_t (*GetNumValueSites)(
const void *Record, uint32_t VKind);
382 uint32_t (*GetNumValueData)(
const void *Record, uint32_t VKind);
383 uint32_t (*GetNumValueDataForSite)(
const void *R, uint32_t VK, uint32_t S);
390 uint64_t (*RemapValueData)(uint32_t, uint64_t Value);
391 void (*GetValueForSite)(
const void *R, InstrProfValueData *Dst, uint32_t K,
393 ValueProfData *(*AllocValueProfData)(
size_t TotalSizeInBytes);
394 } ValueProfRecordClosure;
396 INSTR_PROF_VISIBILITY ValueProfRecord *
397 getFirstValueProfRecord(ValueProfData *VPD);
398 INSTR_PROF_VISIBILITY ValueProfRecord *
399 getValueProfRecordNext(ValueProfRecord *VPR);
400 INSTR_PROF_VISIBILITY InstrProfValueData *
401 getValueProfRecordValueData(ValueProfRecord *VPR);
402 INSTR_PROF_VISIBILITY uint32_t
403 getValueProfRecordHeaderSize(uint32_t NumValueSites);
405 #undef INSTR_PROF_VALUE_PROF_DATA
409 #ifdef INSTR_PROF_COMMON_API_IMPL
410 #define INSTR_PROF_DATA_DEFINED
412 #define INSTR_PROF_INLINE inline
413 #define INSTR_PROF_NULLPTR nullptr
415 #define INSTR_PROF_INLINE
416 #define INSTR_PROF_NULLPTR NULL
420 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
427 INSTR_PROF_VISIBILITY INSTR_PROF_INLINE
428 uint32_t getValueProfRecordHeaderSize(uint32_t NumValueSites) {
429 uint32_t Size = offsetof(ValueProfRecord, SiteCountArray) +
430 sizeof(uint8_t) * NumValueSites;
432 Size = (Size + 7) & ~7;
440 INSTR_PROF_VISIBILITY INSTR_PROF_INLINE
441 uint32_t getValueProfRecordSize(uint32_t NumValueSites,
442 uint32_t NumValueData) {
443 return getValueProfRecordHeaderSize(NumValueSites) +
444 sizeof(InstrProfValueData) * NumValueData;
450 INSTR_PROF_VISIBILITY INSTR_PROF_INLINE
451 InstrProfValueData *getValueProfRecordValueData(ValueProfRecord *This) {
452 return (InstrProfValueData *)((
char *)This + getValueProfRecordHeaderSize(
453 This->NumValueSites));
459 INSTR_PROF_VISIBILITY INSTR_PROF_INLINE
460 uint32_t getValueProfRecordNumValueData(ValueProfRecord *This) {
461 uint32_t NumValueData = 0;
463 for (I = 0; I < This->NumValueSites; I++)
464 NumValueData += This->SiteCountArray[I];
471 INSTR_PROF_VISIBILITY INSTR_PROF_INLINE
472 ValueProfRecord *getValueProfRecordNext(ValueProfRecord *This) {
473 uint32_t NumValueData = getValueProfRecordNumValueData(This);
474 return (ValueProfRecord *)((
char *)This +
475 getValueProfRecordSize(This->NumValueSites,
482 INSTR_PROF_VISIBILITY INSTR_PROF_INLINE
483 ValueProfRecord *getFirstValueProfRecord(ValueProfData *This) {
484 return (ValueProfRecord *)((
char *)This +
sizeof(ValueProfData));
493 INSTR_PROF_VISIBILITY uint32_t
494 getValueProfDataSize(ValueProfRecordClosure *Closure) {
496 uint32_t TotalSize =
sizeof(ValueProfData);
497 const void *Record = Closure->Record;
499 for (Kind = IPVK_First; Kind <= IPVK_Last; Kind++) {
500 uint32_t NumValueSites = Closure->GetNumValueSites(Record, Kind);
503 TotalSize += getValueProfRecordSize(NumValueSites,
504 Closure->GetNumValueData(Record, Kind));
513 INSTR_PROF_VISIBILITY
void
514 serializeValueProfRecordFrom(ValueProfRecord *This,
515 ValueProfRecordClosure *Closure,
516 uint32_t ValueKind, uint32_t NumValueSites) {
518 const void *Record = Closure->Record;
519 This->Kind = ValueKind;
520 This->NumValueSites = NumValueSites;
521 InstrProfValueData *DstVD = getValueProfRecordValueData(This);
523 for (S = 0; S < NumValueSites; S++) {
524 uint32_t ND = Closure->GetNumValueDataForSite(Record, ValueKind, S);
525 This->SiteCountArray[S] = ND;
526 Closure->GetValueForSite(Record, DstVD, ValueKind, S);
538 INSTR_PROF_VISIBILITY ValueProfData *
539 serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
540 ValueProfData *DstData) {
543 DstData ? DstData->TotalSize : getValueProfDataSize(Closure);
546 DstData ? DstData : Closure->AllocValueProfData(TotalSize);
548 VPD->TotalSize = TotalSize;
549 VPD->NumValueKinds = Closure->GetNumValueKinds(Closure->Record);
550 ValueProfRecord *VR = getFirstValueProfRecord(VPD);
551 for (Kind = IPVK_First; Kind <= IPVK_Last; Kind++) {
552 uint32_t NumValueSites = Closure->GetNumValueSites(Closure->Record, Kind);
555 serializeValueProfRecordFrom(VR, Closure, Kind, NumValueSites);
556 VR = getValueProfRecordNext(VR);
561 #undef INSTR_PROF_COMMON_API_IMPL
566 #ifndef INSTR_PROF_DATA_DEFINED
568 #ifndef INSTR_PROF_DATA_INC
569 #define INSTR_PROF_DATA_INC
572 #define INSTR_PROF_SIMPLE_QUOTE(x) #x
573 #define INSTR_PROF_QUOTE(x) INSTR_PROF_SIMPLE_QUOTE(x)
574 #define INSTR_PROF_SIMPLE_CONCAT(x,y) x ## y
575 #define INSTR_PROF_CONCAT(x,y) INSTR_PROF_SIMPLE_CONCAT(x,y)
584 #define INSTR_PROF_RAW_MAGIC_64 (uint64_t)255 << 56 | (uint64_t)'l' << 48 | \
585 (uint64_t)'p' << 40 | (uint64_t)'r' << 32 | (uint64_t)'o' << 24 | \
586 (uint64_t)'f' << 16 | (uint64_t)'r' << 8 | (uint64_t)129
587 #define INSTR_PROF_RAW_MAGIC_32 (uint64_t)255 << 56 | (uint64_t)'l' << 48 | \
588 (uint64_t)'p' << 40 | (uint64_t)'r' << 32 | (uint64_t)'o' << 24 | \
589 (uint64_t)'f' << 16 | (uint64_t)'R' << 8 | (uint64_t)129
592 #define INSTR_PROF_RAW_VERSION 4
594 #define INSTR_PROF_INDEX_VERSION 4
596 #define INSTR_PROF_COVMAP_VERSION 1
603 #define VARIANT_MASKS_ALL 0xff00000000000000ULL
604 #define GET_VERSION(V) ((V) & ~VARIANT_MASKS_ALL)
605 #define VARIANT_MASK_IR_PROF (0x1ULL << 56)
606 #define INSTR_PROF_RAW_VERSION_VAR __llvm_profile_raw_version
607 #define INSTR_PROF_PROFILE_RUNTIME_VAR __llvm_profile_runtime
611 #define INSTR_PROF_PROFILE_NAME_VAR __llvm_profile_filename
614 #define INSTR_PROF_DATA_SECT_NAME __llvm_prf_data
615 #define INSTR_PROF_NAME_SECT_NAME __llvm_prf_names
616 #define INSTR_PROF_CNTS_SECT_NAME __llvm_prf_cnts
620 #define INSTR_PROF_VALS_SECT_NAME __llvm_prf_vals
622 #define INSTR_PROF_VNODES_SECT_NAME __llvm_prf_vnds
623 #define INSTR_PROF_COVMAP_SECT_NAME __llvm_covmap
625 #define INSTR_PROF_DATA_SECT_NAME_STR \
626 INSTR_PROF_QUOTE(INSTR_PROF_DATA_SECT_NAME)
627 #define INSTR_PROF_NAME_SECT_NAME_STR \
628 INSTR_PROF_QUOTE(INSTR_PROF_NAME_SECT_NAME)
629 #define INSTR_PROF_CNTS_SECT_NAME_STR \
630 INSTR_PROF_QUOTE(INSTR_PROF_CNTS_SECT_NAME)
631 #define INSTR_PROF_COVMAP_SECT_NAME_STR \
632 INSTR_PROF_QUOTE(INSTR_PROF_COVMAP_SECT_NAME)
633 #define INSTR_PROF_VALS_SECT_NAME_STR \
634 INSTR_PROF_QUOTE(INSTR_PROF_VALS_SECT_NAME)
635 #define INSTR_PROF_VNODES_SECT_NAME_STR \
636 INSTR_PROF_QUOTE(INSTR_PROF_VNODES_SECT_NAME)
643 #define INSTR_PROF_SECT_START(Sect) \
644 INSTR_PROF_CONCAT(__start_,Sect)
645 #define INSTR_PROF_SECT_STOP(Sect) \
646 INSTR_PROF_CONCAT(__stop_,Sect)
649 #define INSTR_PROF_VALUE_PROF_FUNC __llvm_profile_instrument_target
650 #define INSTR_PROF_VALUE_PROF_FUNC_STR \
651 INSTR_PROF_QUOTE(INSTR_PROF_VALUE_PROF_FUNC)
654 #define INSTR_PROF_DATA_ALIGNMENT 8
659 typedef struct InstrProfValueData {
664 } InstrProfValueData;
669 #undef INSTR_PROF_DATA_DEFINED
#define VALUE_PROF_FUNC_PARAM(ParamType, ParamName, ParamLLVMType)
static IntegerType * getInt64Ty(LLVMContext &C)
#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 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.