[PGO] move raw magic and version def to InstrProfData.inc
[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. Changes can only
18  * be made directly made in the master copy. Whenever the master copy changes,
19  * the compiler-rt copy needs to be kept in sync with the master.
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 /* INSTR_PROF_DATA start. */
60 /* Definition of member fields of the per-function control structure. */
61 #ifndef INSTR_PROF_DATA
62 #define INSTR_PROF_DATA(Type, LLVMType, Name, Initializer)
63 #else
64 #define INSTR_PROF_DATA_DEFINED
65 #endif
66
67 INSTR_PROF_DATA(const uint32_t, llvm::Type::getInt32Ty(Ctx), NameSize, \
68                 ConstantInt::get(llvm::Type::getInt32Ty(Ctx), \
69                 NamePtr->getType()->getPointerElementType()->getArrayNumElements()))
70 INSTR_PROF_DATA(const uint32_t, llvm::Type::getInt32Ty(Ctx), NumCounters, \
71                 ConstantInt::get(llvm::Type::getInt32Ty(Ctx), NumCounters))
72 INSTR_PROF_DATA(const uint64_t, llvm::Type::getInt64Ty(Ctx), FuncHash, \
73                 ConstantInt::get(llvm::Type::getInt64Ty(Ctx), \
74                 Inc->getHash()->getZExtValue()))
75 INSTR_PROF_DATA(const IntPtrT, llvm::Type::getInt8PtrTy(Ctx), NamePtr, \
76                 ConstantExpr::getBitCast(NamePtr, llvm::Type::getInt8PtrTy(Ctx)))
77 INSTR_PROF_DATA(const IntPtrT, llvm::Type::getInt64PtrTy(Ctx), CounterPtr, \
78                 ConstantExpr::getBitCast(CounterPtr, \
79                 llvm::Type::getInt64PtrTy(Ctx)))
80 INSTR_PROF_DATA(const IntPtrT, llvm::Type::getInt8PtrTy(Ctx), FunctionPointer, \
81                 FunctionAddr)
82 INSTR_PROF_DATA(IntPtrT, llvm::Type::getInt8PtrTy(Ctx), Values, \
83                 ConstantPointerNull::get(Int8PtrTy))
84 INSTR_PROF_DATA(const uint16_t, Int16ArrayTy, NumValueSites[IPVK_Last+1], \
85                 ConstantArray::get(Int16ArrayTy, Int16ArrayVals))
86 #undef INSTR_PROF_DATA
87 /* INSTR_PROF_DATA end. */
88
89 /* INSTR_PROF_RAW_HEADER  start */
90 /* Definition of member fields of the raw profile header data structure. */
91 #ifndef INSTR_PROF_RAW_HEADER
92 #define INSTR_PROF_RAW_HEADER(Type, Name, Initializer)
93 #else
94 #define INSTR_PROF_DATA_DEFINED
95 #endif
96 INSTR_PROF_RAW_HEADER(const uint64_t, Magic, __llvm_profile_get_magic())
97 INSTR_PROF_RAW_HEADER(const uint64_t, Version, __llvm_profile_get_version())
98 INSTR_PROF_RAW_HEADER(const uint64_t, DataSize, DataSize)
99 INSTR_PROF_RAW_HEADER(const uint64_t, CountersSize, CountersSize)
100 INSTR_PROF_RAW_HEADER(const uint64_t, NamesSize,  NameSize)
101 INSTR_PROF_RAW_HEADER(const uint64_t, CountersDelta, (uintptr_t)CountersBegin)
102 INSTR_PROF_RAW_HEADER(const uint64_t, NamesDelta, (uintptr_t)NamesBegin)
103 INSTR_PROF_RAW_HEADER(const uint64_t, ValueKindLast, IPVK_Last)
104 INSTR_PROF_RAW_HEADER(const uint64_t, ValueDataSize, ValueDataSize)
105 INSTR_PROF_RAW_HEADER(const uint64_t, ValueDataDelta, (uintptr_t)ValueDataBegin)
106 #undef INSTR_PROF_RAW_HEADER
107 /* INSTR_PROF_RAW_HEADER  end */
108
109 /* VALUE_PROF_FUNC_PARAM start */
110 /* Definition of parameter types of the runtime API used to do value profiling
111  * for a given value site.
112  */
113 #ifndef VALUE_PROF_FUNC_PARAM
114 #define VALUE_PROF_FUNC_PARAM(ArgType, ArgName, ArgLLVMType)
115 #define INSTR_PROF_COMMA
116 #else
117 #define INSTR_PROF_DATA_DEFINED
118 #define INSTR_PROF_COMMA ,
119 #endif
120 VALUE_PROF_FUNC_PARAM(uint64_t, TargetValue, Type::getInt64Ty(Ctx)) \
121                       INSTR_PROF_COMMA
122 VALUE_PROF_FUNC_PARAM(void *, Data, Type::getInt8PtrTy(Ctx)) INSTR_PROF_COMMA
123 VALUE_PROF_FUNC_PARAM(uint32_t, CounterIndex, Type::getInt32Ty(Ctx))
124 #undef VALUE_PROF_FUNC_PARAM
125 #undef INSTR_PROF_COMMA
126 /* VALUE_PROF_FUNC_PARAM end */
127
128 /* VALUE_PROF_KIND start */
129 #ifndef VALUE_PROF_KIND
130 #define VALUE_PROF_KIND(Enumerator, Value)
131 #else
132 #define INSTR_PROF_DATA_DEFINED
133 #endif
134 VALUE_PROF_KIND(IPVK_IndirectCallTarget, 0)
135 /* These two kinds must be the last to be
136  * declared. This is to make sure the string
137  * array created with the template can be
138  * indexed with the kind value.
139  */
140 VALUE_PROF_KIND(IPVK_First, IPVK_IndirectCallTarget)
141 VALUE_PROF_KIND(IPVK_Last, IPVK_IndirectCallTarget)
142
143 #undef VALUE_PROF_KIND
144 /* VALUE_PROF_KIND end */
145
146 /* COVMAP_FUNC_RECORD start */
147 /* Definition of member fields of the function record structure in coverage
148  * map.
149  */
150 #ifndef COVMAP_FUNC_RECORD
151 #define COVMAP_FUNC_RECORD(Type, LLVMType, Name, Initializer)
152 #else
153 #define INSTR_PROF_DATA_DEFINED
154 #endif
155 COVMAP_FUNC_RECORD(const IntPtrT, llvm::Type::getInt8PtrTy(Ctx), \
156                    NamePtr, llvm::ConstantExpr::getBitCast(NamePtr, \
157                    llvm::Type::getInt8PtrTy(Ctx))) 
158 COVMAP_FUNC_RECORD(const uint32_t, llvm::Type::getInt32Ty(Ctx), NameSize, \
159                    llvm::ConstantInt::get(llvm::Type::getInt32Ty(Ctx),\
160                    NameValue.size()))
161 COVMAP_FUNC_RECORD(const uint32_t, llvm::Type::getInt32Ty(Ctx), DataSize, \
162                    llvm::ConstantInt::get(llvm::Type::getInt32Ty(Ctx),\
163                    CoverageMapping.size()))
164 COVMAP_FUNC_RECORD(const uint64_t, llvm::Type::getInt64Ty(Ctx), FuncHash, \
165                    llvm::ConstantInt::get(llvm::Type::getInt64Ty(Ctx), FuncHash))
166 #undef COVMAP_FUNC_RECORD
167 /* COVMAP_FUNC_RECORD end.  */
168
169
170
171 /*============================================================================*/
172
173
174 #ifndef INSTR_PROF_DATA_DEFINED
175
176 #ifndef INSTR_PROF_DATA_INC_
177 #define INSTR_PROF_DATA_INC_
178
179 /* Magic number to detect file format and endianness.
180  * Use 255 at one end, since no UTF-8 file can use that character.  Avoid 0,             
181  * so that utilities, like strings, don't grab it as a string.  129 is also              
182  * invalid UTF-8, and high enough to be interesting.
183  * Use "lprofr" in the centre to stand for "LLVM Profile Raw", or "lprofR"               
184  * for 32-bit platforms.
185  * The magic and version need to be kept in sync with                                    
186  * projects/compiler-rt/lib/profile/InstrProfiling.c                                     
187  */
188 #define INSTR_PROF_RAW_MAGIC_64 uint64_t(255) << 56 | uint64_t('l') << 48 | \
189        uint64_t('p') << 40 | uint64_t('r') << 32 | uint64_t('o') << 24 |  \
190         uint64_t('f') << 16 | uint64_t('r') << 8 | uint64_t(129)
191 #define INSTR_PROF_RAW_MAGIC_32 uint64_t(255) << 56 | uint64_t('l') << 48 | \
192        uint64_t('p') << 40 | uint64_t('r') << 32 | uint64_t('o') << 24 |  \
193         uint64_t('f') << 16 | uint64_t('R') << 8 | uint64_t(129)
194
195 /* Raw profile format version. */
196 #define INSTR_PROF_RAW_VERSION 2
197
198 #endif /* INSTR_PROF_DATA_INC_ */
199
200 #else
201 #undef INSTR_PROF_DATA_DEFINED
202 #endif
203