21#include <mlir/Bytecode/BytecodeImplementation.h>
22#include <mlir/IR/DialectImplementation.h>
23#include <mlir/Support/LLVM.h>
25#include <llvm/ADT/TypeSwitch.h>
33#define GET_ATTRDEF_CLASSES
46enum class LLZKAttrEncoding : uint8_t {
53 Attribute readAttribute(DialectBytecodeReader &reader)
const final {
55 if (failed(reader.readVarInt(encoding))) {
58 if (encoding > std::numeric_limits<uint8_t>::max()) {
59 reader.emitError(
"unknown LLZK attribute encoding: ") << encoding;
63 switch (
static_cast<LLZKAttrEncoding
>(encoding)) {
64 case LLZKAttrEncoding::LoopBounds: {
68 if (failed(lower) || failed(upper) || failed(step)) {
71 return LoopBoundsAttr::get(getContext(), *lower, *upper, *step);
75 reader.emitError(
"unknown LLZK attribute encoding: ") << encoding;
79 LogicalResult writeAttribute(Attribute attr, DialectBytecodeWriter &writer)
const final {
80 if (
auto loopBounds = dyn_cast<LoopBoundsAttr>(attr)) {
81 writer.writeVarInt(
static_cast<uint64_t
>(LLZKAttrEncoding::LoopBounds));
91LogicalResult verifyLlzkMainAttr(Operation *op, Attribute attr) {
92 ModuleOp moduleOp = llvm::dyn_cast<ModuleOp>(op);
94 return op->emitError().append(
96 ModuleOp::getOperationName(),
'\''
101 if (succeeded(mainStructTypeOpt)) {
103 SymbolTableCollection symbolTables;
104 return st.getDefinition(symbolTables, op);
114 return verifyLlzkMainAttr(op, attr.getValue());
119auto LLZKDialect::initialize() ->
void {
122 #define GET_ATTRDEF_LIST
131 addInterfaces<LLZKDialectBytecodeInterfaceImpl>();
::llvm::LogicalResult verifyOperationAttribute(::mlir::Operation *op, ::mlir::NamedAttribute attribute) override
Provides a hook for verifying dialect attributes attached to the given op.
mlir::FailureOr< llvm::DynamicAPInt > readDynamicAPInt(mlir::DialectBytecodeReader &reader)
Decode a signed integer, rejecting invalid widths before allocating storage.
FailureOr< StructType > getTypeFromLlzkMainAttr(ModuleOp op, Attribute attr)
constexpr char MAIN_ATTR_NAME[]
Name of the attribute on the top-level ModuleOp that specifies the type of the main struct.
void writeDynamicAPInt(mlir::DialectBytecodeWriter &writer, const llvm::DynamicAPInt &value)
Write the minimal signed two's-complement encoding of a mathematical integer.
This implements the bytecode interface for the LLZK dialect.
LLZKDialectBytecodeInterface(mlir::Dialect *dia)