LLVM 20.0.0git
Classes | Public Member Functions | List of all members
llvm::BitstreamWriter Class Reference

#include "llvm/Bitstream/BitstreamWriter.h"

Public Member Functions

 BitstreamWriter (raw_ostream &OutStream, uint32_t FlushThreshold=512)
 Create a BitstreamWriter over a raw_ostream OutStream.
 
 BitstreamWriter (SmallVectorImpl< char > &Buff)
 Convenience constructor for users that start with a vector - avoids needing to wrap it in a raw_svector_ostream.
 
 ~BitstreamWriter ()
 
void markAndBlockFlushing ()
 For scenarios where the user wants to access a section of the stream to (for example) compute some checksum, disable flushing and remember the position in the internal buffer where that happened.
 
StringRef getMarkedBufferAndResumeFlushing ()
 resumes flushing, but does not flush, and returns the section in the internal buffer starting from the position marked with markAndBlockFlushing.
 
uint64_t GetCurrentBitNo () const
 Retrieve the current position in the stream, in bits.
 
unsigned GetAbbrevIDWidth () const
 Retrieve the number of bits currently used to encode an abbrev ID.
 
void BackpatchByte (uint64_t BitNo, uint8_t NewByte)
 Backpatch a byte in the output at the given bit offset with the specified value.
 
void BackpatchHalfWord (uint64_t BitNo, uint16_t Val)
 
void BackpatchWord (uint64_t BitNo, unsigned Val)
 
void BackpatchWord64 (uint64_t BitNo, uint64_t Val)
 
void Emit (uint32_t Val, unsigned NumBits)
 
void FlushToWord ()
 
void EmitVBR (uint32_t Val, unsigned NumBits)
 
void EmitVBR64 (uint64_t Val, unsigned NumBits)
 
void EmitCode (unsigned Val)
 EmitCode - Emit the specified code.
 
BlockInfo * getBlockInfo (unsigned BlockID)
 getBlockInfo - If there is block info for the specified ID, return it, otherwise return null.
 
void EnterSubblock (unsigned BlockID, unsigned CodeLen)
 
void ExitBlock ()
 
template<class UIntTy >
void emitBlob (ArrayRef< UIntTy > Bytes, bool ShouldEmitSize=true)
 Emit a blob, including flushing before and tail-padding.
 
void emitBlob (StringRef Bytes, bool ShouldEmitSize=true)
 
template<typename Container >
void EmitRecord (unsigned Code, const Container &Vals, unsigned Abbrev=0)
 EmitRecord - Emit the specified record to the stream, using an abbrev if we have one to compress the output.
 
template<typename Container >
void EmitRecordWithAbbrev (unsigned Abbrev, const Container &Vals)
 EmitRecordWithAbbrev - Emit a record with the specified abbreviation.
 
template<typename Container >
void EmitRecordWithBlob (unsigned Abbrev, const Container &Vals, StringRef Blob)
 EmitRecordWithBlob - Emit the specified record to the stream, using an abbrev that includes a blob at the end.
 
template<typename Container >
void EmitRecordWithBlob (unsigned Abbrev, const Container &Vals, const char *BlobData, unsigned BlobLen)
 
template<typename Container >
void EmitRecordWithArray (unsigned Abbrev, const Container &Vals, StringRef Array)
 EmitRecordWithArray - Just like EmitRecordWithBlob, works with records that end with an array.
 
template<typename Container >
void EmitRecordWithArray (unsigned Abbrev, const Container &Vals, const char *ArrayData, unsigned ArrayLen)
 
unsigned EmitAbbrev (std::shared_ptr< BitCodeAbbrev > Abbv)
 Emits the abbreviation Abbv to the stream.
 
void EnterBlockInfoBlock ()
 EnterBlockInfoBlock - Start emitting the BLOCKINFO_BLOCK.
 
unsigned EmitBlockInfoAbbrev (unsigned BlockID, std::shared_ptr< BitCodeAbbrev > Abbv)
 EmitBlockInfoAbbrev - Emit a DEFINE_ABBREV record for the specified BlockID.
 

Detailed Description

Definition at line 31 of file BitstreamWriter.h.

Constructor & Destructor Documentation

◆ BitstreamWriter() [1/2]

llvm::BitstreamWriter::BitstreamWriter ( raw_ostream OutStream,
uint32_t  FlushThreshold = 512 
)
inline

Create a BitstreamWriter over a raw_ostream OutStream.

If OutStream is a raw_svector_ostream, the BitstreamWriter will write directly to the latter's buffer. In all other cases, the BitstreamWriter will use an internal buffer and flush at the end of its lifetime.

In addition, if is a raw_fd_stream supporting seek, tell, and read (besides write), the BitstreamWriter will also flush incrementally, when a subblock is finished, and if the FlushThreshold is passed.

NOTE: FlushThreshold's unit is MB.

Definition at line 156 of file BitstreamWriter.h.

◆ BitstreamWriter() [2/2]

llvm::BitstreamWriter::BitstreamWriter ( SmallVectorImpl< char > &  Buff)
inline

Convenience constructor for users that start with a vector - avoids needing to wrap it in a raw_svector_ostream.

