LLZK 3.0.0
An open-source IR for Zero Knowledge (ZK) circuits
Loading...
Searching...
No Matches
Attrs.cpp
Go to the documentation of this file.
1//===-- Attrs.cpp - Felt Attr method implementations ------------*- C++ -*-===//
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
11
13
14using namespace mlir;
15
16namespace llzk::felt {
17
18LogicalResult FieldSpecAttr::verify(
19 llvm::function_ref<InFlightDiagnostic()> emitError, StringAttr,
20 // TableGen requires this parameter to be passed by value.
21 llzk::DynamicAPIntValue primeWrapper // NOLINT(performance-unnecessary-value-param)
22) {
23 const llvm::DynamicAPInt &prime = primeWrapper; // implict unwrap
24 if (prime < 2) {
25 return emitError() << "field modulus must be at least 2";
26 }
27 return success();
28}
29
30StringAttr FeltConstAttr::getFieldName() const {
31 FeltType ft = getType();
32 return ft ? ft.getFieldName() : StringAttr();
33}
34
35std::optional<llvm::DynamicAPInt> FeltConstAttr::getReducedValue() const {
36 FeltType type = getType();
37 if (!type || !type.hasField()) {
38 return std::nullopt;
39 }
40 return type.getField().reduce(getRawValue());
41}
42
43llvm::DynamicAPInt FeltConstAttr::getReducedValueOrRaw() const {
44 if (auto reduced = getReducedValue()) {
45 return *reduced;
46 }
47 return getRawValue();
48}
49
50} // namespace llzk::felt
This file implements helpers for DynamicAPInt operations and conversions that LLVM does not provide.
Attribute storage adapter providing numeric hashing for DynamicAPInt.
llvm::DynamicAPInt reduce(const llvm::DynamicAPInt &i) const
Returns the canonical representative of i mod p in [0, p).
const ::llzk::Field & getField() const
Definition Dialect.cpp:255
::mlir::StringAttr getFieldName() const
bool hasField() const
Definition Types.h.inc:50