Go to the documentation of this file.
225 #ifndef LLVM_PROFILEDATA_SAMPLEPROFREADER_H
226 #define LLVM_PROFILEDATA_SAMPLEPROFREADER_H
245 #include <system_error>
246 #include <unordered_set>
254 namespace sampleprof {
256 class SampleProfileReader;
264 std::unique_ptr<SymbolRemappingReader> SRR,
267 assert(Remappings &&
"Remappings cannot be nullptr");
293 return Remappings->lookup(FunctionName);
302 std::unique_ptr<MemoryBuffer> Buffer;
303 std::unique_ptr<SymbolRemappingReader> Remappings;
312 bool RemappingApplied =
false;
371 if (std::error_code EC =
readImpl())
380 virtual std::error_code
readImpl() = 0;
412 if (!FGUID.empty()) {
413 assert(
useMD5() &&
"New name should only be generated for md5 profile");
428 if (
auto NameInProfile =
Remapper->lookUpNameInProfile(Fname)) {
429 auto It =
Profiles.find(*NameInProfile);
452 const std::string RemapFilename =
"");
460 const std::string RemapFilename =
"");
523 static std::unique_ptr<ProfileSummary>
531 std::unique_ptr<SampleProfileReaderItaniumRemapper>
Remapper;
570 std::error_code
readImpl()
override;
578 std::list<SampleContextFrameVector> CSNameTable;
588 virtual std::error_code
readHeader()
override;
591 std::error_code
readImpl()
override;
643 const uint8_t *
End =
nullptr;
653 std::error_code readSummaryEntry(std::vector<ProfileSummaryEntry> &Entries);
659 virtual std::error_code verifySPMagic(
uint64_t Magic)
override;
691 std::error_code decompressSection(
const uint8_t *SecStart,
693 const uint8_t *&DecompressBuf,
713 virtual std::error_code
readHeader()
override;
730 std::unique_ptr<std::vector<std::pair<SampleContext, uint64_t>>>
753 std::unique_ptr<const std::vector<SampleContextFrameVector>>
CSNameTable;
767 std::error_code
readImpl()
override;
791 virtual std::error_code verifySPMagic(
uint64_t Magic)
override;
792 virtual std::error_code
811 std::vector<std::string> NameTable;
817 virtual std::error_code verifySPMagic(
uint64_t Magic)
override;
818 virtual std::error_code readNameTable()
override;
821 virtual std::error_code readHeader()
override;
822 std::error_code readFuncOffsetTable();
833 std::error_code
readImpl()
override;
840 virtual bool useMD5()
override {
return true; }
868 std::error_code
readImpl()
override;
900 #endif // LLVM_PROFILEDATA_SAMPLEPROFREADER_H
bool ProfileIsFS
Whether the function profiles use FS discriminators.
void dump(raw_ostream &OS=dbgs())
Print all the profiles on stream OS.
virtual std::error_code readNameTable()
Read the whole name table.
uint32_t CSProfileCount
Number of context-sensitive profiles.
std::error_code readImpl() override
Read sample profiles from the associated file.
bool FixedLengthMD5
Use fixed length MD5 instead of ULEB128 encoding so NameTable doesn't need to be read in up front and...
static ErrorOr< std::unique_ptr< SampleProfileReaderItaniumRemapper > > create(const std::string Filename, SampleProfileReader &Reader, LLVMContext &C)
Create a remapper from the given remapping file.
SampleProfileReaderExtBinary(std::unique_ptr< MemoryBuffer > B, LLVMContext &C, SampleProfileFormat Format=SPF_Ext_Binary)
This is an optimization pass for GlobalISel generic memory operations.
const Module * M
The current module being compiled if SampleProfileReader is used by compiler.
std::unique_ptr< SampleProfileReaderItaniumRemapper > Remapper
virtual bool useMD5() override
Return whether names in the profile are all MD5 numbers.
SampleProfileReaderExtBinaryBase/SampleProfileWriterExtBinaryBase defines the basic structure of the ...
SampleProfileReaderBinary(std::unique_ptr< MemoryBuffer > B, LLVMContext &C, SampleProfileFormat Format=SPF_None)
std::error_code readFunctionProfiles()
bool profileIsProbeBased() const
Whether input profile is based on pseudo probes.
std::error_code readSectionTag(uint32_t Expected)
Read the section tag and check that it's the same as Expected.
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
SampleProfileReaderRawBinary(std::unique_ptr< MemoryBuffer > B, LLVMContext &C, SampleProfileFormat Format=SPF_Binary)
std::error_code readCSNameTableSec()
std::error_code readProfile(FunctionSamples &FProfile)
Read the contents of the given profile instance.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
ErrorOr< SampleContextFrames > readContextFromTable()
SampleProfileReaderExtBinaryBase(std::unique_ptr< MemoryBuffer > B, LLVMContext &C, SampleProfileFormat Format)
std::vector< SecHdrTableEntry > SecHdrTable
virtual ErrorOr< StringRef > readStringFromTable() override
Read a string indirectly via the name table.
static bool hasFormat(const MemoryBuffer &Buffer)
Return true if Buffer is in the format supported by this class.
std::error_code readNameTableSec(bool IsMD5)
GCOVBuffer GcovBuffer
GCOV buffer containing the profile.
std::unordered_map< SampleContext, FunctionSamples, SampleContext::Hash > SampleProfileMap
void applyRemapping(LLVMContext &Ctx)
Apply remappings to the profile read by Reader.
virtual std::error_code verifySPMagic(uint64_t Magic) override=0
The instances of the Type class are immutable: once they are created, they are never changed.
static unsigned getN1Bits(int N)
std::unique_ptr< const std::vector< SampleContextFrameVector > > CSNameTable
CSNameTable is used to save full context vectors.
virtual std::error_code readCustomSection(const SecHdrTableEntry &Entry)=0
std::error_code readNameTable()
std::vector< std::string > Names
Function names in this profile.
SampleProfileReaderText(std::unique_ptr< MemoryBuffer > B, LLVMContext &C)
std::error_code readMD5NameTable()
std::error_code readSecHdrTableEntry(uint32_t Idx)
virtual ErrorOr< SampleContext > readSampleContextFromTable() override
virtual bool collectFuncsFromModule()
Collect functions with definitions in Module M.
Tagged union holding either a T or a Error.
SampleProfileReaderItaniumRemapper * getRemapper()
std::unique_ptr< ProfileSummary > Summary
Profile summary information.
std::error_code readOneFunctionProfile(const InlineCallStack &InlineStack, bool Update, uint32_t Offset)
This interface provides simple read-only access to a block of memory, and provides simple methods for...
ErrorOr< T > readNumber()
virtual ErrorOr< StringRef > readStringFromTable()
Read a string indirectly via the name table.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
uint32_t getDiscriminatorMask() const
Get the bitmask the discriminators: For FS profiles, return the bit mask for this pass.
std::vector< StringRef > NameTable
Function name table.
static std::unique_ptr< ProfileSummary > takeSummary(SampleProfileReader &Reader)
Take ownership of the summary of this reader.
bool profileIsCS() const
Whether input profile is fully context-sensitive.
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...
std::error_code readImpl() override
Read samples only for functions to use.
static bool hasFormat(const MemoryBuffer &Buffer)
Return true if Buffer is in the format supported by this class.
std::error_code read()
The interface to read sample profiles from the associated file.
(vector float) vec_cmpeq(*A, *B) C
virtual FunctionSamples * getSamplesFor(StringRef Fname)
Return the samples collected for function F.
std::error_code readFuncProfile(const uint8_t *Start)
Read the next function profile instance.
std::unordered_set< std::string > MD5NameBuffer
Extra name buffer holding names created on demand.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Optional< StringRef > lookUpNameInProfile(StringRef FunctionName)
Return the equivalent name in the profile for FunctionName if it exists.
ErrorOr< StringRef > readString()
Read a string from the profile.
virtual std::unique_ptr< ProfileSymbolList > getProfileSymbolList() override
This class implements an extremely fast bulk output stream that can only output to a stream.
virtual std::error_code readHeader()=0
Read and validate the file header.
DenseMap< SampleContext, uint64_t > FuncOffsetTable
The table mapping from function context to the offset of its FunctionSample towards file start.
MemoryBuffer * getBuffer() const
static bool hasFormat(const MemoryBuffer &Buffer)
Return true if Buffer is in the format supported by this class.
virtual void setSkipFlatProf(bool Skip) override
Don't read profile without context if the flag is set.
virtual std::vector< StringRef > * getNameTable()
It includes all the names that have samples either in outline instance or inline instance.
bool exist(StringRef FunctionName)
Query whether there is equivalent in the remapper which has been inserted.
Implements a dense probed hash-table based set.
std::error_code readSecHdrTable()
uint64_t getSectionSize(SecType Type)
Get the total size of all Type sections.
FunctionSamples * getSamplesFor(const Function &F)
Return the samples collected for function F.
void insert(StringRef FunctionName)
Insert function name into remapper.
Representation of the samples collected for a function.
Allocate memory in an ever growing pool, as if by bump-pointer.
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
std::unique_ptr< ProfileSymbolList > ProfSymList
static const uint32_t GCOVTagAFDOFileNames
GCOV tags used to separate sections in the profile file.
std::unique_ptr< std::vector< std::string > > MD5StringBuf
If MD5 is used in NameTable section, the section saves uint64_t data.
This is an important class for using LLVM in a threaded context.
SampleProfileReader(std::unique_ptr< MemoryBuffer > B, LLVMContext &C, SampleProfileFormat Format=SPF_None)
SampleProfileReaderGCC(std::unique_ptr< MemoryBuffer > B, LLVMContext &C)
SampleProfileFormat Format
The format of sample.
virtual ~SampleProfileReader()=default
SampleProfileReaderItaniumRemapper(std::unique_ptr< MemoryBuffer > B, std::unique_ptr< SymbolRemappingReader > SRR, SampleProfileReader &R)
uint32_t MaskedBitFrom
Zero out the discriminator bits higher than bit MaskedBitFrom (0 based).
virtual ErrorOr< SampleContext > readSampleContextFromTable()
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool ProfileIsPreInlined
Whether function profile contains ShouldBeInlined contexts.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
std::error_code readFuncMetadata(bool ProfileHasAttribute)
static bool UseMD5
Whether the profile uses MD5 to represent string.
ErrorOr< StringRef > readString()
static ErrorOr< std::unique_ptr< SampleProfileReader > > create(const std::string Filename, LLVMContext &C, FSDiscriminatorPass P=FSDiscriminatorPass::Base, const std::string RemapFilename="")
Create a sample profile reader appropriate to the file format.
A Module instance is used to store all the information related to an LLVM module.
virtual void setSkipFlatProf(bool Skip)
Don't read profile without context if the flag is set.
Diagnostic information for the sample profiler.
std::error_code readMagicIdent()
Read the contents of Magic number and Version number.
static const uint32_t GCOVTagAFDOFunction
const uint8_t * End
Points to the end of the buffer.
virtual bool hasUniqSuffix()
Return whether any name in the profile contains ".__uniq." suffix.
std::error_code readImpl() override
Read sample profiles in extensible format from the associated file.
StringRef - Represent a constant reference to a string, i.e.
static const char Magic[]
virtual std::unique_ptr< ProfileSymbolList > getProfileSymbolList()
std::error_code readHeader() override
Read and validate the file header.
void reportError(int64_t LineNumber, const Twine &Msg) const
Report a parse error message.
void computeSummary()
Compute summary for this profile.
SampleProfileFormat getFormat() const
Return the profile format.
virtual std::vector< StringRef > * getNameTable() override
It includes all the names that have samples either in outline instance or inline instance.
ProfileSummary & getSummary() const
Return the profile summary.
const CustomOperand< const MCSubtargetInfo & > Msg[]
SampleProfileMap & getProfiles()
Return all the profiles.
void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
SampleProfileMap Profiles
Map every function to its associated profile.
FunctionSamples * getOrCreateSamplesFor(const Function &F)
Return the samples collected for function F, create empty FunctionSamples if it doesn't exist.
Should compile to something r4 addze r3 instead we get
std::error_code skipNextWord()
virtual std::error_code readImpl()=0
The implementaion to read sample profiles from the associated file.
std::error_code readSummary()
Read profile summary.
std::error_code readHeader() override
Read and validate the file header.
virtual bool useMD5() override
Return whether names in the profile are all MD5 numbers.
DenseSet< StringRef > FuncsToUse
The set containing the functions to use when compiling a module.
Sample-based profile reader.
uint64_t getFileSize()
Get the total size of header and all sections.
const uint8_t * MD5NameMemStart
The starting address of NameTable containing fixed length MD5.
virtual std::error_code readHeader() override
Read and validate the file header.
void setModule(const Module *Mod)
@ HIST_TYPE_INDIR_CALL_TOPN
bool profileIsPreInlined() const
Whether input profile contains ShouldBeInlined contexts.
ErrorOr< T > readUnencodedNumber()
Read a numeric value of type T from the profile.
static StringRef getCanonicalFnName(const Function &F)
Return the canonical name for a function, taking into account suffix elision policy attributes.
bool SkipFlatProf
If SkipFlatProf is true, skip the sections with SecFlagFlat flag.
ErrorOr< T > readNumber()
Read a numeric value of type T from the profile.
virtual bool dumpSectionInfo(raw_ostream &OS=dbgs())
std::error_code readImpl() override
Read sample profiles from the associated file.
std::error_code readFuncProfiles()
LLVMContext & Ctx
LLVM context used to emit diagnostics.
bool collectFuncsFromModule() override
Collect functions with definitions in Module M.
Represents either an error or a value T.
virtual bool useMD5()
Return whether names in the profile are all MD5 numbers.
virtual std::error_code readOneSection(const uint8_t *Start, uint64_t Size, const SecHdrTableEntry &Entry)
std::error_code readFuncOffsetTable()
void dumpFunctionProfile(SampleContext FContext, raw_ostream &OS=dbgs())
Print the profile for FContext on stream OS.
std::error_code readProfileSymbolList()
SampleProfileReaderItaniumRemapper remaps the profile data from a sample profile data reader,...
static bool hasFormat(const MemoryBuffer &Buffer)
Return true if Buffer is in the format supported by this class.
static unsigned getFSPassBitEnd(FSDiscriminatorPass P)
void setDiscriminatorMaskedBitFrom(FSDiscriminatorPass P)
Set the bits for FS discriminators.
bool ProfileIsCS
Whether function profiles are context-sensitive flat profiles.
GCOVBuffer - A wrapper around MemoryBuffer to provide GCOV specific read operations.
virtual bool dumpSectionInfo(raw_ostream &OS=dbgs()) override
static bool hasFormat(const MemoryBuffer &Buffer)
Return true if Buffer is in the format supported by this class.
std::unique_ptr< std::vector< std::pair< SampleContext, uint64_t > > > OrderedFuncOffsets
Function offset mapping ordered by contexts.
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.
const uint8_t * Data
Points to the current location in the buffer.
virtual std::error_code readHeader() override
Read and validate the file header.
std::unique_ptr< MemoryBuffer > Buffer
Memory buffer holding the profile file.
SampleProfileReaderCompactBinary(std::unique_ptr< MemoryBuffer > B, LLVMContext &C)
bool collectFuncsFromModule() override
Collect functions with definitions in Module M.
bool ProfileIsProbeBased
Whether samples are collected based on pseudo probes.
bool at_eof() const
Return true if we've reached the end of file.