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 - 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
10
#include "
llzk/Dialect/Bool/IR/Dialect.h
"
11
12
#include "
llzk/Dialect/Bool/IR/Ops.h
"
13
#include "
llzk/Dialect/Felt/IR/Types.h
"
14
#include "
llzk/Dialect/LLZK/IR/Versioning.h
"
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
25
#include "
llzk/Dialect/Bool/IR/Dialect.cpp.inc
"
26
27
// Need a complete declaration of storage classes for below
28
#define GET_ATTRDEF_CLASSES
29
#include "
llzk/Dialect/Bool/IR/Attrs.cpp.inc
"
30
31
//===------------------------------------------------------------------===//
32
// BoolDialect
33
//===------------------------------------------------------------------===//
34
35
mlir::Operation *
llzk::boolean::BoolDialect::materializeConstant
(
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
47
auto
llzk::boolean::BoolDialect::initialize() ->
void
{
48
// clang-format off
49
addOperations<
50
#define GET_OP_LIST
51
#include "
llzk/Dialect/Bool/IR/Ops.cpp.inc
"
52
>();
53
54
// Suppress false positive from `clang-tidy`
55
// NOLINTNEXTLINE(clang-analyzer-core.StackAddressEscape)
56
addAttributes<
57
#define GET_ATTRDEF_LIST
58
#include "
llzk/Dialect/Bool/IR/Attrs.cpp.inc
"
59
>();
60
// clang-format on
61
addInterfaces<LLZKDialectBytecodeInterface<BoolDialect>>();
62
}
Attrs.cpp.inc
Dialect.cpp.inc
Dialect.h
Ops.cpp.inc
Ops.h
Types.h
Versioning.h
llzk::boolean::BoolDialect::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:35
lib
Dialect
Bool
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.