45#include <system_error>
49using namespace sampleprof;
51#define DEBUG_TYPE "samplepgo-reader"
58 cl::desc(
"Profile uses flow sensitive discriminators"));
66 OS <<
"Function: " << FS.getContext().toString() <<
": " << FS;
71 std::vector<NameFunctionSamples> V;
73 for (
const auto &
I : V)
80 for (
const auto &
I : BodySamples) {
90 if (!CallTargets.empty()) {
92 for (
const auto &J : CallTargets) {
105 for (
const auto &
I : CallsiteSamples)
106 for (
const auto &FS :
I.second) {
126 if (!BodySamples.empty())
130 if (!CallsiteSamples.empty())
132 [&] { DumpCallsiteSamples(CallsiteSamples); });
138 std::vector<NameFunctionSamples> V;
142 for (
const auto &
F : V)
161 size_t n2 = Input.
rfind(
':');
162 size_t n1 = Input.
rfind(
':', n2 - 1);
163 FName = Input.
substr(0, n1);
224 if (Input[
Depth] ==
'!') {
225 LineTy = LineType::Metadata;
229 size_t n1 = Input.
find(
':');
231 size_t n2 = Loc.
find(
'.');
245 LineTy = LineType::BodyProfile;
246 size_t n3 = Rest.
find(
' ');
296 if (n4 == Rest.
size())
302 LineTy = LineType::CallSiteProfile;
304 CalleeName = Rest.
substr(0, n3);
322 uint32_t TopLevelProbeProfileCount = 0;
332 if (pos == LineIt->
npos || (*LineIt)[pos] ==
'#')
346 if ((*LineIt)[0] !=
' ') {
347 uint64_t NumSamples, NumHeadSamples;
349 if (!
ParseHead(*LineIt, FName, NumSamples, NumHeadSamples)) {
351 "Expected 'mangled_name:NUM:NUM', found " + *LineIt);
372 Discriminator, FName, TargetCountMap, FunctionHash,
375 "Expected 'NUM[.NUM]: NUM[ mangled_name:NUM]*', found " +
379 if (LineTy != LineType::Metadata &&
Depth == DepthMetadata) {
382 "Found non-metadata after metadata: " + *LineIt);
393 case LineType::CallSiteProfile: {
402 case LineType::BodyProfile: {
407 for (
const auto &name_count : TargetCountMap) {
409 LineOffset, Discriminator,
418 case LineType::Metadata: {
423 ++TopLevelProbeProfileCount;
428 DepthMetadata =
Depth;
436 "Cannot have both context-sensitive and regular profile");
438 assert((TopLevelProbeProfileCount == 0 ||
439 TopLevelProbeProfileCount ==
Profiles.size()) &&
440 "Cannot have both probe-based profiles and regular profiles");
458 if ((*LineIt)[0] !=
' ') {
459 uint64_t NumSamples, NumHeadSamples;
461 result =
ParseHead(*LineIt, FName, NumSamples, NumHeadSamples);
469 unsigned NumBytesRead = 0;
472 if (Val > std::numeric_limits<T>::max()) {
476 }
else if (
Data + NumBytesRead >
End) {
482 Data += NumBytesRead;
483 return static_cast<T>(Val);
488 if (
Data + Str.size() + 1 >
End) {
494 Data += Str.size() + 1;
506 using namespace support;
507 T Val = endian::readNext<T, llvm::endianness::little>(
Data);
513 auto Idx = readNumber<size_t>();
514 if (std::error_code EC =
Idx.getError())
516 if (*
Idx >= Table.size())
524 if (std::error_code EC =
Idx.getError())
533 auto ContextIdx = readNumber<size_t>();
534 if (std::error_code EC = ContextIdx.getError())
539 *RetIdx = *ContextIdx;
549 if (std::error_code EC = FContext.getError())
554 if (std::error_code EC = FName.getError())
569 return std::make_pair(Context, Hash);
574 auto NumSamples = readNumber<uint64_t>();
575 if (std::error_code EC = NumSamples.getError())
580 auto NumRecords = readNumber<uint32_t>();
581 if (std::error_code EC = NumRecords.getError())
585 auto LineOffset = readNumber<uint64_t>();
586 if (std::error_code EC = LineOffset.getError())
590 return std::error_code();
593 auto Discriminator = readNumber<uint64_t>();
594 if (std::error_code EC = Discriminator.getError())
597 auto NumSamples = readNumber<uint64_t>();
598 if (std::error_code EC = NumSamples.getError())
601 auto NumCalls = readNumber<uint32_t>();
602 if (std::error_code EC = NumCalls.getError())
608 for (
uint32_t J = 0; J < *NumCalls; ++J) {
610 if (std::error_code EC = CalledFunction.getError())
613 auto CalledFunctionSamples = readNumber<uint64_t>();
614 if (std::error_code EC = CalledFunctionSamples.getError())
618 *CalledFunction, *CalledFunctionSamples);
621 FProfile.
addBodySamples(*LineOffset, DiscriminatorVal, *NumSamples);
625 auto NumCallsites = readNumber<uint32_t>();
626 if (std::error_code EC = NumCallsites.getError())
629 for (
uint32_t J = 0; J < *NumCallsites; ++J) {
630 auto LineOffset = readNumber<uint64_t>();
631 if (std::error_code EC = LineOffset.getError())
634 auto Discriminator = readNumber<uint64_t>();
635 if (std::error_code EC = Discriminator.getError())
639 if (std::error_code EC = FName.getError())
648 if (std::error_code EC =
readProfile(CalleeProfile))
658 auto NumHeadSamples = readNumber<uint64_t>();
659 if (std::error_code EC = NumHeadSamples.getError())
663 if (std::error_code EC = FContextHash.getError())
666 auto &[FContext, Hash] = *FContextHash;
673 if (FContext.hasContext())
696 switch (Entry.Type) {
701 Summary->setPartialProfile(
true);
710 bool FixedLengthMD5 =
739 "func offset table should always be sorted in CS profile");
810 auto Size = readNumber<uint64_t>();
811 if (std::error_code EC =
Size.getError())
815 if (UseFuncOffsetList)
822 if (std::error_code EC = FContextHash.getError())
825 auto &[FContext, Hash] = *FContextHash;
826 auto Offset = readNumber<uint64_t>();
827 if (std::error_code EC =
Offset.getError())
830 if (UseFuncOffsetList)
852 const uint8_t *Start =
Data;
853 if (!LoadFuncsToBeUsed) {
884 const auto &FContext = NameOffset.first;
896 if (!CommonContext || !CommonContext->
isPrefixOf(FContext))
897 CommonContext = &FContext;
900 if (CommonContext == &FContext ||
901 (CommonContext && CommonContext->
isPrefixOf(FContext))) {
904 const uint8_t *FuncProfileAddr = Start + NameOffset.second;
916 const uint8_t *FuncProfileAddr = Start + iter->second;
925 StringRef FuncNameStr = FuncName.stringRef();
928 const uint8_t *FuncProfileAddr = Start + NameOffset.second;
938 const uint8_t *FuncProfileAddr = Start + iter->second;
946 "Cannot have both context-sensitive and regular profile");
948 "Section flag should be consistent with actual profile");
954 ProfSymList = std::make_unique<ProfileSymbolList>();
963std::error_code SampleProfileReaderExtBinaryBase::decompressSection(
964 const uint8_t *SecStart,
const uint64_t SecSize,
965 const uint8_t *&DecompressBuf,
uint64_t &DecompressBufSize) {
967 End = SecStart + SecSize;
968 auto DecompressSize = readNumber<uint64_t>();
969 if (std::error_code EC = DecompressSize.getError())
971 DecompressBufSize = *DecompressSize;
973 auto CompressSize = readNumber<uint64_t>();
974 if (std::error_code EC = CompressSize.getError())
981 size_t UCSize = DecompressBufSize;
986 DecompressBuf =
reinterpret_cast<const uint8_t *
>(
Buffer);
991 const uint8_t *BufStart =
992 reinterpret_cast<const uint8_t *
>(
Buffer->getBufferStart());
1003 const uint8_t *SecStart = BufStart + Entry.Offset;
1012 const uint8_t *DecompressBuf;
1014 if (std::error_code EC = decompressSection(
1015 SecStart, SecSize, DecompressBuf, DecompressBufSize))
1017 SecStart = DecompressBuf;
1018 SecSize = DecompressBufSize;
1021 if (std::error_code EC =
readOneSection(SecStart, SecSize, Entry))
1023 if (
Data != SecStart + SecSize)
1028 Data = BufStart + Entry.Offset;
1029 End = BufStart +
Buffer->getBufferSize();
1036std::error_code SampleProfileReaderRawBinary::verifySPMagic(
uint64_t Magic) {
1042std::error_code SampleProfileReaderExtBinary::verifySPMagic(
uint64_t Magic) {
1049 auto Size = readNumber<size_t>();
1050 if (std::error_code EC =
Size.getError())
1071 for (
size_t I = 0;
I < *
Size; ++
I) {
1073 if (std::error_code EC =
Name.getError())
1090 bool FixedLengthMD5) {
1091 if (FixedLengthMD5) {
1093 errs() <<
"If FixedLengthMD5 is true, UseMD5 has to be true";
1094 auto Size = readNumber<size_t>();
1095 if (std::error_code EC =
Size.getError())
1099 "Fixed length MD5 name table does not contain specified number of "
1106 for (
size_t I = 0;
I < *
Size; ++
I) {
1107 using namespace support;
1108 uint64_t FID = endian::read<uint64_t, endianness::little, unaligned>(
1119 assert(!FixedLengthMD5 &&
"FixedLengthMD5 should be unreachable here");
1120 auto Size = readNumber<size_t>();
1121 if (std::error_code EC =
Size.getError())
1128 for (
size_t I = 0;
I < *
Size; ++
I) {
1129 auto FID = readNumber<uint64_t>();
1130 if (std::error_code EC = FID.getError())
1149 auto Size = readNumber<size_t>();
1150 if (std::error_code EC =
Size.getError())
1163 for (
size_t I = 0;
I < *
Size; ++
I) {
1165 auto ContextSize = readNumber<uint32_t>();
1166 if (std::error_code EC = ContextSize.getError())
1168 for (
uint32_t J = 0; J < *ContextSize; ++J) {
1170 if (std::error_code EC = FName.getError())
1172 auto LineOffset = readNumber<uint64_t>();
1173 if (std::error_code EC = LineOffset.getError())
1177 return std::error_code();
1179 auto Discriminator = readNumber<uint64_t>();
1180 if (std::error_code EC = Discriminator.getError())
1184 FName.get(),
LineLocation(LineOffset.get(), Discriminator.get()));
1196 auto Checksum = readNumber<uint64_t>();
1197 if (std::error_code EC = Checksum.getError())
1203 if (ProfileHasAttribute) {
1205 if (std::error_code EC =
Attributes.getError())
1213 auto NumCallsites = readNumber<uint32_t>();
1214 if (std::error_code EC = NumCallsites.getError())
1217 for (
uint32_t J = 0; J < *NumCallsites; ++J) {
1218 auto LineOffset = readNumber<uint64_t>();
1219 if (std::error_code EC = LineOffset.getError())
1222 auto Discriminator = readNumber<uint64_t>();
1223 if (std::error_code EC = Discriminator.getError())
1227 if (std::error_code EC = FContextHash.getError())
1230 auto &[FContext, Hash] = *FContextHash;
1236 *Discriminator))[FContext.getFunction()]);
1238 if (std::error_code EC =
1252 if (std::error_code EC = FContextHash.getError())
1254 auto &[FContext, Hash] = *FContextHash;
1258 FProfile = &It->second;
1271 auto Type = readUnencodedNumber<uint64_t>();
1272 if (std::error_code EC =
Type.getError())
1274 Entry.Type =
static_cast<SecType>(*Type);
1276 auto Flags = readUnencodedNumber<uint64_t>();
1277 if (std::error_code EC = Flags.getError())
1279 Entry.Flags = *Flags;
1281 auto Offset = readUnencodedNumber<uint64_t>();
1282 if (std::error_code EC =
Offset.getError())
1286 auto Size = readUnencodedNumber<uint64_t>();
1287 if (std::error_code EC =
Size.getError())
1291 Entry.LayoutIndex =
Idx;
1297 auto EntryNum = readUnencodedNumber<uint64_t>();
1298 if (std::error_code EC = EntryNum.getError())
1301 for (
uint64_t i = 0; i < (*EntryNum); i++)
1309 const uint8_t *BufStart =
1310 reinterpret_cast<const uint8_t *
>(
Buffer->getBufferStart());
1312 End = BufStart +
Buffer->getBufferSize();
1326 if (Entry.Type ==
Type)
1340 FileSize = std::max(Entry.Offset + Entry.Size, FileSize);
1348 Flags.append(
"{compressed,");
1353 Flags.append(
"flat,");
1355 switch (Entry.Type) {
1358 Flags.append(
"fixlenmd5,");
1360 Flags.append(
"md5,");
1362 Flags.append(
"uniq,");
1366 Flags.append(
"partial,");
1368 Flags.append(
"context,");
1370 Flags.append(
"preInlined,");
1372 Flags.append(
"fs-discriminator,");
1376 Flags.append(
"ordered,");
1380 Flags.append(
"probe,");
1382 Flags.append(
"attr,");
1387 char &last = Flags.back();
1398 OS <<
getSecName(Entry.Type) <<
" - Offset: " << Entry.Offset
1399 <<
", Size: " << Entry.Size <<
", Flags: " <<
getSecFlagsStr(Entry)
1402 TotalSecsSize += Entry.Size;
1406 "Size of 'header + sections' doesn't match the total size of profile");
1408 OS <<
"Header Size: " << HeaderSize <<
"\n";
1409 OS <<
"Total Sections Size: " << TotalSecsSize <<
"\n";
1416 auto Magic = readNumber<uint64_t>();
1417 if (std::error_code EC = Magic.getError())
1419 else if (std::error_code EC = verifySPMagic(*Magic))
1423 auto Version = readNumber<uint64_t>();
1424 if (std::error_code EC =
Version.getError())
1433 Data =
reinterpret_cast<const uint8_t *
>(
Buffer->getBufferStart());
1447std::error_code SampleProfileReaderBinary::readSummaryEntry(
1448 std::vector<ProfileSummaryEntry> &Entries) {
1449 auto Cutoff = readNumber<uint64_t>();
1450 if (std::error_code EC = Cutoff.getError())
1453 auto MinBlockCount = readNumber<uint64_t>();
1454 if (std::error_code EC = MinBlockCount.getError())
1457 auto NumBlocks = readNumber<uint64_t>();
1458 if (std::error_code EC = NumBlocks.getError())
1461 Entries.emplace_back(*Cutoff, *MinBlockCount, *NumBlocks);
1466 auto TotalCount = readNumber<uint64_t>();
1467 if (std::error_code EC = TotalCount.getError())
1470 auto MaxBlockCount = readNumber<uint64_t>();
1471 if (std::error_code EC = MaxBlockCount.getError())
1474 auto MaxFunctionCount = readNumber<uint64_t>();
1475 if (std::error_code EC = MaxFunctionCount.getError())
1478 auto NumBlocks = readNumber<uint64_t>();
1479 if (std::error_code EC = NumBlocks.getError())
1482 auto NumFunctions = readNumber<uint64_t>();
1483 if (std::error_code EC = NumFunctions.getError())
1486 auto NumSummaryEntries = readNumber<uint64_t>();
1487 if (std::error_code EC = NumSummaryEntries.getError())
1490 std::vector<ProfileSummaryEntry> Entries;
1491 for (
unsigned i = 0; i < *NumSummaryEntries; i++) {
1492 std::error_code EC = readSummaryEntry(Entries);
1496 Summary = std::make_unique<ProfileSummary>(
1498 *MaxFunctionCount, *NumBlocks, *NumFunctions);
1504 const uint8_t *
Data =
1505 reinterpret_cast<const uint8_t *
>(
Buffer.getBufferStart());
1511 const uint8_t *
Data =
1512 reinterpret_cast<const uint8_t *
>(
Buffer.getBufferStart());
1528 return static_cast<T>(Val);
1529 }
else if (
sizeof(
T) <=
sizeof(
uint64_t)) {
1532 return static_cast<T>(Val);
1594 Names.push_back(std::string(Str));
1620 if (InlineStack.
size() == 0)
1639 if (InlineStack.
size() == 0) {
1687 for (
auto *CallerProfile : NewStack)
1688 CallerProfile->addTotalSamples(Count);
1697 for (
uint32_t J = 0; J < NumTargets; J++) {
1758 StringRef Magic(
reinterpret_cast<const char *
>(
Buffer.getBufferStart()));
1759 return Magic ==
"adcg*704";
1768 "Profile data remapping cannot be applied to profile data "
1769 "using MD5 names (original mangled names are not available).",
1776 assert(Remappings &&
"should be initialized while creating remapper");
1779 Sample.second.findAllNames(NamesInSample);
1780 for (
auto &
Name : NamesInSample) {
1782 if (
auto Key = Remappings->insert(NameStr))
1783 NameMap.insert({Key, NameStr});
1787 RemappingApplied =
true;
1790std::optional<StringRef>
1792 if (
auto Key = Remappings->lookup(Fname)) {
1794 if (!Result.empty())
1797 return std::nullopt;
1806 : FS.getBufferForFile(Filename);
1807 if (std::error_code EC = BufferOrErr.getError())
1809 auto Buffer = std::move(BufferOrErr.get());
1811 return std::move(Buffer);
1830 if (std::error_code EC = BufferOrError.getError())
1832 return create(BufferOrError.get(),
C, FS,
P, RemapFilename);
1851 if (std::error_code EC = BufferOrError.getError())
1853 return create(BufferOrError.get(), Reader,
C);
1870 auto Remappings = std::make_unique<SymbolRemappingReader>();
1871 if (
Error E = Remappings->read(*
B)) {
1881 return std::make_unique<SampleProfileReaderItaniumRemapper>(
1882 std::move(
B), std::move(Remappings), Reader);
1900 std::unique_ptr<SampleProfileReader> Reader;
1912 if (!RemapFilename.
empty()) {
1914 RemapFilename, FS, *Reader,
C);
1915 if (std::error_code EC = ReaderOrErr.getError()) {
1916 std::string Msg =
"Could not create remapper: " + EC.message();
1920 Reader->Remapper = std::move(ReaderOrErr.get());
1923 if (std::error_code EC = Reader->readHeader()) {
1927 Reader->setDiscriminatorMaskedBitFrom(
P);
1929 return std::move(Reader);
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
This file defines the DenseMap class.
Provides ErrorOr<T> smart pointer.
This file supports working with JSON data.
Module.h This file contains the declarations for the Module class.
static bool isDigit(const char C)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static bool ParseHead(const StringRef &Input, StringRef &FName, uint64_t &NumSamples, uint64_t &NumHeadSamples)
Parse Input as function head.
static void dumpFunctionProfileJson(const FunctionSamples &S, json::OStream &JOS, bool TopLevel=false)
static bool isOffsetLegal(unsigned L)
Returns true if line offset L is legal (only has 16 bits).
static bool ParseLine(const StringRef &Input, LineType &LineTy, uint32_t &Depth, uint64_t &NumSamples, uint32_t &LineOffset, uint32_t &Discriminator, StringRef &CalleeName, DenseMap< StringRef, uint64_t > &TargetCountMap, uint64_t &FunctionHash, uint32_t &Attributes)
Parse Input as line sample.
static cl::opt< bool > ProfileIsFSDisciminator("profile-isfs", cl::Hidden, cl::init(false), cl::desc("Profile uses flow sensitive discriminators"))
static std::string getSecFlagsStr(const SecHdrTableEntry &Entry)
static bool parseMetadata(const StringRef &Input, uint64_t &FunctionHash, uint32_t &Attributes)
Parse Input that contains metadata.
Defines the virtual file system interface vfs::FileSystem.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
LLVM_ATTRIBUTE_RETURNS_NONNULL void * Allocate(size_t Size, Align Alignment)
Allocate space at the specified alignment.
Implements a dense probed hash-table based set.
Diagnostic information for the sample profiler.
Represents either an error or a value T.
Lightweight error class with error context and mandatory checking.
Tagged union holding either a T or a Error.
bool readInt(uint32_t &Val)
bool readInt64(uint64_t &Val)
bool readGCOVVersion(GCOV::GCOVVersion &version)
readGCOVVersion - Read GCOV version.
bool readString(StringRef &str)
bool readGCDAFormat()
readGCDAFormat - Check GCDA signature is valid at the beginning of buffer.
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
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...
virtual StringRef getBufferIdentifier() const
Return an identifier for this buffer, typically the filename it was read from.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getSTDIN()
Read all of stdin into a file buffer, and return it.
static const ArrayRef< uint32_t > DefaultCutoffs
A vector of useful cutoff values for detailed summary.
std::unique_ptr< ProfileSummary > computeSummaryForProfiles(const sampleprof::SampleProfileMap &Profiles)
void push_back(const T &Elt)
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.
bool getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
constexpr bool empty() const
empty - Check if the string is empty.
constexpr size_t size() const
size - Get the string size.
size_t find_last_of(char C, size_t From=npos) const
Find the last character in the string that is C, or npos if not found.
size_t find_first_of(char C, size_t From=0) const
Find the first character in the string that is C, or npos if not found.
size_t rfind(char C, size_t From=npos) const
Search for the last character C in the string.
size_t find(char C, size_t From=0) const
Search for the first character C in the string.
StringRef trim(char Char) const
Return string with consecutive Char characters starting from the left and right removed.
static constexpr size_t npos
size_t find_first_not_of(char C, size_t From=0) const
Find the first character in the string that is not C or npos if not found.
int64_t getLineNum() const
StringRef getMessage() const
Target - Wrapper for Target specific information.
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)
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
json::OStream allows writing well-formed JSON without materializing all structures as json::Value ahe...
void object(Block Contents)
Emit an object whose elements are emitted in the provided Block.
void attribute(llvm::StringRef Key, const Value &Contents)
Emit an attribute whose value is self-contained (number, vector<int> etc).
void attributeArray(llvm::StringRef Key, Block Contents)
Emit an attribute whose value is an array with elements from the Block.
A forward iterator which reads text lines from a buffer.
int64_t line_number() const
Return the current line number. May return any number at EOF.
bool is_at_eof() const
Return true if we've reached EOF or are an "end" iterator.
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.
StringRef stringRef() const
Convert to StringRef.
uint64_t getHashCode() const
Get hash code of this object.
std::string str() const
Convert to a string, usually for output purpose.
Representation of the samples collected for a function.
static bool ProfileIsPreInlined
sampleprof_error addTotalSamples(uint64_t Num, uint64_t Weight=1)
uint64_t getHeadSamples() const
For top-level functions, return the total number of branch samples that have the function as the bran...
void setFunction(FunctionId NewFunctionID)
Set the name of the function.
FunctionId getFunction() const
Return the function name.
sampleprof_error addHeadSamples(uint64_t Num, uint64_t Weight=1)
sampleprof_error addCalledTargetSamples(uint32_t LineOffset, uint32_t Discriminator, FunctionId Func, uint64_t Num, uint64_t Weight=1)
FunctionSamplesMap & functionSamplesAt(const LineLocation &Loc)
Return the function samples at the given callsite location.
static bool ProfileIsProbeBased
static StringRef getCanonicalFnName(const Function &F)
Return the canonical name for a function, taking into account suffix elision policy attributes.
sampleprof_error addBodySamples(uint32_t LineOffset, uint32_t Discriminator, uint64_t Num, uint64_t Weight=1)
void setFunctionHash(uint64_t Hash)
static bool ProfileIsFS
If this profile uses flow sensitive discriminators.
SampleContext & getContext() const
static bool HasUniqSuffix
Whether the profile contains any ".__uniq." suffix in a name.
uint64_t getTotalSamples() const
Return the total number of samples collected inside the function.
const CallsiteSampleMap & getCallsiteSamples() const
Return all the callsite samples collected in the body of the function.
void setContext(const SampleContext &FContext)
const BodySampleMap & getBodySamples() const
Return all the samples collected in the body of the function.
std::pair< iterator, bool > try_emplace(const key_type &Hash, const original_key_type &Key, Ts &&...Args)
void setAllAttributes(uint32_t A)
uint64_t getHashCode() const
FunctionId getFunction() const
bool isPrefixOf(const SampleContext &That) const
iterator find(const SampleContext &Ctx)
mapped_type & create(const SampleContext &Ctx)
std::error_code readProfile(FunctionSamples &FProfile)
Read the contents of the given profile instance.
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< FunctionId > NameTable
Function name table.
ErrorOr< T > readNumber()
Read a numeric value of type T from the profile.
ErrorOr< SampleContextFrames > readContextFromTable(size_t *RetIdx=nullptr)
Read a context indirectly via the CSNameTable.
ErrorOr< std::pair< SampleContext, uint64_t > > readSampleContextFromTable()
Read a context indirectly via the CSNameTable if the profile has context, otherwise same as readStrin...
std::error_code readHeader() override
Read and validate the file header.
const uint64_t * MD5SampleContextStart
The starting address of the table of MD5 values of sample contexts.
std::vector< SampleContextFrameVector > CSNameTable
CSNameTable is used to save full context vectors.
std::error_code readImpl() override
Read sample profiles from the associated file.
ErrorOr< FunctionId > readStringFromTable(size_t *RetIdx=nullptr)
Read a string indirectly via the name table. Optionally return the index.
std::vector< uint64_t > MD5SampleContextTable
Table to cache MD5 values of sample contexts corresponding to readSampleContextFromTable(),...
ErrorOr< size_t > readStringIndex(T &Table)
Read the string index and check whether it overflows the table.
const uint8_t * End
Points to the end of the buffer.
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.
std::error_code readFuncOffsetTable()
std::vector< SecHdrTableEntry > SecHdrTable
std::error_code readFuncMetadata(bool ProfileHasAttribute)
bool collectFuncsFromModule() override
Collect functions with definitions in Module M.
uint64_t getSectionSize(SecType Type)
Get the total size of all Type sections.
std::error_code readCSNameTableSec()
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::error_code readSecHdrTable()
std::error_code readFuncProfiles()
bool useFuncOffsetList() const
Determine which container readFuncOffsetTable() should populate, the list FuncOffsetList or the map F...
std::error_code readNameTableSec(bool IsMD5, bool FixedLengthMD5)
std::error_code readSecHdrTableEntry(uint64_t Idx)
std::error_code readImpl() override
Read sample profiles in extensible format from the associated file.
virtual std::error_code readOneSection(const uint8_t *Start, uint64_t Size, const SecHdrTableEntry &Entry)
bool dumpSectionInfo(raw_ostream &OS=dbgs()) override
bool SkipFlatProf
If SkipFlatProf is true, skip the sections with SecFlagFlat flag.
DenseMap< hash_code, uint64_t > FuncOffsetTable
The table mapping from a function context's MD5 to the offset of its FunctionSample towards file star...
std::error_code readHeader() override
Read and validate the file header.
uint64_t getFileSize()
Get the total size of header and all sections.
std::error_code readProfileSymbolList()
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()
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.
static ErrorOr< std::unique_ptr< SampleProfileReaderItaniumRemapper > > create(StringRef 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.
std::optional< StringRef > lookUpNameInProfile(StringRef FunctionName)
Return the equivalent name in the profile for FunctionName if it exists.
static bool hasFormat(const MemoryBuffer &Buffer)
Return true if Buffer is in the format supported by this class.
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.
bool ProfileIsPreInlined
Whether function profile contains ShouldBeInlined contexts.
SampleProfileMap & getProfiles()
Return all the profiles.
uint32_t CSProfileCount
Number of context-sensitive profiles.
static 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.
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
MemoryBuffer * getBuffer() const
bool ProfileIsCS
Whether function profiles are context-sensitive flat profiles.
bool ProfileIsMD5
Whether the profile uses MD5 for Sample Contexts and function names.
std::unique_ptr< ProfileSummary > Summary
Profile summary information.
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.
bool ProfileIsFS
Whether the function profiles use FS discriminators.
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.
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.
Representation of a single sample record.
uint64_t getSamples() const
const SortedCallTargetSet getSortedCallTargets() const
The virtual file system interface.
@ C
The default llvm calling convention, compatible with C.
initializer< Ty > init(const Ty &Val)
Error decompress(ArrayRef< uint8_t > Input, uint8_t *Output, size_t &UncompressedSize)
void sortFuncProfiles(const SampleProfileMap &ProfileMap, std::vector< NameFunctionSamples > &SortedProfiles)
static uint64_t SPMagic(SampleProfileFormat Format=SPF_Binary)
static bool hasSecFlag(const SecHdrTableEntry &Entry, SecFlagType Flag)
std::map< LineLocation, FunctionSamplesMap > CallsiteSampleMap
@ HIST_TYPE_INDIR_CALL_TOPN
uint64_t MD5Hash(const FunctionId &Obj)
std::map< LineLocation, SampleRecord > BodySampleMap
@ SecFlagIsPreInlined
SecFlagIsPreInlined means this profile contains ShouldBeInlined contexts thus this is CS preinliner c...
@ SecFlagPartial
SecFlagPartial means the profile is for common/shared code.
@ SecFlagFSDiscriminator
SecFlagFSDiscriminator means this profile uses flow-sensitive discriminators.
@ SecFlagFullContext
SecFlagContext means this is context-sensitive flat profile for CSSPGO.
SmallVector< SampleContextFrame, 1 > SampleContextFrameVector
static std::string getSecName(SecType Type)
static uint64_t SPVersion()
uint64_t read64le(const void *P)
void write64le(void *P, uint64_t V)
This is an optimization pass for GlobalISel generic memory operations.
static Expected< std::unique_ptr< MemoryBuffer > > setupMemoryBuffer(const Twine &Filename, vfs::FileSystem &FS)
void handleAllErrors(Error E, HandlerTs &&... Handlers)
Behaves the same as handleErrors, except that by contract all errors must be handled by the given han...
uint64_t decodeULEB128(const uint8_t *p, unsigned *n=nullptr, const uint8_t *end=nullptr, const char **error=nullptr)
Utility function to decode a ULEB128 value.
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
sampleprof_error mergeSampleProfErrors(sampleprof_error &Accumulator, sampleprof_error Result)
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
auto count(R &&Range, const E &Element)
Wrapper function around std::count to count the number of times an element Element occurs in the give...
Represents the relative location of an instruction.