MLIR  20.0.0git
Public Member Functions | List of all members
mlir::DialectBytecodeWriter Class Referenceabstract

This class defines a virtual interface for writing to a bytecode stream, providing hooks into the bytecode writer. More...

#include "mlir/Bytecode/BytecodeImplementation.h"

+ Inheritance diagram for mlir::DialectBytecodeWriter:

Public Member Functions

virtual ~DialectBytecodeWriter ()=default
 
template<typename RangeT , typename CallbackFn >
void writeList (RangeT &&range, CallbackFn &&callback)
 Write out a list of elements, invoking the provided callback for each element. More...
 
virtual void writeAttribute (Attribute attr)=0
 Write a reference to the given attribute. More...
 
virtual void writeOptionalAttribute (Attribute attr)=0
 
template<typename T >
void writeAttributes (ArrayRef< T > attrs)
 
virtual void writeType (Type type)=0
 Write a reference to the given type. More...
 
template<typename T >
void writeTypes (ArrayRef< T > types)
 
virtual void writeResourceHandle (const AsmDialectResourceHandle &resource)=0
 Write the given handle to a dialect resource. More...
 
virtual void writeVarInt (uint64_t value)=0
 Write a variable width integer to the output stream. More...
 
virtual void writeSignedVarInt (int64_t value)=0
 Write a signed variable width integer to the output stream. More...
 
void writeSignedVarInts (ArrayRef< int64_t > value)
 
void writeVarIntWithFlag (uint64_t value, bool flag)
 Write a VarInt and a flag packed together. More...
 
template<typename T >
void writeSparseArray (ArrayRef< T > array)
 Write out a "small" sparse array of integer <= 32 bits elements, where index/value pairs can be compressed when the array is small. More...
 
virtual void writeAPIntWithKnownWidth (const APInt &value)=0
 Write an APInt to the bytecode stream whose bitwidth will be known externally at read time. More...
 
virtual void writeAPFloatWithKnownSemantics (const APFloat &value)=0
 Write an APFloat to the bytecode stream whose semantics will be known externally at read time. More...
 
virtual void writeOwnedString (StringRef str)=0
 Write a string to the bytecode, which is owned by the caller and is guaranteed to not die before the end of the bytecode process. More...
 
virtual void writeOwnedBlob (ArrayRef< char > blob)=0
 Write a blob to the bytecode, which is owned by the caller and is guaranteed to not die before the end of the bytecode process. More...
 
virtual void writeOwnedBool (bool value)=0
 Write a bool to the output stream. More...
 
virtual int64_t getBytecodeVersion () const =0
 Return the bytecode version being emitted for. More...
 
virtual FailureOr< const DialectVersion * > getDialectVersion (StringRef dialectName) const =0
 Retrieve the dialect version by name if available. More...
 
template<class T >
FailureOr< const DialectVersion * > getDialectVersion () const
 

Detailed Description

This class defines a virtual interface for writing to a bytecode stream, providing hooks into the bytecode writer.

As such, this class should only be derived and defined by the main bytecode writer, users (i.e. dialects) should generally only interact with this class via the BytecodeDialectInterface below.

Definition at line 277 of file BytecodeImplementation.h.

Constructor & Destructor Documentation

◆ ~DialectBytecodeWriter()

virtual mlir::DialectBytecodeWriter::~DialectBytecodeWriter ( )
virtualdefault

Member Function Documentation

◆ getBytecodeVersion()

virtual int64_t mlir::DialectBytecodeWriter::getBytecodeVersion ( ) const
pure virtual

Return the bytecode version being emitted for.

Implemented in mlir::bytecode::detail::IRNumberingState::NumberingDialectWriter.

◆ getDialectVersion() [1/2]

template<class T >
FailureOr<const DialectVersion *> mlir::DialectBytecodeWriter::getDialectVersion ( ) const
inline

Definition at line 412 of file BytecodeImplementation.h.

◆ getDialectVersion() [2/2]

virtual FailureOr<const DialectVersion *> mlir::DialectBytecodeWriter::getDialectVersion ( StringRef  dialectName) const
pure virtual

Retrieve the dialect version by name if available.

Implemented in mlir::bytecode::detail::IRNumberingState::NumberingDialectWriter.

◆ writeAPFloatWithKnownSemantics()

virtual void mlir::DialectBytecodeWriter::writeAPFloatWithKnownSemantics ( const APFloat &  value)
pure virtual

Write an APFloat to the bytecode stream whose semantics will be known externally at read time.

This method is useful for encoding APFloat values when the semantics are known via external means, such as via a type.

Implemented in mlir::bytecode::detail::IRNumberingState::NumberingDialectWriter.

◆ writeAPIntWithKnownWidth()

virtual void mlir::DialectBytecodeWriter::writeAPIntWithKnownWidth ( const APInt &  value)
pure virtual

Write an APInt to the bytecode stream whose bitwidth will be known externally at read time.

This method is useful for encoding APInt values when the width is known via external means, such as via a type. This method should generally only be invoked if you need an APInt, otherwise use the varint methods above. APInt values are generally encoded using zigzag encoding, to enable more efficient encodings for negative values.

