[PGO]: Implement Func PGO name string compression
[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 /// Given a vector of strings (function PGO names) \c NameStrs, the
164 /// method generates a combined string \c Result thatis ready to be
165 /// serialized.  The \c Result string is comprised of three fields:
166 /// The first field is the legnth of the uncompressed strings, and the
167 /// the second field is the length of the zlib-compressed string.
168 /// Both fields are encoded in ULEB128.  If \c doCompress is false, the
169 ///  third field is the uncompressed strings; otherwise it is the 
170 /// compressed string. When the string compression is off, the 
171 /// second field will have value zero.
172 int collectPGOFuncNameStrings(const std::vector<std::string> &NameStrs,
173                               bool doCompression, std::string &Result);
174 /// Produce \c Result string with the same format described above. The input
175 /// is vector of PGO function name variables that are referenced.
176 int collectPGOFuncNameStrings(const std::vector<GlobalVariable *> &NameVars,
177                               std::string &Result);
178 class InstrProfSymtab;
179 /// \c NameStrings is a string composed of one of more sub-strings encoded in
180 /// the
181 /// format described above. The substrings are seperated by 0 or more zero
182 /// bytes.
183 /// This method decodes the string and populates the \c Symtab.
184 int readPGOFuncNameStrings(StringRef NameStrings, InstrProfSymtab &Symtab);
185
186 const std::error_category &instrprof_category();
187
188 enum class instrprof_error {
189   success = 0,
190   eof,
191   unrecognized_format,
192   bad_magic,
193   bad_header,
194   unsupported_version,
195   unsupported_hash_type,
196   too_large,
197   truncated,
198   malformed,
199   unknown_function,
200   hash_mismatch,
201   count_mismatch,
202   counter_overflow,
203   value_site_count_mismatch
204 };
205
206 inline std::error_code make_error_code(instrprof_error E) {
207   return std::error_code(static_cast<int>(E), instrprof_category());
208 }
209
210 inline instrprof_error MergeResult(instrprof_error &Accumulator,
211                                    instrprof_error Result) {
212   // Prefer first error encountered as later errors may be secondary effects of
213   // the initial problem.
214   if (Accumulator == instrprof_error::success &&
215       Result != instrprof_error::success)
216     Accumulator = Result;
217   return Accumulator;
218 }
219
220 enum InstrProfValueKind : uint32_t {
221 #define VALUE_PROF_KIND(Enumerator, Value) Enumerator = Value,
222 #include "llvm/ProfileData/InstrProfData.inc"
223 };
224
225 namespace object {
226 class SectionRef;
227 }
228
229 namespace IndexedInstrProf {
230 uint64_t ComputeHash(StringRef K);
231 }
232
233 /// A symbol table used for function PGO name look-up with keys
234 /// (such as pointers, md5hash values) to the function. A function's
235 /// PGO name or name's md5hash are used in retrieving the profile
236 /// data of the function. See \c getPGOFuncName() method for details
237 /// on how PGO name is formed.
238 class InstrProfSymtab {
239 public:
240   typedef std::vector<std::pair<uint64_t, uint64_t>> AddrHashMap;
241
242 private:
243   StringRef Data;
244   uint64_t Address;
245   // A map from MD5 hash keys to function name strings.
246   std::vector<std::pair<uint64_t, std::string>> HashNameMap;
247   // A map from function runtime address to function name MD5 hash.
248   // This map is only populated and used by raw instr profile reader.
249   AddrHashMap AddrToMD5Map;
250
251 public:
252   InstrProfSymtab() : Data(), Address(0), HashNameMap(), AddrToMD5Map() {}
253
254   /// Create InstrProfSymtab from an object file section which
255   /// contains function PGO names that are uncompressed.
256   /// This interface is used by CoverageMappingReader.
257   std::error_code create(object::SectionRef &Section);
258   /// This interface is used by reader of CoverageMapping test
259   /// format.
260   inline std::error_code create(StringRef D, uint64_t BaseAddr);
261   /// \c NameStrings is a string composed of one of more sub-strings
262   ///  encoded in the format described above. The substrings are
263   /// seperated by 0 or more zero bytes. This method decodes the
264   /// string and populates the \c Symtab.
265   inline std::error_code create(StringRef NameStrings);
266   /// Create InstrProfSymtab from a set of names iteratable from
267   /// \p IterRange. This interface is used by IndexedProfReader.
268   template <typename NameIterRange> void create(const NameIterRange &IterRange);
269   // If the symtab is created by a series of calls to \c addFuncName, \c
270   // finalizeSymtab needs to be called before looking up function names.
271   // This is required because the underlying map is a vector (for space
272   // efficiency) which needs to be sorted.
273   inline void finalizeSymtab();
274   /// Update the symtab by adding \p FuncName to the table. This interface
275   /// is used by the raw and text profile readers.
276   void addFuncName(StringRef FuncName) {
277     HashNameMap.push_back(std::make_pair(
278         IndexedInstrProf::ComputeHash(FuncName), FuncName.str()));
279   }
280   /// Map a function address to its name's MD5 hash. This interface
281   /// is only used by the raw profiler reader.
282   void mapAddress(uint64_t Addr, uint64_t MD5Val) {
283     AddrToMD5Map.push_back(std::make_pair(Addr, MD5Val));
284   }
285   AddrHashMap &getAddrHashMap() { return AddrToMD5Map; }
286   /// Return function's PGO name from the function name's symbol
287   /// address in the object file. If an error occurs, return
288   /// an empty string.
289   StringRef getFuncName(uint64_t FuncNameAddress, size_t NameSize);
290   /// Return function's PGO name from the name's md5 hash value.
291   /// If not found, return an empty string.
292   inline StringRef getFuncName(uint64_t FuncMD5Hash);
293 };
294
295 std::error_code InstrProfSymtab::create(StringRef D, uint64_t BaseAddr) {
296   Data = D;
297   Address = BaseAddr;
298   return std::error_code();
299 }
300
301 std::error_code InstrProfSymtab::create(StringRef NameStrings) {
302   if (readPGOFuncNameStrings(NameStrings, *this))
303     return make_error_code(instrprof_error::malformed);
304   return std::error_code();
305 }
306
307 template <typename NameIterRange>
308 void InstrProfSymtab::create(const NameIterRange &IterRange) {
309   for (auto Name : IterRange)
310     HashNameMap.push_back(
311         std::make_pair(IndexedInstrProf::ComputeHash(Name), Name.str()));
312   finalizeSymtab();
313 }
314
315 void InstrProfSymtab::finalizeSymtab() {
316   std::sort(HashNameMap.begin(), HashNameMap.end(), less_first());
317   HashNameMap.erase(std::unique(HashNameMap.begin(), HashNameMap.end()),
318                     HashNameMap.end());
319   std::sort(AddrToMD5Map.begin(), AddrToMD5Map.end(), less_first());
320   AddrToMD5Map.erase(std::unique(AddrToMD5Map.begin(), AddrToMD5Map.end()),
321                      AddrToMD5Map.end());
322 }
323
324 StringRef InstrProfSymtab::getFuncName(uint64_t FuncMD5Hash) {
325   auto Result =
326       std::lower_bound(HashNameMap.begin(), HashNameMap.end(), FuncMD5Hash,
327                        [](const std::pair<uint64_t, std::string> &LHS,
328                           uint64_t RHS) { return LHS.first < RHS; });
329   if (Result != HashNameMap.end())
330     return Result->second;
331   return StringRef();
332 }
333
334 struct InstrProfValueSiteRecord {
335   /// Value profiling data pairs at a given value site.
336   std::list<InstrProfValueData> ValueData;
337
338   InstrProfValueSiteRecord() { ValueData.clear(); }
339   template <class InputIterator>
340   InstrProfValueSiteRecord(InputIterator F, InputIterator L)
341       : ValueData(F, L) {}
342
343   /// Sort ValueData ascending by Value
344   void sortByTargetValues() {
345     ValueData.sort(
346         [](const InstrProfValueData &left, const InstrProfValueData &right) {
347           return left.Value < right.Value;
348         });
349   }
350
351   /// Merge data from another InstrProfValueSiteRecord
352   /// Optionally scale merged counts by \p Weight.
353   instrprof_error mergeValueData(InstrProfValueSiteRecord &Input,
354                                  uint64_t Weight = 1);
355 };
356
357 /// Profiling information for a single function.
358 struct InstrProfRecord {
359   InstrProfRecord() {}
360   InstrProfRecord(StringRef Name, uint64_t Hash, std::vector<uint64_t> Counts)
361       : Name(Name), Hash(Hash), Counts(std::move(Counts)) {}
362   StringRef Name;
363   uint64_t Hash;
364   std::vector<uint64_t> Counts;
365
366   typedef std::vector<std::pair<uint64_t, uint64_t>> ValueMapType;
367
368   /// Return the number of value profile kinds with non-zero number
369   /// of profile sites.
370   inline uint32_t getNumValueKinds() const;
371   /// Return the number of instrumented sites for ValueKind.
372   inline uint32_t getNumValueSites(uint32_t ValueKind) const;
373   /// Return the total number of ValueData for ValueKind.
374   inline uint32_t getNumValueData(uint32_t ValueKind) const;
375   /// Return the number of value data collected for ValueKind at profiling
376   /// site: Site.
377   inline uint32_t getNumValueDataForSite(uint32_t ValueKind,
378                                          uint32_t Site) const;
379   /// Return the array of profiled values at \p Site.
380   inline std::unique_ptr<InstrProfValueData[]>
381   getValueForSite(uint32_t ValueKind, uint32_t Site,
382                   uint64_t (*ValueMapper)(uint32_t, uint64_t) = 0) const;
383   inline void
384   getValueForSite(InstrProfValueData Dest[], uint32_t ValueKind, uint32_t Site,
385                   uint64_t (*ValueMapper)(uint32_t, uint64_t) = 0) const;
386   /// Reserve space for NumValueSites sites.
387   inline void reserveSites(uint32_t ValueKind, uint32_t NumValueSites);
388   /// Add ValueData for ValueKind at value Site.
389   void addValueData(uint32_t ValueKind, uint32_t Site,
390                     InstrProfValueData *VData, uint32_t N,
391                     ValueMapType *ValueMap);
392
393   /// Merge the counts in \p Other into this one.
394   /// Optionally scale merged counts by \p Weight.
395   instrprof_error merge(InstrProfRecord &Other, uint64_t Weight = 1);
396
397   /// Clear value data entries
398   void clearValueData() {
399     for (uint32_t Kind = IPVK_First; Kind <= IPVK_Last; ++Kind)
400       getValueSitesForKind(Kind).clear();
401   }
402
403 private:
404   std::vector<InstrProfValueSiteRecord> IndirectCallSites;
405   const std::vector<InstrProfValueSiteRecord> &
406   getValueSitesForKind(uint32_t ValueKind) const {
407     switch (ValueKind) {
408     case IPVK_IndirectCallTarget:
409       return IndirectCallSites;
410     default:
411       llvm_unreachable("Unknown value kind!");
412     }
413     return IndirectCallSites;
414   }
415
416   std::vector<InstrProfValueSiteRecord> &
417   getValueSitesForKind(uint32_t ValueKind) {
418     return const_cast<std::vector<InstrProfValueSiteRecord> &>(
419         const_cast<const InstrProfRecord *>(this)
420             ->getValueSitesForKind(ValueKind));
421   }
422
423   // Map indirect call target name hash to name string.
424   uint64_t remapValue(uint64_t Value, uint32_t ValueKind,
425                       ValueMapType *HashKeys);
426
427   // Merge Value Profile data from Src record to this record for ValueKind.
428   // Scale merged value counts by \p Weight.
429   instrprof_error mergeValueProfData(uint32_t ValueKind, InstrProfRecord &Src,
430                                      uint64_t Weight);
431 };
432
433 uint32_t InstrProfRecord::getNumValueKinds() const {
434   uint32_t NumValueKinds = 0;
435   for (uint32_t Kind = IPVK_First; Kind <= IPVK_Last; ++Kind)
436     NumValueKinds += !(getValueSitesForKind(Kind).empty());
437   return NumValueKinds;
438 }
439
440 uint32_t InstrProfRecord::getNumValueData(uint32_t ValueKind) const {
441   uint32_t N = 0;
442   const std::vector<InstrProfValueSiteRecord> &SiteRecords =
443       getValueSitesForKind(ValueKind);
444   for (auto &SR : SiteRecords) {
445     N += SR.ValueData.size();
446   }
447   return N;
448 }
449
450 uint32_t InstrProfRecord::getNumValueSites(uint32_t ValueKind) const {
451   return getValueSitesForKind(ValueKind).size();
452 }
453
454 uint32_t InstrProfRecord::getNumValueDataForSite(uint32_t ValueKind,
455                                                  uint32_t Site) const {
456   return getValueSitesForKind(ValueKind)[Site].ValueData.size();
457 }
458
459 std::unique_ptr<InstrProfValueData[]> InstrProfRecord::getValueForSite(
460     uint32_t ValueKind, uint32_t Site,
461     uint64_t (*ValueMapper)(uint32_t, uint64_t)) const {
462   uint32_t N = getNumValueDataForSite(ValueKind, Site);
463   if (N == 0)
464     return std::unique_ptr<InstrProfValueData[]>(nullptr);
465
466   auto VD = llvm::make_unique<InstrProfValueData[]>(N);
467   getValueForSite(VD.get(), ValueKind, Site, ValueMapper);
468
469   return VD;
470 }
471
472 void InstrProfRecord::getValueForSite(InstrProfValueData Dest[],
473                                       uint32_t ValueKind, uint32_t Site,
474                                       uint64_t (*ValueMapper)(uint32_t,
475                                                               uint64_t)) const {
476   uint32_t I = 0;
477   for (auto V : getValueSitesForKind(ValueKind)[Site].ValueData) {
478     Dest[I].Value = ValueMapper ? ValueMapper(ValueKind, V.Value) : V.Value;
479     Dest[I].Count = V.Count;
480     I++;
481   }
482 }
483
484 void InstrProfRecord::reserveSites(uint32_t ValueKind, uint32_t NumValueSites) {
485   std::vector<InstrProfValueSiteRecord> &ValueSites =
486       getValueSitesForKind(ValueKind);
487   ValueSites.reserve(NumValueSites);
488 }
489
490 inline support::endianness getHostEndianness() {
491   return sys::IsLittleEndianHost ? support::little : support::big;
492 }
493
494 // Include definitions for value profile data
495 #define INSTR_PROF_VALUE_PROF_DATA
496 #include "llvm/ProfileData/InstrProfData.inc"
497
498  /*
499  * Initialize the record for runtime value profile data.
500  * Return 0 if the initialization is successful, otherwise
501  * return 1.
502  */
503 int initializeValueProfRuntimeRecord(ValueProfRuntimeRecord *RuntimeRecord,
504                                      const uint16_t *NumValueSites,
505                                      ValueProfNode **Nodes);
506
507 /* Release memory allocated for the runtime record.  */
508 void finalizeValueProfRuntimeRecord(ValueProfRuntimeRecord *RuntimeRecord);
509
510 /* Return the size of ValueProfData structure that can be used to store
511    the value profile data collected at runtime. */
512 uint32_t getValueProfDataSizeRT(const ValueProfRuntimeRecord *Record);
513
514 /* Return a ValueProfData instance that stores the data collected at runtime. */
515 ValueProfData *
516 serializeValueProfDataFromRT(const ValueProfRuntimeRecord *Record,
517                              ValueProfData *Dst);
518
519 namespace IndexedInstrProf {
520
521 enum class HashT : uint32_t {
522   MD5,
523
524   Last = MD5
525 };
526
527 static inline uint64_t MD5Hash(StringRef Str) {
528   MD5 Hash;
529   Hash.update(Str);
530   llvm::MD5::MD5Result Result;
531   Hash.final(Result);
532   // Return the least significant 8 bytes. Our MD5 implementation returns the
533   // result in little endian, so we may need to swap bytes.
534   using namespace llvm::support;
535   return endian::read<uint64_t, little, unaligned>(Result);
536 }
537
538 inline uint64_t ComputeHash(HashT Type, StringRef K) {
539   switch (Type) {
540   case HashT::MD5:
541     return IndexedInstrProf::MD5Hash(K);
542   }
543   llvm_unreachable("Unhandled hash type");
544 }
545
546 const uint64_t Magic = 0x8169666f72706cff; // "\xfflprofi\x81"
547 const uint64_t Version = INSTR_PROF_INDEX_VERSION;
548 const HashT HashType = HashT::MD5;
549
550 inline uint64_t ComputeHash(StringRef K) { return ComputeHash(HashType, K); }
551
552 // This structure defines the file header of the LLVM profile
553 // data file in indexed-format.
554 struct Header {
555   uint64_t Magic;
556   uint64_t Version;
557   uint64_t MaxFunctionCount;
558   uint64_t HashType;
559   uint64_t HashOffset;
560 };
561
562 } // end namespace IndexedInstrProf
563
564 namespace RawInstrProf {
565
566 const uint64_t Version = INSTR_PROF_RAW_VERSION;
567
568 template <class IntPtrT> inline uint64_t getMagic();
569 template <> inline uint64_t getMagic<uint64_t>() {
570   return INSTR_PROF_RAW_MAGIC_64;
571 }
572
573 template <> inline uint64_t getMagic<uint32_t>() {
574   return INSTR_PROF_RAW_MAGIC_32;
575 }
576
577 // Per-function profile data header/control structure.
578 // The definition should match the structure defined in
579 // compiler-rt/lib/profile/InstrProfiling.h.
580 // It should also match the synthesized type in
581 // Transforms/Instrumentation/InstrProfiling.cpp:getOrCreateRegionCounters.
582 template <class IntPtrT> struct LLVM_ALIGNAS(8) ProfileData {
583   #define INSTR_PROF_DATA(Type, LLVMType, Name, Init) Type Name;
584   #include "llvm/ProfileData/InstrProfData.inc"
585 };
586
587 // File header structure of the LLVM profile data in raw format.
588 // The definition should match the header referenced in
589 // compiler-rt/lib/profile/InstrProfilingFile.c  and
590 // InstrProfilingBuffer.c.
591 struct Header {
592 #define INSTR_PROF_RAW_HEADER(Type, Name, Init) const Type Name;
593 #include "llvm/ProfileData/InstrProfData.inc"
594 };
595
596 }  // end namespace RawInstrProf
597
598 namespace coverage {
599
600 // Profile coverage map has the following layout:
601 // [CoverageMapFileHeader]
602 // [ArrayStart]
603 //  [CovMapFunctionRecord]
604 //  [CovMapFunctionRecord]
605 //  ...
606 // [ArrayEnd]
607 // [Encoded Region Mapping Data]
608 LLVM_PACKED_START
609 template <class IntPtrT> struct CovMapFunctionRecord {
610   #define COVMAP_FUNC_RECORD(Type, LLVMType, Name, Init) Type Name;
611   #include "llvm/ProfileData/InstrProfData.inc"
612 };
613 LLVM_PACKED_END
614
615 }
616
617 } // end namespace llvm
618
619 namespace std {
620 template <>
621 struct is_error_code_enum<llvm::instrprof_error> : std::true_type {};
622 }
623
624 #endif // LLVM_PROFILEDATA_INSTRPROF_H_