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 - 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
11
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
25
26#define GET_ATTRDEF_CLASSES
28
29//===------------------------------------------------------------------===//
30// CastDialect
31//===------------------------------------------------------------------===//
32
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
46auto llzk::cast::CastDialect::initialize() -> void {
47 // clang-format off
48 addOperations<
49 #define GET_OP_LIST
51 >();
52
53 addAttributes<
54 #define GET_ATTRDEF_LIST
56 >();
57 // clang-format on
58 addInterfaces<LLZKDialectBytecodeInterface<CastDialect>>();
59}
::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
static FeltConstantOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::Type result, ::llzk::felt::FeltConstAttr value)
Definition Ops.cpp.inc:1274