1//===-- Ops.td ---------------------------------------------*- tablegen -*-===//
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
8//===----------------------------------------------------------------------===//
10#ifndef LLZK_CONSTRAIN_OPS
11#define LLZK_CONSTRAIN_OPS
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"
20include "mlir/Interfaces/SideEffectInterfaces.td"
21include "mlir/IR/OpBase.td"
22include "mlir/IR/SymbolInterfaces.td"
24//===------------------------------------------------------------------===//
25// Constraint emit operations
26//===------------------------------------------------------------------===//
28class EmitOp<string mnemonic, list<Trait> traits = []>
29 : Op<ConstrainDialect, mnemonic,
30 traits#[ConstraintOpInterface, ConstraintGen,
31 DeclareOpInterfaceMethods<SymbolUserOpInterface>]> {}
34 : EmitOp<"eq", [Commutative, ElementwiseMappable, TypesUnify<"lhs", "rhs">,
36 let summary = "emit an equality constraint";
38 Emits an equality constraint between lhs and rhs. For the built-in Signal
39 struct, the constraint is performed on the Signal's inner `@reg` felt field.
42 let arguments = (ins EmitEqType:$lhs, EmitEqType:$rhs);
44 let assemblyFormat = [{
45 $lhs `,` $rhs `:` type($lhs)
46 `` custom<InferredOrParsedType>(type($rhs), ref(type($lhs)))
50 let extraClassDeclaration = [{
51 static ::mlir::Type inferRHS(::mlir::Type lhsType);
53 static ::mlir::ParseResult parseInferredOrParsedType(::mlir::OpAsmParser &parser,
54 ::mlir::Type &rhsType, ::mlir::Type lhsType
56 if (mlir::succeeded(parser.parseOptionalComma())) {
57 // If there is a comma, parse the `rhsType`
59 if (parser.parseCustomTypeWithFallback(type)) {
60 return mlir::failure();
64 // Otherwise, infer the `rhsType` from `lhsType`
65 rhsType = inferRHS(lhsType);
67 return mlir::success();
70 static void printInferredOrParsedType(::mlir::OpAsmPrinter &printer,
71 ::mlir::Operation *op, ::mlir::Type rhsType, ::mlir::Type lhsType
74 printer.printStrippedAttrOrType(rhsType);
79def EmitContainmentOp : EmitOp<"in"> {
80 let summary = "emit a containment constraint";
82 Emits a containment constraint between lhs and rhs (rhs must be contained
83 within lhs). If lhs is an N-dimensional array (N >= 1), rhs must be an
84 M-dimensional array, where N >= M (M=0 means that rhs is a scalar element
85 of type accepted by the `constrain.eq` operation).
88 let arguments = (ins LLZK_ArrayType:$lhs, AnyLLZKType:$rhs);
90 let assemblyFormat = [{
91 $lhs `,` $rhs `:` type($lhs) `,` type($rhs) attr-dict
94 let hasVerifier = true;
97#endif // LLZK_CONSTRAIN_OPS