LLZK 2.0.0
An open-source IR for Zero Knowledge (ZK) circuits
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
11
14
15#include <mlir/Support/LLVM.h>
16
17#include <llvm/ADT/STLExtras.h>
18
19// TableGen'd implementation files
20#define GET_OP_CLASSES
22
23namespace llzk::cast {
24
25bool IntToFeltOp::isCompatibleReturnTypes(::mlir::TypeRange lhs, ::mlir::TypeRange rhs) {
26 return lhs.size() == rhs.size() && llvm::all_of(llvm::zip_equal(lhs, rhs), [](auto pair) {
27 auto [lhsType, rhsType] = pair;
28 auto lhsFeltType = mlir::dyn_cast<llzk::felt::FeltType>(lhsType);
29 auto rhsFeltType = mlir::dyn_cast<llzk::felt::FeltType>(rhsType);
30
31 // If both types are felts but NOT structurally equal then check if the types are valid
32 // with the additional consideration that lhs is allowed to NOT have
33 // a declared field.
34 if (lhsFeltType && rhsFeltType && lhsFeltType != rhsFeltType) {
35 // If we reached this point we know that the felts are not equal and that only the lhs is
36 // allowed to not have a declared field. Thus, rhs must have a declared field. If lhs has a
37 // declared field, then, since they are not structurally equal, it must be a different field
38 // than rhs. With all that, the types are compatible if lhs does not have a field, so we can
39 // simply return that.
40 return !lhsFeltType.hasField();
41 }
42
43 // Any other case gets handled by standard equality.
44 return lhsType == rhsType;
45 });
46}
47} // namespace llzk::cast
static bool isCompatibleReturnTypes(::mlir::TypeRange lhs, ::mlir::TypeRange rhs)
Definition Ops.cpp:25