LLZK 2.0.0
An open-source IR for Zero Knowledge (ZK) circuits
Loading...
Searching...
No Matches
Array.cpp
Go to the documentation of this file.
1//===-- Array.cpp - Array dialect C API implementation ----------*- 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
12#include "llzk-c/Support.h"
13
14#include "llzk/CAPI/Builder.h"
15#include "llzk/CAPI/Support.h"
19
20#include <mlir-c/IR.h>
21#include <mlir-c/Pass.h>
22
23#include <mlir/CAPI/IR.h>
24#include <mlir/CAPI/Pass.h>
25#include <mlir/CAPI/Registration.h>
26#include <mlir/CAPI/Wrap.h>
27
28using namespace mlir;
29using namespace llzk;
30using namespace llzk::array;
31
32static void registerLLZKArrayTransformationPasses() { registerTransformationPasses(); }
33
34// Include the generated CAPI
38
39MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(Array, llzk__array, ArrayDialect)
40
41//===----------------------------------------------------------------------===//
42// ArrayType
43//===----------------------------------------------------------------------===//
44
45MlirType
46llzkArray_ArrayTypeGetWithDims(MlirType elementType, intptr_t nDims, MlirAttribute const *dims) {
47 SmallVector<Attribute> dimsSto;
48 return wrap(ArrayType::get(unwrap(elementType), unwrapList(nDims, dims, dimsSto)));
49}
50
51MlirType
52llzkArray_ArrayTypeGetWithShape(MlirType elementType, intptr_t nDims, int64_t const *dims) {
53 return wrap(ArrayType::get(unwrap(elementType), ArrayRef(dims, nDims)));
54}
55
56//===----------------------------------------------------------------------===//
57// CreateArrayOp
58//===----------------------------------------------------------------------===//
59
61 Array, CreateArrayOp, WithValues, MlirType arrayType, intptr_t nValues, MlirValue const *values
62) {
63 SmallVector<Value> valueSto;
64 return wrap(
66 builder, location, unwrap_cast<ArrayType>(arrayType),
67 ValueRange(unwrapList(nValues, values, valueSto))
68 )
69 );
70}
71
73 Array, CreateArrayOp, WithMapOperands, MlirType arrayType,
75) {
76 MapOperandsHelper<> mapOps(mapOperands.nMapOperands, mapOperands.mapOperands);
77 auto numDimsPerMap =
78 llzkAffineMapOperandsBuilderGetDimsPerMapAttr(mapOperands, mlirLocationGetContext(location));
79 return wrap(
81 builder, location, unwrap_cast<ArrayType>(arrayType), *mapOps,
83 )
84 );
85}
MlirType llzkArray_ArrayTypeGetWithShape(MlirType elementType, intptr_t nDims, int64_t const *dims)
Creates an llzk::array::ArrayType using a list of numbers as dimensions.
Definition Array.cpp:52
MlirType llzkArray_ArrayTypeGetWithDims(MlirType elementType, intptr_t nDims, MlirAttribute const *dims)
Creates an llzk::array::ArrayType using a list of attributes as dimensions.
Definition Array.cpp:46
MlirAttribute llzkAffineMapOperandsBuilderGetDimsPerMapAttr(LlzkAffineMapOperandsBuilder builder, MlirContext context)
Returns the number of dimensions per map represented as an attribute.
Definition Support.cpp:195
Helper for unwrapping the C arguments for the map operands.
Definition Support.h:61
static ArrayType get(::mlir::Type elementType, ::llvm::ArrayRef<::mlir::Attribute > dimensionSizes)
Definition Types.cpp.inc:83
#define LLZK_DEFINE_SUFFIX_OP_BUILD_METHOD(dialect, op, suffix,...)
Definition Support.h:27
void registerTransformationPasses()
mlir::Operation * create(MlirOpBuilder cBuilder, MlirLocation cLocation, Args &&...args)
Creates a new operation using an ODS build method.
Definition Builder.h:41
auto unwrap_cast(auto &from)
Definition Support.h:51
Encapsulates the arguments related to affine maps that are common in operation constructors that supp...
Definition Support.h:103
MlirValueRange * mapOperands
Definition Support.h:107