LLZK 3.0.0
An open-source IR for Zero Knowledge (ZK) circuits
Loading...
Searching...
No Matches
CallLikeOpInterfaces.td
Go to the documentation of this file.
1//===-- CallLikeOpInterfaces.td ----------------------------*- tablegen -*-===//
2//
3// Part of the LLZK Project, under the Apache License v2.0.
4// See LICENSE.txt for license information.
5// Copyright 2026 Project LLZK
6// SPDX-License-Identifier: Apache-2.0
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef LLZK_CALL_LIKE_OP_INTERFACES
11#define LLZK_CALL_LIKE_OP_INTERFACES
12
13include "llzk/Dialect/Shared/OpTraits.td"
14
15include "mlir/IR/Interfaces.td"
16include "mlir/IR/OpBase.td"
17include "mlir/Interfaces/CallInterfaces.td"
18
19def LLZKCallLikeOpInterface
20 : OpInterface<
21 "LLZKCallLikeOpInterface",
22 [DeclareOpInterfaceMethods<
23 CallOpInterface, ["resolveCallable", "resolveCallableInTable"]>,
24 DeclareOpInterfaceMethods<
25 SymbolUserOpInterface, ["verifySymbolUses"]>]> {
26 let cppNamespace = "::llzk";
27 let methods =
28 [InterfaceMethod<
29 [{Returns the "self" value from the callee (or nullptr if it's not a struct target).}],
30 "::mlir::Value", "getSelfValue">,
31 InterfaceMethod<
32 [{Returns the function signature inferred from this call site.}],
33 "::mlir::FunctionType", "getTypeSignature", (ins), /*methodBody=*/"",
34 /*defaultImplementation=*/[{ return ::mlir::FunctionType::get(
35 $_op.getContext(),
36 $_op.getArgOperands().getTypes(),
37 $_op->getResultTypes());
38 }]>,
39 InterfaceMethod<
40 [{Unifies this call site's inferred signature with `other`, resolving paths in
41 `other` relative to `rhsReversePrefix`.}],
42 "::mlir::FailureOr<::llzk::UnificationMap>",
43 "unifyTypeSignatureWithNamespace",
44 (ins "::mlir::FunctionType":$other,
45 "::mlir::ArrayRef<::llvm::StringRef>":$rhsReversePrefix),
46 /*methodBody=*/"", /*defaultImplementation=*/[{
47 ::llzk::UnificationMap unifications;
48 if (::llzk::functionTypesUnify($_op.getTypeSignature(), other, rhsReversePrefix, &unifications)) {
49 return unifications;
50 } else {
51 return ::mlir::failure();
52 }
53 }]>,
54 InterfaceMethod<
55 [{Unifies this call site's inferred signature with `other`.}],
56 "::mlir::FailureOr<::llzk::UnificationMap>", "unifyTypeSignature",
57 (ins "::mlir::FunctionType":$other), /*methodBody=*/"",
58 /*defaultImplementation=*/
59 [{ return $_op.unifyTypeSignatureWithNamespace(other, {}); }]>,
60 StaticInterfaceMethod<
61 [{Allocates consecutive storage for operand groups so they can be passed to builders
62 as an `ArrayRef<ValueRange>`.}],
63 "::llvm::SmallVector<::mlir::ValueRange>", "toVectorOfValueRange",
64 (ins "::mlir::OperandRangeRange":$input), /*methodBody=*/"",
65 /*defaultImplementation=*/[{
66 ::llvm::SmallVector<::mlir::ValueRange, 4> output;
67 output.reserve(input.size());
68 output.insert(output.end(), input.begin(), input.end());
69 return output;
70 }]>,
71 InterfaceMethod<
72 [{Checks a template parameter value against the declared type of its target parameter.}],
73 "::mlir::LogicalResult", "verifyTemplateParamValueCompatibility",
74 (ins "::mlir::Attribute":$paramFromCallOp,
75 "::llzk::polymorphic::TemplateParamOp":$targetParam),
76 /*methodBody=*/"",
77 /*defaultImplementation=*/[{
78 return ::llzk::verifyTemplateParamValueCompatibility(
79 $_op.getOperation(), paramFromCallOp, targetParam);
80 }]>,
81 InterfaceMethod<
82 [{Checks each explicit template parameter against its corresponding declared parameter.
83
84 Pre-condition assertions:
85 - `!isNullOrEmpty(getTemplateParamsAttr())`
86 - `getTemplateParamsAttr().size() == llvm::range_size(targetParamDefs)`}],
87 "::mlir::LogicalResult", "verifyTemplateParamValuesCompatibility",
88 (ins "::llvm::iterator_range<::mlir::Region::op_iterator<::llzk::"
89 "polymorphic::TemplateParamOp>>":$targetParamDefs),
90 /*methodBody=*/"",
91 /*defaultImplementation=*/[{
92 return ::llzk::verifyTemplateParamValuesCompatibility(
93 $_op.getOperation(), $_op.getTemplateParamsAttr(), targetParamDefs);
94 }]>,
95 InterfaceMethod<
96 [{Checks that explicit template parameters agree with their inferred values.
97
98 Pre-condition assertions:
99 - `!isNullOrEmpty(getTemplateParamsAttr())`
100 - `getTemplateParamsAttr().size() == llvm::range_size(targetParamDefs)`}],
101 "::mlir::LogicalResult", "verifyTemplateParamsMatchInferred",
102 (ins "::llvm::iterator_range<::mlir::Region::op_iterator<::llzk::"
103 "polymorphic::TemplateParamOp>>":$targetParamDefs,
104 "const ::llzk::UnificationMap &":$unifications),
105 /*methodBody=*/"",
106 /*defaultImplementation=*/[{
107 return ::llzk::verifyTemplateParamsMatchInferred(
108 $_op.getOperation(), $_op.getTemplateParamsAttr(), targetParamDefs, unifications);
109 }]>];
110}
111
112#endif // LLZK_CALL_LIKE_OP_INTERFACES