Implemented in mlir::bytecode::detail::IRNumberingState::NumberingDialectWriter.

◆ writeAttribute()

virtual void mlir::DialectBytecodeWriter::writeAttribute ( Attribute  attr)
pure virtual

Write a reference to the given attribute.

Implemented in mlir::bytecode::detail::IRNumberingState::NumberingDialectWriter.

Referenced by writeAttributes().

◆ writeAttributes()

template<typename T >
void mlir::DialectBytecodeWriter::writeAttributes ( ArrayRef< T >  attrs)
inline

Definition at line 298 of file BytecodeImplementation.h.

References writeAttribute(), and writeList().

◆ writeList()

template<typename RangeT , typename CallbackFn >
void mlir::DialectBytecodeWriter::writeList ( RangeT &&  range,
CallbackFn &&  callback 
)
inline

Write out a list of elements, invoking the provided callback for each element.

Definition at line 288 of file BytecodeImplementation.h.

References writeVarInt().

Referenced by writeAttributes(), writeSignedVarInts(), and writeTypes().

◆ writeOptionalAttribute()

virtual void mlir::DialectBytecodeWriter::writeOptionalAttribute ( Attribute  attr)
pure virtual

◆ writeOwnedBlob()

virtual void mlir::DialectBytecodeWriter::writeOwnedBlob ( ArrayRef< char >  blob)
pure virtual

Write a blob to the bytecode, which is owned by the caller and is guaranteed to not die before the end of the bytecode process.

The blob is written as-is, with no additional compression or compaction.

Implemented in mlir::bytecode::detail::IRNumberingState::NumberingDialectWriter.

◆ writeOwnedBool()

virtual void mlir::DialectBytecodeWriter::writeOwnedBool ( bool  value)
pure virtual

Write a bool to the output stream.

Implemented in mlir::bytecode::detail::IRNumberingState::NumberingDialectWriter.

◆ writeOwnedString()

virtual void mlir::DialectBytecodeWriter::writeOwnedString ( StringRef  str)
pure virtual

Write a string to the bytecode, which is owned by the caller and is guaranteed to not die before the end of the bytecode process.

This should only be called if such a guarantee can be made, such as when the string is owned by an attribute or type.

Implemented in mlir::bytecode::detail::IRNumberingState::NumberingDialectWriter.

◆ writeResourceHandle()

virtual void mlir::DialectBytecodeWriter::writeResourceHandle ( const AsmDialectResourceHandle resource)
pure virtual

Write the given handle to a dialect resource.

Implemented in mlir::bytecode::detail::IRNumberingState::NumberingDialectWriter.

◆ writeSignedVarInt()

virtual void mlir::DialectBytecodeWriter::writeSignedVarInt ( int64_t  value)
pure virtual

Write a signed variable width integer to the output stream.

This should be the preferred method for emitting signed integers whenever possible.

Implemented in mlir::bytecode::detail::IRNumberingState::NumberingDialectWriter.

Referenced by writeSignedVarInts().

◆ writeSignedVarInts()

void mlir::DialectBytecodeWriter::writeSignedVarInts ( ArrayRef< int64_t >  value)
inline

Definition at line 324 of file BytecodeImplementation.h.

References writeList(), and writeSignedVarInt().

◆ writeSparseArray()

template<typename T >
void mlir::DialectBytecodeWriter::writeSparseArray ( ArrayRef< T >  array)
inline

Write out a "small" sparse array of integer <= 32 bits elements, where index/value pairs can be compressed when the array is small.

This method will scan the array multiple times and should not be used for large arrays. The optional provided "zero" can be used to adjust for the expected repeated value. We assume here that the array size fits in a 32 bits integer.

Definition at line 340 of file BytecodeImplementation.h.

References writeVarInt(), and writeVarIntWithFlag().

◆ writeType()

virtual void mlir::DialectBytecodeWriter::writeType ( Type  type)
pure virtual

Write a reference to the given type.

Implemented in mlir::bytecode::detail::IRNumberingState::NumberingDialectWriter.

Referenced by writeTypes().

◆ writeTypes()

template<typename T >
void mlir::DialectBytecodeWriter::writeTypes ( ArrayRef< T >  types)
inline

Definition at line 305 of file BytecodeImplementation.h.

References writeList(), and writeType().

◆ writeVarInt()

virtual void mlir::DialectBytecodeWriter::writeVarInt ( uint64_t  value)
pure virtual

Write a variable width integer to the output stream.

This should be the preferred method for emitting integers whenever possible.

Implemented in mlir::bytecode::detail::IRNumberingState::NumberingDialectWriter.

Referenced by writeList(), writeSparseArray(), and writeVarIntWithFlag().

◆ writeVarIntWithFlag()

void mlir::DialectBytecodeWriter::writeVarIntWithFlag ( uint64_t  value,
bool  flag 
)
inline

Write a VarInt and a flag packed together.

Definition at line 329 of file BytecodeImplementation.h.

References writeVarInt().

Referenced by writeSparseArray().


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