LLZK 2.1.1
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/BuiltinAttributes.h>
21#include <mlir-c/IR.h>
22#include <mlir-c/Pass.h>
23
24#include <mlir/CAPI/IR.h>
25#include <mlir/CAPI/Pass.h>
26#include <mlir/CAPI/Registration.h>
27#include <mlir/CAPI/Wrap.h>
28
29using namespace mlir;
30using namespace llzk;
31using namespace llzk::array;
32
33static void registerLLZKArrayTransformationPasses() { registerTransformationPasses(); }
34
35// Include the generated CAPI
39
40MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(Array, llzk__array, ArrayDialect)
41
42//===----------------------------------------------------------------------===//
43// ArrayType
44//===----------------------------------------------------------------------===//
45
46MlirType
47llzkArray_ArrayTypeGetWithDims(MlirType elementType, intptr_t nDims, MlirAttribute const *dims) {
48 SmallVector<Attribute> dimsSto;
49 return wrap(ArrayType::get(unwrap(elementType), unwrapList(nDims, dims, dimsSto)));
50}
51
52MlirType
53llzkArray_ArrayTypeGetWithShape(MlirType elementType, intptr_t nDims, int64_t const *dims) {
54 return wrap(ArrayType::get(unwrap(elementType), ArrayRef(dims, nDims)));
55}
56
57//===----------------------------------------------------------------------===//
58// CreateArrayOp
59//===----------------------------------------------------------------------===//
60
62 Array, CreateArrayOp, WithValues, MlirType arrayType, intptr_t nValues, MlirValue const *values
63) {
64 SmallVector<Value> valueSto;
65 return wrap(
67 builder, location, unwrap_cast<ArrayType>(arrayType),
68 ValueRange(unwrapList(nValues, values, valueSto))
69 )
70 );
71}
72
74 Array, CreateArrayOp, WithMapOperands, MlirType arrayType,
76) {
77 MapOperandsHelper<> mapOps(mapOperands.nMapOperands, mapOperands.mapOperands);
78 auto numDimsPerMap =
79 llzkAffineMapOperandsBuilderGetDimsPerMapAttr(mapOperands, mlirLocationGetContext(location));
80 return wrap(
82 builder, location, unwrap_cast<ArrayType>(arrayType), *mapOps,
84 )
85 );
86}
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:53
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:47
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