MLIR 22.0.0git
BytecodeReader.cpp File Reference
#include "mlir/Bytecode/BytecodeReader.h"
#include "mlir/AsmParser/AsmParser.h"
#include "mlir/Bytecode/BytecodeImplementation.h"
#include "mlir/Bytecode/BytecodeOpInterface.h"
#include "mlir/Bytecode/Encoding.h"
#include "mlir/IR/BuiltinOps.h"
#include "mlir/IR/Diagnostics.h"
#include "mlir/IR/OpImplementation.h"
#include "mlir/IR/Verifier.h"
#include "mlir/IR/Visitors.h"
#include "mlir/Support/LLVM.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/ScopeExit.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/MemoryBufferRef.h"
#include "llvm/Support/SourceMgr.h"
#include <cstddef>
#include <cstdint>
#include <list>
#include <memory>
#include <numeric>
#include <optional>

Go to the source code of this file.

Classes

class  mlir::BytecodeReader::Impl
 This class is used to read a bytecode buffer and translate it into MLIR. More...

Macros

#define DEBUG_TYPE   "mlir-bytecode-reader"

Functions

static std::string toString (bytecode::Section::ID sectionID)
 Stringify the given section ID.
static bool isSectionOptional (bytecode::Section::ID sectionID, int version)
 Returns true if the given top-level section ID is optional.
template<typename RangeT, typename T>
static LogicalResult resolveEntry (EncodingReader &reader, RangeT &entries, uint64_t index, T &entry, StringRef entryStr)
 Resolve an index into the given entry list.
template<typename RangeT, typename T>
static LogicalResult parseEntry (EncodingReader &reader, RangeT &entries, T &entry, StringRef entryStr)
 Parse and resolve an index into the given entry list.
static LogicalResult parseDialectGrouping (EncodingReader &reader, MutableArrayRef< std::unique_ptr< BytecodeDialect > > dialects, function_ref< LogicalResult(BytecodeDialect *)> entryCallback)
 Parse a single dialect group encoded in the byte stream.
template<typename T>
static LogicalResult parseResourceGroup (Location fileLoc, bool allowEmpty, EncodingReader &offsetReader, EncodingReader &resourceReader, StringSectionReader &stringReader, T *handler, const std::shared_ptr< llvm::SourceMgr > &bufferOwnerRef, function_ref< StringRef(StringRef)> remapKey={}, function_ref< LogicalResult(StringRef)> processKeyFn={})
static LogicalResult readBytecodeFileImpl (llvm::MemoryBufferRef buffer, Block *block, const ParserConfig &config, const std::shared_ptr< llvm::SourceMgr > &bufferOwnerRef)
 Read the bytecode from the provided memory buffer reference.

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "mlir-bytecode-reader"

Definition at line 35 of file BytecodeReader.cpp.

Function Documentation

◆ isSectionOptional()

◆ parseDialectGrouping()

LogicalResult parseDialectGrouping ( EncodingReader & reader,
MutableArrayRef< std::unique_ptr< BytecodeDialect > > dialects,
function_ref< LogicalResult(BytecodeDialect *)> entryCallback )
static

Parse a single dialect group encoded in the byte stream.

Definition at line 559 of file BytecodeReader.cpp.

References parseEntry(), and success().

◆ parseEntry()

template<typename RangeT, typename T>
LogicalResult parseEntry ( EncodingReader & reader,
RangeT & entries,
T & entry,
StringRef entryStr )
static

Parse and resolve an index into the given entry list.

Definition at line 404 of file BytecodeReader.cpp.

References resolveEntry().

Referenced by parseDialectGrouping().

◆ parseResourceGroup()

template<typename T>
LogicalResult parseResourceGroup ( Location fileLoc,
bool allowEmpty,
EncodingReader & offsetReader,
EncodingReader & resourceReader,
StringSectionReader & stringReader,
T * handler,
const std::shared_ptr< llvm::SourceMgr > & bufferOwnerRef,
function_ref< StringRef(StringRef)> remapKey = {},
function_ref< LogicalResult(StringRef)> processKeyFn = {} )
static

Definition at line 687 of file BytecodeReader.cpp.

◆ readBytecodeFileImpl()

LogicalResult readBytecodeFileImpl ( llvm::MemoryBufferRef buffer,
Block * block,
const ParserConfig & config,
const std::shared_ptr< llvm::SourceMgr > & bufferOwnerRef )
static

Read the bytecode from the provided memory buffer reference.

bufferOwnerRef if provided is the owning source manager for the buffer, and may be used to extend the lifetime of the buffer.

Definition at line 2663 of file BytecodeReader.cpp.

References mlir::config, mlir::emitError(), mlir::FileLineColLoc::get(), mlir::isBytecode(), and mlir::BytecodeReader::Impl::read().

Referenced by mlir::readBytecodeFile(), and mlir::readBytecodeFile().

◆ resolveEntry()

template<typename RangeT, typename T>
LogicalResult resolveEntry ( EncodingReader & reader,
RangeT & entries,
uint64_t index,
T & entry,
StringRef entryStr )
static

Resolve an index into the given entry list.

entry may either be a reference, in which case it is assigned to the corresponding value in entries, or a pointer, in which case it is assigned to the address of the element in entries.

Definition at line 388 of file BytecodeReader.cpp.

References success().

Referenced by parseEntry().

◆ toString()