1 /*===-- InstrProfData.inc - instr profiling runtime structures -----------=== *\
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 /* INSTR_PROF_DATA start. */
61 /* Definition of member fields of the per-function control structure. */
62 #ifndef INSTR_PROF_DATA
63 #define INSTR_PROF_DATA(Type, LLVMType, Name, Initializer)
65 #define INSTR_PROF_DATA_DEFINED
68 INSTR_PROF_DATA(const uint32_t, llvm::Type::getInt32Ty(Ctx), NameSize, \
69 ConstantInt::get(llvm::Type::getInt32Ty(Ctx), \
70 NamePtr->getType()->getPointerElementType()->getArrayNumElements()))
71 INSTR_PROF_DATA(const uint32_t, llvm::Type::getInt32Ty(Ctx), NumCounters, \
72 ConstantInt::get(llvm::Type::getInt32Ty(Ctx), NumCounters))
73 INSTR_PROF_DATA(const uint64_t, llvm::Type::getInt64Ty(Ctx), FuncHash, \
74 ConstantInt::get(llvm::Type::getInt64Ty(Ctx), \
75 Inc->getHash()->getZExtValue()))
76 INSTR_PROF_DATA(const IntPtrT, llvm::Type::getInt8PtrTy(Ctx), NamePtr, \
77 ConstantExpr::getBitCast(NamePtr, llvm::Type::getInt8PtrTy(Ctx)))
78 INSTR_PROF_DATA(const IntPtrT, llvm::Type::getInt64PtrTy(Ctx), CounterPtr, \
79 ConstantExpr::getBitCast(CounterPtr, \
80 llvm::Type::getInt64PtrTy(Ctx)))
81 INSTR_PROF_DATA(const IntPtrT, llvm::Type::getInt8PtrTy(Ctx), FunctionPointer, \
83 INSTR_PROF_DATA(IntPtrT, llvm::Type::getInt8PtrTy(Ctx), Values, \
84 ConstantPointerNull::get(Int8PtrTy))
85 INSTR_PROF_DATA(const uint16_t, Int16ArrayTy, NumValueSites[IPVK_Last+1], \
86 ConstantArray::get(Int16ArrayTy, Int16ArrayVals))
87 #undef INSTR_PROF_DATA
88 /* INSTR_PROF_DATA end. */
90 /* INSTR_PROF_RAW_HEADER start */
91 /* Definition of member fields of the raw profile header data structure. */
92 #ifndef INSTR_PROF_RAW_HEADER
93 #define INSTR_PROF_RAW_HEADER(Type, Name, Initializer)
95 #define INSTR_PROF_DATA_DEFINED
97 INSTR_PROF_RAW_HEADER(uint64_t, Magic, __llvm_profile_get_magic())
98 INSTR_PROF_RAW_HEADER(uint64_t, Version, __llvm_profile_get_version())
99 INSTR_PROF_RAW_HEADER(uint64_t, DataSize, DataSize)
100 INSTR_PROF_RAW_HEADER(uint64_t, CountersSize, CountersSize)
101 INSTR_PROF_RAW_HEADER(uint64_t, NamesSize, NamesSize)
102 INSTR_PROF_RAW_HEADER(uint64_t, CountersDelta, (uintptr_t)CountersBegin)
103 INSTR_PROF_RAW_HEADER(uint64_t, NamesDelta, (uintptr_t)NamesBegin)
104 INSTR_PROF_RAW_HEADER(uint64_t, ValueKindLast, IPVK_Last)
105 INSTR_PROF_RAW_HEADER(uint64_t, ValueDataSize, ValueDataSize)
106 INSTR_PROF_RAW_HEADER(uint64_t, ValueDataDelta, (uintptr_t)ValueDataBegin)
107 #undef INSTR_PROF_RAW_HEADER
108 /* INSTR_PROF_RAW_HEADER end */
110 /* VALUE_PROF_FUNC_PARAM start */
111 /* Definition of parameter types of the runtime API used to do value profiling
112 * for a given value site.
114 #ifndef VALUE_PROF_FUNC_PARAM
115 #define VALUE_PROF_FUNC_PARAM(ArgType, ArgName, ArgLLVMType)
116 #define INSTR_PROF_COMMA
118 #define INSTR_PROF_DATA_DEFINED
119 #define INSTR_PROF_COMMA ,
121 VALUE_PROF_FUNC_PARAM(uint64_t, TargetValue, Type::getInt64Ty(Ctx)) \
123 VALUE_PROF_FUNC_PARAM(void *, Data, Type::getInt8PtrTy(Ctx)) INSTR_PROF_COMMA
124 VALUE_PROF_FUNC_PARAM(uint32_t, CounterIndex, Type::getInt32Ty(Ctx))
125 #undef VALUE_PROF_FUNC_PARAM
126 #undef INSTR_PROF_COMMA
127 /* VALUE_PROF_FUNC_PARAM end */
129 /* VALUE_PROF_KIND start */
130 #ifndef VALUE_PROF_KIND
131 #define VALUE_PROF_KIND(Enumerator, Value)
133 #define INSTR_PROF_DATA_DEFINED
135 VALUE_PROF_KIND(IPVK_IndirectCallTarget, 0)
136 /* These two kinds must be the last to be
137 * declared. This is to make sure the string
138 * array created with the template can be
139 * indexed with the kind value.
141 VALUE_PROF_KIND(IPVK_First, IPVK_IndirectCallTarget)
142 VALUE_PROF_KIND(IPVK_Last, IPVK_IndirectCallTarget)
144 #undef VALUE_PROF_KIND
145 /* VALUE_PROF_KIND end */
147 /* COVMAP_FUNC_RECORD start */
148 /* Definition of member fields of the function record structure in coverage
151 #ifndef COVMAP_FUNC_RECORD
152 #define COVMAP_FUNC_RECORD(Type, LLVMType, Name, Initializer)
154 #define INSTR_PROF_DATA_DEFINED
156 COVMAP_FUNC_RECORD(const IntPtrT, llvm::Type::getInt8PtrTy(Ctx), \
157 NamePtr, llvm::ConstantExpr::getBitCast(NamePtr, \
158 llvm::Type::getInt8PtrTy(Ctx)))
159 COVMAP_FUNC_RECORD(const uint32_t, llvm::Type::getInt32Ty(Ctx), NameSize, \
160 llvm::ConstantInt::get(llvm::Type::getInt32Ty(Ctx),\
162 COVMAP_FUNC_RECORD(const uint32_t, llvm::Type::getInt32Ty(Ctx), DataSize, \
163 llvm::ConstantInt::get(llvm::Type::getInt32Ty(Ctx),\
164 CoverageMapping.size()))
165 COVMAP_FUNC_RECORD(const uint64_t, llvm::Type::getInt64Ty(Ctx), FuncHash, \
166 llvm::ConstantInt::get(llvm::Type::getInt64Ty(Ctx), FuncHash))
167 #undef COVMAP_FUNC_RECORD
168 /* COVMAP_FUNC_RECORD end. */
171 #ifdef INSTR_PROF_VALUE_PROF_DATA
172 #define INSTR_PROF_DATA_DEFINED
175 * This is the header of the data structure that defines the on-disk
176 * layout of the value profile data of a particular kind for one function.
178 typedef struct ValueProfRecord {
179 /* The kind of the value profile record. */
182 * The number of value profile sites. It is guaranteed to be non-zero;
183 * otherwise the record for this kind won't be emitted.
185 uint32_t NumValueSites;
187 * The first element of the array that stores the number of profiled
188 * values for each value site. The size of the array is NumValueSites.
189 * Since NumValueSites is greater than zero, there is at least one
190 * element in the array.
192 uint8_t SiteCountArray[1];
195 * The fake declaration is for documentation purpose only.
196 * Align the start of next field to be on 8 byte boundaries.
200 /* The array of value profile data. The size of the array is the sum
201 * of all elements in SiteCountArray[].
202 InstrProfValueData ValueData[];
207 * \brief Return the number of value sites.
209 uint32_t getNumValueSites() const { return NumValueSites; }
211 * \brief Read data from this record and save it to Record.
213 void deserializeTo(InstrProfRecord &Record,
214 InstrProfRecord::ValueMapType *VMap);
216 * In-place byte swap:
217 * Do byte swap for this instance. \c Old is the original order before
218 * the swap, and \c New is the New byte order.
220 void swapBytes(support::endianness Old, support::endianness New);
225 * Per-function header/control data structure for value profiling
226 * data in indexed format.
228 typedef struct ValueProfData {
230 * Total size in bytes including this field. It must be a multiple
231 * of sizeof(uint64_t).
235 *The number of value profile kinds that has value profile data.
236 * In this implementation, a value profile kind is considered to
237 * have profile data if the number of value profile sites for the
238 * kind is not zero. More aggressively, the implementation can
239 * choose to check the actual data value: if none of the value sites
240 * has any profiled values, the kind can be skipped.
242 uint32_t NumValueKinds;
245 * Following are a sequence of variable length records. The prefix/header
246 * of each record is defined by ValueProfRecord type. The number of
247 * records is NumValueKinds.
248 * ValueProfRecord Record_1;
249 * ValueProfRecord Record_N;
254 * Return the total size in bytes of the on-disk value profile data
255 * given the data stored in Record.
257 static uint32_t getSize(const InstrProfRecord &Record);
259 * Return a pointer to \c ValueProfData instance ready to be streamed.
261 static std::unique_ptr<ValueProfData>
262 serializeFrom(const InstrProfRecord &Record);
264 * Check the integrity of the record. Return the error code when
265 * an error is detected, otherwise return instrprof_error::success.
267 instrprof_error checkIntegrity();
269 * Return a pointer to \c ValueProfileData instance ready to be read.
270 * All data in the instance are properly byte swapped. The input
271 * data is assumed to be in little endian order.
273 static ErrorOr<std::unique_ptr<ValueProfData>>
274 getValueProfData(const unsigned char *SrcBuffer,
275 const unsigned char *const SrcBufferEnd,
276 support::endianness SrcDataEndianness);
278 * Swap byte order from \c Endianness order to host byte order.
280 void swapBytesToHost(support::endianness Endianness);
282 * Swap byte order from host byte order to \c Endianness order.
284 void swapBytesFromHost(support::endianness Endianness);
286 * Return the total size of \c ValueProfileData.
288 uint32_t getSize() const { return TotalSize; }
290 * Read data from this data and save it to \c Record.
292 void deserializeTo(InstrProfRecord &Record,
293 InstrProfRecord::ValueMapType *VMap);
298 * The closure is designed to abstact away two types of value profile data:
299 * - InstrProfRecord which is the primary data structure used to
300 * represent profile data in host tools (reader, writer, and profile-use)
301 * - value profile runtime data structure suitable to be used by C
304 * Both sources of data need to serialize to disk/memory-buffer in common
305 * format: ValueProfData. The abstraction allows compiler-rt's raw profiler
306 * writer to share * the same code with indexed profile writer.
308 * For documentation of the member methods below, refer to corresponding methods
309 * in class InstrProfRecord.
311 typedef struct ValueProfRecordClosure {
313 uint32_t (*GetNumValueKinds)(const void *Record);
314 uint32_t (*GetNumValueSites)(const void *Record, uint32_t VKind);
315 uint32_t (*GetNumValueData)(const void *Record, uint32_t VKind);
316 uint32_t (*GetNumValueDataForSite)(const void *R, uint32_t VK, uint32_t S);
319 * After extracting the value profile data from the value profile record,
320 * this method is used to map the in-memory value to on-disk value. If
321 * the method is null, value will be written out untranslated.
323 uint64_t (*RemapValueData)(uint32_t, uint64_t Value);
324 void (*GetValueForSite)(const void *R, InstrProfValueData *Dst, uint32_t K,
325 uint32_t S, uint64_t (*Mapper)(uint32_t, uint64_t));
326 ValueProfData *(*AllocValueProfData)(size_t TotalSizeInBytes);
327 } ValueProfRecordClosure;
330 * A wrapper struct that represents value profile runtime data.
331 * Like InstrProfRecord class which is used by profiling host tools,
332 * ValueProfRuntimeRecord also implements the abstract intefaces defined in
333 * ValueProfRecordClosure so that the runtime data can be serialized using
334 * shared C implementation. In this structure, NumValueSites and Nodes
335 * members are the primary fields while other fields hold the derived
336 * information for fast implementation of closure interfaces.
338 typedef struct ValueProfRuntimeRecord {
339 /* Number of sites for each value profile kind. */
340 uint16_t *NumValueSites;
341 /* An array of linked-list headers. The size of of the array is the
342 * total number of value profile sites : sum(NumValueSites[*])). Each
343 * linked-list stores the values profiled for a value profile site. */
344 ValueProfNode **Nodes;
346 /* Total number of value profile kinds which have at least one
347 * value profile sites. */
348 uint32_t NumValueKinds;
349 /* An array recording the number of values tracked at each site.
350 * The size of the array is TotalNumValueSites. */
351 uint8_t *SiteCountArray[IPVK_Last + 1];
352 ValueProfNode **NodesKind[IPVK_Last + 1];
353 } ValueProfRuntimeRecord;
355 #undef INSTR_PROF_VALUE_PROF_DATA
356 #endif /* INSTR_PROF_VALUE_PROF_DATA */
359 #ifdef INSTR_PROF_COMMON_API_IMPL
360 #define INSTR_PROF_DATA_DEFINED
362 #define INSTR_PROF_INLINE inline
364 #define INSTR_PROF_INLINE
368 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
372 * \brief Return the \c ValueProfRecord header size including the
376 uint32_t getValueProfRecordHeaderSize(uint32_t NumValueSites) {
377 uint32_t Size = offsetof(ValueProfRecord, SiteCountArray) +
378 sizeof(uint8_t) * NumValueSites;
379 /* Round the size to multiple of 8 bytes. */
380 Size = (Size + 7) & ~7;
385 * \brief Return the total size of the value profile record including the
386 * header and the value data.
389 uint32_t getValueProfRecordSize(uint32_t NumValueSites,
390 uint32_t NumValueData) {
391 return getValueProfRecordHeaderSize(NumValueSites) +
392 sizeof(InstrProfValueData) * NumValueData;
396 * \brief Return the pointer to the start of value data array.
399 InstrProfValueData *getValueProfRecordValueData(ValueProfRecord *This) {
400 return (InstrProfValueData *)((char *)This + getValueProfRecordHeaderSize(
401 This->NumValueSites));
405 * \brief Return the total number of value data for \c This record.
408 uint32_t getValueProfRecordNumValueData(ValueProfRecord *This) {
409 uint32_t NumValueData = 0;
411 for (I = 0; I < This->NumValueSites; I++)
412 NumValueData += This->SiteCountArray[I];
417 * \brief Use this method to advance to the next \c This \c ValueProfRecord.
420 ValueProfRecord *getValueProfRecordNext(ValueProfRecord *This) {
421 uint32_t NumValueData = getValueProfRecordNumValueData(This);
422 return (ValueProfRecord *)((char *)This +
423 getValueProfRecordSize(This->NumValueSites,
428 * \brief Return the first \c ValueProfRecord instance.
431 ValueProfRecord *getFirstValueProfRecord(ValueProfData *This) {
432 return (ValueProfRecord *)((char *)This + sizeof(ValueProfData));
435 /* Closure based interfaces. */
438 * Return the total size in bytes of the on-disk value profile data
439 * given the data stored in Record.
441 uint32_t getValueProfDataSize(ValueProfRecordClosure *Closure) {
443 uint32_t TotalSize = sizeof(ValueProfData);
444 const void *Record = Closure->Record;
445 uint32_t NumValueKinds = Closure->GetNumValueKinds(Record);
446 if (NumValueKinds == 0)
449 for (Kind = IPVK_First; Kind <= IPVK_Last; Kind++) {
450 uint32_t NumValueSites = Closure->GetNumValueSites(Record, Kind);
453 TotalSize += getValueProfRecordSize(NumValueSites,
454 Closure->GetNumValueData(Record, Kind));
460 * Extract value profile data of a function for the profile kind \c ValueKind
461 * from the \c Closure and serialize the data into \c This record instance.
463 void serializeValueProfRecordFrom(ValueProfRecord *This,
464 ValueProfRecordClosure *Closure,
465 uint32_t ValueKind, uint32_t NumValueSites) {
467 const void *Record = Closure->Record;
468 This->Kind = ValueKind;
469 This->NumValueSites = NumValueSites;
470 InstrProfValueData *DstVD = getValueProfRecordValueData(This);
472 for (S = 0; S < NumValueSites; S++) {
473 uint32_t ND = Closure->GetNumValueDataForSite(Record, ValueKind, S);
474 This->SiteCountArray[S] = ND;
475 Closure->GetValueForSite(Record, DstVD, ValueKind, S,
476 Closure->RemapValueData);
482 * Extract value profile data of a function from the \c Closure
483 * and serialize the data into \c DstData if it is not NULL or heap
484 * memory allocated by the \c Closure's allocator method.
486 ValueProfData *serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
487 ValueProfData *DstData) {
489 uint32_t TotalSize = getValueProfDataSize(Closure);
492 DstData ? DstData : Closure->AllocValueProfData(TotalSize);
494 VPD->TotalSize = TotalSize;
495 VPD->NumValueKinds = Closure->GetNumValueKinds(Closure->Record);
496 ValueProfRecord *VR = getFirstValueProfRecord(VPD);
497 for (Kind = IPVK_First; Kind <= IPVK_Last; Kind++) {
498 uint32_t NumValueSites = Closure->GetNumValueSites(Closure->Record, Kind);
501 serializeValueProfRecordFrom(VR, Closure, Kind, NumValueSites);
502 VR = getValueProfRecordNext(VR);
508 * The value profiler runtime library stores the value profile data
509 * for a given function in NumValueSites and Nodes. This is the
510 * method to initialize the RuntimeRecord with the runtime data to
511 * pre-compute the information needed to efficiently implement
512 * ValueProfRecordClosure's callback interfaces.
514 int initializeValueProfRuntimeRecord(ValueProfRuntimeRecord *RuntimeRecord,
515 uint16_t *NumValueSites,
516 ValueProfNode **Nodes) {
517 unsigned I, J, S = 0, NumValueKinds = 0;
518 RuntimeRecord->NumValueSites = NumValueSites;
519 RuntimeRecord->Nodes = Nodes;
520 for (I = 0; I <= IPVK_Last; I++) {
521 uint16_t N = NumValueSites[I];
523 RuntimeRecord->SiteCountArray[I] = 0;
527 RuntimeRecord->SiteCountArray[I] = (uint8_t *)calloc(N, 1);
528 RuntimeRecord->NodesKind[I] = &RuntimeRecord->Nodes[S];
529 if (!RuntimeRecord->NodesKind[I])
531 for (J = 0; J < N; J++) {
533 ValueProfNode *Site = RuntimeRecord->Nodes[S + J];
540 RuntimeRecord->SiteCountArray[I][J] = C;
544 RuntimeRecord->NumValueKinds = NumValueKinds;
548 void finalizeValueProfRuntimeRecord(ValueProfRuntimeRecord *RuntimeRecord) {
550 for (I = 0; I <= IPVK_Last; I++) {
551 if (RuntimeRecord->SiteCountArray[I])
552 free(RuntimeRecord->SiteCountArray[I]);
556 /* ValueProfRecordClosure Interface implementation for
557 * ValueProfDataRuntimeRecord. */
558 uint32_t getNumValueKindsRT(const void *R) {
559 return ((const ValueProfRuntimeRecord *)R)->NumValueKinds;
562 uint32_t getNumValueSitesRT(const void *R, uint32_t VK) {
563 return ((const ValueProfRuntimeRecord *)R)->NumValueSites[VK];
566 uint32_t getNumValueDataForSiteRT(const void *R, uint32_t VK, uint32_t S) {
567 const ValueProfRuntimeRecord *Record = (const ValueProfRuntimeRecord *)R;
568 return Record->SiteCountArray[VK][S];
571 uint32_t getNumValueDataRT(const void *R, uint32_t VK) {
573 const ValueProfRuntimeRecord *Record = (const ValueProfRuntimeRecord *)R;
574 if (Record->SiteCountArray[VK] == 0)
576 for (I = 0; I < Record->NumValueSites[VK]; I++)
577 S += Record->SiteCountArray[VK][I];
581 void getValueForSiteRT(const void *R, InstrProfValueData *Dst, uint32_t VK,
582 uint32_t S, uint64_t (*Mapper)(uint32_t, uint64_t)) {
584 const ValueProfRuntimeRecord *Record = (const ValueProfRuntimeRecord *)R;
585 N = getNumValueDataForSiteRT(R, VK, S);
586 ValueProfNode *VNode = Record->NodesKind[VK][S];
587 for (I = 0; I < N; I++) {
588 Dst[I] = VNode->VData;
593 ValueProfData *allocValueProfDataRT(size_t TotalSizeInBytes) {
594 return (ValueProfData *)calloc(TotalSizeInBytes, 1);
597 static ValueProfRecordClosure RTRecordClosure = {0,
601 getNumValueDataForSiteRT,
604 allocValueProfDataRT};
607 * Return the size of ValueProfData structure to store data
608 * recorded in the runtime record.
610 uint32_t getValueProfDataSizeRT(const ValueProfRuntimeRecord *Record) {
611 RTRecordClosure.Record = Record;
612 return getValueProfDataSize(&RTRecordClosure);
616 * Return a ValueProfData instance that stores the data collected
617 * from runtime. If \c DstData is provided by the caller, the value
618 * profile data will be store in *DstData and DstData is returned,
619 * otherwise the method will allocate space for the value data and
620 * return pointer to the newly allocated space.
623 serializeValueProfDataFromRT(const ValueProfRuntimeRecord *Record,
624 ValueProfData *DstData) {
625 RTRecordClosure.Record = Record;
626 return serializeValueProfDataFrom(&RTRecordClosure, DstData);
630 #undef INSTR_PROF_COMMON_API_IMPL
631 #endif /* INSTR_PROF_COMMON_API_IMPL */
633 /*============================================================================*/
636 #ifndef INSTR_PROF_DATA_DEFINED
638 #ifndef INSTR_PROF_DATA_INC_
639 #define INSTR_PROF_DATA_INC_
642 #define INSTR_PROF_SIMPLE_QUOTE(x) #x
643 #define INSTR_PROF_QUOTE(x) INSTR_PROF_SIMPLE_QUOTE(x)
644 #define INSTR_PROF_SIMPLE_CONCAT(x,y) x ## y
645 #define INSTR_PROF_CONCAT(x,y) INSTR_PROF_SIMPLE_CONCAT(x,y)
647 /* Magic number to detect file format and endianness.
648 * Use 255 at one end, since no UTF-8 file can use that character. Avoid 0,
649 * so that utilities, like strings, don't grab it as a string. 129 is also
650 * invalid UTF-8, and high enough to be interesting.
651 * Use "lprofr" in the centre to stand for "LLVM Profile Raw", or "lprofR"
652 * for 32-bit platforms.
654 #define INSTR_PROF_RAW_MAGIC_64 (uint64_t)255 << 56 | (uint64_t)'l' << 48 | \
655 (uint64_t)'p' << 40 | (uint64_t)'r' << 32 | (uint64_t)'o' << 24 | \
656 (uint64_t)'f' << 16 | (uint64_t)'r' << 8 | (uint64_t)129
657 #define INSTR_PROF_RAW_MAGIC_32 (uint64_t)255 << 56 | (uint64_t)'l' << 48 | \
658 (uint64_t)'p' << 40 | (uint64_t)'r' << 32 | (uint64_t)'o' << 24 | \
659 (uint64_t)'f' << 16 | (uint64_t)'R' << 8 | (uint64_t)129
661 /* Raw profile format version. */
662 #define INSTR_PROF_RAW_VERSION 2
664 /* Runtime section names and name strings. */
665 #define INSTR_PROF_DATA_SECT_NAME __llvm_prf_data
666 #define INSTR_PROF_NAME_SECT_NAME __llvm_prf_names
667 #define INSTR_PROF_CNTS_SECT_NAME __llvm_prf_cnts
669 #define INSTR_PROF_DATA_SECT_NAME_STR \
670 INSTR_PROF_QUOTE(INSTR_PROF_DATA_SECT_NAME)
671 #define INSTR_PROF_NAME_SECT_NAME_STR \
672 INSTR_PROF_QUOTE(INSTR_PROF_NAME_SECT_NAME)
673 #define INSTR_PROF_CNTS_SECT_NAME_STR \
674 INSTR_PROF_QUOTE(INSTR_PROF_CNTS_SECT_NAME)
676 /* Macros to define start/stop section symbol for a given
677 * section on Linux. For instance
678 * INSTR_PROF_SECT_START(INSTR_PROF_DATA_SECT_NAME) will
679 * expand to __start___llvm_prof_data
681 #define INSTR_PROF_SECT_START(Sect) \
682 INSTR_PROF_CONCAT(__start_,Sect)
683 #define INSTR_PROF_SECT_STOP(Sect) \
684 INSTR_PROF_CONCAT(__stop_,Sect)
686 /* Value Profiling API linkage name. */
687 #define INSTR_PROF_VALUE_PROF_FUNC __llvm_profile_instrument_target
688 #define INSTR_PROF_VALUE_PROF_FUNC_STR \
689 INSTR_PROF_QUOTE(INSTR_PROF_VALUE_PROF_FUNC)
691 /* InstrProfile per-function control data alignment. */
692 #define INSTR_PROF_DATA_ALIGNMENT 8
694 /* The data structure that represents a tracked value by the
697 typedef struct InstrProfValueData {
698 /* Profiled value. */
700 /* Number of times the value appears in the training run. */
702 } InstrProfValueData;
704 /* This is an internal data structure used by value profiler. It
705 * is defined here to allow serialization code sharing by LLVM
706 * to be used in unit test.
708 typedef struct ValueProfNode {
709 InstrProfValueData VData;
710 struct ValueProfNode *Next;
713 #endif /* INSTR_PROF_DATA_INC_ */
716 #undef INSTR_PROF_DATA_DEFINED