12#ifndef LLVM_PROFILEDATA_SAMPLEPROFWRITER_H
13#define LLVM_PROFILEDATA_SAMPLEPROFWRITER_H
24#include <system_error>
65 virtual void Erase(
size_t CurrentOutputSize) = 0;
69 std::vector<NameFunctionSamples> SortedFunctions;
85 void Erase(
size_t CurrentOutputSize)
override;
107 template <
typename FunctionPruningStrategy = DefaultFunctionPruningStrategy>
109 size_t OutputSizeLimit) {
144 size_t OutputSizeLimit,
208 std::set<FunctionId> &V);
226const std::array<SmallVector<SecHdrTableEntry, 8>,
NumOfLayout>
291 assert(Entry.Flags == 0 &&
292 "resetSecLayout has to be called before any flag setting");
303 template <
class SecFlagType>
306 if (Entry.Type ==
Type)
310 template <
class SecFlagType>
358 void allocSecHdrTable();
359 std::error_code writeSecHdrTable();
361 std::error_code compressAndOutput();
371 std::unique_ptr<raw_ostream> LocalBufStream;
381 std::vector<SecHdrTableEntry> SecHdrTable;
407 std::error_code writeCustomSection(
SecType Type)
override {
413 "Unsupported layout");
Provides ErrorOr<T> smart pointer.
This file implements a map that provides insertion order iteration.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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.
void Erase(size_t CurrentOutputSize) override
In this default implementation, functions with fewest samples are dropped first.
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)
void stablizeNameTable(MapVector< FunctionId, uint32_t > &NameTable, std::set< FunctionId > &V)
virtual void addContext(const SampleContext &Context)
virtual std::error_code writeNameTable()
virtual std::error_code writeMagicIdent(SampleProfileFormat Format)
std::error_code writeSummary()
MapVector< FunctionId, uint32_t > NameTable
void addNames(const FunctionSamples &S)
virtual std::error_code writeContextIdx(const SampleContext &Context)
std::error_code writeSample(const FunctionSamples &S) override
Write samples of a top-level function to a binary file.
std::error_code writeHeader(const SampleProfileMap &ProfileMap) override
Write a file header for the profile file.
virtual MapVector< FunctionId, uint32_t > & getNameTable()
std::error_code writeBody(const FunctionSamples &S)
std::error_code writeNameIdx(FunctionId FName)
void addName(FunctionId FName)
std::error_code writeNameTableSection(const SampleProfileMap &ProfileMap)
SmallVector< SecHdrTableEntry, 8 > SectionHdrLayout
void setUseMD5() override
std::error_code writeFuncMetadata(const SampleProfileMap &Profiles)
void setToCompressSection(SecType Type)
virtual std::error_code writeCustomSection(SecType Type)=0
virtual std::error_code writeOneSection(SecType Type, uint32_t LayoutIdx, const SampleProfileMap &ProfileMap)
std::error_code writeFuncOffsetTable()
std::error_code writeCSNameTableSection()
std::error_code writeCSNameIdx(const SampleContext &Context)
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) override
std::error_code writeNameTable() override
void addSectionFlag(SecType Type, SecFlagType Flag)
std::error_code writeProfileSymbolListSection()
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...
void addContext(const SampleContext &Context) override
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...
void setToCompressAllSections() override
void addSectionFlag(uint32_t SectionIdx, SecFlagType Flag)
uint64_t SecLBRProfileStart
std::error_code write(const SampleProfileMap &ProfileMap) override
Write all the sample profiles in the given map of samples.
std::error_code writeContextIdx(const SampleContext &Context) override
std::error_code writeSample(const FunctionSamples &S) override
Write samples of a top-level function to a binary file.
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.
std::error_code writeSample(const FunctionSamples &S) override
Write samples to a text file.
Sample-based profile writer. Base class.
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.
SampleProfileFormat Format
Profile format.
std::error_code writeWithSizeLimitInternal(SampleProfileMap &ProfileMap, size_t OutputSizeLimit, FunctionPruningStrategy *Strategy)
raw_ostream & getOutputStream()
void computeSummary(const SampleProfileMap &ProfileMap)
Compute summary for this profile.
virtual void setPartialProfile()
virtual std::error_code writeFuncProfiles(const SampleProfileMap &ProfileMap)
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)
virtual void resetSecLayout(SectionLayout SL)
size_t LineCount
For writeWithSizeLimit in text mode, each newline takes 1 additional byte on Windows when actually wr...
static ErrorOr< std::unique_ptr< SampleProfileWriter > > create(StringRef Filename, SampleProfileFormat Format)
Profile writer factory.
virtual std::error_code writeHeader(const SampleProfileMap &ProfileMap)=0
Write a file header for the profile file.
virtual ~SampleProfileWriter()=default
virtual std::error_code write(const SampleProfileMap &ProfileMap)
Write all the sample profiles in the given map of samples.
static void addSecFlag(SecHdrTableEntry &Entry, SecFlagType Flag)
const std::array< SmallVector< SecHdrTableEntry, 8 >, NumOfLayout > ExtBinaryHdrLayoutTable
@ SecFlagPartial
SecFlagPartial means the profile is for common/shared code.
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.