[PGO] Move Raw Header def into template file InstrProfData.inc
[oota-llvm.git] / include / llvm / ProfileData / InstrProf.h
1 //=-- InstrProf.h - Instrumented profiling format support ---------*- C++ -*-=//
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 // Instrumentation-based profiling data is generated by instrumented
11 // binaries through library functions in compiler-rt, and read by the clang
12 // frontend to feed PGO.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_PROFILEDATA_INSTRPROF_H_
17 #define LLVM_PROFILEDATA_INSTRPROF_H_
18
19 #include "llvm/ADT/StringRef.h"
20 #include "llvm/ADT/StringSet.h"
21 #include "llvm/IR/GlobalValue.h"
22 #include "llvm/Support/Endian.h"
23 #include "llvm/Support/ErrorHandling.h"
24 #include "llvm/Support/ErrorOr.h"
25 #include "llvm/Support/MD5.h"
26 #include <cstdint>
27 #include <list>
28 #include <system_error>
29 #include <vector>
30
31 namespace llvm {
32
33 class Function;
34 class GlobalVariable;
35 class Module;
36
37 /// Return the name of data section containing profile counter variables.
38 inline StringRef getInstrProfCountersSectionName(bool AddSegment) {
39   return AddSegment ? "__DATA,__llvm_prf_cnts" : "__llvm_prf_cnts";
40 }
41
42 /// Return the name of data section containing names of instrumented
43 /// functions.
44 inline StringRef getInstrProfNameSectionName(bool AddSegment) {
45   return AddSegment ? "__DATA,__llvm_prf_names" : "__llvm_prf_names";
46 }
47
48 /// Return the name of the data section containing per-function control
49 /// data.
50 inline StringRef getInstrProfDataSectionName(bool AddSegment) {
51   return AddSegment ? "__DATA,__llvm_prf_data" : "__llvm_prf_data";
52 }
53
54 /// Return the name of the section containing function coverage mapping
55 /// data.
56 inline StringRef getInstrProfCoverageSectionName(bool AddSegment) {
57   return AddSegment ? "__DATA,__llvm_covmap" : "__llvm_covmap";
58 }
59
60 /// Return the name prefix of variables containing instrumented function names.
61 inline StringRef getInstrProfNameVarPrefix() { return "__llvm_profile_name_"; }
62
63 /// Return the name prefix of variables containing per-function control data.
64 inline StringRef getInstrProfDataVarPrefix() { return "__llvm_profile_data_"; }
65
66 /// Return the name prefix of profile counter variables.
67 inline StringRef getInstrProfCountersVarPrefix() {
68   return "__llvm_profile_counters_";
69 }
70
71 /// Return the name prefix of the COMDAT group for instrumentation variables
72 /// associated with a COMDAT function.
73 inline StringRef getInstrProfComdatPrefix() { return "__llvm_profile_vars_"; }
74
75 /// Return the name of a covarage mapping variable (internal linkage) 
76 /// for each instrumented source module. Such variables are allocated
77 /// in the __llvm_covmap section.
78 inline StringRef getCoverageMappingVarName() {
79   return "__llvm_coverage_mapping";
80 }
81
82 /// Return the name of function that registers all the per-function control
83 /// data at program startup time by calling __llvm_register_function. This
84 /// function has internal linkage and is called by  __llvm_profile_init
85 /// runtime method. This function is not generated for these platforms:
86 /// Darwin, Linux, and FreeBSD.
87 inline StringRef getInstrProfRegFuncsName() {
88   return "__llvm_profile_register_functions";
89 }
90
91 /// Return the name of the runtime interface that registers per-function control
92 /// data for one instrumented function.
93 inline StringRef getInstrProfRegFuncName() {
94   return "__llvm_profile_register_function";
95 }
96
97 /// Return the name of the runtime initialization method that is generated by
98 /// the compiler. The function calls __llvm_profile_register_functions and
99 /// __llvm_profile_override_default_filename functions if needed. This function
100 /// has internal linkage and invoked at startup time via init_array.
101 inline StringRef getInstrProfInitFuncName() { return "__llvm_profile_init"; }
102
103 /// Return the name of the hook variable defined in profile runtime library.
104 /// A reference to the variable causes the linker to link in the runtime
105 /// initialization module (which defines the hook variable).
106 inline StringRef getInstrProfRuntimeHookVarName() {
107   return "__llvm_profile_runtime";
108 }
109
110 /// Return the name of the compiler generated function that references the
111 /// runtime hook variable. The function is a weak global.
112 inline StringRef getInstrProfRuntimeHookVarUseFuncName() {
113   return "__llvm_profile_runtime_user";
114 }
115
116 /// Return the name of the profile runtime interface that overrides the default
117 /// profile data file name.
118 inline StringRef getInstrProfFileOverriderFuncName() {
119   return "__llvm_profile_override_default_filename";
120 }
121
122 /// Return the modified name for function \c F suitable to be
123 /// used the key for profile lookup.
124 std::string getPGOFuncName(const Function &F);
125
126 /// Return the modified name for a function suitable to be
127 /// used the key for profile lookup. The function's original
128 /// name is \c RawFuncName and has linkage of type \c Linkage.
129 /// The function is defined in module \c FileName.
130 std::string getPGOFuncName(StringRef RawFuncName,
131                            GlobalValue::LinkageTypes Linkage,
132                            StringRef FileName);
133
134 /// Create and return the global variable for function name used in PGO
135 /// instrumentation. \c FuncName is the name of the function returned
136 /// by \c getPGOFuncName call.
137 GlobalVariable *createPGOFuncNameVar(Function &F, StringRef FuncName);
138
139 /// Create and return the global variable for function name used in PGO
140 /// instrumentation.  /// \c FuncName is the name of the function
141 /// returned by \c getPGOFuncName call, \c M is the owning module,
142 /// and \c Linkage is the linkage of the instrumented function.
143 GlobalVariable *createPGOFuncNameVar(Module &M,
144                                      GlobalValue::LinkageTypes Linkage,
145                                      StringRef FuncName);
146
147 const std::error_category &instrprof_category();
148
149 enum class instrprof_error {
150   success = 0,
151   eof,
152   unrecognized_format,
153   bad_magic,
154   bad_header,
155   unsupported_version,
156   unsupported_hash_type,
157   too_large,
158   truncated,
159   malformed,
160   unknown_function,
161   hash_mismatch,
162   count_mismatch,
163   counter_overflow,
164   value_site_count_mismatch
165 };
166
167 inline std::error_code make_error_code(instrprof_error E) {
168   return std::error_code(static_cast<int>(E), instrprof_category());
169 }
170
171 enum InstrProfValueKind : uint32_t {
172   IPVK_IndirectCallTarget = 0,
173
174   IPVK_First = IPVK_IndirectCallTarget,
175   IPVK_Last = IPVK_IndirectCallTarget
176 };
177
178 struct InstrProfStringTable {
179   // Set of string values in profiling data.
180   StringSet<> StringValueSet;
181   InstrProfStringTable() { StringValueSet.clear(); }
182   // Get a pointer to internal storage of a string in set
183   const char *getStringData(StringRef Str) {
184     auto Result = StringValueSet.find(Str);
185     return (Result == StringValueSet.end()) ? nullptr : Result->first().data();
186   }
187   // Insert a string to StringTable
188   const char *insertString(StringRef Str) {
189     auto Result = StringValueSet.insert(Str);
190     return Result.first->first().data();
191   }
192 };
193
194 struct InstrProfValueData {
195   // Profiled value.
196   uint64_t Value;
197   // Number of times the value appears in the training run.
198   uint64_t Count;
199 };
200
201 struct InstrProfValueSiteRecord {
202   /// Value profiling data pairs at a given value site.
203   std::list<InstrProfValueData> ValueData;
204
205   InstrProfValueSiteRecord() { ValueData.clear(); }
206   template <class InputIterator>
207   InstrProfValueSiteRecord(InputIterator F, InputIterator L)
208       : ValueData(F, L) {}
209
210   /// Sort ValueData ascending by Value
211   void sortByTargetValues() {
212     ValueData.sort(
213         [](const InstrProfValueData &left, const InstrProfValueData &right) {
214           return left.Value < right.Value;
215         });
216   }
217
218   /// Merge data from another InstrProfValueSiteRecord
219   void mergeValueData(InstrProfValueSiteRecord &Input) {
220     this->sortByTargetValues();
221     Input.sortByTargetValues();
222     auto I = ValueData.begin();
223     auto IE = ValueData.end();
224     for (auto J = Input.ValueData.begin(), JE = Input.ValueData.end(); J != JE;
225          ++J) {
226       while (I != IE && I->Value < J->Value)
227         ++I;
228       if (I != IE && I->Value == J->Value) {
229         I->Count = SaturatingAdd(I->Count, J->Count);
230         ++I;
231         continue;
232       }
233       ValueData.insert(I, *J);
234     }
235   }
236 };
237
238 /// Profiling information for a single function.
239 struct InstrProfRecord {
240   InstrProfRecord() {}
241   InstrProfRecord(StringRef Name, uint64_t Hash, std::vector<uint64_t> Counts)
242       : Name(Name), Hash(Hash), Counts(std::move(Counts)) {}
243   StringRef Name;
244   uint64_t Hash;
245   std::vector<uint64_t> Counts;
246
247   typedef std::vector<std::pair<uint64_t, const char *>> ValueMapType;
248
249   /// Return the number of value profile kinds with non-zero number
250   /// of profile sites.
251   inline uint32_t getNumValueKinds() const;
252   /// Return the number of instrumented sites for ValueKind.
253   inline uint32_t getNumValueSites(uint32_t ValueKind) const;
254   /// Return the total number of ValueData for ValueKind.
255   inline uint32_t getNumValueData(uint32_t ValueKind) const;
256   /// Return the number of value data collected for ValueKind at profiling
257   /// site: Site.
258   inline uint32_t getNumValueDataForSite(uint32_t ValueKind,
259                                          uint32_t Site) const;
260   inline std::unique_ptr<InstrProfValueData[]>
261   getValueForSite(uint32_t ValueKind, uint32_t Site) const;
262   /// Reserve space for NumValueSites sites.
263   inline void reserveSites(uint32_t ValueKind, uint32_t NumValueSites);
264   /// Add ValueData for ValueKind at value Site.
265   inline void addValueData(uint32_t ValueKind, uint32_t Site,
266                            InstrProfValueData *VData, uint32_t N,
267                            ValueMapType *HashKeys);
268
269   /// Merge the counts in \p Other into this one.
270   inline instrprof_error merge(InstrProfRecord &Other);
271
272   /// Used by InstrProfWriter: update the value strings to commoned strings in
273   /// the writer instance.
274   inline void updateStrings(InstrProfStringTable *StrTab);
275
276   /// Clear value data entries
277   inline void clearValueData() {
278     for (uint32_t Kind = IPVK_First; Kind <= IPVK_Last; ++Kind)
279       getValueSitesForKind(Kind).clear();
280   }
281
282 private:
283   std::vector<InstrProfValueSiteRecord> IndirectCallSites;
284   const std::vector<InstrProfValueSiteRecord> &
285   getValueSitesForKind(uint32_t ValueKind) const {
286     switch (ValueKind) {
287     case IPVK_IndirectCallTarget:
288       return IndirectCallSites;
289     default:
290       llvm_unreachable("Unknown value kind!");
291     }
292     return IndirectCallSites;
293   }
294
295   std::vector<InstrProfValueSiteRecord> &
296   getValueSitesForKind(uint32_t ValueKind) {
297     return const_cast<std::vector<InstrProfValueSiteRecord> &>(
298         const_cast<const InstrProfRecord *>(this)
299             ->getValueSitesForKind(ValueKind));
300   }
301
302   // Map indirect call target name hash to name string.
303   uint64_t remapValue(uint64_t Value, uint32_t ValueKind,
304                       ValueMapType *HashKeys) {
305     if (!HashKeys)
306       return Value;
307     switch (ValueKind) {
308     case IPVK_IndirectCallTarget: {
309       auto Result =
310           std::lower_bound(HashKeys->begin(), HashKeys->end(), Value,
311                            [](const std::pair<uint64_t, const char *> &LHS,
312                               uint64_t RHS) { return LHS.first < RHS; });
313       if (Result != HashKeys->end())
314         Value = (uint64_t)Result->second;
315       break;
316     }
317     }
318     return Value;
319   }
320
321   // Merge Value Profile data from Src record to this record for ValueKind.
322   instrprof_error mergeValueProfData(uint32_t ValueKind, InstrProfRecord &Src) {
323     uint32_t ThisNumValueSites = getNumValueSites(ValueKind);
324     uint32_t OtherNumValueSites = Src.getNumValueSites(ValueKind);
325     if (ThisNumValueSites != OtherNumValueSites)
326       return instrprof_error::value_site_count_mismatch;
327     std::vector<InstrProfValueSiteRecord> &ThisSiteRecords =
328         getValueSitesForKind(ValueKind);
329     std::vector<InstrProfValueSiteRecord> &OtherSiteRecords =
330         Src.getValueSitesForKind(ValueKind);
331     for (uint32_t I = 0; I < ThisNumValueSites; I++)
332       ThisSiteRecords[I].mergeValueData(OtherSiteRecords[I]);
333     return instrprof_error::success;
334   }
335 };
336
337 uint32_t InstrProfRecord::getNumValueKinds() const {
338   uint32_t NumValueKinds = 0;
339   for (uint32_t Kind = IPVK_First; Kind <= IPVK_Last; ++Kind)
340     NumValueKinds += !(getValueSitesForKind(Kind).empty());
341   return NumValueKinds;
342 }
343
344 uint32_t InstrProfRecord::getNumValueData(uint32_t ValueKind) const {
345   uint32_t N = 0;
346   const std::vector<InstrProfValueSiteRecord> &SiteRecords =
347       getValueSitesForKind(ValueKind);
348   for (auto &SR : SiteRecords) {
349     N += SR.ValueData.size();
350   }
351   return N;
352 }
353
354 uint32_t InstrProfRecord::getNumValueSites(uint32_t ValueKind) const {
355   return getValueSitesForKind(ValueKind).size();
356 }
357
358 uint32_t InstrProfRecord::getNumValueDataForSite(uint32_t ValueKind,
359                                                  uint32_t Site) const {
360   return getValueSitesForKind(ValueKind)[Site].ValueData.size();
361 }
362
363 std::unique_ptr<InstrProfValueData[]>
364 InstrProfRecord::getValueForSite(uint32_t ValueKind, uint32_t Site) const {
365   uint32_t N = getNumValueDataForSite(ValueKind, Site);
366   if (N == 0)
367     return std::unique_ptr<InstrProfValueData[]>(nullptr);
368
369   std::unique_ptr<InstrProfValueData[]> VD(new InstrProfValueData[N]);
370   uint32_t I = 0;
371   for (auto V : getValueSitesForKind(ValueKind)[Site].ValueData) {
372     VD[I] = V;
373     I++;
374   }
375   assert(I == N);
376
377   return VD;
378 }
379
380 void InstrProfRecord::addValueData(uint32_t ValueKind, uint32_t Site,
381                                    InstrProfValueData *VData, uint32_t N,
382                                    ValueMapType *HashKeys) {
383   for (uint32_t I = 0; I < N; I++) {
384     VData[I].Value = remapValue(VData[I].Value, ValueKind, HashKeys);
385   }
386   std::vector<InstrProfValueSiteRecord> &ValueSites =
387       getValueSitesForKind(ValueKind);
388   if (N == 0)
389     ValueSites.push_back(InstrProfValueSiteRecord());
390   else
391     ValueSites.emplace_back(VData, VData + N);
392 }
393
394 void InstrProfRecord::reserveSites(uint32_t ValueKind, uint32_t NumValueSites) {
395   std::vector<InstrProfValueSiteRecord> &ValueSites =
396       getValueSitesForKind(ValueKind);
397   ValueSites.reserve(NumValueSites);
398 }
399
400 void InstrProfRecord::updateStrings(InstrProfStringTable *StrTab) {
401   if (!StrTab)
402     return;
403
404   Name = StrTab->insertString(Name);
405   for (auto &VSite : IndirectCallSites)
406     for (auto &VData : VSite.ValueData)
407       VData.Value = (uint64_t)StrTab->insertString((const char *)VData.Value);
408 }
409
410 instrprof_error InstrProfRecord::merge(InstrProfRecord &Other) {
411   // If the number of counters doesn't match we either have bad data
412   // or a hash collision.
413   if (Counts.size() != Other.Counts.size())
414     return instrprof_error::count_mismatch;
415
416   for (size_t I = 0, E = Other.Counts.size(); I < E; ++I) {
417     if (Counts[I] + Other.Counts[I] < Counts[I])
418       return instrprof_error::counter_overflow;
419     Counts[I] += Other.Counts[I];
420   }
421
422   for (uint32_t Kind = IPVK_First; Kind <= IPVK_Last; ++Kind) {
423     instrprof_error result = mergeValueProfData(Kind, Other);
424     if (result != instrprof_error::success)
425       return result;
426   }
427
428   return instrprof_error::success;
429 }
430
431 inline support::endianness getHostEndianness() {
432   return sys::IsLittleEndianHost ? support::little : support::big;
433 }
434
435 /// This is the header of the data structure that defines the on-disk
436 /// layout of the value profile data of a particular kind for one function.
437 struct ValueProfRecord {
438   // The kind of the value profile record.
439   uint32_t Kind;
440   // The number of value profile sites. It is guaranteed to be non-zero;
441   // otherwise the record for this kind won't be emitted.
442   uint32_t NumValueSites;
443   // The first element of the array that stores the number of profiled
444   // values for each value site. The size of the array is NumValueSites.
445   // Since NumValueSites is greater than zero, there is at least one
446   // element in the array.
447   uint8_t SiteCountArray[1];
448
449   // The fake declaration is for documentation purpose only.
450   // Align the start of next field to be on 8 byte boundaries.
451   // uint8_t Padding[X];
452
453   // The array of value profile data. The size of the array is the sum
454   // of all elements in SiteCountArray[].
455   // InstrProfValueData ValueData[];
456
457   /// Return the \c ValueProfRecord header size including the padding bytes.
458   static uint32_t getHeaderSize(uint32_t NumValueSites);
459   /// Return the total size of the value profile record including the
460   /// header and the value data.
461   static uint32_t getSize(uint32_t NumValueSites, uint32_t NumValueData);
462   /// Return the total size of the value profile record including the
463   /// header and the value data.
464   uint32_t getSize() const { return getSize(NumValueSites, getNumValueData()); }
465   /// Use this method to advance to the next \c ValueProfRecord.
466   ValueProfRecord *getNext();
467   /// Return the pointer to the first value profile data.
468   InstrProfValueData *getValueData();
469   /// Return the number of value sites.
470   uint32_t getNumValueSites() const { return NumValueSites; }
471   /// Return the number of value data.
472   uint32_t getNumValueData() const;
473   /// Read data from this record and save it to Record.
474   void deserializeTo(InstrProfRecord &Record,
475                      InstrProfRecord::ValueMapType *VMap);
476   /// Extract data from \c Record and serialize into this instance.
477   void serializeFrom(const InstrProfRecord &Record, uint32_t ValueKind,
478                      uint32_t NumValueSites);
479   /// In-place byte swap:
480   /// Do byte swap for this instance. \c Old is the original order before
481   /// the swap, and \c New is the New byte order.
482   void swapBytes(support::endianness Old, support::endianness New);
483 };
484
485 /// Per-function header/control data structure for value profiling
486 /// data in indexed format.
487 struct ValueProfData {
488   // Total size in bytes including this field. It must be a multiple
489   // of sizeof(uint64_t).
490   uint32_t TotalSize;
491   // The number of value profile kinds that has value profile data.
492   // In this implementation, a value profile kind is considered to
493   // have profile data if the number of value profile sites for the
494   // kind is not zero. More aggressively, the implementation can
495   // choose to check the actual data value: if none of the value sites
496   // has any profiled values, the kind can be skipped.
497   uint32_t NumValueKinds;
498
499   // Following are a sequence of variable length records. The prefix/header
500   // of each record is defined by ValueProfRecord type. The number of
501   // records is NumValueKinds.
502   // ValueProfRecord Record_1;
503   // ValueProfRecord Record_N;
504
505   /// Return the total size in bytes of the on-disk value profile data
506   /// given the data stored in Record.
507   static uint32_t getSize(const InstrProfRecord &Record);
508   /// Return a pointer to \c ValueProfData instance ready to be streamed.
509   static std::unique_ptr<ValueProfData>
510   serializeFrom(const InstrProfRecord &Record);
511   /// Return a pointer to \c ValueProfileData instance ready to be read.
512   /// All data in the instance are properly byte swapped. The input
513   /// data is assumed to be in little endian order.
514   static ErrorOr<std::unique_ptr<ValueProfData>>
515   getValueProfData(const unsigned char *D, const unsigned char *const BufferEnd,
516                    support::endianness SrcDataEndianness);
517   /// Swap byte order from \c Endianness order to host byte order.
518   void swapBytesToHost(support::endianness Endianness);
519   /// Swap byte order from host byte order to \c Endianness order.
520   void swapBytesFromHost(support::endianness Endianness);
521   /// Return the total size of \c ValueProfileData.
522   uint32_t getSize() const { return TotalSize; }
523   /// Read data from this data and save it to \c Record.
524   void deserializeTo(InstrProfRecord &Record,
525                      InstrProfRecord::ValueMapType *VMap);
526   /// Return the first \c ValueProfRecord instance.
527   ValueProfRecord *getFirstValueProfRecord();
528 };
529
530 namespace IndexedInstrProf {
531
532 enum class HashT : uint32_t {
533   MD5,
534
535   Last = MD5
536 };
537
538 static inline uint64_t MD5Hash(StringRef Str) {
539   MD5 Hash;
540   Hash.update(Str);
541   llvm::MD5::MD5Result Result;
542   Hash.final(Result);
543   // Return the least significant 8 bytes. Our MD5 implementation returns the
544   // result in little endian, so we may need to swap bytes.
545   using namespace llvm::support;
546   return endian::read<uint64_t, little, unaligned>(Result);
547 }
548
549 static inline uint64_t ComputeHash(HashT Type, StringRef K) {
550   switch (Type) {
551   case HashT::MD5:
552     return IndexedInstrProf::MD5Hash(K);
553   }
554   llvm_unreachable("Unhandled hash type");
555 }
556
557 const uint64_t Magic = 0x8169666f72706cff; // "\xfflprofi\x81"
558 const uint64_t Version = 3;
559 const HashT HashType = HashT::MD5;
560
561 // This structure defines the file header of the LLVM profile
562 // data file in indexed-format.
563 struct Header {
564   uint64_t Magic;
565   uint64_t Version;
566   uint64_t MaxFunctionCount;
567   uint64_t HashType;
568   uint64_t HashOffset;
569 };
570
571 } // end namespace IndexedInstrProf
572
573 namespace RawInstrProf {
574
575 const uint64_t Version = 2;
576
577 // Magic number to detect file format and endianness.
578 // Use 255 at one end, since no UTF-8 file can use that character.  Avoid 0,
579 // so that utilities, like strings, don't grab it as a string.  129 is also
580 // invalid UTF-8, and high enough to be interesting.
581 // Use "lprofr" in the centre to stand for "LLVM Profile Raw", or "lprofR"
582 // for 32-bit platforms.
583 // The magic and version need to be kept in sync with
584 // projects/compiler-rt/lib/profile/InstrProfiling.c
585
586 template <class IntPtrT>
587 inline uint64_t getMagic();
588 template <>
589 inline uint64_t getMagic<uint64_t>() {
590   return uint64_t(255) << 56 | uint64_t('l') << 48 | uint64_t('p') << 40 |
591          uint64_t('r') << 32 | uint64_t('o') << 24 | uint64_t('f') << 16 |
592          uint64_t('r') << 8 | uint64_t(129);
593 }
594
595 template <>
596 inline uint64_t getMagic<uint32_t>() {
597   return uint64_t(255) << 56 | uint64_t('l') << 48 | uint64_t('p') << 40 |
598          uint64_t('r') << 32 | uint64_t('o') << 24 | uint64_t('f') << 16 |
599          uint64_t('R') << 8 | uint64_t(129);
600 }
601
602 // Per-function profile data header/control structure.
603 // The definition should match the structure defined in
604 // compiler-rt/lib/profile/InstrProfiling.h.
605 // It should also match the synthesized type in
606 // Transforms/Instrumentation/InstrProfiling.cpp:getOrCreateRegionCounters.
607 template <class IntPtrT> struct LLVM_ALIGNAS(8) ProfileData {
608   #define INSTR_PROF_DATA(Type, LLVMType, Name, Init) Type Name;
609   #include "llvm/ProfileData/InstrProfData.inc"
610 };
611
612 // File header structure of the LLVM profile data in raw format.
613 // The definition should match the header referenced in
614 // compiler-rt/lib/profile/InstrProfilingFile.c  and
615 // InstrProfilingBuffer.c.
616 struct Header {
617 #define INSTR_PROF_RAW_HEADER(Type, Name, Init) Type Name;
618 #include "llvm/ProfileData/InstrProfData.inc"
619 };
620
621 }  // end namespace RawInstrProf
622
623 namespace coverage {
624
625 // Profile coverage map has the following layout:
626 // [CoverageMapFileHeader]
627 // [ArrayStart]
628 //  [CovMapFunctionRecord]
629 //  [CovMapFunctionRecord]
630 //  ...
631 // [ArrayEnd]
632 // [Encoded Region Mapping Data]
633 LLVM_PACKED_START
634 template <class IntPtrT> struct CovMapFunctionRecord {
635   #define COVMAP_FUNC_RECORD(Type, LLVMType, Name, Init) Type Name;
636   #include "llvm/ProfileData/InstrProfData.inc"
637 };
638 LLVM_PACKED_END
639
640 }
641
642 } // end namespace llvm
643
644 namespace std {
645 template <>
646 struct is_error_code_enum<llvm::instrprof_error> : std::true_type {};
647 }
648
649 #endif // LLVM_PROFILEDATA_INSTRPROF_H_