LLVM  14.0.0git
SampleProfWriter.h
Go to the documentation of this file.
1 //===- SampleProfWriter.h - Write 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 writing sample profiles.
10 //
11 //===----------------------------------------------------------------------===//
12 #ifndef LLVM_PROFILEDATA_SAMPLEPROFWRITER_H
13 #define LLVM_PROFILEDATA_SAMPLEPROFWRITER_H
14 
15 #include "llvm/ADT/MapVector.h"
16 #include "llvm/ADT/StringMap.h"
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/ADT/StringSet.h"
19 #include "llvm/IR/ProfileSummary.h"
21 #include "llvm/Support/ErrorOr.h"
23 #include <algorithm>
24 #include <cstdint>
25 #include <memory>
26 #include <set>
27 #include <system_error>
28 #include <unordered_set>
29 
30 namespace llvm {
31 namespace sampleprof {
32 
35  // The layout splits profile with context information from profile without
36  // context information. When Thinlto is enabled, ThinLTO postlink phase only
37  // has to load profile with context information and can skip the other part.
40 };
41 
42 /// Sample-based profile writer. Base class.
44 public:
45  virtual ~SampleProfileWriter() = default;
46 
47  /// Write sample profiles in \p S.
48  ///
49  /// \returns status code of the file update operation.
50  virtual std::error_code writeSample(const FunctionSamples &S) = 0;
51 
52  /// Write all the sample profiles in the given map of samples.
53  ///
54  /// \returns status code of the file update operation.
55  virtual std::error_code write(const SampleProfileMap &ProfileMap);
56 
58 
59  /// Profile writer factory.
60  ///
61  /// Create a new file writer based on the value of \p Format.
64 
65  /// Create a new stream writer based on the value of \p Format.
66  /// For testing.
68  create(std::unique_ptr<raw_ostream> &OS, SampleProfileFormat Format);
69 
71  virtual void setToCompressAllSections() {}
72  virtual void setUseMD5() {}
73  virtual void setPartialProfile() {}
74  virtual void resetSecLayout(SectionLayout SL) {}
75 
76 protected:
77  SampleProfileWriter(std::unique_ptr<raw_ostream> &OS)
78  : OutputStream(std::move(OS)) {}
79 
80  /// Write a file header for the profile file.
81  virtual std::error_code writeHeader(const SampleProfileMap &ProfileMap) = 0;
82 
83  // Write function profiles to the profile file.
84  virtual std::error_code writeFuncProfiles(const SampleProfileMap &ProfileMap);
85 
86  /// Output stream where to emit the profile to.
87  std::unique_ptr<raw_ostream> OutputStream;
88 
89  /// Profile summary.
90  std::unique_ptr<ProfileSummary> Summary;
91 
92  /// Compute summary for this profile.
93  void computeSummary(const SampleProfileMap &ProfileMap);
94 
95  /// Profile format.
97 };
98 
99 /// Sample-based profile writer (text format).
101 public:
102  std::error_code writeSample(const FunctionSamples &S) override;
103 
104 protected:
105  SampleProfileWriterText(std::unique_ptr<raw_ostream> &OS)
106  : SampleProfileWriter(OS), Indent(0) {}
107 
108  std::error_code writeHeader(const SampleProfileMap &ProfileMap) override {
110  }
111 
112 private:
113  /// Indent level to use when writing.
114  ///
115  /// This is used when printing inlined callees.
116  unsigned Indent;
117 
119  SampleProfileWriter::create(std::unique_ptr<raw_ostream> &OS,
121 };
122 
123 /// Sample-based profile writer (binary format).
125 public:
126  SampleProfileWriterBinary(std::unique_ptr<raw_ostream> &OS)
127  : SampleProfileWriter(OS) {}
128 
129  virtual std::error_code writeSample(const FunctionSamples &S) override;
130 
131 protected:
133  virtual std::error_code writeMagicIdent(SampleProfileFormat Format);
134  virtual std::error_code writeNameTable();
135  virtual std::error_code
136  writeHeader(const SampleProfileMap &ProfileMap) override;
137  std::error_code writeSummary();
138  virtual std::error_code writeContextIdx(const SampleContext &Context);
139  std::error_code writeNameIdx(StringRef FName);
140  std::error_code writeBody(const FunctionSamples &S);
142  std::set<StringRef> &V);
143 
145 
146  void addName(StringRef FName);
147  virtual void addContext(const SampleContext &Context);
148  void addNames(const FunctionSamples &S);
149 
150 private:
152  SampleProfileWriter::create(std::unique_ptr<raw_ostream> &OS,
154 };
155 
158 };
159 
160 const std::array<SmallVector<SecHdrTableEntry, 8>, NumOfLayout>
162  // Note that SecFuncOffsetTable section is written after SecLBRProfile
163  // in the profile, but is put before SecLBRProfile in SectionHdrLayout.
164  // This is because sample reader follows the order in SectionHdrLayout
165  // to read each section. To read function profiles on demand, sample
166  // reader need to get the offset of each function profile first.
167  //
168  // DefaultLayout
170  {SecNameTable, 0, 0, 0, 0},
171  {SecCSNameTable, 0, 0, 0, 0},
172  {SecFuncOffsetTable, 0, 0, 0, 0},
173  {SecLBRProfile, 0, 0, 0, 0},
174  {SecProfileSymbolList, 0, 0, 0, 0},
175  {SecFuncMetadata, 0, 0, 0, 0}}),
176  // CtxSplitLayout
178  {SecNameTable, 0, 0, 0, 0},
179  // profile with context
180  // for next two sections
181  {SecFuncOffsetTable, 0, 0, 0, 0},
182  {SecLBRProfile, 0, 0, 0, 0},
183  // profile without context
184  // for next two sections
185  {SecFuncOffsetTable, 0, 0, 0, 0},
186  {SecLBRProfile, 0, 0, 0, 0},
187  {SecProfileSymbolList, 0, 0, 0, 0},
188  {SecFuncMetadata, 0, 0, 0, 0}}),
189 };
190 
193 public:
194  virtual std::error_code write(const SampleProfileMap &ProfileMap) override;
195 
196  virtual void setToCompressAllSections() override;
198  virtual std::error_code writeSample(const FunctionSamples &S) override;
199 
200  // Set to use MD5 to represent string in NameTable.
201  virtual void setUseMD5() override {
202  UseMD5 = true;
204  // MD5 will be stored as plain uint64_t instead of variable-length
205  // quantity format in NameTable section.
207  }
208 
209  // Set the profile to be partial. It means the profile is for
210  // common/shared code. The common profile is usually merged from
211  // profiles collected from running other targets.
212  virtual void setPartialProfile() override {
214  }
215 
216  virtual void setProfileSymbolList(ProfileSymbolList *PSL) override {
217  ProfSymList = PSL;
218  };
219 
220  virtual void resetSecLayout(SectionLayout SL) override {
221  verifySecLayout(SL);
222 #ifndef NDEBUG
223  // Make sure resetSecLayout is called before any flag setting.
224  for (auto &Entry : SectionHdrLayout) {
225  assert(Entry.Flags == 0 &&
226  "resetSecLayout has to be called before any flag setting");
227  }
228 #endif
229  SecLayout = SL;
231  }
232 
233 protected:
235  std::error_code addNewSection(SecType Sec, uint32_t LayoutIdx,
236  uint64_t SectionStart);
237  template <class SecFlagType>
238  void addSectionFlag(SecType Type, SecFlagType Flag) {
239  for (auto &Entry : SectionHdrLayout) {
240  if (Entry.Type == Type)
241  addSecFlag(Entry, Flag);
242  }
243  }
244  template <class SecFlagType>
245  void addSectionFlag(uint32_t SectionIdx, SecFlagType Flag) {
246  addSecFlag(SectionHdrLayout[SectionIdx], Flag);
247  }
248 
249  virtual void addContext(const SampleContext &Context) override;
250 
251  // placeholder for subclasses to dispatch their own section writers.
252  virtual std::error_code writeCustomSection(SecType Type) = 0;
253  // Verify the SecLayout is supported by the format.
254  virtual void verifySecLayout(SectionLayout SL) = 0;
255 
256  // specify the order to write sections.
257  virtual std::error_code writeSections(const SampleProfileMap &ProfileMap) = 0;
258 
259  // Dispatch section writer for each section. \p LayoutIdx is the sequence
260  // number indicating where the section is located in SectionHdrLayout.
261  virtual std::error_code writeOneSection(SecType Type, uint32_t LayoutIdx,
262  const SampleProfileMap &ProfileMap);
263 
264  // Helper function to write name table.
265  virtual std::error_code writeNameTable() override;
266  virtual std::error_code
267  writeContextIdx(const SampleContext &Context) override;
268  std::error_code writeCSNameIdx(const SampleContext &Context);
269  std::error_code writeCSNameTableSection();
270 
271  std::error_code writeFuncMetadata(const SampleProfileMap &Profiles);
272  std::error_code writeFuncMetadata(const FunctionSamples &Profile);
273 
274  // Functions to write various kinds of sections.
275  std::error_code writeNameTableSection(const SampleProfileMap &ProfileMap);
276  std::error_code writeFuncOffsetTable();
277  std::error_code writeProfileSymbolListSection();
278 
280  // Specifiy the order of sections in section header table. Note
281  // the order of sections in SecHdrTable may be different that the
282  // order in SectionHdrLayout. sample Reader will follow the order
283  // in SectionHdrLayout to read each section.
286 
287  // Save the start of SecLBRProfile so we can compute the offset to the
288  // start of SecLBRProfile for each Function's Profile and will keep it
289  // in FuncOffsetTable.
291 
292 private:
293  void allocSecHdrTable();
294  std::error_code writeSecHdrTable();
295  virtual std::error_code
296  writeHeader(const SampleProfileMap &ProfileMap) override;
297  std::error_code compressAndOutput();
298 
299  // We will swap the raw_ostream held by LocalBufStream and that
300  // held by OutputStream if we try to add a section which needs
301  // compression. After the swap, all the data written to output
302  // will be temporarily buffered into the underlying raw_string_ostream
303  // originally held by LocalBufStream. After the data writing for the
304  // section is completed, compress the data in the local buffer,
305  // swap the raw_ostream back and write the compressed data to the
306  // real output.
307  std::unique_ptr<raw_ostream> LocalBufStream;
308  // The location where the output stream starts.
309  uint64_t FileStart;
310  // The location in the output stream where the SecHdrTable should be
311  // written to.
312  uint64_t SecHdrTableOffset;
313  // The table contains SecHdrTableEntry entries in order of how they are
314  // populated in the writer. It may be different from the order in
315  // SectionHdrLayout which specifies the sequence in which sections will
316  // be read.
317  std::vector<SecHdrTableEntry> SecHdrTable;
318 
319  // FuncOffsetTable maps function context to its profile offset in
320  // SecLBRProfile section. It is used to load function profile on demand.
321  MapVector<SampleContext, uint64_t> FuncOffsetTable;
322  // Whether to use MD5 to represent string.
323  bool UseMD5 = false;
324 
325  /// CSNameTable maps function context to its offset in SecCSNameTable section.
326  /// The offset will be used everywhere where the context is referenced.
328 
329  ProfileSymbolList *ProfSymList = nullptr;
330 };
331 
333 public:
334  SampleProfileWriterExtBinary(std::unique_ptr<raw_ostream> &OS)
336 
337 private:
338  std::error_code writeDefaultLayout(const SampleProfileMap &ProfileMap);
339  std::error_code writeCtxSplitLayout(const SampleProfileMap &ProfileMap);
340 
341  virtual std::error_code
342  writeSections(const SampleProfileMap &ProfileMap) override;
343 
344  virtual std::error_code writeCustomSection(SecType Type) override {
346  };
347 
348  virtual void verifySecLayout(SectionLayout SL) override {
349  assert((SL == DefaultLayout || SL == CtxSplitLayout) &&
350  "Unsupported layout");
351  }
352 };
353 
354 // CompactBinary is a compact format of binary profile which both reduces
355 // the profile size and the load time needed when compiling. It has two
356 // major difference with Binary format.
357 // 1. It represents all the strings in name table using md5 hash.
358 // 2. It saves a function offset table which maps function name index to
359 // the offset of its function profile to the start of the binary profile,
360 // so by using the function offset table, for those function profiles which
361 // will not be needed when compiling a module, the profile reader does't
362 // have to read them and it saves compile time if the profile size is huge.
363 // The layout of the compact format is shown as follows:
364 //
365 // Part1: Profile header, the same as binary format, containing magic
366 // number, version, summary, name table...
367 // Part2: Function Offset Table Offset, which saves the position of
368 // Part4.
369 // Part3: Function profile collection
370 // function1 profile start
371 // ....
372 // function2 profile start
373 // ....
374 // function3 profile start
375 // ....
376 // ......
377 // Part4: Function Offset Table
378 // function1 name index --> function1 profile start
379 // function2 name index --> function2 profile start
380 // function3 name index --> function3 profile start
381 //
382 // We need Part2 because profile reader can use it to find out and read
383 // function offset table without reading Part3 first.
386 
387 public:
388  virtual std::error_code writeSample(const FunctionSamples &S) override;
389  virtual std::error_code write(const SampleProfileMap &ProfileMap) override;
390 
391 protected:
392  /// The table mapping from function name to the offset of its FunctionSample
393  /// towards profile start.
395  /// The offset of the slot to be filled with the offset of FuncOffsetTable
396  /// towards profile start.
398  virtual std::error_code writeNameTable() override;
399  virtual std::error_code
400  writeHeader(const SampleProfileMap &ProfileMap) override;
401  std::error_code writeFuncOffsetTable();
402 };
403 
404 } // end namespace sampleprof
405 } // end namespace llvm
406 
407 #endif // LLVM_PROFILEDATA_SAMPLEPROFWRITER_H
llvm::sampleprof::SampleProfileWriterText::SampleProfileWriterText
SampleProfileWriterText(std::unique_ptr< raw_ostream > &OS)
Definition: SampleProfWriter.h:105
llvm::sampleprof::SampleProfileWriter::OutputStream
std::unique_ptr< raw_ostream > OutputStream
Output stream where to emit the profile to.
Definition: SampleProfWriter.h:87
llvm::sampleprof::SampleProfileWriterExtBinaryBase::addSectionFlag
void addSectionFlag(uint32_t SectionIdx, SecFlagType Flag)
Definition: SampleProfWriter.h:245
llvm::sampleprof::SectionLayout
SectionLayout
Definition: SampleProfWriter.h:33
llvm::sampleprof::SampleProfileWriterBinary::NameTable
MapVector< StringRef, uint32_t > NameTable
Definition: SampleProfWriter.h:144
llvm::sampleprof::SampleProfileWriterText
Sample-based profile writer (text format).
Definition: SampleProfWriter.h:100
llvm::sampleprof::SampleProfileWriter::create
static ErrorOr< std::unique_ptr< SampleProfileWriter > > create(StringRef Filename, SampleProfileFormat Format)
Profile writer factory.
Definition: SampleProfWriter.cpp:846
llvm::sampleprof::CtxSplitLayout
@ CtxSplitLayout
Definition: SampleProfWriter.h:38
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
llvm::sampleprof::SampleProfileWriterBinary::stablizeNameTable
void stablizeNameTable(MapVector< StringRef, uint32_t > &NameTable, std::set< StringRef > &V)
Definition: SampleProfWriter.cpp:582
llvm::sampleprof::SampleProfileWriterExtBinaryBase::writeNameTable
virtual std::error_code writeNameTable() override
Definition: SampleProfWriter.cpp:241
llvm::sampleprof::SampleProfileWriter::Format
SampleProfileFormat Format
Profile format.
Definition: SampleProfWriter.h:96
llvm::sampleprof::SampleProfileWriterExtBinaryBase::setPartialProfile
virtual void setPartialProfile() override
Definition: SampleProfWriter.h:212
llvm::sampleprof::SampleProfileWriterBinary::writeBody
std::error_code writeBody(const FunctionSamples &S)
Definition: SampleProfWriter.cpp:777
llvm::sampleprof::SampleProfileWriterExtBinaryBase::writeFuncOffsetTable
std::error_code writeFuncOffsetTable()
Definition: SampleProfWriter.cpp:161
ProfileSummary.h
StringRef.h
llvm::sampleprof::SampleProfileWriter::setUseMD5
virtual void setUseMD5()
Definition: SampleProfWriter.h:72
llvm::sampleprof::SecNameTableFlags::SecFlagFixedLengthMD5
@ SecFlagFixedLengthMD5
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1177
llvm::sampleprof::SampleProfileWriter::setToCompressAllSections
virtual void setToCompressAllSections()
Definition: SampleProfWriter.h:71
llvm::sampleprof::DefaultLayout
@ DefaultLayout
Definition: SampleProfWriter.h:34
MapVector.h
llvm::sampleprof::SampleProfileMap
std::unordered_map< SampleContext, FunctionSamples, SampleContext::Hash > SampleProfileMap
Definition: SampleProf.h:1128
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::sampleprof::SampleProfileWriterBinary::addName
void addName(StringRef FName)
Definition: SampleProfWriter.cpp:545
llvm::sampleprof::SecFuncOffsetTable
@ SecFuncOffsetTable
Definition: SampleProf.h:126
llvm::sampleprof::SampleProfileWriter::computeSummary
void computeSummary(const SampleProfileMap &ProfileMap)
Compute summary for this profile.
Definition: SampleProfWriter.cpp:899
llvm::sampleprof::addSecFlag
static void addSecFlag(SecHdrTableEntry &Entry, SecFlagType Flag)
Definition: SampleProf.h:249
llvm::sampleprof::SampleProfileWriterCompactBinary::writeFuncOffsetTable
std::error_code writeFuncOffsetTable()
Definition: SampleProfWriter.cpp:606
llvm::MapVector
This class implements a map that also provides access to all stored values in a deterministic order.
Definition: MapVector.h:37
llvm::sampleprof::SampleProfileWriterCompactBinary::writeHeader
virtual std::error_code writeHeader(const SampleProfileMap &ProfileMap) override
Write a file header for the profile file.
Definition: SampleProfWriter.cpp:747
llvm::sampleprof::SecNameTableFlags::SecFlagMD5Name
@ SecFlagMD5Name
llvm::sampleprof::SampleProfileWriterExtBinaryBase::writeNameTableSection
std::error_code writeNameTableSection(const SampleProfileMap &ProfileMap)
Definition: SampleProfWriter.cpp:259
llvm::sampleprof::SampleProfileWriter::writeFuncProfiles
virtual std::error_code writeFuncProfiles(const SampleProfileMap &ProfileMap)
Definition: SampleProfWriter.cpp:45
llvm::sampleprof::SPF_None
@ SPF_None
Definition: SampleProf.h:91
llvm::sampleprof::SampleProfileWriterExtBinaryBase::setToCompressAllSections
virtual void setToCompressAllSections() override
Definition: SampleProfWriter.cpp:672
llvm::sampleprof::SampleProfileWriterBinary::writeSample
virtual std::error_code writeSample(const FunctionSamples &S) override
Write samples of a top-level function to a binary file.
Definition: SampleProfWriter.cpp:824
llvm::sampleprof::SampleProfileWriterExtBinaryBase::writeSample
virtual std::error_code writeSample(const FunctionSamples &S) override
Write samples of a top-level function to a binary file.
Definition: SampleProfWriter.cpp:153
Context
ManagedStatic< detail::RecordContext > Context
Definition: Record.cpp:96
llvm::sampleprof::SampleProfileWriterExtBinaryBase::writeCustomSection
virtual std::error_code writeCustomSection(SecType Type)=0
llvm::sampleprof::SampleProfileWriter::Summary
std::unique_ptr< ProfileSummary > Summary
Profile summary.
Definition: SampleProfWriter.h:90
llvm::sampleprof::SampleProfileFormat
SampleProfileFormat
Definition: SampleProf.h:90
llvm::sampleprof::SampleProfileWriterExtBinaryBase::writeSections
virtual std::error_code writeSections(const SampleProfileMap &ProfileMap)=0
llvm::sampleprof::SampleProfileWriterBinary::addNames
void addNames(const FunctionSamples &S)
Definition: SampleProfWriter.cpp:554
llvm::sampleprof::SampleProfileWriter::write
virtual std::error_code write(const SampleProfileMap &ProfileMap)
Write all the sample profiles in the given map of samples.
Definition: SampleProfWriter.cpp:55
llvm::sampleprof::SecProfSummaryFlags::SecFlagPartial
@ SecFlagPartial
SecFlagPartial means the profile is for common/shared code.
llvm::sampleprof::SampleProfileWriterRawBinary
Definition: SampleProfWriter.h:156
llvm::sampleprof::SampleProfileWriterBinary::writeHeader
virtual std::error_code writeHeader(const SampleProfileMap &ProfileMap) override
Write a file header for the profile file.
Definition: SampleProfWriter.cpp:654
llvm::sampleprof::SampleProfileWriterExtBinaryBase::addContext
virtual void addContext(const SampleContext &Context) override
Definition: SampleProfWriter.cpp:571
llvm::sampleprof::SampleProfileWriterBinary::writeNameTable
virtual std::error_code writeNameTable()
Definition: SampleProfWriter.cpp:592
SampleProf.h
llvm::sampleprof::SampleProfileWriter::writeSample
virtual std::error_code writeSample(const FunctionSamples &S)=0
Write sample profiles in S.
llvm::MCID::Flag
Flag
These should be considered private to the implementation of the MCInstrDesc class.
Definition: MCInstrDesc.h:146
llvm::sampleprof::SampleProfileWriterExtBinaryBase::setProfileSymbolList
virtual void setProfileSymbolList(ProfileSymbolList *PSL) override
Definition: SampleProfWriter.h:216
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::sampleprof::SampleProfileWriterExtBinaryBase::SectionHdrLayout
SmallVector< SecHdrTableEntry, 8 > SectionHdrLayout
Definition: SampleProfWriter.h:284
llvm::sampleprof::SampleProfileWriterCompactBinary::TableOffset
uint64_t TableOffset
The offset of the slot to be filled with the offset of FuncOffsetTable towards profile start.
Definition: SampleProfWriter.h:397
StringMap.h
llvm::sampleprof::SampleProfileWriterExtBinaryBase::write
virtual std::error_code write(const SampleProfileMap &ProfileMap) override
Write all the sample profiles in the given map of samples.
Definition: SampleProfWriter.cpp:120
llvm::sampleprof::SampleContext
Definition: SampleProf.h:470
llvm::sampleprof::SampleProfileWriter::setPartialProfile
virtual void setPartialProfile()
Definition: SampleProfWriter.h:73
llvm::sampleprof::SampleProfileWriter::~SampleProfileWriter
virtual ~SampleProfileWriter()=default
llvm::sampleprof::SampleProfileWriterCompactBinary::writeNameTable
virtual std::error_code writeNameTable() override
Definition: SampleProfWriter.cpp:631
llvm::sampleprof::SampleProfileWriterBinary::SampleProfileWriterBinary
SampleProfileWriterBinary(std::unique_ptr< raw_ostream > &OS)
Definition: SampleProfWriter.h:126
llvm::sampleprof::SampleProfileWriterCompactBinary::FuncOffsetTable
MapVector< StringRef, uint64_t > FuncOffsetTable
The table mapping from function name to the offset of its FunctionSample towards profile start.
Definition: SampleProfWriter.h:394
llvm::sampleprof::SampleProfileWriterExtBinaryBase::markSectionStart
uint64_t markSectionStart(SecType Type, uint32_t LayoutIdx)
Return the current position and prepare to use it as the start position of a section given the sectio...
Definition: SampleProfWriter.cpp:69
llvm::sampleprof::SecProfSummary
@ SecProfSummary
Definition: SampleProf.h:123
llvm::sampleprof::SampleProfileWriterBinary::getNameTable
virtual MapVector< StringRef, uint32_t > & getNameTable()
Definition: SampleProfWriter.h:132
llvm::sampleprof::ProfileSymbolList
ProfileSymbolList records the list of function symbols shown up in the binary used to generate the pr...
Definition: SampleProf.h:1221
uint64_t
llvm::sampleprof::SampleProfileWriterCompactBinary::write
virtual std::error_code write(const SampleProfileMap &ProfileMap) override
Write all the sample profiles in the given map of samples.
Definition: SampleProfWriter.cpp:456
llvm::sampleprof::SampleProfileWriterText::writeHeader
std::error_code writeHeader(const SampleProfileMap &ProfileMap) override
Write a file header for the profile file.
Definition: SampleProfWriter.h:108
llvm::sampleprof::FunctionSamples
Representation of the samples collected for a function.
Definition: SampleProf.h:689
llvm::sampleprof::SampleProfileWriter::resetSecLayout
virtual void resetSecLayout(SectionLayout SL)
Definition: SampleProfWriter.h:74
ErrorOr.h
llvm::sampleprof::SampleProfileWriterExtBinaryBase::writeCSNameIdx
std::error_code writeCSNameIdx(const SampleContext &Context)
Definition: SampleProfWriter.cpp:144
llvm::sampleprof::SecLBRProfile
@ SecLBRProfile
Definition: SampleProf.h:131
llvm::sampleprof::SampleProfileWriter::SampleProfileWriter
SampleProfileWriter(std::unique_ptr< raw_ostream > &OS)
Definition: SampleProfWriter.h:77
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::sampleprof::SampleProfileWriterBinary::addContext
virtual void addContext(const SampleContext &Context)
Definition: SampleProfWriter.cpp:550
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:1707
llvm::sampleprof::SampleProfileWriterExtBinaryBase::addSectionFlag
void addSectionFlag(SecType Type, SecFlagType Flag)
Definition: SampleProfWriter.h:238
llvm::sampleprof::SampleProfileWriterText::writeSample
std::error_code writeSample(const FunctionSamples &S) override
Write samples to a text file.
Definition: SampleProfWriter.cpp:472
llvm::sampleprof::SampleProfileWriterBinary::writeNameIdx
std::error_code writeNameIdx(StringRef FName)
Definition: SampleProfWriter.cpp:536
llvm::sampleprof::SampleProfileWriterExtBinaryBase::setUseMD5
virtual void setUseMD5() override
Definition: SampleProfWriter.h:201
llvm::sampleprof::SampleProfileWriterExtBinaryBase::addNewSection
std::error_code addNewSection(SecType Sec, uint32_t LayoutIdx, uint64_t SectionStart)
Add a new section into section header table given the section type Type, its position LayoutIdx in Se...
Definition: SampleProfWriter.cpp:104
llvm::sampleprof::NumOfLayout
@ NumOfLayout
Definition: SampleProfWriter.h:39
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
uint32_t
llvm::sampleprof::SampleProfileWriterExtBinaryBase::writeFuncMetadata
std::error_code writeFuncMetadata(const SampleProfileMap &Profiles)
Definition: SampleProfWriter.cpp:229
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
Profile
Load MIR Sample Profile
Definition: MIRSampleProfile.cpp:62
llvm::sampleprof::SampleProfileWriter::writeHeader
virtual std::error_code writeHeader(const SampleProfileMap &ProfileMap)=0
Write a file header for the profile file.
llvm::sampleprof::SampleProfileWriterExtBinary
Definition: SampleProfWriter.h:332
StringSet.h
llvm::sampleprof::SampleProfileWriterExtBinaryBase::writeOneSection
virtual std::error_code writeOneSection(SecType Type, uint32_t LayoutIdx, const SampleProfileMap &ProfileMap)
Definition: SampleProfWriter.cpp:319
std
Definition: BitVector.h:838
llvm::sampleprof::SampleProfileWriterBinary::writeSummary
std::error_code writeSummary()
Definition: SampleProfWriter.cpp:760
llvm::sampleprof::SampleProfileWriterExtBinaryBase::setToCompressSection
void setToCompressSection(SecType Type)
Definition: SampleProfWriter.cpp:677
llvm::sampleprof::SampleProfileWriter::setProfileSymbolList
virtual void setProfileSymbolList(ProfileSymbolList *PSL)
Definition: SampleProfWriter.h:70
llvm::sampleprof::SecProfileSymbolList
@ SecProfileSymbolList
Definition: SampleProf.h:125
llvm::sampleprof::SampleProfileWriterExtBinaryBase::verifySecLayout
virtual void verifySecLayout(SectionLayout SL)=0
llvm::sampleprof::SampleProfileWriterExtBinaryBase::SecLBRProfileStart
uint64_t SecLBRProfileStart
Definition: SampleProfWriter.h:290
llvm::sampleprof::SecType
SecType
Definition: SampleProf.h:121
llvm::sampleprof::SampleProfileWriterExtBinaryBase::writeCSNameTableSection
std::error_code writeCSNameTableSection()
Definition: SampleProfWriter.cpp:282
llvm::sampleprof::SampleProfileWriterExtBinaryBase::writeProfileSymbolListSection
std::error_code writeProfileSymbolListSection()
Definition: SampleProfWriter.cpp:311
llvm::sampleprof::SampleProfileWriterBinary::writeContextIdx
virtual std::error_code writeContextIdx(const SampleContext &Context)
Definition: SampleProfWriter.cpp:531
llvm::sampleprof_error::success
@ success
llvm::sampleprof::SampleProfileWriterExtBinaryBase::resetSecLayout
virtual void resetSecLayout(SectionLayout SL) override
Definition: SampleProfWriter.h:220
llvm::sampleprof::SampleProfileWriterExtBinaryBase::writeContextIdx
virtual std::error_code writeContextIdx(const SampleContext &Context) override
Definition: SampleProfWriter.cpp:135
llvm::sampleprof::SampleProfileWriterBinary
Sample-based profile writer (binary format).
Definition: SampleProfWriter.h:124
llvm::sampleprof::SampleProfileWriterCompactBinary::writeSample
virtual std::error_code writeSample(const FunctionSamples &S) override
Write samples of a top-level function to a binary file.
Definition: SampleProfWriter.cpp:830
llvm::sampleprof::ExtBinaryHdrLayoutTable
const std::array< SmallVector< SecHdrTableEntry, 8 >, NumOfLayout > ExtBinaryHdrLayoutTable
Definition: SampleProfWriter.h:161
llvm::sampleprof::SecCSNameTable
@ SecCSNameTable
Definition: SampleProf.h:128
llvm::ErrorOr
Represents either an error or a value T.
Definition: ErrorOr.h:56
llvm::sampleprof::SecNameTable
@ SecNameTable
Definition: SampleProf.h:124
llvm::sampleprof::SampleProfileWriterBinary::writeMagicIdent
virtual std::error_code writeMagicIdent(SampleProfileFormat Format)
Definition: SampleProfWriter.cpp:645
llvm::sampleprof::SecFuncMetadata
@ SecFuncMetadata
Definition: SampleProf.h:127
raw_ostream.h
llvm::sampleprof::SampleProfileWriterExtBinary::SampleProfileWriterExtBinary
SampleProfileWriterExtBinary(std::unique_ptr< raw_ostream > &OS)
Definition: SampleProfWriter.h:334
llvm::sampleprof::SampleProfileWriterCompactBinary
Definition: SampleProfWriter.h:384
llvm::sampleprof::SampleProfileWriter::getOutputStream
raw_ostream & getOutputStream()
Definition: SampleProfWriter.h:57
llvm::sampleprof::SampleProfileWriter
Sample-based profile writer. Base class.
Definition: SampleProfWriter.h:43
llvm::sampleprof::SampleProfileWriterExtBinaryBase::SecLayout
SectionLayout SecLayout
Definition: SampleProfWriter.h:279
llvm::sampleprof::SampleProfileWriterExtBinaryBase
Definition: SampleProfWriter.h:191