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