LLZK 0.1.0
Veridise's ZK Language IR
Loading...
Searching...
No Matches
Ops.cpp
Go to the documentation of this file.
1//===-- Ops.cpp - Cast operation implementations ----------------*- C++ -*-===//
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
13
14// TableGen'd implementation files
15#define GET_OP_CLASSES
17
18using namespace mlir;
19using namespace llzk::component;
20using namespace llzk::function;
21
22namespace llzk::cast {
23
24//===------------------------------------------------------------------===//
25// FeltToIndexOp
26//===------------------------------------------------------------------===//
27
28LogicalResult FeltToIndexOp::verify() {
29 if (auto parentOr = getParentOfType<FuncDefOp>(*this);
30 succeeded(parentOr) && !parentOr->hasAllowWitnessAttr()) {
31 // Traverse the def-use chain to see if this operand, which is a felt, ever
32 // derives from a Signal struct.
33 SmallVector<Value, 2> frontier {getValue()};
34 DenseSet<Value> visited;
35
36 while (!frontier.empty()) {
37 Value v = frontier.pop_back_val();
38 if (visited.contains(v)) {
39 continue;
40 }
41 visited.insert(v);
42
43 if (Operation *op = v.getDefiningOp()) {
44 if (FieldReadOp readf = mlir::dyn_cast<FieldReadOp>(op);
45 readf && isSignalType(readf.getComponent().getType())) {
46 return (emitOpError() << "input is derived from a Signal struct, which is "
47 << "only valid within a '" << FuncDefOp::getOperationName()
48 << "' with '" << AllowConstraintAttr::name << "' attribute")
49 .attachNote(readf.getLoc())
50 .append("Signal struct value is read here");
51 }
52 frontier.insert(frontier.end(), op->operand_begin(), op->operand_end());
53 }
54 }
55 }
56
57 return success();
58}
59
60} // namespace llzk::cast
::mlir::LogicalResult verify()
Definition Ops.cpp:28
::mlir::TypedValue<::llzk::felt::FeltType > getValue()
Definition Ops.cpp.inc:98
static constexpr ::llvm::StringLiteral getOperationName()
Definition Ops.h.inc:478
bool isSignalType(Type type)
mlir::FailureOr< OpClass > getParentOfType(mlir::Operation *op)
Return the closest surrounding parent operation that is of type 'OpClass'.
Definition OpHelpers.h:32