LLZK 3.0.0
An open-source IR for Zero Knowledge (ZK) circuits
Loading...
Searching...
No Matches
Dialect.cpp
Go to the documentation of this file.
1//===-- Dialect.cpp - Global value dialect implementation -------*- C++ -*-===//
2//
3// Part of the LLZK Project, under the Apache License v2.0.
4// See LICENSE.txt for license information.
5// Copyright 2025 Veridise Inc.
6// SPDX-License-Identifier: Apache-2.0
7//
8//===----------------------------------------------------------------------===//
9
11
12#include "InitializerUtils.h"
13
16
17// TableGen'd implementation files
19
20using namespace mlir;
21using namespace llzk;
22
23//===------------------------------------------------------------------===//
24// GlobalDialect
25//===------------------------------------------------------------------===//
26
27namespace {
28
29class GlobalDialectBytecodeInterface : public LLZKDialectBytecodeInterface<global::GlobalDialect> {
30 using Base = LLZKDialectBytecodeInterface<global::GlobalDialect>;
31
32public:
33 using Base::Base;
34
35 LogicalResult upgradeFromVersion(
36 Operation *root, const LLZKDialectVersion & /*current*/,
37 const LLZKDialectVersion & /*requested*/
38 ) const final {
39 auto res = root->walk([](global::GlobalDefOp global) -> WalkResult {
40 if (Attribute initialValue = global.getInitialValueAttr()) {
41 auto errFn = [context = initialValue.getContext()] {
43 };
44 FailureOr<global::NormalizedGlobalInitializer> normalized =
45 global::normalizeGlobalInitializer(global.getType(), initialValue, errFn);
46 if (failed(normalized)) {
47 return global.emitError(
48 "contains a legacy initializer that is incompatible with its declared type"
49 );
50 }
51 global.setInitialValueAttr(normalized->value);
52 global.setTypeAttr(TypeAttr::get(normalized->type));
53 }
54 return WalkResult::advance();
55 });
56 return failure(res.wasInterrupted());
57 }
58};
59
60} // namespace
61
62auto global::GlobalDialect::initialize() -> void {
63 // clang-format off
64 addOperations<
65 #define GET_OP_LIST
67 >();
68 // clang-format on
69 addInterfaces<GlobalDialectBytecodeInterface>();
70}
static InFlightDiagnosticWrapper createSilent(mlir::MLIRContext *ctx)
Construct a silent diagnostic that does nothing when appended to or reported.
Definition ErrorHelper.h:74
void setInitialValueAttr(::mlir::Attribute attr)
Definition Ops.h.inc:287
::mlir::Type getType()
Definition Ops.cpp.inc:401
void setTypeAttr(::mlir::TypeAttr attr)
Definition Ops.h.inc:282
::mlir::Attribute getInitialValueAttr()
Definition Ops.h.inc:267
mlir::FailureOr< NormalizedGlobalInitializer > normalizeGlobalInitializer(mlir::Type type, mlir::Attribute value, EmitErrorFn emitError)
Normalize unambiguous initializer representations and their declared type.
This implements the bytecode interface for the LLZK dialect.
Definition Versioning.h:63