LLVM  10.0.0svn
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 //
31 // This is a nested tree in which the identation represents the nesting level
32 // of the inline stack. There are no blank lines in the file. And the spacing
33 // within a single line is fixed. Additional spaces will result in an error
34 // while reading the file.
35 //
36 // Any line starting with the '#' character is completely ignored.
37 //
38 // Inlined calls are represented with indentation. The Inline stack is a
39 // stack of source locations in which the top of the stack represents the
40 // leaf function, and the bottom of the stack represents the actual
41 // symbol to which the instruction belongs.
42 //
43 // Function names must be mangled in order for the profile loader to
44 // match them in the current translation unit. The two numbers in the
45 // function header specify how many total samples were accumulated in the
46 // function (first number), and the total number of samples accumulated
47 // in the prologue of the function (second number). This head sample
48 // count provides an indicator of how frequently the function is invoked.
49 //
50 // There are two types of lines in the function body.
51 //
52 // * Sampled line represents the profile information of a source location.
53 // * Callsite line represents the profile information of a callsite.
54 //
55 // Each sampled line may contain several items. Some are optional (marked
56 // below):
57 //
58 // a. Source line offset. This number represents the line number
59 // in the function where the sample was collected. The line number is
60 // always relative to the line where symbol of the function is
61 // defined. So, if the function has its header at line 280, the offset
62 // 13 is at line 293 in the file.
63 //
64 // Note that this offset should never be a negative number. This could
65 // happen in cases like macros. The debug machinery will register the
66 // line number at the point of macro expansion. So, if the macro was
67 // expanded in a line before the start of the function, the profile
68 // converter should emit a 0 as the offset (this means that the optimizers
69 // will not be able to associate a meaningful weight to the instructions
70 // in the macro).
71 //
72 // b. [OPTIONAL] Discriminator. This is used if the sampled program
73 // was compiled with DWARF discriminator support
74 // (http://wiki.dwarfstd.org/index.php?title=Path_Discriminators).
75 // DWARF discriminators are unsigned integer values that allow the
76 // compiler to distinguish between multiple execution paths on the
77 // same source line location.
78 //
79 // For example, consider the line of code ``if (cond) foo(); else bar();``.
80 // If the predicate ``cond`` is true 80% of the time, then the edge
81 // into function ``foo`` should be considered to be taken most of the
82 // time. But both calls to ``foo`` and ``bar`` are at the same source
83 // line, so a sample count at that line is not sufficient. The
84 // compiler needs to know which part of that line is taken more
85 // frequently.
86 //
87 // This is what discriminators provide. In this case, the calls to
88 // ``foo`` and ``bar`` will be at the same line, but will have
89 // different discriminator values. This allows the compiler to correctly
90 // set edge weights into ``foo`` and ``bar``.
91 //
92 // c. Number of samples. This is an integer quantity representing the
93 // number of samples collected by the profiler at this source
94 // location.
95 //
96 // d. [OPTIONAL] Potential call targets and samples. If present, this
97 // line contains a call instruction. This models both direct and
98 // number of samples. For example,
99 //
100 // 130: 7 foo:3 bar:2 baz:7
101 //
102 // The above means that at relative line offset 130 there is a call
103 // instruction that calls one of ``foo()``, ``bar()`` and ``baz()``,
104 // with ``baz()`` being the relatively more frequently called target.
105 //
106 // Each callsite line may contain several items. Some are optional.
107 //
108 // a. Source line offset. This number represents the line number of the
109 // callsite that is inlined in the profiled binary.
110 //
111 // b. [OPTIONAL] Discriminator. Same as the discriminator for sampled line.
112 //
113 // c. Number of samples. This is an integer quantity representing the
114 // total number of samples collected for the inlined instance at this
115 // callsite
116 //
117 //
118 // Binary format
119 // -------------
120 //
121 // This is a more compact encoding. Numbers are encoded as ULEB128 values
122 // and all strings are encoded in a name table. The file is organized in
123 // the following sections:
124 //
125 // MAGIC (uint64_t)
126 // File identifier computed by function SPMagic() (0x5350524f463432ff)
127 //
128 // VERSION (uint32_t)
129 // File format version number computed by SPVersion()
130 //
131 // SUMMARY
132 // TOTAL_COUNT (uint64_t)
133 // Total number of samples in the profile.
134 // MAX_COUNT (uint64_t)
135 // Maximum value of samples on a line.
136 // MAX_FUNCTION_COUNT (uint64_t)
137 // Maximum number of samples at function entry (head samples).
138 // NUM_COUNTS (uint64_t)
139 // Number of lines with samples.
140 // NUM_FUNCTIONS (uint64_t)
141 // Number of functions with samples.
142 // NUM_DETAILED_SUMMARY_ENTRIES (size_t)
143 // Number of entries in detailed summary
144 // DETAILED_SUMMARY
145 // A list of detailed summary entry. Each entry consists of
146 // CUTOFF (uint32_t)
147 // Required percentile of total sample count expressed as a fraction
148 // multiplied by 1000000.
149 // MIN_COUNT (uint64_t)
150 // The minimum number of samples required to reach the target
151 // CUTOFF.
152 // NUM_COUNTS (uint64_t)
153 // Number of samples to get to the desrired percentile.
154 //
155 // NAME TABLE
156 // SIZE (uint32_t)
157 // Number of entries in the name table.
158 // NAMES
159 // A NUL-separated list of SIZE strings.
160 //
161 // FUNCTION BODY (one for each uninlined function body present in the profile)
162 // HEAD_SAMPLES (uint64_t) [only for top-level functions]
163 // Total number of samples collected at the head (prologue) of the
164 // function.
165 // NOTE: This field should only be present for top-level functions
166 // (i.e., not inlined into any caller). Inlined function calls
167 // have no prologue, so they don't need this.
168 // NAME_IDX (uint32_t)
169 // Index into the name table indicating the function name.
170 // SAMPLES (uint64_t)
171 // Total number of samples collected in this function.
172 // NRECS (uint32_t)
173 // Total number of sampling records this function's profile.
174 // BODY RECORDS
175 // A list of NRECS entries. Each entry contains:
176 // OFFSET (uint32_t)
177 // Line offset from the start of the function.
178 // DISCRIMINATOR (uint32_t)
179 // Discriminator value (see description of discriminators
180 // in the text format documentation above).
181 // SAMPLES (uint64_t)
182 // Number of samples collected at this location.
183 // NUM_CALLS (uint32_t)
184 // Number of non-inlined function calls made at this location. In the
185 // case of direct calls, this number will always be 1. For indirect
186 // calls (virtual functions and function pointers) this will
187 // represent all the actual functions called at runtime.
188 // CALL_TARGETS
189 // A list of NUM_CALLS entries for each called function:
190 // NAME_IDX (uint32_t)
191 // Index into the name table with the callee name.
192 // SAMPLES (uint64_t)
193 // Number of samples collected at the call site.
194 // NUM_INLINED_FUNCTIONS (uint32_t)
195 // Number of callees inlined into this function.
196 // INLINED FUNCTION RECORDS
197 // A list of NUM_INLINED_FUNCTIONS entries describing each of the inlined
198 // callees.
199 // OFFSET (uint32_t)
200 // Line offset from the start of the function.
201 // DISCRIMINATOR (uint32_t)
202 // Discriminator value (see description of discriminators
203 // in the text format documentation above).
204 // FUNCTION BODY
205 // A FUNCTION BODY entry describing the inlined function.
206 //===----------------------------------------------------------------------===//
207 
208 #ifndef LLVM_PROFILEDATA_SAMPLEPROFREADER_H
209 #define LLVM_PROFILEDATA_SAMPLEPROFREADER_H
210 
211 #include "llvm/ADT/SmallVector.h"
212 #include "llvm/ADT/StringMap.h"
213 #include "llvm/ADT/StringRef.h"
214 #include "llvm/ADT/Twine.h"
215 #include "llvm/IR/DiagnosticInfo.h"
216 #include "llvm/IR/Function.h"
217 #include "llvm/IR/LLVMContext.h"
218 #include "llvm/IR/ProfileSummary.h"
219 #include "llvm/ProfileData/GCOV.h"
221 #include "llvm/Support/Debug.h"
222 #include "llvm/Support/ErrorOr.h"
225 #include <algorithm>
226 #include <cstdint>
227 #include <memory>
228 #include <string>
229 #include <system_error>
230 #include <vector>
231 
232 namespace llvm {
233 
234 class raw_ostream;
235 
236 namespace sampleprof {
237 
238 /// Sample-based profile reader.
239 ///
240 /// Each profile contains sample counts for all the functions
241 /// executed. Inside each function, statements are annotated with the
242 /// collected samples on all the instructions associated with that
243 /// statement.
244 ///
245 /// For this to produce meaningful data, the program needs to be
246 /// compiled with some debug information (at minimum, line numbers:
247 /// -gline-tables-only). Otherwise, it will be impossible to match IR
248 /// instructions to the line numbers collected by the profiler.
249 ///
250 /// From the profile file, we are interested in collecting the
251 /// following information:
252 ///
253 /// * A list of functions included in the profile (mangled names).
254 ///
255 /// * For each function F:
256 /// 1. The total number of samples collected in F.
257 ///
258 /// 2. The samples collected at each line in F. To provide some
259 /// protection against source code shuffling, line numbers should
260 /// be relative to the start of the function.
261 ///
262 /// The reader supports two file formats: text and binary. The text format
263 /// is useful for debugging and testing, while the binary format is more
264 /// compact and I/O efficient. They can both be used interchangeably.
266 public:
267  SampleProfileReader(std::unique_ptr<MemoryBuffer> B, LLVMContext &C,
269  : Profiles(0), Ctx(C), Buffer(std::move(B)), Format(Format) {}
270 
271  virtual ~SampleProfileReader() = default;
272 
273  /// Read and validate the file header.
274  virtual std::error_code readHeader() = 0;
275 
276  /// Read sample profiles from the associated file.
277  virtual std::error_code read() = 0;
278 
279  /// Print the profile for \p FName on stream \p OS.
280  void dumpFunctionProfile(StringRef FName, raw_ostream &OS = dbgs());
281 
282  virtual void collectFuncsToUse(const Module &M) {}
283 
284  /// Print all the profiles on stream \p OS.
285  void dump(raw_ostream &OS = dbgs());
286 
287  /// Return the samples collected for function \p F.
289  // The function name may have been updated by adding suffix. Call
290  // a helper to (optionally) strip off suffixes so that we can
291  // match against the original function name in the profile.
293  return getSamplesFor(CanonName);
294  }
295 
296  /// Return the samples collected for function \p F.
298  std::string FGUID;
299  Fname = getRepInFormat(Fname, getFormat(), FGUID);
300  auto It = Profiles.find(Fname);
301  if (It != Profiles.end())
302  return &It->second;
303  return nullptr;
304  }
305 
306  /// Return all the profiles.
308 
309  /// Report a parse error message.
310  void reportError(int64_t LineNumber, Twine Msg) const {
311  Ctx.diagnose(DiagnosticInfoSampleProfile(Buffer->getBufferIdentifier(),
312  LineNumber, Msg));
313  }
314 
315  /// Create a sample profile reader appropriate to the file format.
317  create(const Twine &Filename, LLVMContext &C);
318 
319  /// Create a sample profile reader from the supplied memory buffer.
321  create(std::unique_ptr<MemoryBuffer> &B, LLVMContext &C);
322 
323  /// Return the profile summary.
324  ProfileSummary &getSummary() { return *(Summary.get()); }
325 
326  /// \brief Return the profile format.
328 
329  virtual std::unique_ptr<ProfileSymbolList> getProfileSymbolList() {
330  return nullptr;
331  };
332 
333  /// It includes all the names that have samples either in outline instance
334  /// or inline instance.
335  virtual std::vector<StringRef> *getNameTable() { return nullptr; }
336  virtual bool dumpSectionInfo(raw_ostream &OS = dbgs()) { return false; };
337 
338 protected:
339  /// Map every function to its associated profile.
340  ///
341  /// The profile of every function executed at runtime is collected
342  /// in the structure FunctionSamples. This maps function objects
343  /// to their corresponding profiles.
345 
346  /// LLVM context used to emit diagnostics.
348 
349  /// Memory buffer holding the profile file.
350  std::unique_ptr<MemoryBuffer> Buffer;
351 
352  /// Profile summary information.
353  std::unique_ptr<ProfileSummary> Summary;
354 
355  /// Take ownership of the summary of this reader.
356  static std::unique_ptr<ProfileSummary>
358  return std::move(Reader.Summary);
359  }
360 
361  /// Compute summary for this profile.
362  void computeSummary();
363 
364  /// \brief The format of sample.
366 };
367 
369 public:
370  SampleProfileReaderText(std::unique_ptr<MemoryBuffer> B, LLVMContext &C)
371  : SampleProfileReader(std::move(B), C, SPF_Text) {}
372 
373  /// Read and validate the file header.
374  std::error_code readHeader() override { return sampleprof_error::success; }
375 
376  /// Read sample profiles from the associated file.
377  std::error_code read() override;
378 
379  /// Return true if \p Buffer is in the format supported by this class.
380  static bool hasFormat(const MemoryBuffer &Buffer);
381 };
382 
384 public:
385  SampleProfileReaderBinary(std::unique_ptr<MemoryBuffer> B, LLVMContext &C,
387  : SampleProfileReader(std::move(B), C, Format) {}
388 
389  /// Read and validate the file header.
390  virtual std::error_code readHeader() override;
391 
392  /// Read sample profiles from the associated file.
393  std::error_code read() override;
394 
395  /// It includes all the names that have samples either in outline instance
396  /// or inline instance.
397  virtual std::vector<StringRef> *getNameTable() override { return &NameTable; }
398 
399 protected:
400  /// Read a numeric value of type T from the profile.
401  ///
402  /// If an error occurs during decoding, a diagnostic message is emitted and
403  /// EC is set.
404  ///
405  /// \returns the read value.
406  template <typename T> ErrorOr<T> readNumber();
407 
408  /// Read a numeric value of type T from the profile. The value is saved
409  /// without encoded.
410  template <typename T> ErrorOr<T> readUnencodedNumber();
411 
412  /// Read a string from the profile.
413  ///
414  /// If an error occurs during decoding, a diagnostic message is emitted and
415  /// EC is set.
416  ///
417  /// \returns the read value.
419 
420  /// Read the string index and check whether it overflows the table.
421  template <typename T> inline ErrorOr<uint32_t> readStringIndex(T &Table);
422 
423  /// Return true if we've reached the end of file.
424  bool at_eof() const { return Data >= End; }
425 
426  /// Read the next function profile instance.
427  std::error_code readFuncProfile();
428 
429  /// Read the contents of the given profile instance.
430  std::error_code readProfile(FunctionSamples &FProfile);
431 
432  /// Read the contents of Magic number and Version number.
433  std::error_code readMagicIdent();
434 
435  /// Read profile summary.
436  std::error_code readSummary();
437 
438  /// Read the whole name table.
439  virtual std::error_code readNameTable();
440 
441  /// Points to the current location in the buffer.
442  const uint8_t *Data = nullptr;
443 
444  /// Points to the end of the buffer.
445  const uint8_t *End = nullptr;
446 
447  /// Function name table.
448  std::vector<StringRef> NameTable;
449 
450  /// Read a string indirectly via the name table.
451  virtual ErrorOr<StringRef> readStringFromTable();
452 
453 private:
454  std::error_code readSummaryEntry(std::vector<ProfileSummaryEntry> &Entries);
455  virtual std::error_code verifySPMagic(uint64_t Magic) = 0;
456 };
457 
459 private:
460  virtual std::error_code verifySPMagic(uint64_t Magic) override;
461 
462 public:
463  SampleProfileReaderRawBinary(std::unique_ptr<MemoryBuffer> B, LLVMContext &C,
465  : SampleProfileReaderBinary(std::move(B), C, Format) {}
466 
467  /// \brief Return true if \p Buffer is in the format supported by this class.
468  static bool hasFormat(const MemoryBuffer &Buffer);
469 };
470 
471 /// SampleProfileReaderExtBinaryBase/SampleProfileWriterExtBinaryBase defines
472 /// the basic structure of the extensible binary format.
473 /// The format is organized in sections except the magic and version number
474 /// at the beginning. There is a section table before all the sections, and
475 /// each entry in the table describes the entry type, start, size and
476 /// attributes. The format in each section is defined by the section itself.
477 ///
478 /// It is easy to add a new section while maintaining the backward
479 /// compatibility of the profile. Nothing extra needs to be done. If we want
480 /// to extend an existing section, like add cache misses information in
481 /// addition to the sample count in the profile body, we can add a new section
482 /// with the extension and retire the existing section, and we could choose
483 /// to keep the parser of the old section if we want the reader to be able
484 /// to read both new and old format profile.
485 ///
486 /// SampleProfileReaderExtBinary/SampleProfileWriterExtBinary define the
487 /// commonly used sections of a profile in extensible binary format. It is
488 /// possible to define other types of profile inherited from
489 /// SampleProfileReaderExtBinaryBase/SampleProfileWriterExtBinaryBase.
491 protected:
492  std::vector<SecHdrTableEntry> SecHdrTable;
493  std::unique_ptr<ProfileSymbolList> ProfSymList;
494  std::error_code readSecHdrTableEntry();
495  std::error_code readSecHdrTable();
496  virtual std::error_code readHeader() override;
497  virtual std::error_code verifySPMagic(uint64_t Magic) override = 0;
498  virtual std::error_code readOneSection(const uint8_t *Start, uint64_t Size,
499  SecType Type) = 0;
500 
501 public:
502  SampleProfileReaderExtBinaryBase(std::unique_ptr<MemoryBuffer> B,
504  : SampleProfileReaderBinary(std::move(B), C, Format) {}
505 
506  /// Read sample profiles in extensible format from the associated file.
507  std::error_code read() override;
508 
509  /// Get the total size of all \p Type sections.
510  uint64_t getSectionSize(SecType Type);
511  /// Get the total size of header and all sections.
512  uint64_t getFileSize();
513  virtual bool dumpSectionInfo(raw_ostream &OS = dbgs()) override;
514 };
515 
517 private:
518  virtual std::error_code verifySPMagic(uint64_t Magic) override;
519  virtual std::error_code readOneSection(const uint8_t *Start, uint64_t Size,
520  SecType Type) override;
521  std::error_code readProfileSymbolList();
522 
523 public:
524  SampleProfileReaderExtBinary(std::unique_ptr<MemoryBuffer> B, LLVMContext &C,
526  : SampleProfileReaderExtBinaryBase(std::move(B), C, Format) {}
527 
528  /// \brief Return true if \p Buffer is in the format supported by this class.
529  static bool hasFormat(const MemoryBuffer &Buffer);
530 
531  virtual std::unique_ptr<ProfileSymbolList> getProfileSymbolList() override {
532  return std::move(ProfSymList);
533  };
534 };
535 
537 private:
538  /// Function name table.
539  std::vector<std::string> NameTable;
540  /// The table mapping from function name to the offset of its FunctionSample
541  /// towards file start.
542  DenseMap<StringRef, uint64_t> FuncOffsetTable;
543  /// The set containing the functions to use when compiling a module.
544  DenseSet<StringRef> FuncsToUse;
545  /// Use all functions from the input profile.
546  bool UseAllFuncs = true;
547  virtual std::error_code verifySPMagic(uint64_t Magic) override;
548  virtual std::error_code readNameTable() override;
549  /// Read a string indirectly via the name table.
550  virtual ErrorOr<StringRef> readStringFromTable() override;
551  virtual std::error_code readHeader() override;
552  std::error_code readFuncOffsetTable();
553 
554 public:
555  SampleProfileReaderCompactBinary(std::unique_ptr<MemoryBuffer> B,
556  LLVMContext &C)
558 
559  /// \brief Return true if \p Buffer is in the format supported by this class.
560  static bool hasFormat(const MemoryBuffer &Buffer);
561 
562  /// Read samples only for functions to use.
563  std::error_code read() override;
564 
565  /// Collect functions to be used when compiling Module \p M.
566  void collectFuncsToUse(const Module &M) override;
567 };
568 
570 
571 // Supported histogram types in GCC. Currently, we only need support for
572 // call target histograms.
573 enum HistType {
582 };
583 
585 public:
586  SampleProfileReaderGCC(std::unique_ptr<MemoryBuffer> B, LLVMContext &C)
587  : SampleProfileReader(std::move(B), C, SPF_GCC),
588  GcovBuffer(Buffer.get()) {}
589 
590  /// Read and validate the file header.
591  std::error_code readHeader() override;
592 
593  /// Read sample profiles from the associated file.
594  std::error_code read() override;
595 
596  /// Return true if \p Buffer is in the format supported by this class.
597  static bool hasFormat(const MemoryBuffer &Buffer);
598 
599 protected:
600  std::error_code readNameTable();
601  std::error_code readOneFunctionProfile(const InlineCallStack &InlineStack,
602  bool Update, uint32_t Offset);
603  std::error_code readFunctionProfiles();
604  std::error_code skipNextWord();
605  template <typename T> ErrorOr<T> readNumber();
607 
608  /// Read the section tag and check that it's the same as \p Expected.
609  std::error_code readSectionTag(uint32_t Expected);
610 
611  /// GCOV buffer containing the profile.
613 
614  /// Function names in this profile.
615  std::vector<std::string> Names;
616 
617  /// GCOV tags used to separate sections in the profile file.
618  static const uint32_t GCOVTagAFDOFileNames = 0xaa000000;
619  static const uint32_t GCOVTagAFDOFunction = 0xac000000;
620 };
621 
622 /// A profile data reader proxy that remaps the profile data from another
623 /// sample profile data reader, by applying a provided set of equivalences
624 /// between components of the symbol names in the profile.
626 public:
628  std::unique_ptr<MemoryBuffer> B, LLVMContext &C,
629  std::unique_ptr<SampleProfileReader> Underlying)
630  : SampleProfileReader(std::move(B), C, Underlying->getFormat()) {
631  Profiles = std::move(Underlying->getProfiles());
632  Summary = takeSummary(*Underlying);
633  // Keep the underlying reader alive; the profile data may contain
634  // StringRefs referencing names in its name table.
635  UnderlyingReader = std::move(Underlying);
636  }
637 
638  /// Create a remapped sample profile from the given remapping file and
639  /// underlying samples.
641  create(const Twine &Filename, LLVMContext &C,
642  std::unique_ptr<SampleProfileReader> Underlying);
643 
644  /// Read and validate the file header.
645  std::error_code readHeader() override { return sampleprof_error::success; }
646 
647  /// Read remapping file and apply it to the sample profile.
648  std::error_code read() override;
649 
650  /// Return the samples collected for function \p F.
651  FunctionSamples *getSamplesFor(StringRef FunctionName) override;
653 
654 private:
655  SymbolRemappingReader Remappings;
657  std::unique_ptr<SampleProfileReader> UnderlyingReader;
658 };
659 
660 } // end namespace sampleprof
661 
662 } // end namespace llvm
663 
664 #endif // LLVM_PROFILEDATA_SAMPLEPROFREADER_H
virtual bool dumpSectionInfo(raw_ostream &OS=dbgs())
std::vector< std::string > Names
Function names in this profile.
uint64_t CallInst * C
std::unique_ptr< MemoryBuffer > Buffer
Memory buffer holding the profile file.
Represents either an error or a value T.
Definition: ErrorOr.h:56
This class represents lattice values for constants.
Definition: AllocatorList.h:23
static StringRef getRepInFormat(StringRef Name, SampleProfileFormat Format, std::string &GUIDBuf)
Definition: SampleProf.h:104
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:65
Implements a dense probed hash-table based set.
Definition: DenseSet.h:249
static ErrorOr< std::unique_ptr< SampleProfileReader > > create(const Twine &Filename, LLVMContext &C)
Create a sample profile reader appropriate to the file format.
F(f)
GCOVBuffer - A wrapper around MemoryBuffer to provide GCOV specific read operations.
Definition: GCOV.h:67
virtual void collectFuncsToUse(const Module &M)
Representation of the samples collected for a function.
Definition: SampleProf.h:283
Definition: BitVector.h:937
virtual std::error_code read()=0
Read sample profiles from the associated file.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:80
static std::unique_ptr< ProfileSummary > takeSummary(SampleProfileReader &Reader)
Take ownership of the summary of this reader.
SampleProfileReaderRawBinary(std::unique_ptr< MemoryBuffer > B, LLVMContext &C, SampleProfileFormat Format=SPF_Binary)
StringMap< FunctionSamples > Profiles
Map every function to its associated profile.
SampleProfileReader(std::unique_ptr< MemoryBuffer > B, LLVMContext &C, SampleProfileFormat Format=SPF_None)
Tagged union holding either a T or a Error.
Definition: yaml2obj.h:21
SampleProfileFormat getFormat()
Return the profile format.
SampleProfileReaderGCC(std::unique_ptr< MemoryBuffer > B, LLVMContext &C)
virtual FunctionSamples * getSamplesFor(StringRef Fname)
Return the samples collected for function F.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
std::error_code readHeader() override
Read and validate the file header.
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:64
FunctionSamples * getSamplesFor(const Function &F)
Return the samples collected for function F.
LLVMContext & Ctx
LLVM context used to emit diagnostics.
SampleProfileFormat Format
The format of sample.
SampleProfileReaderExtBinary(std::unique_ptr< MemoryBuffer > B, LLVMContext &C, SampleProfileFormat Format=SPF_Ext_Binary)
static StringRef getCanonicalFnName(const Function &F)
Return the canonical name for a function, taking into account suffix elision policy attributes...
Definition: SampleProf.h:482
std::underlying_type< E >::type Underlying(E Val)
Check that Val is in range for E, and return Val cast to E&#39;s underlying type.
Definition: BitmaskEnum.h:90
A profile data reader proxy that remaps the profile data from another sample profile data reader...
virtual std::vector< StringRef > * getNameTable() override
It includes all the names that have samples either in outline instance or inline instance.
SampleProfileReaderExtBinaryBase(std::unique_ptr< MemoryBuffer > B, LLVMContext &C, SampleProfileFormat Format)
virtual std::unique_ptr< ProfileSymbolList > getProfileSymbolList() override
SampleProfileReaderExtBinaryBase/SampleProfileWriterExtBinaryBase defines the basic structure of the ...
void dumpFunctionProfile(StringRef FName, raw_ostream &OS=dbgs())
Print the profile for FName on stream OS.
static const char *const Magic
Definition: Archive.cpp:41
virtual std::unique_ptr< ProfileSymbolList > getProfileSymbolList()
std::unique_ptr< ProfileSymbolList > ProfSymList
bool at_eof() const
Return true if we&#39;ve reached the end of file.
virtual std::error_code readHeader()=0
Read and validate the file header.
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:837
std::vector< StringRef > NameTable
Function name table.
virtual std::vector< StringRef > * getNameTable()
It includes all the names that have samples either in outline instance or inline instance.
This interface provides simple read-only access to a block of memory, and provides simple methods for...
Definition: MemoryBuffer.h:41
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
Definition: StringMap.h:219
static StringRef readString(WasmObjectFile::ReadContext &Ctx)
StringMap< FunctionSamples > & getProfiles()
Return all the profiles.
SampleProfileReaderItaniumRemapper(std::unique_ptr< MemoryBuffer > B, LLVMContext &C, std::unique_ptr< SampleProfileReader > Underlying)
Reader for symbol remapping files.
std::error_code readHeader() override
Read and validate the file header.
uint32_t Size
Definition: Profile.cpp:46
void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
Provides ErrorOr<T> smart pointer.
SampleProfileReaderText(std::unique_ptr< MemoryBuffer > B, LLVMContext &C)
SampleProfileReaderBinary(std::unique_ptr< MemoryBuffer > B, LLVMContext &C, SampleProfileFormat Format=SPF_None)
void reportError(int64_t LineNumber, Twine Msg) const
Report a parse error message.
Sample-based profile reader.
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
GCOVBuffer GcovBuffer
GCOV buffer containing the profile.
Diagnostic information for the sample profiler.
void computeSummary()
Compute summary for this profile.
void dump(raw_ostream &OS=dbgs())
Print all the profiles on stream OS.
ProfileSummary & getSummary()
Return the profile summary.
SampleProfileReaderCompactBinary(std::unique_ptr< MemoryBuffer > B, LLVMContext &C)
std::unique_ptr< ProfileSummary > Summary
Profile summary information.