LLZK 0.1.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_IR_H
15#define LLZK_C_IR_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(op, suffix) llzk##op##Build##suffix
33#define LLZK_DECLARE_SUFFIX_OP_BUILD_METHOD(op, suffix, ...) \
34 MLIR_CAPI_EXPORTED MlirOperation LLZK_BUILD_METHOD_NAME(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(op, ...) LLZK_DECLARE_SUFFIX_OP_BUILD_METHOD(op, , __VA_ARGS__)
39
40#define LLZK_DECLARE_PREDICATE(name, ...) MLIR_CAPI_EXPORTED bool llzk##name(__VA_ARGS__)
41
42#define LLZK_DECLARE_OP_PREDICATE(op, name) \
43 MLIR_CAPI_EXPORTED bool llzk##op##Get##name(MlirOperation op)
44#define LLZK_DECLARE_NARY_OP_PREDICATE(op, name, ...) \
45 MLIR_CAPI_EXPORTED bool llzk##op##Get##name(MlirOperation op, __VA_ARGS__)
46
47#define LLZK_DECLARE_ISA(what, root) MLIR_CAPI_EXPORTED bool llzk##root##IsA##what(Mlir##root what)
48#define LLZK_DECLARE_TYPE_ISA(what) LLZK_DECLARE_ISA(what, Type)
49#define LLZK_DECLARE_OP_ISA(what) LLZK_DECLARE_ISA(what, Operation)
50#define LLZK_DECLARE_ATTR_ISA(what) LLZK_DECLARE_ISA(what, Attribute)
51
52//===----------------------------------------------------------------------===//
53// Representation of a mlir::ValueRange.
54//===----------------------------------------------------------------------===//
55
57 MlirValue const *values;
58 intptr_t size;
59};
61
62//===----------------------------------------------------------------------===//
63// Symbol lookup result.
64//===----------------------------------------------------------------------===//
65
69
71MLIR_CAPI_EXPORTED void llzkSymbolLookupResultDestroy(LlzkSymbolLookupResult result);
72
76MLIR_CAPI_EXPORTED MlirOperation LlzkSymbolLookupResultGetOperation(LlzkSymbolLookupResult result);
77
78//===----------------------------------------------------------------------===//
79// MLIR ports.
80//===----------------------------------------------------------------------===//
81
84MLIR_CAPI_EXPORTED void
85mlirOperationReplaceUsesOfWith(MlirOperation op, MlirValue of, MlirValue with);
86
87//===----------------------------------------------------------------------===//
88// CAPI support of additional MLIR functionality.
89//===----------------------------------------------------------------------===//
90
94MLIR_CAPI_EXPORTED
96 MlirOperation from, MlirOperationWalkCallback callback, void *userData, MlirWalkOrder walkOrder
97);
98
99//===----------------------------------------------------------------------===//
100// Helper types and functions for map operands constructor arguments.
101//===----------------------------------------------------------------------===//
102
106 intptr_t nMapOperands;
107 // A list of lists of Values. The outer list is owned by this struct but the inner lists
108 // are not and are considered views (similar to the C++ `ValueRange` class).
113 intptr_t nDimsPerMap;
114 union {
115 MlirAttribute attr;
118 int32_t *array;
121
124
127
129MLIR_CAPI_EXPORTED void llzkAffineMapOperandsBuilderAppendOperands(
130 LlzkAffineMapOperandsBuilder *builder, intptr_t n, MlirValueRange const *mapOperands
131);
132
139 LlzkAffineMapOperandsBuilder *builder, intptr_t n, MlirValueRange const *mapOperands,
140 int32_t const *dimsPerMap
141);
142
147MLIR_CAPI_EXPORTED void llzkAffineMapOperandsBuilderAppendDimCount(
148 LlzkAffineMapOperandsBuilder *builder, intptr_t n, int32_t const *dimsPerMap
149);
150
156 LlzkAffineMapOperandsBuilder *builder, MlirAttribute attribute
157);
158
162MLIR_CAPI_EXPORTED void
164
169 LlzkAffineMapOperandsBuilder *builder, MlirContext context
170);
171
173MLIR_CAPI_EXPORTED MlirAttribute llzkAffineMapOperandsBuilderGetDimsPerMapAttr(
174 LlzkAffineMapOperandsBuilder builder, MlirContext context
175);
176
177#ifdef __cplusplus
178}
179#endif
180
181#endif
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:62
MLIR_CAPI_EXPORTED void llzkAffineMapOperandsBuilderDestroy(LlzkAffineMapOperandsBuilder *builder)
Destroys the struct releasing its resources.
Definition Support.cpp:123
MLIR_CAPI_EXPORTED void llzkSymbolLookupResultDestroy(LlzkSymbolLookupResult result)
Destroys the lookup result, releasing its resources.
Definition Support.cpp:30
MLIR_CAPI_EXPORTED LlzkAffineMapOperandsBuilder llzkAffineMapOperandsBuilderCreate(void)
Creates a new struct. The owner is responsible for cleaning the struct.
Definition Support.cpp:113
MLIR_CAPI_EXPORTED MlirOperation LlzkSymbolLookupResultGetOperation(LlzkSymbolLookupResult result)
Returns the looked up Operation.
Definition Support.cpp:37
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:151
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:141
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:135
MLIR_CAPI_EXPORTED void llzkAffineMapOperandsBuilderSetDimsPerMapFromAttr(LlzkAffineMapOperandsBuilder *builder, MlirAttribute attribute)
Sets the number of dimensions per map to the given attribute.
Definition Support.cpp:158
MLIR_CAPI_EXPORTED MlirAttribute llzkAffineMapOperandsBuilderGetDimsPerMapAttr(LlzkAffineMapOperandsBuilder builder, MlirContext context)
Returns the number of dimensions per map represented as an attribute.
Definition Support.cpp:186
MLIR_CAPI_EXPORTED void llzkAffineMapOperandsBuilderConvertDimsPerMapToArray(LlzkAffineMapOperandsBuilder *builder)
Converts the list of dimensions defined as an attribute into an array.
Definition Support.cpp:167
MLIR_CAPI_EXPORTED void llzkAffineMapOperandsBuilderConvertDimsPerMapToAttr(LlzkAffineMapOperandsBuilder *builder, MlirContext context)
Converts the list of dimensions defined as an array into an attribute.
Definition Support.cpp:178
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:43
Encapsulates the arguments related to affine maps that are common in operation constructors that supp...
Definition Support.h:105
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:113
MlirValueRange * mapOperands
Definition Support.h:109
int32_t * array
List of dimension counts.
Definition Support.h:118
MlirValue const * values
Definition Support.h:57
intptr_t size
Definition Support.h:58