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(const uint64_t, Magic, __llvm_profile_get_magic())
98 INSTR_PROF_RAW_HEADER(const uint64_t, Version, __llvm_profile_get_version())
99 INSTR_PROF_RAW_HEADER(const uint64_t, DataSize, DataSize)
100 INSTR_PROF_RAW_HEADER(const uint64_t, CountersSize, CountersSize)
101 INSTR_PROF_RAW_HEADER(const uint64_t, NamesSize, NameSize)
102 INSTR_PROF_RAW_HEADER(const uint64_t, CountersDelta, (uintptr_t)CountersBegin)
103 INSTR_PROF_RAW_HEADER(const uint64_t, NamesDelta, (uintptr_t)NamesBegin)
104 INSTR_PROF_RAW_HEADER(const uint64_t, ValueKindLast, IPVK_Last)
105 INSTR_PROF_RAW_HEADER(const uint64_t, ValueDataSize, ValueDataSize)
106 INSTR_PROF_RAW_HEADER(const 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. */
172 /*============================================================================*/
175 #ifndef INSTR_PROF_DATA_DEFINED
177 #ifndef INSTR_PROF_DATA_INC_
178 #define INSTR_PROF_DATA_INC_
181 #define INSTR_PROF_SIMPLE_QUOTE(x) #x
182 #define INSTR_PROF_QUOTE(x) INSTR_PROF_SIMPLE_QUOTE(x)
183 #define INSTR_PROF_SIMPLE_CONCAT(x,y) x ## y
184 #define INSTR_PROF_CONCAT(x,y) INSTR_PROF_SIMPLE_CONCAT(x,y)
187 /* Magic number to detect file format and endianness.
188 * Use 255 at one end, since no UTF-8 file can use that character. Avoid 0,
189 * so that utilities, like strings, don't grab it as a string. 129 is also
190 * invalid UTF-8, and high enough to be interesting.
191 * Use "lprofr" in the centre to stand for "LLVM Profile Raw", or "lprofR"
192 * for 32-bit platforms.
193 * The magic and version need to be kept in sync with
194 * projects/compiler-rt/lib/profile/InstrProfiling.c
196 #define INSTR_PROF_RAW_MAGIC_64 uint64_t(255) << 56 | uint64_t('l') << 48 | \
197 uint64_t('p') << 40 | uint64_t('r') << 32 | uint64_t('o') << 24 | \
198 uint64_t('f') << 16 | uint64_t('r') << 8 | uint64_t(129)
199 #define INSTR_PROF_RAW_MAGIC_32 uint64_t(255) << 56 | uint64_t('l') << 48 | \
200 uint64_t('p') << 40 | uint64_t('r') << 32 | uint64_t('o') << 24 | \
201 uint64_t('f') << 16 | uint64_t('R') << 8 | uint64_t(129)
203 /* Raw profile format version. */
204 #define INSTR_PROF_RAW_VERSION 2
206 /* Runtime section names and name strings. */
207 #define INSTR_PROF_DATA_SECT_NAME __llvm_prf_data
208 #define INSTR_PROF_NAME_SECT_NAME __llvm_prf_names
209 #define INSTR_PROF_CNTS_SECT_NAME __llvm_prf_cnts
211 #define INSTR_PROF_DATA_SECT_NAME_STR \
212 INSTR_PROF_QUOTE(INSTR_PROF_DATA_SECT_NAME)
213 #define INSTR_PROF_NAME_SECT_NAME_STR \
214 INSTR_PROF_QUOTE(INSTR_PROF_NAME_SECT_NAME)
215 #define INSTR_PROF_CNTS_SECT_NAME_STR \
216 INSTR_PROF_QUOTE(INSTR_PROF_CNTS_SECT_NAME)
218 /* Macros to define start/stop section symbol for a given
219 * section on Linux. For instance
220 * INSTR_PROF_SECT_START(INSTR_PROF_DATA_SECT_NAME) will
221 * expand to __start___llvm_prof_data
223 #define INSTR_PROF_SECT_START(Sect) \
224 INSTR_PROF_CONCAT(__start_,Sect)
225 #define INSTR_PROF_SECT_STOP(Sect) \
226 INSTR_PROF_CONCAT(__stop_,Sect)
228 /* Value Profiling API linkage name. */
229 #define INSTR_PROF_VALUE_PROF_FUNC __llvm_profile_instrument_target
230 #define INSTR_PROF_VALUE_PROF_FUNC_STR \
231 INSTR_PROF_QUOTE(INSTR_PROF_VALUE_PROF_FUNC)
233 #endif /* INSTR_PROF_DATA_INC_ */
236 #undef INSTR_PROF_DATA_DEFINED