MLIR  20.0.0git
Classes | Macros | Functions
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 <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. More...
 
static bool isSectionOptional (bytecode::Section::ID sectionID, int version)
 Returns true if the given top-level section ID is optional. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "mlir-bytecode-reader"

Definition at line 34 of file BytecodeReader.cpp.

Function Documentation

◆ isSectionOptional()

static bool isSectionOptional ( bytecode::Section::ID  sectionID,
int  version 
)
static

◆ parseDialectGrouping()

static 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 511 of file BytecodeReader.cpp.

References parseEntry().

◆ parseEntry()

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

Parse and resolve an index into the given entry list.

Definition at line 356 of file BytecodeReader.cpp.

References resolveEntry().

Referenced by parseDialectGrouping().

◆ parseResourceGroup()

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

Definition at line 639 of file BytecodeReader.cpp.

◆ readBytecodeFileImpl()

static 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 2571 of file BytecodeReader.cpp.

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

Referenced by mlir::readBytecodeFile().

◆ resolveEntry()

template<typename RangeT , typename T >
static 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 340 of file BytecodeReader.cpp.

Referenced by parseEntry().

◆ toString()

static std::string toString ( bytecode::Section::ID  sectionID)
static