LLZK 2.0.0
An open-source IR for Zero Knowledge (ZK) circuits
Loading...
Searching...
No Matches
ArrayTypeHelper.h
Go to the documentation of this file.
1//===-- ArrayTypeHelper.h ---------------------------------------*- 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
10#pragma once
11
14
15#include <mlir/IR/Attributes.h>
16#include <mlir/IR/Builders.h>
17#include <mlir/IR/BuiltinTypes.h>
18#include <mlir/IR/Location.h>
19#include <mlir/IR/MLIRContext.h>
20
21#include <llvm/ADT/ArrayRef.h>
22#include <llvm/ADT/SmallVector.h>
23
24#include <optional>
25
26namespace llzk::array {
27
30class ArrayIndexGen {
31 llvm::ArrayRef<int64_t> shape; // owned by the ArrayType from constructor
32 int64_t linearSize;
33 llvm::SmallVector<int64_t> strides;
34
35 ArrayIndexGen(ArrayType);
36
37public:
38 ~ArrayIndexGen() = default;
39 ArrayIndexGen(ArrayIndexGen &&) noexcept = default;
40 ArrayIndexGen &operator=(ArrayIndexGen &&) noexcept = default;
41 ArrayIndexGen(const ArrayIndexGen &) = delete;
42 ArrayIndexGen &operator=(const ArrayIndexGen &) = delete;
43
45 static ArrayIndexGen from(ArrayType);
46
47 std::optional<llvm::SmallVector<mlir::Value>>
48 delinearize(int64_t, mlir::Location, mlir::OpBuilder &) const;
49
50 std::optional<llvm::SmallVector<mlir::Attribute>> delinearize(int64_t, mlir::MLIRContext *) const;
51
52 template <typename InListType> std::optional<int64_t> linearize(InListType multiDimIndex) const;
53
54 // NOTE: If the 'multiDimIndex' is shorter than the array rank (i.e., number of dimensions), they
55 // indices are treated as the high-order/front dimensions of the array.
56 template <typename InListType>
57 std::optional<llvm::SmallVector<mlir::Attribute>> checkAndConvert(InListType multiDimIndex);
58};
59
60} // namespace llzk::array
std::optional< llvm::SmallVector< mlir::Attribute > > checkAndConvert(InListType multiDimIndex)
ArrayIndexGen(ArrayIndexGen &&) noexcept=default
static ArrayIndexGen from(ArrayType)
Construct new ArrayIndexGen. Will assert if hasStaticShape() is false.
std::optional< int64_t > linearize(InListType multiDimIndex) const
std::optional< llvm::SmallVector< mlir::Value > > delinearize(int64_t, mlir::Location, mlir::OpBuilder &) const