LLVM 20.0.0git
InstrProfData.inc
Go to the documentation of this file.
1/*===-- InstrProfData.inc - instr profiling runtime structures -*- C++ -*-=== *\
2|*
3|* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4|* See https://llvm.org/LICENSE.txt for license information.
5|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6|*
7\*===----------------------------------------------------------------------===*/
8/*
9 * This is the main file that defines all the data structure, signature,
10 * constant literals that are shared across profiling runtime library,
11 * compiler (instrumentation), and host tools (reader/writer). The entities
12 * defined in this file affect the profile runtime ABI, the raw profile format,
13 * or both.
14 *
15 * The file has two identical copies. The primary copy lives in LLVM and
16 * the other one sits in compiler-rt/lib/profile directory. To make changes
17 * in this file, first modify the primary copy and copy it over to compiler-rt.
18 * Testing of any change in this file can start only after the two copies are
19 * synced up.
20 *
21 * The first part of the file includes macros that defines types, names, and
22 * initializers for the member fields of the core data structures. The field
23 * declarations for one structure is enabled by defining the field activation
24 * macro associated with that structure. Only one field activation record
25 * can be defined at one time and the rest definitions will be filtered out by
26 * the preprocessor.
27 *
28 * Examples of how the template is used to instantiate structure definition:
29 * 1. To declare a structure:
30 *
31 * struct ProfData {
32 * #define INSTR_PROF_DATA(Type, LLVMType, Name, Initializer) \
33 * Type Name;
34 * #include "llvm/ProfileData/InstrProfData.inc"
35 * };
36 *
37 * 2. To construct LLVM type arrays for the struct type:
38 *
39 * Type *DataTypes[] = {
40 * #define INSTR_PROF_DATA(Type, LLVMType, Name, Initializer) \
41 * LLVMType,
42 * #include "llvm/ProfileData/InstrProfData.inc"
43 * };
44 *
45 * 4. To construct constant array for the initializers:
46 * #define INSTR_PROF_DATA(Type, LLVMType, Name, Initializer) \
47 * Initializer,
48 * Constant *ConstantVals[] = {
49 * #include "llvm/ProfileData/InstrProfData.inc"
50 * };
51 *
52 *
53 * The second part of the file includes definitions all other entities that
54 * are related to runtime ABI and format. When no field activation macro is
55 * defined, this file can be included to introduce the definitions.
56 *
57\*===----------------------------------------------------------------------===*/
58
59/* Functions marked with INSTR_PROF_VISIBILITY must have hidden visibility in
60 * the compiler runtime. */
61#ifndef INSTR_PROF_VISIBILITY
62#define INSTR_PROF_VISIBILITY
63#endif
64
65// clang-format off:consider re-enabling clang-format if auto-formatted C macros
66// are readable (e.g., after `issue #82426` is fixed)
67/* INSTR_PROF_DATA start. */
68/* Definition of member fields of the per-function control structure. */
69#ifndef INSTR_PROF_DATA
70#define INSTR_PROF_DATA(Type, LLVMType, Name, Initializer)
71#else
72#define INSTR_PROF_DATA_DEFINED
73#endif
75 ConstantInt::get(llvm::Type::getInt64Ty(Ctx), \
76 IndexedInstrProf::ComputeHash(getPGOFuncNameVarInitializer(Inc->getName()))))
77INSTR_PROF_DATA(const uint64_t, llvm::Type::getInt64Ty(Ctx), FuncHash, \
78 ConstantInt::get(llvm::Type::getInt64Ty(Ctx), \
79 Inc->getHash()->getZExtValue()))
80INSTR_PROF_DATA(const IntPtrT, IntPtrTy, CounterPtr, RelativeCounterPtr)
81INSTR_PROF_DATA(const IntPtrT, IntPtrTy, BitmapPtr, RelativeBitmapPtr)
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
84 * data.
85 */
86INSTR_PROF_DATA(const IntPtrT, llvm::PointerType::getUnqual(Ctx), FunctionPointer, \
87 FunctionAddr)
88INSTR_PROF_DATA(IntPtrT, llvm::PointerType::getUnqual(Ctx), Values, \
89 ValuesPtrExpr)
90INSTR_PROF_DATA(const uint32_t, llvm::Type::getInt32Ty(Ctx), NumCounters, \
91 ConstantInt::get(llvm::Type::getInt32Ty(Ctx), NumCounters))
92INSTR_PROF_DATA(const uint16_t, Int16ArrayTy, NumValueSites[IPVK_Last+1], \
93 ConstantArray::get(Int16ArrayTy, Int16ArrayVals)) \
94INSTR_PROF_DATA(const uint32_t, llvm::Type::getInt32Ty(Ctx), NumBitmapBytes, \
95 ConstantInt::get(llvm::Type::getInt32Ty(Ctx), NumBitmapBytes))
96#undef INSTR_PROF_DATA
97/* INSTR_PROF_DATA end. */
98
99/* For a virtual table object, record the name hash to associate profiled
100 * addresses with global variables, and record {starting address, size in bytes}
101 * to map the profiled virtual table (which usually have an offset from the
102 * starting address) back to a virtual table object. */
103#ifndef INSTR_PROF_VTABLE_DATA
104#define INSTR_PROF_VTABLE_DATA(Type, LLVMType, Name, Initializer)
105#else
106#define INSTR_PROF_VTABLE_DATA_DEFINED
107#endif
109 VTableNameHash, ConstantInt::get(llvm::Type::getInt64Ty(Ctx), \
110 IndexedInstrProf::ComputeHash(PGOVTableName)))
112 VTablePointer, VTableAddr)
114 ConstantInt::get(llvm::Type::getInt32Ty(Ctx), \
115 VTableSizeVal))
116#undef INSTR_PROF_VTABLE_DATA
117/* INSTR_PROF_VTABLE_DATA end. */
118
119/* This is an internal data structure used by value profiler. It
120 * is defined here to allow serialization code sharing by LLVM
121 * to be used in unit test.
122 *
123 * typedef struct ValueProfNode {
124 * // InstrProfValueData VData;
125 * uint64_t Value;
126 * uint64_t Count;
127 * struct ValueProfNode *Next;
128 * } ValueProfNode;
129 */
130/* INSTR_PROF_VALUE_NODE start. */
131#ifndef INSTR_PROF_VALUE_NODE
132#define INSTR_PROF_VALUE_NODE(Type, LLVMType, Name, Initializer)
133#else
134#define INSTR_PROF_DATA_DEFINED
135#endif
137 ConstantInt::get(llvm::Type::GetInt64Ty(Ctx), 0))
138INSTR_PROF_VALUE_NODE(uint64_t, llvm::Type::getInt64Ty(Ctx), Count, \
139 ConstantInt::get(llvm::Type::GetInt64Ty(Ctx), 0))
140INSTR_PROF_VALUE_NODE(PtrToNodeT, llvm::PointerType::getUnqual(Ctx), Next, \
141 ConstantInt::get(llvm::PointerType::getUnqual(Ctx), 0))
142#undef INSTR_PROF_VALUE_NODE
143/* INSTR_PROF_VALUE_NODE end. */
144
145/* INSTR_PROF_RAW_HEADER start */
146/* Definition of member fields of the raw profile header data structure. */
147/* Please update llvm/docs/InstrProfileFormat.rst as appropriate when updating
148 raw profile format. */
149#ifndef INSTR_PROF_RAW_HEADER
150#define INSTR_PROF_RAW_HEADER(Type, Name, Initializer)
151#else
152#define INSTR_PROF_DATA_DEFINED
153#endif
154INSTR_PROF_RAW_HEADER(uint64_t, Magic, __llvm_profile_get_magic())
155INSTR_PROF_RAW_HEADER(uint64_t, Version, __llvm_profile_get_version())
156INSTR_PROF_RAW_HEADER(uint64_t, BinaryIdsSize, __llvm_write_binary_ids(NULL))
157INSTR_PROF_RAW_HEADER(uint64_t, NumData, NumData)
158INSTR_PROF_RAW_HEADER(uint64_t, PaddingBytesBeforeCounters, PaddingBytesBeforeCounters)
159INSTR_PROF_RAW_HEADER(uint64_t, NumCounters, NumCounters)
160INSTR_PROF_RAW_HEADER(uint64_t, PaddingBytesAfterCounters, PaddingBytesAfterCounters)
161INSTR_PROF_RAW_HEADER(uint64_t, NumBitmapBytes, NumBitmapBytes)
162INSTR_PROF_RAW_HEADER(uint64_t, PaddingBytesAfterBitmapBytes, PaddingBytesAfterBitmapBytes)
163INSTR_PROF_RAW_HEADER(uint64_t, NamesSize, NamesSize)
164INSTR_PROF_RAW_HEADER(uint64_t, CountersDelta,
165 (uintptr_t)CountersBegin - (uintptr_t)DataBegin)
167 (uintptr_t)BitmapBegin - (uintptr_t)DataBegin)
168INSTR_PROF_RAW_HEADER(uint64_t, NamesDelta, (uintptr_t)NamesBegin)
169INSTR_PROF_RAW_HEADER(uint64_t, NumVTables, NumVTables)
170INSTR_PROF_RAW_HEADER(uint64_t, VNamesSize, VNamesSize)
171INSTR_PROF_RAW_HEADER(uint64_t, ValueKindLast, IPVK_Last)
172#undef INSTR_PROF_RAW_HEADER
173/* INSTR_PROF_RAW_HEADER end */
174
175/* VALUE_PROF_FUNC_PARAM start */
176/* Definition of parameter types of the runtime API used to do value profiling
177 * for a given value site.
178 */
179#ifndef VALUE_PROF_FUNC_PARAM
180#define VALUE_PROF_FUNC_PARAM(ArgType, ArgName, ArgLLVMType)
181#define INSTR_PROF_COMMA
182#else
183#define INSTR_PROF_DATA_DEFINED
184#define INSTR_PROF_COMMA ,
185#endif
186VALUE_PROF_FUNC_PARAM(uint64_t, TargetValue, Type::getInt64Ty(Ctx)) \
187 INSTR_PROF_COMMA
188VALUE_PROF_FUNC_PARAM(void *, Data, PointerType::getUnqual(Ctx)) INSTR_PROF_COMMA
189VALUE_PROF_FUNC_PARAM(uint32_t, CounterIndex, Type::getInt32Ty(Ctx))
190#undef VALUE_PROF_FUNC_PARAM
191#undef INSTR_PROF_COMMA
192/* VALUE_PROF_FUNC_PARAM end */
193
194/* VALUE_PROF_KIND start */
195#ifndef VALUE_PROF_KIND
196#define VALUE_PROF_KIND(Enumerator, Value, Descr)
197#else
198#define INSTR_PROF_DATA_DEFINED
199#endif
200/* For indirect function call value profiling, the addresses of the target
201 * functions are profiled by the instrumented code. The target addresses are
202 * written in the raw profile data and converted to target function name's MD5
203 * hash by the profile reader during deserialization. Typically, this happens
204 * when the raw profile data is read during profile merging.
205 *
206 * For this remapping the ProfData is used. ProfData contains both the function
207 * name hash and the function address.
208 */
209VALUE_PROF_KIND(IPVK_IndirectCallTarget, 0, "indirect call target")
210/* For memory intrinsic functions size profiling. */
211VALUE_PROF_KIND(IPVK_MemOPSize, 1, "memory intrinsic functions size")
212/* For virtual table address profiling, the address point of the virtual table
213 * (i.e., the address contained in objects pointing to a virtual table) are
214 * profiled. Note this may not be the address of the per C++ class virtual table
215 * object (e.g., there might be an offset).
216 *
217 * The profiled addresses are stored in raw profile, together with the following
218 * two types of information.
219 * 1. The (starting and ending) addresses of per C++ class virtual table objects.
220 * 2. The (compressed) virtual table object names.
221 * RawInstrProfReader converts profiled virtual table addresses to virtual table
222 * objects' MD5 hash.
223 */
224VALUE_PROF_KIND(IPVK_VTableTarget, 2, "The profiled address point of the vtable")
225/* These two kinds must be the last to be
226 * declared. This is to make sure the string
227 * array created with the template can be
228 * indexed with the kind value.
229 */
230VALUE_PROF_KIND(IPVK_First, IPVK_IndirectCallTarget, "first")
231VALUE_PROF_KIND(IPVK_Last, IPVK_VTableTarget, "last")
232
233#undef VALUE_PROF_KIND
234/* VALUE_PROF_KIND end */
235
236#undef COVMAP_V2_OR_V3
237#ifdef COVMAP_V2
238#define COVMAP_V2_OR_V3
239#endif
240#ifdef COVMAP_V3
241#define COVMAP_V2_OR_V3
242#endif
243
244/* COVMAP_FUNC_RECORD start */
245/* Definition of member fields of the function record structure in coverage
246 * map.
247 */
248#ifndef COVMAP_FUNC_RECORD
249#define COVMAP_FUNC_RECORD(Type, LLVMType, Name, Initializer)
250#else
251#define INSTR_PROF_DATA_DEFINED
252#endif
253#ifdef COVMAP_V1
255 NamePtr, llvm::ConstantExpr::getBitCast(NamePtr, \
258 llvm::ConstantInt::get(llvm::Type::getInt32Ty(Ctx), \
259 NameValue.size()))
260#endif
261#ifdef COVMAP_V2_OR_V3
262COVMAP_FUNC_RECORD(const int64_t, llvm::Type::getInt64Ty(Ctx), NameRef, \
263 llvm::ConstantInt::get( \
264 llvm::Type::getInt64Ty(Ctx), NameHash))
265#endif
267 llvm::ConstantInt::get( \
268 llvm::Type::getInt32Ty(Ctx), CoverageMapping.size()))
269COVMAP_FUNC_RECORD(const uint64_t, llvm::Type::getInt64Ty(Ctx), FuncHash, \
270 llvm::ConstantInt::get( \
271 llvm::Type::getInt64Ty(Ctx), FuncHash))
272#ifdef COVMAP_V3
273COVMAP_FUNC_RECORD(const uint64_t, llvm::Type::getInt64Ty(Ctx), FilenamesRef, \
274 llvm::ConstantInt::get( \
275 llvm::Type::getInt64Ty(Ctx), FilenamesRef))
276COVMAP_FUNC_RECORD(const char, \
278 CoverageMapping.size()), \
279 CoverageMapping,
281 CoverageMapping, CoverageMapping.size(), \
283#endif
284#undef COVMAP_FUNC_RECORD
285/* COVMAP_FUNC_RECORD end. */
286
287/* COVMAP_HEADER start */
288/* Definition of member fields of coverage map header.
289 */
290#ifndef COVMAP_HEADER
291#define COVMAP_HEADER(Type, LLVMType, Name, Initializer)
292#else
293#define INSTR_PROF_DATA_DEFINED
294#endif
295COVMAP_HEADER(uint32_t, Int32Ty, NRecords, \
296 llvm::ConstantInt::get(Int32Ty, NRecords))
297COVMAP_HEADER(uint32_t, Int32Ty, FilenamesSize, \
298 llvm::ConstantInt::get(Int32Ty, FilenamesSize))
299COVMAP_HEADER(uint32_t, Int32Ty, CoverageSize, \
300 llvm::ConstantInt::get(Int32Ty, CoverageMappingSize))
301COVMAP_HEADER(uint32_t, Int32Ty, Version, \
302 llvm::ConstantInt::get(Int32Ty, CovMapVersion::CurrentVersion))
303#undef COVMAP_HEADER
304/* COVMAP_HEADER end. */
305
306/* COVINIT_FUNC start */
307#ifndef COVINIT_FUNC
308#define COVINIT_FUNC(Type, LLVMType, Name, Initializer)
309#else
310#define INSTR_PROF_DATA_DEFINED
311#endif
312COVINIT_FUNC(IntPtrT, llvm::PointerType::getUnqual(Ctx), WriteoutFunction, \
313 WriteoutF)
315 ResetF)
316#undef COVINIT_FUNC
317/* COVINIT_FUNC end */
318
319#ifdef INSTR_PROF_SECT_ENTRY
320#define INSTR_PROF_DATA_DEFINED
321INSTR_PROF_SECT_ENTRY(IPSK_data, \
322 INSTR_PROF_QUOTE(INSTR_PROF_DATA_COMMON), \
323 INSTR_PROF_DATA_COFF, "__DATA,")
324INSTR_PROF_SECT_ENTRY(IPSK_cnts, \
325 INSTR_PROF_QUOTE(INSTR_PROF_CNTS_COMMON), \
326 INSTR_PROF_CNTS_COFF, "__DATA,")
327INSTR_PROF_SECT_ENTRY(IPSK_bitmap, \
328 INSTR_PROF_QUOTE(INSTR_PROF_BITS_COMMON), \
329 INSTR_PROF_BITS_COFF, "__DATA,")
330INSTR_PROF_SECT_ENTRY(IPSK_name, \
331 INSTR_PROF_QUOTE(INSTR_PROF_NAME_COMMON), \
332 INSTR_PROF_NAME_COFF, "__DATA,")
333INSTR_PROF_SECT_ENTRY(IPSK_vname, \
334 INSTR_PROF_QUOTE(INSTR_PROF_VNAME_COMMON), \
335 INSTR_PROF_VNAME_COFF, "__DATA,")
336INSTR_PROF_SECT_ENTRY(IPSK_vals, \
337 INSTR_PROF_QUOTE(INSTR_PROF_VALS_COMMON), \
338 INSTR_PROF_VALS_COFF, "__DATA,")
339INSTR_PROF_SECT_ENTRY(IPSK_vnodes, \
340 INSTR_PROF_QUOTE(INSTR_PROF_VNODES_COMMON), \
341 INSTR_PROF_VNODES_COFF, "__DATA,")
342INSTR_PROF_SECT_ENTRY(IPSK_vtab, \
343 INSTR_PROF_QUOTE(INSTR_PROF_VTAB_COMMON), \
344 INSTR_PROF_VTAB_COFF, "__DATA,")
345INSTR_PROF_SECT_ENTRY(IPSK_covmap, \
346 INSTR_PROF_QUOTE(INSTR_PROF_COVMAP_COMMON), \
347 INSTR_PROF_COVMAP_COFF, "__LLVM_COV,")
348INSTR_PROF_SECT_ENTRY(IPSK_covfun, \
349 INSTR_PROF_QUOTE(INSTR_PROF_COVFUN_COMMON), \
350 INSTR_PROF_COVFUN_COFF, "__LLVM_COV,")
351INSTR_PROF_SECT_ENTRY(IPSK_orderfile, \
352 INSTR_PROF_QUOTE(INSTR_PROF_ORDERFILE_COMMON), \
353 INSTR_PROF_QUOTE(INSTR_PROF_ORDERFILE_COFF), "__DATA,")
354INSTR_PROF_SECT_ENTRY(IPSK_covdata, \
355 INSTR_PROF_QUOTE(INSTR_PROF_COVDATA_COMMON), \
356 INSTR_PROF_COVDATA_COFF, "__LLVM_COV,")
357INSTR_PROF_SECT_ENTRY(IPSK_covname, \
358 INSTR_PROF_QUOTE(INSTR_PROF_COVNAME_COMMON), \
359 INSTR_PROF_COVNAME_COFF, "__LLVM_COV,")
360INSTR_PROF_SECT_ENTRY(IPSK_covinit, \
361 INSTR_PROF_QUOTE(INSTR_PROF_COVINIT_COMMON), \
362 INSTR_PROF_COVINIT_COFF, "__LLVM_COV,")
363
364#undef INSTR_PROF_SECT_ENTRY
365#endif
366
367
368#ifdef INSTR_PROF_VALUE_PROF_DATA
369#define INSTR_PROF_DATA_DEFINED
370
371#define INSTR_PROF_MAX_NUM_VAL_PER_SITE 255
372/*!
373 * This is the header of the data structure that defines the on-disk
374 * layout of the value profile data of a particular kind for one function.
375 */
376typedef struct ValueProfRecord {
377 /* The kind of the value profile record. */
379 /*
380 * The number of value profile sites. It is guaranteed to be non-zero;
381 * otherwise the record for this kind won't be emitted.
382 */
383 uint32_t NumValueSites;
384 /*
385 * The first element of the array that stores the number of profiled
386 * values for each value site. The size of the array is NumValueSites.
387 * Since NumValueSites is greater than zero, there is at least one
388 * element in the array.
389 */
390 uint8_t SiteCountArray[1];
391
392 /*
393 * The fake declaration is for documentation purpose only.
394 * Align the start of next field to be on 8 byte boundaries.
395 uint8_t Padding[X];
396 */
397
398 /* The array of value profile data. The size of the array is the sum
399 * of all elements in SiteCountArray[].
400 InstrProfValueData ValueData[];
401 */
402
403#ifdef __cplusplus
404 /*!
405 * Return the number of value sites.
406 */
407 uint32_t getNumValueSites() const { return NumValueSites; }
408 /*!
409 * Read data from this record and save it to Record.
410 */
411 void deserializeTo(InstrProfRecord &Record,
412 InstrProfSymtab *SymTab);
413 /*
414 * In-place byte swap:
415 * Do byte swap for this instance. \c Old is the original order before
416 * the swap, and \c New is the New byte order.
417 */
419#endif
420} ValueProfRecord;
421
422/*!
423 * Per-function header/control data structure for value profiling
424 * data in indexed format.
425 */
426typedef struct ValueProfData {
427 /*
428 * Total size in bytes including this field. It must be a multiple
429 * of sizeof(uint64_t).
430 */
431 uint32_t TotalSize;
432 /*
433 *The number of value profile kinds that has value profile data.
434 * In this implementation, a value profile kind is considered to
435 * have profile data if the number of value profile sites for the
436 * kind is not zero. More aggressively, the implementation can
437 * choose to check the actual data value: if none of the value sites
438 * has any profiled values, the kind can be skipped.
439 */
440 uint32_t NumValueKinds;
441
442 /*
443 * Following are a sequence of variable length records. The prefix/header
444 * of each record is defined by ValueProfRecord type. The number of
445 * records is NumValueKinds.
446 * ValueProfRecord Record_1;
447 * ValueProfRecord Record_N;
448 */
449
450#if __cplusplus
451 /*!
452 * Return the total size in bytes of the on-disk value profile data
453 * given the data stored in Record.
454 */
455 static uint32_t getSize(const InstrProfRecord &Record);
456 /*!
457 * Return a pointer to \c ValueProfData instance ready to be streamed.
458 */
459 static std::unique_ptr<ValueProfData>
460 serializeFrom(const InstrProfRecord &Record);
461 /*!
462 * Check the integrity of the record.
463 */
464 Error checkIntegrity();
465 /*!
466 * Return a pointer to \c ValueProfileData instance ready to be read.
467 * All data in the instance are properly byte swapped. The input
468 * data is assumed to be in little endian order.
469 */
470 static Expected<std::unique_ptr<ValueProfData>>
471 getValueProfData(const unsigned char *SrcBuffer,
472 const unsigned char *const SrcBufferEnd,
473 llvm::endianness SrcDataEndianness);
474 /*!
475 * Swap byte order from \c Endianness order to host byte order.
476 */
477 void swapBytesToHost(llvm::endianness Endianness);
478 /*!
479 * Swap byte order from host byte order to \c Endianness order.
480 */
481 void swapBytesFromHost(llvm::endianness Endianness);
482 /*!
483 * Return the total size of \c ValueProfileData.
484 */
485 uint32_t getSize() const { return TotalSize; }
486 /*!
487 * Read data from this data and save it to \c Record.
488 */
489 void deserializeTo(InstrProfRecord &Record,
490 InstrProfSymtab *SymTab);
491 void operator delete(void *ptr) { ::operator delete(ptr); }
492#endif
493} ValueProfData;
494
495/*
496 * The closure is designed to abstact away two types of value profile data:
497 * - InstrProfRecord which is the primary data structure used to
498 * represent profile data in host tools (reader, writer, and profile-use)
499 * - value profile runtime data structure suitable to be used by C
500 * runtime library.
501 *
502 * Both sources of data need to serialize to disk/memory-buffer in common
503 * format: ValueProfData. The abstraction allows compiler-rt's raw profiler
504 * writer to share the same format and code with indexed profile writer.
505 *
506 * For documentation of the member methods below, refer to corresponding methods
507 * in class InstrProfRecord.
508 */
509typedef struct ValueProfRecordClosure {
510 const void *Record;
511 uint32_t (*GetNumValueKinds)(const void *Record);
512 uint32_t (*GetNumValueSites)(const void *Record, uint32_t VKind);
513 uint32_t (*GetNumValueData)(const void *Record, uint32_t VKind);
514 uint32_t (*GetNumValueDataForSite)(const void *R, uint32_t VK, uint32_t S);
515
516 /*
517 * After extracting the value profile data from the value profile record,
518 * this method is used to map the in-memory value to on-disk value. If
519 * the method is null, value will be written out untranslated.
520 */
521 uint64_t (*RemapValueData)(uint32_t, uint64_t Value);
522 void (*GetValueForSite)(const void *R, InstrProfValueData *Dst, uint32_t K,
523 uint32_t S);
524 ValueProfData *(*AllocValueProfData)(size_t TotalSizeInBytes);
525} ValueProfRecordClosure;
526
527INSTR_PROF_VISIBILITY ValueProfRecord *
528getFirstValueProfRecord(ValueProfData *VPD);
529INSTR_PROF_VISIBILITY ValueProfRecord *
530getValueProfRecordNext(ValueProfRecord *VPR);
531INSTR_PROF_VISIBILITY InstrProfValueData *
532getValueProfRecordValueData(ValueProfRecord *VPR);
533INSTR_PROF_VISIBILITY uint32_t
534getValueProfRecordHeaderSize(uint32_t NumValueSites);
535
536#undef INSTR_PROF_VALUE_PROF_DATA
537#endif /* INSTR_PROF_VALUE_PROF_DATA */
538
539
540#ifdef INSTR_PROF_COMMON_API_IMPL
541#define INSTR_PROF_DATA_DEFINED
542#ifdef __cplusplus
543#define INSTR_PROF_INLINE inline
544#define INSTR_PROF_NULLPTR nullptr
545#else
546#define INSTR_PROF_INLINE
547#define INSTR_PROF_NULLPTR NULL
548#endif
549
550#ifndef offsetof
551#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
552#endif
553
554// clang-format on
555
556/*!
557 * Return the \c ValueProfRecord header size including the
558 * padding bytes.
559 */
560INSTR_PROF_VISIBILITY INSTR_PROF_INLINE uint32_t
561getValueProfRecordHeaderSize(uint32_t NumValueSites) {
562 uint32_t Size = offsetof(ValueProfRecord, SiteCountArray) +
563 sizeof(uint8_t) * NumValueSites;
564 /* Round the size to multiple of 8 bytes. */
565 Size = (Size + 7) & ~7;
566 return Size;
567}
568
569/*!
570 * Return the total size of the value profile record including the
571 * header and the value data.
572 */
573INSTR_PROF_VISIBILITY INSTR_PROF_INLINE uint32_t
574getValueProfRecordSize(uint32_t NumValueSites, uint32_t NumValueData) {
575 return getValueProfRecordHeaderSize(NumValueSites) +
576 sizeof(InstrProfValueData) * NumValueData;
577}
578
579/*!
580 * Return the pointer to the start of value data array.
581 */
582INSTR_PROF_VISIBILITY INSTR_PROF_INLINE InstrProfValueData *
583getValueProfRecordValueData(ValueProfRecord *This) {
584 return (InstrProfValueData *)((char *)This + getValueProfRecordHeaderSize(
585 This->NumValueSites));
586}
587
588/*!
589 * Return the total number of value data for \c This record.
590 */
591INSTR_PROF_VISIBILITY INSTR_PROF_INLINE uint32_t
592getValueProfRecordNumValueData(ValueProfRecord *This) {
593 uint32_t NumValueData = 0;
594 uint32_t I;
595 for (I = 0; I < This->NumValueSites; I++)
596 NumValueData += This->SiteCountArray[I];
597 return NumValueData;
598}
599
600/*!
601 * Use this method to advance to the next \c This \c ValueProfRecord.
602 */
603INSTR_PROF_VISIBILITY INSTR_PROF_INLINE ValueProfRecord *
604getValueProfRecordNext(ValueProfRecord *This) {
605 uint32_t NumValueData = getValueProfRecordNumValueData(This);
606 return (ValueProfRecord *)((char *)This +
607 getValueProfRecordSize(This->NumValueSites,
608 NumValueData));
609}
610
611/*!
612 * Return the first \c ValueProfRecord instance.
613 */
614INSTR_PROF_VISIBILITY INSTR_PROF_INLINE ValueProfRecord *
615getFirstValueProfRecord(ValueProfData *This) {
616 return (ValueProfRecord *)((char *)This + sizeof(ValueProfData));
617}
618
619/* Closure based interfaces. */
620
621/*!
622 * Return the total size in bytes of the on-disk value profile data
623 * given the data stored in Record.
624 */
625INSTR_PROF_VISIBILITY uint32_t
626getValueProfDataSize(ValueProfRecordClosure *Closure) {
628 uint32_t TotalSize = sizeof(ValueProfData);
629 const void *Record = Closure->Record;
630
631 for (Kind = IPVK_First; Kind <= IPVK_Last; Kind++) {
632 uint32_t NumValueSites = Closure->GetNumValueSites(Record, Kind);
633 if (!NumValueSites)
634 continue;
635 TotalSize += getValueProfRecordSize(NumValueSites,
636 Closure->GetNumValueData(Record, Kind));
637 }
638 return TotalSize;
639}
640
641/*!
642 * Extract value profile data of a function for the profile kind \c ValueKind
643 * from the \c Closure and serialize the data into \c This record instance.
644 */
645INSTR_PROF_VISIBILITY void
646serializeValueProfRecordFrom(ValueProfRecord *This,
647 ValueProfRecordClosure *Closure,
648 uint32_t ValueKind, uint32_t NumValueSites) {
649 uint32_t S;
650 const void *Record = Closure->Record;
651 This->Kind = ValueKind;
652 This->NumValueSites = NumValueSites;
653 InstrProfValueData *DstVD = getValueProfRecordValueData(This);
654
655 for (S = 0; S < NumValueSites; S++) {
656 uint32_t ND = Closure->GetNumValueDataForSite(Record, ValueKind, S);
657 This->SiteCountArray[S] = ND;
658 Closure->GetValueForSite(Record, DstVD, ValueKind, S);
659 DstVD += ND;
660 }
661}
662
663/*!
664 * Extract value profile data of a function from the \c Closure
665 * and serialize the data into \c DstData if it is not NULL or heap
666 * memory allocated by the \c Closure's allocator method. If \c
667 * DstData is not null, the caller is expected to set the TotalSize
668 * in DstData.
669 */
670INSTR_PROF_VISIBILITY ValueProfData *
671serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
672 ValueProfData *DstData) {
674 uint32_t TotalSize =
675 DstData ? DstData->TotalSize : getValueProfDataSize(Closure);
676
677 ValueProfData *VPD =
678 DstData ? DstData : Closure->AllocValueProfData(TotalSize);
679
680 VPD->TotalSize = TotalSize;
681 VPD->NumValueKinds = Closure->GetNumValueKinds(Closure->Record);
682 ValueProfRecord *VR = getFirstValueProfRecord(VPD);
683 for (Kind = IPVK_First; Kind <= IPVK_Last; Kind++) {
684 uint32_t NumValueSites = Closure->GetNumValueSites(Closure->Record, Kind);
685 if (!NumValueSites)
686 continue;
687 serializeValueProfRecordFrom(VR, Closure, Kind, NumValueSites);
688 VR = getValueProfRecordNext(VR);
689 }
690 return VPD;
691}
692
693#undef INSTR_PROF_COMMON_API_IMPL
694#endif /* INSTR_PROF_COMMON_API_IMPL */
695
696/*============================================================================*/
697
698// clang-format off:consider re-enabling clang-format if auto-formatted C macros
699// are readable (e.g., after `issue #82426` is fixed)
700#ifndef INSTR_PROF_DATA_DEFINED
701
702#ifndef INSTR_PROF_DATA_INC
703#define INSTR_PROF_DATA_INC
704
705/* Helper macros. */
706#define INSTR_PROF_SIMPLE_QUOTE(x) #x
707#define INSTR_PROF_QUOTE(x) INSTR_PROF_SIMPLE_QUOTE(x)
708#define INSTR_PROF_SIMPLE_CONCAT(x,y) x ## y
709#define INSTR_PROF_CONCAT(x,y) INSTR_PROF_SIMPLE_CONCAT(x,y)
710
711/* Magic number to detect file format and endianness.
712 * Use 255 at one end, since no UTF-8 file can use that character. Avoid 0,
713 * so that utilities, like strings, don't grab it as a string. 129 is also
714 * invalid UTF-8, and high enough to be interesting.
715 * Use "lprofr" in the centre to stand for "LLVM Profile Raw", or "lprofR"
716 * for 32-bit platforms.
717 */
718#define INSTR_PROF_RAW_MAGIC_64 (uint64_t)255 << 56 | (uint64_t)'l' << 48 | \
719 (uint64_t)'p' << 40 | (uint64_t)'r' << 32 | (uint64_t)'o' << 24 | \
720 (uint64_t)'f' << 16 | (uint64_t)'r' << 8 | (uint64_t)129
721#define INSTR_PROF_RAW_MAGIC_32 (uint64_t)255 << 56 | (uint64_t)'l' << 48 | \
722 (uint64_t)'p' << 40 | (uint64_t)'r' << 32 | (uint64_t)'o' << 24 | \
723 (uint64_t)'f' << 16 | (uint64_t)'R' << 8 | (uint64_t)129
724
725/* Raw profile format version (start from 1). */
726#define INSTR_PROF_RAW_VERSION 10
727/* Indexed profile format version (start from 1). */
728#define INSTR_PROF_INDEX_VERSION 12
729/* Coverage mapping format version (start from 0). */
730#define INSTR_PROF_COVMAP_VERSION 6
731
732/* Profile version is always of type uint64_t. Reserve the upper 32 bits in the
733 * version for other variants of profile. We set the 8th most significant bit
734 * (i.e. bit 56) to 1 to indicate if this is an IR-level instrumentation
735 * generated profile, and 0 if this is a Clang FE generated profile.
736 * 1 in bit 57 indicates there are context-sensitive records in the profile.
737 * The 54th bit indicates whether to always instrument loop entry blocks.
738 * The 58th bit indicates whether to always instrument function entry blocks.
739 * The 59th bit indicates whether to use debug info to correlate profiles.
740 * The 60th bit indicates single byte coverage instrumentation.
741 * The 61st bit indicates function entry instrumentation only.
742 * The 62nd bit indicates whether memory profile information is present.
743 * The 63rd bit indicates if this is a temporal profile.
744 */
745#define VARIANT_MASKS_ALL 0xffffffff00000000ULL
746#define GET_VERSION(V) ((V) & ~VARIANT_MASKS_ALL)
747#define VARIANT_MASK_INSTR_LOOP_ENTRIES (0x1ULL << 55)
748#define VARIANT_MASK_IR_PROF (0x1ULL << 56)
749#define VARIANT_MASK_CSIR_PROF (0x1ULL << 57)
750#define VARIANT_MASK_INSTR_ENTRY (0x1ULL << 58)
751#define VARIANT_MASK_DBG_CORRELATE (0x1ULL << 59)
752#define VARIANT_MASK_BYTE_COVERAGE (0x1ULL << 60)
753#define VARIANT_MASK_FUNCTION_ENTRY_ONLY (0x1ULL << 61)
754#define VARIANT_MASK_MEMPROF (0x1ULL << 62)
755#define VARIANT_MASK_TEMPORAL_PROF (0x1ULL << 63)
756#define INSTR_PROF_RAW_VERSION_VAR __llvm_profile_raw_version
757#define INSTR_PROF_PROFILE_RUNTIME_VAR __llvm_profile_runtime
758#define INSTR_PROF_PROFILE_COUNTER_BIAS_VAR __llvm_profile_counter_bias
759#define INSTR_PROF_PROFILE_BITMAP_BIAS_VAR __llvm_profile_bitmap_bias
760#define INSTR_PROF_PROFILE_SET_TIMESTAMP __llvm_profile_set_timestamp
761#define INSTR_PROF_PROFILE_SAMPLING_VAR __llvm_profile_sampling
762
763/* The variable that holds the name of the profile data
764 * specified via command line. */
765#define INSTR_PROF_PROFILE_NAME_VAR __llvm_profile_filename
766
767/* section name strings common to all targets other
768 than WIN32 */
769#define INSTR_PROF_DATA_COMMON __llvm_prf_data
770#define INSTR_PROF_NAME_COMMON __llvm_prf_names
771#define INSTR_PROF_VNAME_COMMON __llvm_prf_vns
772#define INSTR_PROF_CNTS_COMMON __llvm_prf_cnts
773#define INSTR_PROF_BITS_COMMON __llvm_prf_bits
774#define INSTR_PROF_VALS_COMMON __llvm_prf_vals
775#define INSTR_PROF_VNODES_COMMON __llvm_prf_vnds
776#define INSTR_PROF_VTAB_COMMON __llvm_prf_vtab
777#define INSTR_PROF_COVMAP_COMMON __llvm_covmap
778#define INSTR_PROF_COVFUN_COMMON __llvm_covfun
779#define INSTR_PROF_COVDATA_COMMON __llvm_covdata
780#define INSTR_PROF_COVNAME_COMMON __llvm_covnames
781#define INSTR_PROF_ORDERFILE_COMMON __llvm_orderfile
782#define INSTR_PROF_COVINIT_COMMON __llvm_covinit
783
784/* Windows section names. Because these section names contain dollar characters,
785 * they must be quoted.
786 */
787#define INSTR_PROF_DATA_COFF ".lprfd$M"
788#define INSTR_PROF_NAME_COFF ".lprfn$M"
789#define INSTR_PROF_VNAME_COFF ".lprfvn$M"
790#define INSTR_PROF_CNTS_COFF ".lprfc$M"
791#define INSTR_PROF_BITS_COFF ".lprfb$M"
792#define INSTR_PROF_VALS_COFF ".lprfv$M"
793#define INSTR_PROF_VNODES_COFF ".lprfnd$M"
794#define INSTR_PROF_VTAB_COFF ".lprfvt$M"
795#define INSTR_PROF_COVMAP_COFF ".lcovmap$M"
796#define INSTR_PROF_COVFUN_COFF ".lcovfun$M"
797/* Since cov data and cov names sections are not allocated, we don't need to
798 * access them at runtime.
799 */
800#define INSTR_PROF_COVDATA_COFF ".lcovd"
801#define INSTR_PROF_COVNAME_COFF ".lcovn"
802#define INSTR_PROF_ORDERFILE_COFF ".lorderfile$M"
803
804// FIXME: Placeholder for Windows. Windows currently does not initialize
805// the GCOV functions in the runtime.
806#define INSTR_PROF_COVINIT_COFF ".lcovd$M"
807
808#ifdef _WIN32
809/* Runtime section names and name strings. */
810#define INSTR_PROF_DATA_SECT_NAME INSTR_PROF_DATA_COFF
811#define INSTR_PROF_NAME_SECT_NAME INSTR_PROF_NAME_COFF
812#define INSTR_PROF_CNTS_SECT_NAME INSTR_PROF_CNTS_COFF
813#define INSTR_PROF_BITS_SECT_NAME INSTR_PROF_BITS_COFF
814#define INSTR_PROF_VTAB_SECT_NAME INSTR_PROF_VTAB_COFF
815#define INSTR_PROF_VNAME_SECT_NAME INSTR_PROF_VNAME_COFF
816/* Array of pointers. Each pointer points to a list
817 * of value nodes associated with one value site.
818 */
819#define INSTR_PROF_VALS_SECT_NAME INSTR_PROF_VALS_COFF
820/* Value profile nodes section. */
821#define INSTR_PROF_VNODES_SECT_NAME INSTR_PROF_VNODES_COFF
822#define INSTR_PROF_COVMAP_SECT_NAME INSTR_PROF_COVMAP_COFF
823#define INSTR_PROF_COVFUN_SECT_NAME INSTR_PROF_COVFUN_COFF
824#define INSTR_PROF_COVDATA_SECT_NAME INSTR_PROF_COVDATA_COFF
825#define INSTR_PROF_COVNAME_SECT_NAME INSTR_PROF_COVNAME_COFF
826#define INSTR_PROF_ORDERFILE_SECT_NAME INSTR_PROF_ORDERFILE_COFF
827#define INSTR_PROF_COVINIT_SECT_NAME INSTR_PROF_COVINIT_COFF
828#else
829/* Runtime section names and name strings. */
830#define INSTR_PROF_DATA_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_DATA_COMMON)
831#define INSTR_PROF_NAME_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_NAME_COMMON)
832#define INSTR_PROF_CNTS_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_CNTS_COMMON)
833#define INSTR_PROF_BITS_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_BITS_COMMON)
834#define INSTR_PROF_VTAB_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_VTAB_COMMON)
835#define INSTR_PROF_VNAME_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_VNAME_COMMON)
836/* Array of pointers. Each pointer points to a list
837 * of value nodes associated with one value site.
838 */
839#define INSTR_PROF_VALS_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_VALS_COMMON)
840/* Value profile nodes section. */
841#define INSTR_PROF_VNODES_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_VNODES_COMMON)
842#define INSTR_PROF_COVMAP_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_COVMAP_COMMON)
843#define INSTR_PROF_COVFUN_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_COVFUN_COMMON)
844#define INSTR_PROF_COVDATA_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_COVDATA_COMMON)
845#define INSTR_PROF_COVNAME_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_COVNAME_COMMON)
846/* Order file instrumentation. */
847#define INSTR_PROF_ORDERFILE_SECT_NAME \
848 INSTR_PROF_QUOTE(INSTR_PROF_ORDERFILE_COMMON)
849#define INSTR_PROF_COVINIT_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_COVINIT_COMMON)
850#endif
851
852#define INSTR_PROF_ORDERFILE_BUFFER_NAME _llvm_order_file_buffer
853#define INSTR_PROF_ORDERFILE_BUFFER_NAME_STR \
854 INSTR_PROF_QUOTE(INSTR_PROF_ORDERFILE_BUFFER_NAME)
855#define INSTR_PROF_ORDERFILE_BUFFER_IDX_NAME _llvm_order_file_buffer_idx
856#define INSTR_PROF_ORDERFILE_BUFFER_IDX_NAME_STR \
857 INSTR_PROF_QUOTE(INSTR_PROF_ORDERFILE_BUFFER_IDX_NAME)
858
859/* Macros to define start/stop section symbol for a given
860 * section on Linux. For instance
861 * INSTR_PROF_SECT_START(INSTR_PROF_DATA_SECT_NAME) will
862 * expand to __start___llvm_prof_data
863 */
864#define INSTR_PROF_SECT_START(Sect) \
865 INSTR_PROF_CONCAT(__start_,Sect)
866#define INSTR_PROF_SECT_STOP(Sect) \
867 INSTR_PROF_CONCAT(__stop_,Sect)
868
869/* Value Profiling API linkage name. */
870#define INSTR_PROF_VALUE_PROF_FUNC __llvm_profile_instrument_target
871#define INSTR_PROF_VALUE_PROF_FUNC_STR \
872 INSTR_PROF_QUOTE(INSTR_PROF_VALUE_PROF_FUNC)
873#define INSTR_PROF_VALUE_PROF_MEMOP_FUNC __llvm_profile_instrument_memop
874#define INSTR_PROF_VALUE_PROF_MEMOP_FUNC_STR \
875 INSTR_PROF_QUOTE(INSTR_PROF_VALUE_PROF_MEMOP_FUNC)
876
877/* InstrProfile per-function control data alignment. */
878#define INSTR_PROF_DATA_ALIGNMENT 8
879
880/* The data structure that represents a tracked value by the
881 * value profiler.
882 */
883typedef struct InstrProfValueData {
884 /* Profiled value. */
886 /* Number of times the value appears in the training run. */
887 uint64_t Count;
888} InstrProfValueData;
889
890#endif /* INSTR_PROF_DATA_INC */
891
892#ifndef INSTR_ORDER_FILE_INC
893/* The maximal # of functions: 128*1024 (the buffer size will be 128*4 KB). */
894#define INSTR_ORDER_FILE_BUFFER_SIZE 131072
895#define INSTR_ORDER_FILE_BUFFER_BITS 17
896#define INSTR_ORDER_FILE_BUFFER_MASK 0x1ffff
897#endif /* INSTR_ORDER_FILE_INC */
898#else
899#undef INSTR_PROF_DATA_DEFINED
900#endif
901
902#undef COVMAP_V2_OR_V3
903
904#ifdef INSTR_PROF_VALUE_PROF_MEMOP_API
905
906#ifdef __cplusplus
907#define INSTR_PROF_INLINE inline
908#else
909#define INSTR_PROF_INLINE
910#endif
911
912/* The value range buckets (22 buckets) for the memop size value profiling looks
913 * like:
914 *
915 * [0, 0]
916 * [1, 1]
917 * [2, 2]
918 * [3, 3]
919 * [4, 4]
920 * [5, 5]
921 * [6, 6]
922 * [7, 7]
923 * [8, 8]
924 * [9, 15]
925 * [16, 16]
926 * [17, 31]
927 * [32, 32]
928 * [33, 63]
929 * [64, 64]
930 * [65, 127]
931 * [128, 128]
932 * [129, 255]
933 * [256, 256]
934 * [257, 511]
935 * [512, 512]
936 * [513, UINT64_MAX]
937 *
938 * Each range has a 'representative value' which is the lower end value of the
939 * range and used to store in the runtime profile data records and the VP
940 * metadata. For example, it's 2 for [2, 2] and 64 for [65, 127].
941 */
942#define INSTR_PROF_NUM_BUCKETS 22
943
944/*
945 * Clz and Popcount. This code was copied from
946 * compiler-rt/lib/fuzzer/{FuzzerBuiltins.h,FuzzerBuiltinsMsvc.h} and
947 * llvm/include/llvm/Support/MathExtras.h.
948 */
949#if defined(_MSC_VER) && !defined(__clang__)
950
951#include <intrin.h>
952INSTR_PROF_VISIBILITY INSTR_PROF_INLINE
953int InstProfClzll(unsigned long long X) {
954 unsigned long LeadZeroIdx = 0;
955#if !defined(_M_ARM64) && !defined(_M_X64)
956 // Scan the high 32 bits.
957 if (_BitScanReverse(&LeadZeroIdx, (unsigned long)(X >> 32)))
958 return (int)(63 - (LeadZeroIdx + 32)); // Create a bit offset
959 // from the MSB.
960 // Scan the low 32 bits.
961 if (_BitScanReverse(&LeadZeroIdx, (unsigned long)(X)))
962 return (int)(63 - LeadZeroIdx);
963#else
964 if (_BitScanReverse64(&LeadZeroIdx, X)) return 63 - LeadZeroIdx;
965#endif
966 return 64;
967}
968INSTR_PROF_VISIBILITY INSTR_PROF_INLINE
969int InstProfPopcountll(unsigned long long X) {
970 // This code originates from https://reviews.llvm.org/rG30626254510f.
971 unsigned long long v = X;
972 v = v - ((v >> 1) & 0x5555555555555555ULL);
973 v = (v & 0x3333333333333333ULL) + ((v >> 2) & 0x3333333333333333ULL);
974 v = (v + (v >> 4)) & 0x0F0F0F0F0F0F0F0FULL;
975 return (int)((unsigned long long)(v * 0x0101010101010101ULL) >> 56);
976}
977
978#else
979
980INSTR_PROF_VISIBILITY INSTR_PROF_INLINE
981int InstProfClzll(unsigned long long X) { return __builtin_clzll(X); }
982INSTR_PROF_VISIBILITY INSTR_PROF_INLINE
983int InstProfPopcountll(unsigned long long X) { return __builtin_popcountll(X); }
984
985#endif /* defined(_MSC_VER) && !defined(__clang__) */
986
987// clang-format on
988
989/* Map an (observed) memop size value to the representative value of its range.
990 * For example, 5 -> 5, 22 -> 17, 99 -> 65, 256 -> 256, 1001 -> 513. */
991INSTR_PROF_VISIBILITY INSTR_PROF_INLINE uint64_t
992InstrProfGetRangeRepValue(uint64_t Value) {
993 if (Value <= 8)
994 // The first ranges are individually tracked. Use the value as is.
995 return Value;
996 else if (Value >= 513)
997 // The last range is mapped to its lowest value.
998 return 513;
999 else if (InstProfPopcountll(Value) == 1)
1000 // If it's a power of two, use it as is.
1001 return Value;
1002 else
1003 // Otherwise, take to the previous power of two + 1.
1004 return (UINT64_C(1) << (64 - InstProfClzll(Value) - 1)) + 1;
1005}
1006
1007/* Return true if the range that an (observed) memop size value belongs to has
1008 * only a single value in the range. For example, 0 -> true, 8 -> true, 10 ->
1009 * false, 64 -> true, 100 -> false, 513 -> false. */
1010INSTR_PROF_VISIBILITY INSTR_PROF_INLINE unsigned
1011InstrProfIsSingleValRange(uint64_t Value) {
1012 if (Value <= 8)
1013 // The first ranges are individually tracked.
1014 return 1;
1015 else if (InstProfPopcountll(Value) == 1)
1016 // If it's a power of two, there's only one value.
1017 return 1;
1018 else
1019 // Otherwise, there's more than one value in the range.
1020 return 0;
1021}
1022
1023#endif /* INSTR_PROF_VALUE_PROF_MEMOP_API */
aarch64 promote const
Lower uses of LDS variables from non kernel functions
#define offsetof(TYPE, MEMBER)
RelocType Type
Definition: COFFYAML.cpp:410
#define COVMAP_HEADER(Type, LLVMType, Name, Init)
#define COVMAP_FUNC_RECORD(Type, LLVMType, Name, Init)
uint64_t Size
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
#define COVINIT_FUNC(Type, LLVMType, Name, Init)
#define INSTR_PROF_RAW_HEADER(Type, Name, Init)
Definition: InstrProf.h:1297
#define INSTR_PROF_SECT_ENTRY(Kind, SectNameCommon, SectNameCoff, Prefix)
Definition: InstrProf.h:61
#define INSTR_PROF_VTABLE_DATA(Type, LLVMType, Name, Init)
Definition: InstrProf.h:1288
#define INSTR_PROF_DATA(Type, LLVMType, Name, Init)
Definition: InstrProf.h:1283
#define VALUE_PROF_KIND(Enumerator, Value, Descr)
Definition: InstrProf.h:276
#define INSTR_PROF_VALUE_NODE(Type, LLVMType, Name, Init)
#define VALUE_PROF_FUNC_PARAM(ParamType, ParamName, ParamLLVMType)
#define I(x, y, z)
Definition: MD5.cpp:58
static unsigned getSize(unsigned Kind)
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
static Constant * getRaw(StringRef Data, uint64_t NumElements, Type *ElementTy)
getRaw() constructor - Return a constant with array type with an element count and element type match...
Definition: Constants.h:728
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:2321
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
Definition: DerivedTypes.h:686
static IntegerType * getInt8Ty(LLVMContext &C)
static IntegerType * getInt32Ty(LLVMContext &C)
static IntegerType * getInt64Ty(LLVMContext &C)
ValueKind
Value kinds.
std::enable_if_t< std::is_arithmetic< T >::value, void > swapBytes(T &value)
Definition: DXContainer.h:32
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
StringRef getPGOFuncNameVarInitializer(GlobalVariable *NameVar)
Return the initializer in string of the PGO name var NameVar.
Definition: InstrProf.cpp:719
endianness
Definition: bit.h:70