LLZK
3.0.0
An open-source IR for Zero Knowledge (ZK) circuits
Toggle main menu visibility
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-c/Dialect/Array.h
"
11
12
#include "
llzk-c/Support.h
"
13
14
#include "
llzk/CAPI/Builder.h
"
15
#include "
llzk/CAPI/Support.h
"
16
#include "
llzk/Dialect/Array/IR/Ops.h
"
17
#include "
llzk/Dialect/Array/IR/Types.h
"
18
#include "
llzk/Dialect/Array/Transforms/TransformationPasses.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
29
using namespace
mlir
;
30
using namespace
llzk
;
31
using namespace
llzk::array
;
32
33
static
inline
void
registerLLZKArrayTransformationPasses() {
registerTransformationPasses
(); }
34
35
// Include the generated CAPI
36
#include "
llzk/Dialect/Array/IR/Ops.capi.cpp.inc
"
37
#include "
llzk/Dialect/Array/IR/Types.capi.cpp.inc
"
38
#include "
llzk/Dialect/Array/Transforms/TransformationPasses.capi.cpp.inc
"
39
40
MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(Array, llzk__array,
ArrayDialect
)
41
42
//===----------------------------------------------------------------------===//
43
// ArrayType
44
//===----------------------------------------------------------------------===//
45
46
MlirType
47
llzkArray_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
52
MlirType
53
llzkArray_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
61
LLZK_DEFINE_SUFFIX_OP_BUILD_METHOD
(
62
Array,
CreateArrayOp
, WithValues, MlirType arrayType, intptr_t nValues, MlirValue
const
*values
63
) {
64
SmallVector<Value> valueSto;
65
return
mlirOpBuilderInsert
(
66
builder, wrap(
67
create<CreateArrayOp>
(
68
builder, location,
unwrap_cast<ArrayType>
(arrayType),
69
ValueRange(unwrapList(nValues, values, valueSto))
70
)
71
)
72
);
73
}
74
75
LLZK_DEFINE_SUFFIX_OP_BUILD_METHOD
(
76
Array,
CreateArrayOp
, WithMapOperands, MlirType arrayType,
77
LlzkAffineMapOperandsBuilder
mapOperands
78
) {
79
MapOperandsHelper<>
mapOps(mapOperands.
nMapOperands
, mapOperands.
mapOperands
);
80
auto
numDimsPerMap =
81
llzkAffineMapOperandsBuilderGetDimsPerMapAttr
(mapOperands, mlirLocationGetContext(location));
82
return
mlirOpBuilderInsert
(
83
builder, wrap(
84
create<CreateArrayOp>
(
85
builder, location,
unwrap_cast<ArrayType>
(arrayType), *mapOps,
86
unwrap_cast<DenseI32ArrayAttr>
(numDimsPerMap)
87
)
88
)
89
);
90
}
Ops.capi.cpp.inc
Ops.h
Types.capi.cpp.inc
Types.h
TransformationPasses.capi.cpp.inc
TransformationPasses.h
llzkArray_ArrayTypeGetWithShape
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
llzkArray_ArrayTypeGetWithDims
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
Array.h
mlirOpBuilderInsert
MlirOperation mlirOpBuilderInsert(MlirOpBuilder builder, MlirOperation op)
Inserts op at the current insertion point of builder and returns it.
Definition
Builder.cpp:167
llzkAffineMapOperandsBuilderGetDimsPerMapAttr
MlirAttribute llzkAffineMapOperandsBuilderGetDimsPerMapAttr(LlzkAffineMapOperandsBuilder builder, MlirContext context)
Returns the number of dimensions per map represented as an attribute.
Definition
Support.cpp:195
MapOperandsHelper
Helper for unwrapping the C arguments for the map operands.
Definition
Support.h:61
llzk::array::ArrayDialect
Definition
Dialect.h.inc:13
llzk::array::ArrayType::get
static ArrayType get(::mlir::Type elementType, ::llvm::ArrayRef<::mlir::Attribute > dimensionSizes)
Definition
Types.cpp.inc:83
llzk::array::CreateArrayOp
Definition
Ops.h.inc:339
Support.h
Builder.h
Support.h
LLZK_DEFINE_SUFFIX_OP_BUILD_METHOD
#define LLZK_DEFINE_SUFFIX_OP_BUILD_METHOD(dialect, op, suffix,...)
Definition
Support.h:27
llzk::array
Definition
Ops.cpp:43
llzk::array::registerTransformationPasses
void registerTransformationPasses()
Definition
TransformationPasses.h:119
llzk
Definition
AnalysisPassEnums.cpp:19
llzk::create
mlir::Operation * create(MlirOpBuilder cBuilder, MlirLocation cLocation, Args &&...args)
Creates a new operation using an ODS build method.
Definition
Builder.h:41
mlir
Definition
ValueModel.h:30
mlir::unwrap_cast
auto unwrap_cast(auto &from)
Definition
Support.h:51
LlzkAffineMapOperandsBuilder
Encapsulates the arguments related to affine maps that are common in operation constructors that supp...
Definition
Support.h:103
LlzkAffineMapOperandsBuilder::nMapOperands
intptr_t nMapOperands
Definition
Support.h:104
LlzkAffineMapOperandsBuilder::mapOperands
MlirValueRange * mapOperands
Definition
Support.h:107
lib
CAPI
Dialect
Array.cpp
Generated by
1.17.0
Copyright 2025 Veridise Inc. under the Apache License v2.0. Copyright 2026 Project LLZK under the Apache License v2.0.