LLZK 3.0.0
An open-source IR for Zero Knowledge (ZK) circuits
Loading...
Searching...
No Matches
OpInterfaces.td
Go to the documentation of this file.
1//===-- OpInterfaces.td ------------------------------------*- tablegen -*-===//
2//
3// Part of the LLZK Project, under the Apache License v2.0.
4// See LICENSE.txt for license information.
5// Copyright 2026 Project LLZK
6// SPDX-License-Identifier: Apache-2.0
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef LLZK_VERIF_OP_INTERFACES
11#define LLZK_VERIF_OP_INTERFACES
12
13include "mlir/IR/Interfaces.td"
14include "mlir/Interfaces/SideEffectInterfaces.td"
15include "mlir/Interfaces/MemorySlotInterfaces.td"
16include "mlir/IR/SymbolInterfaces.td"
17
18def ConditionOpInterface
19 : OpInterface<"ConditionOpInterface", [DeclareOpInterfaceMethods<
20 MemoryEffectsOpInterface>]> {
21 let description = [{
22 Common interface for precondition and postcondition operations.
23
24 This declares the `MemoryEffectsOpInterface`, which, like the `cf.assert` (MLIR `cf` dialect)
25 and `bool.assert` (LLZK `bool` dialect) ops, adds a MemWrite affect to model program termination.
26 }];
27 let cppNamespace = "::llzk::verif";
28
29 let methods = [
30 // Requires implementors to have a condition argument
31 InterfaceMethod<[{Gets the SSA Value for the condition operand.}],
32 "::mlir::TypedValue<::mlir::IntegerType>", "getCondition",
33 (ins)>];
34}
35
36def PreconditionOpInterface
37 : OpInterface<"PreconditionOpInterface", [ConditionOpInterface]> {
38 let description = [{
39 Common interface for precondition operations (i.e., `require_*`).
40 }];
41 let cppNamespace = "::llzk::verif";
42}
43
44def PostconditionOpInterface
45 : OpInterface<"PostconditionOpInterface", [ConditionOpInterface]> {
46 let description = [{
47 Common interface for postcondition operations (i.e., `ensure_*`).
48 }];
49 let cppNamespace = "::llzk::verif";
50}
51
52def InvariantTarget : OpInterface<"InvariantTargetOpInterface"> {
53 let description = [{
54 Interface implemented by operations that can be targeted by a loop invariant.
55
56 Targets are referenced by a label that implementations of this interface must provide.
57 }];
58 let cppNamespace = "::llzk::verif";
59
60 let methods =
61 [InterfaceMethod<[{Gets the label of the loop, if available.}],
62 "::mlir::FailureOr<::mlir::StringRef>", "getLabel",
63 (ins), [{
64 auto attr = ::mlir::dyn_cast_or_null<::mlir::StringAttr>($_op->getDiscardableAttr("loop_label"));
65 if (!attr) return ::mlir::failure();
66 return attr.getValue();
67 }]>,
68 InterfaceMethod<
69 [{Gets the types of the values that the invariant binds inside its body.}],
70 "::mlir::SmallVector<::mlir::Type>", "getArgumentTypes", (ins)>,
71 ];
72}
73
74def ContractTarget : OpInterface<"ContractTargetOpInterface", [Symbol]> {
75 let description = [{
76 Interface implemented by operations that can be targeted by a contract.
77
78 Targets are referenced by name so implementations of this interface must also implement the `Symbol` interface.
79 }];
80 let cppNamespace = "::llzk::verif";
81
82 let methods = [InterfaceMethod<
83 [{Gets the ops that can be targeted by invariant ops.}],
84 "::llvm::SmallVector<::llzk::verif::InvariantTargetOpInterface>",
85 "getLoops", (ins), [{
86 auto op = $_op; // walkCollect expects an l-value but the expansion of $_op is not.
87 return walkCollect<::llzk::verif::InvariantTargetOpInterface>(op);
88 }]>];
89
90 let extraClassDeclaration = [{
91 /// Emulates the static method with the same name found in operations.
92 static ::mlir::StringLiteral getOperationName() {
93 return ::mlir::StringLiteral("contract target interface implementation");
94 }
95 }];
96}
97
98#endif // LLZK_VERIF_OP_INTERFACES