LLZK 3.0.0
An open-source IR for Zero Knowledge (ZK) circuits
Loading...
Searching...
No Matches
Support.h
Go to the documentation of this file.
1//===-- Support.h - C API general utilities -----------------------*- 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// This header declares utilities for working with the C API.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLZK_C_SUPPORT_H
15#define LLZK_C_SUPPORT_H
16
17#include "llzk-c/Builder.h" // IWYU pragma: keep
18
19#include <mlir-c/IR.h> // IWYU pragma: keep
20#include <mlir-c/Support.h>
21
22#include <stdint.h> // NOLINT(modernize-deprecated-headers)
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28//===----------------------------------------------------------------------===//
29// Utility macros for function declarations.
30//===----------------------------------------------------------------------===//
31
32#define LLZK_BUILD_METHOD_NAME(dialect, op, suffix) llzk##dialect##_##op##Build##suffix
33#define LLZK_DECLARE_SUFFIX_OP_BUILD_METHOD(dialect, op, suffix, ...) \
34 MLIR_CAPI_EXPORTED MlirOperation LLZK_BUILD_METHOD_NAME(dialect, op, suffix)( \
35 MlirOpBuilder builder, MlirLocation location, __VA_ARGS__ \
36 )
37// Used for when the build method is "general" and does not have a suffix at the end.
38#define LLZK_DECLARE_OP_BUILD_METHOD(dialect, op, ...) \
39 LLZK_DECLARE_SUFFIX_OP_BUILD_METHOD(dialect, op, , __VA_ARGS__)
40
41#define LLZK_DECLARE_OP_PREDICATE(dialect, op, name) \
42 MLIR_CAPI_EXPORTED bool llzk##dialect##_##op##name(MlirOperation op)
43#define LLZK_DECLARE_NARY_OP_PREDICATE(dialect, op, name, ...) \
44 MLIR_CAPI_EXPORTED bool llzk##dialect##_##op##name(MlirOperation op, __VA_ARGS__)
45
49 MlirValue const *values;
51 intptr_t size;
52};
54
60
62MLIR_CAPI_EXPORTED void llzkSymbolLookupResultDestroy(LlzkSymbolLookupResult result);
63
67MLIR_CAPI_EXPORTED MlirOperation LlzkSymbolLookupResultGetOperation(LlzkSymbolLookupResult result);
68
69//===----------------------------------------------------------------------===//
70// CAPI support of additional MLIR functionality.
71//===----------------------------------------------------------------------===//
72
76MLIR_CAPI_EXPORTED
78 MlirOperation from, MlirOperationWalkCallback callback, void *userData, MlirWalkOrder walkOrder
79);
80
86MLIR_CAPI_EXPORTED void llzkSymbolTableInsert(MlirOperation symTableOp, MlirOperation newSymbolOp);
87
88//===----------------------------------------------------------------------===//
89// Helper types and functions for map operands constructor arguments.
90//===----------------------------------------------------------------------===//
91
95 intptr_t nMapOperands;
96 // A list of lists of Values. The outer list is owned by this struct but the inner lists
97 // are not and are considered views (similar to the C++ `ValueRange` class).
102 intptr_t nDimsPerMap;
103 union {
104 MlirAttribute attr;
107 int32_t *array;
110
113
116
118MLIR_CAPI_EXPORTED void llzkAffineMapOperandsBuilderAppendOperands(
119 LlzkAffineMapOperandsBuilder *builder, intptr_t n, MlirValueRange const *mapOperands
120);
121
128 LlzkAffineMapOperandsBuilder *builder, intptr_t n, MlirValueRange const *mapOperands,
129 int32_t const *dimsPerMap
130);
131
136MLIR_CAPI_EXPORTED void llzkAffineMapOperandsBuilderAppendDimCount(
137 LlzkAffineMapOperandsBuilder *builder, intptr_t n, int32_t const *dimsPerMap
138);
139
145 LlzkAffineMapOperandsBuilder *builder, MlirAttribute attribute
146);
147
151MLIR_CAPI_EXPORTED void
153
158 LlzkAffineMapOperandsBuilder *builder, MlirContext context
159);
160
162MLIR_CAPI_EXPORTED MlirAttribute llzkAffineMapOperandsBuilderGetDimsPerMapAttr(
163 LlzkAffineMapOperandsBuilder builder, MlirContext context
164);
165
166#ifdef __cplusplus
167}
168#endif
169
170#endif // LLZK_C_SUPPORT_H
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for and distribution as defined by Sections through of this document Licensor shall mean the copyright owner or entity authorized by the copyright owner that is granting the License Legal Entity shall mean the union of the acting entity and all other entities that control are controlled by or are under common control with that entity For the purposes of this definition control direct or to cause the direction or management of such whether by contract or including but not limited to software source documentation and configuration files Object form shall mean any form resulting from mechanical transformation or translation of a Source including but not limited to compiled object generated and conversions to other media types Work shall mean the work of whether in Source or Object made available under the as indicated by a copyright notice that is included in or attached to the whether in Source or Object that is based or other modifications as a an original work of authorship For the purposes of this Derivative Works shall not include works that remain separable from
Definition LICENSE.txt:45
MLIR_CAPI_EXPORTED void mlirOperationWalkReverse(MlirOperation from, MlirOperationWalkCallback callback, void *userData, MlirWalkOrder walkOrder)
Walks operation op in walkOrder, with operations at the same nesting level traversed in reverse order...
Definition Support.cpp:61
MLIR_CAPI_EXPORTED void llzkAffineMapOperandsBuilderDestroy(LlzkAffineMapOperandsBuilder *builder)
Destroys the struct releasing its resources.
Definition Support.cpp:128
MLIR_CAPI_EXPORTED void llzkSymbolTableInsert(MlirOperation symTableOp, MlirOperation newSymbolOp)
Inserts newSymbolOp into the symbol table owned by symTableOp.
Definition Support.cpp:77
MLIR_CAPI_EXPORTED void llzkSymbolLookupResultDestroy(LlzkSymbolLookupResult result)
Destroys the lookup result, releasing its resources.
Definition Support.cpp:33
MLIR_CAPI_EXPORTED LlzkAffineMapOperandsBuilder llzkAffineMapOperandsBuilderCreate(void)
Creates a new struct. The owner is responsible for cleaning the struct.
Definition Support.cpp:118
MLIR_CAPI_EXPORTED MlirOperation LlzkSymbolLookupResultGetOperation(LlzkSymbolLookupResult result)
Returns the looked up Operation.
Definition Support.cpp:40
MLIR_CAPI_EXPORTED void llzkAffineMapOperandsBuilderAppendDimCount(LlzkAffineMapOperandsBuilder *builder, intptr_t n, int32_t const *dimsPerMap)
Appends a dimension count to the list of dimensions per map.
Definition Support.cpp:156
MLIR_CAPI_EXPORTED void llzkAffineMapOperandsBuilderAppendOperandsWithDimCount(LlzkAffineMapOperandsBuilder *builder, intptr_t n, MlirValueRange const *mapOperands, int32_t const *dimsPerMap)
Appends the value ranges to the list of map operands and indicates how many of these operands are dim...
Definition Support.cpp:146
MLIR_CAPI_EXPORTED void llzkAffineMapOperandsBuilderAppendOperands(LlzkAffineMapOperandsBuilder *builder, intptr_t n, MlirValueRange const *mapOperands)
Appends the value ranges to the list of map operands.
Definition Support.cpp:140
MLIR_CAPI_EXPORTED void llzkAffineMapOperandsBuilderSetDimsPerMapFromAttr(LlzkAffineMapOperandsBuilder *builder, MlirAttribute attribute)
Sets the number of dimensions per map to the given attribute.
Definition Support.cpp:163
MLIR_CAPI_EXPORTED MlirAttribute llzkAffineMapOperandsBuilderGetDimsPerMapAttr(LlzkAffineMapOperandsBuilder builder, MlirContext context)
Returns the number of dimensions per map represented as an attribute.
Definition Support.cpp:191
MLIR_CAPI_EXPORTED void llzkAffineMapOperandsBuilderConvertDimsPerMapToArray(LlzkAffineMapOperandsBuilder *builder)
Converts the list of dimensions defined as an attribute into an array.
Definition Support.cpp:172
MLIR_CAPI_EXPORTED void llzkAffineMapOperandsBuilderConvertDimsPerMapToAttr(LlzkAffineMapOperandsBuilder *builder, MlirContext context)
Converts the list of dimensions defined as an array into an attribute.
Definition Support.cpp:183
Encapsulates the arguments related to affine maps that are common in operation constructors that supp...
Definition Support.h:94
union LlzkAffineMapOperandsBuilder::@126363357317107207232312003203325156066212176243 dimsPerMap
intptr_t nDimsPerMap
Set to a negative number to indicate that dimsPerMap.attr must be used instead of dimsPerMap....
Definition Support.h:102
MlirValueRange * mapOperands
Definition Support.h:98
int32_t * array
List of dimension counts.
Definition Support.h:107
Owned result of an LLZK symbol lookup.
Definition Support.h:56
void * ptr
raw pointer to the result
Definition Support.h:58
Representation of an mlir::ValueRange.
Definition Support.h:47
MlirValue const * values
Pointer to the first value in the range.
Definition Support.h:49
intptr_t size
Number of values in the range.
Definition Support.h:51