208 #ifndef LLVM_PROFILEDATA_SAMPLEPROFREADER_H 209 #define LLVM_PROFILEDATA_SAMPLEPROFREADER_H 229 #include <system_error> 236 namespace sampleprof {
238 class SampleProfileReader;
246 std::unique_ptr<SymbolRemappingReader> SRR,
248 : Buffer(
std::move(B)), Remappings(
std::move(SRR)), Reader(R) {
249 assert(Remappings &&
"Remappings cannot be nullptr");
275 return Remappings->lookup(FunctionName);
284 std::unique_ptr<MemoryBuffer> Buffer;
285 std::unique_ptr<SymbolRemappingReader> Remappings;
291 bool RemappingApplied =
false;
325 : Profiles(0), Ctx(C), Buffer(
std::move(B)), Format(Format) {}
330 virtual std::error_code readHeader() = 0;
334 if (std::error_code EC = readImpl())
337 Remapper->applyRemapping(Ctx);
342 virtual std::error_code readImpl() = 0;
367 return &Profiles[CanonName];
373 if (
auto FS = Remapper->getSamplesFor(Fname))
378 auto It = Profiles.find(Fname);
379 if (It != Profiles.end())
397 const std::string RemapFilename =
"");
403 const std::string RemapFilename =
"");
440 static std::unique_ptr<ProfileSummary>
442 return std::move(Reader.
Summary);
446 void computeSummary();
448 std::unique_ptr<SampleProfileReaderItaniumRemapper>
Remapper;
463 std::error_code readImpl()
override;
476 virtual std::error_code readHeader()
override;
479 std::error_code readImpl()
override;
483 virtual std::vector<StringRef> *
getNameTable()
override {
return &NameTable; }
492 template <
typename T>
ErrorOr<T> readNumber();
496 template <
typename T>
ErrorOr<T> readUnencodedNumber();
513 std::error_code readFuncProfile(
const uint8_t *Start);
519 std::error_code readMagicIdent();
522 std::error_code readSummary();
525 virtual std::error_code readNameTable();
531 const uint8_t *End =
nullptr;
540 std::error_code readSummaryEntry(std::vector<ProfileSummaryEntry> &Entries);
541 virtual std::error_code verifySPMagic(uint64_t
Magic) = 0;
546 virtual std::error_code verifySPMagic(uint64_t
Magic)
override;
578 std::error_code decompressSection(
const uint8_t *SecStart,
579 const uint64_t SecSize,
580 const uint8_t *&DecompressBuf,
581 uint64_t &DecompressBufSize);
588 std::error_code readSecHdrTableEntry();
589 std::error_code readSecHdrTable();
590 virtual std::error_code readHeader()
override;
591 virtual std::error_code verifySPMagic(uint64_t
Magic)
override = 0;
592 virtual std::error_code readOneSection(
const uint8_t *Start, uint64_t
Size,
601 std::error_code readImpl()
override;
606 uint64_t getFileSize();
612 virtual std::error_code verifySPMagic(uint64_t
Magic)
override;
613 virtual std::error_code readOneSection(
const uint8_t *Start, uint64_t
Size,
615 std::error_code readProfileSymbolList();
616 std::error_code readFuncOffsetTable();
617 std::error_code readFuncProfiles();
625 bool UseAllFuncs =
true;
636 return std::move(ProfSymList);
640 void collectFuncsFrom(
const Module &M)
override;
646 std::vector<std::string> NameTable;
653 bool UseAllFuncs =
true;
654 virtual std::error_code verifySPMagic(uint64_t
Magic)
override;
655 virtual std::error_code readNameTable()
override;
658 virtual std::error_code readHeader()
override;
659 std::error_code readFuncOffsetTable();
670 std::error_code readImpl()
override;
673 void collectFuncsFrom(
const Module &M)
override;
695 GcovBuffer(Buffer.get()) {}
698 std::error_code readHeader()
override;
701 std::error_code readImpl()
override;
707 std::error_code readNameTable();
708 std::error_code readOneFunctionProfile(
const InlineCallStack &InlineStack,
710 std::error_code readFunctionProfiles();
711 std::error_code skipNextWord();
712 template <
typename T>
ErrorOr<T> readNumber();
725 static const uint32_t GCOVTagAFDOFileNames = 0xaa000000;
726 static const uint32_t GCOVTagAFDOFunction = 0xac000000;
733 #endif // LLVM_PROFILEDATA_SAMPLEPROFREADER_H std::vector< std::string > Names
Function names in this profile.
std::unique_ptr< MemoryBuffer > Buffer
Memory buffer holding the profile file.
Represents either an error or a value T.
This class represents lattice values for constants.
static StringRef getRepInFormat(StringRef Name, SampleProfileFormat Format, std::string &GUIDBuf)
A Module instance is used to store all the information related to an LLVM module. ...
FunctionSamples * getSamplesFor(StringRef FunctionName)
Return the samples collected for function F if remapper knows it is present in SampleMap.
Implements a dense probed hash-table based set.
virtual void collectFuncsFrom(const Module &M)
void applyRemapping(LLVMContext &Ctx)
Apply remappings to the profile read by Reader.
bool exist(StringRef FunctionName)
Query whether there is equivalent in the remapper which has been inserted.
GCOVBuffer - A wrapper around MemoryBuffer to provide GCOV specific read operations.
Representation of the samples collected for a function.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static std::unique_ptr< ProfileSummary > takeSummary(SampleProfileReader &Reader)
Take ownership of the summary of this reader.
SampleProfileReaderRawBinary(std::unique_ptr< MemoryBuffer > B, LLVMContext &C, SampleProfileFormat Format=SPF_Binary)
StringMap< FunctionSamples > Profiles
Map every function to its associated profile.
SampleProfileReader(std::unique_ptr< MemoryBuffer > B, LLVMContext &C, SampleProfileFormat Format=SPF_None)
Tagged union holding either a T or a Error.
MemoryBuffer * getBuffer() const
SampleProfileReaderGCC(std::unique_ptr< MemoryBuffer > B, LLVMContext &C)
virtual FunctionSamples * getSamplesFor(StringRef Fname)
Return the samples collected for function F.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
static ErrorOr< std::unique_ptr< SampleProfileReaderItaniumRemapper > > create(const std::string Filename, SampleProfileReader &Reader, LLVMContext &C)
Create a remapper from the given remapping file.
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
Allocate memory in an ever growing pool, as if by bump-pointer.
FunctionSamples * getSamplesFor(const Function &F)
Return the samples collected for function F.
std::error_code read()
The interface to read sample profiles from the associated file.
LLVMContext & Ctx
LLVM context used to emit diagnostics.
FunctionSamples * getOrCreateSamplesFor(const Function &F)
Return the samples collected for function F, create empty FunctionSamples if it doesn't exist...
SampleProfileReaderExtBinary(std::unique_ptr< MemoryBuffer > B, LLVMContext &C, SampleProfileFormat Format=SPF_Ext_Binary)
static StringRef getCanonicalFnName(const Function &F)
Return the canonical name for a function, taking into account suffix elision policy attributes...
SampleProfileReaderItaniumRemapper remaps the profile data from a sample profile data reader...
virtual std::vector< StringRef > * getNameTable() override
It includes all the names that have samples either in outline instance or inline instance.
SampleProfileReaderExtBinaryBase(std::unique_ptr< MemoryBuffer > B, LLVMContext &C, SampleProfileFormat Format)
virtual std::unique_ptr< ProfileSymbolList > getProfileSymbolList() override
SampleProfileReaderExtBinaryBase/SampleProfileWriterExtBinaryBase defines the basic structure of the ...
std::vector< SecHdrTableEntry > SecHdrTable
static const char *const Magic
virtual std::unique_ptr< ProfileSymbolList > getProfileSymbolList()
std::unique_ptr< ProfileSymbolList > ProfSymList
bool at_eof() const
Return true if we've reached the end of file.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
std::vector< StringRef > NameTable
Function name table.
SampleProfileReaderItaniumRemapper(std::unique_ptr< MemoryBuffer > B, std::unique_ptr< SymbolRemappingReader > SRR, SampleProfileReader &R)
virtual std::vector< StringRef > * getNameTable()
It includes all the names that have samples either in outline instance or inline instance.
This interface provides simple read-only access to a block of memory, and provides simple methods for...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
static StringRef readString(WasmObjectFile::ReadContext &Ctx)
StringMap< FunctionSamples > & getProfiles()
Return all the profiles.
std::error_code readHeader() override
Read and validate the file header.
SampleProfileFormat getFormat() const
Return the profile format.
Provides ErrorOr<T> smart pointer.
ProfileSummary & getSummary() const
Return the profile summary.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
SampleProfileReaderText(std::unique_ptr< MemoryBuffer > B, LLVMContext &C)
SampleProfileReaderBinary(std::unique_ptr< MemoryBuffer > B, LLVMContext &C, SampleProfileFormat Format=SPF_None)
void reportError(int64_t LineNumber, Twine Msg) const
Report a parse error message.
Sample-based profile reader.
This class implements an extremely fast bulk output stream that can only output to a stream...
StringRef - Represent a constant reference to a string, i.e.
GCOVBuffer GcovBuffer
GCOV buffer containing the profile.
Diagnostic information for the sample profiler.
void insert(StringRef FunctionName)
Insert function name into remapper.
SampleProfileReaderCompactBinary(std::unique_ptr< MemoryBuffer > B, LLVMContext &C)
std::unique_ptr< ProfileSummary > Summary
Profile summary information.
std::unique_ptr< SampleProfileReaderItaniumRemapper > Remapper