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 - Cast 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/Cast/IR/Dialect.h
"
11
12
#include "
llzk/Dialect/Cast/IR/Attrs.h
"
13
#include "
llzk/Dialect/Cast/IR/Ops.h
"
14
#include "
llzk/Dialect/Felt/IR/Attrs.h
"
15
#include "
llzk/Dialect/Felt/IR/Ops.h
"
16
#include "
llzk/Dialect/LLZK/IR/Versioning.h
"
17
18
#include <mlir/Dialect/Arith/IR/Arith.h>
19
#include <mlir/IR/DialectImplementation.h>
20
21
#include <llvm/ADT/TypeSwitch.h>
22
23
// TableGen'd implementation files
24
#include "
llzk/Dialect/Cast/IR/Dialect.cpp.inc
"
25
26
#define GET_ATTRDEF_CLASSES
27
#include "
llzk/Dialect/Cast/IR/Attrs.cpp.inc
"
28
29
//===------------------------------------------------------------------===//
30
// CastDialect
31
//===------------------------------------------------------------------===//
32
34
mlir::Operation *
llzk::cast::CastDialect::materializeConstant
(
35
mlir::OpBuilder &builder, mlir::Attribute value, mlir::Type type, mlir::Location loc
36
) {
37
if
(
auto
attr = llvm::dyn_cast<llzk::felt::FeltConstAttr>(value);
38
attr && attr.getType() == type) {
39
return
llzk::felt::FeltConstantOp::create
(builder, loc, attr);
40
}
41
// No need to check `value.getType() == type` because it's already done internally
42
// by the `materialize()` function, returning `nullptr` on mismatch.
43
return
mlir::arith::ConstantOp::materialize(builder, value, type, loc);
44
}
45
46
auto
llzk::cast::CastDialect::initialize() ->
void
{
47
// clang-format off
48
addOperations<
49
#define GET_OP_LIST
50
#include "
llzk/Dialect/Cast/IR/Ops.cpp.inc
"
51
>();
52
53
addAttributes<
54
#define GET_ATTRDEF_LIST
55
#include "
llzk/Dialect/Cast/IR/Attrs.cpp.inc
"
56
>();
57
// clang-format on
58
addInterfaces<LLZKDialectBytecodeInterface<CastDialect>>();
59
}
Attrs.cpp.inc
Attrs.h
Dialect.cpp.inc
Dialect.h
Ops.cpp.inc
Ops.h
Attrs.h
Ops.h
Versioning.h
llzk::cast::CastDialect::materializeConstant
::mlir::Operation * materializeConstant(::mlir::OpBuilder &builder, ::mlir::Attribute value, ::mlir::Type type, ::mlir::Location loc) override
Materialize a single constant operation from a given attribute value with the desired resultant type.
Definition
Dialect.cpp:34
llzk::felt::FeltConstantOp::create
static FeltConstantOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::Type result, ::llzk::felt::FeltConstAttr value)
Definition
Ops.cpp.inc:1274
lib
Dialect
Cast
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.