LLZK 3.0.0
An open-source IR for Zero Knowledge (ZK) circuits
Loading...
Searching...
No Matches
Attrs.td
Go to the documentation of this file.
1//===-- Attrs.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_ATTRS
11#define LLZK_ATTRS
12
13include "llzk/Dialect/LLZK/IR/Dialect.td"
14include "llzk/Dialect/LLZK/IR/AttributeHelper.td"
15
16include "mlir/IR/AttrTypeBase.td"
17include "mlir/IR/BuiltinAttributeInterfaces.td"
18include "mlir/IR/EnumAttr.td"
19
20class LLZKDialectAttr<string name, string attrMnemonic, list<Trait> traits = []>
21 : AttrDef<LLZKDialect, name, traits> {
22 let mnemonic = attrMnemonic;
23}
24
25def LLZK_PublicAttr : LLZKDialectAttr<"Public", "pub"> {
26 let summary = "A unit attribute to mark an input/output as public";
27 let description = [{
28 This attribute is used on parameters of `compute()` and `constrain()` functions
29 within a `struct.def` to denote the public inputs of the circuit and on
30 `struct.member` ops to denote public output of the circuit.
31
32 Examples:
33
34 ```llzk
35 struct.member @member_name : !felt.type {llzk.pub}
36
37 function.def @compute(%0: !felt.type {llzk.pub})
38 ```
39 }];
40}
41
42def LLZK_LoopBoundsAttr : LLZKDialectAttr<"LoopBounds", "loopbounds"> {
43 let summary = "Trusted annotation with the bounds of a loop";
44 let description = [{
45 This attribute indicates the loop variable's lower bound (inclusive), upper
46 bound (exclusive), and step size.
47
48 These attributes are trusted unconditionally, so the producer must ensure
49 these values agree with the loop's behavior. Passes are not required to
50 produce an error diagnostic if the values specified by the attribute
51 contradict the IR itself; incorrect annotations can change program behavior.
52
53 Example:
54
55 ```llzk
56 scf.while ... {
57 ...
58 } do {
59 ...
60 } attributes { llzk.loopbounds = #llzk.loopbounds<0 to 10 step 1> }
61 ```
62 }];
63
64 let parameters = (ins DynamicAPIntParameter<
65 "Loop variable lower bound (inclusive)">:$lower,
66 DynamicAPIntParameter<"Loop variable upper bound (exclusive)">:$upper,
67 DynamicAPIntParameter<"Loop variable step/increment">:$step);
68
69 let builders = [AttrBuilder<(ins "const ::llvm::DynamicAPInt &":$lower,
70 "const ::llvm::DynamicAPInt &":$upper,
71 "const ::llvm::DynamicAPInt &":$step),
72 [{ return $_get(context,
73 ::llzk::DynamicAPIntValue(lower),
74 ::llzk::DynamicAPIntValue(upper),
75 ::llzk::DynamicAPIntValue(step)); }]>];
76
77 let assemblyFormat = "`<` $lower `to` $upper `step` $step `>`";
78}
79
80#endif // LLZK_ATTRS