Definition at line 163 of file BitstreamWriter.h.

◆ ~BitstreamWriter()

llvm::BitstreamWriter::~BitstreamWriter ( )
inline

Definition at line 166 of file BitstreamWriter.h.

References assert(), and FlushToWord().

Member Function Documentation

◆ BackpatchByte()

void llvm::BitstreamWriter::BackpatchByte ( uint64_t  BitNo,
uint8_t  NewByte 
)
inline

Backpatch a byte in the output at the given bit offset with the specified value.

Definition at line 205 of file BitstreamWriter.h.

References assert(), llvm::little, llvm::raw_fd_stream::read(), llvm::support::endian::readAtBitAlignment(), llvm::raw_fd_ostream::seek(), llvm::raw_ostream::tell(), and llvm::raw_ostream::write().

Referenced by BackpatchHalfWord().

◆ BackpatchHalfWord()

void llvm::BitstreamWriter::BackpatchHalfWord ( uint64_t  BitNo,
uint16_t  Val 
)
inline

Definition at line 267 of file BitstreamWriter.h.

References BackpatchByte().

Referenced by BackpatchWord().

◆ BackpatchWord()

void llvm::BitstreamWriter::BackpatchWord ( uint64_t  BitNo,
unsigned  Val 
)
inline

Definition at line 272 of file BitstreamWriter.h.

References BackpatchHalfWord().

Referenced by BackpatchWord64(), and ExitBlock().

◆ BackpatchWord64()

void llvm::BitstreamWriter::BackpatchWord64 ( uint64_t  BitNo,
uint64_t  Val 
)
inline

Definition at line 277 of file BitstreamWriter.h.

References BackpatchWord().

◆ Emit()

void llvm::BitstreamWriter::Emit ( uint32_t  Val,
unsigned  NumBits 
)
inline

◆ EmitAbbrev()

unsigned llvm::BitstreamWriter::EmitAbbrev ( std::shared_ptr< BitCodeAbbrev Abbv)
inline

Emits the abbreviation Abbv to the stream.

Definition at line 651 of file BitstreamWriter.h.

References llvm::bitc::FIRST_APPLICATION_ABBREV.

Referenced by llvm::BCGenericRecordLayout< IDField, Fields >::emitAbbrev(), and writeIdentificationBlock().

◆ emitBlob() [1/2]

template<class UIntTy >
void llvm::BitstreamWriter::emitBlob ( ArrayRef< UIntTy >  Bytes,
bool  ShouldEmitSize = true 
)
inline

◆ emitBlob() [2/2]

void llvm::BitstreamWriter::emitBlob ( StringRef  Bytes,
bool  ShouldEmitSize = true 
)
inline

Definition at line 563 of file BitstreamWriter.h.

References llvm::StringRef::data(), emitBlob(), and llvm::StringRef::size().

◆ EmitBlockInfoAbbrev()

unsigned llvm::BitstreamWriter::EmitBlockInfoAbbrev ( unsigned  BlockID,
std::shared_ptr< BitCodeAbbrev Abbv 
)
inline

◆ EmitCode()

void llvm::BitstreamWriter::EmitCode ( unsigned  Val)
inline

EmitCode - Emit the specified code.

Definition at line 342 of file BitstreamWriter.h.

References Emit().

Referenced by EmitRecord(), EnterSubblock(), and ExitBlock().

◆ EmitRecord()

template<typename Container >
void llvm::BitstreamWriter::EmitRecord ( unsigned  Code,
const Container &  Vals,
unsigned  Abbrev = 0 
)
inline

EmitRecord - Emit the specified record to the stream, using an abbrev if we have one to compress the output.

Definition at line 571 of file BitstreamWriter.h.

References EmitCode(), EmitVBR(), EmitVBR64(), and llvm::bitc::UNABBREV_RECORD.

Referenced by llvm::PGOCtxProfileWriter::PGOCtxProfileWriter(), writeFunctionHeapProfileRecords(), writeFunctionTypeMetadataRecords(), writeIdentificationBlock(), writeStringRecord(), and llvm::dxil::DXILBitcodeWriter::writeStringRecord().

◆ EmitRecordWithAbbrev()

template<typename Container >
void llvm::BitstreamWriter::EmitRecordWithAbbrev ( unsigned  Abbrev,
const Container &  Vals 
)
inline

EmitRecordWithAbbrev - Emit a record with the specified abbreviation.

Unlike EmitRecord, the code for the record should be included in Vals as the first entry.

Definition at line 591 of file BitstreamWriter.h.

Referenced by llvm::detail::BCRecordCoding< BCArray< ElementTy > >::emit(), llvm::detail::BCRecordCoding< ElementTy >::emit(), llvm::remarks::BitstreamRemarkSerializerHelper::emitMetaBlock(), llvm::remarks::BitstreamRemarkSerializerHelper::emitMetaRemarkVersion(), and llvm::remarks::BitstreamRemarkSerializerHelper::emitRemarkBlock().

◆ EmitRecordWithArray() [1/2]

