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