#include "llvm/ProfileData/SampleProfReader.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/ProfileSummary.h"
#include "llvm/ProfileData/ProfileCommon.h"
#include "llvm/ProfileData/SampleProf.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Compression.h"
#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/JSON.h"
#include "llvm/Support/LEB128.h"
#include "llvm/Support/LineIterator.h"
#include "llvm/Support/MD5.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/VirtualFileSystem.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <limits>
#include <memory>
#include <system_error>
#include <vector>
usingnamespacellvm;
usingnamespacesampleprof;
#define DEBUG_TYPE …
static cl::opt<bool> ProfileIsFSDisciminator(
"profile-isfs", cl::Hidden, cl::init(false),
cl::desc("Profile uses flow sensitive discriminators"));
void SampleProfileReader::dumpFunctionProfile(const FunctionSamples &FS,
raw_ostream &OS) { … }
void SampleProfileReader::dump(raw_ostream &OS) { … }
static void dumpFunctionProfileJson(const FunctionSamples &S,
json::OStream &JOS, bool TopLevel = false) { … }
void SampleProfileReader::dumpJson(raw_ostream &OS) { … }
static bool ParseHead(const StringRef &Input, StringRef &FName,
uint64_t &NumSamples, uint64_t &NumHeadSamples) { … }
static bool isOffsetLegal(unsigned L) { … }
static bool parseMetadata(const StringRef &Input, uint64_t &FunctionHash,
uint32_t &Attributes) { … }
enum class LineType { … };
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,
bool &IsFlat) { … }
std::error_code SampleProfileReaderText::readImpl() { … }
bool SampleProfileReaderText::hasFormat(const MemoryBuffer &Buffer) { … }
template <typename T> ErrorOr<T> SampleProfileReaderBinary::readNumber() { … }
ErrorOr<StringRef> SampleProfileReaderBinary::readString() { … }
template <typename T>
ErrorOr<T> SampleProfileReaderBinary::readUnencodedNumber() { … }
template <typename T>
inline ErrorOr<size_t> SampleProfileReaderBinary::readStringIndex(T &Table) { … }
ErrorOr<FunctionId>
SampleProfileReaderBinary::readStringFromTable(size_t *RetIdx) { … }
ErrorOr<SampleContextFrames>
SampleProfileReaderBinary::readContextFromTable(size_t *RetIdx) { … }
ErrorOr<std::pair<SampleContext, uint64_t>>
SampleProfileReaderBinary::readSampleContextFromTable() { … }
std::error_code
SampleProfileReaderBinary::readProfile(FunctionSamples &FProfile) { … }
std::error_code
SampleProfileReaderBinary::readFuncProfile(const uint8_t *Start,
SampleProfileMap &Profiles) { … }
std::error_code
SampleProfileReaderBinary::readFuncProfile(const uint8_t *Start) { … }
std::error_code SampleProfileReaderBinary::readImpl() { … }
std::error_code SampleProfileReaderExtBinaryBase::readOneSection(
const uint8_t *Start, uint64_t Size, const SecHdrTableEntry &Entry) { … }
bool SampleProfileReaderExtBinaryBase::useFuncOffsetList() const { … }
std::error_code
SampleProfileReaderExtBinaryBase::read(const DenseSet<StringRef> &FuncsToUse,
SampleProfileMap &Profiles) { … }
bool SampleProfileReaderExtBinaryBase::collectFuncsFromModule() { … }
std::error_code SampleProfileReaderExtBinaryBase::readFuncOffsetTable() { … }
std::error_code SampleProfileReaderExtBinaryBase::readFuncProfiles(
const DenseSet<StringRef> &FuncsToUse, SampleProfileMap &Profiles) { … }
std::error_code SampleProfileReaderExtBinaryBase::readFuncProfiles() { … }
std::error_code SampleProfileReaderExtBinaryBase::readProfileSymbolList() { … }
std::error_code SampleProfileReaderExtBinaryBase::decompressSection(
const uint8_t *SecStart, const uint64_t SecSize,
const uint8_t *&DecompressBuf, uint64_t &DecompressBufSize) { … }
std::error_code SampleProfileReaderExtBinaryBase::readImpl() { … }
std::error_code SampleProfileReaderRawBinary::verifySPMagic(uint64_t Magic) { … }
std::error_code SampleProfileReaderExtBinary::verifySPMagic(uint64_t Magic) { … }
std::error_code SampleProfileReaderBinary::readNameTable() { … }
std::error_code
SampleProfileReaderExtBinaryBase::readNameTableSec(bool IsMD5,
bool FixedLengthMD5) { … }
std::error_code SampleProfileReaderExtBinaryBase::readCSNameTableSec() { … }
std::error_code
SampleProfileReaderExtBinaryBase::readFuncMetadata(bool ProfileHasAttribute,
FunctionSamples *FProfile) { … }
std::error_code
SampleProfileReaderExtBinaryBase::readFuncMetadata(bool ProfileHasAttribute,
SampleProfileMap &Profiles) { … }
std::error_code
SampleProfileReaderExtBinaryBase::readFuncMetadata(bool ProfileHasAttribute) { … }
std::error_code
SampleProfileReaderExtBinaryBase::readSecHdrTableEntry(uint64_t Idx) { … }
std::error_code SampleProfileReaderExtBinaryBase::readSecHdrTable() { … }
std::error_code SampleProfileReaderExtBinaryBase::readHeader() { … }
uint64_t SampleProfileReaderExtBinaryBase::getSectionSize(SecType Type) { … }
uint64_t SampleProfileReaderExtBinaryBase::getFileSize() { … }
static std::string getSecFlagsStr(const SecHdrTableEntry &Entry) { … }
bool SampleProfileReaderExtBinaryBase::dumpSectionInfo(raw_ostream &OS) { … }
std::error_code SampleProfileReaderBinary::readMagicIdent() { … }
std::error_code SampleProfileReaderBinary::readHeader() { … }
std::error_code SampleProfileReaderBinary::readSummaryEntry(
std::vector<ProfileSummaryEntry> &Entries) { … }
std::error_code SampleProfileReaderBinary::readSummary() { … }
bool SampleProfileReaderRawBinary::hasFormat(const MemoryBuffer &Buffer) { … }
bool SampleProfileReaderExtBinary::hasFormat(const MemoryBuffer &Buffer) { … }
std::error_code SampleProfileReaderGCC::skipNextWord() { … }
template <typename T> ErrorOr<T> SampleProfileReaderGCC::readNumber() { … }
ErrorOr<StringRef> SampleProfileReaderGCC::readString() { … }
std::error_code SampleProfileReaderGCC::readHeader() { … }
std::error_code SampleProfileReaderGCC::readSectionTag(uint32_t Expected) { … }
std::error_code SampleProfileReaderGCC::readNameTable() { … }
std::error_code SampleProfileReaderGCC::readFunctionProfiles() { … }
std::error_code SampleProfileReaderGCC::readOneFunctionProfile(
const InlineCallStack &InlineStack, bool Update, uint32_t Offset) { … }
std::error_code SampleProfileReaderGCC::readImpl() { … }
bool SampleProfileReaderGCC::hasFormat(const MemoryBuffer &Buffer) { … }
void SampleProfileReaderItaniumRemapper::applyRemapping(LLVMContext &Ctx) { … }
std::optional<StringRef>
SampleProfileReaderItaniumRemapper::lookUpNameInProfile(StringRef Fname) { … }
static ErrorOr<std::unique_ptr<MemoryBuffer>>
setupMemoryBuffer(const Twine &Filename, vfs::FileSystem &FS) { … }
ErrorOr<std::unique_ptr<SampleProfileReader>>
SampleProfileReader::create(StringRef Filename, LLVMContext &C,
vfs::FileSystem &FS, FSDiscriminatorPass P,
StringRef RemapFilename) { … }
ErrorOr<std::unique_ptr<SampleProfileReaderItaniumRemapper>>
SampleProfileReaderItaniumRemapper::create(StringRef Filename,
vfs::FileSystem &FS,
SampleProfileReader &Reader,
LLVMContext &C) { … }
ErrorOr<std::unique_ptr<SampleProfileReaderItaniumRemapper>>
SampleProfileReaderItaniumRemapper::create(std::unique_ptr<MemoryBuffer> &B,
SampleProfileReader &Reader,
LLVMContext &C) { … }
ErrorOr<std::unique_ptr<SampleProfileReader>>
SampleProfileReader::create(std::unique_ptr<MemoryBuffer> &B, LLVMContext &C,
vfs::FileSystem &FS, FSDiscriminatorPass P,
StringRef RemapFilename) { … }
void SampleProfileReader::computeSummary() { … }