Fix a typo introduced in previous patches
[oota-llvm.git] / include / llvm / ProfileData / InstrProfData.inc
1 /*===-- InstrProfData.inc - instr profiling runtime structures -----------=== *\
2 |*
3 |*                     The LLVM Compiler Infrastructure
4 |*
5 |* This file is distributed under the University of Illinois Open Source
6 |* License. See LICENSE.TXT for details.
7 |*
8 \*===----------------------------------------------------------------------===*/
9 /*
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,
14  * or both.
15  *
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
20  * synced up.
21  *
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
27  * the preprocessor.
28  *
29  * Examples of how the template is used to instantiate structure definition:
30  * 1. To declare a structure:
31  * 
32  * struct ProfData {
33  * #define INSTR_PROF_DATA(Type, LLVMType, Name, Initializer) \
34  *    Type Name;
35  * #include "llvm/ProfileData/InstrProfData.inc"
36  * };
37  *
38  * 2. To construct LLVM type arrays for the struct type:
39  *
40  * Type *DataTypes[] = {
41  * #define INSTR_PROF_DATA(Type, LLVMType, Name, Initializer) \
42  *   LLVMType,
43  * #include "llvm/ProfileData/InstrProfData.inc"
44  * };
45  *
46  * 4. To construct constant array for the initializers:
47  * #define INSTR_PROF_DATA(Type, LLVMType, Name, Initializer) \
48  *   Initializer,
49  * Constant *ConstantVals[] = {
50  * #include "llvm/ProfileData/InstrProfData.inc"
51  * };
52  *
53  *
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.
57  *
58 \*===----------------------------------------------------------------------===*/
59
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)
64 #else
65 #define INSTR_PROF_DATA_DEFINED
66 #endif
67
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, \
82                 FunctionAddr)
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. */
89
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)
94 #else
95 #define INSTR_PROF_DATA_DEFINED
96 #endif
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 */
109
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.
113  */
114 #ifndef VALUE_PROF_FUNC_PARAM
115 #define VALUE_PROF_FUNC_PARAM(ArgType, ArgName, ArgLLVMType)
116 #define INSTR_PROF_COMMA
117 #else
118 #define INSTR_PROF_DATA_DEFINED
119 #define INSTR_PROF_COMMA ,
120 #endif
121 VALUE_PROF_FUNC_PARAM(uint64_t, TargetValue, Type::getInt64Ty(Ctx)) \
122                       INSTR_PROF_COMMA
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 */
128
129 /* VALUE_PROF_KIND start */
130 #ifndef VALUE_PROF_KIND
131 #define VALUE_PROF_KIND(Enumerator, Value)
132 #else
133 #define INSTR_PROF_DATA_DEFINED
134 #endif
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.
140  */
141 VALUE_PROF_KIND(IPVK_First, IPVK_IndirectCallTarget)
142 VALUE_PROF_KIND(IPVK_Last, IPVK_IndirectCallTarget)
143
144 #undef VALUE_PROF_KIND
145 /* VALUE_PROF_KIND end */
146
147 /* COVMAP_FUNC_RECORD start */
148 /* Definition of member fields of the function record structure in coverage
149  * map.
150  */
151 #ifndef COVMAP_FUNC_RECORD
152 #define COVMAP_FUNC_RECORD(Type, LLVMType, Name, Initializer)
153 #else
154 #define INSTR_PROF_DATA_DEFINED
155 #endif
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),\
161                    NameValue.size()))
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.  */
169
170
171
172 /*============================================================================*/
173
174
175 #ifndef INSTR_PROF_DATA_DEFINED
176
177 #ifndef INSTR_PROF_DATA_INC_
178 #define INSTR_PROF_DATA_INC_
179
180 /* Helper macros.  */
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)
185
186 /* Magic number to detect file format and endianness.
187  * Use 255 at one end, since no UTF-8 file can use that character.  Avoid 0,
188  * so that utilities, like strings, don't grab it as a string.  129 is also
189  * invalid UTF-8, and high enough to be interesting.
190  * Use "lprofr" in the centre to stand for "LLVM Profile Raw", or "lprofR"
191  * for 32-bit platforms.
192  */
193 #define INSTR_PROF_RAW_MAGIC_64 (uint64_t)255 << 56 | (uint64_t)'l' << 48 | \
194        (uint64_t)'p' << 40 | (uint64_t)'r' << 32 | (uint64_t)'o' << 24 |  \
195         (uint64_t)'f' << 16 | (uint64_t)'r' << 8 | (uint64_t)129
196 #define INSTR_PROF_RAW_MAGIC_32 (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
200 /* Raw profile format version. */
201 #define INSTR_PROF_RAW_VERSION 2
202
203 /* Runtime section names and name strings.  */
204 #define INSTR_PROF_DATA_SECT_NAME __llvm_prf_data
205 #define INSTR_PROF_NAME_SECT_NAME __llvm_prf_names
206 #define INSTR_PROF_CNTS_SECT_NAME __llvm_prf_cnts
207
208 #define INSTR_PROF_DATA_SECT_NAME_STR \
209         INSTR_PROF_QUOTE(INSTR_PROF_DATA_SECT_NAME)
210 #define INSTR_PROF_NAME_SECT_NAME_STR \
211         INSTR_PROF_QUOTE(INSTR_PROF_NAME_SECT_NAME)
212 #define INSTR_PROF_CNTS_SECT_NAME_STR \
213         INSTR_PROF_QUOTE(INSTR_PROF_CNTS_SECT_NAME)
214
215 /* Macros to define start/stop section symbol for a given
216  * section on Linux. For instance
217  * INSTR_PROF_SECT_START(INSTR_PROF_DATA_SECT_NAME) will
218  * expand to __start___llvm_prof_data
219  */
220 #define INSTR_PROF_SECT_START(Sect) \
221         INSTR_PROF_CONCAT(__start_,Sect)
222 #define INSTR_PROF_SECT_STOP(Sect) \
223         INSTR_PROF_CONCAT(__stop_,Sect)
224
225 /* Value Profiling API linkage name.  */
226 #define INSTR_PROF_VALUE_PROF_FUNC __llvm_profile_instrument_target
227 #define INSTR_PROF_VALUE_PROF_FUNC_STR \
228         INSTR_PROF_QUOTE(INSTR_PROF_VALUE_PROF_FUNC)
229
230 /* InstrProfile per-function control data alignment.  */
231 #define INSTR_PROF_DATA_ALIGNMENT 8
232
233 /* The data structure that represents a tracked value by the
234  * value profiler.
235  */
236 typedef struct InstrProfValueData {
237   /* Profiled value. */
238   uint64_t Value;
239   /* Number of times the value appears in the training run. */
240   uint64_t Count;
241 } InstrProfValueData;
242
243 /* This is an internal data structure used by value profiler. It
244  * is defined here to allow serialization code sharing by LLVM
245  * to be used in unit test.
246  */
247 typedef struct ValueProfNode {
248   InstrProfValueData VData;
249   struct ValueProfNode *Next;
250 } ValueProfNode;
251
252 #endif /* INSTR_PROF_DATA_INC_ */
253
254 #else
255 #undef INSTR_PROF_DATA_DEFINED
256 #endif
257