LLZK
3.0.0
An open-source IR for Zero Knowledge (ZK) circuits
Toggle main menu visibility
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
#pragma once
11
12
#include "
llzk-c/Builder.h
"
13
14
#include <mlir/CAPI/IR.h>
15
#include <mlir/CAPI/Wrap.h>
16
#include <mlir/IR/Builders.h>
17
18
DEFINE_C_API_PTR_METHODS(MlirOpBuilder, mlir::OpBuilder)
19
20
namespace
llzk
{
21
22
// Taken from mlir/IR/Builders.h
23
template
<
typename
OpT>
24
mlir::RegisteredOperationName
getCheckRegisteredInfo
(mlir::MLIRContext *ctx) {
25
std::optional<mlir::RegisteredOperationName> opName =
26
mlir::RegisteredOperationName::lookup(OpT::getOperationName(), ctx);
27
if
(LLVM_UNLIKELY(!opName)) {
28
llvm::report_fatal_error(
29
"Building op `"
+ OpT::getOperationName() +
30
"` but it isn't known in this MLIRContext: the dialect may not "
31
"be loaded or this operation hasn't been added by the dialect. See "
32
"also https://mlir.llvm.org/getting_started/Faq/"
33
"#registered-loaded-dependent-whats-up-with-dialects-management"
34
);
35
}
36
return
*opName;
37
}
38
40
template
<
typename
OpTy,
typename
... Args>
41
mlir::Operation *
create
(MlirOpBuilder cBuilder, MlirLocation cLocation, Args &&...args) {
42
auto
location = unwrap(cLocation);
43
auto
*builder = unwrap(cBuilder);
44
assert(builder);
45
mlir::OperationState state(location,
getCheckRegisteredInfo<OpTy>
(location.getContext()));
46
OpTy::build(*builder, state, std::forward<Args>(args)...);
47
auto
*op = mlir::Operation::create(state);
48
assert(llvm::isa<OpTy>(op) &&
"builder didn't return the right type"
);
49
return
op;
50
}
51
52
}
// namespace llzk
Builder.h
llzk
Definition
AnalysisPassEnums.cpp:19
llzk::getCheckRegisteredInfo
mlir::RegisteredOperationName getCheckRegisteredInfo(mlir::MLIRContext *ctx)
Definition
Builder.h:24
llzk::create
mlir::Operation * create(MlirOpBuilder cBuilder, MlirLocation cLocation, Args &&...args)
Creates a new operation using an ODS build method.
Definition
Builder.h:41
include
llzk
CAPI
Builder.h
Generated by
1.17.0
Copyright 2025 Veridise Inc. under the Apache License v2.0. Copyright 2026 Project LLZK under the Apache License v2.0.