LLVM  4.0.0
InstrProf.h
Go to the documentation of this file.
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/IR/Metadata.h"
26 #include "llvm/Support/Endian.h"
28 #include "llvm/Support/MD5.h"
30 #include <cstdint>
31 #include <list>
32 #include <system_error>
33 #include <vector>
34 
35 namespace llvm {
36 
37 class Function;
38 class GlobalVariable;
39 class Module;
40 
41 /// Return the name of data section containing profile counter variables.
42 inline StringRef getInstrProfCountersSectionName(bool AddSegment) {
43  return AddSegment ? "__DATA," INSTR_PROF_CNTS_SECT_NAME_STR
44  : INSTR_PROF_CNTS_SECT_NAME_STR;
45 }
46 
47 /// Return the name of data section containing names of instrumented
48 /// functions.
49 inline StringRef getInstrProfNameSectionName(bool AddSegment) {
50  return AddSegment ? "__DATA," INSTR_PROF_NAME_SECT_NAME_STR
51  : INSTR_PROF_NAME_SECT_NAME_STR;
52 }
53 
54 /// Return the name of the data section containing per-function control
55 /// data.
56 inline StringRef getInstrProfDataSectionName(bool AddSegment) {
57  return AddSegment ? "__DATA," INSTR_PROF_DATA_SECT_NAME_STR
58  ",regular,live_support"
59  : INSTR_PROF_DATA_SECT_NAME_STR;
60 }
61 
62 /// Return the name of data section containing pointers to value profile
63 /// counters/nodes.
64 inline StringRef getInstrProfValuesSectionName(bool AddSegment) {
65  return AddSegment ? "__DATA," INSTR_PROF_VALS_SECT_NAME_STR
66  : INSTR_PROF_VALS_SECT_NAME_STR;
67 }
68 
69 /// Return the name of data section containing nodes holdling value
70 /// profiling data.
71 inline StringRef getInstrProfVNodesSectionName(bool AddSegment) {
72  return AddSegment ? "__DATA," INSTR_PROF_VNODES_SECT_NAME_STR
73  : INSTR_PROF_VNODES_SECT_NAME_STR;
74 }
75 
76 /// Return the name profile runtime entry point to do value profiling
77 /// for a given site.
79  return INSTR_PROF_VALUE_PROF_FUNC_STR;
80 }
81 
82 /// Return the name of the section containing function coverage mapping
83 /// data.
84 inline StringRef getInstrProfCoverageSectionName(bool AddSegment) {
85  return AddSegment ? "__LLVM_COV," INSTR_PROF_COVMAP_SECT_NAME_STR
86  : INSTR_PROF_COVMAP_SECT_NAME_STR;
87 }
88 
89 /// Return the name prefix of variables containing instrumented function names.
90 inline StringRef getInstrProfNameVarPrefix() { return "__profn_"; }
91 
92 /// Return the name prefix of variables containing per-function control data.
93 inline StringRef getInstrProfDataVarPrefix() { return "__profd_"; }
94 
95 /// Return the name prefix of profile counter variables.
96 inline StringRef getInstrProfCountersVarPrefix() { return "__profc_"; }
97 
98 /// Return the name prefix of value profile variables.
99 inline StringRef getInstrProfValuesVarPrefix() { return "__profvp_"; }
100 
101 /// Return the name of value profile node array variables:
102 inline StringRef getInstrProfVNodesVarName() { return "__llvm_prf_vnodes"; }
103 
104 /// Return the name prefix of the COMDAT group for instrumentation variables
105 /// associated with a COMDAT function.
106 inline StringRef getInstrProfComdatPrefix() { return "__profv_"; }
107 
108 /// Return the name of the variable holding the strings (possibly compressed)
109 /// of all function's PGO names.
111  return "__llvm_prf_nm";
112 }
113 
114 /// Return the name of a covarage mapping variable (internal linkage)
115 /// for each instrumented source module. Such variables are allocated
116 /// in the __llvm_covmap section.
118  return "__llvm_coverage_mapping";
119 }
120 
121 /// Return the name of the internal variable recording the array
122 /// of PGO name vars referenced by the coverage mapping. The owning
123 /// functions of those names are not emitted by FE (e.g, unused inline
124 /// functions.)
126  return "__llvm_coverage_names";
127 }
128 
129 /// Return the name of function that registers all the per-function control
130 /// data at program startup time by calling __llvm_register_function. This
131 /// function has internal linkage and is called by __llvm_profile_init
132 /// runtime method. This function is not generated for these platforms:
133 /// Darwin, Linux, and FreeBSD.
135  return "__llvm_profile_register_functions";
136 }
137 
138 /// Return the name of the runtime interface that registers per-function control
139 /// data for one instrumented function.
141  return "__llvm_profile_register_function";
142 }
143 
144 /// Return the name of the runtime interface that registers the PGO name strings.
146  return "__llvm_profile_register_names_function";
147 }
148 
149 /// Return the name of the runtime initialization method that is generated by
150 /// the compiler. The function calls __llvm_profile_register_functions and
151 /// __llvm_profile_override_default_filename functions if needed. This function
152 /// has internal linkage and invoked at startup time via init_array.
153 inline StringRef getInstrProfInitFuncName() { return "__llvm_profile_init"; }
154 
155 /// Return the name of the hook variable defined in profile runtime library.
156 /// A reference to the variable causes the linker to link in the runtime
157 /// initialization module (which defines the hook variable).
159  return INSTR_PROF_QUOTE(INSTR_PROF_PROFILE_RUNTIME_VAR);
160 }
161 
162 /// Return the name of the compiler generated function that references the
163 /// runtime hook variable. The function is a weak global.
165  return "__llvm_profile_runtime_user";
166 }
167 
168 /// Return the marker used to separate PGO names during serialization.
169 inline StringRef getInstrProfNameSeparator() { return "\01"; }
170 
171 /// Return the modified name for function \c F suitable to be
172 /// used the key for profile lookup. Variable \c InLTO indicates if this
173 /// is called in LTO optimization passes.
174 std::string getPGOFuncName(const Function &F, bool InLTO = false,
175  uint64_t Version = INSTR_PROF_INDEX_VERSION);
176 
177 /// Return the modified name for a function suitable to be
178 /// used the key for profile lookup. The function's original
179 /// name is \c RawFuncName and has linkage of type \c Linkage.
180 /// The function is defined in module \c FileName.
181 std::string getPGOFuncName(StringRef RawFuncName,
183  StringRef FileName,
184  uint64_t Version = INSTR_PROF_INDEX_VERSION);
185 
186 /// Return the name of the global variable used to store a function
187 /// name in PGO instrumentation. \c FuncName is the name of the function
188 /// returned by the \c getPGOFuncName call.
189 std::string getPGOFuncNameVarName(StringRef FuncName,
190  GlobalValue::LinkageTypes Linkage);
191 
192 /// Create and return the global variable for function name used in PGO
193 /// instrumentation. \c FuncName is the name of the function returned
194 /// by \c getPGOFuncName call.
195 GlobalVariable *createPGOFuncNameVar(Function &F, StringRef PGOFuncName);
196 
197 /// Create and return the global variable for function name used in PGO
198 /// instrumentation. /// \c FuncName is the name of the function
199 /// returned by \c getPGOFuncName call, \c M is the owning module,
200 /// and \c Linkage is the linkage of the instrumented function.
201 GlobalVariable *createPGOFuncNameVar(Module &M,
203  StringRef PGOFuncName);
204 /// Return the initializer in string of the PGO name var \c NameVar.
205 StringRef getPGOFuncNameVarInitializer(GlobalVariable *NameVar);
206 
207 /// Given a PGO function name, remove the filename prefix and return
208 /// the original (static) function name.
209 StringRef getFuncNameWithoutPrefix(StringRef PGOFuncName,
210  StringRef FileName = "<unknown>");
211 
212 /// Given a vector of strings (function PGO names) \c NameStrs, the
213 /// method generates a combined string \c Result thatis ready to be
214 /// serialized. The \c Result string is comprised of three fields:
215 /// The first field is the legnth of the uncompressed strings, and the
216 /// the second field is the length of the zlib-compressed string.
217 /// Both fields are encoded in ULEB128. If \c doCompress is false, the
218 /// third field is the uncompressed strings; otherwise it is the
219 /// compressed string. When the string compression is off, the
220 /// second field will have value zero.
221 Error collectPGOFuncNameStrings(const std::vector<std::string> &NameStrs,
222  bool doCompression, std::string &Result);
223 /// Produce \c Result string with the same format described above. The input
224 /// is vector of PGO function name variables that are referenced.
225 Error collectPGOFuncNameStrings(const std::vector<GlobalVariable *> &NameVars,
226  std::string &Result, bool doCompression = true);
227 class InstrProfSymtab;
228 /// \c NameStrings is a string composed of one of more sub-strings encoded in
229 /// the format described above. The substrings are separated by 0 or more zero
230 /// bytes. This method decodes the string and populates the \c Symtab.
231 Error readPGOFuncNameStrings(StringRef NameStrings, InstrProfSymtab &Symtab);
232 
233 /// Check if INSTR_PROF_RAW_VERSION_VAR is defined. This global is only being
234 /// set in IR PGO compilation.
235 bool isIRPGOFlagSet(const Module *M);
236 
237 /// Check if we can safely rename this Comdat function. Instances of the same
238 /// comdat function may have different control flows thus can not share the
239 /// same counter variable.
240 bool canRenameComdatFunc(const Function &F, bool CheckAddressTaken = false);
241 
243 #define VALUE_PROF_KIND(Enumerator, Value) Enumerator = Value,
245 };
246 
247 struct InstrProfRecord;
248 
249 /// Get the value profile data for value site \p SiteIdx from \p InstrProfR
250 /// and annotate the instruction \p Inst with the value profile meta data.
251 /// Annotate up to \p MaxMDCount (default 3) number of records per value site.
252 void annotateValueSite(Module &M, Instruction &Inst,
253  const InstrProfRecord &InstrProfR,
254  InstrProfValueKind ValueKind, uint32_t SiteIndx,
255  uint32_t MaxMDCount = 3);
256 /// Same as the above interface but using an ArrayRef, as well as \p Sum.
257 void annotateValueSite(Module &M, Instruction &Inst,
258  ArrayRef<InstrProfValueData> VDs,
259  uint64_t Sum, InstrProfValueKind ValueKind,
260  uint32_t MaxMDCount);
261 
262 /// Extract the value profile data from \p Inst which is annotated with
263 /// value profile meta data. Return false if there is no value data annotated,
264 /// otherwise return true.
265 bool getValueProfDataFromInst(const Instruction &Inst,
266  InstrProfValueKind ValueKind,
267  uint32_t MaxNumValueData,
268  InstrProfValueData ValueData[],
269  uint32_t &ActualNumValueData, uint64_t &TotalC);
270 
271 inline StringRef getPGOFuncNameMetadataName() { return "PGOFuncName"; }
272 
273 /// Return the PGOFuncName meta data associated with a function.
274 MDNode *getPGOFuncNameMetadata(const Function &F);
275 
276 /// Create the PGOFuncName meta data if PGOFuncName is different from
277 /// function's raw name. This should only apply to internal linkage functions
278 /// declared by users only.
279 void createPGOFuncNameMetadata(Function &F, StringRef PGOFuncName);
280 
281 /// Check if we can use Comdat for profile variables. This will eliminate
282 /// the duplicated profile variables for Comdat functions.
283 bool needsComdatForCounter(const Function &F, const Module &M);
284 
286 
287 enum class instrprof_error {
288  success = 0,
289  eof,
291  bad_magic,
292  bad_header,
295  too_large,
296  truncated,
297  malformed,
306 };
307 
308 inline std::error_code make_error_code(instrprof_error E) {
309  return std::error_code(static_cast<int>(E), instrprof_category());
310 }
311 
312 class InstrProfError : public ErrorInfo<InstrProfError> {
313 public:
314  InstrProfError(instrprof_error Err) : Err(Err) {
315  assert(Err != instrprof_error::success && "Not an error");
316  }
317 
318  std::string message() const override;
319 
320  void log(raw_ostream &OS) const override { OS << message(); }
321 
322  std::error_code convertToErrorCode() const override {
323  return make_error_code(Err);
324  }
325 
326  instrprof_error get() const { return Err; }
327 
328  /// Consume an Error and return the raw enum value contained within it. The
329  /// Error must either be a success value, or contain a single InstrProfError.
331  auto Err = instrprof_error::success;
332  handleAllErrors(std::move(E), [&Err](const InstrProfError &IPE) {
333  assert(Err == instrprof_error::success && "Multiple errors encountered");
334  Err = IPE.get();
335  });
336  return Err;
337  }
338 
339  static char ID;
340 
341 private:
342  instrprof_error Err;
343 };
344 
346  /// Count the number of soft instrprof_errors encountered and keep track of
347  /// the first such error for reporting purposes.
348 
349  /// The first soft error encountered.
350  instrprof_error FirstError;
351 
352  /// The number of hash mismatches.
353  unsigned NumHashMismatches;
354 
355  /// The number of count mismatches.
356  unsigned NumCountMismatches;
357 
358  /// The number of counter overflows.
359  unsigned NumCounterOverflows;
360 
361  /// The number of value site count mismatches.
362  unsigned NumValueSiteCountMismatches;
363 
364 public:
366  : FirstError(instrprof_error::success), NumHashMismatches(0),
367  NumCountMismatches(0), NumCounterOverflows(0),
368  NumValueSiteCountMismatches(0) {}
369 
371  assert(FirstError == instrprof_error::success &&
372  "Unchecked soft error encountered");
373  }
374 
375  /// Track a soft error (\p IE) and increment its associated counter.
377 
378  /// Get the number of hash mismatches.
379  unsigned getNumHashMismatches() const { return NumHashMismatches; }
380 
381  /// Get the number of count mismatches.
382  unsigned getNumCountMismatches() const { return NumCountMismatches; }
383 
384  /// Get the number of counter overflows.
385  unsigned getNumCounterOverflows() const { return NumCounterOverflows; }
386 
387  /// Get the number of value site count mismatches.
389  return NumValueSiteCountMismatches;
390  }
391 
392  /// Return the first encountered error and reset FirstError to a success
393  /// value.
395  if (FirstError == instrprof_error::success)
396  return Error::success();
397  auto E = make_error<InstrProfError>(FirstError);
398  FirstError = instrprof_error::success;
399  return E;
400  }
401 };
402 
403 namespace object {
404 class SectionRef;
405 }
406 
407 namespace IndexedInstrProf {
408 uint64_t ComputeHash(StringRef K);
409 }
410 
411 /// A symbol table used for function PGO name look-up with keys
412 /// (such as pointers, md5hash values) to the function. A function's
413 /// PGO name or name's md5hash are used in retrieving the profile
414 /// data of the function. See \c getPGOFuncName() method for details
415 /// on how PGO name is formed.
417 public:
418  typedef std::vector<std::pair<uint64_t, uint64_t>> AddrHashMap;
419 
420 private:
421  StringRef Data;
422  uint64_t Address;
423  // Unique name strings.
424  StringSet<> NameTab;
425  // A map from MD5 keys to function name strings.
426  std::vector<std::pair<uint64_t, StringRef>> MD5NameMap;
427  // A map from MD5 keys to function define. We only populate this map
428  // when build the Symtab from a Module.
429  std::vector<std::pair<uint64_t, Function *>> MD5FuncMap;
430  // A map from function runtime address to function name MD5 hash.
431  // This map is only populated and used by raw instr profile reader.
432  AddrHashMap AddrToMD5Map;
433 
434 public:
436  : Data(), Address(0), NameTab(), MD5NameMap(), MD5FuncMap(),
437  AddrToMD5Map() {}
438 
439  /// Create InstrProfSymtab from an object file section which
440  /// contains function PGO names. When section may contain raw
441  /// string data or string data in compressed form. This method
442  /// only initialize the symtab with reference to the data and
443  /// the section base address. The decompression will be delayed
444  /// until before it is used. See also \c create(StringRef) method.
446  /// This interface is used by reader of CoverageMapping test
447  /// format.
448  inline Error create(StringRef D, uint64_t BaseAddr);
449  /// \c NameStrings is a string composed of one of more sub-strings
450  /// encoded in the format described in \c collectPGOFuncNameStrings.
451  /// This method is a wrapper to \c readPGOFuncNameStrings method.
452  inline Error create(StringRef NameStrings);
453  /// A wrapper interface to populate the PGO symtab with functions
454  /// decls from module \c M. This interface is used by transformation
455  /// passes such as indirect function call promotion. Variable \c InLTO
456  /// indicates if this is called from LTO optimization passes.
457  void create(Module &M, bool InLTO = false);
458  /// Create InstrProfSymtab from a set of names iteratable from
459  /// \p IterRange. This interface is used by IndexedProfReader.
460  template <typename NameIterRange> void create(const NameIterRange &IterRange);
461  // If the symtab is created by a series of calls to \c addFuncName, \c
462  // finalizeSymtab needs to be called before looking up function names.
463  // This is required because the underlying map is a vector (for space
464  // efficiency) which needs to be sorted.
465  inline void finalizeSymtab();
466  /// Update the symtab by adding \p FuncName to the table. This interface
467  /// is used by the raw and text profile readers.
468  void addFuncName(StringRef FuncName) {
469  auto Ins = NameTab.insert(FuncName);
470  if (Ins.second)
471  MD5NameMap.push_back(std::make_pair(
472  IndexedInstrProf::ComputeHash(FuncName), Ins.first->getKey()));
473  }
474  /// Map a function address to its name's MD5 hash. This interface
475  /// is only used by the raw profiler reader.
476  void mapAddress(uint64_t Addr, uint64_t MD5Val) {
477  AddrToMD5Map.push_back(std::make_pair(Addr, MD5Val));
478  }
479  AddrHashMap &getAddrHashMap() { return AddrToMD5Map; }
480  /// Return function's PGO name from the function name's symbol
481  /// address in the object file. If an error occurs, return
482  /// an empty string.
483  StringRef getFuncName(uint64_t FuncNameAddress, size_t NameSize);
484  /// Return function's PGO name from the name's md5 hash value.
485  /// If not found, return an empty string.
486  inline StringRef getFuncName(uint64_t FuncMD5Hash);
487  /// Return function from the name's md5 hash. Return nullptr if not found.
488  inline Function *getFunction(uint64_t FuncMD5Hash);
489  /// Return the function's original assembly name by stripping off
490  /// the prefix attached (to symbols with priviate linkage). For
491  /// global functions, it returns the same string as getFuncName.
492  inline StringRef getOrigFuncName(uint64_t FuncMD5Hash);
493  /// Return the name section data.
494  inline StringRef getNameData() const { return Data; }
495 };
496 
498  Data = D;
499  Address = BaseAddr;
500  return Error::success();
501 }
502 
504  return readPGOFuncNameStrings(NameStrings, *this);
505 }
506 
507 template <typename NameIterRange>
508 void InstrProfSymtab::create(const NameIterRange &IterRange) {
509  for (auto Name : IterRange)
510  addFuncName(Name);
511 
512  finalizeSymtab();
513 }
514 
516  std::sort(MD5NameMap.begin(), MD5NameMap.end(), less_first());
517  std::sort(MD5FuncMap.begin(), MD5FuncMap.end(), less_first());
518  std::sort(AddrToMD5Map.begin(), AddrToMD5Map.end(), less_first());
519  AddrToMD5Map.erase(std::unique(AddrToMD5Map.begin(), AddrToMD5Map.end()),
520  AddrToMD5Map.end());
521 }
522 
524  auto Result =
525  std::lower_bound(MD5NameMap.begin(), MD5NameMap.end(), FuncMD5Hash,
526  [](const std::pair<uint64_t, std::string> &LHS,
527  uint64_t RHS) { return LHS.first < RHS; });
528  if (Result != MD5NameMap.end() && Result->first == FuncMD5Hash)
529  return Result->second;
530  return StringRef();
531 }
532 
533 Function* InstrProfSymtab::getFunction(uint64_t FuncMD5Hash) {
534  auto Result =
535  std::lower_bound(MD5FuncMap.begin(), MD5FuncMap.end(), FuncMD5Hash,
536  [](const std::pair<uint64_t, Function*> &LHS,
537  uint64_t RHS) { return LHS.first < RHS; });
538  if (Result != MD5FuncMap.end() && Result->first == FuncMD5Hash)
539  return Result->second;
540  return nullptr;
541 }
542 
543 // See also getPGOFuncName implementation. These two need to be
544 // matched.
546  StringRef PGOName = getFuncName(FuncMD5Hash);
547  size_t S = PGOName.find_first_of(':');
548  if (S == StringRef::npos)
549  return PGOName;
550  return PGOName.drop_front(S + 1);
551 }
552 
554  /// Value profiling data pairs at a given value site.
555  std::list<InstrProfValueData> ValueData;
556 
558  template <class InputIterator>
559  InstrProfValueSiteRecord(InputIterator F, InputIterator L)
560  : ValueData(F, L) {}
561 
562  /// Sort ValueData ascending by Value
564  ValueData.sort(
565  [](const InstrProfValueData &left, const InstrProfValueData &right) {
566  return left.Value < right.Value;
567  });
568  }
569  /// Sort ValueData Descending by Count
570  inline void sortByCount();
571 
572  /// Merge data from another InstrProfValueSiteRecord
573  /// Optionally scale merged counts by \p Weight.
575  uint64_t Weight = 1);
576  /// Scale up value profile data counts.
577  void scale(SoftInstrProfErrors &SIPE, uint64_t Weight);
578 };
579 
580 /// Profiling information for a single function.
583  InstrProfRecord(StringRef Name, uint64_t Hash, std::vector<uint64_t> Counts)
584  : Name(Name), Hash(Hash), Counts(std::move(Counts)), SIPE() {}
586  uint64_t Hash;
587  std::vector<uint64_t> Counts;
589 
590  typedef std::vector<std::pair<uint64_t, uint64_t>> ValueMapType;
591 
592  /// Return the number of value profile kinds with non-zero number
593  /// of profile sites.
594  inline uint32_t getNumValueKinds() const;
595  /// Return the number of instrumented sites for ValueKind.
596  inline uint32_t getNumValueSites(uint32_t ValueKind) const;
597  /// Return the total number of ValueData for ValueKind.
598  inline uint32_t getNumValueData(uint32_t ValueKind) const;
599  /// Return the number of value data collected for ValueKind at profiling
600  /// site: Site.
601  inline uint32_t getNumValueDataForSite(uint32_t ValueKind,
602  uint32_t Site) const;
603  /// Return the array of profiled values at \p Site. If \p TotalC
604  /// is not null, the total count of all target values at this site
605  /// will be stored in \c *TotalC.
606  inline std::unique_ptr<InstrProfValueData[]>
607  getValueForSite(uint32_t ValueKind, uint32_t Site,
608  uint64_t *TotalC = 0) const;
609  /// Get the target value/counts of kind \p ValueKind collected at site
610  /// \p Site and store the result in array \p Dest. Return the total
611  /// counts of all target values at this site.
612  inline uint64_t getValueForSite(InstrProfValueData Dest[], uint32_t ValueKind,
613  uint32_t Site) const;
614  /// Reserve space for NumValueSites sites.
615  inline void reserveSites(uint32_t ValueKind, uint32_t NumValueSites);
616  /// Add ValueData for ValueKind at value Site.
617  void addValueData(uint32_t ValueKind, uint32_t Site,
618  InstrProfValueData *VData, uint32_t N,
620 
621  /// Merge the counts in \p Other into this one.
622  /// Optionally scale merged counts by \p Weight.
623  void merge(InstrProfRecord &Other, uint64_t Weight = 1);
624 
625  /// Scale up profile counts (including value profile data) by
626  /// \p Weight.
627  void scale(uint64_t Weight);
628 
629  /// Sort value profile data (per site) by count.
630  void sortValueData() {
631  for (uint32_t Kind = IPVK_First; Kind <= IPVK_Last; ++Kind) {
632  std::vector<InstrProfValueSiteRecord> &SiteRecords =
633  getValueSitesForKind(Kind);
634  for (auto &SR : SiteRecords)
635  SR.sortByCount();
636  }
637  }
638  /// Clear value data entries
639  void clearValueData() {
640  for (uint32_t Kind = IPVK_First; Kind <= IPVK_Last; ++Kind)
641  getValueSitesForKind(Kind).clear();
642  }
643 
644  /// Get the error contained within the record's soft error counter.
645  Error takeError() { return SIPE.takeError(); }
646 
647 private:
648  std::vector<InstrProfValueSiteRecord> IndirectCallSites;
649  const std::vector<InstrProfValueSiteRecord> &
650  getValueSitesForKind(uint32_t ValueKind) const {
651  switch (ValueKind) {
652  case IPVK_IndirectCallTarget:
653  return IndirectCallSites;
654  default:
655  llvm_unreachable("Unknown value kind!");
656  }
657  return IndirectCallSites;
658  }
659 
660  std::vector<InstrProfValueSiteRecord> &
661  getValueSitesForKind(uint32_t ValueKind) {
662  return const_cast<std::vector<InstrProfValueSiteRecord> &>(
663  const_cast<const InstrProfRecord *>(this)
664  ->getValueSitesForKind(ValueKind));
665  }
666 
667  // Map indirect call target name hash to name string.
668  uint64_t remapValue(uint64_t Value, uint32_t ValueKind,
669  ValueMapType *HashKeys);
670 
671  // Merge Value Profile data from Src record to this record for ValueKind.
672  // Scale merged value counts by \p Weight.
673  void mergeValueProfData(uint32_t ValueKind, InstrProfRecord &Src,
674  uint64_t Weight);
675  // Scale up value profile data count.
676  void scaleValueProfData(uint32_t ValueKind, uint64_t Weight);
677 };
678 
680  uint32_t NumValueKinds = 0;
681  for (uint32_t Kind = IPVK_First; Kind <= IPVK_Last; ++Kind)
682  NumValueKinds += !(getValueSitesForKind(Kind).empty());
683  return NumValueKinds;
684 }
685 
687  uint32_t N = 0;
688  const std::vector<InstrProfValueSiteRecord> &SiteRecords =
689  getValueSitesForKind(ValueKind);
690  for (auto &SR : SiteRecords) {
691  N += SR.ValueData.size();
692  }
693  return N;
694 }
695 
697  return getValueSitesForKind(ValueKind).size();
698 }
699 
701  uint32_t Site) const {
702  return getValueSitesForKind(ValueKind)[Site].ValueData.size();
703 }
704 
705 std::unique_ptr<InstrProfValueData[]>
707  uint64_t *TotalC) const {
708  uint64_t Dummy;
709  uint64_t &TotalCount = (TotalC == 0 ? Dummy : *TotalC);
710  uint32_t N = getNumValueDataForSite(ValueKind, Site);
711  if (N == 0) {
712  TotalCount = 0;
713  return std::unique_ptr<InstrProfValueData[]>(nullptr);
714  }
715 
716  auto VD = llvm::make_unique<InstrProfValueData[]>(N);
717  TotalCount = getValueForSite(VD.get(), ValueKind, Site);
718 
719  return VD;
720 }
721 
722 uint64_t InstrProfRecord::getValueForSite(InstrProfValueData Dest[],
723  uint32_t ValueKind,
724  uint32_t Site) const {
725  uint32_t I = 0;
726  uint64_t TotalCount = 0;
727  for (auto V : getValueSitesForKind(ValueKind)[Site].ValueData) {
728  Dest[I].Value = V.Value;
729  Dest[I].Count = V.Count;
730  TotalCount = SaturatingAdd(TotalCount, V.Count);
731  I++;
732  }
733  return TotalCount;
734 }
735 
736 void InstrProfRecord::reserveSites(uint32_t ValueKind, uint32_t NumValueSites) {
737  std::vector<InstrProfValueSiteRecord> &ValueSites =
738  getValueSitesForKind(ValueKind);
739  ValueSites.reserve(NumValueSites);
740 }
741 
744 }
745 
746 // Include definitions for value profile data
747 #define INSTR_PROF_VALUE_PROF_DATA
749 
751  ValueData.sort(
752  [](const InstrProfValueData &left, const InstrProfValueData &right) {
753  return left.Count > right.Count;
754  });
755  // Now truncate
756  size_t max_s = INSTR_PROF_MAX_NUM_VAL_PER_SITE;
757  if (ValueData.size() > max_s)
758  ValueData.resize(max_s);
759 }
760 
761 namespace IndexedInstrProf {
762 
763 enum class HashT : uint32_t {
764  MD5,
765 
766  Last = MD5
767 };
768 
769 inline uint64_t ComputeHash(HashT Type, StringRef K) {
770  switch (Type) {
771  case HashT::MD5:
772  return MD5Hash(K);
773  }
774  llvm_unreachable("Unhandled hash type");
775 }
776 
777 const uint64_t Magic = 0x8169666f72706cff; // "\xfflprofi\x81"
778 
780  // Version 1 is the first version. In this version, the value of
781  // a key/value pair can only include profile data of a single function.
782  // Due to this restriction, the number of block counters for a given
783  // function is not recorded but derived from the length of the value.
784  Version1 = 1,
785  // The version 2 format supports recording profile data of multiple
786  // functions which share the same key in one value field. To support this,
787  // the number block counters is recorded as an uint64_t field right after the
788  // function structural hash.
789  Version2 = 2,
790  // Version 3 supports value profile data. The value profile data is expected
791  // to follow the block counter profile data.
792  Version3 = 3,
793  // In this version, profile summary data \c IndexedInstrProf::Summary is
794  // stored after the profile header.
795  Version4 = 4,
796  // The current version is 4.
797  CurrentVersion = INSTR_PROF_INDEX_VERSION
798 };
800 
802 
803 inline uint64_t ComputeHash(StringRef K) { return ComputeHash(HashType, K); }
804 
805 // This structure defines the file header of the LLVM profile
806 // data file in indexed-format.
807 struct Header {
808  uint64_t Magic;
809  uint64_t Version;
810  uint64_t Unused; // Becomes unused since version 4
811  uint64_t HashType;
812  uint64_t HashOffset;
813 };
814 
815 // Profile summary data recorded in the profile data file in indexed
816 // format. It is introduced in version 4. The summary data follows
817 // right after the profile file header.
818 struct Summary {
819 
820  struct Entry {
821  uint64_t Cutoff; ///< The required percentile of total execution count.
822  uint64_t
823  MinBlockCount; ///< The minimum execution count for this percentile.
824  uint64_t NumBlocks; ///< Number of blocks >= the minumum execution count.
825  };
826  // The field kind enumerator to assigned value mapping should remain
827  // unchanged when a new kind is added or an old kind gets deleted in
828  // the future.
830  /// The total number of functions instrumented.
832  /// Total number of instrumented blocks/edges.
834  /// The maximal execution count among all functions.
835  /// This field does not exist for profile data from IR based
836  /// instrumentation.
838  /// Max block count of the program.
840  /// Max internal block count of the program (excluding entry blocks).
842  /// The sum of all instrumented block counts.
845  };
846 
847  // The number of summmary fields following the summary header.
849  // The number of Cutoff Entries (Summary::Entry) following summary fields.
851 
853  return sizeof(Summary) + NumCutoffEntries * sizeof(Entry) +
854  NumSumFields * sizeof(uint64_t);
855  }
856 
857  const uint64_t *getSummaryDataBase() const {
858  return reinterpret_cast<const uint64_t *>(this + 1);
859  }
860  uint64_t *getSummaryDataBase() {
861  return reinterpret_cast<uint64_t *>(this + 1);
862  }
863  const Entry *getCutoffEntryBase() const {
864  return reinterpret_cast<const Entry *>(
866  }
868  return reinterpret_cast<Entry *>(&getSummaryDataBase()[NumSummaryFields]);
869  }
870 
871  uint64_t get(SummaryFieldKind K) const {
872  return getSummaryDataBase()[K];
873  }
874 
875  void set(SummaryFieldKind K, uint64_t V) {
876  getSummaryDataBase()[K] = V;
877  }
878 
879  const Entry &getEntry(uint32_t I) const { return getCutoffEntryBase()[I]; }
881  Entry &ER = getCutoffEntryBase()[I];
882  ER.Cutoff = E.Cutoff;
883  ER.MinBlockCount = E.MinCount;
884  ER.NumBlocks = E.NumCounts;
885  }
886 
887  Summary(uint32_t Size) { memset(this, 0, Size); }
888  void operator delete(void *ptr) { ::operator delete(ptr); }
889 
890  Summary() = delete;
891 };
892 
893 inline std::unique_ptr<Summary> allocSummary(uint32_t TotalSize) {
894  return std::unique_ptr<Summary>(new (::operator new(TotalSize))
895  Summary(TotalSize));
896 }
897 } // end namespace IndexedInstrProf
898 
899 namespace RawInstrProf {
900 
901 // Version 1: First version
902 // Version 2: Added value profile data section. Per-function control data
903 // struct has more fields to describe value profile information.
904 // Version 3: Compressed name section support. Function PGO name reference
905 // from control data struct is changed from raw pointer to Name's MD5 value.
906 // Version 4: ValueDataBegin and ValueDataSizes fields are removed from the
907 // raw header.
908 const uint64_t Version = INSTR_PROF_RAW_VERSION;
909 
910 template <class IntPtrT> inline uint64_t getMagic();
911 template <> inline uint64_t getMagic<uint64_t>() {
912  return INSTR_PROF_RAW_MAGIC_64;
913 }
914 
915 template <> inline uint64_t getMagic<uint32_t>() {
916  return INSTR_PROF_RAW_MAGIC_32;
917 }
918 
919 // Per-function profile data header/control structure.
920 // The definition should match the structure defined in
921 // compiler-rt/lib/profile/InstrProfiling.h.
922 // It should also match the synthesized type in
923 // Transforms/Instrumentation/InstrProfiling.cpp:getOrCreateRegionCounters.
924 template <class IntPtrT> struct LLVM_ALIGNAS(8) ProfileData {
925  #define INSTR_PROF_DATA(Type, LLVMType, Name, Init) Type Name;
927 };
928 
929 // File header structure of the LLVM profile data in raw format.
930 // The definition should match the header referenced in
931 // compiler-rt/lib/profile/InstrProfilingFile.c and
932 // InstrProfilingBuffer.c.
933 struct Header {
934 #define INSTR_PROF_RAW_HEADER(Type, Name, Init) const Type Name;
936 };
937 
938 } // end namespace RawInstrProf
939 
940 } // end namespace llvm
941 
942 #endif // LLVM_PROFILEDATA_INSTRPROF_H
MachineLoop * L
void scale(uint64_t Weight)
Scale up profile counts (including value profile data) by Weight.
Definition: InstrProf.cpp:422
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
Definition: StringRef.h:634
void log(raw_ostream &OS) const override
Print an error message to an output stream.
Definition: InstrProf.h:320
StringRef getInstrProfRuntimeHookVarUseFuncName()
Return the name of the compiler generated function that references the runtime hook variable...
Definition: InstrProf.h:164
unsigned getNumCountMismatches() const
Get the number of count mismatches.
Definition: InstrProf.h:382
A symbol table used for function PGO name look-up with keys (such as pointers, md5hash values) to the...
Definition: InstrProf.h:416
static uint32_t getSize(uint32_t NumSumFields, uint32_t NumCutoffEntries)
Definition: InstrProf.h:852
void sortByCount()
Sort ValueData Descending by Count.
Definition: InstrProf.h:750
uint32_t Cutoff
The required percentile of counts.
StringRef getInstrProfNameVarPrefix()
Return the name prefix of variables containing instrumented function names.
Definition: InstrProf.h:90
uint64_t getMagic()
void sortValueData()
Sort value profile data (per site) by count.
Definition: InstrProf.h:630
SoftInstrProfErrors SIPE
Definition: InstrProf.h:588
uint64_t MinBlockCount
The minimum execution count for this percentile.
Definition: InstrProf.h:823
StringRef getOrigFuncName(uint64_t FuncMD5Hash)
Return the function's original assembly name by stripping off the prefix attached (to symbols with pr...
Definition: InstrProf.h:545
StringRef getInstrProfRegFuncsName()
Return the name of function that registers all the per-function control data at program startup time ...
Definition: InstrProf.h:134
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:52
uint32_t getNumValueData(uint32_t ValueKind) const
Return the total number of ValueData for ValueKind.
Definition: InstrProf.h:686
const Entry & getEntry(uint32_t I) const
Definition: InstrProf.h:879
void setEntry(uint32_t I, const ProfileSummaryEntry &E)
Definition: InstrProf.h:880
static instrprof_error take(Error E)
Consume an Error and return the raw enum value contained within it.
Definition: InstrProf.h:330
bool canRenameComdatFunc(const Function &F, bool CheckAddressTaken=false)
Check if we can safely rename this Comdat function.
Definition: InstrProf.cpp:836
This file contains the declarations for metadata subclasses.
MDNode * getPGOFuncNameMetadata(const Function &F)
Return the PGOFuncName meta data associated with a function.
Definition: InstrProf.cpp:773
uint64_t MD5Hash(StringRef Str)
Helper to compute and return lower 64 bits of the given string's MD5 hash.
Definition: MD5.h:74
Function * getFunction(uint64_t FuncMD5Hash)
Return function from the name's md5 hash. Return nullptr if not found.
Definition: InstrProf.h:533
uint64_t getMagic< uint64_t >()
Definition: InstrProf.h:911
Max block count of the program.
Definition: InstrProf.h:839
AddrHashMap & getAddrHashMap()
Definition: InstrProf.h:479
std::unique_ptr< Summary > allocSummary(uint32_t TotalSize)
Definition: InstrProf.h:893
StringRef getInstrProfValuesVarPrefix()
Return the name prefix of value profile variables.
Definition: InstrProf.h:99
void reserveSites(uint32_t ValueKind, uint32_t NumValueSites)
Reserve space for NumValueSites sites.
Definition: InstrProf.h:736
std::enable_if< std::is_unsigned< T >::value, T >::type SaturatingAdd(T X, T Y, bool *ResultOverflowed=nullptr)
Add two unsigned integers, X and Y, of type T.
Definition: MathExtras.h:750
StringRef getInstrProfDataSectionName(bool AddSegment)
Return the name of the data section containing per-function control data.
Definition: InstrProf.h:56
const uint64_t Magic
Definition: InstrProf.h:777
Error create(object::SectionRef &Section)
Create InstrProfSymtab from an object file section which contains function PGO names.
Error takeError()
Get the error contained within the record's soft error counter.
Definition: InstrProf.h:645
StringRef getInstrProfInitFuncName()
Return the name of the runtime initialization method that is generated by the compiler.
Definition: InstrProf.h:153
InstrProfRecord(StringRef Name, uint64_t Hash, std::vector< uint64_t > Counts)
Definition: InstrProf.h:583
const HashT HashType
Definition: InstrProf.h:801
StringRef getInstrProfDataVarPrefix()
Return the name prefix of variables containing per-function control data.
Definition: InstrProf.h:93
const std::error_category & instrprof_category()
Definition: InstrProf.cpp:92
static GCRegistry::Add< StatepointGC > D("statepoint-example","an example strategy for statepoint")
InstrProfValueKind
Definition: InstrProf.h:242
std::error_code make_error_code(BitcodeError E)
StringRef getInstrProfCoverageSectionName(bool AddSegment)
Return the name of the section containing function coverage mapping data.
Definition: InstrProf.h:84
void merge(InstrProfRecord &Other, uint64_t Weight=1)
Merge the counts in Other into this one.
Definition: InstrProf.cpp:394
StringRef getCoverageUnusedNamesVarName()
Return the name of the internal variable recording the array of PGO name vars referenced by the cover...
Definition: InstrProf.h:125
Error collectPGOFuncNameStrings(const std::vector< std::string > &NameStrs, bool doCompression, std::string &Result)
Given a vector of strings (function PGO names) NameStrs, the method generates a combined string Resul...
Definition: InstrProf.cpp:244
const Entry * getCutoffEntryBase() const
Definition: InstrProf.h:863
void mapAddress(uint64_t Addr, uint64_t MD5Val)
Map a function address to its name's MD5 hash.
Definition: InstrProf.h:476
StringRef getInstrProfNamesRegFuncName()
Return the name of the runtime interface that registers the PGO name strings.
Definition: InstrProf.h:145
static const bool IsLittleEndianHost
Definition: Host.h:40
StringRef getFuncNameWithoutPrefix(StringRef PGOFuncName, StringRef FileName="<unknown>")
Given a PGO function name, remove the filename prefix and return the original (static) function name...
Definition: InstrProf.cpp:169
#define F(x, y, z)
Definition: MD5.cpp:51
unsigned getNumValueSiteCountMismatches() const
Get the number of value site count mismatches.
Definition: InstrProf.h:388
StringRef getFuncName(uint64_t FuncNameAddress, size_t NameSize)
Return function's PGO name from the function name's symbol address in the object file.
void addFuncName(StringRef FuncName)
Update the symtab by adding FuncName to the table.
Definition: InstrProf.h:468
StringRef getInstrProfNameSeparator()
Return the marker used to separate PGO names during serialization.
Definition: InstrProf.h:169
void addError(instrprof_error IE)
Track a soft error (IE) and increment its associated counter.
Definition: InstrProf.cpp:98
const uint64_t Version
Definition: InstrProf.h:908
uint64_t NumBlocks
Number of blocks >= the minumum execution count.
Definition: InstrProf.h:824
void merge(SoftInstrProfErrors &SIPE, InstrProfValueSiteRecord &Input, uint64_t Weight=1)
Merge data from another InstrProfValueSiteRecord Optionally scale merged counts by Weight...
Definition: InstrProf.cpp:342
bool isIRPGOFlagSet(const Module *M)
Check if INSTR_PROF_RAW_VERSION_VAR is defined.
Definition: InstrProf.cpp:816
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
std::vector< std::pair< uint64_t, uint64_t > > AddrHashMap
Definition: InstrProf.h:418
std::string message() const override
Return the error message as a string.
Definition: InstrProf.cpp:123
uint64_t getMagic< uint32_t >()
Definition: InstrProf.h:915
bool needsComdatForCounter(const Function &F, const Module &M)
Check if we can use Comdat for profile variables.
Definition: InstrProf.cpp:789
bool getValueProfDataFromInst(const Instruction &Inst, InstrProfValueKind ValueKind, uint32_t MaxNumValueData, InstrProfValueData ValueData[], uint32_t &ActualNumValueData, uint64_t &TotalC)
Extract the value profile data from Inst which is annotated with value profile meta data...
Definition: InstrProf.cpp:721
void scale(SoftInstrProfErrors &SIPE, uint64_t Weight)
Scale up value profile data counts.
Definition: InstrProf.cpp:365
std::string getPGOFuncNameVarName(StringRef FuncName, GlobalValue::LinkageTypes Linkage)
Return the name of the global variable used to store a function name in PGO instrumentation.
Definition: InstrProf.cpp:180
uint64_t Cutoff
The required percentile of total execution count.
Definition: InstrProf.h:821
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
StringRef getInstrProfValueProfFuncName()
Return the name profile runtime entry point to do value profiling for a given site.
Definition: InstrProf.h:78
StringRef getInstrProfNamesVarName()
Return the name of the variable holding the strings (possibly compressed) of all function's PGO names...
Definition: InstrProf.h:110
static ManagedStatic< _object_error_category > error_category
StringRef getInstrProfValuesSectionName(bool AddSegment)
Return the name of data section containing pointers to value profile counters/nodes.
Definition: InstrProf.h:64
std::list< InstrProfValueData > ValueData
Value profiling data pairs at a given value site.
Definition: InstrProf.h:555
void handleAllErrors(Error E, HandlerTs &&...Handlers)
Behaves the same as handleErrors, except that it requires that all errors be handled by the given han...
uint64_t ComputeHash(StringRef K)
Definition: InstrProf.h:803
unsigned getNumHashMismatches() const
Get the number of hash mismatches.
Definition: InstrProf.h:379
void annotateValueSite(Module &M, Instruction &Inst, const InstrProfRecord &InstrProfR, InstrProfValueKind ValueKind, uint32_t SiteIndx, uint32_t MaxMDCount=3)
Get the value profile data for value site SiteIdx from InstrProfR and annotate the instruction Inst w...
Definition: InstrProf.cpp:676
uint32_t getNumValueDataForSite(uint32_t ValueKind, uint32_t Site) const
Return the number of value data collected for ValueKind at profiling site: Site.
Definition: InstrProf.h:700
void createPGOFuncNameMetadata(Function &F, StringRef PGOFuncName)
Create the PGOFuncName meta data if PGOFuncName is different from function's raw name.
Definition: InstrProf.cpp:777
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Error readPGOFuncNameStrings(StringRef NameStrings, InstrProfSymtab &Symtab)
NameStrings is a string composed of one of more sub-strings encoded in the format described above...
Definition: InstrProf.cpp:302
std::pair< typename base::iterator, bool > insert(StringRef Key)
Definition: StringSet.h:32
Error takeError()
Return the first encountered error and reset FirstError to a success value.
Definition: InstrProf.h:394
struct LLVM_ALIGNAS(8) ProfileData
Definition: InstrProf.h:924
StringRef getInstrProfCountersVarPrefix()
Return the name prefix of profile counter variables.
Definition: InstrProf.h:96
void addValueData(uint32_t ValueKind, uint32_t Site, InstrProfValueData *VData, uint32_t N, ValueMapType *ValueMap)
Add ValueData for ValueKind at value Site.
Definition: InstrProf.cpp:458
void clearValueData()
Clear value data entries.
Definition: InstrProf.h:639
static ErrorSuccess success()
Create a success value.
StringRef getCoverageMappingVarName()
Return the name of a covarage mapping variable (internal linkage) for each instrumented source module...
Definition: InstrProf.h:117
See the file comment.
Definition: ValueMap.h:87
const uint64_t * getSummaryDataBase() const
Definition: InstrProf.h:857
instrprof_error get() const
Definition: InstrProf.h:326
StringRef getPGOFuncNameMetadataName()
Definition: InstrProf.h:271
StringRef getInstrProfVNodesSectionName(bool AddSegment)
Return the name of data section containing nodes holdling value profiling data.
Definition: InstrProf.h:71
LinkageTypes
An enumeration for the kinds of linkage for global values.
Definition: GlobalValue.h:48
static char ID
Definition: InstrProf.h:339
StringRef getInstrProfRuntimeHookVarName()
Return the name of the hook variable defined in profile runtime library.
Definition: InstrProf.h:158
StringRef getInstrProfRegFuncName()
Return the name of the runtime interface that registers per-function control data for one instrumente...
Definition: InstrProf.h:140
Base class for user error types.
void sortByTargetValues()
Sort ValueData ascending by Value.
Definition: InstrProf.h:563
The total number of functions instrumented.
Definition: InstrProf.h:831
std::vector< uint64_t > Counts
Definition: InstrProf.h:587
unsigned getNumCounterOverflows() const
Get the number of counter overflows.
Definition: InstrProf.h:385
StringRef getInstrProfCountersSectionName(bool AddSegment)
Return the name of data section containing profile counter variables.
Definition: InstrProf.h:42
static const size_t npos
Definition: StringRef.h:51
The sum of all instrumented block counts.
Definition: InstrProf.h:843
Profiling information for a single function.
Definition: InstrProf.h:581
std::string getPGOFuncName(const Function &F, bool InLTO=false, uint64_t Version=INSTR_PROF_INDEX_VERSION)
Return the modified name for function F suitable to be used the key for profile lookup.
Definition: InstrProf.cpp:149
uint32_t getNumValueKinds() const
Return the number of value profile kinds with non-zero number of profile sites.
Definition: InstrProf.h:679
instrprof_error
Definition: InstrProf.h:287
#define I(x, y, z)
Definition: MD5.cpp:54
#define N
GlobalVariable * createPGOFuncNameVar(Function &F, StringRef PGOFuncName)
Create and return the global variable for function name used in PGO instrumentation.
Definition: InstrProf.cpp:226
Definition: MD5.h:39
InstrProfValueSiteRecord(InputIterator F, InputIterator L)
Definition: InstrProf.h:559
The maximal execution count among all functions.
Definition: InstrProf.h:837
StringRef getNameData() const
Return the name section data.
Definition: InstrProf.h:494
uint32_t getNumValueSites(uint32_t ValueKind) const
Return the number of instrumented sites for ValueKind.
Definition: InstrProf.h:696
const unsigned Kind
LLVM_NODISCARD size_t find_first_of(char C, size_t From=0) const
Find the first character in the string that is C, or npos if not found.
Definition: StringRef.h:392
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Max internal block count of the program (excluding entry blocks).
Definition: InstrProf.h:841
std::unique_ptr< InstrProfValueData[]> getValueForSite(uint32_t ValueKind, uint32_t Site, uint64_t *TotalC=0) const
Return the array of profiled values at Site.
Definition: InstrProf.h:706
StringRef getInstrProfVNodesVarName()
Return the name of value profile node array variables:
Definition: InstrProf.h:102
Lightweight error class with error context and mandatory checking.
uint64_t MinCount
The minimum count for this percentile.
StringSet - A wrapper for StringMap that provides set-like functionality.
Definition: StringSet.h:23
support::endianness getHostEndianness()
Definition: InstrProf.h:742
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
std::vector< std::pair< uint64_t, uint64_t > > ValueMapType
Definition: InstrProf.h:590
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
Total number of instrumented blocks/edges.
Definition: InstrProf.h:833
uint64_t NumCounts
Number of counts >= the minimum count.
StringRef getInstrProfComdatPrefix()
Return the name prefix of the COMDAT group for instrumentation variables associated with a COMDAT fun...
Definition: InstrProf.h:106
StringRef getInstrProfNameSectionName(bool AddSegment)
Return the name of data section containing names of instrumented functions.
Definition: InstrProf.h:49
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Definition: InstrProf.h:322
void set(SummaryFieldKind K, uint64_t V)
Definition: InstrProf.h:875
InstrProfError(instrprof_error Err)
Definition: InstrProf.h:314
const uint64_t Version
Definition: InstrProf.h:799
Function object to check whether the first component of a std::pair compares less than the first comp...
Definition: STLExtras.h:590
StringRef getPGOFuncNameVarInitializer(GlobalVariable *NameVar)
Return the initializer in string of the PGO name var NameVar.
Definition: InstrProf.cpp:285
This is a value type class that represents a single section in the list of sections in the object fil...
Definition: ObjectFile.h:70