#include "mlir/Bytecode/BytecodeWriter.h"
#include "IRNumbering.h"
#include "mlir/Bytecode/BytecodeImplementation.h"
#include "mlir/Bytecode/BytecodeOpInterface.h"
#include "mlir/Bytecode/Encoding.h"
#include "mlir/IR/Attributes.h"
#include "mlir/IR/Diagnostics.h"
#include "mlir/IR/OpImplementation.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/CachedHashString.h"
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/raw_ostream.h"
#include <optional>
#define DEBUG_TYPE …
usingnamespacemlir;
usingnamespacemlir::bytecode::detail;
struct BytecodeWriterConfig::Impl { … };
BytecodeWriterConfig::BytecodeWriterConfig(StringRef producer)
: … { … }
BytecodeWriterConfig::BytecodeWriterConfig(FallbackAsmResourceMap &map,
StringRef producer)
: … { … }
BytecodeWriterConfig::~BytecodeWriterConfig() = default;
ArrayRef<std::unique_ptr<AttrTypeBytecodeWriter<Attribute>>>
BytecodeWriterConfig::getAttributeWriterCallbacks() const { … }
ArrayRef<std::unique_ptr<AttrTypeBytecodeWriter<Type>>>
BytecodeWriterConfig::getTypeWriterCallbacks() const { … }
void BytecodeWriterConfig::attachAttributeCallback(
std::unique_ptr<AttrTypeBytecodeWriter<Attribute>> callback) { … }
void BytecodeWriterConfig::attachTypeCallback(
std::unique_ptr<AttrTypeBytecodeWriter<Type>> callback) { … }
void BytecodeWriterConfig::attachResourcePrinter(
std::unique_ptr<AsmResourcePrinter> printer) { … }
void BytecodeWriterConfig::setElideResourceDataFlag(
bool shouldElideResourceData) { … }
void BytecodeWriterConfig::setDesiredBytecodeVersion(int64_t bytecodeVersion) { … }
int64_t BytecodeWriterConfig::getDesiredBytecodeVersion() const { … }
llvm::StringMap<std::unique_ptr<DialectVersion>> &
BytecodeWriterConfig::getDialectVersionMap() const { … }
void BytecodeWriterConfig::setDialectVersion(
llvm::StringRef dialectName,
std::unique_ptr<DialectVersion> dialectVersion) const { … }
namespace {
class EncodingEmitter { … };
namespace {
class StringSectionBuilder { … };
}
class DialectWriter : public DialectBytecodeWriter { … };
namespace {
class PropertiesSectionBuilder { … };
}
class RawEmitterOstream : public raw_ostream { … };
}
void EncodingEmitter::writeTo(raw_ostream &os) const { … }
void EncodingEmitter::emitMultiByteVarInt(uint64_t value, StringLiteral desc) { … }
namespace {
class BytecodeWriter { … };
}
LogicalResult BytecodeWriter::write(Operation *rootOp, raw_ostream &os) { … }
template <typename EntriesT, typename EntryCallbackT>
static void writeDialectGrouping(EncodingEmitter &emitter, EntriesT &&entries,
EntryCallbackT &&callback) { … }
void BytecodeWriter::writeDialectSection(EncodingEmitter &emitter) { … }
void BytecodeWriter::writeAttrTypeSection(EncodingEmitter &emitter) { … }
LogicalResult BytecodeWriter::writeBlock(EncodingEmitter &emitter,
Block *block) { … }
LogicalResult BytecodeWriter::writeOp(EncodingEmitter &emitter, Operation *op) { … }
void BytecodeWriter::writeUseListOrders(EncodingEmitter &emitter,
uint8_t &opEncodingMask,
ValueRange range) { … }
LogicalResult BytecodeWriter::writeRegion(EncodingEmitter &emitter,
Region *region) { … }
LogicalResult BytecodeWriter::writeIRSection(EncodingEmitter &emitter,
Operation *op) { … }
namespace {
class ResourceBuilder : public AsmResourceBuilder { … };
}
void BytecodeWriter::writeResourceSection(Operation *op,
EncodingEmitter &emitter) { … }
void BytecodeWriter::writeStringSection(EncodingEmitter &emitter) { … }
void BytecodeWriter::writePropertiesSection(EncodingEmitter &emitter) { … }
LogicalResult mlir::writeBytecodeToFile(Operation *op, raw_ostream &os,
const BytecodeWriterConfig &config) { … }