LLZK 0.1.0
Veridise's ZK Language IR
Loading...
Searching...
No Matches
Ops.cpp
Go to the documentation of this file.
1//===-- Ops.cpp - Operation implementations ---------------------*- 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
14
15// TableGen'd implementation files
16#define GET_OP_CLASSES
18
19using namespace mlir;
20using namespace llzk::component;
21
23
24//===------------------------------------------------------------------===//
25// ConstReadOp
26//===------------------------------------------------------------------===//
27
28LogicalResult ConstReadOp::verifySymbolUses(SymbolTableCollection &tables) {
29 FailureOr<StructDefOp> getParentRes = verifyInStruct(*this);
30 if (failed(getParentRes)) {
31 return failure(); // verifyInStruct() already emits a sufficient error message
32 }
33 // Ensure the named constant is a a parameter of the parent struct
34 if (!getParentRes->hasParamNamed(this->getConstNameAttr())) {
35 return this->emitOpError()
36 .append("references unknown symbol \"", this->getConstNameAttr(), "\"")
37 .attachNote(getParentRes->getLoc())
38 .append("must reference a parameter of this struct");
39 }
40 // Ensure any SymbolRef used in the type are valid
41 return verifyTypeResolution(tables, *this, getType());
42}
43
44//===------------------------------------------------------------------===//
45// ApplyMapOp
46//===------------------------------------------------------------------===//
47
48LogicalResult ApplyMapOp::verify() {
49 // Check input and output dimensions match.
50 AffineMap map = getMap();
51
52 // Verify that the map only produces one result.
53 if (map.getNumResults() != 1) {
54 return emitOpError("must produce exactly one value");
55 }
56
57 // Verify that operand count matches affine map dimension and symbol count.
58 unsigned mapDims = map.getNumDims();
59 if (getNumOperands() != mapDims + map.getNumSymbols()) {
60 return emitOpError("operand count must equal affine map dimension+symbol count");
61 } else if (mapDims != getNumDimsAttr().getInt()) {
62 return emitOpError("dimension operand count must equal affine map dimension count");
63 }
64
65 return success();
66}
67
68//===------------------------------------------------------------------===//
69// UnifiableCastOp
70//===------------------------------------------------------------------===//
71
72LogicalResult UnifiableCastOp::verify() {
73 if (!typesUnify(getInput().getType(), getResult().getType())) {
74 return emitOpError() << "input type " << getInput().getType() << " and output type "
75 << getResult().getType() << " are not unifiable";
76 }
77
78 return success();
79}
80
81} // namespace llzk::polymorphic
::mlir::LogicalResult verify()
Definition Ops.cpp:48
::mlir::AffineMap getMap()
Definition Ops.cpp.inc:367
::mlir::IntegerAttr getNumDimsAttr()
Definition Ops.cpp.inc:372
::mlir::FlatSymbolRefAttr getConstNameAttr()
Definition Ops.cpp.inc:662
::mlir::LogicalResult verifySymbolUses(::mlir::SymbolTableCollection &symbolTable)
Definition Ops.cpp:28
::mlir::LogicalResult verify()
Definition Ops.cpp:72
FailureOr< StructDefOp > verifyInStruct(Operation *op)
Definition Ops.cpp:39
LogicalResult verifyTypeResolution(SymbolTableCollection &tables, Operation *origin, Type ty)
bool typesUnify(Type lhs, Type rhs, ArrayRef< StringRef > rhsReversePrefix, UnificationMap *unifications)