15#include "llvm/ADT/APFloat.h"
16#include "llvm/ADT/SmallVector.h"
31template <
class EntryTy>
34 if (storage.empty()) {
40 writer.
writeList(storage, [&](EntryTy val) {
41 if constexpr (std::is_base_of_v<Attribute, EntryTy>) {
43 }
else if constexpr (std::is_integral_v<EntryTy>) {
46 static_assert(
true,
"EntryTy not supported");
51template <
class EntryTy>
54 bool isPresent =
false;
61 auto readEntry = [&]() -> FailureOr<EntryTy> {
63 if constexpr (std::is_base_of_v<Attribute, EntryTy>) {
66 }
else if constexpr (std::is_integral_v<EntryTy>) {
70 static_assert(
true,
"EntryTy not supported");
75 return reader.
readList(storage, readEntry);
82template <
class EntryTy>
84 std::optional<EntryTy> storage) {
85 static_assert(std::is_integral_v<EntryTy>,
86 "EntryTy must be an integral type");
87 EntryTy val = storage.value_or(0);
91template <
class EntryTy>
93 std::optional<EntryTy> &storage) {
94 static_assert(std::is_integral_v<EntryTy>,
95 "EntryTy must be an integral type");
101 storage =
static_cast<EntryTy
>(
result);
103 storage = std::nullopt;
112#include "mlir/Dialect/LLVMIR/LLVMDialectBytecode.cpp.inc"
120struct LLVMDialectBytecodeInterface :
public BytecodeDialectInterface {
121 LLVMDialectBytecodeInterface(Dialect *dialect)
122 : BytecodeDialectInterface(dialect) {}
125 Attribute readAttribute(DialectBytecodeReader &reader)
const override {
129 LogicalResult writeAttribute(Attribute attr,
130 DialectBytecodeWriter &writer)
const override {
131 return ::writeAttribute(attr, writer);
135 Type readType(DialectBytecodeReader &reader)
const override {
139 LogicalResult writeType(Type type,
140 DialectBytecodeWriter &writer)
const override {
141 return ::writeType(type, writer);
147 dialect->addInterfaces<LLVMDialectBytecodeInterface>();
This class defines a virtual interface for reading a bytecode stream, providing hooks into the byteco...
virtual LogicalResult readBool(bool &result)=0
Read a bool from the bytecode.
virtual LogicalResult readVarInt(uint64_t &result)=0
Read a variable width integer.
LogicalResult readVarIntWithFlag(uint64_t &result, bool &flag)
Parse a variable length encoded integer whose low bit is used to encode an unrelated flag,...
virtual LogicalResult readOptionalAttribute(Attribute &attr)=0
Read an optional reference to the given attribute.
LogicalResult readList(SmallVectorImpl< T > &result, CallbackFn &&callback)
Read out a list of elements, invoking the provided callback for each element.
This class defines a virtual interface for writing to a bytecode stream, providing hooks into the byt...
virtual void writeOptionalAttribute(Attribute attr)=0
virtual void writeVarInt(uint64_t value)=0
Write a variable width integer to the output stream.
void writeVarIntWithFlag(uint64_t value, bool flag)
Write a VarInt and a flag packed together.
void writeList(RangeT &&range, CallbackFn &&callback)
Write out a list of elements, invoking the provided callback for each element.
virtual void writeOwnedBool(bool value)=0
Write a bool to the output stream.
void addBytecodeInterface(LLVMDialect *dialect)
Add the interfaces necessary for encoding the LLVM dialect components in bytecode.
Include the generated interface declarations.