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>]> {
33 let assemblyFormat = [{
34 $lhs `,` $rhs `:` type($lhs)
35 `` custom<InferredOrParsedType>(type($rhs), ref(type($lhs)))
39 let extraClassDeclaration = [{
40 static ::mlir::Type inferRHS(::mlir::Type lhsType);
42 static ::mlir::ParseResult parseInferredOrParsedType(::mlir::OpAsmParser &parser,
43 ::mlir::Type &rhsType, ::mlir::Type lhsType
45 if (mlir::succeeded(parser.parseOptionalComma())) {
46 // If there is a comma, parse the `rhsType`
48 if (parser.parseCustomTypeWithFallback(type)) {
49 return mlir::failure();
53 // Otherwise, infer the `rhsType` from `lhsType`
54 rhsType = inferRHS(lhsType);
56 return mlir::success();
59 static void printInferredOrParsedType(::mlir::OpAsmPrinter &printer,
60 ::mlir::Operation *op, ::mlir::Type rhsType, ::mlir::Type lhsType
63 printer.printStrippedAttrOrType(rhsType);
69 : EmitOp<"eq", [Commutative, ElementwiseMappable, TypesUnify<"lhs", "rhs">,
71 let summary = "emit an equality constraint";
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.
77 let arguments = (ins EmitEqType:$lhs, EmitEqType:$rhs);
80def EmitContainmentOp : EmitOp<"in", [ArrayElemTypeUnifyWith<"lhs", "rhs">]> {
81 let summary = "emit a containment constraint";
82 let description = [{}];
84 let arguments = (ins LLZK_ArrayType:$lhs, ArrayElemType:$rhs);
87#endif // LLZK_CONSTRAIN_OPS