LLZK 0.1.0
Veridise's ZK Language IR
Loading...
Searching...
No Matches
Ops.td
Go to the documentation of this file.
1//===-- Ops.td ---------------------------------------------*- tablegen -*-===//
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#ifndef LLZK_CONSTRAIN_OPS
11#define LLZK_CONSTRAIN_OPS
12
13include "llzk/Dialect/Array/IR/Types.td"
14include "llzk/Dialect/Constrain/IR/Dialect.td"
15include "llzk/Dialect/Constrain/IR/OpInterfaces.td"
16include "llzk/Dialect/Function/IR/OpTraits.td"
17include "llzk/Dialect/Shared/Types.td"
18include "llzk/Dialect/Shared/OpTraits.td"
19
20include "mlir/Interfaces/SideEffectInterfaces.td"
21include "mlir/IR/OpBase.td"
22include "mlir/IR/SymbolInterfaces.td"
23
24//===------------------------------------------------------------------===//
25// Constraint emit operations
26//===------------------------------------------------------------------===//
27
28class EmitOp<string mnemonic, list<Trait> traits = []>
29 : Op<ConstrainDialect, mnemonic,
30 traits#[ConstraintOpInterface, ConstraintGen,
31 DeclareOpInterfaceMethods<SymbolUserOpInterface>]> {
32
33 let assemblyFormat = [{
34 $lhs `,` $rhs `:` type($lhs)
35 `` custom<InferredOrParsedType>(type($rhs), ref(type($lhs)))
36 attr-dict
37 }];
38
39 let extraClassDeclaration = [{
40 static ::mlir::Type inferRHS(::mlir::Type lhsType);
41
42 static ::mlir::ParseResult parseInferredOrParsedType(::mlir::OpAsmParser &parser,
43 ::mlir::Type &rhsType, ::mlir::Type lhsType
44 ) {
45 if (mlir::succeeded(parser.parseOptionalComma())) {
46 // If there is a comma, parse the `rhsType`
47 mlir::Type type;
48 if (parser.parseCustomTypeWithFallback(type)) {
49 return mlir::failure();
50 }
51 rhsType = type;
52 } else {
53 // Otherwise, infer the `rhsType` from `lhsType`
54 rhsType = inferRHS(lhsType);
55 }
56 return mlir::success();
57 }
58
59 static void printInferredOrParsedType(::mlir::OpAsmPrinter &printer,
60 ::mlir::Operation *op, ::mlir::Type rhsType, ::mlir::Type lhsType
61 ) {
62 printer << ", ";
63 printer.printStrippedAttrOrType(rhsType);
64 }
65 }];
66}
67
68def EmitEqualityOp
69 : EmitOp<"eq", [Commutative, ElementwiseMappable, TypesUnify<"lhs", "rhs">,
70]> {
71 let summary = "emit an equality constraint";
72 let description = [{
73 Emits an equality constraint between lhs and rhs. For the built-in Signal
74 struct, the constraint is performed on the Signal's inner `@reg` felt field.
75 }];
76
77 let arguments = (ins EmitEqType:$lhs, EmitEqType:$rhs);
78}
79
80def EmitContainmentOp : EmitOp<"in", [ArrayElemTypeUnifyWith<"lhs", "rhs">]> {
81 let summary = "emit a containment constraint";
82 let description = [{}];
83
84 let arguments = (ins LLZK_ArrayType:$lhs, ArrayElemType:$rhs);
85}
86
87#endif // LLZK_CONSTRAIN_OPS