LLZK 0.1.0
Veridise's ZK Language IR
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
18#include <mlir/CAPI/IR.h>
19#include <mlir/CAPI/Pass.h>
20#include <mlir/CAPI/Registration.h>
21#include <mlir/CAPI/Wrap.h>
22
23#include <mlir-c/Pass.h>
24
25using namespace mlir;
26using namespace llzk::array;
27using namespace llzk;
28
29static void registerLLZKArrayTransformationPasses() { llzk::array::registerTransformationPasses(); }
30
31// Include impl for transformation passes
33
35
36//===----------------------------------------------------------------------===//
37// ArrayType
38//===----------------------------------------------------------------------===//
39
40MlirType llzkArrayTypeGet(MlirType elementType, intptr_t nDims, MlirAttribute const *dims) {
41 SmallVector<Attribute> dimsSto;
42 return wrap(ArrayType::get(unwrap(elementType), unwrapList(nDims, dims, dimsSto)));
43}
44
45MlirType
46llzkArrayTypeGetWithNumericDims(MlirType elementType, intptr_t nDims, int64_t const *dims) {
47 return wrap(ArrayType::get(unwrap(elementType), ArrayRef(dims, nDims)));
48}
49
50bool llzkTypeIsAArrayType(MlirType type) { return mlir::isa<ArrayType>(unwrap(type)); }
51
52MlirType llzkArrayTypeGetElementType(MlirType type) {
53 return wrap(mlir::unwrap_cast<ArrayType>(type).getElementType());
54}
55
56intptr_t llzkArrayTypeGetNumDims(MlirType type) {
57 return static_cast<intptr_t>(mlir::unwrap_cast<ArrayType>(type).getDimensionSizes().size());
58}
59
60MlirAttribute llzkArrayTypeGetDim(MlirType type, intptr_t idx) {
61 return wrap(mlir::unwrap_cast<ArrayType>(type).getDimensionSizes()[idx]);
62}
63
64//===----------------------------------------------------------------------===//
65// CreateArrayOp
66//===----------------------------------------------------------------------===//
67
69 CreateArrayOp, WithValues, MlirType arrayType, intptr_t nValues, MlirValue const *values
70) {
71 SmallVector<Value> valueSto;
72 return wrap(create<CreateArrayOp>(
73 builder, location, mlir::unwrap_cast<ArrayType>(arrayType),
74 ValueRange(unwrapList(nValues, values, valueSto))
75 ));
76}
77
79 CreateArrayOp, WithMapOperands, MlirType arrayType, intptr_t nMapOperands,
80 MlirValueRange const *mapOperands, MlirAttribute numDimsPerMap
81) {
82 MapOperandsHelper<> mapOps(nMapOperands, mapOperands);
83 return wrap(create<CreateArrayOp>(
84 builder, location, mlir::unwrap_cast<ArrayType>(arrayType), *mapOps,
86 ));
87}
88
91 CreateArrayOp, WithMapOperandsAndDims, MlirType arrayType, intptr_t nMapOperands,
92 MlirValueRange const *mapOperands, intptr_t nNumsDimsPerMap, int32_t const *numDimsPerMap
93) {
94 MapOperandsHelper<> mapOps(nMapOperands, mapOperands);
95 return wrap(create<CreateArrayOp>(
96 builder, location, mlir::unwrap_cast<ArrayType>(arrayType), *mapOps,
97 ArrayRef(numDimsPerMap, nNumsDimsPerMap)
98 ));
99}
MlirAttribute llzkArrayTypeGetDim(MlirType type, intptr_t idx)
Returns the n-th dimention of an llzk::array::ArrayType.
Definition Array.cpp:60
bool llzkTypeIsAArrayType(MlirType type)
Definition Array.cpp:50
intptr_t llzkArrayTypeGetNumDims(MlirType type)
Returns the number of dimensions of an llzk::array::ArrayType.
Definition Array.cpp:56
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:46
MlirType llzkArrayTypeGetElementType(MlirType type)
Returns the element type of an llzk::array::ArrayType.
Definition Array.cpp:52
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:40
MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(Polymorphic, llzk__polymorphic, llzk::polymorphic::PolymorphicDialect) MlirType llzkTypeVarTypeGet(MlirContext ctx
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