1 /*===-- InstrProfData.inc - instr profiling runtime structures -*- C++ -*-=== *\
3 |* The LLVM Compiler Infrastructure
5 |* This file is distributed under the University of Illinois Open Source
6 |* License. See LICENSE.TXT for details.
8 \*===----------------------------------------------------------------------===*/
10 * This is the master file that defines all the data structure, signature,
11 * constant literals that are shared across profiling runtime library,
12 * compiler (instrumentation), and host tools (reader/writer). The entities
13 * defined in this file affect the profile runtime ABI, the raw profile format,
16 * The file has two identical copies. The master copy lives in LLVM and
17 * the other one sits in compiler-rt/lib/profile directory. To make changes
18 * in this file, first modify the master copy and copy it over to compiler-rt.
19 * Testing of any change in this file can start only after the two copies are
22 * The first part of the file includes macros that defines types, names, and
23 * initializers for the member fields of the core data structures. The field
24 * declarations for one structure is enabled by defining the field activation
25 * macro associated with that structure. Only one field activation record
26 * can be defined at one time and the rest definitions will be filtered out by
29 * Examples of how the template is used to instantiate structure definition:
30 * 1. To declare a structure:
33 * #define INSTR_PROF_DATA(Type, LLVMType, Name, Initializer) \
35 * #include "llvm/ProfileData/InstrProfData.inc"
38 * 2. To construct LLVM type arrays for the struct type:
40 * Type *DataTypes[] = {
41 * #define INSTR_PROF_DATA(Type, LLVMType, Name, Initializer) \
43 * #include "llvm/ProfileData/InstrProfData.inc"
46 * 4. To construct constant array for the initializers:
47 * #define INSTR_PROF_DATA(Type, LLVMType, Name, Initializer) \
49 * Constant *ConstantVals[] = {
50 * #include "llvm/ProfileData/InstrProfData.inc"
54 * The second part of the file includes definitions all other entities that
55 * are related to runtime ABI and format. When no field activation macro is
56 * defined, this file can be included to introduce the definitions.
58 \*===----------------------------------------------------------------------===*/
60 /* Functions marked with INSTR_PROF_VISIBILITY must have hidden visibility in
61 * the compiler runtime. */
62 #ifndef INSTR_PROF_VISIBILITY
63 #define INSTR_PROF_VISIBILITY
66 /* INSTR_PROF_DATA start. */
67 /* Definition of member fields of the per-function control structure. */
68 #ifndef INSTR_PROF_DATA
69 #define INSTR_PROF_DATA(Type, LLVMType, Name, Initializer)
71 #define INSTR_PROF_DATA_DEFINED
73 INSTR_PROF_DATA(const uint64_t, llvm::Type::getInt64Ty(Ctx), NameRef, \
74 ConstantInt::get(llvm::Type::getInt64Ty(Ctx), \
75 IndexedInstrProf::ComputeHash(getPGOFuncNameVarInitializer(Inc->getName()))))
76 INSTR_PROF_DATA(const uint64_t, llvm::Type::getInt64Ty(Ctx), FuncHash, \
77 ConstantInt::get(llvm::Type::getInt64Ty(Ctx), \
78 Inc->getHash()->getZExtValue()))
79 INSTR_PROF_DATA(const IntPtrT, llvm::Type::getInt64PtrTy(Ctx), CounterPtr, \
80 ConstantExpr::getBitCast(CounterPtr, \
81 llvm::Type::getInt64PtrTy(Ctx)))
82 /* This is used to map function pointers for the indirect call targets to
83 * function name hashes during the conversion from raw to merged profile
86 INSTR_PROF_DATA(const IntPtrT, llvm::Type::getInt8PtrTy(Ctx), FunctionPointer, \
88 INSTR_PROF_DATA(IntPtrT, llvm::Type::getInt8PtrTy(Ctx), Values, \
90 INSTR_PROF_DATA(const uint32_t, llvm::Type::getInt32Ty(Ctx), NumCounters, \
91 ConstantInt::get(llvm::Type::getInt32Ty(Ctx), NumCounters))
92 INSTR_PROF_DATA(const uint16_t, Int16ArrayTy, NumValueSites[IPVK_Last+1], \
93 ConstantArray::get(Int16ArrayTy, Int16ArrayVals))
94 #undef INSTR_PROF_DATA
95 /* INSTR_PROF_DATA end. */
98 /* This is an internal data structure used by value profiler. It
99 * is defined here to allow serialization code sharing by LLVM
100 * to be used in unit test.
102 * typedef struct ValueProfNode {
103 * // InstrProfValueData VData;
106 * struct ValueProfNode *Next;
109 /* INSTR_PROF_VALUE_NODE start. */
110 #ifndef INSTR_PROF_VALUE_NODE
111 #define INSTR_PROF_VALUE_NODE(Type, LLVMType, Name, Initializer)
113 #define INSTR_PROF_DATA_DEFINED
115 INSTR_PROF_VALUE_NODE(uint64_t, llvm::Type::getInt64Ty(Ctx), Value, \
116 ConstantInt::get(llvm::Type::GetInt64Ty(Ctx), 0))
117 INSTR_PROF_VALUE_NODE(uint64_t, llvm::Type::getInt64Ty(Ctx), Count, \
118 ConstantInt::get(llvm::Type::GetInt64Ty(Ctx), 0))
119 INSTR_PROF_VALUE_NODE(PtrToNodeT, llvm::Type::getInt8PtrTy(Ctx), Next, \
120 ConstantInt::get(llvm::Type::GetInt8PtrTy(Ctx), 0))
121 #undef INSTR_PROF_VALUE_NODE
122 /* INSTR_PROF_VALUE_NODE end. */
124 /* INSTR_PROF_RAW_HEADER start */
125 /* Definition of member fields of the raw profile header data structure. */
126 #ifndef INSTR_PROF_RAW_HEADER
127 #define INSTR_PROF_RAW_HEADER(Type, Name, Initializer)
129 #define INSTR_PROF_DATA_DEFINED
131 INSTR_PROF_RAW_HEADER(uint64_t, Magic, __llvm_profile_get_magic())
132 INSTR_PROF_RAW_HEADER(uint64_t, Version, __llvm_profile_get_version())
133 INSTR_PROF_RAW_HEADER(uint64_t, DataSize, DataSize)
134 INSTR_PROF_RAW_HEADER(uint64_t, CountersSize, CountersSize)
135 INSTR_PROF_RAW_HEADER(uint64_t, NamesSize, NamesSize)
136 INSTR_PROF_RAW_HEADER(uint64_t, CountersDelta, (uintptr_t)CountersBegin)
137 INSTR_PROF_RAW_HEADER(uint64_t, NamesDelta, (uintptr_t)NamesBegin)
138 INSTR_PROF_RAW_HEADER(uint64_t, ValueKindLast, IPVK_Last)
139 #undef INSTR_PROF_RAW_HEADER
140 /* INSTR_PROF_RAW_HEADER end */
142 /* VALUE_PROF_FUNC_PARAM start */
143 /* Definition of parameter types of the runtime API used to do value profiling
144 * for a given value site.
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 ,
153 VALUE_PROF_FUNC_PARAM(uint64_t, TargetValue, Type::getInt64Ty(Ctx)) \
155 VALUE_PROF_FUNC_PARAM(void *, Data, Type::getInt8PtrTy(Ctx)) INSTR_PROF_COMMA
156 #ifndef VALUE_RANGE_PROF
157 VALUE_PROF_FUNC_PARAM(uint32_t, CounterIndex, Type::getInt32Ty(Ctx))
158 #else /* VALUE_RANGE_PROF */
159 VALUE_PROF_FUNC_PARAM(uint32_t, CounterIndex, Type::getInt32Ty(Ctx)) \
161 VALUE_PROF_FUNC_PARAM(uint64_t, PreciseRangeStart, Type::getInt64Ty(Ctx)) \
163 VALUE_PROF_FUNC_PARAM(uint64_t, PreciseRangeLast, Type::getInt64Ty(Ctx)) \
165 VALUE_PROF_FUNC_PARAM(uint64_t, LargeValue, Type::getInt64Ty(Ctx))
166 #endif /*VALUE_RANGE_PROF */
167 #undef VALUE_PROF_FUNC_PARAM
168 #undef INSTR_PROF_COMMA
169 /* VALUE_PROF_FUNC_PARAM end */
171 /* VALUE_PROF_KIND start */
172 #ifndef VALUE_PROF_KIND
173 #define VALUE_PROF_KIND(Enumerator, Value)
175 #define INSTR_PROF_DATA_DEFINED
177 /* For indirect function call value profiling, the addresses of the target
178 * functions are profiled by the instrumented code. The target addresses are
179 * written in the raw profile data and converted to target function name's MD5
180 * hash by the profile reader during deserialization. Typically, this happens
181 * when the raw profile data is read during profile merging.
183 * For this remapping the ProfData is used. ProfData contains both the function
184 * name hash and the function address.
186 VALUE_PROF_KIND(IPVK_IndirectCallTarget, 0)
187 /* For memory intrinsic functions size profiling. */
188 VALUE_PROF_KIND(IPVK_MemOPSize, 1)
189 /* These two kinds must be the last to be
190 * declared. This is to make sure the string
191 * array created with the template can be
192 * indexed with the kind value.
194 VALUE_PROF_KIND(IPVK_First, IPVK_IndirectCallTarget)
195 VALUE_PROF_KIND(IPVK_Last, IPVK_MemOPSize)
197 #undef VALUE_PROF_KIND
198 /* VALUE_PROF_KIND end */
200 /* COVMAP_FUNC_RECORD start */
201 /* Definition of member fields of the function record structure in coverage
204 #ifndef COVMAP_FUNC_RECORD
205 #define COVMAP_FUNC_RECORD(Type, LLVMType, Name, Initializer)
207 #define INSTR_PROF_DATA_DEFINED
210 COVMAP_FUNC_RECORD(const IntPtrT, llvm::Type::getInt8PtrTy(Ctx), \
211 NamePtr, llvm::ConstantExpr::getBitCast(NamePtr, \
212 llvm::Type::getInt8PtrTy(Ctx)))
213 COVMAP_FUNC_RECORD(const uint32_t, llvm::Type::getInt32Ty(Ctx), NameSize, \
214 llvm::ConstantInt::get(llvm::Type::getInt32Ty(Ctx), \
217 COVMAP_FUNC_RECORD(const int64_t, llvm::Type::getInt64Ty(Ctx), NameRef, \
218 llvm::ConstantInt::get(llvm::Type::getInt64Ty(Ctx), \
219 llvm::IndexedInstrProf::ComputeHash(NameValue)))
221 COVMAP_FUNC_RECORD(const uint32_t, llvm::Type::getInt32Ty(Ctx), DataSize, \
222 llvm::ConstantInt::get(llvm::Type::getInt32Ty(Ctx),\
223 CoverageMapping.size()))
224 COVMAP_FUNC_RECORD(const uint64_t, llvm::Type::getInt64Ty(Ctx), FuncHash, \
225 llvm::ConstantInt::get(llvm::Type::getInt64Ty(Ctx), FuncHash))
226 #undef COVMAP_FUNC_RECORD
227 /* COVMAP_FUNC_RECORD end. */
229 /* COVMAP_HEADER start */
230 /* Definition of member fields of coverage map header.
232 #ifndef COVMAP_HEADER
233 #define COVMAP_HEADER(Type, LLVMType, Name, Initializer)
235 #define INSTR_PROF_DATA_DEFINED
237 COVMAP_HEADER(uint32_t, Int32Ty, NRecords, \
238 llvm::ConstantInt::get(Int32Ty, FunctionRecords.size()))
239 COVMAP_HEADER(uint32_t, Int32Ty, FilenamesSize, \
240 llvm::ConstantInt::get(Int32Ty, FilenamesSize))
241 COVMAP_HEADER(uint32_t, Int32Ty, CoverageSize, \
242 llvm::ConstantInt::get(Int32Ty, CoverageMappingSize))
243 COVMAP_HEADER(uint32_t, Int32Ty, Version, \
244 llvm::ConstantInt::get(Int32Ty, CovMapVersion::CurrentVersion))
246 /* COVMAP_HEADER end. */
249 #ifdef INSTR_PROF_SECT_ENTRY
250 #define INSTR_PROF_DATA_DEFINED
251 INSTR_PROF_SECT_ENTRY(IPSK_data, \
252 INSTR_PROF_QUOTE(INSTR_PROF_DATA_COMMON), \
253 INSTR_PROF_QUOTE(INSTR_PROF_DATA_COFF), "__DATA,")
254 INSTR_PROF_SECT_ENTRY(IPSK_cnts, \
255 INSTR_PROF_QUOTE(INSTR_PROF_CNTS_COMMON), \
256 INSTR_PROF_QUOTE(INSTR_PROF_CNTS_COFF), "__DATA,")
257 INSTR_PROF_SECT_ENTRY(IPSK_name, \
258 INSTR_PROF_QUOTE(INSTR_PROF_NAME_COMMON), \
259 INSTR_PROF_QUOTE(INSTR_PROF_NAME_COFF), "__DATA,")
260 INSTR_PROF_SECT_ENTRY(IPSK_vals, \
261 INSTR_PROF_QUOTE(INSTR_PROF_VALS_COMMON), \
262 INSTR_PROF_QUOTE(INSTR_PROF_VALS_COFF), "__DATA,")
263 INSTR_PROF_SECT_ENTRY(IPSK_vnodes, \
264 INSTR_PROF_QUOTE(INSTR_PROF_VNODES_COMMON), \
265 INSTR_PROF_QUOTE(INSTR_PROF_VNODES_COFF), "__DATA,")
266 INSTR_PROF_SECT_ENTRY(IPSK_covmap, \
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
279 * This is the header of the data structure that defines the on-disk
280 * layout of the value profile data of a particular kind for one function.
282 typedef struct ValueProfRecord {
283 /* The kind of the value profile record. */
286 * The number of value profile sites. It is guaranteed to be non-zero;
287 * otherwise the record for this kind won't be emitted.
289 uint32_t NumValueSites;
291 * The first element of the array that stores the number of profiled
292 * values for each value site. The size of the array is NumValueSites.
293 * Since NumValueSites is greater than zero, there is at least one
294 * element in the array.
296 uint8_t SiteCountArray[1];
299 * The fake declaration is for documentation purpose only.
300 * Align the start of next field to be on 8 byte boundaries.
304 /* The array of value profile data. The size of the array is the sum
305 * of all elements in SiteCountArray[].
306 InstrProfValueData ValueData[];
311 * \brief Return the number of value sites.
313 uint32_t getNumValueSites() const { return NumValueSites; }
315 * \brief Read data from this record and save it to Record.
317 void deserializeTo(InstrProfRecord &Record,
318 InstrProfRecord::ValueMapType *VMap);
320 * In-place byte swap:
321 * Do byte swap for this instance. \c Old is the original order before
322 * the swap, and \c New is the New byte order.
324 void swapBytes(support::endianness Old, support::endianness New);
329 * Per-function header/control data structure for value profiling
330 * data in indexed format.
332 typedef struct ValueProfData {
334 * Total size in bytes including this field. It must be a multiple
335 * of sizeof(uint64_t).
339 *The number of value profile kinds that has value profile data.
340 * In this implementation, a value profile kind is considered to
341 * have profile data if the number of value profile sites for the
342 * kind is not zero. More aggressively, the implementation can
343 * choose to check the actual data value: if none of the value sites
344 * has any profiled values, the kind can be skipped.
346 uint32_t NumValueKinds;
349 * Following are a sequence of variable length records. The prefix/header
350 * of each record is defined by ValueProfRecord type. The number of
351 * records is NumValueKinds.
352 * ValueProfRecord Record_1;
353 * ValueProfRecord Record_N;
358 * Return the total size in bytes of the on-disk value profile data
359 * given the data stored in Record.
361 static uint32_t getSize(const InstrProfRecord &Record);
363 * Return a pointer to \c ValueProfData instance ready to be streamed.
365 static std::unique_ptr<ValueProfData>
366 serializeFrom(const InstrProfRecord &Record);
368 * Check the integrity of the record.
370 Error checkIntegrity();
372 * Return a pointer to \c ValueProfileData instance ready to be read.
373 * All data in the instance are properly byte swapped. The input
374 * data is assumed to be in little endian order.
376 static Expected<std::unique_ptr<ValueProfData>>
377 getValueProfData(const unsigned char *SrcBuffer,
378 const unsigned char *const SrcBufferEnd,
379 support::endianness SrcDataEndianness);
381 * Swap byte order from \c Endianness order to host byte order.
383 void swapBytesToHost(support::endianness Endianness);
385 * Swap byte order from host byte order to \c Endianness order.
387 void swapBytesFromHost(support::endianness Endianness);
389 * Return the total size of \c ValueProfileData.
391 uint32_t getSize() const { return TotalSize; }
393 * Read data from this data and save it to \c Record.
395 void deserializeTo(InstrProfRecord &Record,
396 InstrProfRecord::ValueMapType *VMap);
397 void operator delete(void *ptr) { ::operator delete(ptr); }
402 * The closure is designed to abstact away two types of value profile data:
403 * - InstrProfRecord which is the primary data structure used to
404 * represent profile data in host tools (reader, writer, and profile-use)
405 * - value profile runtime data structure suitable to be used by C
408 * Both sources of data need to serialize to disk/memory-buffer in common
409 * format: ValueProfData. The abstraction allows compiler-rt's raw profiler
410 * writer to share the same format and code with indexed profile writer.
412 * For documentation of the member methods below, refer to corresponding methods
413 * in class InstrProfRecord.
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);
423 * After extracting the value profile data from the value profile record,
424 * this method is used to map the in-memory value to on-disk value. If
425 * the method is null, value will be written out untranslated.
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
443 #endif /* 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)
461 * \brief Return the \c ValueProfRecord header size including the
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;
468 /* Round the size to multiple of 8 bytes. */
469 Size = (Size + 7) & ~7;
474 * \brief Return the total size of the value profile record including the
475 * header and the value data.
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;
485 * \brief Return the pointer to the start of value data array.
487 INSTR_PROF_VISIBILITY INSTR_PROF_INLINE
488 InstrProfValueData *getValueProfRecordValueData(ValueProfRecord *This) {
489 return (InstrProfValueData *)((char *)This + getValueProfRecordHeaderSize(
490 This->NumValueSites));
494 * \brief Return the total number of value data for \c This record.
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];
506 * \brief Use this method to advance to the next \c This \c ValueProfRecord.
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,
517 * \brief Return the first \c ValueProfRecord instance.
519 INSTR_PROF_VISIBILITY INSTR_PROF_INLINE
520 ValueProfRecord *getFirstValueProfRecord(ValueProfData *This) {
521 return (ValueProfRecord *)((char *)This + sizeof(ValueProfData));
524 /* Closure based interfaces. */
527 * Return the total size in bytes of the on-disk value profile data
528 * given the data stored in Record.
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));
547 * Extract value profile data of a function for the profile kind \c ValueKind
548 * from the \c Closure and serialize the data into \c This record instance.
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;
556 This->Kind = ValueKind;
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);
569 * Extract value profile data of a function from the \c Closure
570 * and serialize the data into \c DstData if it is not NULL or heap
571 * memory allocated by the \c Closure's allocator method. If \c
572 * DstData is not null, the caller is expected to set the TotalSize
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
599 #endif /* INSTR_PROF_COMMON_API_IMPL */
601 /*============================================================================*/
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)
614 /* Magic number to detect file format and endianness.
615 * Use 255 at one end, since no UTF-8 file can use that character. Avoid 0,
616 * so that utilities, like strings, don't grab it as a string. 129 is also
617 * invalid UTF-8, and high enough to be interesting.
618 * Use "lprofr" in the centre to stand for "LLVM Profile Raw", or "lprofR"
619 * for 32-bit platforms.
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
628 /* Raw profile format version (start from 1). */
629 #define INSTR_PROF_RAW_VERSION 4
630 /* Indexed profile format version (start from 1). */
631 #define INSTR_PROF_INDEX_VERSION 5
632 /* Coverage mapping format vresion (start from 0). */
633 #define INSTR_PROF_COVMAP_VERSION 2
635 /* Profile version is always of type uint64_t. Reserve the upper 8 bits in the
636 * version for other variants of profile. We set the lowest bit of the upper 8
637 * bits (i.e. bit 56) to 1 to indicate if this is an IR-level instrumentaiton
638 * generated profile, and 0 if this is a Clang FE generated profile.
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
646 /* The variable that holds the name of the profile data
647 * specified via command line. */
648 #define INSTR_PROF_PROFILE_NAME_VAR __llvm_profile_filename
650 /* section name strings common to all targets other
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
667 /* Runtime section names and name strings. */
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
671 /* Array of pointers. Each pointer points to a list
672 * of value nodes associated with one value site.
674 #define INSTR_PROF_VALS_SECT_NAME INSTR_PROF_VALS_COFF
675 /* Value profile nodes section. */
676 #define INSTR_PROF_VNODES_SECT_NAME INSTR_PROF_VNODES_COFF
677 #define INSTR_PROF_COVMAP_SECT_NAME INSTR_PROF_COVMAP_COFF
679 /* Runtime section names and name strings. */
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
683 /* Array of pointers. Each pointer points to a list
684 * of value nodes associated with one value site.
686 #define INSTR_PROF_VALS_SECT_NAME INSTR_PROF_VALS_COMMON
687 /* Value profile nodes section. */
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)
705 /* Macros to define start/stop section symbol for a given
706 * section on Linux. For instance
707 * INSTR_PROF_SECT_START(INSTR_PROF_DATA_SECT_NAME) will
708 * expand to __start___llvm_prof_data
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)
715 /* Value Profiling API linkage name. */
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)
723 /* InstrProfile per-function control data alignment. */
724 #define INSTR_PROF_DATA_ALIGNMENT 8
726 /* The data structure that represents a tracked value by the
729 typedef struct InstrProfValueData {
730 /* Profiled value. */
732 /* Number of times the value appears in the training run. */
734 } InstrProfValueData;
736 #endif /* INSTR_PROF_DATA_INC */
739 #undef INSTR_PROF_DATA_DEFINED