225#ifndef LLVM_PROFILEDATA_SAMPLEPROFREADER_H
226#define LLVM_PROFILEDATA_SAMPLEPROFREADER_H
246#include <system_error>
247#include <unordered_set>
259namespace sampleprof {
261class SampleProfileReader;
269 std::unique_ptr<SymbolRemappingReader> SRR,
272 assert(Remappings &&
"Remappings cannot be nullptr");
298 return Remappings->lookup(FunctionName);
307 std::unique_ptr<MemoryBuffer> Buffer;
308 std::unique_ptr<SymbolRemappingReader> Remappings;
317 bool RemappingApplied =
false;
376 if (std::error_code EC =
readImpl())
432 Fname = R->second.stringRef();
440 if (
auto NameInProfile =
Remapper->lookUpNameInProfile(Fname)) {
543 static std::unique_ptr<ProfileSummary>
545 return std::move(Reader.
Summary);
559 std::unique_ptr<SampleProfileReaderItaniumRemapper>
Remapper;
569 std::unordered_map<uint64_t, std::pair<const uint8_t *, const uint8_t *>>
619 std::error_code
readHeader()
override {
return sampleprof_error::success; }
622 std::error_code readImpl()
override;
633 std::list<SampleContextFrameVector> CSNameTable;
643 std::error_code readHeader()
override;
646 std::error_code readImpl()
override;
661 template <
typename T>
ErrorOr<T> readNumber();
665 template <
typename T>
ErrorOr<T> readUnencodedNumber();
679 std::error_code readFuncProfile(
const uint8_t *Start);
680 std::error_code readFuncProfile(
const uint8_t *Start,
687 std::error_code readMagicIdent();
690 std::error_code readSummary();
693 std::error_code readNameTable();
731 std::error_code readSummaryEntry(std::vector<ProfileSummaryEntry> &Entries);
732 virtual std::error_code verifySPMagic(
uint64_t Magic) = 0;
737 std::error_code verifySPMagic(
uint64_t Magic)
override;
770 std::error_code decompressSection(
const uint8_t *SecStart,
779 std::error_code readSecHdrTableEntry(
uint64_t Idx);
780 std::error_code readSecHdrTable();
782 std::error_code readFuncMetadata(
bool ProfileHasAttribute,
784 std::error_code readFuncMetadata(
bool ProfileHasAttribute);
785 std::error_code readFuncMetadata(
bool ProfileHasAttribute,
787 std::error_code readFuncOffsetTable();
788 std::error_code readFuncProfiles();
791 std::error_code readNameTableSec(
bool IsMD5,
bool FixedLengthMD5);
792 std::error_code readCSNameTableSec();
793 std::error_code readProfileSymbolList();
795 std::error_code readHeader()
override;
804 bool useFuncOffsetList()
const;
826 std::error_code readImpl()
override;
836 bool collectFuncsFromModule()
override;
839 return std::move(ProfSymList);
854 std::error_code verifySPMagic(
uint64_t Magic)
override;
858 return sampleprof_error::success;
889 GcovBuffer(Buffer.
get()) {}
892 std::error_code readHeader()
override;
895 std::error_code readImpl()
override;
901 std::error_code readNameTable();
902 std::error_code readOneFunctionProfile(
const InlineCallStack &InlineStack,
904 std::error_code readFunctionProfiles();
905 std::error_code skipNextWord();
906 template <
typename T>
ErrorOr<T> readNumber();
919 static const uint32_t GCOVTagAFDOFileNames = 0xaa000000;
920 static const uint32_t GCOVTagAFDOFunction = 0xac000000;
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
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.
This file defines the SmallVector class.
static StringRef readString(WasmObjectFile::ReadContext &Ctx)
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.
LLVM_ABI 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.
std::pair< iterator, bool > insert(const ValueT &V)
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.
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 LLVM_ABI bool UseMD5
Whether the profile uses MD5 to represent string.
This class is a wrapper to associative container MapT<KeyT, ValueT> using the hash value of the origi...
This class provides operator overloads to the map container using MD5 as the key type,...
iterator find(const SampleContext &Ctx)
std::vector< FunctionId > NameTable
Function name table.
std::vector< SampleContextFrameVector > CSNameTable
CSNameTable is used to save full context vectors.
SampleProfileReaderBinary(std::unique_ptr< MemoryBuffer > B, LLVMContext &C, SampleProfileFormat Format=SPF_None)
std::vector< uint64_t > MD5SampleContextTable
Table to cache MD5 values of sample contexts corresponding to readSampleContextFromTable(),...
std::vector< FunctionId > * getNameTable() override
It includes all the names that have samples either in outline instance or inline instance.
SampleProfileReaderExtBinaryBase/SampleProfileWriterExtBinaryBase defines the basic structure of the ...
std::vector< SecHdrTableEntry > SecHdrTable
virtual std::error_code readCustomSection(const SecHdrTableEntry &Entry)=0
std::vector< std::pair< SampleContext, uint64_t > > FuncOffsetList
The list version of FuncOffsetTable.
DenseSet< StringRef > FuncsToUse
The set containing the functions to use when compiling a module.
std::unique_ptr< ProfileSymbolList > ProfSymList
std::unique_ptr< ProfileSymbolList > getProfileSymbolList() override
std::error_code verifySPMagic(uint64_t Magic) override=0
SampleProfileReaderExtBinaryBase(std::unique_ptr< MemoryBuffer > B, LLVMContext &C, SampleProfileFormat Format)
DenseMap< hash_code, uint64_t > FuncOffsetTable
The table mapping from a function context's MD5 to the offset of its FunctionSample towards file star...
SampleProfileReaderExtBinary(std::unique_ptr< MemoryBuffer > B, LLVMContext &C, SampleProfileFormat Format=SPF_Ext_Binary)
GCOVBuffer GcovBuffer
GCOV buffer containing the profile.
std::vector< std::string > Names
Function names in this profile.
SampleProfileReaderGCC(std::unique_ptr< MemoryBuffer > B, LLVMContext &C)
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 LLVM_ABI ErrorOr< std::unique_ptr< SampleProfileReaderItaniumRemapper > > create(StringRef Filename, vfs::FileSystem &FS, SampleProfileReader &Reader, LLVMContext &C)
Create a remapper from the given remapping file.
LLVM_ABI 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.
LLVM_ABI 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)
SampleProfileReaderText(std::unique_ptr< MemoryBuffer > B, LLVMContext &C)
void setProfileUseMD5() override
Text format sample profile does not support MD5 for now.
std::error_code readHeader() override
Read and validate the file header.
Sample-based profile reader.
uint32_t MaskedBitFrom
Zero out the discriminator bits higher than bit MaskedBitFrom (0 based).
std::pair< const uint8_t *, const uint8_t * > ProfileSecRange
bool ProfileIsPreInlined
Whether function profile contains ShouldBeInlined contexts.
std::unordered_map< uint64_t, std::pair< const uint8_t *, const uint8_t * > > FuncMetadataIndex
SampleProfileMap & getProfiles()
Return all the profiles.
uint32_t CSProfileCount
Number of context-sensitive profiles.
static LLVM_ABI ErrorOr< std::unique_ptr< SampleProfileReader > > create(StringRef Filename, LLVMContext &C, vfs::FileSystem &FS, FSDiscriminatorPass P=FSDiscriminatorPass::Base, StringRef RemapFilename="")
Create a sample profile reader appropriate to the file format.
bool profileIsProbeBased() const
Whether input profile is based on pseudo probes.
FunctionSamples * getSamplesFor(const Function &F)
Return the samples collected for function F.
LLVM_ABI void dump(raw_ostream &OS=dbgs())
Print all the profiles on stream OS.
bool useMD5() const
Return whether names in the profile are all MD5 numbers.
const Module * M
The current module being compiled if SampleProfileReader is used by compiler.
std::unique_ptr< MemoryBuffer > Buffer
Memory buffer holding the profile file.
std::unique_ptr< SampleProfileReaderItaniumRemapper > Remapper
bool ProfileHasAttribute
Whether the profile has attribute metadata.
bool SkipFlatProf
If SkipFlatProf is true, skip functions marked with !Flat in text mode or sections with SecFlagFlat f...
bool profileIsPreInlined() const
Whether input profile contains ShouldBeInlined contexts.
std::error_code read()
The interface to read sample profiles from the associated file.
bool profileIsFS() const
Whether input profile is flow-sensitive.
MemoryBuffer * getBuffer() const
const HashKeyMap< std::unordered_map, FunctionId, FunctionId > * FuncNameToProfNameMap
virtual ~SampleProfileReader()=default
SampleProfileReaderItaniumRemapper * getRemapper()
bool ProfileIsCS
Whether function profiles are context-sensitive flat profiles.
std::error_code read(const DenseSet< StringRef > &FuncsToUse)
Read sample profiles for the given functions.
bool ProfileIsMD5
Whether the profile uses MD5 for Sample Contexts and function names.
void setModule(const Module *Mod)
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.
LLVM_ABI 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.
virtual bool dumpSectionInfo(raw_ostream &OS=dbgs())
SampleProfileFormat getFormat() const
Return the profile format.
virtual void setProfileUseMD5()
Force the profile to use MD5 in Sample contexts, even if function names are present.
void setDiscriminatorMaskedBitFrom(FSDiscriminatorPass P)
Set the bits for FS discriminators.
virtual std::error_code read(const DenseSet< StringRef > &FuncsToUse, SampleProfileMap &Profiles)
Read sample profiles for the given functions and write them to the given profile map.
void setFuncNameToProfNameMap(const HashKeyMap< std::unordered_map, FunctionId, FunctionId > &FPMap)
virtual std::vector< FunctionId > * getNameTable()
It includes all the names that have samples either in outline instance or inline instance.
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.
FunctionSamples * getSamplesFor(StringRef Fname)
Return the samples collected for function F.
LLVM_ABI void dumpJson(raw_ostream &OS=dbgs())
Print all the profiles on stream OS in the JSON format.
SampleProfileMap Profiles
Map every function to its associated profile.
virtual std::error_code readHeader()=0
Read and validate the file header.
void setSkipFlatProf(bool Skip)
Don't read profile without context if the flag is set.
LLVM_ABI void dumpFunctionProfile(const FunctionSamples &FS, raw_ostream &OS=dbgs())
Print the profile for FunctionSamples on stream OS.
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.
@ HIST_TYPE_INDIR_CALL_TOPN
This is an optimization pass for GlobalISel generic memory operations.
static unsigned getFSPassBitEnd(sampleprof::FSDiscriminatorPass P)
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
LLVM_ABI 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.
Implement std::hash so that hash_code can be used in STL containers.