LLZK 0.1.0
Veridise's ZK Language IR
Loading...
Searching...
No Matches
Builder.h
Go to the documentation of this file.
1//===-- Builder.h - C API for op builder --------------------------*- 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 a type that supports the creation of operations and
11// handles their insertion in blocks.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLZK_C_BUILDER_H
16#define LLZK_C_BUILDER_H
17
18#include <mlir-c/IR.h>
19#include <mlir-c/Support.h>
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25#define DEFINE_C_API_STRUCT(name, storage) \
26 struct name { \
27 storage *ptr; \
28 }; \
29 typedef struct name name
30
31DEFINE_C_API_STRUCT(MlirOpBuilder, void);
32DEFINE_C_API_STRUCT(MlirOpBuilderListener, void);
33
34#undef DEFINE_C_API_STRUCT
35
37 MlirBlock block;
38 MlirOperation point;
39};
41
42typedef void (*MlirNotifyOperationInserted)(MlirOperation, MlirOpBuilderInsertPoint, void *);
43typedef void (*MlirNotifyBlockInserted)(MlirBlock, MlirRegion, MlirBlock, void *);
44
45//===----------------------------------------------------------------------===//
46// MlirOpBuilder
47//===----------------------------------------------------------------------===//
48
49// The API for OpBuilder is left barebones for now since we only need a reference that we can pass
50// to op build methods that we expose. More methods can be added as the need for them arises.
51
52#define DECLARE_SUFFIX_OP_BUILDER_CREATE_FN(suffix, ...) \
53 MLIR_CAPI_EXPORTED MlirOpBuilder mlirOpBuilderCreate##suffix(__VA_ARGS__); \
54 MLIR_CAPI_EXPORTED MlirOpBuilder mlirOpBuilderCreate##suffix##WithListener( \
55 __VA_ARGS__, MlirOpBuilderListener \
56 );
57#define DECLARE_OP_BUILDER_CREATE_FN(...) DECLARE_SUFFIX_OP_BUILDER_CREATE_FN(, __VA_ARGS__)
58
59DECLARE_OP_BUILDER_CREATE_FN(MlirContext context)
60
61#undef DECLARE_OP_BUILDER_CREATE_FN
62
64MLIR_CAPI_EXPORTED void mlirOpBuilderDestroy(MlirOpBuilder builder);
65
67MLIR_CAPI_EXPORTED MlirContext mlirOpBuilderGetContext(MlirOpBuilder builder);
68
70MLIR_CAPI_EXPORTED void
71mlirOpBuilderSetInsertionPointToStart(MlirOpBuilder builder, MlirBlock block);
72
74MLIR_CAPI_EXPORTED MlirOperation mlirOpBuilderGetInsertionPoint(MlirOpBuilder builder);
75
77MLIR_CAPI_EXPORTED MlirBlock mlirOpBuilderGetInsertionBlock(MlirOpBuilder builder);
78
79//===----------------------------------------------------------------------===//
80// MlirOpBuilderListener
81//===----------------------------------------------------------------------===//
82
85MLIR_CAPI_EXPORTED MlirOpBuilderListener mlirOpBuilderListenerCreate(
86 MlirNotifyOperationInserted operationCb, MlirNotifyBlockInserted blockCb, void *userData
87);
88
90MLIR_CAPI_EXPORTED void mlirOpBuilderListenerDestroy(MlirOpBuilderListener listener);
91
92#ifdef __cplusplus
93}
94#endif
95
96#endif
MLIR_CAPI_EXPORTED MlirOpBuilderListener mlirOpBuilderListenerCreate(MlirNotifyOperationInserted operationCb, MlirNotifyBlockInserted blockCb, void *userData)
Creates a new mlir::OpBuilder::Listener.
Definition Builder.cpp:94
#define DECLARE_OP_BUILDER_CREATE_FN(...)
Definition Builder.h:57
void(* MlirNotifyOperationInserted)(MlirOperation, MlirOpBuilderInsertPoint, void *)
Definition Builder.h:42
MLIR_CAPI_EXPORTED MlirOperation mlirOpBuilderGetInsertionPoint(MlirOpBuilder builder)
Returns the current insertion point in the builder.
Definition Builder.cpp:75
#define DEFINE_C_API_STRUCT(name, storage)
Definition Builder.h:25
MLIR_CAPI_EXPORTED void mlirOpBuilderDestroy(MlirOpBuilder builder)
Destroys the given builder.
Definition Builder.cpp:63
MLIR_CAPI_EXPORTED MlirContext mlirOpBuilderGetContext(MlirOpBuilder builder)
Returns the context.
Definition Builder.cpp:67
MLIR_CAPI_EXPORTED MlirBlock mlirOpBuilderGetInsertionBlock(MlirOpBuilder builder)
Returns the current insertion block in the builder.
Definition Builder.cpp:86
MLIR_CAPI_EXPORTED void mlirOpBuilderListenerDestroy(MlirOpBuilderListener listener)
Destroys the given listener.
Definition Builder.cpp:100
MLIR_CAPI_EXPORTED void mlirOpBuilderSetInsertionPointToStart(MlirOpBuilder builder, MlirBlock block)
Sets the insertion point to the beginning of the given block.
Definition Builder.cpp:71
void(* MlirNotifyBlockInserted)(MlirBlock, MlirRegion, MlirBlock, void *)
Definition Builder.h:43
MlirOperation point
Definition Builder.h:38