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//===----------------------------------------------------------------------===//
13include "llzk/Dialect/LLZK/IR/Dialect.td"
14include "llzk/Dialect/LLZK/IR/Attrs.td" // must be included to generate docs
15include "llzk/Dialect/Shared/Types.td"
17include "mlir/IR/OpAsmInterface.td"
18include "mlir/IR/OpBase.td"
19include "mlir/Interfaces/SideEffectInterfaces.td"
21//===------------------------------------------------------------------===//
23//===------------------------------------------------------------------===//
25class LLZKDialectOp<string mnemonic, list<Trait> traits = []>
26 : Op<LLZKDialect, mnemonic, traits>;
29 : LLZKDialectOp<"nondet", [AlwaysSpeculatable,
30 DeclareOpInterfaceMethods<
31 OpAsmOpInterface, ["getAsmResultNames"]>]> {
32 let summary = "uninitialized variable";
34 This operation produces an SSA variable of the specified type but with
35 nondeterministic value.
37 This op can be used in `@constrain()` functions in place of expressions that
38 cannot be included in constraints. It may also be generated for a frontend
39 language that supports uninitialized variables and can also be introduced by
40 the `llzk-array-to-scalar` pass if there is a read from an array index
41 that was not dominated by an earlier write to that same index.
46 %0 = llzk.nondet : !felt.type
49 Note that `llzk.nondet` does not have the `ConstantLike` or `NoMemoryEffect`
50 traits because different SSA variables initialized with `llzk.nondet` may be
51 constrained in different ways so they cannot be treated as identical values.
52 However, it does have the `AlwaysSpeculatable` trait to denote that it is
53 free to move, hoist, and sick without changing the semantics.
58 %0 = llzk.nondet : !felt.type
59 %1 = llzk.nondet : !felt.type
61 constrain.eq %0, %c1 : !felt.type
63 %m = struct.readm %self[@m] : !struct.type<@S>, !felt.type
64 constrain.eq %m, %1 : !felt.type
67 In the above example, `%m` is effectively unconstrained, as it is only constrained
68 to the nondet value `%1`. However, if `%0` and `%1` were treated as pure constants,
69 `%0` and `%1` could be combined, resulting in:
72 %0 = llzk.nondet : !felt.type
74 constrain.eq %0, %c1 : !felt.type
76 %m = struct.readm %self[@m] : !struct.type<@S>, !felt.type
77 constrain.eq %m, %0 : !felt.type
80 This transformation would constrain `%m` to be exactly equal to 1, thus changing
81 the semantics of the circuit.
84 let results = (outs AnyLLZKType:$res);
85 let assemblyFormat = [{ `:` type($res) attr-dict }];
86 let hasCanonicalizer = 1;