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