LLZK 2.1.1
An open-source IR for Zero Knowledge (ZK) circuits
Loading...
Searching...
No Matches
Ops.cpp.inc
Go to the documentation of this file.
1/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\
2|* *|
3|* Op Definitions *|
4|* *|
5|* Automatically generated file, do not edit! *|
6|* From: Ops.td *|
7|* *|
8\*===----------------------------------------------------------------------===*/
9
10#ifdef GET_OP_LIST
11#undef GET_OP_LIST
12
15#endif // GET_OP_LIST
16
17#ifdef GET_OP_CLASSES
18#undef GET_OP_CLASSES
19
20
21//===----------------------------------------------------------------------===//
22// Local Utility Method Definitions
23//===----------------------------------------------------------------------===//
24
25namespace llzk {
26namespace cast {
27
28static ::llvm::LogicalResult __mlir_ods_local_type_constraint_Ops1(
29 ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind,
30 unsigned valueIndex) {
31 if (!((::llvm::isa<::llzk::felt::FeltType>(type)))) {
32 return op->emitOpError(valueKind) << " #" << valueIndex
33 << " must be finite field element, but got " << type;
34 }
35 return ::mlir::success();
36}
37
38static ::llvm::LogicalResult __mlir_ods_local_type_constraint_Ops2(
39 ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind,
40 unsigned valueIndex) {
41 if (!((::llvm::isa<::mlir::IndexType>(type)))) {
42 return op->emitOpError(valueKind) << " #" << valueIndex
43 << " must be index, but got " << type;
44 }
45 return ::mlir::success();
46}
47
48static ::llvm::LogicalResult __mlir_ods_local_type_constraint_Ops3(
49 ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind,
50 unsigned valueIndex) {
51 if (!(((type.isSignlessInteger(1))) || ((::llvm::isa<::mlir::IndexType>(type))))) {
52 return op->emitOpError(valueKind) << " #" << valueIndex
53 << " must be 1-bit signless integer or index, but got " << type;
54 }
55 return ::mlir::success();
56}
57
58static ::llvm::LogicalResult __mlir_ods_local_attr_constraint_Ops1(
59 ::mlir::Attribute attr, ::llvm::StringRef attrName, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) {
60 if (attr && !((::llvm::isa<::llzk::cast::OverflowSemanticsAttr>(attr))))
61 return emitError() << "attribute '" << attrName
62 << "' failed to satisfy constraint: Cast overflow semantics";
63 return ::mlir::success();
64}
65static ::llvm::LogicalResult __mlir_ods_local_attr_constraint_Ops1(
66 ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) {
67 return __mlir_ods_local_attr_constraint_Ops1(attr, attrName, [op]() {
68 return op->emitOpError();
69 });
70}
71} // namespace cast
72} // namespace llzk
73namespace llzk {
74namespace cast {
75
76//===----------------------------------------------------------------------===//
77// ::llzk::cast::FeltToIndexOp definitions
78//===----------------------------------------------------------------------===//
79
80namespace detail {
82
83::llzk::cast::OverflowSemanticsAttr FeltToIndexOpGenericAdaptorBase::getOverflowAttr() {
84 auto attr = ::llvm::dyn_cast_or_null<::llzk::cast::OverflowSemanticsAttr>(getProperties().overflow);
85 return attr;
86}
87
92
93} // namespace detail
95
96::llvm::LogicalResult FeltToIndexOpAdaptor::verify(::mlir::Location loc) {
97 auto tblgen_overflow = getProperties().overflow; (void)tblgen_overflow;
98
99 if (tblgen_overflow && !((::llvm::isa<::llzk::cast::OverflowSemanticsAttr>(tblgen_overflow))))
100 return emitError(loc, "'cast.toindex' op ""attribute 'overflow' failed to satisfy constraint: Cast overflow semantics");
101 return ::mlir::success();
102}
103
104::llvm::LogicalResult FeltToIndexOp::setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) {
105 ::mlir::DictionaryAttr dict = ::llvm::dyn_cast<::mlir::DictionaryAttr>(attr);
106 if (!dict) {
107 emitError() << "expected DictionaryAttr to set properties";
108 return ::mlir::failure();
109 }
110
111 {
112 auto &propStorage = prop.overflow;
113 auto attr = dict.get("overflow");
114 if (attr) {
115 auto convertedAttr = ::llvm::dyn_cast<std::remove_reference_t<decltype(propStorage)>>(attr);
116 if (convertedAttr) {
117 propStorage = convertedAttr;
118 } else {
119 emitError() << "Invalid attribute `overflow` in property conversion: " << attr;
120 return ::mlir::failure();
121 }
122 }
123 }
124 return ::mlir::success();
125}
126
127::mlir::Attribute FeltToIndexOp::getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop) {
128 ::mlir::SmallVector<::mlir::NamedAttribute> attrs;
129 ::mlir::Builder odsBuilder{ctx};
130
131 {
132 const auto &propStorage = prop.overflow;
133 if (propStorage)
134 attrs.push_back(odsBuilder.getNamedAttr("overflow",
135 propStorage));
136 }
137
138 if (!attrs.empty())
139 return odsBuilder.getDictionaryAttr(attrs);
140 return {};
141}
142
144 return llvm::hash_combine(
145 llvm::hash_value(prop.overflow.getAsOpaquePointer()));
146}
147
148std::optional<mlir::Attribute> FeltToIndexOp::getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name) {
149 if (name == "overflow")
150 return prop.overflow;
151 return std::nullopt;
152}
153
154void FeltToIndexOp::setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value) {
155 if (name == "overflow") {
156 prop.overflow = ::llvm::dyn_cast_or_null<std::remove_reference_t<decltype(prop.overflow)>>(value);
157 return;
158 }
159}
160
161void FeltToIndexOp::populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs) {
162 if (prop.overflow) attrs.append("overflow", prop.overflow);
163}
164
165::llvm::LogicalResult FeltToIndexOp::verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) {
166 {
167 ::mlir::Attribute attr = attrs.get(getOverflowAttrName(opName));
168 if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_Ops1(attr, "overflow", emitError)))
169 return ::mlir::failure();
170 }
171 return ::mlir::success();
172}
173
174::llvm::LogicalResult FeltToIndexOp::readProperties(::mlir::DialectBytecodeReader &reader, ::mlir::OperationState &state) {
175 auto &prop = state.getOrAddProperties<Properties>(); (void)prop;
176 if (::mlir::failed(reader.readOptionalAttribute(prop.overflow)))
177 return ::mlir::failure();
178 return ::mlir::success();
179}
180
181void FeltToIndexOp::writeProperties(::mlir::DialectBytecodeWriter &writer) {
182 auto &prop = getProperties(); (void)prop;
183
184 writer.writeOptionalAttribute(prop.overflow);
185}
186
188 auto attr = getOverflowAttr();
189 return attr.getValue();
190}
191
193 getProperties().overflow = ::llzk::cast::OverflowSemanticsAttr::get(::mlir::Builder((*this)->getContext()).getContext(), attrValue);
194}
195
196void FeltToIndexOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type result, ::llzk::cast::OverflowSemanticsAttr overflow, ::mlir::Value value) {
197 odsState.addOperands(value);
198 if (overflow) {
199 odsState.getOrAddProperties<Properties>().overflow = overflow;
200 }
201 odsState.addTypes(result);
202}
203
204void FeltToIndexOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::llzk::cast::OverflowSemanticsAttr overflow, ::mlir::Value value) {
205 odsState.addOperands(value);
206 if (overflow) {
207 odsState.getOrAddProperties<Properties>().overflow = overflow;
208 }
209
210 ::llvm::SmallVector<::mlir::Type, 2> inferredReturnTypes;
211 if (::mlir::succeeded(FeltToIndexOp::inferReturnTypes(odsBuilder.getContext(),
212 odsState.location, odsState.operands,
213 odsState.attributes.getDictionary(odsState.getContext()),
214 odsState.getRawProperties(),
215 odsState.regions, inferredReturnTypes)))
216 odsState.addTypes(inferredReturnTypes);
217 else
218 ::mlir::detail::reportFatalInferReturnTypesError(odsState);
219
220}
221
222void FeltToIndexOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::llzk::cast::OverflowSemanticsAttr overflow, ::mlir::Value value) {
223 odsState.addOperands(value);
224 if (overflow) {
225 odsState.getOrAddProperties<Properties>().overflow = overflow;
226 }
227 assert(resultTypes.size() == 1u && "mismatched number of results");
228 odsState.addTypes(resultTypes);
229}
230
231void FeltToIndexOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type result, ::llzk::cast::OverflowSemantics overflow, ::mlir::Value value) {
232 odsState.addOperands(value);
233 odsState.getOrAddProperties<Properties>().overflow = ::llzk::cast::OverflowSemanticsAttr::get(odsBuilder.getContext(), overflow);
234 odsState.addTypes(result);
235}
236
237void FeltToIndexOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::llzk::cast::OverflowSemantics overflow, ::mlir::Value value) {
238 odsState.addOperands(value);
239 odsState.getOrAddProperties<Properties>().overflow = ::llzk::cast::OverflowSemanticsAttr::get(odsBuilder.getContext(), overflow);
240
241 ::llvm::SmallVector<::mlir::Type, 2> inferredReturnTypes;
242 if (::mlir::succeeded(FeltToIndexOp::inferReturnTypes(odsBuilder.getContext(),
243 odsState.location, odsState.operands,
244 odsState.attributes.getDictionary(odsState.getContext()),
245 odsState.getRawProperties(),
246 odsState.regions, inferredReturnTypes)))
247 odsState.addTypes(inferredReturnTypes);
248 else
249 ::mlir::detail::reportFatalInferReturnTypesError(odsState);
250
251}
252
253void FeltToIndexOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::llzk::cast::OverflowSemantics overflow, ::mlir::Value value) {
254 odsState.addOperands(value);
255 odsState.getOrAddProperties<Properties>().overflow = ::llzk::cast::OverflowSemanticsAttr::get(odsBuilder.getContext(), overflow);
256 assert(resultTypes.size() == 1u && "mismatched number of results");
257 odsState.addTypes(resultTypes);
258}
259
260void FeltToIndexOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) {
261 assert(operands.size() == 1u && "mismatched number of parameters");
262 odsState.addOperands(operands);
263 odsState.addAttributes(attributes);
264 assert(resultTypes.size() == 1u && "mismatched number of return types");
265 odsState.addTypes(resultTypes);
266
267 if (!attributes.empty()) {
268 ::mlir::OpaqueProperties properties =
269 &odsState.getOrAddProperties<FeltToIndexOp::Properties>();
270 std::optional<::mlir::RegisteredOperationName> info =
271 odsState.name.getRegisteredInfo();
272 if (failed(info->setOpPropertiesFromAttribute(odsState.name, properties,
273 odsState.attributes.getDictionary(odsState.getContext()), nullptr)))
274 ::llvm::report_fatal_error("Property conversion failed.");
275 }
276}
277
278void FeltToIndexOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) {
279 assert(operands.size() == 1u && "mismatched number of parameters");
280 odsState.addOperands(operands);
281 odsState.addAttributes(attributes);
282
283 if (!attributes.empty()) {
284 ::mlir::OpaqueProperties properties =
285 &odsState.getOrAddProperties<FeltToIndexOp::Properties>();
286 std::optional<::mlir::RegisteredOperationName> info =
287 odsState.name.getRegisteredInfo();
288 if (failed(info->setOpPropertiesFromAttribute(odsState.name, properties,
289 odsState.attributes.getDictionary(odsState.getContext()), nullptr)))
290 ::llvm::report_fatal_error("Property conversion failed.");
291 }
292 ::llvm::SmallVector<::mlir::Type, 2> inferredReturnTypes;
293 if (::mlir::succeeded(FeltToIndexOp::inferReturnTypes(odsBuilder.getContext(),
294 odsState.location, operands,
295 odsState.attributes.getDictionary(odsState.getContext()),
296 odsState.getRawProperties(),
297 odsState.regions, inferredReturnTypes))) {
298 assert(inferredReturnTypes.size() == 1u && "mismatched number of return types");
299 odsState.addTypes(inferredReturnTypes);
300 } else {
301 ::llvm::report_fatal_error("Failed to infer result type(s).");
302 }
303}
304
305void FeltToIndexOp::populateDefaultProperties(::mlir::OperationName opName, Properties &properties) {
306 ::mlir::Builder odsBuilder(opName.getContext());
307 if (!properties.overflow)
308 properties.overflow = ::llzk::cast::OverflowSemanticsAttr::get(odsBuilder.getContext(), OverflowSemantics::ASSERT);
309}
310
311::llvm::LogicalResult FeltToIndexOp::verifyInvariantsImpl() {
312 auto tblgen_overflow = getProperties().overflow; (void)tblgen_overflow;
313
314 if (::mlir::failed(__mlir_ods_local_attr_constraint_Ops1(*this, tblgen_overflow, "overflow")))
315 return ::mlir::failure();
316 {
317 unsigned index = 0; (void)index;
318 auto valueGroup0 = getODSOperands(0);
319
320 for (auto v : valueGroup0) {
321 if (::mlir::failed(__mlir_ods_local_type_constraint_Ops1(*this, v.getType(), "operand", index++)))
322 return ::mlir::failure();
323 }
324 }
325 {
326 unsigned index = 0; (void)index;
327 auto valueGroup0 = getODSResults(0);
328
329 for (auto v : valueGroup0) {
330 if (::mlir::failed(__mlir_ods_local_type_constraint_Ops2(*this, v.getType(), "result", index++)))
331 return ::mlir::failure();
332 }
333 }
334 return ::mlir::success();
335}
336
337::llvm::LogicalResult FeltToIndexOp::verifyInvariants() {
338 return verifyInvariantsImpl();
339}
340
341void FeltToIndexOp::getCanonicalizationPatterns(::mlir::RewritePatternSet &results, ::mlir::MLIRContext *context) {
342 results.add(canonicalize);
343}
344
345::llvm::LogicalResult FeltToIndexOp::inferReturnTypes(::mlir::MLIRContext *context, ::std::optional<::mlir::Location> location, ::mlir::ValueRange operands, ::mlir::DictionaryAttr attributes, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions, ::llvm::SmallVectorImpl<::mlir::Type>&inferredReturnTypes) {
346 inferredReturnTypes.resize(1);
347 ::mlir::Builder odsBuilder(context);
348 ::mlir::Type odsInferredType0 = odsBuilder.getIndexType();
349 inferredReturnTypes[0] = odsInferredType0;
350 return ::mlir::success();
351}
352
353::mlir::ParseResult FeltToIndexOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) {
354 ::llzk::cast::OverflowSemanticsAttr overflowAttr;
355 ::mlir::OpAsmParser::UnresolvedOperand valueRawOperand{};
356 ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> valueOperands(&valueRawOperand, 1); ::llvm::SMLoc valueOperandsLoc;
357 (void)valueOperandsLoc;
358 ::mlir::Type valueRawType{};
359 ::llvm::ArrayRef<::mlir::Type> valueTypes(&valueRawType, 1);
360 {
361 auto odsResult = parseOptionalOverflowSemantics(parser, overflowAttr);
362 if (odsResult) return ::mlir::failure();
363 if (overflowAttr)
364 result.getOrAddProperties<FeltToIndexOp::Properties>().overflow = overflowAttr;
365 }
366
367 valueOperandsLoc = parser.getCurrentLocation();
368 if (parser.parseOperand(valueRawOperand))
369 return ::mlir::failure();
370 {
371 auto odsResult = parseInferredOrParsedType(parser, valueRawType, true);
372 if (odsResult) return ::mlir::failure();
373 }
374 {
375 auto loc = parser.getCurrentLocation();(void)loc;
376 if (parser.parseOptionalAttrDict(result.attributes))
377 return ::mlir::failure();
378 if (failed(verifyInherentAttrs(result.name, result.attributes, [&]() {
379 return parser.emitError(loc) << "'" << result.name.getStringRef() << "' op ";
380 })))
381 return ::mlir::failure();
382 }
383 ::mlir::Type odsBuildableType0 = parser.getBuilder().getIndexType();
384 result.addTypes(odsBuildableType0);
385 if (parser.resolveOperands(valueOperands, valueTypes, valueOperandsLoc, result.operands))
386 return ::mlir::failure();
387 return ::mlir::success();
388}
389
390void FeltToIndexOp::print(::mlir::OpAsmPrinter &_odsPrinter) {
391 printOptionalOverflowSemantics(_odsPrinter, *this, getOverflowAttr());
392 _odsPrinter << ' ';
393 _odsPrinter << getValue();
394 printInferredOrParsedType(_odsPrinter, *this, getValue().getType(), true);
395 ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs;
396 elidedAttrs.push_back("overflow");
397 {
398 ::mlir::Builder odsBuilder(getContext());
399 ::mlir::Attribute attr = getOverflowAttr();
400 if(attr && (attr == ::llzk::cast::OverflowSemanticsAttr::get(odsBuilder.getContext(), OverflowSemantics::ASSERT)))
401 elidedAttrs.push_back("overflow");
402 }
403 _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs);
404}
405
406void FeltToIndexOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) {
407}
408
409} // namespace cast
410} // namespace llzk
411MLIR_DEFINE_EXPLICIT_TYPE_ID(::llzk::cast::FeltToIndexOp)
412
413namespace llzk {
414namespace cast {
415
416//===----------------------------------------------------------------------===//
417// ::llzk::cast::IntToFeltOp definitions
418//===----------------------------------------------------------------------===//
419
420namespace detail {
421IntToFeltOpGenericAdaptorBase::IntToFeltOpGenericAdaptorBase(IntToFeltOp op) : odsAttrs(op->getRawDictionaryAttrs()), odsOpName(op->getName()), properties(op.getProperties()), odsRegions(op->getRegions()) {}
422
423::llzk::cast::OverflowSemanticsAttr IntToFeltOpGenericAdaptorBase::getOverflowAttr() {
424 auto attr = ::llvm::dyn_cast_or_null<::llzk::cast::OverflowSemanticsAttr>(getProperties().overflow);
425 return attr;
426}
427
432
433} // namespace detail
435
436::llvm::LogicalResult IntToFeltOpAdaptor::verify(::mlir::Location loc) {
437 auto tblgen_overflow = getProperties().overflow; (void)tblgen_overflow;
438
439 if (tblgen_overflow && !((::llvm::isa<::llzk::cast::OverflowSemanticsAttr>(tblgen_overflow))))
440 return emitError(loc, "'cast.tofelt' op ""attribute 'overflow' failed to satisfy constraint: Cast overflow semantics");
441 return ::mlir::success();
442}
443
444::llvm::LogicalResult IntToFeltOp::setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) {
445 ::mlir::DictionaryAttr dict = ::llvm::dyn_cast<::mlir::DictionaryAttr>(attr);
446 if (!dict) {
447 emitError() << "expected DictionaryAttr to set properties";
448 return ::mlir::failure();
449 }
450
451 {
452 auto &propStorage = prop.overflow;
453 auto attr = dict.get("overflow");
454 if (attr) {
455 auto convertedAttr = ::llvm::dyn_cast<std::remove_reference_t<decltype(propStorage)>>(attr);
456 if (convertedAttr) {
457 propStorage = convertedAttr;
458 } else {
459 emitError() << "Invalid attribute `overflow` in property conversion: " << attr;
460 return ::mlir::failure();
461 }
462 }
463 }
464 return ::mlir::success();
465}
466
467::mlir::Attribute IntToFeltOp::getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop) {
468 ::mlir::SmallVector<::mlir::NamedAttribute> attrs;
469 ::mlir::Builder odsBuilder{ctx};
470
471 {
472 const auto &propStorage = prop.overflow;
473 if (propStorage)
474 attrs.push_back(odsBuilder.getNamedAttr("overflow",
475 propStorage));
476 }
477
478 if (!attrs.empty())
479 return odsBuilder.getDictionaryAttr(attrs);
480 return {};
481}
482
483llvm::hash_code IntToFeltOp::computePropertiesHash(const Properties &prop) {
484 return llvm::hash_combine(
485 llvm::hash_value(prop.overflow.getAsOpaquePointer()));
486}
487
488std::optional<mlir::Attribute> IntToFeltOp::getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name) {
489 if (name == "overflow")
490 return prop.overflow;
491 return std::nullopt;
492}
493
494void IntToFeltOp::setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value) {
495 if (name == "overflow") {
496 prop.overflow = ::llvm::dyn_cast_or_null<std::remove_reference_t<decltype(prop.overflow)>>(value);
497 return;
498 }
499}
500
501void IntToFeltOp::populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs) {
502 if (prop.overflow) attrs.append("overflow", prop.overflow);
503}
504
505::llvm::LogicalResult IntToFeltOp::verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) {
506 {
507 ::mlir::Attribute attr = attrs.get(getOverflowAttrName(opName));
508 if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_Ops1(attr, "overflow", emitError)))
509 return ::mlir::failure();
510 }
511 return ::mlir::success();
512}
513
514::llvm::LogicalResult IntToFeltOp::readProperties(::mlir::DialectBytecodeReader &reader, ::mlir::OperationState &state) {
515 auto &prop = state.getOrAddProperties<Properties>(); (void)prop;
516 if (::mlir::failed(reader.readOptionalAttribute(prop.overflow)))
517 return ::mlir::failure();
518 return ::mlir::success();
519}
520
521void IntToFeltOp::writeProperties(::mlir::DialectBytecodeWriter &writer) {
522 auto &prop = getProperties(); (void)prop;
523
524 writer.writeOptionalAttribute(prop.overflow);
525}
526
528 auto attr = getOverflowAttr();
529 return attr.getValue();
530}
531
533 getProperties().overflow = ::llzk::cast::OverflowSemanticsAttr::get(::mlir::Builder((*this)->getContext()).getContext(), attrValue);
534}
535
536void IntToFeltOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type result, ::llzk::cast::OverflowSemanticsAttr overflow, ::mlir::Value value) {
537 odsState.addOperands(value);
538 if (overflow) {
539 odsState.getOrAddProperties<Properties>().overflow = overflow;
540 }
541 odsState.addTypes(result);
542}
543
544void IntToFeltOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::llzk::cast::OverflowSemanticsAttr overflow, ::mlir::Value value) {
545 odsState.addOperands(value);
546 if (overflow) {
547 odsState.getOrAddProperties<Properties>().overflow = overflow;
548 }
549
550 ::llvm::SmallVector<::mlir::Type, 2> inferredReturnTypes;
551 if (::mlir::succeeded(IntToFeltOp::inferReturnTypes(odsBuilder.getContext(),
552 odsState.location, odsState.operands,
553 odsState.attributes.getDictionary(odsState.getContext()),
554 odsState.getRawProperties(),
555 odsState.regions, inferredReturnTypes)))
556 odsState.addTypes(inferredReturnTypes);
557 else
558 ::mlir::detail::reportFatalInferReturnTypesError(odsState);
559
560}
561
562void IntToFeltOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::llzk::cast::OverflowSemanticsAttr overflow, ::mlir::Value value) {
563 odsState.addOperands(value);
564 if (overflow) {
565 odsState.getOrAddProperties<Properties>().overflow = overflow;
566 }
567 assert(resultTypes.size() == 1u && "mismatched number of results");
568 odsState.addTypes(resultTypes);
569}
570
571void IntToFeltOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type result, ::llzk::cast::OverflowSemantics overflow, ::mlir::Value value) {
572 odsState.addOperands(value);
573 odsState.getOrAddProperties<Properties>().overflow = ::llzk::cast::OverflowSemanticsAttr::get(odsBuilder.getContext(), overflow);
574 odsState.addTypes(result);
575}
576
577void IntToFeltOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::llzk::cast::OverflowSemantics overflow, ::mlir::Value value) {
578 odsState.addOperands(value);
579 odsState.getOrAddProperties<Properties>().overflow = ::llzk::cast::OverflowSemanticsAttr::get(odsBuilder.getContext(), overflow);
580
581 ::llvm::SmallVector<::mlir::Type, 2> inferredReturnTypes;
582 if (::mlir::succeeded(IntToFeltOp::inferReturnTypes(odsBuilder.getContext(),
583 odsState.location, odsState.operands,
584 odsState.attributes.getDictionary(odsState.getContext()),
585 odsState.getRawProperties(),
586 odsState.regions, inferredReturnTypes)))
587 odsState.addTypes(inferredReturnTypes);
588 else
589 ::mlir::detail::reportFatalInferReturnTypesError(odsState);
590
591}
592
593void IntToFeltOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::llzk::cast::OverflowSemantics overflow, ::mlir::Value value) {
594 odsState.addOperands(value);
595 odsState.getOrAddProperties<Properties>().overflow = ::llzk::cast::OverflowSemanticsAttr::get(odsBuilder.getContext(), overflow);
596 assert(resultTypes.size() == 1u && "mismatched number of results");
597 odsState.addTypes(resultTypes);
598}
599
600void IntToFeltOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) {
601 assert(operands.size() == 1u && "mismatched number of parameters");
602 odsState.addOperands(operands);
603 odsState.addAttributes(attributes);
604 assert(resultTypes.size() == 1u && "mismatched number of return types");
605 odsState.addTypes(resultTypes);
606
607 if (!attributes.empty()) {
608 ::mlir::OpaqueProperties properties =
609 &odsState.getOrAddProperties<IntToFeltOp::Properties>();
610 std::optional<::mlir::RegisteredOperationName> info =
611 odsState.name.getRegisteredInfo();
612 if (failed(info->setOpPropertiesFromAttribute(odsState.name, properties,
613 odsState.attributes.getDictionary(odsState.getContext()), nullptr)))
614 ::llvm::report_fatal_error("Property conversion failed.");
615 }
616}
617
618void IntToFeltOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) {
619 assert(operands.size() == 1u && "mismatched number of parameters");
620 odsState.addOperands(operands);
621 odsState.addAttributes(attributes);
622
623 if (!attributes.empty()) {
624 ::mlir::OpaqueProperties properties =
625 &odsState.getOrAddProperties<IntToFeltOp::Properties>();
626 std::optional<::mlir::RegisteredOperationName> info =
627 odsState.name.getRegisteredInfo();
628 if (failed(info->setOpPropertiesFromAttribute(odsState.name, properties,
629 odsState.attributes.getDictionary(odsState.getContext()), nullptr)))
630 ::llvm::report_fatal_error("Property conversion failed.");
631 }
632 ::llvm::SmallVector<::mlir::Type, 2> inferredReturnTypes;
633 if (::mlir::succeeded(IntToFeltOp::inferReturnTypes(odsBuilder.getContext(),
634 odsState.location, operands,
635 odsState.attributes.getDictionary(odsState.getContext()),
636 odsState.getRawProperties(),
637 odsState.regions, inferredReturnTypes))) {
638 assert(inferredReturnTypes.size() == 1u && "mismatched number of return types");
639 odsState.addTypes(inferredReturnTypes);
640 } else {
641 ::llvm::report_fatal_error("Failed to infer result type(s).");
642 }
643}
644
645void IntToFeltOp::populateDefaultProperties(::mlir::OperationName opName, Properties &properties) {
646 ::mlir::Builder odsBuilder(opName.getContext());
647 if (!properties.overflow)
648 properties.overflow = ::llzk::cast::OverflowSemanticsAttr::get(odsBuilder.getContext(), OverflowSemantics::ASSERT);
649}
650
651::llvm::LogicalResult IntToFeltOp::verifyInvariantsImpl() {
652 auto tblgen_overflow = getProperties().overflow; (void)tblgen_overflow;
653
654 if (::mlir::failed(__mlir_ods_local_attr_constraint_Ops1(*this, tblgen_overflow, "overflow")))
655 return ::mlir::failure();
656 {
657 unsigned index = 0; (void)index;
658 auto valueGroup0 = getODSOperands(0);
659
660 for (auto v : valueGroup0) {
661 if (::mlir::failed(__mlir_ods_local_type_constraint_Ops3(*this, v.getType(), "operand", index++)))
662 return ::mlir::failure();
663 }
664 }
665 {
666 unsigned index = 0; (void)index;
667 auto valueGroup0 = getODSResults(0);
668
669 for (auto v : valueGroup0) {
670 if (::mlir::failed(__mlir_ods_local_type_constraint_Ops1(*this, v.getType(), "result", index++)))
671 return ::mlir::failure();
672 }
673 }
674 return ::mlir::success();
675}
676
677::llvm::LogicalResult IntToFeltOp::verifyInvariants() {
678 return verifyInvariantsImpl();
679}
680
681void IntToFeltOp::getCanonicalizationPatterns(::mlir::RewritePatternSet &results, ::mlir::MLIRContext *context) {
682 results.add(canonicalize);
683}
684
685::llvm::LogicalResult IntToFeltOp::inferReturnTypes(::mlir::MLIRContext *context, ::std::optional<::mlir::Location> location, ::mlir::ValueRange operands, ::mlir::DictionaryAttr attributes, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions, ::llvm::SmallVectorImpl<::mlir::Type>&inferredReturnTypes) {
686 inferredReturnTypes.resize(1);
687 ::mlir::Builder odsBuilder(context);
688 ::mlir::Type odsInferredType0 = ::llzk::felt::FeltType::get(odsBuilder.getContext());
689 inferredReturnTypes[0] = odsInferredType0;
690 return ::mlir::success();
691}
692
693::mlir::ParseResult IntToFeltOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) {
694 ::llzk::cast::OverflowSemanticsAttr overflowAttr;
695 ::mlir::OpAsmParser::UnresolvedOperand valueRawOperand{};
696 ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> valueOperands(&valueRawOperand, 1); ::llvm::SMLoc valueOperandsLoc;
697 (void)valueOperandsLoc;
698 ::mlir::Type valueRawType{};
699 ::llvm::ArrayRef<::mlir::Type> valueTypes(&valueRawType, 1);
700 ::mlir::Type resultRawType{};
701 ::llvm::ArrayRef<::mlir::Type> resultTypes(&resultRawType, 1);
702 {
703 auto odsResult = parseOptionalOverflowSemantics(parser, overflowAttr);
704 if (odsResult) return ::mlir::failure();
705 if (overflowAttr)
706 result.getOrAddProperties<IntToFeltOp::Properties>().overflow = overflowAttr;
707 }
708
709 valueOperandsLoc = parser.getCurrentLocation();
710 if (parser.parseOperand(valueRawOperand))
711 return ::mlir::failure();
712 if (parser.parseColon())
713 return ::mlir::failure();
714
715 {
716 ::mlir::Type type;
717 if (parser.parseCustomTypeWithFallback(type))
718 return ::mlir::failure();
719 valueRawType = type;
720 }
721 {
722 auto odsResult = parseInferredOrParsedType(parser, resultRawType, false);
723 if (odsResult) return ::mlir::failure();
724 }
725 {
726 auto loc = parser.getCurrentLocation();(void)loc;
727 if (parser.parseOptionalAttrDict(result.attributes))
728 return ::mlir::failure();
729 if (failed(verifyInherentAttrs(result.name, result.attributes, [&]() {
730 return parser.emitError(loc) << "'" << result.name.getStringRef() << "' op ";
731 })))
732 return ::mlir::failure();
733 }
734 result.addTypes(resultTypes);
735 if (parser.resolveOperands(valueOperands, valueTypes, valueOperandsLoc, result.operands))
736 return ::mlir::failure();
737 return ::mlir::success();
738}
739
740void IntToFeltOp::print(::mlir::OpAsmPrinter &_odsPrinter) {
741 printOptionalOverflowSemantics(_odsPrinter, *this, getOverflowAttr());
742 _odsPrinter << ' ';
743 _odsPrinter << getValue();
744 _odsPrinter << ' ' << ":";
745 _odsPrinter << ' ';
746 {
747 auto type = getValue().getType();
748 if (auto validType = ::llvm::dyn_cast<::mlir::Type>(type))
749 _odsPrinter.printStrippedAttrOrType(validType);
750 else
751 _odsPrinter << type;
752 }
753 printInferredOrParsedType(_odsPrinter, *this, getResult().getType(), false);
754 ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs;
755 elidedAttrs.push_back("overflow");
756 {
757 ::mlir::Builder odsBuilder(getContext());
758 ::mlir::Attribute attr = getOverflowAttr();
759 if(attr && (attr == ::llzk::cast::OverflowSemanticsAttr::get(odsBuilder.getContext(), OverflowSemantics::ASSERT)))
760 elidedAttrs.push_back("overflow");
761 }
762 _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs);
763}
764
765void IntToFeltOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) {
766}
767
768} // namespace cast
769} // namespace llzk
770MLIR_DEFINE_EXPLICIT_TYPE_ID(::llzk::cast::IntToFeltOp)
771
772
773#endif // GET_OP_CLASSES
774
::llvm::LogicalResult verify(::mlir::Location loc)
Definition Ops.cpp.inc:96
FeltToIndexOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, const Properties &properties, ::mlir::RegionRange regions={})
Definition Ops.h.inc:86
FeltToIndexOpAdaptor(FeltToIndexOp op)
Definition Ops.cpp.inc:94
static void populateDefaultProperties(::mlir::OperationName opName, Properties &properties)
Definition Ops.cpp.inc:305
static void populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs)
Definition Ops.cpp.inc:161
::llvm::LogicalResult verifyInvariants()
Definition Ops.cpp.inc:337
::llzk::cast::OverflowSemantics getOverflow()
Definition Ops.cpp.inc:187
::llvm::LogicalResult setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError)
Definition Ops.cpp.inc:104
static void setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value)
Definition Ops.cpp.inc:154
void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect > > &effects)
Definition Ops.cpp.inc:406
static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type result, ::llzk::cast::OverflowSemanticsAttr overflow, ::mlir::Value value)
Definition Ops.cpp.inc:196
static llvm::hash_code computePropertiesHash(const Properties &prop)
Definition Ops.cpp.inc:143
::mlir::TypedValue<::llzk::felt::FeltType > getValue()
Definition Ops.h.inc:161
void print(::mlir::OpAsmPrinter &_odsPrinter)
Definition Ops.cpp.inc:390
::mlir::StringAttr getOverflowAttrName()
Definition Ops.h.inc:139
::llzk::cast::OverflowSemanticsAttr getOverflowAttr()
Definition Ops.h.inc:193
FoldAdaptor::Properties Properties
Definition Ops.h.inc:133
::mlir::Operation::result_range getODSResults(unsigned index)
Definition Ops.h.inc:174
void writeProperties(::mlir::DialectBytecodeWriter &writer)
Definition Ops.cpp.inc:181
::llvm::LogicalResult canonicalize(FeltToIndexOp op, ::mlir::PatternRewriter &rewriter)
Definition Ops.cpp:107
::llvm::LogicalResult readProperties(::mlir::DialectBytecodeReader &reader, ::mlir::OperationState &state)
Definition Ops.cpp.inc:174
static void getCanonicalizationPatterns(::mlir::RewritePatternSet &results, ::mlir::MLIRContext *context)
Definition Ops.cpp.inc:341
::mlir::Attribute getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop)
Definition Ops.cpp.inc:127
static void printOptionalOverflowSemantics(::mlir::OpAsmPrinter &printer, FeltToIndexOp op, ::llzk::cast::OverflowSemanticsAttr overflow)
Definition Ops.cpp:125
::llvm::LogicalResult inferReturnTypes(::mlir::MLIRContext *context, ::std::optional<::mlir::Location > location, ::mlir::ValueRange operands, ::mlir::DictionaryAttr attributes, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions, ::llvm::SmallVectorImpl<::mlir::Type > &inferredReturnTypes)
Definition Ops.cpp.inc:345
void setOverflow(::llzk::cast::OverflowSemantics attrValue)
Definition Ops.cpp.inc:192
::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result)
Definition Ops.cpp.inc:353
::mlir::Operation::operand_range getODSOperands(unsigned index)
Definition Ops.h.inc:155
::llvm::LogicalResult verifyInvariantsImpl()
Definition Ops.cpp.inc:311
::mlir::ParseResult parseOptionalOverflowSemantics(::mlir::OpAsmParser &parser, ::llzk::cast::OverflowSemanticsAttr &overflow)
Definition Ops.cpp:119
::llvm::LogicalResult verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError)
Definition Ops.cpp.inc:165
static std::optional< mlir::Attribute > getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name)
Definition Ops.cpp.inc:148
::llvm::LogicalResult verify(::mlir::Location loc)
Definition Ops.cpp.inc:436
IntToFeltOpAdaptor(IntToFeltOp op)
Definition Ops.cpp.inc:434
IntToFeltOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, const Properties &properties, ::mlir::RegionRange regions={})
Definition Ops.h.inc:336
::llvm::LogicalResult verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError)
Definition Ops.cpp.inc:505
static void populateDefaultProperties(::mlir::OperationName opName, Properties &properties)
Definition Ops.cpp.inc:645
void print(::mlir::OpAsmPrinter &_odsPrinter)
Definition Ops.cpp.inc:740
void setOverflow(::llzk::cast::OverflowSemantics attrValue)
Definition Ops.cpp.inc:532
::llvm::LogicalResult verifyInvariantsImpl()
Definition Ops.cpp.inc:651
::llzk::cast::OverflowSemanticsAttr getOverflowAttr()
Definition Ops.h.inc:443
static void populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs)
Definition Ops.cpp.inc:501
::mlir::StringAttr getOverflowAttrName()
Definition Ops.h.inc:389
::llvm::LogicalResult inferReturnTypes(::mlir::MLIRContext *context, ::std::optional<::mlir::Location > location, ::mlir::ValueRange operands, ::mlir::DictionaryAttr attributes, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions, ::llvm::SmallVectorImpl<::mlir::Type > &inferredReturnTypes)
Definition Ops.cpp.inc:685
void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect > > &effects)
Definition Ops.cpp.inc:765
static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type result, ::llzk::cast::OverflowSemanticsAttr overflow, ::mlir::Value value)
Definition Ops.cpp.inc:536
::mlir::Attribute getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop)
Definition Ops.cpp.inc:467
::llvm::LogicalResult setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError)
Definition Ops.cpp.inc:444
static void getCanonicalizationPatterns(::mlir::RewritePatternSet &results, ::mlir::MLIRContext *context)
Definition Ops.cpp.inc:681
static llvm::hash_code computePropertiesHash(const Properties &prop)
Definition Ops.cpp.inc:483
static std::optional< mlir::Attribute > getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name)
Definition Ops.cpp.inc:488
FoldAdaptor::Properties Properties
Definition Ops.h.inc:383
static void printOptionalOverflowSemantics(::mlir::OpAsmPrinter &printer, IntToFeltOp op, ::llzk::cast::OverflowSemanticsAttr overflow)
Definition Ops.cpp:101
::mlir::Operation::operand_range getODSOperands(unsigned index)
Definition Ops.h.inc:405
::mlir::ParseResult parseOptionalOverflowSemantics(::mlir::OpAsmParser &parser, ::llzk::cast::OverflowSemanticsAttr &overflow)
Definition Ops.cpp:97
::mlir::TypedValue<::llzk::felt::FeltType > getResult()
Definition Ops.h.inc:430
::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result)
Definition Ops.cpp.inc:693
::llvm::LogicalResult readProperties(::mlir::DialectBytecodeReader &reader, ::mlir::OperationState &state)
Definition Ops.cpp.inc:514
::llzk::cast::OverflowSemantics getOverflow()
Definition Ops.cpp.inc:527
void writeProperties(::mlir::DialectBytecodeWriter &writer)
Definition Ops.cpp.inc:521
::mlir::Operation::result_range getODSResults(unsigned index)
Definition Ops.h.inc:424
::llvm::LogicalResult verifyInvariants()
Definition Ops.cpp.inc:677
static void setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value)
Definition Ops.cpp.inc:494
::llvm::LogicalResult canonicalize(IntToFeltOp op, ::mlir::PatternRewriter &rewriter)
Definition Ops.cpp:81
::mlir::TypedValue<::mlir::Type > getValue()
Definition Ops.h.inc:411
FeltToIndexOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const Properties &properties, ::mlir::RegionRange regions={})
Definition Ops.h.inc:59
::std::optional<::mlir::OperationName > odsOpName
Definition Ops.h.inc:55
::llzk::cast::OverflowSemanticsAttr getOverflowAttr()
Definition Ops.cpp.inc:83
::llzk::cast::OverflowSemantics getOverflow()
Definition Ops.cpp.inc:88
::std::optional<::mlir::OperationName > odsOpName
Definition Ops.h.inc:305
::llzk::cast::OverflowSemantics getOverflow()
Definition Ops.cpp.inc:428
::llzk::cast::OverflowSemanticsAttr getOverflowAttr()
Definition Ops.cpp.inc:423
IntToFeltOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const Properties &properties, ::mlir::RegionRange regions={})
Definition Ops.h.inc:309
static FeltType get(::mlir::MLIRContext *context, ::mlir::StringAttr fieldName)
Definition Types.cpp.inc:67