225#ifndef LLVM_PROFILEDATA_SAMPLEPROFREADER_H
226#define LLVM_PROFILEDATA_SAMPLEPROFREADER_H
245#include <system_error>
246#include <unordered_set>
258namespace sampleprof {
260class SampleProfileReader;
268 std::unique_ptr<SymbolRemappingReader> SRR,
271 assert(Remappings &&
"Remappings cannot be nullptr");
297 return Remappings->lookup(FunctionName);
306 std::unique_ptr<MemoryBuffer> Buffer;
307 std::unique_ptr<SymbolRemappingReader> Remappings;
316 bool RemappingApplied =
false;
375 if (std::error_code EC =
readImpl())
419 if (!FGUID.empty()) {
420 assert(
useMD5() &&
"New name should only be generated for md5 profile");
435 if (
auto NameInProfile =
Remapper->lookUpNameInProfile(Fname)) {
436 auto It =
Profiles.find(*NameInProfile);
459 const std::string RemapFilename =
"");
467 const std::string RemapFilename =
"");
530 static std::unique_ptr<ProfileSummary>
532 return std::move(Reader.
Summary);
538 std::unique_ptr<SampleProfileReaderItaniumRemapper>
Remapper;
577 std::error_code
readImpl()
override;
585 std::list<SampleContextFrameVector> CSNameTable;
598 std::error_code
readImpl()
override;
650 const uint8_t *
End =
nullptr;
660 std::error_code readSummaryEntry(std::vector<ProfileSummaryEntry> &Entries);
661 virtual std::error_code verifySPMagic(
uint64_t Magic) = 0;
666 std::error_code verifySPMagic(
uint64_t Magic)
override;
698 std::error_code decompressSection(
const uint8_t *SecStart,
700 const uint8_t *&DecompressBuf,
737 std::unique_ptr<std::vector<std::pair<SampleContext, uint64_t>>>
760 std::unique_ptr<const std::vector<SampleContextFrameVector>>
CSNameTable;
774 std::error_code
readImpl()
override;
798 std::error_code verifySPMagic(
uint64_t Magic)
override;
817 std::vector<std::string> NameTable;
823 std::error_code verifySPMagic(
uint64_t Magic)
override;
824 std::error_code readNameTable()
override;
827 std::error_code readHeader()
override;
828 std::error_code readFuncOffsetTable();
839 std::error_code
readImpl()
override;
874 std::error_code
readImpl()
override;
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
Provides ErrorOr<T> smart pointer.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
Allocate memory in an ever growing pool, as if by bump-pointer.
Implements a dense probed hash-table based set.
Diagnostic information for the sample profiler.
Represents either an error or a value T.
Tagged union holding either a T or a Error.
GCOVBuffer - A wrapper around MemoryBuffer to provide GCOV specific read operations.
This is an important class for using LLVM in a threaded context.
void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
This interface provides simple read-only access to a block of memory, and provides simple methods for...
A Module instance is used to store all the information related to an LLVM module.
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.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
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.
Representation of the samples collected for a function.
static StringRef getCanonicalFnName(const Function &F)
Return the canonical name for a function, taking into account suffix elision policy attributes.
static bool UseMD5
Whether the profile uses MD5 to represent string.
std::error_code readProfile(FunctionSamples &FProfile)
Read the contents of the given profile instance.
virtual std::error_code readNameTable()
Read the whole name table.
const uint8_t * Data
Points to the current location in the buffer.
ErrorOr< StringRef > readString()
Read a string from the profile.
std::vector< StringRef > NameTable
Function name table.
ErrorOr< T > readNumber()
Read a numeric value of type T from the profile.
std::error_code readHeader() override
Read and validate the file header.
virtual ErrorOr< StringRef > readStringFromTable()
Read a string indirectly via the name table.
bool at_eof() const
Return true if we've reached the end of file.
std::error_code readImpl() override
Read sample profiles from the associated file.
ErrorOr< uint32_t > readStringIndex(T &Table)
Read the string index and check whether it overflows the table.
SampleProfileReaderBinary(std::unique_ptr< MemoryBuffer > B, LLVMContext &C, SampleProfileFormat Format=SPF_None)
virtual ErrorOr< SampleContext > readSampleContextFromTable()
const uint8_t * End
Points to the end of the buffer.
std::vector< StringRef > * getNameTable() override
It includes all the names that have samples either in outline instance or inline instance.
ErrorOr< T > readUnencodedNumber()
Read a numeric value of type T from the profile.
std::error_code readFuncProfile(const uint8_t *Start)
Read the next function profile instance.
std::error_code readSummary()
Read profile summary.
std::error_code readMagicIdent()
Read the contents of Magic number and Version number.
static bool hasFormat(const MemoryBuffer &Buffer)
Return true if Buffer is in the format supported by this class.
std::error_code readImpl() override
Read samples only for functions to use.
bool useMD5() override
Return whether names in the profile are all MD5 numbers.
SampleProfileReaderCompactBinary(std::unique_ptr< MemoryBuffer > B, LLVMContext &C)
bool collectFuncsFromModule() override
Collect functions with definitions in Module M.
SampleProfileReaderExtBinaryBase/SampleProfileWriterExtBinaryBase defines the basic structure of the ...
std::error_code readFuncOffsetTable()
std::vector< SecHdrTableEntry > SecHdrTable
ErrorOr< StringRef > readStringFromTable() override
Read a string indirectly via the name table.
std::error_code readFuncMetadata(bool ProfileHasAttribute)
std::error_code readNameTableSec(bool IsMD5)
bool collectFuncsFromModule() override
Collect functions with definitions in Module M.
uint64_t getSectionSize(SecType Type)
Get the total size of all Type sections.
void setSkipFlatProf(bool Skip) override
Don't read profile without context if the flag is set.
std::error_code readCSNameTableSec()
virtual std::error_code readCustomSection(const SecHdrTableEntry &Entry)=0
std::unique_ptr< const std::vector< SampleContextFrameVector > > CSNameTable
CSNameTable is used to save full context vectors.
bool FixedLengthMD5
Use fixed length MD5 instead of ULEB128 encoding so NameTable doesn't need to be read in up front and...
DenseSet< StringRef > FuncsToUse
The set containing the functions to use when compiling a module.
ErrorOr< SampleContextFrames > readContextFromTable()
std::unique_ptr< ProfileSymbolList > ProfSymList
std::error_code readSecHdrTable()
std::error_code readFuncProfiles()
std::unique_ptr< ProfileSymbolList > getProfileSymbolList() override
std::unique_ptr< std::vector< std::string > > MD5StringBuf
If MD5 is used in NameTable section, the section saves uint64_t data.
std::error_code readImpl() override
Read sample profiles in extensible format from the associated file.
bool useMD5() override
Return whether names in the profile are all MD5 numbers.
const uint8_t * MD5NameMemStart
The starting address of NameTable containing fixed length MD5.
virtual std::error_code readOneSection(const uint8_t *Start, uint64_t Size, const SecHdrTableEntry &Entry)
bool dumpSectionInfo(raw_ostream &OS=dbgs()) override
std::error_code readMD5NameTable()
std::error_code verifySPMagic(uint64_t Magic) override=0
SampleProfileReaderExtBinaryBase(std::unique_ptr< MemoryBuffer > B, LLVMContext &C, SampleProfileFormat Format)
std::error_code readSecHdrTableEntry(uint32_t Idx)
bool SkipFlatProf
If SkipFlatProf is true, skip the sections with SecFlagFlat flag.
std::error_code readHeader() override
Read and validate the file header.
uint64_t getFileSize()
Get the total size of header and all sections.
DenseMap< SampleContext, uint64_t > FuncOffsetTable
The table mapping from function context to the offset of its FunctionSample towards file start.
std::unique_ptr< std::vector< std::pair< SampleContext, uint64_t > > > OrderedFuncOffsets
Function offset mapping ordered by contexts.
std::error_code readProfileSymbolList()
ErrorOr< SampleContext > readSampleContextFromTable() override
SampleProfileReaderExtBinary(std::unique_ptr< MemoryBuffer > B, LLVMContext &C, SampleProfileFormat Format=SPF_Ext_Binary)
static bool hasFormat(const MemoryBuffer &Buffer)
Return true if Buffer is in the format supported by this class.
ErrorOr< T > readNumber()
GCOVBuffer GcovBuffer
GCOV buffer containing the profile.
std::vector< std::string > Names
Function names in this profile.
std::error_code readImpl() override
Read sample profiles from the associated file.
std::error_code readNameTable()
SampleProfileReaderGCC(std::unique_ptr< MemoryBuffer > B, LLVMContext &C)
std::error_code readHeader() override
Read and validate the file header.
ErrorOr< StringRef > readString()
static const uint32_t GCOVTagAFDOFunction
std::error_code readOneFunctionProfile(const InlineCallStack &InlineStack, bool Update, uint32_t Offset)
std::error_code readFunctionProfiles()
static const uint32_t GCOVTagAFDOFileNames
GCOV tags used to separate sections in the profile file.
std::error_code skipNextWord()
static bool hasFormat(const MemoryBuffer &Buffer)
Return true if Buffer is in the format supported by this class.
std::error_code readSectionTag(uint32_t Expected)
Read the section tag and check that it's the same as Expected.
SampleProfileReaderItaniumRemapper remaps the profile data from a sample profile data reader,...
bool exist(StringRef FunctionName)
Query whether there is equivalent in the remapper which has been inserted.
static ErrorOr< std::unique_ptr< SampleProfileReaderItaniumRemapper > > create(const std::string Filename, vfs::FileSystem &FS, SampleProfileReader &Reader, LLVMContext &C)
Create a remapper from the given remapping file.
void applyRemapping(LLVMContext &Ctx)
Apply remappings to the profile read by Reader.
SampleProfileReaderItaniumRemapper(std::unique_ptr< MemoryBuffer > B, std::unique_ptr< SymbolRemappingReader > SRR, SampleProfileReader &R)
void insert(StringRef FunctionName)
Insert function name into remapper.
std::optional< StringRef > lookUpNameInProfile(StringRef FunctionName)
Return the equivalent name in the profile for FunctionName if it exists.
SampleProfileReaderRawBinary(std::unique_ptr< MemoryBuffer > B, LLVMContext &C, SampleProfileFormat Format=SPF_Binary)
static bool hasFormat(const MemoryBuffer &Buffer)
Return true if Buffer is in the format supported by this class.
SampleProfileReaderText(std::unique_ptr< MemoryBuffer > B, LLVMContext &C)
std::error_code readHeader() override
Read and validate the file header.
std::error_code readImpl() override
Read sample profiles from the associated file.
static bool hasFormat(const MemoryBuffer &Buffer)
Return true if Buffer is in the format supported by this class.
Sample-based profile reader.
uint32_t MaskedBitFrom
Zero out the discriminator bits higher than bit MaskedBitFrom (0 based).
bool ProfileIsPreInlined
Whether function profile contains ShouldBeInlined contexts.
void dumpFunctionProfile(SampleContext FContext, raw_ostream &OS=dbgs())
Print the profile for FContext on stream OS.
SampleProfileMap & getProfiles()
Return all the profiles.
uint32_t CSProfileCount
Number of context-sensitive profiles.
bool profileIsProbeBased() const
Whether input profile is based on pseudo probes.
FunctionSamples * getSamplesFor(const Function &F)
Return the samples collected for function F.
void dump(raw_ostream &OS=dbgs())
Print all the profiles on stream OS.
const Module * M
The current module being compiled if SampleProfileReader is used by compiler.
virtual FunctionSamples * getSamplesFor(StringRef Fname)
Return the samples collected for function F.
std::unique_ptr< MemoryBuffer > Buffer
Memory buffer holding the profile file.
std::unique_ptr< SampleProfileReaderItaniumRemapper > Remapper
FunctionSamples * getOrCreateSamplesFor(const Function &F)
Return the samples collected for function F, create empty FunctionSamples if it doesn't exist.
bool profileIsPreInlined() const
Whether input profile contains ShouldBeInlined contexts.
std::error_code read()
The interface to read sample profiles from the associated file.
virtual bool useMD5()
Return whether names in the profile are all MD5 numbers.
MemoryBuffer * getBuffer() const
virtual ~SampleProfileReader()=default
SampleProfileReaderItaniumRemapper * getRemapper()
bool ProfileIsCS
Whether function profiles are context-sensitive flat profiles.
void setModule(const Module *Mod)
virtual std::vector< StringRef > * getNameTable()
It includes all the names that have samples either in outline instance or inline instance.
static std::unique_ptr< ProfileSummary > takeSummary(SampleProfileReader &Reader)
Take ownership of the summary of this reader.
ProfileSummary & getSummary() const
Return the profile summary.
SampleProfileFormat Format
The format of sample.
SampleProfileReader(std::unique_ptr< MemoryBuffer > B, LLVMContext &C, SampleProfileFormat Format=SPF_None)
std::unique_ptr< ProfileSummary > Summary
Profile summary information.
virtual bool hasUniqSuffix()
Return whether any name in the profile contains ".__uniq." suffix.
void computeSummary()
Compute summary for this profile.
uint32_t getDiscriminatorMask() const
Get the bitmask the discriminators: For FS profiles, return the bit mask for this pass.
std::unordered_set< std::string > MD5NameBuffer
Extra name buffer holding names created on demand.
virtual bool dumpSectionInfo(raw_ostream &OS=dbgs())
SampleProfileFormat getFormat() const
Return the profile format.
void setDiscriminatorMaskedBitFrom(FSDiscriminatorPass P)
Set the bits for FS discriminators.
bool profileIsCS() const
Whether input profile is fully context-sensitive.
bool ProfileIsFS
Whether the function profiles use FS discriminators.
virtual bool collectFuncsFromModule()
Collect functions with definitions in Module M.
virtual void setSkipFlatProf(bool Skip)
Don't read profile without context if the flag is set.
void dumpJson(raw_ostream &OS=dbgs())
Print all the profiles on stream OS in the JSON format.
static ErrorOr< std::unique_ptr< SampleProfileReader > > create(const std::string Filename, LLVMContext &C, vfs::FileSystem &FS, FSDiscriminatorPass P=FSDiscriminatorPass::Base, const std::string RemapFilename="")
Create a sample profile reader appropriate to the file format.
SampleProfileMap Profiles
Map every function to its associated profile.
virtual std::error_code readHeader()=0
Read and validate the file header.
bool ProfileIsProbeBased
Whether samples are collected based on pseudo probes.
void reportError(int64_t LineNumber, const Twine &Msg) const
Report a parse error message.
virtual std::unique_ptr< ProfileSymbolList > getProfileSymbolList()
LLVMContext & Ctx
LLVM context used to emit diagnostics.
virtual std::error_code readImpl()=0
The implementaion to read sample profiles from the associated file.
The virtual file system interface.
@ C
The default llvm calling convention, compatible with C.
std::unordered_map< SampleContext, FunctionSamples, SampleContext::Hash > SampleProfileMap
@ HIST_TYPE_INDIR_CALL_TOPN
static StringRef getRepInFormat(StringRef Name, bool UseMD5, std::string &GUIDBuf)
Get the proper representation of a string according to whether the current Format uses MD5 to represe...
This is an optimization pass for GlobalISel generic memory operations.
static unsigned getFSPassBitEnd(FSDiscriminatorPass P)
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
@ Mod
The access may modify the value stored in memory.
static unsigned getN1Bits(int N)
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.