LLZK 2.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>
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// MLIR ports.
71//===----------------------------------------------------------------------===//
72
75MLIR_CAPI_EXPORTED void
76mlirOperationReplaceUsesOfWith(MlirOperation op, MlirValue of, MlirValue with);
77
78//===----------------------------------------------------------------------===//
79// CAPI support of additional MLIR functionality.
80//===----------------------------------------------------------------------===//
81
85MLIR_CAPI_EXPORTED
87 MlirOperation from, MlirOperationWalkCallback callback, void *userData, MlirWalkOrder walkOrder
88);
89
95MLIR_CAPI_EXPORTED void llzkSymbolTableInsert(MlirOperation symTableOp, MlirOperation newSymbolOp);
96
97//===----------------------------------------------------------------------===//
98// Helper types and functions for map operands constructor arguments.
99//===----------------------------------------------------------------------===//
100
104 intptr_t nMapOperands;
105 // A list of lists of Values. The outer list is owned by this struct but the inner lists
106 // are not and are considered views (similar to the C++ `ValueRange` class).
111 intptr_t nDimsPerMap;
112 union {
113 MlirAttribute attr;
116 int32_t *array;
119
122
125
127MLIR_CAPI_EXPORTED void llzkAffineMapOperandsBuilderAppendOperands(
128 LlzkAffineMapOperandsBuilder *builder, intptr_t n, MlirValueRange const *mapOperands
129);
130
137 LlzkAffineMapOperandsBuilder *builder, intptr_t n, MlirValueRange const *mapOperands,
138 int32_t const *dimsPerMap
139);
140
145MLIR_CAPI_EXPORTED void llzkAffineMapOperandsBuilderAppendDimCount(
146 LlzkAffineMapOperandsBuilder *builder, intptr_t n, int32_t const *dimsPerMap
147);
148
154 LlzkAffineMapOperandsBuilder *builder, MlirAttribute attribute
155);
156
160MLIR_CAPI_EXPORTED void
162
167 LlzkAffineMapOperandsBuilder *builder, MlirContext context
168);
169
171MLIR_CAPI_EXPORTED MlirAttribute llzkAffineMapOperandsBuilderGetDimsPerMapAttr(
172 LlzkAffineMapOperandsBuilder builder, MlirContext context
173);
174
175#ifdef __cplusplus
176}
177#endif
178
179#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 or merely the Work and Derivative Works thereof Contribution shall mean any work of including the original version of the Work and any modifications or additions to that Work or Derivative Works that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner For the purposes of this submitted means any form of or written communication sent to the Licensor or its including but not limited to communication on electronic mailing source code control and issue tracking systems that are managed or on behalf of
Definition LICENSE.txt:57
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:65
MLIR_CAPI_EXPORTED void llzkAffineMapOperandsBuilderDestroy(LlzkAffineMapOperandsBuilder *builder)
Destroys the struct releasing its resources.
Definition Support.cpp:132
MLIR_CAPI_EXPORTED void llzkSymbolTableInsert(MlirOperation symTableOp, MlirOperation newSymbolOp)
Inserts newSymbolOp into the symbol table owned by symTableOp.
Definition Support.cpp:81
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:122
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:160
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:150
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:144
MLIR_CAPI_EXPORTED void llzkAffineMapOperandsBuilderSetDimsPerMapFromAttr(LlzkAffineMapOperandsBuilder *builder, MlirAttribute attribute)
Sets the number of dimensions per map to the given attribute.
Definition Support.cpp:167
MLIR_CAPI_EXPORTED MlirAttribute llzkAffineMapOperandsBuilderGetDimsPerMapAttr(LlzkAffineMapOperandsBuilder builder, MlirContext context)
Returns the number of dimensions per map represented as an attribute.
Definition Support.cpp:195
MLIR_CAPI_EXPORTED void llzkAffineMapOperandsBuilderConvertDimsPerMapToArray(LlzkAffineMapOperandsBuilder *builder)
Converts the list of dimensions defined as an attribute into an array.
Definition Support.cpp:176
MLIR_CAPI_EXPORTED void llzkAffineMapOperandsBuilderConvertDimsPerMapToAttr(LlzkAffineMapOperandsBuilder *builder, MlirContext context)
Converts the list of dimensions defined as an array into an attribute.
Definition Support.cpp:187
MLIR_CAPI_EXPORTED void mlirOperationReplaceUsesOfWith(MlirOperation op, MlirValue of, MlirValue with)
Replace uses of 'of' value with the 'with' value inside the 'op' operation.
Definition Support.cpp:46
Encapsulates the arguments related to affine maps that are common in operation constructors that supp...
Definition Support.h:103
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:111
MlirValueRange * mapOperands
Definition Support.h:107
int32_t * array
List of dimension counts.
Definition Support.h:116
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