LLVM 22.0.0git
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/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>

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "samplepgo-reader"

Enumerations

enum class  LineType { CallSiteProfile , BodyProfile , Metadata , VirtualCallTypeProfile }

Functions

static void dumpFunctionProfileJson (const FunctionSamples &S, json::OStream &JOS, bool TopLevel=false)
static bool ParseHead (const StringRef &Input, StringRef &FName, uint64_t &NumSamples, uint64_t &NumHeadSamples)
 Parse Input as function head.
static bool isOffsetLegal (unsigned L)
 Returns true if line offset L is legal (only has 16 bits).
static bool parseMetadata (const StringRef &Input, uint64_t &FunctionHash, uint32_t &Attributes)
 Parse Input that contains metadata.
static bool parseTypeCountMap (StringRef Input, DenseMap< StringRef, uint64_t > &TypeCountMap)
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, DenseMap< StringRef, uint64_t > &TypeCountMap, uint64_t &FunctionHash, uint32_t &Attributes, bool &IsFlat)
 Parse Input as line sample.
static std::string getSecFlagsStr (const SecHdrTableEntry &Entry)
static ErrorOr< std::unique_ptr< MemoryBuffer > > setupMemoryBuffer (const Twine &Filename, vfs::FileSystem &FS)
 Prepare a memory buffer for the contents of Filename.

Variables

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

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "samplepgo-reader"

Definition at line 51 of file SampleProfReader.cpp.

Enumeration Type Documentation

◆ LineType

enum class LineType
strong
Enumerator
CallSiteProfile 
BodyProfile 
Metadata 
VirtualCallTypeProfile 

Definition at line 196 of file SampleProfReader.cpp.

Function Documentation

◆ dumpFunctionProfileJson()

◆ getSecFlagsStr()

◆ isOffsetLegal()

◆ ParseHead()

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

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.

Returns
true if parsing is successful.

Definition at line 157 of file SampleProfReader.cpp.

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

◆ ParseLine()

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,
DenseMap< StringRef, uint64_t > & TypeCountMap,
uint64_t & FunctionHash,
uint32_t & Attributes,
bool & IsFlat )
static

Parse Input as line sample.

Parameters
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 243 of file SampleProfReader.cpp.

References 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(), llvm::isDigit(), isOffsetLegal(), llvm::sampleprof::kVTableProfPrefix, Metadata, llvm::StringRef::npos, parseMetadata(), parseTypeCountMap(), llvm::StringRef::size(), llvm::StringRef::starts_with(), llvm::StringRef::substr(), and VirtualCallTypeProfile.

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

◆ parseMetadata()

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

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 181 of file SampleProfReader.cpp.

References llvm::StringRef::getAsInteger().

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

◆ parseTypeCountMap()

bool parseTypeCountMap ( StringRef Input,
DenseMap< StringRef, uint64_t > & TypeCountMap )
static

Definition at line 205 of file SampleProfReader.cpp.

References llvm::Count, and llvm::StringRef::npos.

Referenced by ParseLine().

◆ setupMemoryBuffer()

ErrorOr< std::unique_ptr< MemoryBuffer > > setupMemoryBuffer ( const Twine & Filename,
vfs::FileSystem & FS )
static

Prepare a memory buffer for the contents of Filename.

Returns
an error code indicating the status of the buffer.

Definition at line 2011 of file SampleProfReader.cpp.

References llvm::MemoryBuffer::getSTDIN().

Variable Documentation

◆ ProfileIsFSDisciminator

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