LLVM 20.0.0git
Public Member Functions | Static Public Attributes | List of all members
llvm::PGOCtxProfileWriter Class Referencefinal

Write one or more ContextNodes to the provided raw_fd_stream. More...

#include "llvm/ProfileData/PGOCtxProfWriter.h"

Public Member Functions

 PGOCtxProfileWriter (raw_ostream &Out, std::optional< unsigned > VersionOverride=std::nullopt)
 
 ~PGOCtxProfileWriter ()
 
void write (const ctx_profile::ContextNode &)
 

Static Public Attributes

static constexpr unsigned CodeLen = 2
 
static constexpr uint32_t CurrentVersion = 1
 
static constexpr unsigned VBREncodingBits = 6
 
static constexpr StringRef ContainerMagic = "CTXP"
 

Detailed Description

Write one or more ContextNodes to the provided raw_fd_stream.

The caller must destroy the PGOCtxProfileWriter object before closing the stream. The design allows serializing a bunch of contexts embedded in some other file. The overall format is:

[... other data written to the stream...] SubBlock(ProfileMetadataBlockID) Version SubBlock(ContextNodeBlockID) [RECORDS] SubBlock(ContextNodeBlockID) [RECORDS] [... more SubBlocks] EndBlock EndBlock

The "RECORDS" are bitsream records. The IDs are in CtxProfileCodes (except) for Version, which is just for metadata). All contexts will have Guid and Counters, and all but the roots have CalleeIndex. The order in which the records appear does not matter, but they must precede any subcontexts, because that helps keep the reader code simpler.

Subblock containment captures the context->subcontext relationship. The "next()" relationship in the raw profile, between call targets of indirect calls, are just modeled as peer subblocks where the callee index is the same.

Versioning: the writer may produce additional records not known by the reader. The version number indicates a more structural change. The current version, in particular, is set up to expect optional extensions like value profiling - which would appear as additional records. For example, value profiling would produce a new record with a new record ID, containing the profiled values (much like the counters)

Definition at line 63 of file PGOCtxProfWriter.h.

Constructor & Destructor Documentation

◆ PGOCtxProfileWriter()

PGOCtxProfileWriter::PGOCtxProfileWriter ( raw_ostream Out,
std::optional< unsigned VersionOverride = std::nullopt 
)

◆ ~PGOCtxProfileWriter()

llvm::PGOCtxProfileWriter::~PGOCtxProfileWriter ( )
inline

Definition at line 73 of file PGOCtxProfWriter.h.

Member Function Documentation

◆ write()

void PGOCtxProfileWriter::write ( const ctx_profile::ContextNode RootNode)

Definition at line 83 of file PGOCtxProfWriter.cpp.

Referenced by llvm::createCtxProfFromJSON().

Member Data Documentation

◆ CodeLen

constexpr unsigned llvm::PGOCtxProfileWriter::CodeLen = 2
staticconstexpr

Definition at line 78 of file PGOCtxProfWriter.h.

Referenced by PGOCtxProfileWriter().

◆ ContainerMagic

constexpr StringRef llvm::PGOCtxProfileWriter::ContainerMagic = "CTXP"
staticconstexpr

Definition at line 81 of file PGOCtxProfWriter.h.

Referenced by PGOCtxProfileWriter().

◆ CurrentVersion

constexpr uint32_t llvm::PGOCtxProfileWriter::CurrentVersion = 1
staticconstexpr

Definition at line 79 of file PGOCtxProfWriter.h.

Referenced by PGOCtxProfileWriter().

◆ VBREncodingBits

constexpr unsigned llvm::PGOCtxProfileWriter::VBREncodingBits = 6
staticconstexpr

Definition at line 80 of file PGOCtxProfWriter.h.


The documentation for this class was generated from the following files: