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 - Polymorphic 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
15
16#include <mlir/Dialect/Arith/IR/Arith.h>
17#include <mlir/IR/Builders.h>
18#include <mlir/IR/BuiltinAttributes.h>
19#include <mlir/IR/BuiltinTypes.h>
20#include <mlir/IR/DialectImplementation.h>
21
22#include <llvm/ADT/TypeSwitch.h>
23
24// TableGen'd implementation files
26
27#define GET_TYPEDEF_CLASSES
29
30//===------------------------------------------------------------------===//
31// PolymorphicDialect
32//===------------------------------------------------------------------===//
33
35 mlir::OpBuilder &builder, mlir::Attribute value, mlir::Type type, mlir::Location loc
36) {
37 if (llvm::isa<mlir::IndexType, mlir::IntegerType>(type)) {
38 if (auto intAttr = llvm::dyn_cast<mlir::IntegerAttr>(value)) {
39 return builder.create<mlir::arith::ConstantOp>(loc, intAttr);
40 }
41 }
42 return nullptr;
43}
44
45auto llzk::polymorphic::PolymorphicDialect::initialize() -> void {
46 // clang-format off
47 addOperations<
48 #define GET_OP_LIST
50 >();
51
52 // Suppress false positive from `clang-tidy`
53 // NOLINTNEXTLINE(clang-analyzer-core.StackAddressEscape)
54 addTypes<
55 #define GET_TYPEDEF_LIST
57 >();
58 // clang-format on
59 addInterfaces<LLZKDialectBytecodeInterface<PolymorphicDialect>>();
60}
::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