LLZK 2.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 - Boolean 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// Need a complete declaration of storage classes for below
28#define GET_ATTRDEF_CLASSES
30
31//===------------------------------------------------------------------===//
32// BoolDialect
33//===------------------------------------------------------------------===//
34
36 mlir::OpBuilder &builder, mlir::Attribute value, mlir::Type type, mlir::Location loc
37) {
38 // Materialize i1 constants (results of folded bool and cmp ops) as
39 // arith.constant ops, which is already used alongside this dialect.
40 if (llvm::isa<mlir::IntegerAttr>(value) && llvm::isa<mlir::IntegerType>(type) &&
41 llvm::cast<mlir::IntegerType>(type).isInteger(1)) {
42 return builder.create<mlir::arith::ConstantOp>(loc, llvm::cast<mlir::IntegerAttr>(value));
43 }
44 return nullptr;
45}
46
47auto llzk::boolean::BoolDialect::initialize() -> void {
48 // clang-format off
49 addOperations<
50 #define GET_OP_LIST
52 >();
53
54 addAttributes<
55 #define GET_ATTRDEF_LIST
57 >();
58 // clang-format on
59 addInterfaces<LLZKDialectBytecodeInterface<BoolDialect>>();
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:35