LLZK 0.1.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
10#include "llzk/CAPI/Builder.h"
11#include "llzk/CAPI/Support.h"
15
17#include "llzk-c/Support.h"
18
19#include <mlir/CAPI/IR.h>
20#include <mlir/CAPI/Pass.h>
21#include <mlir/CAPI/Registration.h>
22#include <mlir/CAPI/Wrap.h>
23
24#include <mlir-c/IR.h>
25#include <mlir-c/Pass.h>
26
27using namespace mlir;
28using namespace llzk;
29using namespace llzk::array;
30
31static void registerLLZKArrayTransformationPasses() { registerTransformationPasses(); }
32
33// Include impl for transformation passes
35
36MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(Array, llzk__array, ArrayDialect)
37
38//===----------------------------------------------------------------------===//
39// ArrayType
40//===----------------------------------------------------------------------===//
41
42MlirType llzkArrayTypeGet(MlirType elementType, intptr_t nDims, MlirAttribute const *dims) {
43 SmallVector<Attribute> dimsSto;
44 return wrap(ArrayType::get(unwrap(elementType), unwrapList(nDims, dims, dimsSto)));
45}
46
47MlirType
48llzkArrayTypeGetWithNumericDims(MlirType elementType, intptr_t nDims, int64_t const *dims) {
49 return wrap(ArrayType::get(unwrap(elementType), ArrayRef(dims, nDims)));
50}
51
52bool llzkTypeIsAArrayType(MlirType type) { return llvm::isa<ArrayType>(unwrap(type)); }
53
54MlirType llzkArrayTypeGetElementType(MlirType type) {
55 return wrap(unwrap_cast<ArrayType>(type).getElementType());
56}
57
58intptr_t llzkArrayTypeGetNumDims(MlirType type) {
59 return static_cast<intptr_t>(unwrap_cast<ArrayType>(type).getDimensionSizes().size());
60}
61
62MlirAttribute llzkArrayTypeGetDim(MlirType type, intptr_t idx) {
63 return wrap(unwrap_cast<ArrayType>(type).getDimensionSizes()[idx]);
64}
65
66//===----------------------------------------------------------------------===//
67// CreateArrayOp
68//===----------------------------------------------------------------------===//
69
71 CreateArrayOp, WithValues, MlirType arrayType, intptr_t nValues, MlirValue const *values
72) {
73 SmallVector<Value> valueSto;
74 return wrap(
76 builder, location, unwrap_cast<ArrayType>(arrayType),
77 ValueRange(unwrapList(nValues, values, valueSto))
78 )
79 );
80}
81
83 CreateArrayOp, WithMapOperands, MlirType arrayType, LlzkAffineMapOperandsBuilder mapOperands
84) {
85 MapOperandsHelper<> mapOps(mapOperands.nMapOperands, mapOperands.mapOperands);
86 auto numDimsPerMap =
87 llzkAffineMapOperandsBuilderGetDimsPerMapAttr(mapOperands, mlirLocationGetContext(location));
88 return wrap(
90 builder, location, unwrap_cast<ArrayType>(arrayType), *mapOps,
92 )
93 );
94}
MlirAttribute llzkArrayTypeGetDim(MlirType type, intptr_t idx)
Returns the n-th dimention of an llzk::array::ArrayType.
Definition Array.cpp:62
bool llzkTypeIsAArrayType(MlirType type)
Definition Array.cpp:52
intptr_t llzkArrayTypeGetNumDims(MlirType type)
Returns the number of dimensions of an llzk::array::ArrayType.
Definition Array.cpp:58
MlirType llzkArrayTypeGetWithNumericDims(MlirType elementType, intptr_t nDims, int64_t const *dims)
Creates an llzk::array::ArrayType using a list of numbers as dimensions.
Definition Array.cpp:48
MlirType llzkArrayTypeGetElementType(MlirType type)
Returns the element type of an llzk::array::ArrayType.
Definition Array.cpp:54
MlirType llzkArrayTypeGet(MlirType elementType, intptr_t nDims, MlirAttribute const *dims)
Creates an llzk::array::ArrayType using a list of attributes as dimensions.
Definition Array.cpp:42
MlirAttribute llzkAffineMapOperandsBuilderGetDimsPerMapAttr(LlzkAffineMapOperandsBuilder builder, MlirContext context)
Returns the number of dimensions per map represented as an attribute.
Definition Support.cpp:186
Helper for unwrapping the C arguments for the map operands.
Definition Support.h:36
static ArrayType get(::mlir::Type elementType, ::llvm::ArrayRef<::mlir::Attribute > dimensionSizes)
Definition Types.cpp.inc:83
#define LLZK_DEFINE_SUFFIX_OP_BUILD_METHOD(op, suffix,...)
Definition Support.h:25
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:30
Encapsulates the arguments related to affine maps that are common in operation constructors that supp...
Definition Support.h:105
MlirValueRange * mapOperands
Definition Support.h:109