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;
86 void Erase(
size_t CurrentOutputSize)
override;
108 template <
typename FunctionPruningStrategy = DefaultFunctionPruningStrategy>
110 size_t OutputSizeLimit) {
145 size_t OutputSizeLimit,
181 MarkFlatProfiles =
true;
194 bool MarkFlatProfiles =
false;
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);
244const std::array<SmallVector<SecHdrTableEntry, 8>,
NumOfLayout>
276 :
public SampleProfileWriterBinary {
314 assert(Entry.Flags == 0 &&
315 "resetSecLayout has to be called before any flag setting");
326 template <
class SecFlagType>
329 if (Entry.Type ==
Type)
333 template <
class SecFlagType>
381 void allocSecHdrTable();
382 std::error_code writeSecHdrTable();
384 std::error_code compressAndOutput();
394 std::unique_ptr<raw_ostream> LocalBufStream;
404 std::vector<SecHdrTableEntry> SecHdrTable;
430 std::error_code writeCustomSection(
SecType Type)
override {
436 "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.
DefaultFunctionPruningStrategy(SampleProfileMap &ProfileMap, size_t OutputSizeLimit)
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,...
SampleProfileWriterBinary(std::unique_ptr< raw_ostream > &OS)
virtual void addContext(const SampleContext &Context)
MapVector< FunctionId, uint32_t > NameTable
void addNames(const FunctionSamples &S)
std::error_code writeCallsiteVTableProf(const CallsiteTypeMap &CallsiteTypeMap, raw_ostream &OS)
Write CallsiteTypeMap to the output stream OS.
virtual MapVector< FunctionId, uint32_t > & getNameTable()
void addName(FunctionId FName)
std::error_code writeNameTableSection(const SampleProfileMap &ProfileMap)
void setUseCtxSplitLayout() override
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
std::error_code writeNameTable() override
void resetSecLayout(SectionLayout SL)
void addSectionFlag(SecType Type, SecFlagType Flag)
std::error_code writeProfileSymbolListSection()
void setToCompressAllSections() override
void addSectionFlag(uint32_t SectionIdx, SecFlagType Flag)
uint64_t SecLBRProfileStart
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)
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
std::error_code writeSample(const FunctionSamples &S) override
Write samples to a text file.
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.
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)
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
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.
std::map< LineLocation, TypeCountMap > CallsiteTypeMap
This is an optimization pass for GlobalISel generic memory operations.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
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.