template<typename Container >
void llvm::BitstreamWriter::EmitRecordWithArray ( unsigned  Abbrev,
const Container &  Vals,
const char ArrayData,
unsigned  ArrayLen 
)
inline

Definition at line 620 of file BitstreamWriter.h.

◆ EmitRecordWithArray() [2/2]

template<typename Container >
void llvm::BitstreamWriter::EmitRecordWithArray ( unsigned  Abbrev,
const Container &  Vals,
StringRef  Array 
)
inline

EmitRecordWithArray - Just like EmitRecordWithBlob, works with records that end with an array.

Definition at line 615 of file BitstreamWriter.h.

Referenced by llvm::detail::BCRecordCoding< BCArray< ElementTy > >::emit().

◆ EmitRecordWithBlob() [1/2]

template<typename Container >
void llvm::BitstreamWriter::EmitRecordWithBlob ( unsigned  Abbrev,
const Container &  Vals,
const char BlobData,
unsigned  BlobLen 
)
inline

Definition at line 606 of file BitstreamWriter.h.

◆ EmitRecordWithBlob() [2/2]

template<typename Container >
void llvm::BitstreamWriter::EmitRecordWithBlob ( unsigned  Abbrev,
const Container &  Vals,
StringRef  Blob 
)
inline

EmitRecordWithBlob - Emit the specified record to the stream, using an abbrev that includes a blob at the end.

The blob data to emit is specified by the pointer and length specified at the end. In contrast to EmitRecord, this routine expects that the first entry in Vals is the code of the record.

Definition at line 601 of file BitstreamWriter.h.

Referenced by llvm::detail::BCRecordCoding< BCBlob >::emit(), llvm::remarks::BitstreamRemarkSerializerHelper::emitMetaExternalFile(), and llvm::remarks::BitstreamRemarkSerializerHelper::emitMetaStrTab().

◆ EmitVBR()

void llvm::BitstreamWriter::EmitVBR ( uint32_t  Val,
unsigned  NumBits 
)
inline

Definition at line 309 of file BitstreamWriter.h.

References assert(), and Emit().

Referenced by emitBlob(), EmitRecord(), EmitVBR64(), and EnterSubblock().

◆ EmitVBR64()

void llvm::BitstreamWriter::EmitVBR64 ( uint64_t  Val,
unsigned  NumBits 
)
inline

Definition at line 323 of file BitstreamWriter.h.

References assert(), Emit(), and EmitVBR().

Referenced by EmitRecord().

◆ EnterBlockInfoBlock()

void llvm::BitstreamWriter::EnterBlockInfoBlock ( )
inline

EnterBlockInfoBlock - Start emitting the BLOCKINFO_BLOCK.

Definition at line 663 of file BitstreamWriter.h.

References llvm::bitc::BLOCKINFO_BLOCK_ID, and EnterSubblock().

Referenced by llvm::PGOCtxProfileWriter::PGOCtxProfileWriter(), and llvm::remarks::BitstreamRemarkSerializerHelper::setupBlockInfo().

◆ EnterSubblock()

void llvm::BitstreamWriter::EnterSubblock ( unsigned  BlockID,
unsigned  CodeLen 
)
inline

◆ ExitBlock()

void llvm::BitstreamWriter::ExitBlock ( )
inline

◆ FlushToWord()

void llvm::BitstreamWriter::FlushToWord ( )
inline

Definition at line 301 of file BitstreamWriter.h.

Referenced by emitBlob(), EnterSubblock(), ExitBlock(), and ~BitstreamWriter().

◆ GetAbbrevIDWidth()

unsigned llvm::BitstreamWriter::GetAbbrevIDWidth ( ) const
inline

Retrieve the number of bits currently used to encode an abbrev ID.

Definition at line 197 of file BitstreamWriter.h.

◆ getBlockInfo()

BlockInfo * llvm::BitstreamWriter::getBlockInfo ( unsigned  BlockID)
inline

getBlockInfo - If there is block info for the specified ID, return it, otherwise return null.

Definition at line 352 of file BitstreamWriter.h.

Referenced by EnterSubblock().

◆ GetCurrentBitNo()

uint64_t llvm::BitstreamWriter::GetCurrentBitNo ( ) const
inline

Retrieve the current position in the stream, in bits.

Definition at line 194 of file BitstreamWriter.h.

◆ getMarkedBufferAndResumeFlushing()

StringRef llvm::BitstreamWriter::getMarkedBufferAndResumeFlushing ( )
inline

resumes flushing, but does not flush, and returns the section in the internal buffer starting from the position marked with markAndBlockFlushing.

The return should be processed before any additional calls to this object, because those may cause a flush and invalidate the return.

Definition at line 186 of file BitstreamWriter.h.

References assert(), and llvm::SmallVectorBase< Size_T >::size().

◆ markAndBlockFlushing()

void llvm::BitstreamWriter::markAndBlockFlushing ( )
inline

For scenarios where the user wants to access a section of the stream to (for example) compute some checksum, disable flushing and remember the position in the internal buffer where that happened.

Must be paired with a call to getMarkedBufferAndResumeFlushing.

Definition at line 176 of file BitstreamWriter.h.

References assert(), and llvm::SmallVectorBase< Size_T >::size().


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