#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>
#define DEBUG_TYPE …
usingnamespacemlir;
static std::string toString(bytecode::Section::ID sectionID) { … }
static bool isSectionOptional(bytecode::Section::ID sectionID, int version) { … }
namespace {
class EncodingReader { … };
}
template <typename RangeT, typename T>
static LogicalResult resolveEntry(EncodingReader &reader, RangeT &entries,
uint64_t index, T &entry,
StringRef entryStr) { … }
template <typename RangeT, typename T>
static LogicalResult parseEntry(EncodingReader &reader, RangeT &entries,
T &entry, StringRef entryStr) { … }
namespace {
class StringSectionReader { … };
}
LogicalResult StringSectionReader::initialize(Location fileLoc,
ArrayRef<uint8_t> sectionData) { … }
namespace {
class DialectReader;
struct BytecodeDialect { … };
struct BytecodeOperationName { … };
}
static LogicalResult parseDialectGrouping(
EncodingReader &reader,
MutableArrayRef<std::unique_ptr<BytecodeDialect>> dialects,
function_ref<LogicalResult(BytecodeDialect *)> entryCallback) { … }
namespace {
class ResourceSectionReader { … };
class ParsedResourceEntry : public AsmParsedResourceEntry { … };
}
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 = { … }
LogicalResult ResourceSectionReader::initialize(
Location fileLoc, const ParserConfig &config,
MutableArrayRef<std::unique_ptr<BytecodeDialect>> dialects,
StringSectionReader &stringReader, ArrayRef<uint8_t> sectionData,
ArrayRef<uint8_t> offsetSectionData, DialectReader &dialectReader,
const std::shared_ptr<llvm::SourceMgr> &bufferOwnerRef) { … }
namespace {
class AttrTypeReader { … };
class DialectReader : public DialectBytecodeReader { … };
class PropertiesSectionReader { … };
}
LogicalResult AttrTypeReader::initialize(
MutableArrayRef<std::unique_ptr<BytecodeDialect>> dialects,
ArrayRef<uint8_t> sectionData, ArrayRef<uint8_t> offsetSectionData) { … }
template <typename T>
T AttrTypeReader::resolveEntry(SmallVectorImpl<Entry<T>> &entries, size_t index,
StringRef entryType) { … }
template <typename T>
LogicalResult AttrTypeReader::parseAsmEntry(T &result, EncodingReader &reader,
StringRef entryType) { … }
template <typename T>
LogicalResult AttrTypeReader::parseCustomEntry(Entry<T> &entry,
EncodingReader &reader,
StringRef entryType) { … }
class mlir::BytecodeReader::Impl { … };
LogicalResult BytecodeReader::Impl::read(
Block *block, llvm::function_ref<bool(Operation *)> lazyOpsCallback) { … }
LogicalResult BytecodeReader::Impl::parseVersion(EncodingReader &reader) { … }
LogicalResult BytecodeDialect::load(const DialectReader &reader,
MLIRContext *ctx) { … }
LogicalResult
BytecodeReader::Impl::parseDialectSection(ArrayRef<uint8_t> sectionData) { … }
FailureOr<OperationName>
BytecodeReader::Impl::parseOpName(EncodingReader &reader,
std::optional<bool> &wasRegistered) { … }
LogicalResult BytecodeReader::Impl::parseResourceSection(
EncodingReader &reader, std::optional<ArrayRef<uint8_t>> resourceData,
std::optional<ArrayRef<uint8_t>> resourceOffsetData) { … }
FailureOr<BytecodeReader::Impl::UseListMapT>
BytecodeReader::Impl::parseUseListOrderForRange(EncodingReader &reader,
uint64_t numResults) { … }
LogicalResult BytecodeReader::Impl::sortUseListOrder(Value value) { … }
LogicalResult BytecodeReader::Impl::processUseLists(Operation *topLevelOp) { … }
LogicalResult
BytecodeReader::Impl::parseIRSection(ArrayRef<uint8_t> sectionData,
Block *block) { … }
LogicalResult
BytecodeReader::Impl::parseRegions(std::vector<RegionReadState> ®ionStack,
RegionReadState &readState) { … }
FailureOr<Operation *>
BytecodeReader::Impl::parseOpWithoutRegions(EncodingReader &reader,
RegionReadState &readState,
bool &isIsolatedFromAbove) { … }
LogicalResult BytecodeReader::Impl::parseRegion(RegionReadState &readState) { … }
LogicalResult
BytecodeReader::Impl::parseBlockHeader(EncodingReader &reader,
RegionReadState &readState) { … }
LogicalResult BytecodeReader::Impl::parseBlockArguments(EncodingReader &reader,
Block *block) { … }
Value BytecodeReader::Impl::parseOperand(EncodingReader &reader) { … }
LogicalResult BytecodeReader::Impl::defineValues(EncodingReader &reader,
ValueRange newValues) { … }
Value BytecodeReader::Impl::createForwardRef() { … }
BytecodeReader::~BytecodeReader() { … }
BytecodeReader::BytecodeReader(
llvm::MemoryBufferRef buffer, const ParserConfig &config, bool lazyLoading,
const std::shared_ptr<llvm::SourceMgr> &bufferOwnerRef) { … }
LogicalResult BytecodeReader::readTopLevel(
Block *block, llvm::function_ref<bool(Operation *)> lazyOpsCallback) { … }
int64_t BytecodeReader::getNumOpsToMaterialize() const { … }
bool BytecodeReader::isMaterializable(Operation *op) { … }
LogicalResult BytecodeReader::materialize(
Operation *op, llvm::function_ref<bool(Operation *)> lazyOpsCallback) { … }
LogicalResult
BytecodeReader::finalize(function_ref<bool(Operation *)> shouldMaterialize) { … }
bool mlir::isBytecode(llvm::MemoryBufferRef buffer) { … }
static LogicalResult
readBytecodeFileImpl(llvm::MemoryBufferRef buffer, Block *block,
const ParserConfig &config,
const std::shared_ptr<llvm::SourceMgr> &bufferOwnerRef) { … }
LogicalResult mlir::readBytecodeFile(llvm::MemoryBufferRef buffer, Block *block,
const ParserConfig &config) { … }
LogicalResult
mlir::readBytecodeFile(const std::shared_ptr<llvm::SourceMgr> &sourceMgr,
Block *block, const ParserConfig &config) { … }