LLVM  14.0.0git
Macros | Enumerations | Functions | Variables
SampleProfReader.cpp File Reference
#include "llvm/ProfileData/SampleProfReader.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringRef.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/LEB128.h"
#include "llvm/Support/LineIterator.h"
#include "llvm/Support/MD5.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <limits>
#include <memory>
#include <set>
#include <system_error>
#include <vector>
Include dependency graph for SampleProfReader.cpp:

Go to the source code of this file.


#define DEBUG_TYPE   "samplepgo-reader"


enum  LineType { LineType::CallSiteProfile, LineType::BodyProfile, LineType::Metadata }


static bool ParseHead (const StringRef &Input, StringRef &FName, uint64_t &NumSamples, uint64_t &NumHeadSamples)
 Parse Input as function head. More...
static bool isOffsetLegal (unsigned L)
 Returns true if line offset L is legal (only has 16 bits). More...
static bool parseMetadata (const StringRef &Input, uint64_t &FunctionHash, uint32_t &Attributes)
 Parse Input that contains metadata. More...
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. More...
static std::string getSecFlagsStr (const SecHdrTableEntry &Entry)
static ErrorOr< std::unique_ptr< MemoryBuffer > > setupMemoryBuffer (const Twine &Filename)
 Prepare a memory buffer for the contents of Filename. More...


static cl::opt< bool > ProfileIsFSDisciminator ("profile-isfs", cl::Hidden, cl::init(false), cl::desc("Profile uses flow sensitive discriminators"))

Macro Definition Documentation


#define DEBUG_TYPE   "samplepgo-reader"

Definition at line 49 of file SampleProfReader.cpp.

Enumeration Type Documentation

◆ LineType

enum LineType

Definition at line 121 of file SampleProfReader.cpp.

Function Documentation

◆ getSecFlagsStr()

static std::string getSecFlagsStr ( const SecHdrTableEntry Entry)

Definition at line 1200 of file SampleProfReader.cpp.

◆ isOffsetLegal()

static bool isOffsetLegal ( unsigned  L)

Returns true if line offset L is legal (only has 16 bits).

Definition at line 97 of file SampleProfReader.cpp.

Referenced by ParseLine(), llvm::sampleprof::SampleProfileReaderExtBinaryBase::readCSNameTableSec(), and llvm::sampleprof::SampleProfileReaderBinary::readProfile().

◆ ParseHead()

static bool ParseHead ( const StringRef Input,
StringRef FName,
uint64_t NumSamples,
uint64_t NumHeadSamples 

Parse Input as function head.

Parse one line of Input, and update function name in FName, function's total sample count in NumSamples, function's entry count in NumHeadSamples.

true if parsing is successful.

Definition at line 82 of file SampleProfReader.cpp.

References llvm::StringRef::getAsInteger(), llvm::StringRef::rfind(), and llvm::StringRef::substr().

Referenced by llvm::sampleprof::SampleProfileReaderText::hasFormat(), and llvm::sampleprof::SampleProfileReaderText::readImpl().

◆ ParseLine()

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.

Inputinput line.
LineTyType of this line.
Depththe depth of the inline stack.
NumSamplestotal samples of the line/inlined callsite.
LineOffsetline offset to the start of the function.
Discriminatordiscriminator of the line.
TargetCountMapmap from indirect call target to count.
FunctionHashthe function's CFG hash, used by pseudo probe.

returns true if parsing is successful.

Definition at line 139 of file SampleProfReader.cpp.

References Attributes, BodyProfile, CallSiteProfile, llvm::count(), llvm::Depth, llvm::StringRef::find(), llvm::StringRef::find_first_not_of(), llvm::StringRef::find_first_of(), llvm::StringRef::find_last_of(), llvm::StringRef::getAsInteger(), isDigit(), isOffsetLegal(), Metadata, llvm::StringRef::npos, parseMetadata(), llvm::StringRef::size(), and llvm::StringRef::substr().

Referenced by llvm::sampleprof::SampleProfileReaderText::readImpl().

◆ parseMetadata()

static bool parseMetadata ( const StringRef Input,
uint64_t FunctionHash,
uint32_t Attributes 

Parse Input that contains metadata.

Possible metadata:

  • CFG Checksum information: !CFGChecksum: 12345
  • CFG Checksum information: !Attributes: 1 Stores the FunctionHash (a.k.a. CFG Checksum) into FunctionHash.

Definition at line 106 of file SampleProfReader.cpp.

References Attributes, llvm::StringRef::getAsInteger(), llvm::StringRef::startswith(), llvm::StringRef::substr(), and llvm::StringRef::trim().

Referenced by llvm::MetadataLoader::parseFunctionMetadata(), ParseLine(), and llvm::MetadataLoader::parseModuleMetadata().

◆ setupMemoryBuffer()

static ErrorOr<std::unique_ptr<MemoryBuffer> > setupMemoryBuffer ( const Twine Filename)

Prepare a memory buffer for the contents of Filename.

an error code indicating the status of the buffer.

Definition at line 1706 of file SampleProfReader.cpp.

References llvm::sampleprof::SampleProfileReader::Buffer, llvm::MemoryBuffer::getFileOrSTDIN(), llvm::max(), move, and llvm::too_large.

Referenced by llvm::sampleprof::SampleProfileReaderItaniumRemapper::create(), and llvm::sampleprof::SampleProfileReader::create().

Variable Documentation

◆ ProfileIsFSDisciminator

cl::opt<bool> ProfileIsFSDisciminator("profile-isfs", cl::Hidden, cl::init(false), cl::desc("Profile uses flow sensitive discriminators"))