LLZK 3.0.0
An open-source IR for Zero Knowledge (ZK) circuits
Loading...
Searching...
No Matches
ScalarEvaluation.h
Go to the documentation of this file.
1//===-- ScalarEvaluation.h -------------------------------------*- 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
10#pragma once
11
16
17#include <mlir/IR/Builders.h>
18#include <mlir/Interfaces/SideEffectInterfaces.h>
19
21
26inline mlir::LogicalResult evaluateScalarOperation(
27 mlir::Operation *op, llvm::ArrayRef<mlir::Attribute> operands,
28 llvm::SmallVectorImpl<mlir::OpFoldResult> &results
29) {
30 // Assert casts fold only when their range checks are satisfied.
31 if (op->getNumRegions() || (!mlir::isMemoryEffectFree(op) &&
32 !llvm::isa<llzk::cast::FeltToIndexOp, llzk::cast::IntToFeltOp>(op))) {
33 return mlir::failure();
34 }
35 mlir::Operation *temporary = op->clone();
36 auto status = temporary->fold(operands, results);
37 temporary->destroy();
38 return mlir::success(mlir::succeeded(status) && results.size() == op->getNumResults());
39}
40
41} // namespace llzk::polymorphic::detail
This file implements helpers for DynamicAPInt operations and conversions that LLVM does not provide.
Common interface for constant parameter-like symbol operations that can be defined within a TemplateO...
mlir::LogicalResult evaluateScalarOperation(mlir::Operation *op, llvm::ArrayRef< mlir::Attribute > operands, llvm::SmallVectorImpl< mlir::OpFoldResult > &results)
Evaluate a scalar operation using caller-supplied operand constants.