LLZK 3.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
18
19namespace llzk {
20
21namespace component {
22
25template <typename TypeClass>
26// Suppress false positive from `clang-tidy`
27// NOLINTNEXTLINE(bugprone-crtp-constructor-accessibility)
28class SetFuncAllowAttrs : public mlir::OpTrait::TraitBase<TypeClass, SetFuncAllowAttrs> {
29public:
30 static mlir::LogicalResult verifyTrait(mlir::Operation *op);
31};
32
33} // namespace component
34
35namespace function {
36class FuncDefOp;
37} // namespace function
38
39} // namespace llzk
40
41// Include TableGen'd declarations
43
44// Include TableGen'd declarations
45#define GET_OP_CLASSES
47
48namespace llzk::component {
49
50mlir::InFlightDiagnostic
51genCompareErr(StructDefOp expected, mlir::Operation *origin, const char *aspect);
52
53mlir::LogicalResult checkSelfType(
54 mlir::SymbolTableCollection &symbolTable, StructDefOp expectedStruct, mlir::Type actualType,
55 mlir::Operation *origin, const char *aspect
56);
57
59bool isInStruct(mlir::Operation *op);
60
63mlir::FailureOr<StructDefOp> verifyInStruct(mlir::Operation *op);
64
67bool isInStructFunctionNamed(mlir::Operation *op, char const *funcName);
68
71template <char const *FuncName, unsigned PrefixLen>
72mlir::LogicalResult verifyInStructFunctionNamed(
73 mlir::Operation *op, llvm::function_ref<llvm::SmallString<PrefixLen>()> prefix
74) {
75 return isInStructFunctionNamed(op, FuncName)
76 ? mlir::success()
77 : op->emitOpError(prefix())
78 << "only valid within a '" << getOperationName<function::FuncDefOp>()
79 << "' named \"@" << FuncName << "\" within a '"
80 << getOperationName<StructDefOp>() << "' definition";
81}
82
85template <char const *FuncName> struct InStructFunctionNamed {
86 template <typename TypeClass> class Impl : public mlir::OpTrait::TraitBase<TypeClass, Impl> {
87 public:
88 static mlir::LogicalResult verifyTrait(mlir::Operation *op) {
89 return verifyInStructFunctionNamed<FuncName, 0>(op, [] { return llvm::SmallString<0>(); });
90 }
91 };
92};
93
94} // namespace llzk::component
static mlir::LogicalResult verifyTrait(mlir::Operation *op)
Definition Ops.h:88
Only valid/implemented for StructDefOp.
Definition Ops.h:28
static mlir::LogicalResult verifyTrait(mlir::Operation *op)
bool isInStruct(Operation *op)
Definition Ops.cpp:57
InFlightDiagnostic genCompareErr(StructDefOp expected, Operation *origin, const char *aspect)
Definition Ops.cpp:99
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:121
FailureOr< StructDefOp > verifyInStruct(Operation *op)
Definition Ops.cpp:59
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:72
bool isInStructFunctionNamed(Operation *op, char const *funcName)
Definition Ops.cpp:67
llvm::StringLiteral getOperationName()
Get the operation name, like "constrain.eq" for the given OpClass.
Definition OpHelpers.h:32
This class provides a verifier for ops that are expecting to have an ancestor FuncDefOp with the give...
Definition Ops.h:85