[PGO] Move Value Profile Kind to 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 #define VALUE_PROF_KIND(Enumerator, Value) Enumerator = Value,
173 #include "llvm/ProfileData/InstrProfData.inc"
174 };
175
176 struct InstrProfStringTable {
177   // Set of string values in profiling data.
178   StringSet<> StringValueSet;
179   InstrProfStringTable() { StringValueSet.clear(); }
180   // Get a pointer to internal storage of a string in set
181   const char *getStringData(StringRef Str) {
182     auto Result = StringValueSet.find(Str);
183     return (Result == StringValueSet.end()) ? nullptr : Result->first().data();
184   }
185   // Insert a string to StringTable
186   const char *insertString(StringRef Str) {
187     auto Result = StringValueSet.insert(Str);
188     return Result.first->first().data();
189   }
190 };
191
192 struct InstrProfValueData {
193   // Profiled value.
194   uint64_t Value;
195   // Number of times the value appears in the training run.
196   uint64_t Count;
197 };
198
199 struct InstrProfValueSiteRecord {
200   /// Value profiling data pairs at a given value site.
201   std::list<InstrProfValueData> ValueData;
202
203   InstrProfValueSiteRecord() { ValueData.clear(); }
204   template <class InputIterator>
205   InstrProfValueSiteRecord(InputIterator F, InputIterator L)
206       : ValueData(F, L) {}
207
208   /// Sort ValueData ascending by Value
209   void sortByTargetValues() {
210     ValueData.sort(
211         [](const InstrProfValueData &left, const InstrProfValueData &right) {
212           return left.Value < right.Value;
213         });
214   }
215
216   /// Merge data from another InstrProfValueSiteRecord
217   void mergeValueData(InstrProfValueSiteRecord &Input) {
218     this->sortByTargetValues();
219     Input.sortByTargetValues();
220     auto I = ValueData.begin();
221     auto IE = ValueData.end();
222     for (auto J = Input.ValueData.begin(), JE = Input.ValueData.end(); J != JE;
223          ++J) {
224       while (I != IE && I->Value < J->Value)
225         ++I;
226       if (I != IE && I->Value == J->Value) {
227         I->Count = SaturatingAdd(I->Count, J->Count);
228         ++I;
229         continue;
230       }
231       ValueData.insert(I, *J);
232     }
233   }
234 };
235
236 /// Profiling information for a single function.
237 struct InstrProfRecord {
238   InstrProfRecord() {}
239   InstrProfRecord(StringRef Name, uint64_t Hash, std::vector<uint64_t> Counts)
240       : Name(Name), Hash(Hash), Counts(std::move(Counts)) {}
241   StringRef Name;
242   uint64_t Hash;
243   std::vector<uint64_t> Counts;
244
245   typedef std::vector<std::pair<uint64_t, const char *>> ValueMapType;
246
247   /// Return the number of value profile kinds with non-zero number
248   /// of profile sites.
249   inline uint32_t getNumValueKinds() const;
250   /// Return the number of instrumented sites for ValueKind.
251   inline uint32_t getNumValueSites(uint32_t ValueKind) const;
252   /// Return the total number of ValueData for ValueKind.
253   inline uint32_t getNumValueData(uint32_t ValueKind) const;
254   /// Return the number of value data collected for ValueKind at profiling
255   /// site: Site.
256   inline uint32_t getNumValueDataForSite(uint32_t ValueKind,
257                                          uint32_t Site) const;
258   inline std::unique_ptr<InstrProfValueData[]>
259   getValueForSite(uint32_t ValueKind, uint32_t Site) const;
260   /// Reserve space for NumValueSites sites.
261   inline void reserveSites(uint32_t ValueKind, uint32_t NumValueSites);
262   /// Add ValueData for ValueKind at value Site.
263   inline void addValueData(uint32_t ValueKind, uint32_t Site,
264                            InstrProfValueData *VData, uint32_t N,
265                            ValueMapType *HashKeys);
266
267   /// Merge the counts in \p Other into this one.
268   inline instrprof_error merge(InstrProfRecord &Other);
269
270   /// Used by InstrProfWriter: update the value strings to commoned strings in
271   /// the writer instance.
272   inline void updateStrings(InstrProfStringTable *StrTab);
273
274   /// Clear value data entries
275   inline void clearValueData() {
276     for (uint32_t Kind = IPVK_First; Kind <= IPVK_Last; ++Kind)
277       getValueSitesForKind(Kind).clear();
278   }
279
280 private:
281   std::vector<InstrProfValueSiteRecord> IndirectCallSites;
282   const std::vector<InstrProfValueSiteRecord> &
283   getValueSitesForKind(uint32_t ValueKind) const {
284     switch (ValueKind) {
285     case IPVK_IndirectCallTarget:
286       return IndirectCallSites;
287     default:
288       llvm_unreachable("Unknown value kind!");
289     }
290     return IndirectCallSites;
291   }
292
293   std::vector<InstrProfValueSiteRecord> &
294   getValueSitesForKind(uint32_t ValueKind) {
295     return const_cast<std::vector<InstrProfValueSiteRecord> &>(
296         const_cast<const InstrProfRecord *>(this)
297             ->getValueSitesForKind(ValueKind));
298   }
299
300   // Map indirect call target name hash to name string.
301   uint64_t remapValue(uint64_t Value, uint32_t ValueKind,
302                       ValueMapType *HashKeys) {
303     if (!HashKeys)
304       return Value;
305     switch (ValueKind) {
306     case IPVK_IndirectCallTarget: {
307       auto Result =
308           std::lower_bound(HashKeys->begin(), HashKeys->end(), Value,
309                            [](const std::pair<uint64_t, const char *> &LHS,
310                               uint64_t RHS) { return LHS.first < RHS; });
311       if (Result != HashKeys->end())
312         Value = (uint64_t)Result->second;
313       break;
314     }
315     }
316     return Value;
317   }
318
319   // Merge Value Profile data from Src record to this record for ValueKind.
320   instrprof_error mergeValueProfData(uint32_t ValueKind, InstrProfRecord &Src) {
321     uint32_t ThisNumValueSites = getNumValueSites(ValueKind);
322     uint32_t OtherNumValueSites = Src.getNumValueSites(ValueKind);
323     if (ThisNumValueSites != OtherNumValueSites)
324       return instrprof_error::value_site_count_mismatch;
325     std::vector<InstrProfValueSiteRecord> &ThisSiteRecords =
326         getValueSitesForKind(ValueKind);
327     std::vector<InstrProfValueSiteRecord> &OtherSiteRecords =
328         Src.getValueSitesForKind(ValueKind);
329     for (uint32_t I = 0; I < ThisNumValueSites; I++)
330       ThisSiteRecords[I].mergeValueData(OtherSiteRecords[I]);
331     return instrprof_error::success;
332   }
333 };
334
335 uint32_t InstrProfRecord::getNumValueKinds() const {
336   uint32_t NumValueKinds = 0;
337   for (uint32_t Kind = IPVK_First; Kind <= IPVK_Last; ++Kind)
338     NumValueKinds += !(getValueSitesForKind(Kind).empty());
339   return NumValueKinds;
340 }
341
342 uint32_t InstrProfRecord::getNumValueData(uint32_t ValueKind) const {
343   uint32_t N = 0;
344   const std::vector<InstrProfValueSiteRecord> &SiteRecords =
345       getValueSitesForKind(ValueKind);
346   for (auto &SR : SiteRecords) {
347     N += SR.ValueData.size();
348   }
349   return N;
350 }
351
352 uint32_t InstrProfRecord::getNumValueSites(uint32_t ValueKind) const {
353   return getValueSitesForKind(ValueKind).size();
354 }
355
356 uint32_t InstrProfRecord::getNumValueDataForSite(uint32_t ValueKind,
357                                                  uint32_t Site) const {
358   return getValueSitesForKind(ValueKind)[Site].ValueData.size();
359 }
360
361 std::unique_ptr<InstrProfValueData[]>
362 InstrProfRecord::getValueForSite(uint32_t ValueKind, uint32_t Site) const {
363   uint32_t N = getNumValueDataForSite(ValueKind, Site);
364   if (N == 0)
365     return std::unique_ptr<InstrProfValueData[]>(nullptr);
366
367   std::unique_ptr<InstrProfValueData[]> VD(new InstrProfValueData[N]);
368   uint32_t I = 0;
369   for (auto V : getValueSitesForKind(ValueKind)[Site].ValueData) {
370     VD[I] = V;
371     I++;
372   }
373   assert(I == N);
374
375   return VD;
376 }
377
378 void InstrProfRecord::addValueData(uint32_t ValueKind, uint32_t Site,
379                                    InstrProfValueData *VData, uint32_t N,
380                                    ValueMapType *HashKeys) {
381   for (uint32_t I = 0; I < N; I++) {
382     VData[I].Value = remapValue(VData[I].Value, ValueKind, HashKeys);
383   }
384   std::vector<InstrProfValueSiteRecord> &ValueSites =
385       getValueSitesForKind(ValueKind);
386   if (N == 0)
387     ValueSites.push_back(InstrProfValueSiteRecord());
388   else
389     ValueSites.emplace_back(VData, VData + N);
390 }
391
392 void InstrProfRecord::reserveSites(uint32_t ValueKind, uint32_t NumValueSites) {
393   std::vector<InstrProfValueSiteRecord> &ValueSites =
394       getValueSitesForKind(ValueKind);
395   ValueSites.reserve(NumValueSites);
396 }
397
398 void InstrProfRecord::updateStrings(InstrProfStringTable *StrTab) {
399   if (!StrTab)
400     return;
401
402   Name = StrTab->insertString(Name);
403   for (auto &VSite : IndirectCallSites)
404     for (auto &VData : VSite.ValueData)
405       VData.Value = (uint64_t)StrTab->insertString((const char *)VData.Value);
406 }
407
408 instrprof_error InstrProfRecord::merge(InstrProfRecord &Other) {
409   // If the number of counters doesn't match we either have bad data
410   // or a hash collision.
411   if (Counts.size() != Other.Counts.size())
412     return instrprof_error::count_mismatch;
413
414   for (size_t I = 0, E = Other.Counts.size(); I < E; ++I) {
415     if (Counts[I] + Other.Counts[I] < Counts[I])
416       return instrprof_error::counter_overflow;
417     Counts[I] += Other.Counts[I];
418   }
419
420   for (uint32_t Kind = IPVK_First; Kind <= IPVK_Last; ++Kind) {
421     instrprof_error result = mergeValueProfData(Kind, Other);
422     if (result != instrprof_error::success)
423       return result;
424   }
425
426   return instrprof_error::success;
427 }
428
429 inline support::endianness getHostEndianness() {
430   return sys::IsLittleEndianHost ? support::little : support::big;
431 }
432
433 /// This is the header of the data structure that defines the on-disk
434 /// layout of the value profile data of a particular kind for one function.
435 struct ValueProfRecord {
436   // The kind of the value profile record.
437   uint32_t Kind;
438   // The number of value profile sites. It is guaranteed to be non-zero;
439   // otherwise the record for this kind won't be emitted.
440   uint32_t NumValueSites;
441   // The first element of the array that stores the number of profiled
442   // values for each value site. The size of the array is NumValueSites.
443   // Since NumValueSites is greater than zero, there is at least one
444   // element in the array.
445   uint8_t SiteCountArray[1];
446
447   // The fake declaration is for documentation purpose only.
448   // Align the start of next field to be on 8 byte boundaries.
449   // uint8_t Padding[X];
450
451   // The array of value profile data. The size of the array is the sum
452   // of all elements in SiteCountArray[].
453   // InstrProfValueData ValueData[];
454
455   /// Return the \c ValueProfRecord header size including the padding bytes.
456   static uint32_t getHeaderSize(uint32_t NumValueSites);
457   /// Return the total size of the value profile record including the
458   /// header and the value data.
459   static uint32_t getSize(uint32_t NumValueSites, uint32_t NumValueData);
460   /// Return the total size of the value profile record including the
461   /// header and the value data.
462   uint32_t getSize() const { return getSize(NumValueSites, getNumValueData()); }
463   /// Use this method to advance to the next \c ValueProfRecord.
464   ValueProfRecord *getNext();
465   /// Return the pointer to the first value profile data.
466   InstrProfValueData *getValueData();
467   /// Return the number of value sites.
468   uint32_t getNumValueSites() const { return NumValueSites; }
469   /// Return the number of value data.
470   uint32_t getNumValueData() const;
471   /// Read data from this record and save it to Record.
472   void deserializeTo(InstrProfRecord &Record,
473                      InstrProfRecord::ValueMapType *VMap);
474   /// Extract data from \c Record and serialize into this instance.
475   void serializeFrom(const InstrProfRecord &Record, uint32_t ValueKind,
476                      uint32_t NumValueSites);
477   /// In-place byte swap:
478   /// Do byte swap for this instance. \c Old is the original order before
479   /// the swap, and \c New is the New byte order.
480   void swapBytes(support::endianness Old, support::endianness New);
481 };
482
483 /// Per-function header/control data structure for value profiling
484 /// data in indexed format.
485 struct ValueProfData {
486   // Total size in bytes including this field. It must be a multiple
487   // of sizeof(uint64_t).
488   uint32_t TotalSize;
489   // The number of value profile kinds that has value profile data.
490   // In this implementation, a value profile kind is considered to
491   // have profile data if the number of value profile sites for the
492   // kind is not zero. More aggressively, the implementation can
493   // choose to check the actual data value: if none of the value sites
494   // has any profiled values, the kind can be skipped.
495   uint32_t NumValueKinds;
496
497   // Following are a sequence of variable length records. The prefix/header
498   // of each record is defined by ValueProfRecord type. The number of
499   // records is NumValueKinds.
500   // ValueProfRecord Record_1;
501   // ValueProfRecord Record_N;
502
503   /// Return the total size in bytes of the on-disk value profile data
504   /// given the data stored in Record.
505   static uint32_t getSize(const InstrProfRecord &Record);
506   /// Return a pointer to \c ValueProfData instance ready to be streamed.
507   static std::unique_ptr<ValueProfData>
508   serializeFrom(const InstrProfRecord &Record);
509   /// Return a pointer to \c ValueProfileData instance ready to be read.
510   /// All data in the instance are properly byte swapped. The input
511   /// data is assumed to be in little endian order.
512   static ErrorOr<std::unique_ptr<ValueProfData>>
513   getValueProfData(const unsigned char *D, const unsigned char *const BufferEnd,
514                    support::endianness SrcDataEndianness);
515   /// Swap byte order from \c Endianness order to host byte order.
516   void swapBytesToHost(support::endianness Endianness);
517   /// Swap byte order from host byte order to \c Endianness order.
518   void swapBytesFromHost(support::endianness Endianness);
519   /// Return the total size of \c ValueProfileData.
520   uint32_t getSize() const { return TotalSize; }
521   /// Read data from this data and save it to \c Record.
522   void deserializeTo(InstrProfRecord &Record,
523                      InstrProfRecord::ValueMapType *VMap);
524   /// Return the first \c ValueProfRecord instance.
525   ValueProfRecord *getFirstValueProfRecord();
526 };
527
528 namespace IndexedInstrProf {
529
530 enum class HashT : uint32_t {
531   MD5,
532
533   Last = MD5
534 };
535
536 static inline uint64_t MD5Hash(StringRef Str) {
537   MD5 Hash;
538   Hash.update(Str);
539   llvm::MD5::MD5Result Result;
540   Hash.final(Result);
541   // Return the least significant 8 bytes. Our MD5 implementation returns the
542   // result in little endian, so we may need to swap bytes.
543   using namespace llvm::support;
544   return endian::read<uint64_t, little, unaligned>(Result);
545 }
546
547 static inline uint64_t ComputeHash(HashT Type, StringRef K) {
548   switch (Type) {
549   case HashT::MD5:
550     return IndexedInstrProf::MD5Hash(K);
551   }
552   llvm_unreachable("Unhandled hash type");
553 }
554
555 const uint64_t Magic = 0x8169666f72706cff; // "\xfflprofi\x81"
556 const uint64_t Version = 3;
557 const HashT HashType = HashT::MD5;
558
559 // This structure defines the file header of the LLVM profile
560 // data file in indexed-format.
561 struct Header {
562   uint64_t Magic;
563   uint64_t Version;
564   uint64_t MaxFunctionCount;
565   uint64_t HashType;
566   uint64_t HashOffset;
567 };
568
569 } // end namespace IndexedInstrProf
570
571 namespace RawInstrProf {
572
573 const uint64_t Version = 2;
574
575 // Magic number to detect file format and endianness.
576 // Use 255 at one end, since no UTF-8 file can use that character.  Avoid 0,
577 // so that utilities, like strings, don't grab it as a string.  129 is also
578 // invalid UTF-8, and high enough to be interesting.
579 // Use "lprofr" in the centre to stand for "LLVM Profile Raw", or "lprofR"
580 // for 32-bit platforms.
581 // The magic and version need to be kept in sync with
582 // projects/compiler-rt/lib/profile/InstrProfiling.c
583
584 template <class IntPtrT>
585 inline uint64_t getMagic();
586 template <>
587 inline uint64_t getMagic<uint64_t>() {
588   return uint64_t(255) << 56 | uint64_t('l') << 48 | uint64_t('p') << 40 |
589          uint64_t('r') << 32 | uint64_t('o') << 24 | uint64_t('f') << 16 |
590          uint64_t('r') << 8 | uint64_t(129);
591 }
592
593 template <>
594 inline uint64_t getMagic<uint32_t>() {
595   return uint64_t(255) << 56 | uint64_t('l') << 48 | uint64_t('p') << 40 |
596          uint64_t('r') << 32 | uint64_t('o') << 24 | uint64_t('f') << 16 |
597          uint64_t('R') << 8 | uint64_t(129);
598 }
599
600 // Per-function profile data header/control structure.
601 // The definition should match the structure defined in
602 // compiler-rt/lib/profile/InstrProfiling.h.
603 // It should also match the synthesized type in
604 // Transforms/Instrumentation/InstrProfiling.cpp:getOrCreateRegionCounters.
605 template <class IntPtrT> struct LLVM_ALIGNAS(8) ProfileData {
606   #define INSTR_PROF_DATA(Type, LLVMType, Name, Init) Type Name;
607   #include "llvm/ProfileData/InstrProfData.inc"
608 };
609
610 // File header structure of the LLVM profile data in raw format.
611 // The definition should match the header referenced in
612 // compiler-rt/lib/profile/InstrProfilingFile.c  and
613 // InstrProfilingBuffer.c.
614 struct Header {
615 #define INSTR_PROF_RAW_HEADER(Type, Name, Init) Type Name;
616 #include "llvm/ProfileData/InstrProfData.inc"
617 };
618
619 }  // end namespace RawInstrProf
620
621 namespace coverage {
622
623 // Profile coverage map has the following layout:
624 // [CoverageMapFileHeader]
625 // [ArrayStart]
626 //  [CovMapFunctionRecord]
627 //  [CovMapFunctionRecord]
628 //  ...
629 // [ArrayEnd]
630 // [Encoded Region Mapping Data]
631 LLVM_PACKED_START
632 template <class IntPtrT> struct CovMapFunctionRecord {
633   #define COVMAP_FUNC_RECORD(Type, LLVMType, Name, Init) Type Name;
634   #include "llvm/ProfileData/InstrProfData.inc"
635 };
636 LLVM_PACKED_END
637
638 }
639
640 } // end namespace llvm
641
642 namespace std {
643 template <>
644 struct is_error_code_enum<llvm::instrprof_error> : std::true_type {};
645 }
646
647 #endif // LLVM_PROFILEDATA_INSTRPROF_H_