LLVM  15.0.0git
SampleProfReader.h
Go to the documentation of this file.
1 //===- SampleProfReader.h - Read LLVM sample profile data -------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains definitions needed for reading sample profiles.
10 //
11 // NOTE: If you are making changes to this file format, please remember
12 // to document them in the Clang documentation at
13 // tools/clang/docs/UsersManual.rst.
14 //
15 // Text format
16 // -----------
17 //
18 // Sample profiles are written as ASCII text. The file is divided into
19 // sections, which correspond to each of the functions executed at runtime.
20 // Each section has the following format
21 //
22 // function1:total_samples:total_head_samples
23 // offset1[.discriminator]: number_of_samples [fn1:num fn2:num ... ]
24 // offset2[.discriminator]: number_of_samples [fn3:num fn4:num ... ]
25 // ...
26 // offsetN[.discriminator]: number_of_samples [fn5:num fn6:num ... ]
27 // offsetA[.discriminator]: fnA:num_of_total_samples
28 // offsetA1[.discriminator]: number_of_samples [fn7:num fn8:num ... ]
29 // ...
30 // !CFGChecksum: num
31 // !Attribute: flags
32 //
33 // This is a nested tree in which the indentation represents the nesting level
34 // of the inline stack. There are no blank lines in the file. And the spacing
35 // within a single line is fixed. Additional spaces will result in an error
36 // while reading the file.
37 //
38 // Any line starting with the '#' character is completely ignored.
39 //
40 // Inlined calls are represented with indentation. The Inline stack is a
41 // stack of source locations in which the top of the stack represents the
42 // leaf function, and the bottom of the stack represents the actual
43 // symbol to which the instruction belongs.
44 //
45 // Function names must be mangled in order for the profile loader to
46 // match them in the current translation unit. The two numbers in the
47 // function header specify how many total samples were accumulated in the
48 // function (first number), and the total number of samples accumulated
49 // in the prologue of the function (second number). This head sample
50 // count provides an indicator of how frequently the function is invoked.
51 //
52 // There are three types of lines in the function body.
53 //
54 // * Sampled line represents the profile information of a source location.
55 // * Callsite line represents the profile information of a callsite.
56 // * Metadata line represents extra metadata of the function.
57 //
58 // Each sampled line may contain several items. Some are optional (marked
59 // below):
60 //
61 // a. Source line offset. This number represents the line number
62 // in the function where the sample was collected. The line number is
63 // always relative to the line where symbol of the function is
64 // defined. So, if the function has its header at line 280, the offset
65 // 13 is at line 293 in the file.
66 //
67 // Note that this offset should never be a negative number. This could
68 // happen in cases like macros. The debug machinery will register the
69 // line number at the point of macro expansion. So, if the macro was
70 // expanded in a line before the start of the function, the profile
71 // converter should emit a 0 as the offset (this means that the optimizers
72 // will not be able to associate a meaningful weight to the instructions
73 // in the macro).
74 //
75 // b. [OPTIONAL] Discriminator. This is used if the sampled program
76 // was compiled with DWARF discriminator support
77 // (http://wiki.dwarfstd.org/index.php?title=Path_Discriminators).
78 // DWARF discriminators are unsigned integer values that allow the
79 // compiler to distinguish between multiple execution paths on the
80 // same source line location.
81 //
82 // For example, consider the line of code ``if (cond) foo(); else bar();``.
83 // If the predicate ``cond`` is true 80% of the time, then the edge
84 // into function ``foo`` should be considered to be taken most of the
85 // time. But both calls to ``foo`` and ``bar`` are at the same source
86 // line, so a sample count at that line is not sufficient. The
87 // compiler needs to know which part of that line is taken more
88 // frequently.
89 //
90 // This is what discriminators provide. In this case, the calls to
91 // ``foo`` and ``bar`` will be at the same line, but will have
92 // different discriminator values. This allows the compiler to correctly
93 // set edge weights into ``foo`` and ``bar``.
94 //
95 // c. Number of samples. This is an integer quantity representing the
96 // number of samples collected by the profiler at this source
97 // location.
98 //
99 // d. [OPTIONAL] Potential call targets and samples. If present, this
100 // line contains a call instruction. This models both direct and
101 // number of samples. For example,
102 //
103 // 130: 7 foo:3 bar:2 baz:7
104 //
105 // The above means that at relative line offset 130 there is a call
106 // instruction that calls one of ``foo()``, ``bar()`` and ``baz()``,
107 // with ``baz()`` being the relatively more frequently called target.
108 //
109 // Each callsite line may contain several items. Some are optional.
110 //
111 // a. Source line offset. This number represents the line number of the
112 // callsite that is inlined in the profiled binary.
113 //
114 // b. [OPTIONAL] Discriminator. Same as the discriminator for sampled line.
115 //
116 // c. Number of samples. This is an integer quantity representing the
117 // total number of samples collected for the inlined instance at this
118 // callsite
119 //
120 // Metadata line can occur in lines with one indent only, containing extra
121 // information for the top-level function. Furthermore, metadata can only
122 // occur after all the body samples and callsite samples.
123 // Each metadata line may contain a particular type of metadata, marked by
124 // the starting characters annotated with !. We process each metadata line
125 // independently, hence each metadata line has to form an independent piece
126 // of information that does not require cross-line reference.
127 // We support the following types of metadata:
128 //
129 // a. CFG Checksum (a.k.a. function hash):
130 // !CFGChecksum: 12345
131 // b. CFG Checksum (see ContextAttributeMask):
132 // !Atribute: 1
133 //
134 //
135 // Binary format
136 // -------------
137 //
138 // This is a more compact encoding. Numbers are encoded as ULEB128 values
139 // and all strings are encoded in a name table. The file is organized in
140 // the following sections:
141 //
142 // MAGIC (uint64_t)
143 // File identifier computed by function SPMagic() (0x5350524f463432ff)
144 //
145 // VERSION (uint32_t)
146 // File format version number computed by SPVersion()
147 //
148 // SUMMARY
149 // TOTAL_COUNT (uint64_t)
150 // Total number of samples in the profile.
151 // MAX_COUNT (uint64_t)
152 // Maximum value of samples on a line.
153 // MAX_FUNCTION_COUNT (uint64_t)
154 // Maximum number of samples at function entry (head samples).
155 // NUM_COUNTS (uint64_t)
156 // Number of lines with samples.
157 // NUM_FUNCTIONS (uint64_t)
158 // Number of functions with samples.
159 // NUM_DETAILED_SUMMARY_ENTRIES (size_t)
160 // Number of entries in detailed summary
161 // DETAILED_SUMMARY
162 // A list of detailed summary entry. Each entry consists of
163 // CUTOFF (uint32_t)
164 // Required percentile of total sample count expressed as a fraction
165 // multiplied by 1000000.
166 // MIN_COUNT (uint64_t)
167 // The minimum number of samples required to reach the target
168 // CUTOFF.
169 // NUM_COUNTS (uint64_t)
170 // Number of samples to get to the desrired percentile.
171 //
172 // NAME TABLE
173 // SIZE (uint32_t)
174 // Number of entries in the name table.
175 // NAMES
176 // A NUL-separated list of SIZE strings.
177 //
178 // FUNCTION BODY (one for each uninlined function body present in the profile)
179 // HEAD_SAMPLES (uint64_t) [only for top-level functions]
180 // Total number of samples collected at the head (prologue) of the
181 // function.
182 // NOTE: This field should only be present for top-level functions
183 // (i.e., not inlined into any caller). Inlined function calls
184 // have no prologue, so they don't need this.
185 // NAME_IDX (uint32_t)
186 // Index into the name table indicating the function name.
187 // SAMPLES (uint64_t)
188 // Total number of samples collected in this function.
189 // NRECS (uint32_t)
190 // Total number of sampling records this function's profile.
191 // BODY RECORDS
192 // A list of NRECS entries. Each entry contains:
193 // OFFSET (uint32_t)
194 // Line offset from the start of the function.
195 // DISCRIMINATOR (uint32_t)
196 // Discriminator value (see description of discriminators
197 // in the text format documentation above).
198 // SAMPLES (uint64_t)
199 // Number of samples collected at this location.
200 // NUM_CALLS (uint32_t)
201 // Number of non-inlined function calls made at this location. In the
202 // case of direct calls, this number will always be 1. For indirect
203 // calls (virtual functions and function pointers) this will
204 // represent all the actual functions called at runtime.
205 // CALL_TARGETS
206 // A list of NUM_CALLS entries for each called function:
207 // NAME_IDX (uint32_t)
208 // Index into the name table with the callee name.
209 // SAMPLES (uint64_t)
210 // Number of samples collected at the call site.
211 // NUM_INLINED_FUNCTIONS (uint32_t)
212 // Number of callees inlined into this function.
213 // INLINED FUNCTION RECORDS
214 // A list of NUM_INLINED_FUNCTIONS entries describing each of the inlined
215 // callees.
216 // OFFSET (uint32_t)
217 // Line offset from the start of the function.
218 // DISCRIMINATOR (uint32_t)
219 // Discriminator value (see description of discriminators
220 // in the text format documentation above).
221 // FUNCTION BODY
222 // A FUNCTION BODY entry describing the inlined function.
223 //===----------------------------------------------------------------------===//
224 
225 #ifndef LLVM_PROFILEDATA_SAMPLEPROFREADER_H
226 #define LLVM_PROFILEDATA_SAMPLEPROFREADER_H
227 
228 #include "llvm/ADT/Optional.h"
229 #include "llvm/ADT/SmallVector.h"
230 #include "llvm/ADT/StringRef.h"
231 #include "llvm/IR/DiagnosticInfo.h"
232 #include "llvm/IR/LLVMContext.h"
233 #include "llvm/IR/ProfileSummary.h"
234 #include "llvm/ProfileData/GCOV.h"
236 #include "llvm/Support/Debug.h"
238 #include "llvm/Support/ErrorOr.h"
241 #include <cstdint>
242 #include <list>
243 #include <memory>
244 #include <string>
245 #include <system_error>
246 #include <unordered_set>
247 #include <vector>
248 
249 namespace llvm {
250 
251 class raw_ostream;
252 class Twine;
253 
254 namespace sampleprof {
255 
256 class SampleProfileReader;
257 
258 /// SampleProfileReaderItaniumRemapper remaps the profile data from a
259 /// sample profile data reader, by applying a provided set of equivalences
260 /// between components of the symbol names in the profile.
262 public:
263  SampleProfileReaderItaniumRemapper(std::unique_ptr<MemoryBuffer> B,
264  std::unique_ptr<SymbolRemappingReader> SRR,
266  : Buffer(std::move(B)), Remappings(std::move(SRR)), Reader(R) {
267  assert(Remappings && "Remappings cannot be nullptr");
268  }
269 
270  /// Create a remapper from the given remapping file. The remapper will
271  /// be used for profile read in by Reader.
273  create(const std::string Filename, SampleProfileReader &Reader,
274  LLVMContext &C);
275 
276  /// Create a remapper from the given Buffer. The remapper will
277  /// be used for profile read in by Reader.
279  create(std::unique_ptr<MemoryBuffer> &B, SampleProfileReader &Reader,
280  LLVMContext &C);
281 
282  /// Apply remappings to the profile read by Reader.
283  void applyRemapping(LLVMContext &Ctx);
284 
285  bool hasApplied() { return RemappingApplied; }
286 
287  /// Insert function name into remapper.
288  void insert(StringRef FunctionName) { Remappings->insert(FunctionName); }
289 
290  /// Query whether there is equivalent in the remapper which has been
291  /// inserted.
292  bool exist(StringRef FunctionName) {
293  return Remappings->lookup(FunctionName);
294  }
295 
296  /// Return the equivalent name in the profile for \p FunctionName if
297  /// it exists.
299 
300 private:
301  // The buffer holding the content read from remapping file.
302  std::unique_ptr<MemoryBuffer> Buffer;
303  std::unique_ptr<SymbolRemappingReader> Remappings;
304  // Map remapping key to the name in the profile. By looking up the
305  // key in the remapper, a given new name can be mapped to the
306  // cannonical name using the NameMap.
308  // The Reader the remapper is servicing.
309  SampleProfileReader &Reader;
310  // Indicate whether remapping has been applied to the profile read
311  // by Reader -- by calling applyRemapping.
312  bool RemappingApplied = false;
313 };
314 
315 /// Sample-based profile reader.
316 ///
317 /// Each profile contains sample counts for all the functions
318 /// executed. Inside each function, statements are annotated with the
319 /// collected samples on all the instructions associated with that
320 /// statement.
321 ///
322 /// For this to produce meaningful data, the program needs to be
323 /// compiled with some debug information (at minimum, line numbers:
324 /// -gline-tables-only). Otherwise, it will be impossible to match IR
325 /// instructions to the line numbers collected by the profiler.
326 ///
327 /// From the profile file, we are interested in collecting the
328 /// following information:
329 ///
330 /// * A list of functions included in the profile (mangled names).
331 ///
332 /// * For each function F:
333 /// 1. The total number of samples collected in F.
334 ///
335 /// 2. The samples collected at each line in F. To provide some
336 /// protection against source code shuffling, line numbers should
337 /// be relative to the start of the function.
338 ///
339 /// The reader supports two file formats: text and binary. The text format
340 /// is useful for debugging and testing, while the binary format is more
341 /// compact and I/O efficient. They can both be used interchangeably.
343 public:
344  SampleProfileReader(std::unique_ptr<MemoryBuffer> B, LLVMContext &C,
346  : Profiles(0), Ctx(C), Buffer(std::move(B)), Format(Format) {}
347 
348  virtual ~SampleProfileReader() = default;
349 
350  /// Read and validate the file header.
351  virtual std::error_code readHeader() = 0;
352 
353  /// Set the bits for FS discriminators. Parameter Pass specify the sequence
354  /// number, Pass == i is for the i-th round of adding FS discriminators.
355  /// Pass == 0 is for using base discriminators.
358  }
359 
360  /// Get the bitmask the discriminators: For FS profiles, return the bit
361  /// mask for this pass. For non FS profiles, return (unsigned) -1.
363  if (!ProfileIsFS)
364  return 0xFFFFFFFF;
365  assert((MaskedBitFrom != 0) && "MaskedBitFrom is not set properly");
366  return getN1Bits(MaskedBitFrom);
367  }
368 
369  /// The interface to read sample profiles from the associated file.
370  std::error_code read() {
371  if (std::error_code EC = readImpl())
372  return EC;
373  if (Remapper)
374  Remapper->applyRemapping(Ctx);
377  }
378 
379  /// The implementaion to read sample profiles from the associated file.
380  virtual std::error_code readImpl() = 0;
381 
382  /// Print the profile for \p FContext on stream \p OS.
383  void dumpFunctionProfile(SampleContext FContext, raw_ostream &OS = dbgs());
384 
385  /// Collect functions with definitions in Module M. For reader which
386  /// support loading function profiles on demand, return true when the
387  /// reader has been given a module. Always return false for reader
388  /// which doesn't support loading function profiles on demand.
389  virtual bool collectFuncsFromModule() { return false; }
390 
391  /// Print all the profiles on stream \p OS.
392  void dump(raw_ostream &OS = dbgs());
393 
394  /// Return the samples collected for function \p F.
396  // The function name may have been updated by adding suffix. Call
397  // a helper to (optionally) strip off suffixes so that we can
398  // match against the original function name in the profile.
400  return getSamplesFor(CanonName);
401  }
402 
403  /// Return the samples collected for function \p F, create empty
404  /// FunctionSamples if it doesn't exist.
406  std::string FGUID;
408  CanonName = getRepInFormat(CanonName, useMD5(), FGUID);
409  auto It = Profiles.find(CanonName);
410  if (It != Profiles.end())
411  return &It->second;
412  if (!FGUID.empty()) {
413  assert(useMD5() && "New name should only be generated for md5 profile");
414  CanonName = *MD5NameBuffer.insert(FGUID).first;
415  }
416  return &Profiles[CanonName];
417  }
418 
419  /// Return the samples collected for function \p F.
421  std::string FGUID;
422  Fname = getRepInFormat(Fname, useMD5(), FGUID);
423  auto It = Profiles.find(Fname);
424  if (It != Profiles.end())
425  return &It->second;
426 
427  if (Remapper) {
428  if (auto NameInProfile = Remapper->lookUpNameInProfile(Fname)) {
429  auto It = Profiles.find(*NameInProfile);
430  if (It != Profiles.end())
431  return &It->second;
432  }
433  }
434  return nullptr;
435  }
436 
437  /// Return all the profiles.
439 
440  /// Report a parse error message.
441  void reportError(int64_t LineNumber, const Twine &Msg) const {
442  Ctx.diagnose(DiagnosticInfoSampleProfile(Buffer->getBufferIdentifier(),
443  LineNumber, Msg));
444  }
445 
446  /// Create a sample profile reader appropriate to the file format.
447  /// Create a remapper underlying if RemapFilename is not empty.
448  /// Parameter P specifies the FSDiscriminatorPass.
450  create(const std::string Filename, LLVMContext &C,
452  const std::string RemapFilename = "");
453 
454  /// Create a sample profile reader from the supplied memory buffer.
455  /// Create a remapper underlying if RemapFilename is not empty.
456  /// Parameter P specifies the FSDiscriminatorPass.
458  create(std::unique_ptr<MemoryBuffer> &B, LLVMContext &C,
460  const std::string RemapFilename = "");
461 
462  /// Return the profile summary.
463  ProfileSummary &getSummary() const { return *(Summary.get()); }
464 
465  MemoryBuffer *getBuffer() const { return Buffer.get(); }
466 
467  /// \brief Return the profile format.
469 
470  /// Whether input profile is based on pseudo probes.
471  bool profileIsProbeBased() const { return ProfileIsProbeBased; }
472 
473  /// Whether input profile is fully context-sensitive.
474  bool profileIsCS() const { return ProfileIsCS; }
475 
476  /// Whether input profile contains ShouldBeInlined contexts.
477  bool profileIsPreInlined() const { return ProfileIsPreInlined; }
478 
479  virtual std::unique_ptr<ProfileSymbolList> getProfileSymbolList() {
480  return nullptr;
481  };
482 
483  /// It includes all the names that have samples either in outline instance
484  /// or inline instance.
485  virtual std::vector<StringRef> *getNameTable() { return nullptr; }
486  virtual bool dumpSectionInfo(raw_ostream &OS = dbgs()) { return false; };
487 
488  /// Return whether names in the profile are all MD5 numbers.
489  virtual bool useMD5() { return false; }
490 
491  /// Don't read profile without context if the flag is set. This is only meaningful
492  /// for ExtBinary format.
493  virtual void setSkipFlatProf(bool Skip) {}
494  /// Return whether any name in the profile contains ".__uniq." suffix.
495  virtual bool hasUniqSuffix() { return false; }
496 
498 
499  void setModule(const Module *Mod) { M = Mod; }
500 
501 protected:
502  /// Map every function to its associated profile.
503  ///
504  /// The profile of every function executed at runtime is collected
505  /// in the structure FunctionSamples. This maps function objects
506  /// to their corresponding profiles.
508 
509  /// LLVM context used to emit diagnostics.
511 
512  /// Memory buffer holding the profile file.
513  std::unique_ptr<MemoryBuffer> Buffer;
514 
515  /// Extra name buffer holding names created on demand.
516  /// This should only be needed for md5 profiles.
517  std::unordered_set<std::string> MD5NameBuffer;
518 
519  /// Profile summary information.
520  std::unique_ptr<ProfileSummary> Summary;
521 
522  /// Take ownership of the summary of this reader.
523  static std::unique_ptr<ProfileSummary>
525  return std::move(Reader.Summary);
526  }
527 
528  /// Compute summary for this profile.
529  void computeSummary();
530 
531  std::unique_ptr<SampleProfileReaderItaniumRemapper> Remapper;
532 
533  /// \brief Whether samples are collected based on pseudo probes.
534  bool ProfileIsProbeBased = false;
535 
536  /// Whether function profiles are context-sensitive flat profiles.
537  bool ProfileIsCS = false;
538 
539  /// Whether function profile contains ShouldBeInlined contexts.
540  bool ProfileIsPreInlined = false;
541 
542  /// Number of context-sensitive profiles.
544 
545  /// Whether the function profiles use FS discriminators.
546  bool ProfileIsFS = false;
547 
548  /// \brief The format of sample.
550 
551  /// \brief The current module being compiled if SampleProfileReader
552  /// is used by compiler. If SampleProfileReader is used by other
553  /// tools which are not compiler, M is usually nullptr.
554  const Module *M = nullptr;
555 
556  /// Zero out the discriminator bits higher than bit MaskedBitFrom (0 based).
557  /// The default is to keep all the bits.
559 };
560 
562 public:
563  SampleProfileReaderText(std::unique_ptr<MemoryBuffer> B, LLVMContext &C)
565 
566  /// Read and validate the file header.
567  std::error_code readHeader() override { return sampleprof_error::success; }
568 
569  /// Read sample profiles from the associated file.
570  std::error_code readImpl() override;
571 
572  /// Return true if \p Buffer is in the format supported by this class.
573  static bool hasFormat(const MemoryBuffer &Buffer);
574 
575 private:
576  /// CSNameTable is used to save full context vectors. This serves as an
577  /// underlying immutable buffer for all clients.
578  std::list<SampleContextFrameVector> CSNameTable;
579 };
580 
582 public:
583  SampleProfileReaderBinary(std::unique_ptr<MemoryBuffer> B, LLVMContext &C,
586 
587  /// Read and validate the file header.
588  virtual std::error_code readHeader() override;
589 
590  /// Read sample profiles from the associated file.
591  std::error_code readImpl() override;
592 
593  /// It includes all the names that have samples either in outline instance
594  /// or inline instance.
595  virtual std::vector<StringRef> *getNameTable() override { return &NameTable; }
596 
597 protected:
598  /// Read a numeric value of type T from the profile.
599  ///
600  /// If an error occurs during decoding, a diagnostic message is emitted and
601  /// EC is set.
602  ///
603  /// \returns the read value.
604  template <typename T> ErrorOr<T> readNumber();
605 
606  /// Read a numeric value of type T from the profile. The value is saved
607  /// without encoded.
608  template <typename T> ErrorOr<T> readUnencodedNumber();
609 
610  /// Read a string from the profile.
611  ///
612  /// If an error occurs during decoding, a diagnostic message is emitted and
613  /// EC is set.
614  ///
615  /// \returns the read value.
617 
618  /// Read the string index and check whether it overflows the table.
619  template <typename T> inline ErrorOr<uint32_t> readStringIndex(T &Table);
620 
621  /// Return true if we've reached the end of file.
622  bool at_eof() const { return Data >= End; }
623 
624  /// Read the next function profile instance.
625  std::error_code readFuncProfile(const uint8_t *Start);
626 
627  /// Read the contents of the given profile instance.
628  std::error_code readProfile(FunctionSamples &FProfile);
629 
630  /// Read the contents of Magic number and Version number.
631  std::error_code readMagicIdent();
632 
633  /// Read profile summary.
634  std::error_code readSummary();
635 
636  /// Read the whole name table.
637  virtual std::error_code readNameTable();
638 
639  /// Points to the current location in the buffer.
640  const uint8_t *Data = nullptr;
641 
642  /// Points to the end of the buffer.
643  const uint8_t *End = nullptr;
644 
645  /// Function name table.
646  std::vector<StringRef> NameTable;
647 
648  /// Read a string indirectly via the name table.
651 
652 private:
653  std::error_code readSummaryEntry(std::vector<ProfileSummaryEntry> &Entries);
654  virtual std::error_code verifySPMagic(uint64_t Magic) = 0;
655 };
656 
658 private:
659  virtual std::error_code verifySPMagic(uint64_t Magic) override;
660 
661 public:
662  SampleProfileReaderRawBinary(std::unique_ptr<MemoryBuffer> B, LLVMContext &C,
665 
666  /// \brief Return true if \p Buffer is in the format supported by this class.
667  static bool hasFormat(const MemoryBuffer &Buffer);
668 };
669 
670 /// SampleProfileReaderExtBinaryBase/SampleProfileWriterExtBinaryBase defines
671 /// the basic structure of the extensible binary format.
672 /// The format is organized in sections except the magic and version number
673 /// at the beginning. There is a section table before all the sections, and
674 /// each entry in the table describes the entry type, start, size and
675 /// attributes. The format in each section is defined by the section itself.
676 ///
677 /// It is easy to add a new section while maintaining the backward
678 /// compatibility of the profile. Nothing extra needs to be done. If we want
679 /// to extend an existing section, like add cache misses information in
680 /// addition to the sample count in the profile body, we can add a new section
681 /// with the extension and retire the existing section, and we could choose
682 /// to keep the parser of the old section if we want the reader to be able
683 /// to read both new and old format profile.
684 ///
685 /// SampleProfileReaderExtBinary/SampleProfileWriterExtBinary define the
686 /// commonly used sections of a profile in extensible binary format. It is
687 /// possible to define other types of profile inherited from
688 /// SampleProfileReaderExtBinaryBase/SampleProfileWriterExtBinaryBase.
690 private:
691  std::error_code decompressSection(const uint8_t *SecStart,
692  const uint64_t SecSize,
693  const uint8_t *&DecompressBuf,
694  uint64_t &DecompressBufSize);
695 
696  BumpPtrAllocator Allocator;
697 
698 protected:
699  std::vector<SecHdrTableEntry> SecHdrTable;
700  std::error_code readSecHdrTableEntry(uint32_t Idx);
701  std::error_code readSecHdrTable();
702 
703  std::error_code readFuncMetadata(bool ProfileHasAttribute);
704  std::error_code readFuncMetadata(bool ProfileHasAttribute,
705  FunctionSamples *FProfile);
706  std::error_code readFuncOffsetTable();
707  std::error_code readFuncProfiles();
708  std::error_code readMD5NameTable();
709  std::error_code readNameTableSec(bool IsMD5);
710  std::error_code readCSNameTableSec();
711  std::error_code readProfileSymbolList();
712 
713  virtual std::error_code readHeader() override;
714  virtual std::error_code verifySPMagic(uint64_t Magic) override = 0;
715  virtual std::error_code readOneSection(const uint8_t *Start, uint64_t Size,
716  const SecHdrTableEntry &Entry);
717  // placeholder for subclasses to dispatch their own section readers.
718  virtual std::error_code readCustomSection(const SecHdrTableEntry &Entry) = 0;
719  virtual ErrorOr<StringRef> readStringFromTable() override;
722 
723  std::unique_ptr<ProfileSymbolList> ProfSymList;
724 
725  /// The table mapping from function context to the offset of its
726  /// FunctionSample towards file start.
728 
729  /// Function offset mapping ordered by contexts.
730  std::unique_ptr<std::vector<std::pair<SampleContext, uint64_t>>>
732 
733  /// The set containing the functions to use when compiling a module.
735 
736  /// Use fixed length MD5 instead of ULEB128 encoding so NameTable doesn't
737  /// need to be read in up front and can be directly accessed using index.
738  bool FixedLengthMD5 = false;
739  /// The starting address of NameTable containing fixed length MD5.
740  const uint8_t *MD5NameMemStart = nullptr;
741 
742  /// If MD5 is used in NameTable section, the section saves uint64_t data.
743  /// The uint64_t data has to be converted to a string and then the string
744  /// will be used to initialize StringRef in NameTable.
745  /// Note NameTable contains StringRef so it needs another buffer to own
746  /// the string data. MD5StringBuf serves as the string buffer that is
747  /// referenced by NameTable (vector of StringRef). We make sure
748  /// the lifetime of MD5StringBuf is not shorter than that of NameTable.
749  std::unique_ptr<std::vector<std::string>> MD5StringBuf;
750 
751  /// CSNameTable is used to save full context vectors. This serves as an
752  /// underlying immutable buffer for all clients.
753  std::unique_ptr<const std::vector<SampleContextFrameVector>> CSNameTable;
754 
755  /// If SkipFlatProf is true, skip the sections with
756  /// SecFlagFlat flag.
757  bool SkipFlatProf = false;
758 
759  bool FuncOffsetsOrdered = false;
760 
761 public:
762  SampleProfileReaderExtBinaryBase(std::unique_ptr<MemoryBuffer> B,
765 
766  /// Read sample profiles in extensible format from the associated file.
767  std::error_code readImpl() override;
768 
769  /// Get the total size of all \p Type sections.
771  /// Get the total size of header and all sections.
773  virtual bool dumpSectionInfo(raw_ostream &OS = dbgs()) override;
774 
775  /// Collect functions with definitions in Module M. Return true if
776  /// the reader has been given a module.
777  bool collectFuncsFromModule() override;
778 
779  /// Return whether names in the profile are all MD5 numbers.
780  virtual bool useMD5() override { return MD5StringBuf.get(); }
781 
782  virtual std::unique_ptr<ProfileSymbolList> getProfileSymbolList() override {
783  return std::move(ProfSymList);
784  };
785 
786  virtual void setSkipFlatProf(bool Skip) override { SkipFlatProf = Skip; }
787 };
788 
790 private:
791  virtual std::error_code verifySPMagic(uint64_t Magic) override;
792  virtual std::error_code
793  readCustomSection(const SecHdrTableEntry &Entry) override {
794  // Update the data reader pointer to the end of the section.
795  Data = End;
797  };
798 
799 public:
800  SampleProfileReaderExtBinary(std::unique_ptr<MemoryBuffer> B, LLVMContext &C,
803 
804  /// \brief Return true if \p Buffer is in the format supported by this class.
805  static bool hasFormat(const MemoryBuffer &Buffer);
806 };
807 
809 private:
810  /// Function name table.
811  std::vector<std::string> NameTable;
812  /// The table mapping from function name to the offset of its FunctionSample
813  /// towards file start.
814  DenseMap<StringRef, uint64_t> FuncOffsetTable;
815  /// The set containing the functions to use when compiling a module.
816  DenseSet<StringRef> FuncsToUse;
817  virtual std::error_code verifySPMagic(uint64_t Magic) override;
818  virtual std::error_code readNameTable() override;
819  /// Read a string indirectly via the name table.
820  virtual ErrorOr<StringRef> readStringFromTable() override;
821  virtual std::error_code readHeader() override;
822  std::error_code readFuncOffsetTable();
823 
824 public:
825  SampleProfileReaderCompactBinary(std::unique_ptr<MemoryBuffer> B,
826  LLVMContext &C)
828 
829  /// \brief Return true if \p Buffer is in the format supported by this class.
830  static bool hasFormat(const MemoryBuffer &Buffer);
831 
832  /// Read samples only for functions to use.
833  std::error_code readImpl() override;
834 
835  /// Collect functions with definitions in Module M. Return true if
836  /// the reader has been given a module.
837  bool collectFuncsFromModule() override;
838 
839  /// Return whether names in the profile are all MD5 numbers.
840  virtual bool useMD5() override { return true; }
841 };
842 
844 
845 // Supported histogram types in GCC. Currently, we only need support for
846 // call target histograms.
847 enum HistType {
856 };
857 
859 public:
860  SampleProfileReaderGCC(std::unique_ptr<MemoryBuffer> B, LLVMContext &C)
862  GcovBuffer(Buffer.get()) {}
863 
864  /// Read and validate the file header.
865  std::error_code readHeader() override;
866 
867  /// Read sample profiles from the associated file.
868  std::error_code readImpl() override;
869 
870  /// Return true if \p Buffer is in the format supported by this class.
871  static bool hasFormat(const MemoryBuffer &Buffer);
872 
873 protected:
874  std::error_code readNameTable();
875  std::error_code readOneFunctionProfile(const InlineCallStack &InlineStack,
876  bool Update, uint32_t Offset);
877  std::error_code readFunctionProfiles();
878  std::error_code skipNextWord();
879  template <typename T> ErrorOr<T> readNumber();
881 
882  /// Read the section tag and check that it's the same as \p Expected.
883  std::error_code readSectionTag(uint32_t Expected);
884 
885  /// GCOV buffer containing the profile.
887 
888  /// Function names in this profile.
889  std::vector<std::string> Names;
890 
891  /// GCOV tags used to separate sections in the profile file.
892  static const uint32_t GCOVTagAFDOFileNames = 0xaa000000;
893  static const uint32_t GCOVTagAFDOFunction = 0xac000000;
894 };
895 
896 } // end namespace sampleprof
897 
898 } // end namespace llvm
899 
900 #endif // LLVM_PROFILEDATA_SAMPLEPROFREADER_H
llvm::sampleprof::SampleProfileReader::ProfileIsFS
bool ProfileIsFS
Whether the function profiles use FS discriminators.
Definition: SampleProfReader.h:546
MemoryBuffer.h
llvm::sampleprof::SampleProfileReader::dump
void dump(raw_ostream &OS=dbgs())
Print all the profiles on stream OS.
Definition: SampleProfReader.cpp:68
llvm::sampleprof::SampleProfileReaderText
Definition: SampleProfReader.h:561
llvm::sampleprof::SampleProfileReaderBinary::readNameTable
virtual std::error_code readNameTable()
Read the whole name table.
Definition: SampleProfReader.cpp:994
llvm::sampleprof::SampleProfileReader::CSProfileCount
uint32_t CSProfileCount
Number of context-sensitive profiles.
Definition: SampleProfReader.h:543
llvm::sampleprof::SampleProfileReaderText::readImpl
std::error_code readImpl() override
Read sample profiles from the associated file.
Definition: SampleProfReader.cpp:242
llvm::sampleprof::SampleProfileReaderExtBinaryBase::FixedLengthMD5
bool FixedLengthMD5
Use fixed length MD5 instead of ULEB128 encoding so NameTable doesn't need to be read in up front and...
Definition: SampleProfReader.h:738
llvm::sampleprof::SampleProfileReaderItaniumRemapper::create
static ErrorOr< std::unique_ptr< SampleProfileReaderItaniumRemapper > > create(const std::string Filename, SampleProfileReader &Reader, LLVMContext &C)
Create a remapper from the given remapping file.
Definition: SampleProfReader.cpp:1807
llvm::sampleprof::SampleProfileReaderExtBinary::SampleProfileReaderExtBinary
SampleProfileReaderExtBinary(std::unique_ptr< MemoryBuffer > B, LLVMContext &C, SampleProfileFormat Format=SPF_Ext_Binary)
Definition: SampleProfReader.h:800
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::sampleprof::SampleProfileReader::M
const Module * M
The current module being compiled if SampleProfileReader is used by compiler.
Definition: SampleProfReader.h:554
llvm::sampleprof::SampleProfileReader::Remapper
std::unique_ptr< SampleProfileReaderItaniumRemapper > Remapper
Definition: SampleProfReader.h:531
Optional.h
llvm::sampleprof::SampleProfileReaderExtBinaryBase::useMD5
virtual bool useMD5() override
Return whether names in the profile are all MD5 numbers.
Definition: SampleProfReader.h:780
llvm::sampleprof::SampleProfileReaderExtBinaryBase
SampleProfileReaderExtBinaryBase/SampleProfileWriterExtBinaryBase defines the basic structure of the ...
Definition: SampleProfReader.h:689
llvm::sampleprof::SampleProfileReaderBinary::SampleProfileReaderBinary
SampleProfileReaderBinary(std::unique_ptr< MemoryBuffer > B, LLVMContext &C, SampleProfileFormat Format=SPF_None)
Definition: SampleProfReader.h:583
llvm::sampleprof::SampleProfileReaderGCC::readFunctionProfiles
std::error_code readFunctionProfiles()
Definition: SampleProfReader.cpp:1564
llvm::sampleprof::SampleProfileReader::profileIsProbeBased
bool profileIsProbeBased() const
Whether input profile is based on pseudo probes.
Definition: SampleProfReader.h:471
llvm::Function
Definition: Function.h:60
llvm::sampleprof::SampleProfileReaderGCC::readSectionTag
std::error_code readSectionTag(uint32_t Expected)
Read the section tag and check that it's the same as Expected.
Definition: SampleProfReader.cpp:1532
ProfileSummary.h
StringRef.h
P
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
Definition: README-SSE.txt:411
llvm::sampleprof::SecHdrTableEntry
Definition: SampleProf.h:158
llvm::sampleprof::SampleProfileReaderRawBinary::SampleProfileReaderRawBinary
SampleProfileReaderRawBinary(std::unique_ptr< MemoryBuffer > B, LLVMContext &C, SampleProfileFormat Format=SPF_Binary)
Definition: SampleProfReader.h:662
llvm::sampleprof::SampleProfileReaderExtBinaryBase::readCSNameTableSec
std::error_code readCSNameTableSec()
Definition: SampleProfReader.cpp:1049
llvm::sampleprof::SampleProfileReaderBinary::readProfile
std::error_code readProfile(FunctionSamples &FProfile)
Read the contents of the given profile instance.
Definition: SampleProfReader.cpp:504
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1185
llvm::sampleprof::SampleProfileReaderExtBinaryBase::readContextFromTable
ErrorOr< SampleContextFrames > readContextFromTable()
Definition: SampleProfReader.cpp:622
llvm::sampleprof::SampleProfileReaderExtBinaryBase::SampleProfileReaderExtBinaryBase
SampleProfileReaderExtBinaryBase(std::unique_ptr< MemoryBuffer > B, LLVMContext &C, SampleProfileFormat Format)
Definition: SampleProfReader.h:762
llvm::sampleprof::SampleProfileReaderExtBinaryBase::SecHdrTable
std::vector< SecHdrTableEntry > SecHdrTable
Definition: SampleProfReader.h:699
llvm::sampleprof::SampleProfileReaderExtBinaryBase::readStringFromTable
virtual ErrorOr< StringRef > readStringFromTable() override
Read a string indirectly via the name table.
Definition: SampleProfReader.cpp:467
llvm::sampleprof::SampleProfileReaderGCC::hasFormat
static bool hasFormat(const MemoryBuffer &Buffer)
Return true if Buffer is in the format supported by this class.
Definition: SampleProfReader.cpp:1720
llvm::sampleprof::SampleProfileReaderExtBinaryBase::readNameTableSec
std::error_code readNameTableSec(bool IsMD5)
Definition: SampleProfReader.cpp:1039
llvm::sampleprof::SampleProfileReaderGCC::GcovBuffer
GCOVBuffer GcovBuffer
GCOV buffer containing the profile.
Definition: SampleProfReader.h:886
llvm::sampleprof::SampleProfileMap
std::unordered_map< SampleContext, FunctionSamples, SampleContext::Hash > SampleProfileMap
Definition: SampleProf.h:1193
llvm::sampleprof::SampleProfileReaderItaniumRemapper::applyRemapping
void applyRemapping(LLVMContext &Ctx)
Apply remappings to the profile read by Reader.
Definition: SampleProfReader.cpp:1725
Discriminator.h
llvm::sampleprof::SPF_GCC
@ SPF_GCC
Definition: SampleProf.h:93
llvm::sampleprof::SampleProfileReaderExtBinaryBase::verifySPMagic
virtual std::error_code verifySPMagic(uint64_t Magic) override=0
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::getN1Bits
static unsigned getN1Bits(int N)
Definition: Discriminator.h:123
llvm::sampleprof::SampleProfileReaderExtBinaryBase::CSNameTable
std::unique_ptr< const std::vector< SampleContextFrameVector > > CSNameTable
CSNameTable is used to save full context vectors.
Definition: SampleProfReader.h:753
llvm::sampleprof::SampleProfileReaderExtBinaryBase::readCustomSection
virtual std::error_code readCustomSection(const SecHdrTableEntry &Entry)=0
llvm::sampleprof::SampleProfileReaderGCC::readNameTable
std::error_code readNameTable()
Definition: SampleProfReader.cpp:1546
llvm::sampleprof::SampleProfileReaderGCC::Names
std::vector< std::string > Names
Function names in this profile.
Definition: SampleProfReader.h:889
llvm::sampleprof::SampleProfileReaderText::SampleProfileReaderText
SampleProfileReaderText(std::unique_ptr< MemoryBuffer > B, LLVMContext &C)
Definition: SampleProfReader.h:563
llvm::Optional
Definition: APInt.h:33
llvm::sampleprof::SampleProfileReaderExtBinaryBase::readMD5NameTable
std::error_code readMD5NameTable()
Definition: SampleProfReader.cpp:1009
llvm::sampleprof::SampleProfileReaderExtBinaryBase::FuncOffsetsOrdered
bool FuncOffsetsOrdered
Definition: SampleProfReader.h:759
llvm::sampleprof::SampleProfileReaderExtBinaryBase::readSecHdrTableEntry
std::error_code readSecHdrTableEntry(uint32_t Idx)
Definition: SampleProfReader.cpp:1178
llvm::sampleprof::HIST_TYPE_IOR
@ HIST_TYPE_IOR
Definition: SampleProfReader.h:854
llvm::sampleprof::SampleProfileReaderExtBinaryBase::readSampleContextFromTable
virtual ErrorOr< SampleContext > readSampleContextFromTable() override
Definition: SampleProfReader.cpp:632
llvm::sampleprof::SampleProfileReader::collectFuncsFromModule
virtual bool collectFuncsFromModule()
Collect functions with definitions in Module M.
Definition: SampleProfReader.h:389
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:41
llvm::sampleprof::SampleProfileReader::getRemapper
SampleProfileReaderItaniumRemapper * getRemapper()
Definition: SampleProfReader.h:497
llvm::sampleprof::SPF_None
@ SPF_None
Definition: SampleProf.h:90
llvm::sampleprof::SampleProfileReader::Summary
std::unique_ptr< ProfileSummary > Summary
Profile summary information.
Definition: SampleProfReader.h:520
llvm::sampleprof::SampleProfileReaderGCC::readOneFunctionProfile
std::error_code readOneFunctionProfile(const InlineCallStack &InlineStack, bool Update, uint32_t Offset)
Definition: SampleProfReader.cpp:1581
llvm::MemoryBuffer
This interface provides simple read-only access to a block of memory, and provides simple methods for...
Definition: MemoryBuffer.h:50
llvm::sampleprof::SPF_Binary
@ SPF_Binary
Definition: SampleProf.h:95
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::sampleprof::SampleProfileReaderGCC::readNumber
ErrorOr< T > readNumber()
Definition: SampleProfReader.cpp:1488
llvm::sampleprof::SampleProfileReaderBinary::readStringFromTable
virtual ErrorOr< StringRef > readStringFromTable()
Read a string indirectly via the name table.
Definition: SampleProfReader.cpp:452
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
llvm::sampleprof::FSDiscriminatorPass
FSDiscriminatorPass
Definition: Discriminator.h:57
llvm::sampleprof::HIST_TYPE_INDIR_CALL
@ HIST_TYPE_INDIR_CALL
Definition: SampleProfReader.h:852
llvm::sampleprof::SampleProfileReader::getDiscriminatorMask
uint32_t getDiscriminatorMask() const
Get the bitmask the discriminators: For FS profiles, return the bit mask for this pass.
Definition: SampleProfReader.h:362
llvm::sampleprof::SampleProfileReaderBinary::NameTable
std::vector< StringRef > NameTable
Function name table.
Definition: SampleProfReader.h:646
llvm::sampleprof::SampleProfileReader::takeSummary
static std::unique_ptr< ProfileSummary > takeSummary(SampleProfileReader &Reader)
Take ownership of the summary of this reader.
Definition: SampleProfReader.h:524
llvm::sampleprof::SampleProfileReader::profileIsCS
bool profileIsCS() const
Whether input profile is fully context-sensitive.
Definition: SampleProfReader.h:474
llvm::sampleprof::SampleProfileFormat
SampleProfileFormat
Definition: SampleProf.h:89
llvm::sampleprof::getRepInFormat
static StringRef getRepInFormat(StringRef Name, bool UseMD5, std::string &GUIDBuf)
Get the proper representation of a string according to whether the current Format uses MD5 to represe...
Definition: SampleProf.h:107
llvm::sampleprof::SampleProfileReaderCompactBinary::readImpl
std::error_code readImpl() override
Read samples only for functions to use.
Definition: SampleProfReader.cpp:941
llvm::sampleprof::SampleProfileReaderRawBinary::hasFormat
static bool hasFormat(const MemoryBuffer &Buffer)
Return true if Buffer is in the format supported by this class.
Definition: SampleProfReader.cpp:1460
llvm::sampleprof::SampleProfileReader::read
std::error_code read()
The interface to read sample profiles from the associated file.
Definition: SampleProfReader.h:370
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::sampleprof::SampleProfileReader::getSamplesFor
virtual FunctionSamples * getSamplesFor(StringRef Fname)
Return the samples collected for function F.
Definition: SampleProfReader.h:420
GCOV.h
llvm::sampleprof::SampleProfileReaderBinary::readFuncProfile
std::error_code readFuncProfile(const uint8_t *Start)
Read the next function profile instance.
Definition: SampleProfReader.cpp:587
llvm::sampleprof::SampleProfileReader::MD5NameBuffer
std::unordered_set< std::string > MD5NameBuffer
Extra name buffer holding names created on demand.
Definition: SampleProfReader.h:517
SampleProf.h
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::sampleprof::SampleProfileReaderItaniumRemapper::lookUpNameInProfile
Optional< StringRef > lookUpNameInProfile(StringRef FunctionName)
Return the equivalent name in the profile for FunctionName if it exists.
Definition: SampleProfReader.cpp:1752
llvm::sampleprof::SampleProfileReaderBinary::readString
ErrorOr< StringRef > readString()
Read a string from the profile.
Definition: SampleProfReader.cpp:413
llvm::sampleprof::SampleProfileReaderExtBinaryBase::getProfileSymbolList
virtual std::unique_ptr< ProfileSymbolList > getProfileSymbolList() override
Definition: SampleProfReader.h:782
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:54
llvm::sampleprof::SampleProfileReader::readHeader
virtual std::error_code readHeader()=0
Read and validate the file header.
llvm::sampleprof::SampleProfileReaderExtBinaryBase::FuncOffsetTable
DenseMap< SampleContext, uint64_t > FuncOffsetTable
The table mapping from function context to the offset of its FunctionSample towards file start.
Definition: SampleProfReader.h:727
llvm::sampleprof::SampleProfileReader::getBuffer
MemoryBuffer * getBuffer() const
Definition: SampleProfReader.h:465
llvm::sampleprof::SampleProfileReaderText::hasFormat
static bool hasFormat(const MemoryBuffer &Buffer)
Return true if Buffer is in the format supported by this class.
Definition: SampleProfReader.cpp:376
llvm::sampleprof::SampleProfileReaderExtBinaryBase::setSkipFlatProf
virtual void setSkipFlatProf(bool Skip) override
Don't read profile without context if the flag is set.
Definition: SampleProfReader.h:786
llvm::sampleprof::SampleProfileReader::getNameTable
virtual std::vector< StringRef > * getNameTable()
It includes all the names that have samples either in outline instance or inline instance.
Definition: SampleProfReader.h:485
llvm::sampleprof::SampleContext
Definition: SampleProf.h:501
llvm::sampleprof::HIST_TYPE_CONST_DELTA
@ HIST_TYPE_CONST_DELTA
Definition: SampleProfReader.h:851
llvm::sampleprof::SampleProfileReaderItaniumRemapper::exist
bool exist(StringRef FunctionName)
Query whether there is equivalent in the remapper which has been inserted.
Definition: SampleProfReader.h:292
llvm::DenseSet
Implements a dense probed hash-table based set.
Definition: DenseSet.h:268
SymbolRemappingReader.h
llvm::sampleprof::SPF_Compact_Binary
@ SPF_Compact_Binary
Definition: SampleProf.h:92
llvm::sampleprof::SampleProfileReaderExtBinaryBase::readSecHdrTable
std::error_code readSecHdrTable()
Definition: SampleProfReader.cpp:1205
uint64_t
llvm::sampleprof::SampleProfileReaderExtBinaryBase::getSectionSize
uint64_t getSectionSize(SecType Type)
Get the total size of all Type sections.
Definition: SampleProfReader.cpp:1232
llvm::sampleprof::SampleProfileReader::getSamplesFor
FunctionSamples * getSamplesFor(const Function &F)
Return the samples collected for function F.
Definition: SampleProfReader.h:395
llvm::sampleprof::SampleProfileReaderItaniumRemapper::insert
void insert(StringRef FunctionName)
Insert function name into remapper.
Definition: SampleProfReader.h:288
llvm::sampleprof::SampleProfileReaderGCC
Definition: SampleProfReader.h:858
llvm::sampleprof::FunctionSamples
Representation of the samples collected for a function.
Definition: SampleProf.h:720
llvm::BumpPtrAllocatorImpl
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:63
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::sampleprof::SampleProfileReaderExtBinaryBase::ProfSymList
std::unique_ptr< ProfileSymbolList > ProfSymList
Definition: SampleProfReader.h:723
llvm::sampleprof::SampleProfileReaderGCC::GCOVTagAFDOFileNames
static const uint32_t GCOVTagAFDOFileNames
GCOV tags used to separate sections in the profile file.
Definition: SampleProfReader.h:892
llvm::sampleprof::SampleProfileReaderExtBinaryBase::MD5StringBuf
std::unique_ptr< std::vector< std::string > > MD5StringBuf
If MD5 is used in NameTable section, the section saves uint64_t data.
Definition: SampleProfReader.h:749
llvm::LLVMContext
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
llvm::sampleprof::SampleProfileReader::SampleProfileReader
SampleProfileReader(std::unique_ptr< MemoryBuffer > B, LLVMContext &C, SampleProfileFormat Format=SPF_None)
Definition: SampleProfReader.h:344
llvm::sampleprof::SPF_Ext_Binary
@ SPF_Ext_Binary
Definition: SampleProf.h:94
llvm::sampleprof::SampleProfileReaderGCC::SampleProfileReaderGCC
SampleProfileReaderGCC(std::unique_ptr< MemoryBuffer > B, LLVMContext &C)
Definition: SampleProfReader.h:860
llvm::DenseMap
Definition: DenseMap.h:716
ErrorOr.h
llvm::sampleprof::SampleProfileReader::Format
SampleProfileFormat Format
The format of sample.
Definition: SampleProfReader.h:549
llvm::sampleprof::SampleProfileReader::~SampleProfileReader
virtual ~SampleProfileReader()=default
llvm::sampleprof::SampleProfileReaderItaniumRemapper::SampleProfileReaderItaniumRemapper
SampleProfileReaderItaniumRemapper(std::unique_ptr< MemoryBuffer > B, std::unique_ptr< SymbolRemappingReader > SRR, SampleProfileReader &R)
Definition: SampleProfReader.h:263
llvm::sampleprof::SampleProfileReader::MaskedBitFrom
uint32_t MaskedBitFrom
Zero out the discriminator bits higher than bit MaskedBitFrom (0 based).
Definition: SampleProfReader.h:558
llvm::ProfileSummary
Definition: ProfileSummary.h:45
llvm::sampleprof::SampleProfileReaderBinary::readSampleContextFromTable
virtual ErrorOr< SampleContext > readSampleContextFromTable()
Definition: SampleProfReader.cpp:460
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::sampleprof::SampleProfileReader::ProfileIsPreInlined
bool ProfileIsPreInlined
Whether function profile contains ShouldBeInlined contexts.
Definition: SampleProfReader.h:540
llvm::move
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1663
llvm::sampleprof::SampleProfileReaderExtBinaryBase::readFuncMetadata
std::error_code readFuncMetadata(bool ProfileHasAttribute)
Definition: SampleProfReader.cpp:1145
llvm::sampleprof::HIST_TYPE_AVERAGE
@ HIST_TYPE_AVERAGE
Definition: SampleProfReader.h:853
llvm::sampleprof::FunctionSamples::UseMD5
static bool UseMD5
Whether the profile uses MD5 to represent string.
Definition: SampleProf.h:1123
llvm::sampleprof::SampleProfileReaderGCC::readString
ErrorOr< StringRef > readString()
Definition: SampleProfReader.cpp:1504
llvm::sampleprof::SampleProfileReader::create
static ErrorOr< std::unique_ptr< SampleProfileReader > > create(const std::string Filename, LLVMContext &C, FSDiscriminatorPass P=FSDiscriminatorPass::Base, const std::string RemapFilename="")
Create a sample profile reader appropriate to the file format.
Definition: SampleProfReader.cpp:1787
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
llvm::sampleprof::SampleProfileReader::setSkipFlatProf
virtual void setSkipFlatProf(bool Skip)
Don't read profile without context if the flag is set.
Definition: SampleProfReader.h:493
llvm::DiagnosticInfoSampleProfile
Diagnostic information for the sample profiler.
Definition: DiagnosticInfo.h:291
llvm::sampleprof::SampleProfileReaderExtBinary
Definition: SampleProfReader.h:789
llvm::sampleprof::SampleProfileReaderBinary::readMagicIdent
std::error_code readMagicIdent()
Read the contents of Magic number and Version number.
Definition: SampleProfReader.cpp:1323
llvm::sampleprof::SampleProfileReaderGCC::GCOVTagAFDOFunction
static const uint32_t GCOVTagAFDOFunction
Definition: SampleProfReader.h:893
llvm::sampleprof::SampleProfileReaderBinary::End
const uint8_t * End
Points to the end of the buffer.
Definition: SampleProfReader.h:643
llvm::sampleprof::SampleProfileReaderCompactBinary
Definition: SampleProfReader.h:808
llvm::sampleprof::SampleProfileReader::hasUniqSuffix
virtual bool hasUniqSuffix()
Return whether any name in the profile contains ".__uniq." suffix.
Definition: SampleProfReader.h:495
llvm::sampleprof::SampleProfileReaderExtBinaryBase::readImpl
std::error_code readImpl() override
Read sample profiles in extensible format from the associated file.
Definition: SampleProfReader.cpp:895
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::msf::Magic
static const char Magic[]
Definition: MSFCommon.h:23
llvm::sampleprof::SampleProfileReader::getProfileSymbolList
virtual std::unique_ptr< ProfileSymbolList > getProfileSymbolList()
Definition: SampleProfReader.h:479
uint32_t
llvm::sampleprof::SampleProfileReaderText::readHeader
std::error_code readHeader() override
Read and validate the file header.
Definition: SampleProfReader.h:567
llvm::sampleprof::SampleProfileReader::reportError
void reportError(int64_t LineNumber, const Twine &Msg) const
Report a parse error message.
Definition: SampleProfReader.h:441
llvm::sampleprof::SPF_Text
@ SPF_Text
Definition: SampleProf.h:91
llvm::sampleprof::SampleProfileReader::computeSummary
void computeSummary()
Compute summary for this profile.
Definition: SampleProfReader.cpp:1896
llvm::sampleprof::HIST_TYPE_INTERVAL
@ HIST_TYPE_INTERVAL
Definition: SampleProfReader.h:848
llvm::sampleprof::SampleProfileReader::getFormat
SampleProfileFormat getFormat() const
Return the profile format.
Definition: SampleProfReader.h:468
llvm::sampleprof::SampleProfileReaderBinary::getNameTable
virtual std::vector< StringRef > * getNameTable() override
It includes all the names that have samples either in outline instance or inline instance.
Definition: SampleProfReader.h:595
llvm::sampleprof::SampleProfileReader::getSummary
ProfileSummary & getSummary() const
Return the profile summary.
Definition: SampleProfReader.h:463
llvm::AMDGPU::SendMsg::Msg
const CustomOperand< const MCSubtargetInfo & > Msg[]
Definition: AMDGPUAsmUtils.cpp:39
llvm::sampleprof::SampleProfileReaderRawBinary
Definition: SampleProfReader.h:657
llvm::sampleprof::SampleProfileReader::getProfiles
SampleProfileMap & getProfiles()
Return all the profiles.
Definition: SampleProfReader.h:438
llvm::LLVMContext::diagnose
void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
Definition: LLVMContext.cpp:243
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:83
std
Definition: BitVector.h:851
llvm::sampleprof::SampleProfileReader::Profiles
SampleProfileMap Profiles
Map every function to its associated profile.
Definition: SampleProfReader.h:507
llvm::sampleprof::SampleProfileReader::getOrCreateSamplesFor
FunctionSamples * getOrCreateSamplesFor(const Function &F)
Return the samples collected for function F, create empty FunctionSamples if it doesn't exist.
Definition: SampleProfReader.h:405
get
Should compile to something r4 addze r3 instead we get
Definition: README.txt:24
llvm::sampleprof::SampleProfileReaderGCC::skipNextWord
std::error_code skipNextWord()
Definition: SampleProfReader.cpp:1481
llvm::sampleprof::SampleProfileReader::readImpl
virtual std::error_code readImpl()=0
The implementaion to read sample profiles from the associated file.
llvm::sampleprof::SampleProfileReaderBinary::readSummary
std::error_code readSummary()
Read profile summary.
Definition: SampleProfReader.cpp:1422
llvm::sampleprof::SampleProfileReaderGCC::readHeader
std::error_code readHeader() override
Read and validate the file header.
Definition: SampleProfReader.cpp:1511
llvm::sampleprof::SampleProfileReaderCompactBinary::useMD5
virtual bool useMD5() override
Return whether names in the profile are all MD5 numbers.
Definition: SampleProfReader.h:840
llvm::sampleprof::HIST_TYPE_SINGLE_VALUE
@ HIST_TYPE_SINGLE_VALUE
Definition: SampleProfReader.h:850
llvm::sampleprof::SampleProfileReaderExtBinaryBase::FuncsToUse
DenseSet< StringRef > FuncsToUse
The set containing the functions to use when compiling a module.
Definition: SampleProfReader.h:734
DiagnosticInfo.h
llvm::sampleprof::SecType
SecType
Definition: SampleProf.h:120
llvm::sampleprof::SampleProfileReader
Sample-based profile reader.
Definition: SampleProfReader.h:342
llvm::sampleprof::SampleProfileReaderExtBinaryBase::getFileSize
uint64_t getFileSize()
Get the total size of header and all sections.
Definition: SampleProfReader.cpp:1241
llvm::sampleprof::SampleProfileReaderExtBinaryBase::MD5NameMemStart
const uint8_t * MD5NameMemStart
The starting address of NameTable containing fixed length MD5.
Definition: SampleProfReader.h:740
llvm::sampleprof::SampleProfileReaderExtBinaryBase::readHeader
virtual std::error_code readHeader() override
Read and validate the file header.
Definition: SampleProfReader.cpp:1217
llvm::sampleprof::SampleProfileReader::setModule
void setModule(const Module *Mod)
Definition: SampleProfReader.h:499
llvm::sampleprof::HIST_TYPE_INDIR_CALL_TOPN
@ HIST_TYPE_INDIR_CALL_TOPN
Definition: SampleProfReader.h:855
llvm::sampleprof::SampleProfileReader::profileIsPreInlined
bool profileIsPreInlined() const
Whether input profile contains ShouldBeInlined contexts.
Definition: SampleProfReader.h:477
llvm::sampleprof_error::success
@ success
llvm::sampleprof::SampleProfileReaderBinary::readUnencodedNumber
ErrorOr< T > readUnencodedNumber()
Read a numeric value of type T from the profile.
Definition: SampleProfReader.cpp:427
llvm::sampleprof::FunctionSamples::getCanonicalFnName
static StringRef getCanonicalFnName(const Function &F)
Return the canonical name for a function, taking into account suffix elision policy attributes.
Definition: SampleProf.h:1022
llvm::sampleprof::SampleProfileReaderExtBinaryBase::SkipFlatProf
bool SkipFlatProf
If SkipFlatProf is true, skip the sections with SecFlagFlat flag.
Definition: SampleProfReader.h:757
llvm::sampleprof::SampleProfileReaderBinary::readNumber
ErrorOr< T > readNumber()
Read a numeric value of type T from the profile.
Definition: SampleProfReader.cpp:392
llvm::sampleprof::SampleProfileReader::dumpSectionInfo
virtual bool dumpSectionInfo(raw_ostream &OS=dbgs())
Definition: SampleProfReader.h:486
llvm::sampleprof::SampleProfileReaderBinary::readImpl
std::error_code readImpl() override
Read sample profiles from the associated file.
Definition: SampleProfReader.cpp:610
llvm::sampleprof::SampleProfileReaderExtBinaryBase::readFuncProfiles
std::error_code readFuncProfiles()
Definition: SampleProfReader.cpp:755
llvm::sampleprof::SampleProfileReader::Ctx
LLVMContext & Ctx
LLVM context used to emit diagnostics.
Definition: SampleProfReader.h:510
SmallVector.h
llvm::sampleprof::SampleProfileReaderCompactBinary::collectFuncsFromModule
bool collectFuncsFromModule() override
Collect functions with definitions in Module M.
Definition: SampleProfReader.cpp:1395
llvm::sampleprof::SampleProfileReaderBinary
Definition: SampleProfReader.h:581
llvm::ErrorOr
Represents either an error or a value T.
Definition: ErrorOr.h:56
llvm::sampleprof::SampleProfileReader::useMD5
virtual bool useMD5()
Return whether names in the profile are all MD5 numbers.
Definition: SampleProfReader.h:489
llvm::sampleprof::SampleProfileReaderExtBinaryBase::readOneSection
virtual std::error_code readOneSection(const uint8_t *Start, uint64_t Size, const SecHdrTableEntry &Entry)
Definition: SampleProfReader.cpp:646
llvm::sampleprof::SampleProfileReaderExtBinaryBase::readFuncOffsetTable
std::error_code readFuncOffsetTable()
Definition: SampleProfReader.cpp:720
llvm::sampleprof::SampleProfileReader::dumpFunctionProfile
void dumpFunctionProfile(SampleContext FContext, raw_ostream &OS=dbgs())
Print the profile for FContext on stream OS.
Definition: SampleProfReader.cpp:62
llvm::sampleprof::SampleProfileReaderExtBinaryBase::readProfileSymbolList
std::error_code readProfileSymbolList()
Definition: SampleProfReader.cpp:855
llvm::sampleprof::SampleProfileReaderItaniumRemapper
SampleProfileReaderItaniumRemapper remaps the profile data from a sample profile data reader,...
Definition: SampleProfReader.h:261
llvm::sampleprof::SampleProfileReaderCompactBinary::hasFormat
static bool hasFormat(const MemoryBuffer &Buffer)
Return true if Buffer is in the format supported by this class.
Definition: SampleProfReader.cpp:1474
llvm::sampleprof::SampleProfileReaderItaniumRemapper::hasApplied
bool hasApplied()
Definition: SampleProfReader.h:285
llvm::getFSPassBitEnd
static unsigned getFSPassBitEnd(FSDiscriminatorPass P)
Definition: Discriminator.h:89
llvm::sampleprof::SampleProfileReader::setDiscriminatorMaskedBitFrom
void setDiscriminatorMaskedBitFrom(FSDiscriminatorPass P)
Set the bits for FS discriminators.
Definition: SampleProfReader.h:356
llvm::sampleprof::SampleProfileReader::ProfileIsCS
bool ProfileIsCS
Whether function profiles are context-sensitive flat profiles.
Definition: SampleProfReader.h:537
LLVMContext.h
llvm::GCOVBuffer
GCOVBuffer - A wrapper around MemoryBuffer to provide GCOV specific read operations.
Definition: GCOV.h:72
llvm::sampleprof::SampleProfileReaderExtBinaryBase::dumpSectionInfo
virtual bool dumpSectionInfo(raw_ostream &OS=dbgs()) override
Definition: SampleProfReader.cpp:1304
Mod
Module * Mod
Definition: PassBuilderBindings.cpp:54
llvm::sampleprof::HIST_TYPE_POW2
@ HIST_TYPE_POW2
Definition: SampleProfReader.h:849
llvm::sampleprof::SampleProfileReaderExtBinary::hasFormat
static bool hasFormat(const MemoryBuffer &Buffer)
Return true if Buffer is in the format supported by this class.
Definition: SampleProfReader.cpp:1467
llvm::sampleprof::SampleProfileReaderExtBinaryBase::OrderedFuncOffsets
std::unique_ptr< std::vector< std::pair< SampleContext, uint64_t > > > OrderedFuncOffsets
Function offset mapping ordered by contexts.
Definition: SampleProfReader.h:731
llvm::sampleprof::SampleProfileReaderGCC::readImpl
std::error_code readImpl() override
Read sample profiles from the associated file.
Definition: SampleProfReader.cpp:1707
llvm::sampleprof::SampleProfileReaderBinary::readStringIndex
ErrorOr< uint32_t > readStringIndex(T &Table)
Read the string index and check whether it overflows the table.
Definition: SampleProfReader.cpp:442
llvm::sampleprof::SampleProfileReaderBinary::Data
const uint8_t * Data
Points to the current location in the buffer.
Definition: SampleProfReader.h:640
Debug.h
llvm::sampleprof::SampleProfileReaderBinary::readHeader
virtual std::error_code readHeader() override
Read and validate the file header.
Definition: SampleProfReader.cpp:1341
llvm::sampleprof::SampleProfileReader::Buffer
std::unique_ptr< MemoryBuffer > Buffer
Memory buffer holding the profile file.
Definition: SampleProfReader.h:513
llvm::sampleprof::SampleProfileReaderCompactBinary::SampleProfileReaderCompactBinary
SampleProfileReaderCompactBinary(std::unique_ptr< MemoryBuffer > B, LLVMContext &C)
Definition: SampleProfReader.h:825
llvm::sampleprof::HistType
HistType
Definition: SampleProfReader.h:847
llvm::sampleprof::Base
@ Base
Definition: Discriminator.h:58
llvm::sampleprof::SampleProfileReaderExtBinaryBase::collectFuncsFromModule
bool collectFuncsFromModule() override
Collect functions with definitions in Module M.
Definition: SampleProfReader.cpp:711
llvm::sampleprof::SampleProfileReader::ProfileIsProbeBased
bool ProfileIsProbeBased
Whether samples are collected based on pseudo probes.
Definition: SampleProfReader.h:534
llvm::sampleprof::SampleProfileReaderBinary::at_eof
bool at_eof() const
Return true if we've reached the end of file.
Definition: SampleProfReader.h:622