12#ifndef LLVM_PROFILEDATA_SAMPLEPROFWRITER_H
13#define LLVM_PROFILEDATA_SAMPLEPROFWRITER_H
25#include <system_error>
66 virtual void Erase(
size_t CurrentOutputSize) = 0;
70 std::vector<NameFunctionSamples> SortedFunctions;
74 size_t OutputSizeLimit);
86 void Erase(
size_t CurrentOutputSize)
override;
108 template <
typename FunctionPruningStrategy = DefaultFunctionPruningStrategy>
110 size_t OutputSizeLimit) {
112 return writeWithSizeLimitInternal(ProfileMap, OutputSizeLimit, &Strategy);
142 virtual std::error_code writeFuncProfiles(
const SampleProfileMap &ProfileMap);
145 size_t OutputSizeLimit,
177 return sampleprof_error::success;
181 MarkFlatProfiles =
true;
194 bool MarkFlatProfiles =
false;
197 SampleProfileWriter::create(std::unique_ptr<raw_ostream> &
OS,
212 virtual std::error_code writeNameTable();
214 std::error_code writeSummary();
215 virtual std::error_code writeContextIdx(
const SampleContext &Context);
216 std::error_code writeNameIdx(
FunctionId FName);
219 std::set<FunctionId> &V);
229 SampleProfileWriter::create(std::unique_ptr<raw_ostream> &
OS,
237const std::array<SmallVector<SecHdrTableEntry, 8>,
NumOfLayout>
270 using SampleProfileWriterBinary::SampleProfileWriterBinary;
274 void setToCompressAllSections()
override;
281 addSectionFlag(
SecNameTable, SecNameTableFlags::SecFlagMD5Name);
284 addSectionFlag(
SecNameTable, SecNameTableFlags::SecFlagFixedLengthMD5);
291 addSectionFlag(
SecProfSummary, SecProfSummaryFlags::SecFlagPartial);
299 resetSecLayout(SectionLayout::CtxSplitLayout);
306 for (
auto &Entry : SectionHdrLayout) {
307 assert(Entry.Flags == 0 &&
308 "resetSecLayout has to be called before any flag setting");
319 template <
class SecFlagType>
321 for (
auto &Entry : SectionHdrLayout) {
322 if (Entry.Type ==
Type)
323 addSecFlag(Entry, Flag);
326 template <
class SecFlagType>
328 addSecFlag(SectionHdrLayout[SectionIdx], Flag);
347 std::error_code writeNameTable()
override;
348 std::error_code writeContextIdx(
const SampleContext &Context)
override;
349 std::error_code writeCSNameIdx(
const SampleContext &Context);
350 std::error_code writeCSNameTableSection();
357 std::error_code writeFuncOffsetTable();
358 std::error_code writeProfileSymbolListSection();
374 void allocSecHdrTable();
375 std::error_code writeSecHdrTable();
377 std::error_code compressAndOutput();
387 std::unique_ptr<raw_ostream> LocalBufStream;
397 std::vector<SecHdrTableEntry> SecHdrTable;
424 std::error_code writeCustomSection(
SecType Type)
override {
425 return sampleprof_error::success;
429 assert((SL == DefaultLayout || SL == CtxSplitLayout) &&
430 "Unsupported layout");
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Provides ErrorOr<T> smart pointer.
This file implements a map that provides insertion order iteration.
static void write(bool isBE, void *P, T V)
Represents either an error or a value T.
This class implements a map that also provides access to all stored values in a deterministic order.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
The instances of the Type class are immutable: once they are created, they are never changed.
This class implements an extremely fast bulk output stream that can only output to a stream.
This class represents a function that is read from a sample profile.
When writing a profile with size limit, user may want to use a different strategy to reduce function ...
virtual void Erase(size_t CurrentOutputSize)=0
SampleProfileWriter::writeWithSizeLimit() calls this after every write iteration if the output size s...
virtual ~FunctionPruningStrategy()=default
FunctionPruningStrategy(SampleProfileMap &ProfileMap, size_t OutputSizeLimit)
ProfileMap A reference to the original profile map.
SampleProfileMap & ProfileMap
Representation of the samples collected for a function.
ProfileSymbolList records the list of function symbols shown up in the binary used to generate the pr...
This class provides operator overloads to the map container using MD5 as the key type,...
Sample-based profile writer (binary format).
SampleProfileWriterBinary(std::unique_ptr< raw_ostream > &OS)
MapVector< FunctionId, uint32_t > NameTable
virtual MapVector< FunctionId, uint32_t > & getNameTable()
void setUseCtxSplitLayout() override
void setUseMD5() override
virtual std::error_code writeCustomSection(SecType Type)=0
virtual void verifySecLayout(SectionLayout SL)=0
void setProfileSymbolList(ProfileSymbolList *PSL) override
void setPartialProfile() override
virtual std::error_code writeSections(const SampleProfileMap &ProfileMap)=0
void resetSecLayout(SectionLayout SL)
void addSectionFlag(SecType Type, SecFlagType Flag)
void addSectionFlag(uint32_t SectionIdx, SecFlagType Flag)
SampleProfileWriterExtBinary(std::unique_ptr< raw_ostream > &OS)
Sample-based profile writer (text format).
SampleProfileWriterText(std::unique_ptr< raw_ostream > &OS)
std::error_code writeHeader(const SampleProfileMap &ProfileMap) override
Write a file header for the profile file.
void setUseCtxSplitLayout() override
Sample-based profile writer. Base class.
virtual void setUseCtxSplitLayout()
SampleProfileWriter(std::unique_ptr< raw_ostream > &OS)
std::unique_ptr< ProfileSummary > Summary
Profile summary.
virtual std::error_code writeSample(const FunctionSamples &S)=0
Write sample profiles in S.
raw_ostream & getOutputStream()
virtual void setPartialProfile()
std::unique_ptr< raw_ostream > OutputStream
Output stream where to emit the profile to.
virtual void setToCompressAllSections()
std::error_code writeWithSizeLimit(SampleProfileMap &ProfileMap, size_t OutputSizeLimit)
Write sample profiles up to given size limit, using the pruning strategy to drop some functions if ne...
virtual void setProfileSymbolList(ProfileSymbolList *PSL)
size_t LineCount
For writeWithSizeLimit in text mode, each newline takes 1 additional byte on Windows when actually wr...
virtual std::error_code writeHeader(const SampleProfileMap &ProfileMap)=0
Write a file header for the profile file.
virtual ~SampleProfileWriter()=default
const std::array< SmallVector< SecHdrTableEntry, 8 >, NumOfLayout > ExtBinaryHdrLayoutTable
This is an optimization pass for GlobalISel generic memory operations.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Implement std::hash so that hash_code can be used in STL containers.