LLZK 2.0.0
An open-source IR for Zero Knowledge (ZK) circuits
Loading...
Searching...
No Matches
Ops.h
Go to the documentation of this file.
1//===-- Ops.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
17
18namespace llzk {
19
20namespace component {
21
24template <typename TypeClass>
25// Suppress false positive from `clang-tidy`
26// NOLINTNEXTLINE(bugprone-crtp-constructor-accessibility)
27class SetFuncAllowAttrs : public mlir::OpTrait::TraitBase<TypeClass, SetFuncAllowAttrs> {
28public:
29 static mlir::LogicalResult verifyTrait(mlir::Operation *op);
30};
31
32} // namespace component
33
34namespace function {
35class FuncDefOp;
36} // namespace function
37
38} // namespace llzk
39
40// Include TableGen'd declarations
42
43// Include TableGen'd declarations
44#define GET_OP_CLASSES
46
47namespace llzk::component {
48
49mlir::InFlightDiagnostic
50genCompareErr(StructDefOp expected, mlir::Operation *origin, const char *aspect);
51
52mlir::LogicalResult checkSelfType(
53 mlir::SymbolTableCollection &symbolTable, StructDefOp expectedStruct, mlir::Type actualType,
54 mlir::Operation *origin, const char *aspect
55);
56
58bool isInStruct(mlir::Operation *op);
59
62mlir::FailureOr<StructDefOp> verifyInStruct(mlir::Operation *op);
63
66bool isInStructFunctionNamed(mlir::Operation *op, char const *funcName);
67
70template <char const *FuncName, unsigned PrefixLen>
71mlir::LogicalResult verifyInStructFunctionNamed(
72 mlir::Operation *op, llvm::function_ref<llvm::SmallString<PrefixLen>()> prefix
73) {
74 return isInStructFunctionNamed(op, FuncName)
75 ? mlir::success()
76 : op->emitOpError(prefix())
77 << "only valid within a '" << getOperationName<function::FuncDefOp>()
78 << "' named \"@" << FuncName << "\" within a '"
79 << getOperationName<StructDefOp>() << "' definition";
80}
81
84template <char const *FuncName> struct InStructFunctionNamed {
85 template <typename TypeClass> class Impl : public mlir::OpTrait::TraitBase<TypeClass, Impl> {
86 public:
87 static mlir::LogicalResult verifyTrait(mlir::Operation *op) {
88 return verifyInStructFunctionNamed<FuncName, 0>(op, [] { return llvm::SmallString<0>(); });
89 }
90 };
91};
92
93} // namespace llzk::component
static mlir::LogicalResult verifyTrait(mlir::Operation *op)
Definition Ops.h:87
Only valid/implemented for StructDefOp.
Definition Ops.h:27
static mlir::LogicalResult verifyTrait(mlir::Operation *op)
bool isInStruct(Operation *op)
Definition Ops.cpp:55
InFlightDiagnostic genCompareErr(StructDefOp expected, Operation *origin, const char *aspect)
Definition Ops.cpp:97
LogicalResult checkSelfType(SymbolTableCollection &tables, StructDefOp expectedStruct, Type actualType, Operation *origin, const char *aspect)
Verifies that the given actualType matches the StructDefOp given (i.e., for the "self" type parameter...
Definition Ops.cpp:119
FailureOr< StructDefOp > verifyInStruct(Operation *op)
Definition Ops.cpp:57
mlir::LogicalResult verifyInStructFunctionNamed(mlir::Operation *op, llvm::function_ref< llvm::SmallString< PrefixLen >()> prefix)
Checks if the given Operation is contained within a FuncDefOp with the given name that is itself cont...
Definition Ops.h:71
bool isInStructFunctionNamed(Operation *op, char const *funcName)
Definition Ops.cpp:65
llvm::StringLiteral getOperationName()
Get the operation name, like "constrain.eq" for the given OpClass.
Definition OpHelpers.h:51
This class provides a verifier for ops that are expecting to have an ancestor FuncDefOp with the give...
Definition Ops.h:84