LLZK
3.0.0
An open-source IR for Zero Knowledge (ZK) circuits
Toggle main menu visibility
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
10
#include "
llzk/Dialect/Global/IR/Dialect.h
"
11
12
#include "
InitializerUtils.h
"
13
14
#include "
llzk/Dialect/Global/IR/Ops.h
"
15
#include "
llzk/Dialect/LLZK/IR/Versioning.h
"
16
17
// TableGen'd implementation files
18
#include "
llzk/Dialect/Global/IR/Dialect.cpp.inc
"
19
20
using namespace
mlir
;
21
using namespace
llzk
;
22
23
//===------------------------------------------------------------------===//
24
// GlobalDialect
25
//===------------------------------------------------------------------===//
26
27
namespace
{
28
29
class
GlobalDialectBytecodeInterface :
public
LLZKDialectBytecodeInterface
<global::GlobalDialect> {
30
using
Base = LLZKDialectBytecodeInterface<global::GlobalDialect>;
31
32
public
:
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()] {
42
return
InFlightDiagnosticWrapper::createSilent
(context);
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
62
auto
global::GlobalDialect::initialize() ->
void
{
63
// clang-format off
64
addOperations<
65
#define GET_OP_LIST
66
#include "
llzk/Dialect/Global/IR/Ops.cpp.inc
"
67
>();
68
// clang-format on
69
addInterfaces<GlobalDialectBytecodeInterface>();
70
}
Dialect.cpp.inc
Dialect.h
Ops.cpp.inc
Ops.h
InitializerUtils.h
Versioning.h
llzk::InFlightDiagnosticWrapper::createSilent
static InFlightDiagnosticWrapper createSilent(mlir::MLIRContext *ctx)
Construct a silent diagnostic that does nothing when appended to or reported.
Definition
ErrorHelper.h:74
llzk::global::GlobalDefOp::setInitialValueAttr
void setInitialValueAttr(::mlir::Attribute attr)
Definition
Ops.h.inc:287
llzk::global::GlobalDefOp::getType
::mlir::Type getType()
Definition
Ops.cpp.inc:401
llzk::global::GlobalDefOp::setTypeAttr
void setTypeAttr(::mlir::TypeAttr attr)
Definition
Ops.h.inc:282
llzk::global::GlobalDefOp::getInitialValueAttr
::mlir::Attribute getInitialValueAttr()
Definition
Ops.h.inc:267
llzk::global::normalizeGlobalInitializer
mlir::FailureOr< NormalizedGlobalInitializer > normalizeGlobalInitializer(mlir::Type type, mlir::Attribute value, EmitErrorFn emitError)
Normalize unambiguous initializer representations and their declared type.
llzk
Definition
AnalysisPassEnums.cpp:19
mlir
Definition
ValueModel.h:30
llzk::LLZKDialectBytecodeInterface
This implements the bytecode interface for the LLZK dialect.
Definition
Versioning.h:63
lib
Dialect
Global
IR
Dialect.cpp
Generated by
1.17.0
Copyright 2025 Veridise Inc. under the Apache License v2.0. Copyright 2026 Project LLZK under the Apache License v2.0.