15#include "llvm/ADT/APFloat.h"
16#include "llvm/ADT/SmallVector.h"
17#include "llvm/ADT/TypeSwitch.h"
27static void write(DIExpressionElemAttr attribute,
29static LogicalResult writeAttribute(
Attribute attribute,
39template <
class EntryTy>
42 if (storage.empty()) {
48 writer.
writeList(storage, [&](EntryTy val) {
49 if constexpr (std::is_base_of_v<Attribute, EntryTy>) {
51 }
else if constexpr (std::is_integral_v<EntryTy>) {
54 static_assert(
true,
"EntryTy not supported");
59template <
class EntryTy>
62 bool isPresent =
false;
69 auto readEntry = [&]() -> FailureOr<EntryTy> {
71 if constexpr (std::is_base_of_v<Attribute, EntryTy>) {
74 }
else if constexpr (std::is_integral_v<EntryTy>) {
78 static_assert(
true,
"EntryTy not supported");
83 return reader.
readList(storage, readEntry);
90template <
class EntryTy>
92 std::optional<EntryTy> storage) {
93 static_assert(std::is_integral_v<EntryTy>,
94 "EntryTy must be an integral type");
95 EntryTy val = storage.value_or(0);
99template <
class EntryTy>
101 std::optional<EntryTy> &storage) {
102 static_assert(std::is_integral_v<EntryTy>,
103 "EntryTy must be an integral type");
109 storage =
static_cast<EntryTy
>(
result);
111 storage = std::nullopt;
119#include "mlir/Dialect/LLVMIR/LLVMDialectBytecode.cpp.inc"
127 LLVMDialectBytecodeInterface(Dialect *dialect)
128 : BytecodeDialectInterface(dialect) {}
131 Attribute readAttribute(DialectBytecodeReader &reader)
const override {
135 LogicalResult writeAttribute(Attribute attr,
136 DialectBytecodeWriter &writer)
const override {
137 return ::writeAttribute(attr, writer);
141 Type readType(DialectBytecodeReader &reader)
const override {
145 LogicalResult writeType(Type type,
146 DialectBytecodeWriter &writer)
const override {
147 return ::writeType(type, writer);
153 dialect->addInterfaces<LLVMDialectBytecodeInterface>();
Attributes are known-constant values of operations.
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.