LLZK
3.0.0
An open-source IR for Zero Knowledge (ZK) circuits
Toggle main menu visibility
Loading...
Searching...
No Matches
BuilderHelper.h
Go to the documentation of this file.
1
//===-- BuilderHelper.h -----------------------------------------*- 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/Util/ErrorHelper.h
"
13
#include "
llzk/Util/TypeHelper.h
"
14
15
#include <mlir/IR/Builders.h>
16
#include <mlir/IR/Location.h>
17
18
namespace
llzk
{
19
20
template
<
typename
OpClass,
typename
... Args>
21
inline
OpClass
delegate_to_build
(mlir::Location location, Args &&...args) {
22
mlir::OpBuilder builder(location->getContext());
23
return
builder.create<OpClass>(location, std::forward<Args>(args)...);
24
}
25
26
template
<
typename
OpClass>
27
void
addTemplateParams
(
28
mlir::OpBuilder &odsBuilder,
typename
OpClass::Properties &props,
29
llvm::ArrayRef<mlir::Attribute> templateParams
30
) {
31
if
(!templateParams.empty()) {
32
// Must attempt to convert attribute types but `build()` functions do not have a failure path or
33
// error reporting. That comes during validation of the constructed op so ignore errors here.
34
llvm::FailureOr<llvm::SmallVector<mlir::Attribute>> r =
35
llzk::forceIntAttrTypes
(templateParams, [&odsBuilder]() {
36
return
llzk::InFlightDiagnosticWrapper::createSilent
(odsBuilder.getContext());
37
});
38
llvm::ArrayRef<mlir::Attribute> converted = succeeded(r) ? r.value() : templateParams;
39
props.setTemplateParams(odsBuilder.getArrayAttr(converted));
40
}
41
}
42
43
}
// namespace llzk
ErrorHelper.h
TypeHelper.h
llzk::InFlightDiagnosticWrapper::createSilent
static InFlightDiagnosticWrapper createSilent(mlir::MLIRContext *ctx)
Construct a silent diagnostic that does nothing when appended to or reported.
Definition
ErrorHelper.h:74
llzk
Definition
AnalysisPassEnums.cpp:19
llzk::forceIntAttrTypes
FailureOr< SmallVector< Attribute > > forceIntAttrTypes(ArrayRef< Attribute > attrList, EmitErrorFn emitError)
Definition
TypeHelper.cpp:1009
llzk::delegate_to_build
OpClass delegate_to_build(mlir::Location location, Args &&...args)
Definition
BuilderHelper.h:21
llzk::addTemplateParams
void addTemplateParams(mlir::OpBuilder &odsBuilder, typename OpClass::Properties &props, llvm::ArrayRef< mlir::Attribute > templateParams)
Definition
BuilderHelper.h:27
include
llzk
Util
BuilderHelper.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.