15#include "llvm/ADT/APFloat.h"
16#include "llvm/ADT/SmallVector.h"
17#include "llvm/ADT/TypeSwitch.h"
32template <
class EntryTy>
35 if (storage.empty()) {
41 writer.
writeList(storage, [&](EntryTy val) {
42 if constexpr (std::is_base_of_v<Attribute, EntryTy>) {
44 }
else if constexpr (std::is_integral_v<EntryTy>) {
47 static_assert(
true,
"EntryTy not supported");
52template <
class EntryTy>
55 bool isPresent =
false;
62 auto readEntry = [&]() -> FailureOr<EntryTy> {
64 if constexpr (std::is_base_of_v<Attribute, EntryTy>) {
67 }
else if constexpr (std::is_integral_v<EntryTy>) {
71 static_assert(
true,
"EntryTy not supported");
76 return reader.
readList(storage, readEntry);
83template <
class EntryTy>
85 std::optional<EntryTy> storage) {
86 static_assert(std::is_integral_v<EntryTy>,
87 "EntryTy must be an integral type");
88 EntryTy val = storage.value_or(0);
92template <
class EntryTy>
94 std::optional<EntryTy> &storage) {
95 static_assert(std::is_integral_v<EntryTy>,
96 "EntryTy must be an integral type");
102 storage =
static_cast<EntryTy
>(
result);
104 storage = std::nullopt;
112#include "mlir/Dialect/LLVMIR/LLVMDialectBytecode.cpp.inc"
120 LLVMDialectBytecodeInterface(Dialect *dialect)
121 : BytecodeDialectInterface(dialect) {}
124 Attribute readAttribute(DialectBytecodeReader &reader)
const override {
128 LogicalResult writeAttribute(Attribute attr,
129 DialectBytecodeWriter &writer)
const override {
130 return ::writeAttribute(attr, writer);
134 Type readType(DialectBytecodeReader &reader)
const override {
138 LogicalResult writeType(Type type,
139 DialectBytecodeWriter &writer)
const override {
140 return ::writeType(type, writer);
146 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.